Skip to content

Commit 953e473

Browse files
committed
Fix playground not working after dependency upgrades
1 parent 89597e2 commit 953e473

File tree

6 files changed

+104
-112
lines changed

6 files changed

+104
-112
lines changed

src/landing/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@ import { configure, highlightBlock } from "highlight.js";
55

66
configure({ languages: ["typescript", "lua"] });
77

8-
document.addEventListener("DOMContentLoaded", () => {
9-
let codeBlocks = document.getElementsByClassName("example-item");
10-
for (let i = 0; i < codeBlocks.length; i++) {
11-
highlightBlock(codeBlocks[i]);
12-
}
13-
});
8+
document.querySelectorAll(".example-item").forEach(highlightBlock);

src/landing/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = merge(common, {
1010
new HtmlWebpackPlugin({
1111
title: "TypeScriptToLua",
1212
template: path.resolve(__dirname, "../../assets/layout/template.html"),
13-
inject: "head",
1413
filename: "index.html",
1514
contentFile: "landing.html",
1615
}),

src/playground/index.ts

Lines changed: 100 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@ import * as tstl from "typescript-to-lua/dist/LuaAST";
1313
const renderjson = require("renderjson");
1414
const tstlPackageJson = require("typescript-to-lua/package.json");
1515

16-
document.addEventListener("DOMContentLoaded", () => {
17-
const container = document.getElementById("editor-ts");
18-
const outputTerminalHeader = document.getElementById("editor-output-terminal-header");
19-
const outputTerminalContent = document.getElementById("editor-output-terminal-content");
20-
const exampleLua = document.getElementById("editor-lua");
21-
const astLua = document.getElementById("editor-lua-ast");
22-
23-
// Set tstl version
24-
outputTerminalHeader!.textContent = `TypescriptToLua version ${tstlPackageJson.version}`;
25-
26-
// Layout stuff
27-
const luaTabText = document.getElementById("lua-tab-text") as HTMLDivElement | null;
28-
const luaTabAst = document.getElementById("lua-tab-ast") as HTMLDivElement | null;
29-
if (luaTabText && luaTabAst && exampleLua && astLua) {
30-
const tabOnclick = () => {
31-
luaTabText.classList.toggle("lua-tab-active");
32-
luaTabAst.classList.toggle("lua-tab-active");
33-
exampleLua.classList.toggle("editor-lua-active");
34-
astLua.classList.toggle("editor-lua-active");
35-
};
36-
luaTabText.onclick = tabOnclick;
37-
luaTabAst.onclick = tabOnclick;
38-
}
16+
const container = document.getElementById("editor-ts");
17+
const outputTerminalHeader = document.getElementById("editor-output-terminal-header");
18+
const outputTerminalContent = document.getElementById("editor-output-terminal-content");
19+
const exampleLua = document.getElementById("editor-lua");
20+
const astLua = document.getElementById("editor-lua-ast");
21+
22+
// Set tstl version
23+
outputTerminalHeader!.textContent = `TypescriptToLua version ${tstlPackageJson.version}`;
24+
25+
// Layout stuff
26+
const luaTabText = document.getElementById("lua-tab-text") as HTMLDivElement | null;
27+
const luaTabAst = document.getElementById("lua-tab-ast") as HTMLDivElement | null;
28+
if (luaTabText && luaTabAst && exampleLua && astLua) {
29+
const tabOnclick = () => {
30+
luaTabText.classList.toggle("lua-tab-active");
31+
luaTabAst.classList.toggle("lua-tab-active");
32+
exampleLua.classList.toggle("editor-lua-active");
33+
astLua.classList.toggle("editor-lua-active");
34+
};
35+
luaTabText.onclick = tabOnclick;
36+
luaTabAst.onclick = tabOnclick;
37+
}
3938

40-
// Actual editor and transpilation
41-
let example = `/** @noSelfInFile */
39+
// Actual editor and transpilation
40+
let example = `/** @noSelfInFile */
4241
4342
// Declare exposed API
4443
type Vector = [number, number, number];
@@ -68,81 +67,80 @@ function onSpellStart(event: OnSpellStartEvent): void {
6867
}
6968
}`;
7069

71-
var queryStringSrcStart = window.location.hash.indexOf("#src=");
72-
if (queryStringSrcStart == 0) {
73-
var encoded = window.location.hash.substring("#src=".length);
74-
example = decodeURIComponent(encoded);
75-
}
70+
var queryStringSrcStart = window.location.hash.indexOf("#src=");
71+
if (queryStringSrcStart == 0) {
72+
var encoded = window.location.hash.substring("#src=".length);
73+
example = decodeURIComponent(encoded);
74+
}
7675

77-
if (container && exampleLua && astLua) {
78-
let tsEditor = editor.create(container, {
79-
value: example,
80-
language: "typescript",
81-
minimap: { enabled: false },
82-
theme: "vs-dark",
83-
});
84-
85-
let luaEditor = editor.create(exampleLua, {
86-
value: "",
87-
language: "lua",
88-
minimap: { enabled: false },
89-
theme: "vs-dark",
90-
readOnly: true,
91-
});
92-
93-
window.onresize = () => {
94-
tsEditor.layout();
95-
luaEditor.layout();
96-
};
97-
98-
const tstlWorker = new (TSTLWorker as any)();
99-
tstlWorker.postMessage({ tsStr: tsEditor.getValue() });
100-
101-
let timerVar: any;
102-
let ignoreHashChange = false;
103-
104-
tsEditor.onDidChangeModelContent(e => {
105-
clearInterval(timerVar);
106-
// wait one second before submitting work
107-
timerVar = setTimeout(() => {
108-
tstlWorker.postMessage({ tsStr: tsEditor.getValue() });
109-
window.location.replace("#src=" + encodeURIComponent(tsEditor.getValue()));
110-
ignoreHashChange = true;
111-
}, 500);
112-
});
113-
114-
window.onhashchange = () => {
115-
if (ignoreHashChange) {
116-
ignoreHashChange = false;
117-
return;
118-
}
119-
};
120-
121-
const fengariWorker = new (FengariWorker as any)();
122-
123-
tstlWorker.onmessage = (event: MessageEvent) => {
124-
if (event.data.luaStr) {
125-
luaEditor.setValue(event.data.luaStr);
126-
127-
astLua.innerText = "";
128-
astLua.appendChild(
129-
renderjson.set_show_to_level(1).set_replacer((name: string, val: any) => {
130-
if (name === "kind") {
131-
return tstl.SyntaxKind[val];
132-
}
133-
return val;
134-
})(event.data.luaAST),
135-
);
136-
fengariWorker.postMessage({ luaStr: event.data.luaStr });
137-
} else {
138-
luaEditor.setValue(event.data.diagnostics);
139-
}
140-
};
141-
142-
fengariWorker.onmessage = (event: MessageEvent) => {
143-
if (outputTerminalContent) {
144-
outputTerminalContent.innerText = event.data.luaPrint;
145-
}
146-
};
147-
}
148-
});
76+
if (container && exampleLua && astLua) {
77+
let tsEditor = editor.create(container, {
78+
value: example,
79+
language: "typescript",
80+
minimap: { enabled: false },
81+
theme: "vs-dark",
82+
});
83+
84+
let luaEditor = editor.create(exampleLua, {
85+
value: "",
86+
language: "lua",
87+
minimap: { enabled: false },
88+
theme: "vs-dark",
89+
readOnly: true,
90+
});
91+
92+
window.onresize = () => {
93+
tsEditor.layout();
94+
luaEditor.layout();
95+
};
96+
97+
const tstlWorker = new (TSTLWorker as any)();
98+
tstlWorker.postMessage({ tsStr: tsEditor.getValue() });
99+
100+
let timerVar: any;
101+
let ignoreHashChange = false;
102+
103+
tsEditor.onDidChangeModelContent(e => {
104+
clearInterval(timerVar);
105+
// wait one second before submitting work
106+
timerVar = setTimeout(() => {
107+
tstlWorker.postMessage({ tsStr: tsEditor.getValue() });
108+
window.location.replace("#src=" + encodeURIComponent(tsEditor.getValue()));
109+
ignoreHashChange = true;
110+
}, 500);
111+
});
112+
113+
window.onhashchange = () => {
114+
if (ignoreHashChange) {
115+
ignoreHashChange = false;
116+
return;
117+
}
118+
};
119+
120+
const fengariWorker = new (FengariWorker as any)();
121+
122+
tstlWorker.onmessage = (event: MessageEvent) => {
123+
if (event.data.luaStr) {
124+
luaEditor.setValue(event.data.luaStr);
125+
126+
astLua.innerText = "";
127+
astLua.appendChild(
128+
renderjson.set_show_to_level(1).set_replacer((name: string, val: any) => {
129+
if (name === "kind") {
130+
return tstl.SyntaxKind[val];
131+
}
132+
return val;
133+
})(event.data.luaAST),
134+
);
135+
fengariWorker.postMessage({ luaStr: event.data.luaStr });
136+
} else {
137+
luaEditor.setValue(event.data.diagnostics);
138+
}
139+
};
140+
141+
fengariWorker.onmessage = (event: MessageEvent) => {
142+
if (outputTerminalContent) {
143+
outputTerminalContent.innerText = event.data.luaPrint;
144+
}
145+
};
146+
}

src/playground/tstlWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function transpileString(
4141
if (filename.startsWith("lib.") && filename.endsWith(".d.ts")) {
4242
return ts.createSourceFile(
4343
filename,
44-
require(`!raw-loader!../../node_modules/typescript/lib/lib.${filename.slice(4)}`),
44+
require(`!raw-loader!../../node_modules/typescript/lib/lib.${filename.slice(4)}`).default,
4545
ts.ScriptTarget.Latest,
4646
false,
4747
);
@@ -59,7 +59,7 @@ function transpileString(
5959
const emitHost = {
6060
readFile: (fileName: string) => {
6161
let featureName = fileName.replace("/dist/lualib/", "").replace(".lua", "");
62-
return require(`raw-loader!../../node_modules/typescript-to-lua/dist/lualib/${featureName}.lua`);
62+
return require(`raw-loader!../../node_modules/typescript-to-lua/dist/lualib/${featureName}.lua`).default;
6363
},
6464
getCurrentDirectory: () => ".",
6565
};

src/playground/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module.exports = merge(common, {
3131
new HtmlWebpackPlugin({
3232
title: "TypeScriptToLua - Online Compiler",
3333
template: path.resolve(__dirname, "../../assets/layout/template.html"),
34-
inject: "head",
3534
filename: "play.html",
3635
contentFile: "play.html",
3736
}),

src/webpack.common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212
loader: "url-loader",
1313
options: { esModule: false, name: "[path][name].[ext]?hash=[hash:20]", limit: 8192 },
1414
},
15+
{ test: /\.ttf$/, loader: "file-loader" },
1516
{ test: /\.scss$/, use: ["style-loader", "css-loader", "sass-loader"] },
1617
{ test: /\.webmanifest?$/, loader: "file-loader", options: { esModule: false } },
1718
],

0 commit comments

Comments
 (0)