@generaltranslation/compiler 1.3.21 → 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.d.ts +11 -2
- package/dist/state/ScopeTracker.d.ts.map +1 -1
- package/dist/state/ScopeTracker.js +154 -209
- package/dist/state/ScopeTracker.js.map +1 -1
- package/dist/state/StringCollector.d.ts +9 -2
- package/dist/state/StringCollector.d.ts.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.d.ts +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.d.ts.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.d.ts +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.d.ts.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.d.ts +1 -1
- package/dist/utils/calculateHash.d.ts.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.d.ts +1 -1
- package/dist/utils/constants/gt/helpers.d.ts.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 -4
- 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,63 +1,27 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.isStringTranslationTaggedTemplate = isStringTranslationTaggedTemplate;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
const constants_1 = require("../constants/gt/constants");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
require("../constants/gt/constants.js");
|
|
4
|
+
let _babel_types = require("@babel/types");
|
|
5
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
|
+
//#region src/utils/parsing/isStringTranslationTaggedTemplate.ts
|
|
39
7
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
* Checks whether a tagged template expression should be treated as the GT
|
|
9
|
+
* string translation macro.
|
|
10
|
+
*
|
|
11
|
+
* The macro is valid when it is an unbound bare identifier, or when it is
|
|
12
|
+
* imported from gt-react/browser. This covers global `t`, but not explicit
|
|
13
|
+
* member access such as `globalThis.t` or `window.t`. Other bindings are left
|
|
14
|
+
* alone so local/i18next t tags do not get transformed or extracted.
|
|
15
|
+
*/
|
|
48
16
|
function isStringTranslationTaggedTemplate(path, symbol) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
if (!binding.path.isImportSpecifier()) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
const importDecl = binding.path.parentPath;
|
|
60
|
-
return ((importDecl === null || importDecl === void 0 ? void 0 : importDecl.isImportDeclaration()) === true &&
|
|
61
|
-
importDecl.node.source.value === constants_1.GT_IMPORT_SOURCES.GT_REACT_BROWSER);
|
|
17
|
+
if (!_babel_types.isIdentifier(path.node.tag, { name: symbol })) return false;
|
|
18
|
+
const binding = path.scope.getBinding(symbol);
|
|
19
|
+
if (!binding) return true;
|
|
20
|
+
if (!binding.path.isImportSpecifier()) return false;
|
|
21
|
+
const importDecl = binding.path.parentPath;
|
|
22
|
+
return (importDecl === null || importDecl === void 0 ? void 0 : importDecl.isImportDeclaration()) === true && importDecl.node.source.value === "gt-react/browser";
|
|
62
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.isStringTranslationTaggedTemplate = isStringTranslationTaggedTemplate;
|
|
26
|
+
|
|
63
27
|
//# sourceMappingURL=isStringTranslationTaggedTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isStringTranslationTaggedTemplate.js","
|
|
1
|
+
{"version":3,"file":"isStringTranslationTaggedTemplate.js","names":["t"],"sources":["../../../src/utils/parsing/isStringTranslationTaggedTemplate.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport * as t from '@babel/types';\nimport { GT_IMPORT_SOURCES } from '../constants/gt/constants';\n\n/**\n * Checks whether a tagged template expression should be treated as the GT\n * string translation macro.\n *\n * The macro is valid when it is an unbound bare identifier, or when it is\n * imported from gt-react/browser. This covers global `t`, but not explicit\n * member access such as `globalThis.t` or `window.t`. Other bindings are left\n * alone so local/i18next t tags do not get transformed or extracted.\n */\nexport function isStringTranslationTaggedTemplate(\n path: NodePath<t.TaggedTemplateExpression>,\n symbol: string\n): boolean {\n if (!t.isIdentifier(path.node.tag, { name: symbol })) {\n return false;\n }\n\n const binding = path.scope.getBinding(symbol);\n if (!binding) {\n return true;\n }\n\n if (!binding.path.isImportSpecifier()) {\n return false;\n }\n\n const importDecl = binding.path.parentPath;\n return (\n importDecl?.isImportDeclaration() === true &&\n importDecl.node.source.value === GT_IMPORT_SOURCES.GT_REACT_BROWSER\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,SAAgB,kCACd,MACA,QACS;AACT,KAAI,CAACA,aAAE,aAAa,KAAK,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC,CAClD,QAAO;CAGT,MAAM,UAAU,KAAK,MAAM,WAAW,OAAO;AAC7C,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,CAAC,QAAQ,KAAK,mBAAmB,CACnC,QAAO;CAGT,MAAM,aAAa,QAAQ,KAAK;AAChC,SAAA,eAAA,QAAA,eAAA,KAAA,IAAA,KAAA,IACE,WAAY,qBAAqB,MAAK,QACtC,WAAW,KAAK,OAAO,UAAA"}
|
|
@@ -1,100 +1,61 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.buildTransformResult = buildTransformResult;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let _babel_types = require("@babel/types");
|
|
4
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
5
|
+
//#region src/utils/string-expressions/buildTransformationResult.ts
|
|
38
6
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
7
|
+
* Converts merged parts into an AST message node and optional variables object.
|
|
8
|
+
*
|
|
9
|
+
* - All static → StringLiteral, no variables
|
|
10
|
+
* - Has derive/dynamic → TemplateLiteral with derive expressions preserved
|
|
11
|
+
* and dynamic values extracted as {n} placeholders
|
|
12
|
+
*/
|
|
45
13
|
function buildTransformResult(parts) {
|
|
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
|
-
properties.push(t.objectProperty(t.stringLiteral(key), part.node));
|
|
90
|
-
varIndex++;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
// Final quasi (tail)
|
|
94
|
-
flushQuasi(true);
|
|
95
|
-
return {
|
|
96
|
-
message: t.templateLiteral(quasis, expressions),
|
|
97
|
-
variables: properties.length > 0 ? t.objectExpression(properties) : null,
|
|
98
|
-
};
|
|
14
|
+
if (!parts.some((p) => p.type === "derive")) {
|
|
15
|
+
const properties = [];
|
|
16
|
+
let varIndex = 0;
|
|
17
|
+
let message = "";
|
|
18
|
+
for (const part of parts) if (part.type === "static") message += part.value;
|
|
19
|
+
else {
|
|
20
|
+
const key = varIndex.toString();
|
|
21
|
+
message += `{${key}}`;
|
|
22
|
+
properties.push(_babel_types.objectProperty(_babel_types.stringLiteral(key), part.node));
|
|
23
|
+
varIndex++;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
message: _babel_types.stringLiteral(message),
|
|
27
|
+
variables: properties.length > 0 ? _babel_types.objectExpression(properties) : null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const quasis = [];
|
|
31
|
+
const expressions = [];
|
|
32
|
+
const properties = [];
|
|
33
|
+
let varIndex = 0;
|
|
34
|
+
let quasiBuffer = "";
|
|
35
|
+
function flushQuasi(tail) {
|
|
36
|
+
quasis.push(_babel_types.templateElement({
|
|
37
|
+
raw: quasiBuffer,
|
|
38
|
+
cooked: quasiBuffer
|
|
39
|
+
}, tail));
|
|
40
|
+
quasiBuffer = "";
|
|
41
|
+
}
|
|
42
|
+
for (const part of parts) if (part.type === "static") quasiBuffer += part.value;
|
|
43
|
+
else if (part.type === "derive") {
|
|
44
|
+
flushQuasi(false);
|
|
45
|
+
expressions.push(part.node);
|
|
46
|
+
} else {
|
|
47
|
+
const key = varIndex.toString();
|
|
48
|
+
quasiBuffer += `{${key}}`;
|
|
49
|
+
properties.push(_babel_types.objectProperty(_babel_types.stringLiteral(key), part.node));
|
|
50
|
+
varIndex++;
|
|
51
|
+
}
|
|
52
|
+
flushQuasi(true);
|
|
53
|
+
return {
|
|
54
|
+
message: _babel_types.templateLiteral(quasis, expressions),
|
|
55
|
+
variables: properties.length > 0 ? _babel_types.objectExpression(properties) : null
|
|
56
|
+
};
|
|
99
57
|
}
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.buildTransformResult = buildTransformResult;
|
|
60
|
+
|
|
100
61
|
//# sourceMappingURL=buildTransformationResult.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTransformationResult.js","
|
|
1
|
+
{"version":3,"file":"buildTransformationResult.js","names":["t"],"sources":["../../../src/utils/string-expressions/buildTransformationResult.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { Part } from './flattenExpressionToParts';\n\n/**\n * Converts merged parts into an AST message node and optional variables object.\n *\n * - All static → StringLiteral, no variables\n * - Has derive/dynamic → TemplateLiteral with derive expressions preserved\n * and dynamic values extracted as {n} placeholders\n */\nexport function buildTransformResult(parts: Part[]): {\n message: t.StringLiteral | t.TemplateLiteral;\n variables: t.ObjectExpression | null;\n} {\n const hasDerive = parts.some((p) => p.type === 'derive');\n\n // No derive parts: collapse everything into a StringLiteral with {n} placeholders\n if (!hasDerive) {\n const properties: t.ObjectProperty[] = [];\n let varIndex = 0;\n let message = '';\n for (const part of parts) {\n if (part.type === 'static') {\n message += part.value;\n } else {\n const key = varIndex.toString();\n message += `{${key}}`;\n properties.push(t.objectProperty(t.stringLiteral(key), part.node));\n varIndex++;\n }\n }\n return {\n message: t.stringLiteral(message),\n variables: properties.length > 0 ? t.objectExpression(properties) : null,\n };\n }\n\n // Has derive parts: build a TemplateLiteral with derive expressions preserved\n const quasis: t.TemplateElement[] = [];\n const expressions: t.Expression[] = [];\n const properties: t.ObjectProperty[] = [];\n let varIndex = 0;\n let quasiBuffer = '';\n\n function flushQuasi(tail: boolean) {\n quasis.push(\n t.templateElement({ raw: quasiBuffer, cooked: quasiBuffer }, tail)\n );\n quasiBuffer = '';\n }\n\n for (const part of parts) {\n if (part.type === 'static') {\n quasiBuffer += part.value;\n } else if (part.type === 'derive') {\n flushQuasi(false);\n expressions.push(part.node);\n } else {\n const key = varIndex.toString();\n quasiBuffer += `{${key}}`;\n properties.push(t.objectProperty(t.stringLiteral(key), part.node));\n varIndex++;\n }\n }\n\n // Final quasi (tail)\n flushQuasi(true);\n\n return {\n message: t.templateLiteral(quasis, expressions),\n variables: properties.length > 0 ? t.objectExp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
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.INVALID_TEMPLATE_ESCAPE_ERROR = void 0;
|
|
37
|
-
exports.flattenExpressionToParts = flattenExpressionToParts;
|
|
38
|
-
const t = __importStar(require("@babel/types"));
|
|
39
|
-
const isDeriveInvocation_1 = require("../parsing/isDeriveInvocation");
|
|
40
|
-
exports.INVALID_TEMPLATE_ESCAPE_ERROR = 'Template literal contains an invalid escape sequence';
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_utils_parsing_isDeriveInvocation = require("../parsing/isDeriveInvocation.js");
|
|
4
|
+
let _babel_types = require("@babel/types");
|
|
5
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
|
+
//#region src/utils/string-expressions/flattenExpressionToParts.ts
|
|
7
|
+
const INVALID_TEMPLATE_ESCAPE_ERROR = "Template literal contains an invalid escape sequence";
|
|
41
8
|
const INVALID_TEMPLATE_ESCAPE = {
|
|
42
|
-
|
|
43
|
-
|
|
9
|
+
kind: "invalid-template-escape",
|
|
10
|
+
message: INVALID_TEMPLATE_ESCAPE_ERROR
|
|
44
11
|
};
|
|
45
12
|
const INVALID_EXPRESSION = {
|
|
46
|
-
|
|
47
|
-
|
|
13
|
+
kind: "invalid-expression",
|
|
14
|
+
message: "Expression is not a valid expression"
|
|
48
15
|
};
|
|
49
16
|
function isStaticPart(part) {
|
|
50
|
-
|
|
17
|
+
return part != null && "type" in part && part.type === "static";
|
|
51
18
|
}
|
|
52
19
|
function appendPart(parts, part) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
20
|
+
const lastPart = parts[parts.length - 1];
|
|
21
|
+
if (isStaticPart(lastPart) && isStaticPart(part)) {
|
|
22
|
+
lastPart.value += part.value;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
parts.push(part);
|
|
59
26
|
}
|
|
60
27
|
function appendParts(parts, nextParts) {
|
|
61
|
-
|
|
62
|
-
appendPart(parts, part);
|
|
63
|
-
}
|
|
28
|
+
for (const part of nextParts) appendPart(parts, part);
|
|
64
29
|
}
|
|
65
30
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
31
|
+
* Recursively decomposes an expression tree into a flat list of typed parts.
|
|
32
|
+
* Handles string/numeric/boolean/null literals, void expressions,
|
|
33
|
+
* template literals, and binary '+' concatenation. When a NodePath is
|
|
34
|
+
* provided, imported derive() calls are preserved as derive parts.
|
|
35
|
+
*
|
|
36
|
+
* Returns errors alongside parts so callers can report extraction failures
|
|
37
|
+
* without throwing during expression flattening. Adjacent static parts are
|
|
38
|
+
* coalesced before returning.
|
|
39
|
+
*/
|
|
75
40
|
function flattenExpressionToParts(exprPath) {
|
|
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
|
-
|
|
41
|
+
const expr = exprPath.node;
|
|
42
|
+
const scope = exprPath.scope;
|
|
43
|
+
if (_babel_types.isStringLiteral(expr)) return {
|
|
44
|
+
parts: [{
|
|
45
|
+
type: "static",
|
|
46
|
+
value: expr.value
|
|
47
|
+
}],
|
|
48
|
+
errors: []
|
|
49
|
+
};
|
|
50
|
+
if (_babel_types.isNumericLiteral(expr)) return {
|
|
51
|
+
parts: [{
|
|
52
|
+
type: "static",
|
|
53
|
+
value: String(expr.value)
|
|
54
|
+
}],
|
|
55
|
+
errors: []
|
|
56
|
+
};
|
|
57
|
+
if (_babel_types.isBooleanLiteral(expr)) return {
|
|
58
|
+
parts: [{
|
|
59
|
+
type: "static",
|
|
60
|
+
value: String(expr.value)
|
|
61
|
+
}],
|
|
62
|
+
errors: []
|
|
63
|
+
};
|
|
64
|
+
if (_babel_types.isNullLiteral(expr)) return {
|
|
65
|
+
parts: [{
|
|
66
|
+
type: "static",
|
|
67
|
+
value: "null"
|
|
68
|
+
}],
|
|
69
|
+
errors: []
|
|
70
|
+
};
|
|
71
|
+
if (_babel_types.isUnaryExpression(expr) && expr.operator === "void") return {
|
|
72
|
+
parts: [{
|
|
73
|
+
type: "dynamic",
|
|
74
|
+
node: expr
|
|
75
|
+
}],
|
|
76
|
+
errors: []
|
|
77
|
+
};
|
|
78
|
+
if (_babel_types.isTemplateLiteral(expr)) {
|
|
79
|
+
const result = {
|
|
80
|
+
parts: [],
|
|
81
|
+
errors: []
|
|
82
|
+
};
|
|
83
|
+
for (let i = 0; i < expr.quasis.length; i++) {
|
|
84
|
+
const cooked = expr.quasis[i].value.cooked;
|
|
85
|
+
if (cooked == null) {
|
|
86
|
+
result.errors.push(INVALID_TEMPLATE_ESCAPE);
|
|
87
|
+
return result;
|
|
88
|
+
} else if (cooked) appendPart(result.parts, {
|
|
89
|
+
type: "static",
|
|
90
|
+
value: cooked
|
|
91
|
+
});
|
|
92
|
+
if (i < expr.expressions.length) {
|
|
93
|
+
const exprPathIndex = exprPath.get("expressions")[i];
|
|
94
|
+
if (!exprPathIndex.isExpression()) {
|
|
95
|
+
result.errors.push(INVALID_EXPRESSION);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
const expressionResult = flattenExpressionToParts(exprPathIndex);
|
|
99
|
+
appendParts(result.parts, expressionResult.parts);
|
|
100
|
+
result.errors.push(...expressionResult.errors);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
if (_babel_types.isBinaryExpression(expr) && expr.operator === "+") {
|
|
106
|
+
const leftPath = exprPath.get("left");
|
|
107
|
+
if (!leftPath.isExpression()) return {
|
|
108
|
+
parts: [],
|
|
109
|
+
errors: [INVALID_EXPRESSION]
|
|
110
|
+
};
|
|
111
|
+
const { parts: leftParts, errors: leftErrors } = flattenExpressionToParts(leftPath);
|
|
112
|
+
const rightPath = exprPath.get("right");
|
|
113
|
+
if (!rightPath.isExpression()) return {
|
|
114
|
+
parts: [],
|
|
115
|
+
errors: [INVALID_EXPRESSION]
|
|
116
|
+
};
|
|
117
|
+
const { parts: rightParts, errors: rightErrors } = flattenExpressionToParts(rightPath);
|
|
118
|
+
const parts = [];
|
|
119
|
+
appendParts(parts, leftParts);
|
|
120
|
+
appendParts(parts, rightParts);
|
|
121
|
+
return {
|
|
122
|
+
parts,
|
|
123
|
+
errors: [...leftErrors, ...rightErrors]
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (require_utils_parsing_isDeriveInvocation.isDeriveInvocation(expr, scope)) return {
|
|
127
|
+
parts: [{
|
|
128
|
+
type: "derive",
|
|
129
|
+
node: expr
|
|
130
|
+
}],
|
|
131
|
+
errors: []
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
parts: [{
|
|
135
|
+
type: "dynamic",
|
|
136
|
+
node: expr
|
|
137
|
+
}],
|
|
138
|
+
errors: []
|
|
139
|
+
};
|
|
155
140
|
}
|
|
141
|
+
//#endregion
|
|
142
|
+
exports.INVALID_TEMPLATE_ESCAPE_ERROR = INVALID_TEMPLATE_ESCAPE_ERROR;
|
|
143
|
+
exports.flattenExpressionToParts = flattenExpressionToParts;
|
|
144
|
+
|
|
156
145
|
//# sourceMappingURL=flattenExpressionToParts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExpressionToParts.js","
|
|
1
|
+
{"version":3,"file":"flattenExpressionToParts.js","names":["t","isDeriveInvocation"],"sources":["../../../src/utils/string-expressions/flattenExpressionToParts.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { isDeriveInvocation } from '../parsing/isDeriveInvocation';\nimport { ResolutionNode } from '../multiplication/types';\n\nexport type Part =\n | { type: 'static'; value: string }\n | { type: 'derive'; node: t.Expression }\n | { type: 'dynamic'; node: t.Expression };\n\nexport const INVALID_TEMPLATE_ESCAPE_ERROR =\n 'Template literal contains an invalid escape sequence';\n\nexport type FlattenExpressionError = {\n kind: 'invalid-template-escape' | 'invalid-expression';\n message: string;\n};\n\nconst INVALID_TEMPLATE_ESCAPE: FlattenExpressionError = {\n kind: 'invalid-template-escape',\n message: INVALID_TEMPLATE_ESCAPE_ERROR,\n};\n\nconst INVALID_EXPRESSION: FlattenExpressionError = {\n kind: 'invalid-expression',\n message: 'Expression is not a valid expression',\n};\n\ntype FlattenExpressionResult = {\n parts: ResolutionNode<Part>[];\n errors: FlattenExpressionError[];\n};\n\nfunction isStaticPart(\n part: ResolutionNode<Part> | undefined\n): part is Extract<Part, { type: 'static' }> {\n return part != null && 'type' in part && part.type === 'static';\n}\n\nfunction appendPart(\n parts: ResolutionNode<Part>[],\n part: ResolutionNode<Part>\n): void {\n const lastPart = parts[parts.length - 1];\n if (isStaticPart(lastPart) && isStaticPart(part)) {\n lastPart.value += part.value;\n return;\n }\n parts.push(part);\n}\n\nfunction appendParts(\n parts: ResolutionNode<Part>[],\n nextParts: ResolutionNode<Part>[]\n): void {\n for (const part of nextParts) {\n appendPart(parts, part);\n }\n}\n\n/**\n * Recursively decomposes an expression tree into a flat list of typed parts.\n * Handles string/numeric/boolean/null literals, void expressions,\n * template literals, and binary '+' concatenation. When a NodePath is\n * provided, imported derive() calls are preserved as derive parts.\n *\n * Returns errors alongside parts so callers can report extraction failures\n * without throwing during expression flattening. Adjacent static parts are\n * coalesced before returning.\n */\nexport function flattenExpressionToParts(\n exprPath: NodePath<t.Expression>\n): FlattenExpressionResult {\n const expr = exprPath.node;\n const scope = exprPath.scope;\n\n // gt('Hello, World!')\n if (t.isStringLiteral(expr)) {\n return { parts: [{ type: 'static', value: expr.value }], errors: [] };\n }\n\n // gt(123)\n if (t.isNumericLiteral(expr)) {\n return {\n parts: [{ type: 'static', value: String(expr.value) }],\n errors: [],\n };\n }\n\n // gt(true)\n if (t.isBooleanLiteral(expr)) {\n return {\n parts: [{ type: 'static', value: String(expr.value) }],\n errors: [],\n };\n }\n\n // gt(null)\n if (t.isNullLiteral(expr)) {\n return { parts: [{ type: 'static', value: 'null' }], errors: [] };\n }\n\n // gt(void 0)\n if (t.isUnaryExpression(expr) && expr.operator === 'void') {\n return { parts: [{ type: 'dynamic', node: expr }], errors: [] };\n }\n\n // gt(`Hello, ${name}!`)\n if (t.isTemplateLiteral(expr)) {\n const result: FlattenExpressionResult = { parts: [], errors: [] };\n for (let i = 0; i < expr.quasis.length; i++) {\n const cooked = expr.quasis[i].value.cooked;\n if (cooked == null) {\n result.errors.push(INVALID_TEMPLATE_ESCAPE);\n return result;\n } else if (cooked) {\n appendPart(result.parts, { type: 'static', value: cooked });\n }\n if (i < expr.expressions.length) {\n const exprPathIndex = exprPath.get('expressions')[i];\n if (!exprPathIndex.isExpression()) {\n result.errors.push(INVALID_EXPRESSION);\n return result;\n }\n const expressionResult = flattenExpressionToParts(exprPathIndex);\n appendParts(result.parts, expressionResult.parts);\n result.errors.push(...expressionResult.errors);\n }\n }\n return result;\n }\n\n // gt('Hello, ' + name + '!')\n if (t.isBinaryExpression(expr) && expr.operator === '+') {\n const leftPath = exprPath.get('left');\n if (!leftPath.isExpression()) {\n return { parts: [], errors: [INVALID_EXPRESSION] };\n }\n const { parts: leftParts, errors: leftErrors } =\n flattenExpressionToParts(leftPath);\n const rightPath = exprPath.get('right');\n if (!rightPath.isExpression()) {\n return { parts: [], errors: [INVALID_EXPRESSION] };\n }\n const { parts: rightParts, errors: rightErrors } =\n flattenExpressionToParts(rightPath);\n const parts: ResolutionNode<Part>[] = [];\n appendParts(parts, leftParts);\n appendParts(parts, rightParts);\n return {\n parts,\n errors: [...leftErrors, ...rightErrors],\n };\n }\n\n // gt(derive(() => 'Hello, World!'))\n if (isDeriveInvocation(expr, scope)) {\n return { parts: [{ type: 'derive', node: expr }], errors: [] };\n }\n\n // gt(name)\n return { parts: [{ type: 'dynamic', node: expr }], errors: [] };\n}\n"],"mappings":";;;;;;AAUA,MAAa,gCACX;AAOF,MAAM,0BAAkD;CACtD,MAAM;CACN,SAAS;CACV;AAED,MAAM,qBAA6C;CACjD,MAAM;CACN,SAAS;CACV;AAOD,SAAS,aACP,MAC2C;AAC3C,QAAO,QAAQ,QAAQ,UAAU,QAAQ,KAAK,SAAS;;AAGzD,SAAS,WACP,OACA,MACM;CACN,MAAM,WAAW,MAAM,MAAM,SAAS;AACtC,KAAI,aAAa,SAAS,IAAI,aAAa,KAAK,EAAE;AAChD,WAAS,SAAS,KAAK;AACvB;;AAEF,OAAM,KAAK,KAAK;;AAGlB,SAAS,YACP,OACA,WACM;AACN,MAAK,MAAM,QAAQ,UACjB,YAAW,OAAO,KAAK;;;;;;;;;;;;AAc3B,SAAgB,yBACd,UACyB;CACzB,MAAM,OAAO,SAAS;CACtB,MAAM,QAAQ,SAAS;AAGvB,KAAIA,aAAE,gBAAgB,KAAK,CACzB,QAAO;EAAE,OAAO,CAAC;GAAE,MAAM;GAAU,OAAO,KAAK;GAAO,CAAC;EAAE,QAAQ,EAAE;EAAE;AAIvE,KAAIA,aAAE,iBAAiB,KAAK,CAC1B,QAAO;EACL,OAAO,CAAC;GAAE,MAAM;GAAU,OAAO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