@defold-typescript/transpiler 0.51.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/companion-closure.d.ts +7 -0
- package/dist/debug-bootstrap.d.ts +21 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +488 -242
- package/dist/lifecycle-erasure.d.ts +1 -0
- package/dist/transpile.d.ts +3 -0
- package/package.json +5 -2
- package/src/companion-closure.ts +28 -6
- package/src/companion-emit.ts +35 -4
- package/src/debug-bootstrap.ts +88 -0
- package/src/hsm-builtin.ts +2 -2
- package/src/index.ts +8 -0
- package/src/lifecycle-erasure.ts +233 -8
- package/src/timers-runtime.ts +2 -2
- package/src/transpile.ts +48 -12
package/src/transpile.ts
CHANGED
|
@@ -63,23 +63,27 @@ export interface TranspileProjectResult {
|
|
|
63
63
|
// TSTL synthesizes this bundle (no user source) whenever a lualib feature is
|
|
64
64
|
// registered — either by a user source using one (`Object.keys`, spread,
|
|
65
65
|
// `__TS__TypeOf`, ...) or by the timers import lowering, whose generated
|
|
66
|
-
// runtime requires the bundle. The emitted `require("lualib_bundle")`
|
|
67
|
-
//
|
|
66
|
+
// runtime requires the bundle. The emitted `require("lualib_bundle")` is an
|
|
67
|
+
// internal name the CLI respells to where it writes the bundle. Absent when
|
|
68
68
|
// neither trigger fires.
|
|
69
69
|
readonly lualib?: string;
|
|
70
70
|
// Hand-authored runtime Lua for the `@defold-typescript/types/timers`
|
|
71
71
|
// polyfills (`setTimeout`/`wait`/...). Unlike `defineScript`, the import is
|
|
72
|
-
// not erased — it lowers to `require("defold_typescript_timers")`,
|
|
73
|
-
//
|
|
74
|
-
// the module (pay-for-use).
|
|
72
|
+
// not erased — it lowers to `require("defold_typescript_timers")`, an
|
|
73
|
+
// internal name the CLI respells to where it writes this. Present only when
|
|
74
|
+
// a user file imports the module (pay-for-use).
|
|
75
75
|
readonly timersRuntime?: string;
|
|
76
76
|
// The compiled `hsm` modules the program requires, keyed by module name
|
|
77
77
|
// (`index`, `defold`, ...). An hsm import lowers to
|
|
78
|
-
// `require("defold_typescript_hsm.<module>")`,
|
|
79
|
-
//
|
|
80
|
-
// (pay-for-use)
|
|
81
|
-
// at is not in the user's project.
|
|
78
|
+
// `require("defold_typescript_hsm.<module>")`, an internal name the CLI
|
|
79
|
+
// respells to where it writes each one. Present only when some chunk requires one
|
|
80
|
+
// (pay-for-use).
|
|
82
81
|
readonly hsmModules?: Readonly<Record<string, string>>;
|
|
82
|
+
// The source map of each module in `hsmModules`, under the same keys. Its
|
|
83
|
+
// `sources` names `<module>.ts` with an empty `sourceRoot`: only the CLI knows
|
|
84
|
+
// where the module is written and where the hsm source sits, so it sets the
|
|
85
|
+
// root that joins them.
|
|
86
|
+
readonly hsmSourceMaps?: Readonly<Record<string, string>>;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
function flattenDiagnosticMessage(
|
|
@@ -313,6 +317,7 @@ export function collectOutputs(
|
|
|
313
317
|
}
|
|
314
318
|
|
|
315
319
|
const hsm = hsmClosure([...Object.values(lua), ...Object.values(companions)], compileHsmModules);
|
|
320
|
+
const hsmSourceMaps = hsm === undefined ? undefined : selectHsmSourceMaps(Object.keys(hsm));
|
|
316
321
|
|
|
317
322
|
return {
|
|
318
323
|
lua,
|
|
@@ -322,9 +327,22 @@ export function collectOutputs(
|
|
|
322
327
|
...(lualib !== undefined ? { lualib } : {}),
|
|
323
328
|
...(timersImported ? { timersRuntime: TIMERS_RUNTIME } : {}),
|
|
324
329
|
...(hsm !== undefined ? { hsmModules: hsm } : {}),
|
|
330
|
+
...(hsmSourceMaps !== undefined ? { hsmSourceMaps } : {}),
|
|
325
331
|
};
|
|
326
332
|
}
|
|
327
333
|
|
|
334
|
+
function selectHsmSourceMaps(names: readonly string[]): Record<string, string> {
|
|
335
|
+
const maps = compileHsmSourceMaps();
|
|
336
|
+
const selected: Record<string, string> = {};
|
|
337
|
+
for (const name of names) {
|
|
338
|
+
const map = maps[name];
|
|
339
|
+
if (map !== undefined) {
|
|
340
|
+
selected[name] = map;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return selected;
|
|
344
|
+
}
|
|
345
|
+
|
|
328
346
|
function transpileVirtual(
|
|
329
347
|
files: Readonly<Record<string, string>>,
|
|
330
348
|
companionEmit: ReturnType<typeof createCompanionEmitPlugin>,
|
|
@@ -382,7 +400,12 @@ export function transpileProject(input: TranspileProjectInput): TranspileProject
|
|
|
382
400
|
);
|
|
383
401
|
}
|
|
384
402
|
|
|
385
|
-
|
|
403
|
+
interface CompiledHsm {
|
|
404
|
+
readonly lua: Readonly<Record<string, string>>;
|
|
405
|
+
readonly sourceMaps: Readonly<Record<string, string>>;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let compiledHsm: CompiledHsm | undefined;
|
|
386
409
|
|
|
387
410
|
function requiresLualib(lua: string): boolean {
|
|
388
411
|
return scanEmittedRequires(lua).some(({ path: requirePath }) => requirePath === "lualib_bundle");
|
|
@@ -398,6 +421,15 @@ function requiresLualib(lua: string): boolean {
|
|
|
398
421
|
* lualib bundle.
|
|
399
422
|
*/
|
|
400
423
|
export function compileHsmModules(): Readonly<Record<string, string>> {
|
|
424
|
+
return compileHsm().lua;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** The source map of every module `compileHsmModules` returns, under the same keys. */
|
|
428
|
+
export function compileHsmSourceMaps(): Readonly<Record<string, string>> {
|
|
429
|
+
return compileHsm().sourceMaps;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function compileHsm(): CompiledHsm {
|
|
401
433
|
if (compiledHsm !== undefined) {
|
|
402
434
|
return compiledHsm;
|
|
403
435
|
}
|
|
@@ -417,6 +449,7 @@ export function compileHsmModules(): Readonly<Record<string, string>> {
|
|
|
417
449
|
(d) => `${d.file?.fileName ?? "(project)"}: ${flattenDiagnosticMessage(d.messageText)}`,
|
|
418
450
|
);
|
|
419
451
|
const lua: Record<string, string> = {};
|
|
452
|
+
const sourceMaps: Record<string, string> = {};
|
|
420
453
|
for (const file of result.transpiledFiles) {
|
|
421
454
|
if (isLualibBundle(file)) {
|
|
422
455
|
continue;
|
|
@@ -430,14 +463,17 @@ export function compileHsmModules(): Readonly<Record<string, string>> {
|
|
|
430
463
|
problems.push(`the compiled ${name} module requires lualib_bundle`);
|
|
431
464
|
}
|
|
432
465
|
lua[name] = file.lua;
|
|
466
|
+
if (typeof file.luaSourceMap === "string") {
|
|
467
|
+
sourceMaps[name] = file.luaSourceMap;
|
|
468
|
+
}
|
|
433
469
|
}
|
|
434
470
|
if (problems.length > 0) {
|
|
435
471
|
throw new Error(
|
|
436
472
|
`@defold-typescript/transpiler: the hsm library does not compile:\n ${problems.join("\n ")}`,
|
|
437
473
|
);
|
|
438
474
|
}
|
|
439
|
-
compiledHsm = lua;
|
|
440
|
-
return
|
|
475
|
+
compiledHsm = { lua, sourceMaps };
|
|
476
|
+
return compiledHsm;
|
|
441
477
|
}
|
|
442
478
|
|
|
443
479
|
export function transpile(source: string): TranspileResult {
|