@generaltranslation/compiler 1.3.22 → 1.3.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +23 -0
- package/dist/config.js +32 -27
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -187
- package/dist/index.js.map +1 -1
- package/dist/passes/basePass.js +40 -83
- package/dist/passes/basePass.js.map +1 -1
- package/dist/passes/collectionPass.js +18 -11
- package/dist/passes/collectionPass.js.map +1 -1
- package/dist/passes/handleErrors.js +21 -30
- package/dist/passes/handleErrors.js.map +1 -1
- package/dist/passes/injectionPass.js +15 -9
- package/dist/passes/injectionPass.js.map +1 -1
- package/dist/passes/jsxInsertionPass.js +33 -31
- package/dist/passes/jsxInsertionPass.js.map +1 -1
- package/dist/passes/macroExpansionPass.js +28 -26
- package/dist/passes/macroExpansionPass.js.map +1 -1
- package/dist/passes/runtimeTranslatePass.js +37 -35
- package/dist/passes/runtimeTranslatePass.js.map +1 -1
- package/dist/processing/collection/processCallExpression.js +144 -249
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.js +38 -75
- package/dist/processing/collection/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/collection/processVariableDeclarator.js +20 -18
- package/dist/processing/collection/processVariableDeclarator.js.map +1 -1
- package/dist/processing/index.js +29 -31
- package/dist/processing/injection/processCallExpression.js +69 -142
- package/dist/processing/injection/processCallExpression.js.map +1 -1
- package/dist/processing/injection/processVariableDeclarator.js +22 -20
- package/dist/processing/injection/processVariableDeclarator.js.map +1 -1
- package/dist/processing/jsx-insertion/processCallExpression.js +284 -393
- package/dist/processing/jsx-insertion/processCallExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processImportDeclaration.js +37 -83
- package/dist/processing/jsx-insertion/processImportDeclaration.js.map +1 -1
- package/dist/processing/jsx-insertion/processProgram.js +26 -66
- package/dist/processing/jsx-insertion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processImportDeclaration.js +21 -55
- package/dist/processing/macro-expansion/processImportDeclaration.js.map +1 -1
- package/dist/processing/macro-expansion/processProgram.js +20 -26
- package/dist/processing/macro-expansion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js +33 -69
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/processArrowFunctionExpression.js +18 -16
- package/dist/processing/processArrowFunctionExpression.js.map +1 -1
- package/dist/processing/processAssignmentExpression.js +12 -10
- package/dist/processing/processAssignmentExpression.js.map +1 -1
- package/dist/processing/processCatchClause.js +18 -16
- package/dist/processing/processCatchClause.js.map +1 -1
- package/dist/processing/processClassDeclaration.js +18 -16
- package/dist/processing/processClassDeclaration.js.map +1 -1
- package/dist/processing/processClassMethod.js +18 -17
- package/dist/processing/processClassMethod.js.map +1 -1
- package/dist/processing/processClassPrivateMethod.js +18 -17
- package/dist/processing/processClassPrivateMethod.js.map +1 -1
- package/dist/processing/processForInStatement.js +18 -16
- package/dist/processing/processForInStatement.js.map +1 -1
- package/dist/processing/processForOfStatement.js +18 -16
- package/dist/processing/processForOfStatement.js.map +1 -1
- package/dist/processing/processFunctionDeclaration.js +20 -18
- package/dist/processing/processFunctionDeclaration.js.map +1 -1
- package/dist/processing/processFunctionExpression.js +26 -24
- package/dist/processing/processFunctionExpression.js.map +1 -1
- package/dist/processing/processImportDeclaration.js +11 -9
- package/dist/processing/processImportDeclaration.js.map +1 -1
- package/dist/processing/processObjectMethod.js +19 -18
- package/dist/processing/processObjectMethod.js.map +1 -1
- package/dist/processing/processProgram.js +13 -13
- package/dist/processing/processProgram.js.map +1 -1
- package/dist/processing/processScopeChange.js +15 -13
- package/dist/processing/processScopeChange.js.map +1 -1
- package/dist/processing/runtime-translate/processImportDeclaration.js +30 -63
- package/dist/processing/runtime-translate/processImportDeclaration.js.map +1 -1
- package/dist/processing/runtime-translate/processProgram.js +34 -57
- package/dist/processing/runtime-translate/processProgram.js.map +1 -1
- package/dist/state/ErrorTracker.js +18 -17
- package/dist/state/ErrorTracker.js.map +1 -1
- package/dist/state/Logger.js +42 -52
- package/dist/state/Logger.js.map +1 -1
- package/dist/state/ScopeTracker.js +154 -209
- package/dist/state/ScopeTracker.js.map +1 -1
- package/dist/state/StringCollector.js +165 -184
- package/dist/state/StringCollector.js.map +1 -1
- package/dist/state/types.js +1 -3
- package/dist/state/utils/initializeState.js +62 -67
- package/dist/state/utils/initializeState.js.map +1 -1
- package/dist/transform/getTrackedVariable.js +33 -38
- package/dist/transform/getTrackedVariable.js.map +1 -1
- package/dist/transform/injection/callbacks/injectUseGTCallbackParameters.js +19 -27
- package/dist/transform/injection/callbacks/injectUseGTCallbackParameters.js.map +1 -1
- package/dist/transform/injection/callbacks/injectUseMessagesCallbackParameters.js +8 -6
- package/dist/transform/injection/callbacks/injectUseMessagesCallbackParameters.js.map +1 -1
- package/dist/transform/injection/callbacks/injectUseTranslationsCallbackParameters.js +8 -6
- package/dist/transform/injection/callbacks/injectUseTranslationsCallbackParameters.js.map +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js +74 -155
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js.map +1 -1
- package/dist/transform/injection/injectHashIntoTranslationOptions.js +21 -61
- package/dist/transform/injection/injectHashIntoTranslationOptions.js.map +1 -1
- package/dist/transform/injection/injectStandaloneTFunctionParameters.js +21 -27
- package/dist/transform/injection/injectStandaloneTFunctionParameters.js.map +1 -1
- package/dist/transform/injection/injectTComponentParameters.js +25 -65
- package/dist/transform/injection/injectTComponentParameters.js.map +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.js +273 -392
- package/dist/transform/jsx-children/constructJsxChildren.js.map +1 -1
- package/dist/transform/jsx-children/errors.js +16 -6
- package/dist/transform/jsx-children/errors.js.map +1 -1
- package/dist/transform/jsx-children/index.js +3 -6
- package/dist/transform/jsx-children/utils/getBranchComponentParameters.js +26 -85
- package/dist/transform/jsx-children/utils/getBranchComponentParameters.js.map +1 -1
- package/dist/transform/jsx-children/utils/getCalleeNameFromJsxExpressionParam.js +33 -66
- package/dist/transform/jsx-children/utils/getCalleeNameFromJsxExpressionParam.js.map +1 -1
- package/dist/transform/jsx-children/utils/id.js +18 -17
- package/dist/transform/jsx-children/utils/id.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateChildrenElement.js +13 -47
- package/dist/transform/jsx-children/validation/validateChildrenElement.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateChildrenFromArgs.js +25 -63
- package/dist/transform/jsx-children/validation/validateChildrenFromArgs.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateIdentifier.js +38 -41
- package/dist/transform/jsx-children/validation/validateIdentifier.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateJsxCall.js +15 -26
- package/dist/transform/jsx-children/validation/validateJsxCall.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateNameFieldForVarComponent.js +33 -61
- package/dist/transform/jsx-children/validation/validateNameFieldForVarComponent.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateStringLiteralPropertyFromArg.js +38 -66
- package/dist/transform/jsx-children/validation/validateStringLiteralPropertyFromArg.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateTemplateLiteral.js +17 -13
- package/dist/transform/jsx-children/validation/validateTemplateLiteral.js.map +1 -1
- package/dist/transform/jsx-children/validation/validateUnaryExpression.js +26 -61
- package/dist/transform/jsx-children/validation/validateUnaryExpression.js.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js +16 -48
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js.map +1 -1
- package/dist/transform/macro-expansion/injectMacroImport.js +14 -43
- package/dist/transform/macro-expansion/injectMacroImport.js.map +1 -1
- package/dist/transform/macro-expansion/transformTemplateLiteral.js +23 -22
- package/dist/transform/macro-expansion/transformTemplateLiteral.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js +27 -34
- package/dist/transform/registration/callbacks/registerUseGTCallback.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseMessagesCallback.js +9 -9
- package/dist/transform/registration/callbacks/registerUseMessagesCallback.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseTranslationsCallback.js +9 -9
- package/dist/transform/registration/callbacks/registerUseTranslationsCallback.js.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.js +27 -28
- package/dist/transform/registration/registerStandaloneTranslation.js.map +1 -1
- package/dist/transform/registration/registerTranslationComponent.js +15 -15
- package/dist/transform/registration/registerTranslationComponent.js.map +1 -1
- package/dist/transform/runtime-translate/buildRuntimeTranslateCalls.js +34 -85
- package/dist/transform/runtime-translate/buildRuntimeTranslateCalls.js.map +1 -1
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.js +25 -55
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.js.map +1 -1
- package/dist/transform/tracking/trackAssignmentExpression.js +26 -63
- package/dist/transform/tracking/trackAssignmentExpression.js.map +1 -1
- package/dist/transform/tracking/trackCatchClause.js +17 -48
- package/dist/transform/tracking/trackCatchClause.js.map +1 -1
- package/dist/transform/tracking/trackClassDeclaration.js +13 -13
- package/dist/transform/tracking/trackClassDeclaration.js.map +1 -1
- package/dist/transform/tracking/trackForDeclaration.js +17 -53
- package/dist/transform/tracking/trackForDeclaration.js.map +1 -1
- package/dist/transform/tracking/trackFunctionName.js +10 -10
- package/dist/transform/tracking/trackFunctionName.js.map +1 -1
- package/dist/transform/tracking/trackFunctionParams.js +19 -54
- package/dist/transform/tracking/trackFunctionParams.js.map +1 -1
- package/dist/transform/tracking/trackImportDeclaration.js +36 -89
- package/dist/transform/tracking/trackImportDeclaration.js.map +1 -1
- package/dist/transform/tracking/trackOverridingVariable.js +9 -11
- package/dist/transform/tracking/trackOverridingVariable.js.map +1 -1
- package/dist/transform/tracking/trackVariableDeclarator.js +51 -102
- package/dist/transform/tracking/trackVariableDeclarator.js.map +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.js +156 -232
- package/dist/transform/validation/validateTranslationComponentArgs.js.map +1 -1
- package/dist/transform/validation/validateTranslationFunction.js +218 -329
- package/dist/transform/validation/validateTranslationFunction.js.map +1 -1
- package/dist/utils/calculateHash.js +55 -70
- package/dist/utils/calculateHash.js.map +1 -1
- package/dist/utils/constants/gt/constants.js +142 -132
- package/dist/utils/constants/gt/constants.js.map +1 -1
- package/dist/utils/constants/gt/helpers.js +147 -149
- package/dist/utils/constants/gt/helpers.js.map +1 -1
- package/dist/utils/constants/other/constants.js +45 -41
- package/dist/utils/constants/other/constants.js.map +1 -1
- package/dist/utils/constants/other/helpers.js +13 -11
- package/dist/utils/constants/other/helpers.js.map +1 -1
- package/dist/utils/constants/react/constants.js +47 -41
- package/dist/utils/constants/react/constants.js.map +1 -1
- package/dist/utils/constants/react/helpers.js +17 -16
- package/dist/utils/constants/react/helpers.js.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js +41 -76
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js +33 -83
- package/dist/utils/constants/resolveIdentifier/isReactJsxFunction.js.map +1 -1
- package/dist/utils/errors.js +18 -20
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/multiplication/multiply.js +31 -35
- package/dist/utils/multiplication/multiply.js.map +1 -1
- package/dist/utils/multiplication/types.js +1 -3
- package/dist/utils/parsing/extractIdentifiersFromLVal.js +30 -96
- package/dist/utils/parsing/extractIdentifiersFromLVal.js.map +1 -1
- package/dist/utils/parsing/getCalleeNameFromExpression.js +31 -65
- package/dist/utils/parsing/getCalleeNameFromExpression.js.map +1 -1
- package/dist/utils/parsing/getCalleeNameFromExpressionWrapper.js +13 -10
- package/dist/utils/parsing/getCalleeNameFromExpressionWrapper.js.map +1 -1
- package/dist/utils/parsing/getObjectPropertyFromObjectExpression.js +19 -56
- package/dist/utils/parsing/getObjectPropertyFromObjectExpression.js.map +1 -1
- package/dist/utils/parsing/getStringLiteralFromExpression.js +18 -49
- package/dist/utils/parsing/getStringLiteralFromExpression.js.map +1 -1
- package/dist/utils/parsing/isDeriveInvocation.js +25 -61
- package/dist/utils/parsing/isDeriveInvocation.js.map +1 -1
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.js +23 -59
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.js.map +1 -1
- package/dist/utils/string-expressions/buildTransformationResult.js +57 -96
- package/dist/utils/string-expressions/buildTransformationResult.js.map +1 -1
- package/dist/utils/string-expressions/flattenExpressionToParts.js +131 -142
- package/dist/utils/string-expressions/flattenExpressionToParts.js.map +1 -1
- package/dist/utils/string-expressions/resolveStaticExpression.js +36 -34
- package/dist/utils/string-expressions/resolveStaticExpression.js.map +1 -1
- package/dist/utils/validation/validateChildrenFromObjectExpression.js +29 -24
- package/dist/utils/validation/validateChildrenFromObjectExpression.js.map +1 -1
- package/dist/utils/validation/validateExpressionIsNumericLiteral.js +13 -47
- package/dist/utils/validation/validateExpressionIsNumericLiteral.js.map +1 -1
- package/dist/utils/validation/validateExpressionIsStringLiteral.js +15 -48
- package/dist/utils/validation/validateExpressionIsStringLiteral.js.map +1 -1
- package/package.json +8 -5
- package/dist/processing/index.js.map +0 -1
- package/dist/state/types.js.map +0 -1
- package/dist/transform/jsx-children/index.js.map +0 -1
- package/dist/utils/multiplication/types.js.map +0 -1
|
@@ -1,212 +1,157 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/state/ScopeTracker.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return variable;
|
|
155
|
-
}
|
|
156
|
-
isScopedGTFunction(variable) {
|
|
157
|
-
return variable.type === 'generaltranslation';
|
|
158
|
-
}
|
|
159
|
-
/* =============================== */
|
|
160
|
-
/* Namespace Import Methods */
|
|
161
|
-
/* =============================== */
|
|
162
|
-
/**
|
|
163
|
-
* Add a namespace import (e.g., GT from 'gt-next')
|
|
164
|
-
*/
|
|
165
|
-
addNamespaceImport(name) {
|
|
166
|
-
this.namespaceImports.add(name);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Check if a namespace import exists
|
|
170
|
-
*/
|
|
171
|
-
hasNamespaceImport(name) {
|
|
172
|
-
return this.namespaceImports.has(name);
|
|
173
|
-
}
|
|
174
|
-
/* =============================== */
|
|
175
|
-
/* Debugging Methods */
|
|
176
|
-
/* =============================== */
|
|
177
|
-
/**
|
|
178
|
-
* Get scope info for debugging
|
|
179
|
-
*/
|
|
180
|
-
getScopeInfo(scopeId) {
|
|
181
|
-
return this.scopeInfo.get(scopeId) || undefined;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Helper convert to string
|
|
185
|
-
*/
|
|
186
|
-
serialize() {
|
|
187
|
-
return {
|
|
188
|
-
nextScopeId: this.nextScopeId,
|
|
189
|
-
currentScope: this.currentScope,
|
|
190
|
-
scopeStack: this.scopeStack,
|
|
191
|
-
scopeInfo: Object.fromEntries(this.scopeInfo),
|
|
192
|
-
scopedVariables: Object.fromEntries(this.scopedVariables),
|
|
193
|
-
namespaceImports: Array.from(this.namespaceImports),
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Helper to repopulate
|
|
198
|
-
*/
|
|
199
|
-
unserialize(input) {
|
|
200
|
-
this.nextScopeId = input.nextScopeId;
|
|
201
|
-
this.currentScope = input.currentScope;
|
|
202
|
-
this.scopeStack = input.scopeStack;
|
|
203
|
-
this.scopeInfo = new Map(Object.entries(input.scopeInfo).map(([key, value]) => [
|
|
204
|
-
Number(key),
|
|
205
|
-
value,
|
|
206
|
-
]));
|
|
207
|
-
this.scopedVariables = new Map(Object.entries(input.scopedVariables));
|
|
208
|
-
this.namespaceImports = new Set(input.namespaceImports);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
4
|
+
* Tracks scope hierarchy and variable assignments within scopes
|
|
5
|
+
*/
|
|
6
|
+
var ScopeTracker = class {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.nextScopeId = 1;
|
|
9
|
+
this.currentScope = 0;
|
|
10
|
+
this.scopeStack = [];
|
|
11
|
+
this.scopeInfo = /* @__PURE__ */ new Map();
|
|
12
|
+
this.scopedVariables = /* @__PURE__ */ new Map();
|
|
13
|
+
this.namespaceImports = /* @__PURE__ */ new Set();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Enter a new scope and return the new scope ID
|
|
17
|
+
*/
|
|
18
|
+
enterScope() {
|
|
19
|
+
const newScopeId = this.nextScopeId;
|
|
20
|
+
this.nextScopeId += 1;
|
|
21
|
+
const scopeInfo = {
|
|
22
|
+
id: newScopeId,
|
|
23
|
+
parentId: this.currentScope,
|
|
24
|
+
depth: this.currentScope !== 0 ? this.scopeStack.length + 1 : 0
|
|
25
|
+
};
|
|
26
|
+
this.scopeInfo.set(newScopeId, scopeInfo);
|
|
27
|
+
this.scopeStack.push(this.currentScope);
|
|
28
|
+
this.currentScope = newScopeId;
|
|
29
|
+
return newScopeId;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Exit the current scope and return to parent (with aggressive cleanup)
|
|
33
|
+
*/
|
|
34
|
+
exitScope() {
|
|
35
|
+
var _this$scopeInfo$get;
|
|
36
|
+
if (this.currentScope === 0) return;
|
|
37
|
+
for (const [varName, variables] of this.scopedVariables.entries()) {
|
|
38
|
+
const filteredVars = variables.filter((variable) => variable.scopeId !== this.currentScope);
|
|
39
|
+
if (filteredVars.length === 0) this.scopedVariables.delete(varName);
|
|
40
|
+
else this.scopedVariables.set(varName, filteredVars);
|
|
41
|
+
}
|
|
42
|
+
const parentId = ((_this$scopeInfo$get = this.scopeInfo.get(this.currentScope)) === null || _this$scopeInfo$get === void 0 ? void 0 : _this$scopeInfo$get.parentId) || 0;
|
|
43
|
+
this.scopeInfo.delete(this.currentScope);
|
|
44
|
+
this.currentScope = parentId;
|
|
45
|
+
if (this.scopeStack.length > 0) this.scopeStack.pop();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Track a variable assignment in the current scope
|
|
49
|
+
*/
|
|
50
|
+
trackVariable(aliasName, canonicalName, isTranslationFunction, type, identifier) {
|
|
51
|
+
const scopedVar = {
|
|
52
|
+
scopeId: this.currentScope,
|
|
53
|
+
canonicalName,
|
|
54
|
+
aliasName,
|
|
55
|
+
isTranslationFunction,
|
|
56
|
+
type,
|
|
57
|
+
identifier
|
|
58
|
+
};
|
|
59
|
+
const existingVars = this.scopedVariables.get(aliasName) || [];
|
|
60
|
+
existingVars.push(scopedVar);
|
|
61
|
+
this.scopedVariables.set(aliasName, existingVars);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Track a translation function variable
|
|
65
|
+
*/
|
|
66
|
+
trackTranslationVariable(aliasName, canonicalName, identifier) {
|
|
67
|
+
this.trackVariable(aliasName, canonicalName, true, "generaltranslation", identifier);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Track a translation callback function variable
|
|
71
|
+
* const useGT_callback = useGT()
|
|
72
|
+
* @param aliasName - The alias name of callback variable
|
|
73
|
+
* @param canonicalName - The canonical name of the callback function
|
|
74
|
+
* @param identifier - The identifier of the callback function
|
|
75
|
+
* 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
|
+
*/
|
|
77
|
+
trackTranslationCallbackVariable(aliasName, canonicalName, identifier) {
|
|
78
|
+
this.trackVariable(aliasName, canonicalName, true, "generaltranslation", identifier);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Track react variable
|
|
82
|
+
*/
|
|
83
|
+
trackReactVariable(variableName, assignedValue, identifier) {
|
|
84
|
+
this.trackVariable(variableName, assignedValue, false, "react", identifier);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Track a non-translation variable (convenience method)
|
|
88
|
+
*/
|
|
89
|
+
trackRegularVariable(variableName, assignedValue) {
|
|
90
|
+
this.trackVariable(variableName, assignedValue, false, "other", 0);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Find if a variable is accessible in the current scope
|
|
94
|
+
*/
|
|
95
|
+
getVariable(variableName) {
|
|
96
|
+
const variables = this.scopedVariables.get(variableName);
|
|
97
|
+
if (variables && variables.length > 0) return variables[variables.length - 1];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the translation variable info if it exists in current scope
|
|
101
|
+
*/
|
|
102
|
+
getTranslationVariable(variableName) {
|
|
103
|
+
const variable = this.getVariable(variableName);
|
|
104
|
+
if (!variable) return;
|
|
105
|
+
if (!this.isScopedGTFunction(variable)) return;
|
|
106
|
+
return variable;
|
|
107
|
+
}
|
|
108
|
+
isScopedGTFunction(variable) {
|
|
109
|
+
return variable.type === "generaltranslation";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Add a namespace import (e.g., GT from 'gt-next')
|
|
113
|
+
*/
|
|
114
|
+
addNamespaceImport(name) {
|
|
115
|
+
this.namespaceImports.add(name);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a namespace import exists
|
|
119
|
+
*/
|
|
120
|
+
hasNamespaceImport(name) {
|
|
121
|
+
return this.namespaceImports.has(name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get scope info for debugging
|
|
125
|
+
*/
|
|
126
|
+
getScopeInfo(scopeId) {
|
|
127
|
+
return this.scopeInfo.get(scopeId) || void 0;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Helper convert to string
|
|
131
|
+
*/
|
|
132
|
+
serialize() {
|
|
133
|
+
return {
|
|
134
|
+
nextScopeId: this.nextScopeId,
|
|
135
|
+
currentScope: this.currentScope,
|
|
136
|
+
scopeStack: this.scopeStack,
|
|
137
|
+
scopeInfo: Object.fromEntries(this.scopeInfo),
|
|
138
|
+
scopedVariables: Object.fromEntries(this.scopedVariables),
|
|
139
|
+
namespaceImports: Array.from(this.namespaceImports)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Helper to repopulate
|
|
144
|
+
*/
|
|
145
|
+
unserialize(input) {
|
|
146
|
+
this.nextScopeId = input.nextScopeId;
|
|
147
|
+
this.currentScope = input.currentScope;
|
|
148
|
+
this.scopeStack = input.scopeStack;
|
|
149
|
+
this.scopeInfo = new Map(Object.entries(input.scopeInfo).map(([key, value]) => [Number(key), value]));
|
|
150
|
+
this.scopedVariables = new Map(Object.entries(input.scopedVariables));
|
|
151
|
+
this.namespaceImports = new Set(input.namespaceImports);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
//#endregion
|
|
211
155
|
exports.ScopeTracker = ScopeTracker;
|
|
156
|
+
|
|
212
157
|
//# sourceMappingURL=ScopeTracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScopeTracker.js","sourceRoot":"","sources":["../../src/state/Sc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,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,KAA6B;QACvC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CACtB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YACpD,MAAM,CAAC,GAAG,CAAC;YACX,KAAkB;SACnB,CAAC,CACH,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC1D,CAAC;CACF;AArQD,oCAqQC"}
|
|
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;;;;;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,gBAAgB,OAAO,QAAQ;OAEpC,MAAK,gBAAgB,IAAI,SAAS,aAAa;;EAKnD,MAAM,aAAA,sBAAW,KAAK,UAAU,IAAI,KAAK,aAAa,MAAA,QAAA,wBAAA,KAAA,IAAA,KAAA,IAAA,oBAAE,aAAY;AAGpE,OAAK,UAAU,OAAO,KAAK,aAAa;AAGxC,OAAK,eAAe;AAGpB,MAAI,KAAK,WAAW,SAAS,EAC3B,MAAK,WAAW,KAAK;;;;;CAWzB,cACE,WACA,eACA,uBACA,MACA,YACM;EACN,MAAM,YAA4B;GAChC,SAAS,KAAK;GACd;GACA;GACA;GACA;GACA;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