@generaltranslation/vue-extractor 0.0.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 (62) hide show
  1. package/LICENSE.md +105 -0
  2. package/dist/config.d.ts +2 -0
  3. package/dist/config.js +2 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +2 -0
  6. package/dist/internal/compilerAst.d.ts +43 -0
  7. package/dist/internal/compilerAst.js +77 -0
  8. package/dist/internal/compilerAst.js.map +1 -0
  9. package/dist/internal/config/resolveVueCompilerOptions.d.ts +23 -0
  10. package/dist/internal/config/resolveVueCompilerOptions.js +987 -0
  11. package/dist/internal/config/resolveVueCompilerOptions.js.map +1 -0
  12. package/dist/internal/extractFromVueSource.d.ts +9 -0
  13. package/dist/internal/extractFromVueSource.js +332 -0
  14. package/dist/internal/extractFromVueSource.js.map +1 -0
  15. package/dist/internal/script/analyze.d.ts +13 -0
  16. package/dist/internal/script/analyze.js +4761 -0
  17. package/dist/internal/script/analyze.js.map +1 -0
  18. package/dist/internal/script/jsx.d.ts +36 -0
  19. package/dist/internal/script/jsx.js +667 -0
  20. package/dist/internal/script/jsx.js.map +1 -0
  21. package/dist/internal/script/knownValues.d.ts +14 -0
  22. package/dist/internal/script/knownValues.js +148 -0
  23. package/dist/internal/script/knownValues.js.map +1 -0
  24. package/dist/internal/script/localModules.d.ts +80 -0
  25. package/dist/internal/script/localModules.js +364 -0
  26. package/dist/internal/script/localModules.js.map +1 -0
  27. package/dist/internal/script/model.d.ts +317 -0
  28. package/dist/internal/script/model.js +1 -0
  29. package/dist/internal/script/parser.d.ts +3 -0
  30. package/dist/internal/script/parser.js +21 -0
  31. package/dist/internal/script/parser.js.map +1 -0
  32. package/dist/internal/script/replay.d.ts +53 -0
  33. package/dist/internal/script/replay.js +1611 -0
  34. package/dist/internal/script/replay.js.map +1 -0
  35. package/dist/internal/script/snapshot.d.ts +25 -0
  36. package/dist/internal/script/snapshot.js +293 -0
  37. package/dist/internal/script/snapshot.js.map +1 -0
  38. package/dist/internal/script/syntax.d.ts +21 -0
  39. package/dist/internal/script/syntax.js +46 -0
  40. package/dist/internal/script/syntax.js.map +1 -0
  41. package/dist/internal/script.d.ts +2 -0
  42. package/dist/internal/script.js +2 -0
  43. package/dist/internal/stringCalls.d.ts +7 -0
  44. package/dist/internal/stringCalls.js +82 -0
  45. package/dist/internal/stringCalls.js.map +1 -0
  46. package/dist/internal/template.d.ts +4 -0
  47. package/dist/internal/template.js +2198 -0
  48. package/dist/internal/template.js.map +1 -0
  49. package/dist/internal/templatePath.d.ts +12 -0
  50. package/dist/internal/templatePath.js +23 -0
  51. package/dist/internal/templatePath.js.map +1 -0
  52. package/dist/internal/types.d.ts +69 -0
  53. package/dist/internal/types.js +1 -0
  54. package/dist/internal/utils.d.ts +19 -0
  55. package/dist/internal/utils.js +149 -0
  56. package/dist/internal/utils.js.map +1 -0
  57. package/dist/internal/vueCompiler.d.ts +35 -0
  58. package/dist/internal/vueCompiler.js +320 -0
  59. package/dist/internal/vueCompiler.js.map +1 -0
  60. package/dist/types.d.ts +80 -0
  61. package/dist/types.js +1 -0
  62. package/package.json +78 -0
package/LICENSE.md ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-ALv2
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 General Translation, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,2 @@
1
+ export { resolveVueCompilerOptions } from './internal/config/resolveVueCompilerOptions.js';
2
+ export type { VueCompilerOptionsResolution, VueCompilerOptionsResolverOptions, } from './internal/config/resolveVueCompilerOptions.js';
package/dist/config.js ADDED
@@ -0,0 +1,2 @@
1
+ import { resolveVueCompilerOptions } from "./internal/config/resolveVueCompilerOptions.js";
2
+ export { resolveVueCompilerOptions };
@@ -0,0 +1,2 @@
1
+ export { extractFromVueSource } from './internal/extractFromVueSource.js';
2
+ export type { VueCompilerOptions, VueCompiler, VueExtractionMetadata, VueExtractionOptions, VueExtractionOutput, VueExtractionResult, VueSourceCode, } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { extractFromVueSource } from "./internal/extractFromVueSource.js";
2
+ export { extractFromVueSource };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Vue compiler node discriminants used by the extractor.
3
+ *
4
+ * These values are defined locally so the production bundle can inspect the
5
+ * compiler-sfc AST without importing a second runtime copy of compiler-dom.
6
+ * The matching test intentionally compares them with the installed compiler.
7
+ */
8
+ export declare const NodeTypes: {
9
+ readonly ELEMENT: 1;
10
+ readonly TEXT: 2;
11
+ readonly COMMENT: 3;
12
+ readonly SIMPLE_EXPRESSION: 4;
13
+ readonly INTERPOLATION: 5;
14
+ readonly ATTRIBUTE: 6;
15
+ readonly DIRECTIVE: 7;
16
+ };
17
+ /** Vue element discriminants used by the extractor. */
18
+ export declare const ElementTypes: {
19
+ readonly COMPONENT: 1;
20
+ readonly SLOT: 2;
21
+ };
22
+ type CompilerPosition = {
23
+ column: number;
24
+ line: number;
25
+ offset: number;
26
+ };
27
+ type CompilerLocation = {
28
+ end?: Partial<CompilerPosition>;
29
+ source?: string;
30
+ start?: Partial<CompilerPosition>;
31
+ };
32
+ /**
33
+ * Rebases a compiler AST from template-content coordinates to its full SFC.
34
+ *
35
+ * The input is intentionally `unknown`: Vue compiler AST types are not part
36
+ * of the extractor's public declaration graph and differ across supported
37
+ * Vue releases. Runtime structural guards preserve safety at this internal
38
+ * boundary without making consumers install the extractor's test compiler.
39
+ */
40
+ export declare function shiftCompilerAstLocations(ast: unknown, origin: CompilerPosition): void;
41
+ /** Rebases one structurally validated Vue compiler source range. */
42
+ export declare function shiftCompilerLocation(location: CompilerLocation, origin: CompilerPosition, shiftedPositions?: WeakSet<object>): void;
43
+ export {};
@@ -0,0 +1,77 @@
1
+ //#region src/internal/compilerAst.ts
2
+ /**
3
+ * Vue compiler node discriminants used by the extractor.
4
+ *
5
+ * These values are defined locally so the production bundle can inspect the
6
+ * compiler-sfc AST without importing a second runtime copy of compiler-dom.
7
+ * The matching test intentionally compares them with the installed compiler.
8
+ */
9
+ const NodeTypes = {
10
+ ELEMENT: 1,
11
+ TEXT: 2,
12
+ COMMENT: 3,
13
+ SIMPLE_EXPRESSION: 4,
14
+ INTERPOLATION: 5,
15
+ ATTRIBUTE: 6,
16
+ DIRECTIVE: 7
17
+ };
18
+ /** Vue element discriminants used by the extractor. */
19
+ const ElementTypes = {
20
+ COMPONENT: 1,
21
+ SLOT: 2
22
+ };
23
+ /**
24
+ * Rebases a compiler AST from template-content coordinates to its full SFC.
25
+ *
26
+ * The input is intentionally `unknown`: Vue compiler AST types are not part
27
+ * of the extractor's public declaration graph and differ across supported
28
+ * Vue releases. Runtime structural guards preserve safety at this internal
29
+ * boundary without making consumers install the extractor's test compiler.
30
+ */
31
+ function shiftCompilerAstLocations(ast, origin) {
32
+ const seen = /* @__PURE__ */ new WeakSet();
33
+ const shiftedPositions = /* @__PURE__ */ new WeakSet();
34
+ const visit = (value) => {
35
+ if (!value || typeof value !== "object" || seen.has(value)) return;
36
+ seen.add(value);
37
+ if (isCompilerLocation(value)) {
38
+ shiftCompilerLocation(value, origin, shiftedPositions);
39
+ return;
40
+ }
41
+ if (Array.isArray(value)) {
42
+ for (const child of value) visit(child);
43
+ return;
44
+ }
45
+ for (const child of Object.values(value)) visit(child);
46
+ };
47
+ visit(ast);
48
+ }
49
+ /** Rebases one structurally validated Vue compiler source range. */
50
+ function shiftCompilerLocation(location, origin, shiftedPositions = /* @__PURE__ */ new WeakSet()) {
51
+ if (location.start) shiftCompilerPosition(location.start, origin, shiftedPositions);
52
+ if (location.end) shiftCompilerPosition(location.end, origin, shiftedPositions);
53
+ }
54
+ /** Rebases a template-relative position to the containing SFC. */
55
+ function shiftCompilerPosition(position, origin, shiftedPositions) {
56
+ if (shiftedPositions.has(position)) return;
57
+ shiftedPositions.add(position);
58
+ const line = position.line ?? 1;
59
+ const column = position.column ?? 1;
60
+ const offset = position.offset ?? 0;
61
+ position.line = origin.line + line - 1;
62
+ position.column = line === 1 ? origin.column + column - 1 : column;
63
+ position.offset = origin.offset + offset;
64
+ }
65
+ /** Identifies Vue compiler source locations while skipping Babel AST ranges. */
66
+ function isCompilerLocation(value) {
67
+ if (!("start" in value) || !("end" in value) || !("source" in value)) return false;
68
+ return isCompilerPosition(value.start) && isCompilerPosition(value.end);
69
+ }
70
+ /** Returns whether a value has Vue compiler line, column, and offset fields. */
71
+ function isCompilerPosition(value) {
72
+ return !!value && typeof value === "object" && "line" in value && typeof value.line === "number" && "column" in value && typeof value.column === "number" && "offset" in value && typeof value.offset === "number";
73
+ }
74
+ //#endregion
75
+ export { ElementTypes, NodeTypes, shiftCompilerAstLocations, shiftCompilerLocation };
76
+
77
+ //# sourceMappingURL=compilerAst.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilerAst.js","names":[],"sources":["../../src/internal/compilerAst.ts"],"sourcesContent":["/**\n * Vue compiler node discriminants used by the extractor.\n *\n * These values are defined locally so the production bundle can inspect the\n * compiler-sfc AST without importing a second runtime copy of compiler-dom.\n * The matching test intentionally compares them with the installed compiler.\n */\nexport const NodeTypes = {\n ELEMENT: 1,\n TEXT: 2,\n COMMENT: 3,\n SIMPLE_EXPRESSION: 4,\n INTERPOLATION: 5,\n ATTRIBUTE: 6,\n DIRECTIVE: 7,\n} as const;\n\n/** Vue element discriminants used by the extractor. */\nexport const ElementTypes = {\n COMPONENT: 1,\n SLOT: 2,\n} as const;\n\ntype CompilerPosition = {\n column: number;\n line: number;\n offset: number;\n};\n\ntype CompilerLocation = {\n end?: Partial<CompilerPosition>;\n source?: string;\n start?: Partial<CompilerPosition>;\n};\n\n/**\n * Rebases a compiler AST from template-content coordinates to its full SFC.\n *\n * The input is intentionally `unknown`: Vue compiler AST types are not part\n * of the extractor's public declaration graph and differ across supported\n * Vue releases. Runtime structural guards preserve safety at this internal\n * boundary without making consumers install the extractor's test compiler.\n */\nexport function shiftCompilerAstLocations(\n ast: unknown,\n origin: CompilerPosition\n): void {\n const seen = new WeakSet<object>();\n const shiftedPositions = new WeakSet<object>();\n\n const visit = (value: unknown): void => {\n if (!value || typeof value !== 'object' || seen.has(value)) return;\n seen.add(value);\n\n if (isCompilerLocation(value)) {\n shiftCompilerLocation(value, origin, shiftedPositions);\n return;\n }\n if (Array.isArray(value)) {\n for (const child of value) visit(child);\n return;\n }\n for (const child of Object.values(value)) visit(child);\n };\n\n visit(ast);\n}\n\n/** Rebases one structurally validated Vue compiler source range. */\nexport function shiftCompilerLocation(\n location: CompilerLocation,\n origin: CompilerPosition,\n shiftedPositions = new WeakSet<object>()\n): void {\n if (location.start) {\n shiftCompilerPosition(location.start, origin, shiftedPositions);\n }\n if (location.end) {\n shiftCompilerPosition(location.end, origin, shiftedPositions);\n }\n}\n\n/** Rebases a template-relative position to the containing SFC. */\nfunction shiftCompilerPosition(\n position: Partial<CompilerPosition>,\n origin: CompilerPosition,\n shiftedPositions: WeakSet<object>\n): void {\n if (shiftedPositions.has(position)) return;\n shiftedPositions.add(position);\n const line = position.line ?? 1;\n const column = position.column ?? 1;\n const offset = position.offset ?? 0;\n position.line = origin.line + line - 1;\n position.column = line === 1 ? origin.column + column - 1 : column;\n position.offset = origin.offset + offset;\n}\n\n/** Identifies Vue compiler source locations while skipping Babel AST ranges. */\nfunction isCompilerLocation(value: object): value is CompilerLocation {\n if (!('start' in value) || !('end' in value) || !('source' in value)) {\n return false;\n }\n return isCompilerPosition(value.start) && isCompilerPosition(value.end);\n}\n\n/** Returns whether a value has Vue compiler line, column, and offset fields. */\nfunction isCompilerPosition(value: unknown): value is CompilerPosition {\n return (\n !!value &&\n typeof value === 'object' &&\n 'line' in value &&\n typeof value.line === 'number' &&\n 'column' in value &&\n typeof value.column === 'number' &&\n 'offset' in value &&\n typeof value.offset === 'number'\n );\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,YAAY;CACvB,SAAS;CACT,MAAM;CACN,SAAS;CACT,mBAAmB;CACnB,eAAe;CACf,WAAW;CACX,WAAW;CACZ;;AAGD,MAAa,eAAe;CAC1B,WAAW;CACX,MAAM;CACP;;;;;;;;;AAsBD,SAAgB,0BACd,KACA,QACM;CACN,MAAM,uBAAO,IAAI,SAAiB;CAClC,MAAM,mCAAmB,IAAI,SAAiB;CAE9C,MAAM,SAAS,UAAyB;AACtC,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,KAAK,IAAI,MAAM,CAAE;AAC5D,OAAK,IAAI,MAAM;AAEf,MAAI,mBAAmB,MAAM,EAAE;AAC7B,yBAAsB,OAAO,QAAQ,iBAAiB;AACtD;;AAEF,MAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,QAAK,MAAM,SAAS,MAAO,OAAM,MAAM;AACvC;;AAEF,OAAK,MAAM,SAAS,OAAO,OAAO,MAAM,CAAE,OAAM,MAAM;;AAGxD,OAAM,IAAI;;;AAIZ,SAAgB,sBACd,UACA,QACA,mCAAmB,IAAI,SAAiB,EAClC;AACN,KAAI,SAAS,MACX,uBAAsB,SAAS,OAAO,QAAQ,iBAAiB;AAEjE,KAAI,SAAS,IACX,uBAAsB,SAAS,KAAK,QAAQ,iBAAiB;;;AAKjE,SAAS,sBACP,UACA,QACA,kBACM;AACN,KAAI,iBAAiB,IAAI,SAAS,CAAE;AACpC,kBAAiB,IAAI,SAAS;CAC9B,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,SAAS,SAAS,UAAU;CAClC,MAAM,SAAS,SAAS,UAAU;AAClC,UAAS,OAAO,OAAO,OAAO,OAAO;AACrC,UAAS,SAAS,SAAS,IAAI,OAAO,SAAS,SAAS,IAAI;AAC5D,UAAS,SAAS,OAAO,SAAS;;;AAIpC,SAAS,mBAAmB,OAA0C;AACpE,KAAI,EAAE,WAAW,UAAU,EAAE,SAAS,UAAU,EAAE,YAAY,OAC5D,QAAO;AAET,QAAO,mBAAmB,MAAM,MAAM,IAAI,mBAAmB,MAAM,IAAI;;;AAIzE,SAAS,mBAAmB,OAA2C;AACrE,QACE,CAAC,CAAC,SACF,OAAO,UAAU,YACjB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,YAAY,SACZ,OAAO,MAAM,WAAW,YACxB,YAAY,SACZ,OAAO,MAAM,WAAW"}
@@ -0,0 +1,23 @@
1
+ import type { VueCompilerOptions } from '../../types.js';
2
+ /** Result of resolving hash-affecting options from project configuration. */
3
+ export type VueCompilerOptionsResolution = {
4
+ /** Static compiler options that must be passed to Vue source extraction. */
5
+ compilerOptions: VueCompilerOptions;
6
+ /** Diagnostics that make extraction unsafe until the configuration is fixed. */
7
+ errors: string[];
8
+ };
9
+ /** Controls project configuration discovery for compiler-option resolution. */
10
+ export type VueCompilerOptionsResolverOptions = {
11
+ /** A single explicit Vite config path, resolved relative to the project root. */
12
+ viteConfigPath?: string;
13
+ };
14
+ /**
15
+ * Resolves hash-affecting Vue template compiler options without executing
16
+ * project configuration files.
17
+ *
18
+ * Explicit `gt.config.json` values are combined with statically analyzable
19
+ * Vite and Nuxt configuration. Conflicting, dynamic, or unsupported relevant
20
+ * options produce errors so extraction never publishes hashes calculated with
21
+ * compiler behavior that the runtime does not share.
22
+ */
23
+ export declare function resolveVueCompilerOptions(cwd: string, explicitOptions: VueCompilerOptions | undefined, resolverOptions?: VueCompilerOptionsResolverOptions): VueCompilerOptionsResolution;