-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use microverse-library version 0.7.7
- Loading branch information
1 parent
3fec4a4
commit a75e619
Showing
7 changed files
with
112 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16226,23 +16226,18 @@ function checkModule(module) { | |
}); | ||
} | ||
|
||
function compileToModule(text, path) { | ||
async function compileToModule(text, path) { | ||
let language = path.endsWith(".ts") ? "ts" : "js"; | ||
|
||
let jsCompiler; | ||
let tsCompiler; | ||
|
||
if (!jsCompiler) { | ||
jsCompiler = new _compiler_js__WEBPACK_IMPORTED_MODULE_4__.JSCompiler(); | ||
} | ||
|
||
let js = jsCompiler.compile(text, path); | ||
jsCompiler = new _compiler_js__WEBPACK_IMPORTED_MODULE_4__.JSCompiler(); | ||
let js = await jsCompiler.compile(text, path); | ||
|
||
if (language === "ts") { | ||
if (!tsCompiler) { | ||
tsCompiler = new _compiler_js__WEBPACK_IMPORTED_MODULE_4__.TSCompiler(); | ||
} | ||
js = tsCompiler.compile(js, path); | ||
tsCompiler = new _compiler_js__WEBPACK_IMPORTED_MODULE_4__.TSCompiler(); | ||
js = await tsCompiler.compile(js, path); | ||
} | ||
|
||
let dataURL = URL.createObjectURL(new Blob([js], {type: "application/javascript"})); | ||
|
@@ -16269,23 +16264,31 @@ __webpack_require__.r(__webpack_exports__); | |
/* harmony export */ TSCompiler: () => (/* binding */ TSCompiler) | ||
/* harmony export */ }); | ||
class TSCompiler { | ||
constructor() { | ||
if (!window.ts) {return;} | ||
async compile(tsCode, location) { | ||
if (!window.tsPromise) { | ||
window.tsPromise = new Promise((resolve, _reject) => { | ||
let script = document.createElement("script"); | ||
script.src = "https://cdn.jsdelivr.net/npm/[email protected]/lib/typescript.min.js"; | ||
script.onload = resolve; | ||
script.type = "text/javascript"; | ||
document.head.appendChild(script); | ||
}); | ||
} | ||
|
||
await window.tsPromise; | ||
if (!window.ts) {return tsCode;} | ||
this.options = { | ||
module: ts.ModuleKind.ESNext, | ||
target: ts.ScriptTarget.ESNext, | ||
module: window.ts.ModuleKind.ESNext, | ||
target: window.ts.ScriptTarget.ESNext, | ||
noResolve: true, | ||
}; | ||
this.compilerHost = this.createCompilerHost(); | ||
} | ||
|
||
compile(tsCode, location) { | ||
if (!window.ts) {return tsCode;} | ||
this.compilerHost = this.createCompilerHost(); | ||
this.sources = new Map([[location, tsCode]]); | ||
this.results = new Map(); | ||
|
||
let program = ts.createProgram([location], this.options, this.compilerHost); | ||
let result = program.emit(); | ||
let program = window.ts.createProgram([location], this.options, this.compilerHost); | ||
let _result = program.emit(); | ||
|
||
let compiledName = location.replace(/\.ts$/, ".js"); | ||
|
||
|
@@ -16299,7 +16302,7 @@ class TSCompiler { | |
getSourceFile(fileName, languageVersion, _onError) { | ||
const sourceText = this.readFile(fileName); | ||
return sourceText !== undefined | ||
? ts.createSourceFile(fileName, sourceText, languageVersion) | ||
? window.ts.createSourceFile(fileName, sourceText, languageVersion) | ||
: undefined; | ||
} | ||
|
||
|
@@ -16319,7 +16322,7 @@ class TSCompiler { | |
createCompilerHost() { | ||
return { | ||
getSourceFile: this.getSourceFile, | ||
getDefaultLibFileName: (defaultLibOptions) => "/" + ts.getDefaultLibFileName(defaultLibOptions), | ||
getDefaultLibFileName: (defaultLibOptions) => "/" + window.ts.getDefaultLibFileName(defaultLibOptions), | ||
writeFile: (fileName, content) => this.writeFile(fileName, content), | ||
getCurrentDirectory: () => "/", | ||
getDirectories: (_path) => [], | ||
|
@@ -16336,31 +16339,28 @@ class TSCompiler { | |
|
||
class JSCompiler { | ||
compile(jsCode, _location) { | ||
console.log(_location); | ||
let result = []; | ||
|
||
let codeArray = jsCode.split("\n"); | ||
|
||
for (let i = 0; i < codeArray.length; i++) { | ||
let line = codeArray[i]; | ||
if (/^import/.test(line)) { | ||
result.push(""); | ||
result.push(line[line.length - 1] === "\r" ? "\r" : ""); | ||
continue; | ||
} | ||
let test = /^class(\s+)(\S+)\s+extends\s(ActorBehavior|PawnBehavior)(.*)\r?$/.exec(line) | ||
let test = /^\s*class(\s+)(\S+)\s+extends\s(ActorBehavior|PawnBehavior)(.*)(\r?)$/.exec(line); | ||
if (test) { | ||
let newLine = `class${test[1]}${test[2]}${test[4]}`; | ||
let newLine = `class${test[1]}${test[2]}${test[4]}${test[5]}`; | ||
result.push(newLine); | ||
continue; | ||
} | ||
result.push(line); | ||
} | ||
return result.join("\n"); | ||
return Promise.resolve(result.join("\n")); | ||
} | ||
} | ||
|
||
/* globals ts*/ | ||
|
||
|
||
/***/ }), | ||
|
||
|
@@ -117005,4 +117005,4 @@ start(); | |
})(); | ||
|
||
/******/ })() | ||
; | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
commit: 9e5d9a864611fc44571357e957a1dc3e58fc25fb Date: Tue Aug 29 16:59:08 2023 -0700 | ||
commit: ae0c614f57c1bf578c1b807f26080dbb5445b86e Date: Fri Sep 1 13:19:23 2023 -0700 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ export async function prelude() { | |
let css = document.createElement("link"); | ||
css.rel = "stylesheet"; | ||
css.type = "text/css"; | ||
css. | ||
css.id = "joystick-css"; | ||
css.onload = resolve; | ||
css.href = "/assets/css/joystick.css"; | ||
|
@@ -60,13 +59,5 @@ export async function prelude() { | |
Promise like the one above. | ||
*/ | ||
|
||
await new Promise((resolve, reject) => { | ||
let script = document.createElement("script"); | ||
script.src = "https://cdn.jsdelivr.net/npm/[email protected]/lib/typescript.min.js"; | ||
script.onload = resolve; | ||
script.type = "text/javascript"; | ||
document.head.appendChild(script); | ||
}); | ||
|
||
return null; | ||
} |