@backtickjs/compiler 0.0.0-stage → 0.1.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -2
  3. package/dist/CodeInformation.d.ts +8 -0
  4. package/dist/CodeInformation.js +2 -0
  5. package/dist/CodeInformation.js.map +1 -0
  6. package/dist/SourceRange.d.ts +4 -0
  7. package/dist/SourceRange.js +2 -0
  8. package/dist/SourceRange.js.map +1 -0
  9. package/dist/buildMappings.d.ts +10 -0
  10. package/dist/buildMappings.js +21 -0
  11. package/dist/buildMappings.js.map +1 -0
  12. package/dist/compileModule.d.ts +25 -0
  13. package/dist/compileModule.js +78 -0
  14. package/dist/compileModule.js.map +1 -0
  15. package/dist/compileScript.d.ts +24 -0
  16. package/dist/compileScript.js +66 -0
  17. package/dist/compileScript.js.map +1 -0
  18. package/dist/diagnostics.d.ts +8 -0
  19. package/dist/diagnostics.js +2 -0
  20. package/dist/diagnostics.js.map +1 -0
  21. package/dist/emitScript.d.ts +52 -0
  22. package/dist/emitScript.js +201 -0
  23. package/dist/emitScript.js.map +1 -0
  24. package/dist/emitScripts.d.ts +10 -0
  25. package/dist/emitScripts.js +23 -0
  26. package/dist/emitScripts.js.map +1 -0
  27. package/dist/flattenScripts.d.ts +2 -0
  28. package/dist/flattenScripts.js +10 -0
  29. package/dist/flattenScripts.js.map +1 -0
  30. package/dist/hashText.d.ts +1 -0
  31. package/dist/hashText.js +18 -0
  32. package/dist/hashText.js.map +1 -0
  33. package/dist/hostElements.d.ts +3 -0
  34. package/dist/hostElements.js +28 -0
  35. package/dist/hostElements.js.map +1 -0
  36. package/dist/index.d.ts +16 -0
  37. package/dist/index.js +10 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/isComponentTag.d.ts +1 -0
  40. package/dist/isComponentTag.js +15 -0
  41. package/dist/isComponentTag.js.map +1 -0
  42. package/dist/nodeFactory.d.ts +3 -0
  43. package/dist/nodeFactory.js +5 -0
  44. package/dist/nodeFactory.js.map +1 -0
  45. package/dist/parseFile.d.ts +34 -0
  46. package/dist/parseFile.js +200 -0
  47. package/dist/parseFile.js.map +1 -0
  48. package/dist/printVirtualCode.d.ts +9 -0
  49. package/dist/printVirtualCode.js +52 -0
  50. package/dist/printVirtualCode.js.map +1 -0
  51. package/dist/resolveBindings.d.ts +76 -0
  52. package/dist/resolveBindings.js +240 -0
  53. package/dist/resolveBindings.js.map +1 -0
  54. package/dist/rewriteFile.d.ts +12 -0
  55. package/dist/rewriteFile.js +22 -0
  56. package/dist/rewriteFile.js.map +1 -0
  57. package/dist/rewriteScript.d.ts +27 -0
  58. package/dist/rewriteScript.js +268 -0
  59. package/dist/rewriteScript.js.map +1 -0
  60. package/dist/segmentsToString.d.ts +9 -0
  61. package/dist/segmentsToString.js +4 -0
  62. package/dist/segmentsToString.js.map +1 -0
  63. package/dist/tagRoot.d.ts +2 -0
  64. package/dist/tagRoot.js +10 -0
  65. package/dist/tagRoot.js.map +1 -0
  66. package/dist/transform.d.ts +17 -0
  67. package/dist/transform.js +61 -0
  68. package/dist/transform.js.map +1 -0
  69. package/dist/transpile.d.ts +27 -0
  70. package/dist/transpile.js +41 -0
  71. package/dist/transpile.js.map +1 -0
  72. package/dist/unmangle.d.ts +2 -0
  73. package/dist/unmangle.js +9 -0
  74. package/dist/unmangle.js.map +1 -0
  75. package/dist/virtualScript.d.ts +22 -0
  76. package/dist/virtualScript.js +305 -0
  77. package/dist/virtualScript.js.map +1 -0
  78. package/dist/virtualize.d.ts +8 -0
  79. package/dist/virtualize.js +10 -0
  80. package/dist/virtualize.js.map +1 -0
  81. package/package.json +58 -3
  82. package/src/CodeInformation.ts +14 -0
  83. package/src/SourceRange.ts +4 -0
  84. package/src/buildMappings.ts +31 -0
  85. package/src/compileModule.ts +132 -0
  86. package/src/compileScript.ts +97 -0
  87. package/src/diagnostics.ts +9 -0
  88. package/src/emitScript.ts +297 -0
  89. package/src/emitScripts.ts +39 -0
  90. package/src/flattenScripts.ts +13 -0
  91. package/src/hashText.ts +17 -0
  92. package/src/hostElements.ts +34 -0
  93. package/src/index.ts +20 -0
  94. package/src/isComponentTag.ts +15 -0
  95. package/src/nodeFactory.ts +18 -0
  96. package/src/parseFile.ts +331 -0
  97. package/src/printVirtualCode.ts +93 -0
  98. package/src/resolveBindings.ts +417 -0
  99. package/src/rewriteFile.ts +52 -0
  100. package/src/rewriteScript.ts +413 -0
  101. package/src/segmentsToString.ts +16 -0
  102. package/src/tagRoot.ts +14 -0
  103. package/src/transform.ts +96 -0
  104. package/src/transpile.ts +49 -0
  105. package/src/unmangle.ts +10 -0
  106. package/src/virtualScript.ts +355 -0
  107. package/src/virtualize.ts +29 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean-François Bisson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,26 @@
1
- # Temporary Holding Version
1
+ # @backtickjs/compiler
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Internal: the compiler for Backtick's client scripts, `` cs`…` ``. You don't install it directly, and its API may change in any release.
4
+
5
+ It finds each script in a source file, resolves its splices, compiles the script for its framework at build time, and writes the virtual code an editor and the type checker see. It is a dependency of `@backtickjs/tsc`, the build plugins (`@backtickjs/node-plugin`, `@backtickjs/bun-plugin`, `@backtickjs/tspatch-plugin`), `@backtickjs/prettier-plugin` and the editor tooling (`@backtickjs/language-service`, `@backtickjs/language-plugin`). Install one of those instead.
6
+
7
+ ## API
8
+
9
+ - `transform`: a TypeScript transformer that replaces each `cs` with its compiled script, running a framework's plugins over it.
10
+ - `compileModule`: compiles one TypeScript file, its scripts included, to an ES module with an inline source map, using the nearest `tsconfig.json`. What the Node and Bun plugins call.
11
+ - `pluginsFrom`: loads the framework plugins a project names in `package.json` (`"backtick": { "plugins": [...] }`).
12
+ - `transpile`: compiles one standalone file with fixed options, for tests and the playground.
13
+ - `parseSourceFile`, `parseSourceText`: find the scripts and splices in a file.
14
+ - `resolveBindings`, `flattenScripts`, `emitScripts`: resolve each script's splices and captures, walk nested scripts, and emit each script's code.
15
+ - `virtualize`: the virtual code that type-checks scripts and their splices.
16
+ - `mangle`, `unmangle`: map names between source and virtual code.
17
+
18
+ ## Related
19
+
20
+ - [`@backtickjs/core`](https://github.com/backtickjs/backtick/tree/main/packages/core): the `cs` tag
21
+ - [`@backtickjs/tsc`](https://github.com/backtickjs/backtick/tree/main/packages/tsc), [`@backtickjs/node-plugin`](https://github.com/backtickjs/backtick/tree/main/packages/node-plugin), [`@backtickjs/bun-plugin`](https://github.com/backtickjs/backtick/tree/main/packages/bun-plugin): packages that use it
22
+ - [Documentation](https://backtickjs.com/docs)
23
+
24
+ ## License
25
+
26
+ MIT
@@ -0,0 +1,8 @@
1
+ export interface CodeInformation {
2
+ semantic: boolean | {
3
+ shouldHighlight(): boolean;
4
+ };
5
+ completion?: boolean;
6
+ navigation?: boolean;
7
+ verification?: boolean;
8
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CodeInformation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeInformation.js","sourceRoot":"","sources":["../src/CodeInformation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export interface SourceRange {
2
+ readonly start: number;
3
+ readonly end: number;
4
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=SourceRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceRange.js","sourceRoot":"","sources":["../src/SourceRange.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { CodeInformation } from "./CodeInformation.js";
2
+ import type { Segment } from "./segmentsToString.js";
3
+ export interface SourceMapping {
4
+ sourceOffsets: number[];
5
+ generatedOffsets: number[];
6
+ lengths: number[];
7
+ generatedLengths: number[];
8
+ data?: CodeInformation;
9
+ }
10
+ export declare function buildMappings(segments: Segment[]): SourceMapping[];
@@ -0,0 +1,21 @@
1
+ export function buildMappings(segments) {
2
+ const mappings = [];
3
+ let generatedOffset = 0;
4
+ for (const segment of segments) {
5
+ if (typeof segment === "string") {
6
+ generatedOffset += segment.length;
7
+ continue;
8
+ }
9
+ const [text, , sourceOffset, sourceLength, data] = segment;
10
+ mappings.push({
11
+ sourceOffsets: [sourceOffset],
12
+ generatedOffsets: [generatedOffset],
13
+ lengths: [sourceLength],
14
+ generatedLengths: [text.length],
15
+ ...(data && { data }),
16
+ });
17
+ generatedOffset += text.length;
18
+ }
19
+ return mappings;
20
+ }
21
+ //# sourceMappingURL=buildMappings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildMappings.js","sourceRoot":"","sources":["../src/buildMappings.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,aAAa,CAAC,QAAmB;IAC/C,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,IAAI,eAAe,GAAG,CAAC,CAAC;IACxB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;YAClC,SAAS;QACX,CAAC;QACD,MAAM,CAAC,IAAI,EAAE,AAAD,EAAG,YAAY,EAAE,YAAY,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC;QAC3D,QAAQ,CAAC,IAAI,CAAC;YACZ,aAAa,EAAE,CAAC,YAAY,CAAC;YAC7B,gBAAgB,EAAE,CAAC,eAAe,CAAC;YACnC,OAAO,EAAE,CAAC,YAAY,CAAC;YACvB,gBAAgB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;YAC/B,GAAG,CAAC,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC;SACtB,CAAC,CAAC;QACH,eAAe,IAAI,IAAI,CAAC,MAAM,CAAC;IACjC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type ts from "typescript";
2
+ import type { Plugin } from "./compileScript.js";
3
+ /**
4
+ * The framework's compile steps a project names in its `package.json`, made
5
+ * with the project's own `require`:
6
+ *
7
+ * ```json
8
+ * "backtick": { "plugins": ["@backtickjs/react/plugin"] }
9
+ * ```
10
+ */
11
+ export declare function pluginsFrom(packageJson: string, require: (specifier: string) => unknown): Plugin[];
12
+ export interface CompileModuleOptions {
13
+ /** The framework's compile steps, as `pluginsFrom` makes them. */
14
+ readonly plugins: readonly Plugin[];
15
+ /** Transforms run after Backtick's, as a runtime needs its own. */
16
+ readonly before?: readonly ts.TransformerFactory<ts.SourceFile>[];
17
+ }
18
+ /**
19
+ * A TypeScript file, its `cs` scripts included, as an ES module with its
20
+ * source map inline, compiled with the `tsconfig.json` nearest it, as `tsc`
21
+ * and editors find one, so an app and its server can each have their own.
22
+ * Throws the compiler's errors: a refused script is emitted with `null` where
23
+ * its code was, so it must not load.
24
+ */
25
+ export declare function compileModule(ts: typeof import("typescript"), fileName: string, source: string, { plugins, before }: CompileModuleOptions): string;
@@ -0,0 +1,78 @@
1
+ import { transform } from "./transform.js";
2
+ /**
3
+ * The framework's compile steps a project names in its `package.json`, made
4
+ * with the project's own `require`:
5
+ *
6
+ * ```json
7
+ * "backtick": { "plugins": ["@backtickjs/react/plugin"] }
8
+ * ```
9
+ */
10
+ export function pluginsFrom(packageJson, require) {
11
+ const { backtick } = JSON.parse(packageJson);
12
+ return (backtick?.plugins ?? []).map((specifier) => require(specifier).default());
13
+ }
14
+ /**
15
+ * A TypeScript file, its `cs` scripts included, as an ES module with its
16
+ * source map inline, compiled with the `tsconfig.json` nearest it, as `tsc`
17
+ * and editors find one, so an app and its server can each have their own.
18
+ * Throws the compiler's errors: a refused script is emitted with `null` where
19
+ * its code was, so it must not load.
20
+ */
21
+ export function compileModule(ts, fileName, source, { plugins, before = [] }) {
22
+ const diagnostics = [];
23
+ const { outputText } = ts.transpileModule(source, {
24
+ fileName,
25
+ compilerOptions: compilerOptionsFor(ts, directoryOf(fileName)),
26
+ transformers: {
27
+ before: [
28
+ transform(ts, (diagnostic) => diagnostics.push(diagnostic), {
29
+ plugins,
30
+ }),
31
+ ...before,
32
+ ],
33
+ },
34
+ });
35
+ const errors = diagnostics.filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error);
36
+ if (errors.length > 0) {
37
+ throw new Error(ts.formatDiagnostics(errors, {
38
+ getCanonicalFileName: (name) => name,
39
+ getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
40
+ getNewLine: () => "\n",
41
+ }));
42
+ }
43
+ return outputText;
44
+ }
45
+ // Read once per config, however many files share it.
46
+ const optionsByConfig = new Map();
47
+ function compilerOptionsFor(ts, directory) {
48
+ const configPath = ts.findConfigFile(directory, ts.sys.fileExists, "tsconfig.json") ?? "";
49
+ let options = optionsByConfig.get(configPath);
50
+ if (options === undefined) {
51
+ let fromConfig = {};
52
+ if (configPath !== "") {
53
+ const { config } = ts.readConfigFile(configPath, ts.sys.readFile);
54
+ // Parsed whole, so `extends` is followed, as `tsc` follows it.
55
+ fromConfig = ts.parseJsonConfigFileContent(config, ts.sys, directoryOf(configPath)).options;
56
+ }
57
+ // Where `tsc` would write its output says nothing about a file compiled
58
+ // where it loads, but a source map written with it names the file relative
59
+ // to that output, and a runtime resolves the name relative to the file.
60
+ const { outDir: _outDir, outFile: _outFile, rootDir: _rootDir, sourceRoot: _sourceRoot, mapRoot: _mapRoot, ...compiling } = fromConfig;
61
+ options = {
62
+ ...compiling,
63
+ module: ts.ModuleKind.ESNext,
64
+ target: ts.ScriptTarget.ESNext,
65
+ sourceMap: false,
66
+ inlineSourceMap: true,
67
+ inlineSources: true,
68
+ };
69
+ optionsByConfig.set(configPath, options);
70
+ }
71
+ return options;
72
+ }
73
+ // A path's directory, by `/` or `\`, without Node's `path`.
74
+ function directoryOf(path) {
75
+ const end = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
76
+ return end === -1 ? "." : path.slice(0, end);
77
+ }
78
+ //# sourceMappingURL=compileModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileModule.js","sourceRoot":"","sources":["../src/compileModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAW3C;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,WAAmB,EACnB,OAAuC;IAEvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAE1C,CAAC;IACF,OAAO,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAChD,OAAO,CAAC,SAAS,CAAkB,CAAC,OAAO,EAAE,CAC/C,CAAC;AACJ,CAAC;AASD;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,EAA+B,EAC/B,QAAgB,E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AAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { EmittedScript } from "./emitScript.js";
2
+ /**
3
+ * A framework's compile step: a module in, the module it compiles to out, with
4
+ * its map into the module it was given. Solid's adapter's `solid()` is one.
5
+ * Synchronous, as a TypeScript transformer is.
6
+ */
7
+ export type Plugin = (code: string, id: string) => {
8
+ code: string;
9
+ map: string;
10
+ };
11
+ /** A script as a build writes it, a module table's entry. */
12
+ export interface CompiledScript extends EmittedScript {
13
+ /** The modules the code requires, by specifier, as Metro records them. */
14
+ readonly dependencies: readonly string[];
15
+ }
16
+ /**
17
+ * A script as a build writes it: the module whose default export it is,
18
+ * through each plugin in turn, then a module table's entry,
19
+ * `(module, exports, require) => { … }`, as webpack and Metro write one: its
20
+ * body the module as CommonJS, JSX kept where no plugin compiled it, the
21
+ * modules it requires its dependencies, its map chained onto the script's own
22
+ * and naming the host file `sourceName`.
23
+ */
24
+ export declare function compileScript(ts: typeof import("typescript"), script: EmittedScript, sourceName: string, plugins: readonly Plugin[]): CompiledScript;
@@ -0,0 +1,66 @@
1
+ import remapping from "@jridgewell/remapping";
2
+ /**
3
+ * A script as a build writes it: the module whose default export it is,
4
+ * through each plugin in turn, then a module table's entry,
5
+ * `(module, exports, require) => { … }`, as webpack and Metro write one: its
6
+ * body the module as CommonJS, JSX kept where no plugin compiled it, the
7
+ * modules it requires its dependencies, its map chained onto the script's own
8
+ * and naming the host file `sourceName`.
9
+ */
10
+ export function compileScript(ts, script, sourceName, plugins) {
11
+ let code = `export default (\n${script.code}\n);`;
12
+ const maps = [down(renamed(script.map, sourceName))];
13
+ for (const plugin of plugins) {
14
+ const compiled = plugin(code, `${sourceName}.jsx`);
15
+ code = compiled.code;
16
+ maps.unshift(compiled.map);
17
+ }
18
+ // The module as CommonJS, by TypeScript: its imports `require` calls, its
19
+ // default export `exports.default`, so it runs as a function's body.
20
+ const dependencies = [];
21
+ const output = ts.transpileModule(code, {
22
+ fileName: "module.jsx",
23
+ compilerOptions: {
24
+ jsx: ts.JsxEmit.Preserve,
25
+ module: ts.ModuleKind.CommonJS,
26
+ target: ts.ScriptTarget.ESNext,
27
+ sourceMap: true,
28
+ },
29
+ transformers: { before: [specifiers(ts, dependencies)] },
30
+ });
31
+ maps.unshift(output.sourceMapText);
32
+ const body = output.outputText.replace(/\n\/\/# sourceMappingURL=.*$/, "");
33
+ // Chained as an array, not by source name: Babel names a map's source by
34
+ // the id's basename.
35
+ const map = remapping(maps, () => null, { excludeContent: true }).toString();
36
+ return {
37
+ code: `(module, exports, require) => {\n${body}\n}`,
38
+ map: down(map),
39
+ dependencies,
40
+ };
41
+ }
42
+ // What a module imports, by specifier, once each, as TypeScript reads it.
43
+ function specifiers(ts, into) {
44
+ return () => (sourceFile) => {
45
+ for (const statement of sourceFile.statements) {
46
+ if (ts.isImportDeclaration(statement) &&
47
+ ts.isStringLiteral(statement.moduleSpecifier) &&
48
+ !into.includes(statement.moduleSpecifier.text)) {
49
+ into.push(statement.moduleSpecifier.text);
50
+ }
51
+ }
52
+ return sourceFile;
53
+ };
54
+ }
55
+ // A script's map with its one source, the host file, named `sourceName`.
56
+ function renamed(map, sourceName) {
57
+ const parsed = JSON.parse(map);
58
+ return JSON.stringify({ ...parsed, sources: [sourceName] });
59
+ }
60
+ // A map whose code moved down a line, as code does that a wrapper starts on a
61
+ // line of its own.
62
+ function down(map) {
63
+ const parsed = JSON.parse(map);
64
+ return JSON.stringify({ ...parsed, mappings: `;${parsed.mappings}` });
65
+ }
66
+ //# sourceMappingURL=compileScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileScript.js","sourceRoot":"","sources":["../src/compileScript.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAoB9C;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,EAA+B,EAC/B,MAAqB,EACrB,UAAkB,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AAE,oCAAoC,IAAI,KAAK;QACnD,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;QACd,YAAY;KACb,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,SAAS,UAAU,CACjB,EAA+B,EAC/B,IAAc;IAEd,OAAO,GAAG,EAAE,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1B,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YAC9C,IACE,EAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC;gBACjC,EAAE,CAAC,eAAe,CAAC,SAAS,CAAC,eAAe,CAAC;gBAC7C,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,EAC9C,CAAC;gBACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,SAAS,OAAO,CAAC,GAAW,EAAE,UAAkB;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAW,CAAC;IACzC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,8EAA8E;AAC9E,mBAAmB;AACnB,SAAS,IAAI,CAAC,GAAW;IACvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;IACvD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,QAAQ,EAAE,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { DiagnosticCategory } from "typescript";
2
+ import type { SourceRange } from "./SourceRange.js";
3
+ export interface Diagnostic {
4
+ range: SourceRange;
5
+ message: string;
6
+ category: DiagnosticCategory;
7
+ code: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":""}
@@ -0,0 +1,52 @@
1
+ import type { ClientScript } from "./parseFile.js";
2
+ import type { BindingResolution, ResolvedParam } from "./resolveBindings.js";
3
+ /** A script as the client runs it, and where its code came from. */
4
+ export interface EmittedScript {
5
+ /**
6
+ * The script as an expression, `($splice0, …) => body`, a parameter per
7
+ * entry of a script's `params` (see `paramName`). Types are gone and
8
+ * everything else, JSX included, is as the script wrote it, for the
9
+ * framework's own compiler to read when a bundle is built. How it is
10
+ * delivered is the bundle's to write.
11
+ */
12
+ readonly code: string;
13
+ /**
14
+ * The code's source map, into the host file. It carries no
15
+ * `sourcesContent`: the host file is the server's, and a map is shipped.
16
+ */
17
+ readonly map: string;
18
+ }
19
+ /**
20
+ * What a name the script wrote becomes: one of its entry's parameters, called
21
+ * with the bindings a hole hands over where it has `args`, read as it is where
22
+ * not.
23
+ */
24
+ export interface Edit {
25
+ readonly param: string;
26
+ readonly args?: readonly string[];
27
+ }
28
+ /**
29
+ * A script parameter's name: its kind and its index in a script's `params`,
30
+ * `$splice0`, `$capture1`. A script cannot bind a name starting with
31
+ * `$`, so none meets one of its own.
32
+ */
33
+ export declare function paramName(param: ResolvedParam, index: number): string;
34
+ /**
35
+ * The edits a script's text needs, by the host-file offset of what each
36
+ * replaces: every splice it reads, host tags among them, and every binding it
37
+ * captures. What is a reference, and each parameter's number, was decided by
38
+ * `resolveBindings`.
39
+ */
40
+ export declare function scriptEdits(script: ClientScript, bindings: BindingResolution, params: readonly ResolvedParam[]): Map<number, Edit>;
41
+ /**
42
+ * Emits a script's code by compiling its own text with TypeScript, with
43
+ * `edits` applied.
44
+ *
45
+ * TypeScript is handed the script's text alone, as `parseFile` read it: its
46
+ * template's escapes decoded, every `${…}` hole its placeholder. An edit is
47
+ * found where its name stands in the host file, and the source map is moved
48
+ * there, through the script's own offsets. The script alone, not the host file
49
+ * blanked around it: that would make each script cost what the whole file
50
+ * does.
51
+ */
52
+ export declare function emitScript(ts: typeof import("typescript"), script: ClientScript, params: readonly string[], edits: ReadonlyMap<number, Edit>): EmittedScript;
@@ -0,0 +1,201 @@
1
+ import { addMapping, GenMapping, toEncodedMap } from "@jridgewell/gen-mapping";
2
+ import { eachMapping, TraceMap } from "@jridgewell/trace-mapping";
3
+ import { tagRoot } from "./tagRoot.js";
4
+ /**
5
+ * A script parameter's name: its kind and its index in a script's `params`,
6
+ * `$splice0`, `$capture1`. A script cannot bind a name starting with
7
+ * `$`, so none meets one of its own.
8
+ */
9
+ export function paramName(param, index) {
10
+ return `$${param.kind}${index}`;
11
+ }
12
+ // A binding key as `resolveBindings` writes it, `<name>$<fileHash>$<n>`, back
13
+ // to the name the script wrote.
14
+ function sourceName(key) {
15
+ return key.replace(/\$[0-9a-z]+\$\d+$/, "");
16
+ }
17
+ /**
18
+ * The edits a script's text needs, by the host-file offset of what each
19
+ * replaces: every splice it reads, host tags among them, and every binding it
20
+ * captures. What is a reference, and each parameter's number, was decided by
21
+ * `resolveBindings`.
22
+ */
23
+ export function scriptEdits(script, bindings, params) {
24
+ const captureParam = new Map(params.flatMap((param, index) => param.kind === "capture" ? [[param.key, index]] : []));
25
+ const captures = [...captureParam.keys()];
26
+ const read = (key) => {
27
+ const index = captureParam.get(key);
28
+ return index === undefined ? sourceName(key) : `$capture${index}`;
29
+ };
30
+ const edits = new Map();
31
+ const at = (identifier) => script.toSourceRange(identifier).start;
32
+ params.forEach((param, index) => {
33
+ if (param.kind === "capture") {
34
+ return;
35
+ }
36
+ const edit = {
37
+ param: paramName(param, index),
38
+ args: [...param.bindings, ...captures].map(read),
39
+ };
40
+ for (const ref of param.refs) {
41
+ edits.set(at(ref), edit);
42
+ }
43
+ });
44
+ for (const [identifier, key] of bindings) {
45
+ const index = captureParam.get(key);
46
+ if (index !== undefined &&
47
+ identifier.getSourceFile() === script.fileWithPlaceholders) {
48
+ edits.set(at(identifier), { param: `$capture${index}` });
49
+ }
50
+ }
51
+ return edits;
52
+ }
53
+ /**
54
+ * Emits a script's code by compiling its own text with TypeScript, with
55
+ * `edits` applied.
56
+ *
57
+ * TypeScript is handed the script's text alone, as `parseFile` read it: its
58
+ * template's escapes decoded, every `${…}` hole its placeholder. An edit is
59
+ * found where its name stands in the host file, and the source map is moved
60
+ * there, through the script's own offsets. The script alone, not the host file
61
+ * blanked around it: that would make each script cost what the whole file
62
+ * does.
63
+ */
64
+ export function emitScript(ts, script, params, edits) {
65
+ const sourceFile = script.sourceFile;
66
+ const transformer = (context) => (file) => {
67
+ const f = context.factory;
68
+ const editAt = (node) => edits.get(script.toSourceOffset(node.getStart(file)));
69
+ const edited = (edit, from) => {
70
+ const param = f.createIdentifier(edit.param);
71
+ const node = edit.args === undefined
72
+ ? param
73
+ : f.createCallExpression(param, undefined, edit.args.map((arg) => f.createIdentifier(arg)));
74
+ return ts.setOriginalNode(ts.setTextRange(node, from), from);
75
+ };
76
+ // A tag's names where the tag reads a splice: they stay as written, the
77
+ // parameter of the arrow below.
78
+ const asWritten = new Set();
79
+ // A tag that names a splice, `<$Card>`: JSX can't call where a tag goes,
80
+ // so the element is the body of an arrow its tag is a parameter of, called
81
+ // with the splice where the element stands, as any splice is read:
82
+ // `(($Card) => <$Card …/>)($splice0())`. A capture is its value, read as
83
+ // a tag as it is anywhere.
84
+ const hostTag = (node) => {
85
+ const opening = ts.isJsxElement(node) ? node.openingElement : node;
86
+ const root = tagRoot(ts, opening.tagName);
87
+ const edit = root && editAt(root);
88
+ if (root === undefined || edit?.args === undefined) {
89
+ return undefined;
90
+ }
91
+ asWritten.add(opening.tagName);
92
+ if (ts.isJsxElement(node)) {
93
+ asWritten.add(node.closingElement.tagName);
94
+ }
95
+ const call = ts.setTextRange(f.createCallExpression(f.createParenthesizedExpression(f.createArrowFunction(undefined, undefined, [f.createParameterDeclaration(undefined, undefined, root.text)], undefined, f.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.visitEachChild(node, visit, context))), undefined, [edited(edit, root)]), node);
96
+ // Among an element's children, an expression is written in braces.
97
+ return ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent)
98
+ ? f.createJsxExpression(undefined, call)
99
+ : call;
100
+ };
101
+ const visit = (node) => {
102
+ // Types are TypeScript's to strip, after this.
103
+ if (ts.isTypeNode(node) || asWritten.has(node)) {
104
+ return node;
105
+ }
106
+ if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
107
+ const tagged = hostTag(node);
108
+ if (tagged !== undefined) {
109
+ return tagged;
110
+ }
111
+ }
112
+ if (ts.isIdentifier(node)) {
113
+ const edit = editAt(node);
114
+ return edit === undefined ? node : edited(edit, node);
115
+ }
116
+ // `{ count }` names a key as well as a value.
117
+ if (ts.isShorthandPropertyAssignment(node)) {
118
+ const edit = editAt(node.name);
119
+ if (edit !== undefined) {
120
+ return f.createPropertyAssignment(node.name.text, edited(edit, node.name));
121
+ }
122
+ }
123
+ return ts.visitEachChild(node, visit, context);
124
+ };
125
+ const [statement] = file.statements;
126
+ if (statement === undefined) {
127
+ return file;
128
+ }
129
+ // Where the script stands, so the entry maps to it.
130
+ const entry = ts.setTextRange(f.createArrowFunction(undefined, undefined, params.map((name) => f.createParameterDeclaration(undefined, undefined, name)), undefined, f.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.isExpressionStatement(statement)
131
+ ? ts.visitNode(statement.expression, visit, ts.isExpression)
132
+ : ts.visitNode(statement, visit, ts.isBlock)), statement);
133
+ return f.updateSourceFile(file, [
134
+ ts.setOriginalNode(f.createExpressionStatement(entry), statement),
135
+ ]);
136
+ };
137
+ const output = ts.transpileModule(script.textWithPlaceholders, {
138
+ fileName: sourceFile.fileName,
139
+ compilerOptions: {
140
+ target: ts.ScriptTarget.ESNext,
141
+ module: ts.ModuleKind.ESNext,
142
+ jsx: ts.JsxEmit.Preserve,
143
+ sourceMap: true,
144
+ alwaysStrict: false,
145
+ removeComments: true,
146
+ },
147
+ transformers: { before: [transformer] },
148
+ });
149
+ // The file's one expression statement, without its `;` or the comment
150
+ // naming a map file.
151
+ const code = output.outputText
152
+ .replace(/\n\/\/# sourceMappingURL=.*$/, "")
153
+ .replace(/;\s*$/, "");
154
+ return {
155
+ code,
156
+ map: moved(output.sourceMapText, script),
157
+ };
158
+ }
159
+ // A map into the script's text, moved to where each position stands in the
160
+ // host file. Named as the host file was, not relative to an output file there
161
+ // is none of, so maps from files in different directories can be combined.
162
+ function moved(map, script) {
163
+ const sourceFile = script.sourceFile;
164
+ const lineStarts = [0];
165
+ for (const line of script.textWithPlaceholders.matchAll(/\r\n|\n|\r/g)) {
166
+ lineStarts.push(line.index + line[0].length);
167
+ }
168
+ // Lines are 1-based here, columns 0-based.
169
+ const original = (line, column) => {
170
+ const at = sourceFile.getLineAndCharacterOfPosition(script.toSourceOffset(lineStarts[line - 1] + column));
171
+ return { line: at.line + 1, column: at.character };
172
+ };
173
+ const into = new GenMapping({ file: sourceFile.fileName });
174
+ eachMapping(new TraceMap(map), (mapping) => {
175
+ if (mapping.originalLine === null) {
176
+ addMapping(into, {
177
+ generated: {
178
+ line: mapping.generatedLine,
179
+ column: mapping.generatedColumn,
180
+ },
181
+ });
182
+ return;
183
+ }
184
+ // TypeScript writes no names, so there are none to carry.
185
+ addMapping(into, {
186
+ generated: {
187
+ line: mapping.generatedLine,
188
+ column: mapping.generatedColumn,
189
+ },
190
+ source: sourceFile.fileName,
191
+ original: original(mapping.originalLine, mapping.originalColumn),
192
+ });
193
+ });
194
+ // TypeScript's own map, with only where it points changed.
195
+ return JSON.stringify({
196
+ ...JSON.parse(map),
197
+ sources: [sourceFile.fileName],
198
+ mappings: toEncodedMap(into).mappings,
199
+ });
200
+ }
201
+ //# sourceMappingURL=emitScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit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AAO;QACT,CAAC;QACD,0DAA0D;QAC1D,UAAU,CAAC,IAAI,EAAE;YACf,SAAS,EAAE;gBACT,IAAI,EAAE,OAAO,CAAC,aAAa;gBAC3B,MAAM,EAAE,OAAO,CAAC,eAAe;aAChC;YACD,MAAM,EAAE,UAAU,CAAC,QAAQ;YAC3B,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,cAAc,CAAC;SACjE,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,2DAA2D;IAC3D,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,GAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAY;QAC9B,OAAO,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC9B,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ;KACtC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type CompiledScript, type Plugin } from "./compileScript.js";
2
+ /** A script's emitted code, by where the host wrote it. */
3
+ export interface EmittedScriptAt extends CompiledScript {
4
+ readonly start: number;
5
+ }
6
+ /**
7
+ * What each of a file's scripts compiles to for the client, in source order:
8
+ * nested scripts too, each as its own entry.
9
+ */
10
+ export declare function emitScripts(ts: typeof import("typescript"), fileName: string, sourceText: string, plugins?: readonly Plugin[]): EmittedScriptAt[];