Skip to content

Commit

Permalink
create a <script> with the transpiled code and insert it to the DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamjan committed Dec 31, 2023
1 parent 34e6375 commit 5e80278
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ function save(editor) {
*
*/
async function runCode() {

const worker = await monaco.languages.typescript.getTypeScriptWorker();
const client = await worker();
const output = await client.getEmitOutput("file:///example.ts");
const js = output.outputFiles[0].text;

createModule(js, '#console-output');

const outputElement = document.querySelector('#console-output');
outputElement.innerText = js;
outputElement.scrollTo({ top: outputElement.scrollHeight });
}

Expand All @@ -91,9 +91,9 @@ function createModule(code, consoleSelector) {
newModule.textContent = `
const console = { log: (msg) => {
const el = document.querySelector('${consoleSelector}');
el.innerText += msg + '\n';
el.innerText += JSON.stringify(msg) + '\\n';
el.scrollTo({top: el.scrollHeight});
}}
}};
`;
newModule.textContent += code;
if (oldModule) {
Expand Down

0 comments on commit 5e80278

Please sign in to comment.