Skip to content

Commit 8133853

Browse files
HubertYjakebailey
andauthored
Fix DOM element check (#2928)
Co-authored-by: Jake Bailey <[email protected]>
1 parent fdef7b5 commit 8133853

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

packages/playground/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescript/playground",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"main": "dist/index.js",
55
"license": "MIT",
66
"private": true,
@@ -16,7 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@typescript/playground-worker": "0.1.0",
19-
"@typescript/sandbox": "0.1.1",
19+
"@typescript/sandbox": "0.1.2",
2020
"esbuild": "^0.13.4"
2121
},
2222
"devDependencies": {

packages/sandbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescript/sandbox",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"license": "MIT",
55
"author": "TypeScript team",
66
"homepage": "https://github.com/microsoft/TypeScript-Website",

packages/sandbox/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export const createTypeScriptSandbox = (
113113
monaco: Monaco,
114114
ts: typeof import("typescript")
115115
) => {
116-
const config = { ...defaultPlaygroundSettings(), ...partialConfig }
117-
if (!("domID" in config) && !("elementToAppend" in config))
116+
if (!("domID" in partialConfig) && !("elementToAppend" in partialConfig))
118117
throw new Error("You did not provide a domID or elementToAppend")
119118

119+
const config = { ...defaultPlaygroundSettings(), ...partialConfig }
120120
const defaultText = config.suppressAutomaticallyGettingDefaultText
121121
? config.text
122122
: getInitialCode(config.text, document.location)
@@ -144,7 +144,10 @@ export const createTypeScriptSandbox = (
144144

145145
const language = languageType(config)
146146
const filePath = createFileUri(config, compilerOptions, monaco)
147-
const element = (config as any).elementToAppend ? (config as any).elementToAppend : document.getElementById(config.domID)
147+
const element = "elementToAppend" in config ? config.elementToAppend : document.getElementById(config.domID)
148+
if (!element)
149+
throw new Error("DOM element lookup by domID failed")
150+
148151

149152
const model = monaco.editor.createModel(defaultText, language, filePath)
150153
monaco.editor.defineTheme("sandbox", sandboxTheme)

packages/typescriptlang-org/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"@formatjs/intl-relativetimeformat": "^4.5.15",
2424
"@types/node-fetch": "^2.5.3",
2525
"@types/react-helmet": "^5.0.15",
26-
"@typescript/playground": "0.1.1",
27-
"@typescript/sandbox": "0.1.1",
26+
"@typescript/playground": "0.1.2",
27+
"@typescript/sandbox": "0.1.2",
2828
"@typescript/twoslash": "3.2.4",
2929
"gatsby": "^3.8.1",
3030
"gatsby-link": "3.10.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6054,13 +6054,13 @@ __metadata:
60546054
languageName: unknown
60556055
linkType: soft
60566056

6057-
"@typescript/[email protected].1, @typescript/playground@workspace:packages/playground":
6057+
"@typescript/[email protected].2, @typescript/playground@workspace:packages/playground":
60586058
version: 0.0.0-use.local
60596059
resolution: "@typescript/playground@workspace:packages/playground"
60606060
dependencies:
60616061
"@types/jest": ^25.1.3
60626062
"@typescript/playground-worker": 0.1.0
6063-
"@typescript/sandbox": 0.1.1
6063+
"@typescript/sandbox": 0.1.2
60646064
esbuild: ^0.13.4
60656065
jest: ^29.5.0
60666066
monaco-editor: ^0.32.1
@@ -6069,7 +6069,7 @@ __metadata:
60696069
languageName: unknown
60706070
linkType: soft
60716071

6072-
"@typescript/[email protected].1, @typescript/sandbox@workspace:packages/sandbox":
6072+
"@typescript/[email protected].2, @typescript/sandbox@workspace:packages/sandbox":
60736073
version: 0.0.0-use.local
60746074
resolution: "@typescript/sandbox@workspace:packages/sandbox"
60756075
dependencies:
@@ -28857,8 +28857,8 @@ resolve@^2.0.0-next.3:
2885728857
"@types/react": ^16.9.20
2885828858
"@types/react-dom": ^16.9.5
2885928859
"@types/react-helmet": ^5.0.15
28860-
"@typescript/playground": 0.1.1
28861-
"@typescript/sandbox": 0.1.1
28860+
"@typescript/playground": 0.1.2
28861+
"@typescript/sandbox": 0.1.2
2886228862
"@typescript/twoslash": 3.2.4
2886328863
concurrently: ^5.1.0
2886428864
gatsby: ^3.8.1

0 commit comments

Comments
 (0)