Skip to content

Commit cdad769

Browse files
author
Orta Therox
authored
Merge pull request microsoft#2027 from microsoft/fix_js_run
Fixes running the JS when writing JavaScript
2 parents b6c339b + f75ba9a commit cdad769

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/sandbox/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ export type SandboxConfig = {
4646
groupEnd: (...args: any[]) => void
4747
}
4848
} & (
49-
| { /** theID of a dom node to add monaco to */ domID: string }
50-
| { /** theID of a dom node to add monaco to */ elementToAppend: HTMLElement }
51-
)
49+
| { /** theID of a dom node to add monaco to */ domID: string }
50+
| { /** theID of a dom node to add monaco to */ elementToAppend: HTMLElement }
51+
)
5252

5353
const languageType = (config: SandboxConfig) => (config.filetype === "js" ? "javascript" : "typescript")
5454

@@ -192,7 +192,6 @@ export const createTypeScriptSandbox = (
192192

193193
if (config.supportTwoslashCompilerOptions) {
194194
const configOpts = getTwoSlashCompilerOptions(code)
195-
console.log("twoslash", configOpts)
196195
updateCompilerSettings(configOpts)
197196
}
198197

@@ -216,7 +215,7 @@ export const createTypeScriptSandbox = (
216215
defaults.setCompilerOptions(compilerOptions)
217216

218217
// To let clients plug into compiler settings changes
219-
let didUpdateCompilerSettings = (opts: CompilerOptions) => {}
218+
let didUpdateCompilerSettings = (opts: CompilerOptions) => { }
220219

221220
const updateCompilerSettings = (opts: CompilerOptions) => {
222221
const newKeys = Object.keys(opts)
@@ -262,13 +261,19 @@ export const createTypeScriptSandbox = (
262261
/** Gets the results of compiling your editor's code */
263262
const getEmitResult = async () => {
264263
const model = editor.getModel()!
265-
266264
const client = await getWorkerProcess()
267265
return await client.getEmitOutput(model.uri.toString())
268266
}
269267

270268
/** Gets the JS of compiling your editor's code */
271269
const getRunnableJS = async () => {
270+
// This isn't quite _right_ in theory, we can downlevel JS -> JS
271+
// but a browser is basically always esnext-y and setting allowJs and
272+
// checkJs does not actually give the downlevel'd .js file in the output
273+
// later down the line.
274+
if (isJSLang) {
275+
return getText()
276+
}
272277
const result = await getEmitResult()
273278
const firstJS = result.outputFiles.find((o: any) => o.name.endsWith(".js") || o.name.endsWith(".jsx"))
274279
return (firstJS && firstJS.text) || ""

0 commit comments

Comments
 (0)