@defold-typescript/transpiler 0.35.0 → 0.36.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.
@@ -2,5 +2,6 @@ import * as ts from "typescript";
2
2
  import { type Plugin } from "typescript-to-lua";
3
3
  export declare const FACTORY_MODULE = "@defold-typescript/types";
4
4
  export declare const FACTORY_NAMES: Set<string>;
5
+ export declare function resolvesToFactoryExport(callee: ts.Expression, checker: ts.TypeChecker): boolean;
5
6
  export declare function isFactoryOnlyImport(node: ts.ImportDeclaration): boolean;
6
7
  export declare const lifecycleErasurePlugin: Plugin;
@@ -0,0 +1,17 @@
1
+ export interface EmittedRequireSite {
2
+ /** The module path the require names. */
3
+ readonly path: string;
4
+ /** Offset of the argument literal's opening delimiter in the chunk. */
5
+ readonly start: number;
6
+ /** Offset one past its closing delimiter. */
7
+ readonly end: number;
8
+ }
9
+ /**
10
+ * Every code-position `require` of a string literal in an emitted Lua chunk, in
11
+ * source order, with the span of the literal that names it. One scanner for both
12
+ * readers — the resolution check that reports a require and the rewriter that
13
+ * repoints one — so the two can never disagree about what counts as a require.
14
+ * A require whose argument is not a single string literal names no module the
15
+ * build owns and yields no site.
16
+ */
17
+ export declare function scanEmittedRequires(lua: string): EmittedRequireSite[];
@@ -8,4 +8,13 @@ export declare const DEFAULT_INCLUDE: string[];
8
8
  export declare const SCRIPT_SUFFIX_BY_KIND: Record<ScriptKind, string>;
9
9
  export declare function parseBuildConfig(raw: string): BuildConfig;
10
10
  export declare function stripIncludeBase(pattern: string): string;
11
+ /**
12
+ * The `require` path Lua reaches a rel by, mirroring the segment math TSTL
13
+ * applies when it emits one: the extension comes off the last segment, then
14
+ * every remaining `.` becomes `_` *within* a segment, because Lua reads a dot as
15
+ * a path separator and `src/foo.bar.lua` would otherwise be unreachable as
16
+ * `require("src.foo.bar")`. Both sides of the resolution check key through this,
17
+ * so a require and the output meant to satisfy it cannot be spelled differently.
18
+ */
19
+ export declare function requirePathForRel(rel: string): string;
11
20
  export declare function computeOutputRel(rel: string, config: BuildConfig, kind: SourceOutputKind): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Repoint every code-position `require` whose module path `rewrites` maps, and
3
+ * leave the chunk byte-identical everywhere else.
4
+ *
5
+ * Built in one pass over the spans the shared scanner reports rather than by
6
+ * iterated replacement: a chunk is rewritten against the map it was scanned
7
+ * with, so a mapped value that is itself a key is never re-entered, and two
8
+ * paths sharing a prefix cannot bleed into each other. The generated runtimes
9
+ * are rewritten like any other require — unlike the resolution check, which
10
+ * exempts them, the rewriter has to move them when the build writes them under
11
+ * an `outDir`.
12
+ */
13
+ export declare function rewriteEmittedRequires(lua: string, rewrites: ReadonlyMap<string, string>): string;
@@ -1,4 +1,4 @@
1
1
  import * as ts from "typescript";
2
- import type { Plugin } from "typescript-to-lua";
2
+ import { type Plugin } from "typescript-to-lua";
3
3
  export declare function importsTimersModule(sourceFile: ts.SourceFile): boolean;
4
4
  export declare const timersLoweringPlugin: Plugin;
@@ -18,6 +18,7 @@ export interface TranspileProjectResult {
18
18
  readonly lua: Readonly<Record<string, string>>;
19
19
  readonly sourceMaps: Readonly<Record<string, string>>;
20
20
  readonly diagnostics: readonly TranspileDiagnostic[];
21
+ readonly companions?: Readonly<Record<string, string>>;
21
22
  readonly lualib?: string;
22
23
  readonly timersRuntime?: string;
23
24
  }
@@ -28,7 +29,7 @@ interface CollectableFile {
28
29
  readonly lua?: string;
29
30
  readonly luaSourceMap?: string;
30
31
  }
31
- export declare function collectOutputs(transpiledFiles: readonly CollectableFile[], diagnostics: readonly ts.Diagnostic[], userKeys: ReadonlySet<string>): TranspileProjectResult;
32
+ export declare function collectOutputs(transpiledFiles: readonly CollectableFile[], diagnostics: readonly ts.Diagnostic[], userKeys: ReadonlySet<string>, emittedCompanions?: ReadonlyMap<string, string>): TranspileProjectResult;
32
33
  export declare function transpileProject(input: TranspileProjectInput): TranspileProjectResult;
33
34
  export declare function transpile(source: string): TranspileResult;
34
35
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/transpiler",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "TypeScript-to-Lua build pipeline tuned for Defold's runtime.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "test": "bun test"
36
36
  },
37
37
  "dependencies": {
38
- "@defold-typescript/types": "0.35.0",
38
+ "@defold-typescript/types": "0.36.0",
39
39
  "@typescript-to-lua/language-extensions": "1.19.0",
40
40
  "typescript-to-lua": "^1.36.0"
41
41
  }