From e8044453f30123965a6f1577ede3df231ae95828 Mon Sep 17 00:00:00 2001 From: Lee Yi Date: Mon, 25 Mar 2024 12:10:32 -0400 Subject: [PATCH] Module Loading Changes (#2871) * Remove side content state from workspaces and story env * Run format * Fix broken import * Change to new tab loading system * Merge * Fix wrongly named type * Run format * bumping js-slang * update mock context --------- Co-authored-by: henz Co-authored-by: NhatMinh0208 --- package.json | 2 +- src/commons/application/ApplicationTypes.ts | 10 +--------- src/commons/mocks/ContextMocks.ts | 3 ++- src/commons/sideContent/SideContentHelper.ts | 11 +++++++---- src/commons/sideContent/SideContentReducer.ts | 3 +-- src/commons/workspace/WorkspaceTypes.ts | 2 -- src/features/cseMachine/CseMachineUtils.ts | 2 +- src/features/stories/StoriesTypes.ts | 2 -- src/index.tsx | 2 +- yarn.lock | 8 ++++---- 10 files changed, 18 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index dd4d4d2594..f2d1758ef1 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "flexboxgrid": "^6.3.1", "flexboxgrid-helpers": "^1.1.3", "hastscript": "^9.0.0", - "js-slang": "^1.0.51", + "js-slang": "^1.0.52", "js-yaml": "^4.1.0", "konva": "^9.2.0", "lodash": "^4.17.21", diff --git a/src/commons/application/ApplicationTypes.ts b/src/commons/application/ApplicationTypes.ts index 7aef78e62c..fc0c6cfe94 100644 --- a/src/commons/application/ApplicationTypes.ts +++ b/src/commons/application/ApplicationTypes.ts @@ -381,10 +381,6 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): Wo isDebugging: false, enableDebugging: true, debuggerContext: {} as DebuggerContext, - sideContent: { - alerts: [], - dynamicTabs: [] - }, lastDebuggerResult: undefined, lastNonDetResult: null }); @@ -527,11 +523,7 @@ export const createDefaultStoriesEnv = ( stepLimit: 1000, globals: [], usingSubst: false, - debuggerContext: {} as DebuggerContext, - sideContent: { - dynamicTabs: [], - alerts: [] - } + debuggerContext: {} as DebuggerContext }); export const defaultFileSystem: FileSystemState = { diff --git a/src/commons/mocks/ContextMocks.ts b/src/commons/mocks/ContextMocks.ts index df0d15605a..0b7c10bb25 100644 --- a/src/commons/mocks/ContextMocks.ts +++ b/src/commons/mocks/ContextMocks.ts @@ -37,7 +37,8 @@ export function mockRuntimeContext(): Context { control: null, stash: null, envStepsTotal: 0, - breakpointSteps: [] + breakpointSteps: [], + changepointSteps: [] }; return context; } diff --git a/src/commons/sideContent/SideContentHelper.ts b/src/commons/sideContent/SideContentHelper.ts index 27b747432b..893fed7484 100644 --- a/src/commons/sideContent/SideContentHelper.ts +++ b/src/commons/sideContent/SideContentHelper.ts @@ -45,27 +45,30 @@ const requireProvider = (x: string) => { return exports[x]; }; -type RawTab = (provider: ReturnType) => ModuleSideContent; +type RawTab = (provider: ReturnType) => { default: ModuleSideContent }; /** * Returns an array of SideContentTabs to be spawned * @param debuggerContext - DebuggerContext object from redux store */ -export const getDynamicTabs = (debuggerContext: DebuggerContext): SideContentTab[] => { +export function getDynamicTabs(debuggerContext: DebuggerContext): SideContentTab[] { const moduleContexts = debuggerContext?.context?.moduleContexts; if (!moduleContexts) return []; return Object.values(moduleContexts) .flatMap(({ tabs }) => tabs ?? []) - .map((rawTab: RawTab) => rawTab(requireProvider)) + .map((rawTab: RawTab) => { + const { default: content } = rawTab(requireProvider); + return content; + }) .filter(({ toSpawn }) => !toSpawn || toSpawn(debuggerContext)) .map(tab => ({ ...tab, body: tab.body(debuggerContext), id: SideContentType.module })); -}; +} export const generateIconId = (tabId: TabId) => `${tabId}-icon`; export const getTabId = (tab: SideContentTab) => diff --git a/src/commons/sideContent/SideContentReducer.ts b/src/commons/sideContent/SideContentReducer.ts index 33da6e93d5..6781a1ba32 100644 --- a/src/commons/sideContent/SideContentReducer.ts +++ b/src/commons/sideContent/SideContentReducer.ts @@ -2,13 +2,12 @@ import { defaultSideContent, defaultSideContentManager } from '../application/Ap import { SourceActionType } from '../utils/ActionsHelper'; import { getDynamicTabs, getTabId } from './SideContentHelper'; import { getLocation } from './SideContentHelper'; -import { CHANGE_SIDE_CONTENT_HEIGHT } from './SideContentTypes'; +import { CHANGE_SIDE_CONTENT_HEIGHT, SPAWN_SIDE_CONTENT } from './SideContentTypes'; import { END_ALERT_SIDE_CONTENT, REMOVE_SIDE_CONTENT_ALERT, RESET_SIDE_CONTENT, SideContentManagerState, - SPAWN_SIDE_CONTENT, VISIT_SIDE_CONTENT } from './SideContentTypes'; diff --git a/src/commons/workspace/WorkspaceTypes.ts b/src/commons/workspace/WorkspaceTypes.ts index f7b8f41ffe..53343053e5 100644 --- a/src/commons/workspace/WorkspaceTypes.ts +++ b/src/commons/workspace/WorkspaceTypes.ts @@ -6,7 +6,6 @@ import { InterpreterOutput } from '../application/ApplicationTypes'; import { ExternalLibraryName } from '../application/types/ExternalTypes'; import { AutogradingResult, Testcase } from '../assessment/AssessmentTypes'; import { HighlightedLines, Position } from '../editor/EditorTypes'; -import { SideContentState } from '../sideContent/SideContentTypes'; export const ADD_HTML_CONSOLE_ERROR = 'ADD_HTML_CONSOLE_ERROR'; export const BEGIN_CLEAR_CONTEXT = 'BEGIN_CLEAR_CONTEXT'; @@ -147,7 +146,6 @@ export type WorkspaceState = { readonly stepLimit: number; readonly globals: Array<[string, any]>; readonly debuggerContext: DebuggerContext; - readonly sideContent: SideContentState; readonly lastDebuggerResult: any; readonly lastNonDetResult: Result | null; }; diff --git a/src/features/cseMachine/CseMachineUtils.ts b/src/features/cseMachine/CseMachineUtils.ts index 75debd3079..a397af6dce 100644 --- a/src/features/cseMachine/CseMachineUtils.ts +++ b/src/features/cseMachine/CseMachineUtils.ts @@ -10,7 +10,7 @@ import { UnOpInstr } from 'js-slang/dist/cse-machine/types'; import { Environment, Value as StashValue } from 'js-slang/dist/types'; -import { astToString } from 'js-slang/dist/utils/astToString'; +import { astToString } from 'js-slang/dist/utils/ast/astToString'; import { Group } from 'konva/lib/Group'; import { Node } from 'konva/lib/Node'; import { Shape } from 'konva/lib/Shape'; diff --git a/src/features/stories/StoriesTypes.ts b/src/features/stories/StoriesTypes.ts index e383ffe073..524210e5b2 100644 --- a/src/features/stories/StoriesTypes.ts +++ b/src/features/stories/StoriesTypes.ts @@ -1,5 +1,4 @@ import { Context } from 'js-slang'; -import { SideContentState } from 'src/commons/sideContent/SideContentTypes'; import { DebuggerContext } from 'src/commons/workspace/WorkspaceTypes'; import { InterpreterOutput, StoriesRole } from '../../commons/application/ApplicationTypes'; @@ -60,7 +59,6 @@ export type StoriesEnvState = { readonly globals: Array<[string, any]>; readonly usingSubst: boolean; readonly debuggerContext: DebuggerContext; - readonly sideContent: SideContentState; }; export type StoriesAuthState = { diff --git a/src/index.tsx b/src/index.tsx index 4439095cb2..a88fc19943 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,7 +2,7 @@ import 'src/styles/index.scss'; import { Button } from '@blueprintjs/core'; import * as Sentry from '@sentry/browser'; -import { setModulesStaticURL } from 'js-slang/dist/modules/moduleLoader'; +import { setModulesStaticURL } from 'js-slang/dist/modules/loader/moduleLoader'; import { createRoot } from 'react-dom/client'; import { Provider } from 'react-redux'; import Constants, { Links } from 'src/commons/utils/Constants'; diff --git a/yarn.lock b/yarn.lock index 03896564ba..996cf74327 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8305,10 +8305,10 @@ js-sdsl@4.3.0, js-sdsl@^4.1.4: resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.3.0.tgz#aeefe32a451f7af88425b11fdb5f58c90ae1d711" integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ== -js-slang@^1.0.51: - version "1.0.51" - resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.51.tgz#254ec52f4db29a8f51276cf681cf2608698337cf" - integrity sha512-UmoWDfcgwxG86s+Q7y9BxU8PcPnyyTs6jgVK77luaGqMy+kDKwwNqajjIOmd3thVOouAj2U1llAjVT1oZtmCLw== +js-slang@^1.0.52: + version "1.0.52" + resolved "https://registry.yarnpkg.com/js-slang/-/js-slang-1.0.52.tgz#f24d504e09842fc6567789b45e8c9fc3a86a38d3" + integrity sha512-Ioe/XQFxAwZpDGNsg8MDKbC/0CvLXN+0mwhKrtm2jq6PHGa9oldZqykZZAlPYdC5XifI3DktKrRmuc94AIiKfA== dependencies: "@babel/parser" "^7.19.4" "@joeychenofficial/alt-ergo-modified" "^2.4.0"