Skip to content

Commit

Permalink
get javascript from the typescript worker
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamjan committed Dec 30, 2023
1 parent 82d4f82 commit c842105
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions playground/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,16 @@ function save(editor) {
/**
* Run button handler
*
* @param {MonacoEditor} editor
*/
function runCode(editor) {
const code = editor.getValue();
const outputElement = document.querySelector('#console-output');

try {
const result = ts.transpileModule(code, {
compilerOptions: { target: 'es2022', module: 'es2022', },
reportDiagnostics: true,
});
const transpiledCode = result.outputText
.replace(/^[:space:]*import.*from.*irclog-api.*/, `import {CouchDB} from "./dist/index.js"`)
async function runCode() {

createModule(transpiledCode, '#console-output');
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;

outputElement.innerText = 'Code executed successfully';
} catch (error) {
outputElement.innerText += `Error: ${error.message}\n`;
}
const outputElement = document.querySelector('#console-output');
outputElement.innerText = js;
outputElement.scrollTo({ top: outputElement.scrollHeight });
}

Expand Down

0 comments on commit c842105

Please sign in to comment.