@generaltranslation/compiler 1.3.37 → 1.3.38-iris.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/LICENSE.md +18 -102
- package/dist/state/ScopeTracker.d.ts +1 -5
- package/dist/state/ScopeTracker.d.ts.map +1 -1
- package/dist/state/ScopeTracker.js +5 -6
- package/dist/state/ScopeTracker.js.map +1 -1
- package/dist/utils/calculateHash.js +1 -0
- package/dist/utils/calculateHash.js.map +1 -1
- package/package.json +4 -3
package/LICENSE.md
CHANGED
|
@@ -1,105 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
## Abbreviation
|
|
4
|
-
|
|
5
|
-
FSL-1.1-ALv2
|
|
6
|
-
|
|
7
|
-
## Notice
|
|
1
|
+
MIT License
|
|
8
2
|
|
|
9
3
|
Copyright 2026 General Translation, Inc.
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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.
|
|
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.
|
|
@@ -30,10 +30,6 @@ export interface ScopedVariable {
|
|
|
30
30
|
canonicalName: string | GT_ALL_FUNCTIONS;
|
|
31
31
|
/** The variable name (t, translationFunction, etc.) */
|
|
32
32
|
aliasName: string;
|
|
33
|
-
/** Whether the variable is a translation function
|
|
34
|
-
* @deprecated
|
|
35
|
-
*/
|
|
36
|
-
isTranslationFunction: boolean;
|
|
37
33
|
type: VariableType;
|
|
38
34
|
/** The identifier for the variable */
|
|
39
35
|
identifier: number;
|
|
@@ -79,7 +75,7 @@ export declare class ScopeTracker {
|
|
|
79
75
|
/**
|
|
80
76
|
* Track a variable assignment in the current scope
|
|
81
77
|
*/
|
|
82
|
-
trackVariable(aliasName: string, canonicalName: string,
|
|
78
|
+
trackVariable(aliasName: string, canonicalName: string, type: VariableType, identifier: number): void;
|
|
83
79
|
/**
|
|
84
80
|
* Track a translation function variable
|
|
85
81
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopeTracker.d.ts","sourceRoot":"","sources":["../../src/state/ScopeTracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AAIzC;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,mBAAmB;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,oBAAoB,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAi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,EAAE,MAAM,GAAG,OAAO;IAQzC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIpD;;OAEG;IACH,SAAS,IAAI,sBAAsB;IAWnC;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;CAajD"}
|
|
@@ -47,12 +47,11 @@ var ScopeTracker = class {
|
|
|
47
47
|
/**
|
|
48
48
|
* Track a variable assignment in the current scope
|
|
49
49
|
*/
|
|
50
|
-
trackVariable(aliasName, canonicalName,
|
|
50
|
+
trackVariable(aliasName, canonicalName, type, identifier) {
|
|
51
51
|
const scopedVar = {
|
|
52
52
|
scopeId: this.currentScope,
|
|
53
53
|
canonicalName,
|
|
54
54
|
aliasName,
|
|
55
|
-
isTranslationFunction,
|
|
56
55
|
type,
|
|
57
56
|
identifier
|
|
58
57
|
};
|
|
@@ -64,7 +63,7 @@ var ScopeTracker = class {
|
|
|
64
63
|
* Track a translation function variable
|
|
65
64
|
*/
|
|
66
65
|
trackTranslationVariable(aliasName, canonicalName, identifier) {
|
|
67
|
-
this.trackVariable(aliasName, canonicalName,
|
|
66
|
+
this.trackVariable(aliasName, canonicalName, "generaltranslation", identifier);
|
|
68
67
|
}
|
|
69
68
|
/**
|
|
70
69
|
* Track a translation callback function variable
|
|
@@ -75,19 +74,19 @@ var ScopeTracker = class {
|
|
|
75
74
|
* TODO: canonicalName might have to be shifted to the name of the RValue eg useGT in t = useGT() so you can properly map back to the original function
|
|
76
75
|
*/
|
|
77
76
|
trackTranslationCallbackVariable(aliasName, canonicalName, identifier) {
|
|
78
|
-
this.trackVariable(aliasName, canonicalName,
|
|
77
|
+
this.trackVariable(aliasName, canonicalName, "generaltranslation", identifier);
|
|
79
78
|
}
|
|
80
79
|
/**
|
|
81
80
|
* Track react variable
|
|
82
81
|
*/
|
|
83
82
|
trackReactVariable(variableName, assignedValue, identifier) {
|
|
84
|
-
this.trackVariable(variableName, assignedValue,
|
|
83
|
+
this.trackVariable(variableName, assignedValue, "react", identifier);
|
|
85
84
|
}
|
|
86
85
|
/**
|
|
87
86
|
* Track a non-translation variable (convenience method)
|
|
88
87
|
*/
|
|
89
88
|
trackRegularVariable(variableName, assignedValue) {
|
|
90
|
-
this.trackVariable(variableName, assignedValue,
|
|
89
|
+
this.trackVariable(variableName, assignedValue, "other", 0);
|
|
91
90
|
}
|
|
92
91
|
/**
|
|
93
92
|
* Find if a variable is accessible in the current scope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopeTracker.js","names":[],"sources":["../../src/state/ScopeTracker.ts"],"sourcesContent":["/**\n * Scope Tracker - Handles variable scoping and import tracking\n *\n * Tracks useGT/getGT variable assignments across nested scopes\n * Manages variable shadowing and GT component imports\n */\n\nimport {\n GT_ALL_FUNCTIONS,\n GT_CALLBACK_FUNCTIONS,\n} from '../utils/constants/gt/constants';\n\n// TODO: separate callback funtions and imported functions\n\n/**\n * Information about a scope\n */\nexport interface ScopeInfo {\n /** The scope ID */\n id: number;\n /** The parent scope ID */\n parentId: number;\n /** The depth of the scope */\n depth: number;\n}\n\n/**\n * Variable type represents which group the variable belongs to\n */\nexport type VariableType = 'generaltranslation' | 'react' | 'other';\n\n/**\n * Information about a scoped variable assignment\n */\nexport interface ScopedVariable {\n /** The scope ID */\n scopeId: number;\n /** The canonical name of the variable (useGT, getGT, T, etc.) */\n canonicalName: string | GT_ALL_FUNCTIONS;\n /** The variable name (t, translationFunction, etc.) */\n aliasName: string;\n /** Whether the variable is a translation function\n * @deprecated\n */\n isTranslationFunction: boolean;\n type: VariableType;\n /** The identifier for the variable */\n identifier: number;\n}\n\nexport interface ScopedGTFunction extends ScopedVariable {\n /** The canonical name of the GT function (useGT, getGT, etc.) */\n canonicalName: GT_ALL_FUNCTIONS;\n /** The type of GT function */\n type: 'generaltranslation';\n}\n\ntype SerializedScopeTracker = {\n nextScopeId: number;\n currentScope: number;\n scopeStack: number[];\n scopeInfo: Record<string, ScopeInfo>;\n scopedVariables: Record<string, ScopedVariable[]>;\n namespaceImports: string[];\n};\n\n/**\n * Tracks scope hierarchy and variable assignments within scopes\n */\nexport class ScopeTracker {\n /** Next scope ID to assign */\n private nextScopeId: number = 1; // Start at 1, reserve 0 for \"no scope\"\n /** Current scope being processed */\n private currentScope: number = 0;\n /** Stack to track scope nesting for proper exit handling */\n private scopeStack: number[] = [];\n /** Information about each scope */\n private scopeInfo: Map<number, ScopeInfo> = new Map();\n /** Variables tracked per scope */\n private scopedVariables: Map<string, ScopedVariable[]> = new Map();\n /** Namespace imports (e.g., GT from 'gt-next') */\n private namespaceImports: Set<string> = new Set();\n\n /* =============================== */\n /* Scope Tracker Methods */\n /* =============================== */\n\n /**\n * Enter a new scope and return the new scope ID\n */\n enterScope(): number {\n const newScopeId = this.nextScopeId;\n this.nextScopeId += 1;\n\n const scopeInfo: ScopeInfo = {\n id: newScopeId,\n parentId: this.currentScope,\n depth: this.currentScope !== 0 ? this.scopeStack.length + 1 : 0,\n };\n\n this.scopeInfo.set(newScopeId, scopeInfo);\n\n // Push current scope to stack\n this.scopeStack.push(this.currentScope);\n\n this.currentScope = newScopeId;\n return newScopeId;\n }\n\n /**\n * Exit the current scope and return to parent (with aggressive cleanup)\n */\n exitScope(): void {\n if (this.currentScope === 0) {\n return;\n }\n\n // Remove all variables from the exiting scope immediately\n for (const [varName, variables] of this.scopedVariables.entries()) {\n // Filter out variables from the current scope\n // TODO: there is definitely an O(1) solution here rather than iterating over each entire list\n const filteredVars = variables.filter(\n (variable) => variable.scopeId !== this.currentScope\n );\n\n if (filteredVars.length === 0) {\n // Remove empty variable name entries\n this.scopedVariables.delete(varName);\n } else {\n this.scopedVariables.set(varName, filteredVars);\n }\n }\n\n // Get parent scope from the scope info before removing it\n const parentId = this.scopeInfo.get(this.currentScope)?.parentId || 0;\n\n // Remove scope info for the exiting scope\n this.scopeInfo.delete(this.currentScope);\n\n // Update current scope to parent\n this.currentScope = parentId;\n\n // Pop from stack if there are items\n if (this.scopeStack.length > 0) {\n this.scopeStack.pop();\n }\n }\n\n /* =============================== */\n /* Variable Tracking Methods */\n /* =============================== */\n\n /**\n * Track a variable assignment in the current scope\n */\n trackVariable(\n aliasName: string,\n canonicalName: string,\n isTranslationFunction: boolean,\n type: VariableType,\n identifier: number\n ): void {\n const scopedVar: ScopedVariable = {\n scopeId: this.currentScope,\n canonicalName,\n aliasName,\n isTranslationFunction,\n type,\n identifier,\n };\n\n const existingVars = this.scopedVariables.get(aliasName) || [];\n existingVars.push(scopedVar);\n this.scopedVariables.set(aliasName, existingVars);\n }\n\n /**\n * Track a translation function variable\n */\n trackTranslationVariable(\n aliasName: string,\n canonicalName: GT_ALL_FUNCTIONS,\n identifier: number\n ): void {\n this.trackVariable(\n aliasName,\n canonicalName,\n true,\n 'generaltranslation',\n identifier\n );\n }\n\n /**\n * Track a translation callback function variable\n * const useGT_callback = useGT()\n * @param aliasName - The alias name of callback variable\n * @param canonicalName - The canonical name of the callback function\n * @param identifier - The identifier of the callback function\n * TODO: canonicalName might have to be shifted to the name of the RValue eg useGT in t = useGT() so you can properly map back to the original function\n */\n trackTranslationCallbackVariable(\n aliasName: string,\n canonicalName: GT_CALLBACK_FUNCTIONS,\n identifier: number\n ): void {\n this.trackVariable(\n aliasName,\n canonicalName,\n true,\n 'generaltranslation',\n identifier\n );\n }\n\n /**\n * Track react variable\n */\n trackReactVariable(\n variableName: string,\n assignedValue: string,\n identifier: number\n ): void {\n this.trackVariable(variableName, assignedValue, false, 'react', identifier);\n }\n\n /**\n * Track a non-translation variable (convenience method)\n */\n trackRegularVariable(variableName: string, assignedValue: string): void {\n this.trackVariable(variableName, assignedValue, false, 'other', 0); // 0 because we don't care about the identifier\n }\n\n /* =============================== */\n /* Variable Retrieval Methods */\n /* =============================== */\n\n /**\n * Find if a variable is accessible in the current scope\n */\n getVariable(variableName: string): ScopedVariable | undefined {\n const variables = this.scopedVariables.get(variableName);\n if (variables && variables.length > 0) {\n // Return the last (most recent) variable - handles shadowing\n return variables[variables.length - 1];\n }\n return undefined;\n }\n\n /**\n * Get the translation variable info if it exists in current scope\n */\n getTranslationVariable(variableName: string): ScopedGTFunction | undefined {\n const variable = this.getVariable(variableName);\n if (!variable) {\n return undefined;\n }\n\n // Check if the variable is a translation function\n if (!this.isScopedGTFunction(variable)) {\n return undefined;\n }\n return variable;\n }\n\n private isScopedGTFunction(\n variable: ScopedVariable\n ): variable is ScopedGTFunction {\n return variable.type === 'generaltranslation';\n }\n\n /* =============================== */\n /* Namespace Import Methods */\n /* =============================== */\n\n /**\n * Add a namespace import (e.g., GT from 'gt-next')\n */\n addNamespaceImport(name: string): void {\n this.namespaceImports.add(name);\n }\n\n /**\n * Check if a namespace import exists\n */\n hasNamespaceImport(name: string): boolean {\n return this.namespaceImports.has(name);\n }\n\n /* =============================== */\n /* Debugging Methods */\n /* =============================== */\n\n /**\n * Get scope info for debugging\n */\n getScopeInfo(scopeId: number): ScopeInfo | undefined {\n return this.scopeInfo.get(scopeId) || undefined;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedScopeTracker {\n return {\n nextScopeId: this.nextScopeId,\n currentScope: this.currentScope,\n scopeStack: this.scopeStack,\n scopeInfo: Object.fromEntries(this.scopeInfo),\n scopedVariables: Object.fromEntries(this.scopedVariables),\n namespaceImports: Array.from(this.namespaceImports),\n };\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedScopeTracker): void {\n this.nextScopeId = input.nextScopeId;\n this.currentScope = input.currentScope;\n this.scopeStack = input.scopeStack;\n this.scopeInfo = new Map(\n Object.entries(input.scopeInfo).map(([key, value]) => [\n Number(key),\n value as ScopeInfo,\n ])\n );\n this.scopedVariables = new Map(Object.entries(input.scopedVariables));\n this.namespaceImports = new Set(input.namespaceImports);\n }\n}\n"],"mappings":";;;;;AAqEA,IAAa,eAAb,MAA0B;;qBAEM;sBAEC;oBAEA,EAAE;mCAEW,IAAI,KAAK;yCAEI,IAAI,KAAK;0CAE1B,IAAI,KAAK;;;;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/**\n * Scope Tracker - Handles variable scoping and import tracking\n *\n * Tracks useGT/getGT variable assignments across nested scopes\n * Manages variable shadowing and GT component imports\n */\n\nimport {\n GT_ALL_FUNCTIONS,\n GT_CALLBACK_FUNCTIONS,\n} from '../utils/constants/gt/constants';\n\n// TODO: separate callback funtions and imported functions\n\n/**\n * Information about a scope\n */\nexport interface ScopeInfo {\n /** The scope ID */\n id: number;\n /** The parent scope ID */\n parentId: number;\n /** The depth of the scope */\n depth: number;\n}\n\n/**\n * Variable type represents which group the variable belongs to\n */\nexport type VariableType = 'generaltranslation' | 'react' | 'other';\n\n/**\n * Information about a scoped variable assignment\n */\nexport interface ScopedVariable {\n /** The scope ID */\n scopeId: number;\n /** The canonical name of the variable (useGT, getGT, T, etc.) */\n canonicalName: string | GT_ALL_FUNCTIONS;\n /** The variable name (t, translationFunction, etc.) */\n aliasName: string;\n type: VariableType;\n /** The identifier for the variable */\n identifier: number;\n}\n\nexport interface ScopedGTFunction extends ScopedVariable {\n /** The canonical name of the GT function (useGT, getGT, etc.) */\n canonicalName: GT_ALL_FUNCTIONS;\n /** The type of GT function */\n type: 'generaltranslation';\n}\n\ntype SerializedScopeTracker = {\n nextScopeId: number;\n currentScope: number;\n scopeStack: number[];\n scopeInfo: Record<string, ScopeInfo>;\n scopedVariables: Record<string, ScopedVariable[]>;\n namespaceImports: string[];\n};\n\n/**\n * Tracks scope hierarchy and variable assignments within scopes\n */\nexport class ScopeTracker {\n /** Next scope ID to assign */\n private nextScopeId: number = 1; // Start at 1, reserve 0 for \"no scope\"\n /** Current scope being processed */\n private currentScope: number = 0;\n /** Stack to track scope nesting for proper exit handling */\n private scopeStack: number[] = [];\n /** Information about each scope */\n private scopeInfo: Map<number, ScopeInfo> = new Map();\n /** Variables tracked per scope */\n private scopedVariables: Map<string, ScopedVariable[]> = new Map();\n /** Namespace imports (e.g., GT from 'gt-next') */\n private namespaceImports: Set<string> = new Set();\n\n /* =============================== */\n /* Scope Tracker Methods */\n /* =============================== */\n\n /**\n * Enter a new scope and return the new scope ID\n */\n enterScope(): number {\n const newScopeId = this.nextScopeId;\n this.nextScopeId += 1;\n\n const scopeInfo: ScopeInfo = {\n id: newScopeId,\n parentId: this.currentScope,\n depth: this.currentScope !== 0 ? this.scopeStack.length + 1 : 0,\n };\n\n this.scopeInfo.set(newScopeId, scopeInfo);\n\n // Push current scope to stack\n this.scopeStack.push(this.currentScope);\n\n this.currentScope = newScopeId;\n return newScopeId;\n }\n\n /**\n * Exit the current scope and return to parent (with aggressive cleanup)\n */\n exitScope(): void {\n if (this.currentScope === 0) {\n return;\n }\n\n // Remove all variables from the exiting scope immediately\n for (const [varName, variables] of this.scopedVariables.entries()) {\n // Filter out variables from the current scope\n // TODO: there is definitely an O(1) solution here rather than iterating over each entire list\n const filteredVars = variables.filter(\n (variable) => variable.scopeId !== this.currentScope\n );\n\n if (filteredVars.length === 0) {\n // Remove empty variable name entries\n this.scopedVariables.delete(varName);\n } else {\n this.scopedVariables.set(varName, filteredVars);\n }\n }\n\n // Get parent scope from the scope info before removing it\n const parentId = this.scopeInfo.get(this.currentScope)?.parentId || 0;\n\n // Remove scope info for the exiting scope\n this.scopeInfo.delete(this.currentScope);\n\n // Update current scope to parent\n this.currentScope = parentId;\n\n // Pop from stack if there are items\n if (this.scopeStack.length > 0) {\n this.scopeStack.pop();\n }\n }\n\n /* =============================== */\n /* Variable Tracking Methods */\n /* =============================== */\n\n /**\n * Track a variable assignment in the current scope\n */\n trackVariable(\n aliasName: string,\n canonicalName: string,\n type: VariableType,\n identifier: number\n ): void {\n const scopedVar: ScopedVariable = {\n scopeId: this.currentScope,\n canonicalName,\n aliasName,\n type,\n identifier,\n };\n\n const existingVars = this.scopedVariables.get(aliasName) || [];\n existingVars.push(scopedVar);\n this.scopedVariables.set(aliasName, existingVars);\n }\n\n /**\n * Track a translation function variable\n */\n trackTranslationVariable(\n aliasName: string,\n canonicalName: GT_ALL_FUNCTIONS,\n identifier: number\n ): void {\n this.trackVariable(\n aliasName,\n canonicalName,\n 'generaltranslation',\n identifier\n );\n }\n\n /**\n * Track a translation callback function variable\n * const useGT_callback = useGT()\n * @param aliasName - The alias name of callback variable\n * @param canonicalName - The canonical name of the callback function\n * @param identifier - The identifier of the callback function\n * TODO: canonicalName might have to be shifted to the name of the RValue eg useGT in t = useGT() so you can properly map back to the original function\n */\n trackTranslationCallbackVariable(\n aliasName: string,\n canonicalName: GT_CALLBACK_FUNCTIONS,\n identifier: number\n ): void {\n this.trackVariable(\n aliasName,\n canonicalName,\n 'generaltranslation',\n identifier\n );\n }\n\n /**\n * Track react variable\n */\n trackReactVariable(\n variableName: string,\n assignedValue: string,\n identifier: number\n ): void {\n this.trackVariable(variableName, assignedValue, 'react', identifier);\n }\n\n /**\n * Track a non-translation variable (convenience method)\n */\n trackRegularVariable(variableName: string, assignedValue: string): void {\n this.trackVariable(variableName, assignedValue, 'other', 0); // 0 because we don't care about the identifier\n }\n\n /* =============================== */\n /* Variable Retrieval Methods */\n /* =============================== */\n\n /**\n * Find if a variable is accessible in the current scope\n */\n getVariable(variableName: string): ScopedVariable | undefined {\n const variables = this.scopedVariables.get(variableName);\n if (variables && variables.length > 0) {\n // Return the last (most recent) variable - handles shadowing\n return variables[variables.length - 1];\n }\n return undefined;\n }\n\n /**\n * Get the translation variable info if it exists in current scope\n */\n getTranslationVariable(variableName: string): ScopedGTFunction | undefined {\n const variable = this.getVariable(variableName);\n if (!variable) {\n return undefined;\n }\n\n // Check if the variable is a translation function\n if (!this.isScopedGTFunction(variable)) {\n return undefined;\n }\n return variable;\n }\n\n private isScopedGTFunction(\n variable: ScopedVariable\n ): variable is ScopedGTFunction {\n return variable.type === 'generaltranslation';\n }\n\n /* =============================== */\n /* Namespace Import Methods */\n /* =============================== */\n\n /**\n * Add a namespace import (e.g., GT from 'gt-next')\n */\n addNamespaceImport(name: string): void {\n this.namespaceImports.add(name);\n }\n\n /**\n * Check if a namespace import exists\n */\n hasNamespaceImport(name: string): boolean {\n return this.namespaceImports.has(name);\n }\n\n /* =============================== */\n /* Debugging Methods */\n /* =============================== */\n\n /**\n * Get scope info for debugging\n */\n getScopeInfo(scopeId: number): ScopeInfo | undefined {\n return this.scopeInfo.get(scopeId) || undefined;\n }\n\n /**\n * Helper convert to string\n */\n serialize(): SerializedScopeTracker {\n return {\n nextScopeId: this.nextScopeId,\n currentScope: this.currentScope,\n scopeStack: this.scopeStack,\n scopeInfo: Object.fromEntries(this.scopeInfo),\n scopedVariables: Object.fromEntries(this.scopedVariables),\n namespaceImports: Array.from(this.namespaceImports),\n };\n }\n\n /**\n * Helper to repopulate\n */\n unserialize(input: SerializedScopeTracker): void {\n this.nextScopeId = input.nextScopeId;\n this.currentScope = input.currentScope;\n this.scopeStack = input.scopeStack;\n this.scopeInfo = new Map(\n Object.entries(input.scopeInfo).map(([key, value]) => [\n Number(key),\n value as ScopeInfo,\n ])\n );\n this.scopedVariables = new Map(Object.entries(input.scopedVariables));\n this.namespaceImports = new Set(input.namespaceImports);\n }\n}\n"],"mappings":";;;;;AAiEA,IAAa,eAAb,MAA0B;;qBAEM;sBAEC;oBAEA,EAAE;mCAEW,IAAI,KAAK;yCAEI,IAAI,KAAK;0CAE1B,IAAI,KAAK;;;;;CASjD,aAAqB;EACnB,MAAM,aAAa,KAAK;AACxB,OAAK,eAAe;EAEpB,MAAM,YAAuB;GAC3B,IAAI;GACJ,UAAU,KAAK;GACf,OAAO,KAAK,iBAAiB,IAAI,KAAK,WAAW,SAAS,IAAI;GAC/D;AAED,OAAK,UAAU,IAAI,YAAY,UAAU;AAGzC,OAAK,WAAW,KAAK,KAAK,aAAa;AAEvC,OAAK,eAAe;AACpB,SAAO;;;;;CAMT,YAAkB;;AAChB,MAAI,KAAK,iBAAiB,EACxB;AAIF,OAAK,MAAM,CAAC,SAAS,cAAc,KAAK,gBAAgB,SAAS,EAAE;GAGjE,MAAM,eAAe,UAAU,QAC5B,aAAa,SAAS,YAAY,KAAK,aACzC;AAED,OAAI,aAAa,WAAW,EAE1B,MAAK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,IAAI,KAAK;;;;;CAUxC,aAAa,SAAwC;AACnD,SAAO,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAA;;;;;CAMxC,YAAoC;AAClC,SAAO;GACL,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB,YAAY,KAAK;GACjB,WAAW,OAAO,YAAY,KAAK,UAAU;GAC7C,iBAAiB,OAAO,YAAY,KAAK,gBAAgB;GACzD,kBAAkB,MAAM,KAAK,KAAK,iBAAiB;GACpD;;;;;CAMH,YAAY,OAAqC;AAC/C,OAAK,cAAc,MAAM;AACzB,OAAK,eAAe,MAAM;AAC1B,OAAK,aAAa,MAAM;AACxB,OAAK,YAAY,IAAI,IACnB,OAAO,QAAQ,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,WAAW,CACpD,OAAO,IAAI,EACX,MACD,CAAC,CACH;AACD,OAAK,kBAAkB,IAAI,IAAI,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACrE,OAAK,mBAAmB,IAAI,IAAI,MAAM,iBAAiB"}
|
|
@@ -33,6 +33,7 @@ function containsStatic(source) {
|
|
|
33
33
|
return handleChildren(source);
|
|
34
34
|
}
|
|
35
35
|
function handleChildren(source) {
|
|
36
|
+
if (source === null || typeof source === "boolean") return false;
|
|
36
37
|
if (Array.isArray(source)) return source.some((child) => handleChild(child));
|
|
37
38
|
return handleChild(source);
|
|
38
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // Delegate to the shared hasher without custom ids; ids are metadata only.\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n });\n }\n // For Jsx, we set hash to empty string if it contains a static component\n if (containsStatic(source)) {\n return '';\n }\n return _hashSource({ source, context, maxChars, requiresReview, dataFormat });\n}\n\n/* =============================================== */\n/* =============== HELPER FUNCTIONS ============== */\n/* =============================================== */\n\n/**\n * Check if the given source contains a static component\n * @param source\n */\nfunction containsStatic(source: JsxChildren): boolean {\n return handleChildren(source);\n}\n\nfunction handleChildren(source: JsxChildren): boolean {\n if (Array.isArray(source)) {\n return source.some((child) => handleChild(child));\n }\n return handleChild(source);\n}\n\nfunction handleChild(child: JsxChild): boolean {\n if (typeof child === 'string') {\n return false;\n }\n if (isVariable(child)) {\n return handleVariable(child);\n }\n return handleElement(child);\n}\n\nfunction handleVariable(variable: Variable): boolean {\n if (variable.v === ('s' as VariableType)) {\n return true;\n }\n return false;\n}\n\nfunction handleElement(element: JsxElement): boolean {\n // branches\n if (\n element.d &&\n element.d.t &&\n ['p', 'b'].includes(element.d.t) &&\n element.d.b\n ) {\n return Object.values(element.d.b).some((branch) => handleChildren(branch));\n }\n // children\n if (element.c) {\n return handleChildren(element.c);\n }\n return false;\n}\n\nfunction isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAwB,WAAW,EACjC,QACA,SACA,UACA,gBACA,cAOS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,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b,QAAO"}
|
|
1
|
+
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // Delegate to the shared hasher without custom ids; ids are metadata only.\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n });\n }\n // For Jsx, we set hash to empty string if it contains a static component\n if (containsStatic(source)) {\n return '';\n }\n return _hashSource({ source, context, maxChars, requiresReview, dataFormat });\n}\n\n/* =============================================== */\n/* =============== HELPER FUNCTIONS ============== */\n/* =============================================== */\n\n/**\n * Check if the given source contains a static component\n * @param source\n */\nfunction containsStatic(source: JsxChildren): boolean {\n return handleChildren(source);\n}\n\nfunction handleChildren(source: JsxChildren): boolean {\n if (source === null || typeof source === 'boolean') {\n return false;\n }\n if (Array.isArray(source)) {\n return source.some((child) => handleChild(child));\n }\n return handleChild(source);\n}\n\nfunction handleChild(child: JsxChild): boolean {\n if (typeof child === 'string') {\n return false;\n }\n if (isVariable(child)) {\n return handleVariable(child);\n }\n return handleElement(child);\n}\n\nfunction handleVariable(variable: Variable): boolean {\n if (variable.v === ('s' as VariableType)) {\n return true;\n }\n return false;\n}\n\nfunction handleElement(element: JsxElement): boolean {\n // branches\n if (\n element.d &&\n element.d.t &&\n ['p', 'b'].includes(element.d.t) &&\n element.d.b\n ) {\n return Object.values(element.d.b).some((branch) => handleChildren(branch));\n }\n // children\n if (element.c) {\n return handleChildren(element.c);\n }\n return false;\n}\n\nfunction isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAwB,WAAW,EACjC,QACA,SACA,UACA,gBACA,cAOS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,sBAAA,YAAmB;EACjB;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,KAAI,eAAe,OAAO,CACxB,QAAO;AAET,SAAA,GAAA,sBAAA,YAAmB;EAAE;EAAQ;EAAS;EAAU;EAAgB;EAAY,CAAC;;;;;;AAW/E,SAAS,eAAe,QAA8B;AACpD,QAAO,eAAe,OAAO;;AAG/B,SAAS,eAAe,QAA8B;AACpD,KAAI,WAAW,QAAQ,OAAO,WAAW,UACvC,QAAO;AAET,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,MAAM,UAAU,YAAY,MAAM,CAAC;AAEnD,QAAO,YAAY,OAAO;;AAG5B,SAAS,YAAY,OAA0B;AAC7C,KAAI,OAAO,UAAU,SACnB,QAAO;AAET,KAAI,WAAW,MAAM,CACnB,QAAO,eAAe,MAAM;AAE9B,QAAO,cAAc,MAAM;;AAG7B,SAAS,eAAe,UAA6B;AACnD,KAAI,SAAS,MAAO,IAClB,QAAO;AAET,QAAO;;AAGT,SAAS,cAAc,SAA8B;AAEnD,KACE,QAAQ,KACR,QAAQ,EAAE,KACV,CAAC,KAAK,IAAI,CAAC,SAAS,QAAQ,EAAE,EAAE,IAChC,QAAQ,EAAE,EAEV,QAAO,OAAO,OAAO,QAAQ,EAAE,EAAE,CAAC,MAAM,WAAW,eAAe,OAAO,CAAC;AAG5E,KAAI,QAAQ,EACV,QAAO,eAAe,QAAQ,EAAE;AAElC,QAAO;;AAGT,SAAS,WAAW,KAA+B;CACjD,MAAM,cAAc;AACpB,KACE,eACA,OAAO,gBAAgB,YACvB,OAAQ,YAAyB,MAAM,UACvC;EACA,MAAM,IAAI,OAAO,KAAK,YAAY;AAClC,MAAI,EAAE,WAAW,EAAG,QAAO;AAC3B,MAAI,EAAE,WAAW,GAAG;AAClB,OAAI,OAAO,YAAY,MAAM,SAAU,QAAO;AAC9C,OAAI,OAAO,YAAY,MAAM,SAAU,QAAO;;AAEhD,MAAI,EAAE,WAAW;OAEb,OAAO,YAAY,MAAM,YACzB,OAAO,YAAY,MAAM,SAEzB,QAAO;;;AAGb,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generaltranslation/compiler",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.38-iris.0",
|
|
4
4
|
"description": "Universal plugin for compile-time optimization of GT translation components",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"author": "General Translation, Inc.",
|
|
8
|
+
"license": "MIT",
|
|
8
9
|
"repository": {
|
|
9
10
|
"type": "git",
|
|
10
11
|
"url": "git+https://github.com/generaltranslation/gt.git"
|
|
@@ -25,8 +26,8 @@
|
|
|
25
26
|
"@babel/traverse": "^7.23.0",
|
|
26
27
|
"@babel/types": "^7.23.0",
|
|
27
28
|
"unplugin": "^2.3.10",
|
|
28
|
-
"@generaltranslation/format": "0.1.
|
|
29
|
-
"generaltranslation": "9.1.
|
|
29
|
+
"@generaltranslation/format": "0.1.5-iris.0",
|
|
30
|
+
"generaltranslation": "9.1.3-iris.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@types/babel__core": "^7.20.0",
|