@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,355 +1,244 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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.validateTranslationFunction = validateTranslationFunction;
|
|
37
|
-
exports.validateUseTranslationsCallback = validateUseTranslationsCallback;
|
|
38
|
-
exports.validateUseMessagesCallback = validateUseMessagesCallback;
|
|
39
|
-
exports.validateDerive = validateDerive;
|
|
40
|
-
const t = __importStar(require("@babel/types"));
|
|
41
|
-
const constants_1 = require("../../utils/constants/gt/constants");
|
|
42
|
-
const getCalleeNameFromExpression_1 = require("../../utils/parsing/getCalleeNameFromExpression");
|
|
43
|
-
const resolveStaticExpression_1 = require("../../utils/string-expressions/resolveStaticExpression");
|
|
44
|
-
const getTrackedVariable_1 = require("../getTrackedVariable");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
|
+
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_parsing_getCalleeNameFromExpression = require("../../utils/parsing/getCalleeNameFromExpression.js");
|
|
5
|
+
const require_utils_string_expressions_resolveStaticExpression = require("../../utils/string-expressions/resolveStaticExpression.js");
|
|
6
|
+
const require_transform_getTrackedVariable = require("../getTrackedVariable.js");
|
|
7
|
+
let _babel_types = require("@babel/types");
|
|
8
|
+
_babel_types = require_runtime.__toESM(_babel_types);
|
|
9
|
+
//#region src/transform/validation/validateTranslationFunction.ts
|
|
45
10
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
11
|
+
* Validate useGT_callback / getGT_callback / msg() / t()
|
|
12
|
+
* - first argument must be a statically resolvable string expression
|
|
13
|
+
* (string literal, template literal, binary '+' concatenation, or derive() call)
|
|
14
|
+
* - second argument, if present, $id field + $context field must be a string literal
|
|
15
|
+
*/
|
|
51
16
|
function validateTranslationFunction(callExprPath, state) {
|
|
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
|
-
hash = hashProperty.value;
|
|
117
|
-
const formatProperty = validatePropertyFromObjectExpression(objExprPath, constants_1.USEGT_CALLBACK_OPTIONS.$format, 'string');
|
|
118
|
-
errors.push(...formatProperty.errors);
|
|
119
|
-
format = formatProperty.value;
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
errors,
|
|
123
|
-
content,
|
|
124
|
-
context,
|
|
125
|
-
id,
|
|
126
|
-
hash,
|
|
127
|
-
maxChars,
|
|
128
|
-
format,
|
|
129
|
-
hasDeriveContext,
|
|
130
|
-
};
|
|
17
|
+
var _resolvedStaticExpres;
|
|
18
|
+
const callExpr = callExprPath.node;
|
|
19
|
+
const errors = [];
|
|
20
|
+
if (callExpr.arguments.length < 1) {
|
|
21
|
+
errors.push("registration function must have at least 1 argument");
|
|
22
|
+
return { errors };
|
|
23
|
+
}
|
|
24
|
+
if (!_babel_types.isExpression(callExpr.arguments[0])) {
|
|
25
|
+
errors.push("registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.");
|
|
26
|
+
return { errors };
|
|
27
|
+
}
|
|
28
|
+
const resolvedStaticExpression = require_utils_string_expressions_resolveStaticExpression.resolveStaticExpression(callExprPath.get("arguments")[0]);
|
|
29
|
+
const content = (_resolvedStaticExpres = resolvedStaticExpression.values) === null || _resolvedStaticExpres === void 0 ? void 0 : _resolvedStaticExpres[0];
|
|
30
|
+
const resolutionErrors = getResolutionErrorMessages(resolvedStaticExpression.errors, false);
|
|
31
|
+
if (resolutionErrors.length > 0) return { errors: resolutionErrors };
|
|
32
|
+
if (content === void 0 && !state.settings.autoderive.strings) {
|
|
33
|
+
validateDerive(callExpr.arguments[0], state, errors);
|
|
34
|
+
if (errors.length > 0) {
|
|
35
|
+
errors.push(...getResolutionErrorMessages(resolvedStaticExpression.errors));
|
|
36
|
+
errors.push("registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.");
|
|
37
|
+
return { errors };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const contentHasAutoderive = state.settings.autoderive.strings && content === void 0;
|
|
41
|
+
let context;
|
|
42
|
+
let id;
|
|
43
|
+
let hash;
|
|
44
|
+
let maxChars;
|
|
45
|
+
let format;
|
|
46
|
+
let hasDeriveContext;
|
|
47
|
+
if (callExpr.arguments.length === 1) return {
|
|
48
|
+
errors,
|
|
49
|
+
content,
|
|
50
|
+
hasDeriveContext: contentHasAutoderive || void 0
|
|
51
|
+
};
|
|
52
|
+
if (_babel_types.isObjectExpression(callExpr.arguments[1])) {
|
|
53
|
+
const objExprPath = callExprPath.get("arguments")[1];
|
|
54
|
+
const contextProperty = validatePropertyFromObjectExpression(objExprPath, "$context", "string-or-derive", state);
|
|
55
|
+
errors.push(...contextProperty.errors);
|
|
56
|
+
context = contextProperty.value;
|
|
57
|
+
hasDeriveContext = contentHasAutoderive || contextProperty.hasDeriveExpression;
|
|
58
|
+
const idProperty = validatePropertyFromObjectExpression(objExprPath, "$id", "string");
|
|
59
|
+
errors.push(...idProperty.errors);
|
|
60
|
+
id = idProperty.value;
|
|
61
|
+
const maxCharsProperty = validatePropertyFromObjectExpression(objExprPath, "$maxChars", "number");
|
|
62
|
+
errors.push(...maxCharsProperty.errors);
|
|
63
|
+
maxChars = maxCharsProperty.value;
|
|
64
|
+
const hashProperty = validatePropertyFromObjectExpression(objExprPath, "$_hash", "string");
|
|
65
|
+
errors.push(...hashProperty.errors);
|
|
66
|
+
hash = hashProperty.value;
|
|
67
|
+
const formatProperty = validatePropertyFromObjectExpression(objExprPath, "$format", "string");
|
|
68
|
+
errors.push(...formatProperty.errors);
|
|
69
|
+
format = formatProperty.value;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
errors,
|
|
73
|
+
content,
|
|
74
|
+
context,
|
|
75
|
+
id,
|
|
76
|
+
hash,
|
|
77
|
+
maxChars,
|
|
78
|
+
format,
|
|
79
|
+
hasDeriveContext
|
|
80
|
+
};
|
|
131
81
|
}
|
|
132
82
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// eslint-disable-next-line no-unused-vars
|
|
83
|
+
* Validate useTranslations_callback / getTranslations_callback
|
|
84
|
+
* - always valid (arguments can be dynamic)
|
|
85
|
+
*/
|
|
137
86
|
function validateUseTranslationsCallback(_callExpr) {
|
|
138
|
-
|
|
139
|
-
return { errors };
|
|
87
|
+
return { errors: [] };
|
|
140
88
|
}
|
|
141
89
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// eslint-disable-next-line no-unused-vars
|
|
90
|
+
* Validate useMessages_callback / getMessages_callback
|
|
91
|
+
* - always valid
|
|
92
|
+
*/
|
|
146
93
|
function validateUseMessagesCallback(_callExpr) {
|
|
147
|
-
|
|
148
|
-
return { errors };
|
|
94
|
+
return { errors: [] };
|
|
149
95
|
}
|
|
150
|
-
/* =============================== */
|
|
151
|
-
/* Helper Functions */
|
|
152
|
-
/* =============================== */
|
|
153
96
|
function getResolutionErrorMessages(errors, includeDynamic = true) {
|
|
154
|
-
|
|
155
|
-
.filter((error) => includeDynamic || error.kind !== 'dynamic-expression')
|
|
156
|
-
.map(({ message }) => message);
|
|
97
|
+
return errors.filter((error) => includeDynamic || error.kind !== "dynamic-expression").map(({ message }) => message);
|
|
157
98
|
}
|
|
158
99
|
function validatePropertyFromObjectExpression(objExprPath, name, type, state) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
else if (state) {
|
|
198
|
-
// Static resolution failed — check if it's a valid derive() expression
|
|
199
|
-
const deriveErrors = [];
|
|
200
|
-
validateDerive(value.value, state, deriveErrors);
|
|
201
|
-
if (deriveErrors.length === 0) {
|
|
202
|
-
result.hasDeriveExpression = true;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
result.errors.push(...getResolutionErrorMessages(resolved.errors), ...deriveErrors);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
result.errors.push(...getResolutionErrorMessages(resolved.errors));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
const validatedValue = type === 'string'
|
|
214
|
-
? validateExpressionIsStringLiteral(value.value)
|
|
215
|
-
: validateExpressionIsNumericLiteral(value.value);
|
|
216
|
-
result.errors.push(...validatedValue.errors);
|
|
217
|
-
result.value = validatedValue.value;
|
|
218
|
-
}
|
|
219
|
-
return result;
|
|
100
|
+
const result = { errors: [] };
|
|
101
|
+
let valuePath;
|
|
102
|
+
for (const propertyPath of objExprPath.get("properties")) {
|
|
103
|
+
if (!propertyPath.isObjectProperty()) continue;
|
|
104
|
+
const property = propertyPath.node;
|
|
105
|
+
if (_babel_types.isIdentifier(property.key) && property.key.name === name) {
|
|
106
|
+
valuePath = propertyPath;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (_babel_types.isStringLiteral(property.key) && property.key.value === name) {
|
|
110
|
+
valuePath = propertyPath;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!valuePath) return result;
|
|
115
|
+
const value = valuePath.node;
|
|
116
|
+
if (!_babel_types.isExpression(value.value)) {
|
|
117
|
+
result.errors.push(`registration function must use a string literal for its ${name} field. Variable content is not allowed.`);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
if (type === "string-or-derive") {
|
|
121
|
+
var _resolved$values;
|
|
122
|
+
const resolved = require_utils_string_expressions_resolveStaticExpression.resolveStaticExpression(valuePath.get("value"));
|
|
123
|
+
const resolutionErrors = getResolutionErrorMessages(resolved.errors, false);
|
|
124
|
+
if (((_resolved$values = resolved.values) === null || _resolved$values === void 0 ? void 0 : _resolved$values[0]) !== void 0) result.value = resolved.values[0];
|
|
125
|
+
else if (resolutionErrors.length > 0) result.errors.push(...resolutionErrors);
|
|
126
|
+
else if (state) {
|
|
127
|
+
const deriveErrors = [];
|
|
128
|
+
validateDerive(value.value, state, deriveErrors);
|
|
129
|
+
if (deriveErrors.length === 0) result.hasDeriveExpression = true;
|
|
130
|
+
else result.errors.push(...getResolutionErrorMessages(resolved.errors), ...deriveErrors);
|
|
131
|
+
} else result.errors.push(...getResolutionErrorMessages(resolved.errors));
|
|
132
|
+
} else {
|
|
133
|
+
const validatedValue = type === "string" ? validateExpressionIsStringLiteral(value.value) : validateExpressionIsNumericLiteral(value.value);
|
|
134
|
+
result.errors.push(...validatedValue.errors);
|
|
135
|
+
result.value = validatedValue.value;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
220
138
|
}
|
|
221
139
|
/**
|
|
222
|
-
|
|
223
|
-
|
|
140
|
+
* Validate that an expression is a string literal
|
|
141
|
+
*/
|
|
224
142
|
function validateExpressionIsStringLiteral(expr) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
143
|
+
if (_babel_types.isStringLiteral(expr)) return {
|
|
144
|
+
errors: [],
|
|
145
|
+
value: expr.value
|
|
146
|
+
};
|
|
147
|
+
if (_babel_types.isTemplateLiteral(expr) && expr.expressions.length === 0) {
|
|
148
|
+
var _expr$quasis$;
|
|
149
|
+
return {
|
|
150
|
+
errors: [],
|
|
151
|
+
value: (_expr$quasis$ = expr.quasis[0]) === null || _expr$quasis$ === void 0 ? void 0 : _expr$quasis$.value.cooked
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return { errors: ["Expression is not a string literal"] };
|
|
233
155
|
}
|
|
234
156
|
/**
|
|
235
|
-
|
|
236
|
-
|
|
157
|
+
* Validates if an expression uses the derive() function correctly
|
|
158
|
+
*/
|
|
237
159
|
function validateDerive(expr, state, errors) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return { errors };
|
|
277
|
-
}
|
|
278
|
-
if (!expr.expressions.some((expression) => t.isExpression(expression) &&
|
|
279
|
-
validateDerive(expression, state, errors).errors.length === 0)) {
|
|
280
|
-
errors.push('Expression does not use an allowed call expression');
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
errors,
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
// 4. Static literals (string, number, boolean, null)
|
|
287
|
-
if (t.isStringLiteral(expr)) {
|
|
288
|
-
return { errors };
|
|
289
|
-
}
|
|
290
|
-
if (t.isNumericLiteral(expr)) {
|
|
291
|
-
return { errors };
|
|
292
|
-
}
|
|
293
|
-
if (t.isBooleanLiteral(expr)) {
|
|
294
|
-
return { errors };
|
|
295
|
-
}
|
|
296
|
-
if (t.isNullLiteral(expr)) {
|
|
297
|
-
return { errors };
|
|
298
|
-
}
|
|
299
|
-
// Fallthrough: expression type not supported (e.g., plain identifiers/variables)
|
|
300
|
-
errors.push('Variables are not allowed');
|
|
301
|
-
return { errors };
|
|
160
|
+
if (!expr) {
|
|
161
|
+
errors.push("Expression is empty");
|
|
162
|
+
return { errors };
|
|
163
|
+
}
|
|
164
|
+
if (_babel_types.isCallExpression(expr)) {
|
|
165
|
+
const { namespaceName, functionName } = require_utils_parsing_getCalleeNameFromExpression.getCalleeNameFromExpression(expr);
|
|
166
|
+
const { canonicalName, type } = require_transform_getTrackedVariable.getTrackedVariable(state.scopeTracker, namespaceName, functionName);
|
|
167
|
+
if (!canonicalName) {
|
|
168
|
+
errors.push("Expression does not use an allowed call expression");
|
|
169
|
+
return { errors };
|
|
170
|
+
}
|
|
171
|
+
if (type !== "generaltranslation" || canonicalName !== "declareStatic" && canonicalName !== "derive") {
|
|
172
|
+
errors.push("Expression does not use an allowed call expression");
|
|
173
|
+
return { errors };
|
|
174
|
+
}
|
|
175
|
+
validateDeclareStaticExpression(expr, errors);
|
|
176
|
+
return { errors };
|
|
177
|
+
}
|
|
178
|
+
if (_babel_types.isBinaryExpression(expr) && expr.operator === "+") {
|
|
179
|
+
if (!_babel_types.isExpression(expr.left) || !_babel_types.isExpression(expr.right)) {
|
|
180
|
+
errors.push("Operands must be expressions");
|
|
181
|
+
return { errors };
|
|
182
|
+
}
|
|
183
|
+
validateDerive(expr.right, state, errors);
|
|
184
|
+
validateDerive(expr.left, state, errors);
|
|
185
|
+
return { errors };
|
|
186
|
+
}
|
|
187
|
+
if (_babel_types.isTemplateLiteral(expr)) {
|
|
188
|
+
if (expr.expressions.length === 0) return { errors };
|
|
189
|
+
if (!expr.expressions.some((expression) => _babel_types.isExpression(expression) && validateDerive(expression, state, errors).errors.length === 0)) errors.push("Expression does not use an allowed call expression");
|
|
190
|
+
return { errors };
|
|
191
|
+
}
|
|
192
|
+
if (_babel_types.isStringLiteral(expr)) return { errors };
|
|
193
|
+
if (_babel_types.isNumericLiteral(expr)) return { errors };
|
|
194
|
+
if (_babel_types.isBooleanLiteral(expr)) return { errors };
|
|
195
|
+
if (_babel_types.isNullLiteral(expr)) return { errors };
|
|
196
|
+
errors.push("Variables are not allowed");
|
|
197
|
+
return { errors };
|
|
302
198
|
}
|
|
303
199
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
200
|
+
* Takes in a call expression to check if:
|
|
201
|
+
* - it has exactly one argument
|
|
202
|
+
* - the argument is a call expression
|
|
203
|
+
* Example: derive(getName())
|
|
204
|
+
*/
|
|
309
205
|
function validateDeclareStaticExpression(expr, errors) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (!t.isCallExpression(onlyArg)) {
|
|
328
|
-
errors.push('derive() must have a call expression as the argument');
|
|
329
|
-
return { errors };
|
|
330
|
-
}
|
|
331
|
-
return { errors };
|
|
206
|
+
if (expr.arguments.length !== 1) {
|
|
207
|
+
errors.push("derive() must have one argument");
|
|
208
|
+
return { errors };
|
|
209
|
+
}
|
|
210
|
+
const [onlyArg] = expr.arguments;
|
|
211
|
+
if (_babel_types.isAwaitExpression(onlyArg)) {
|
|
212
|
+
if (!_babel_types.isCallExpression(onlyArg.argument)) {
|
|
213
|
+
errors.push("derive() must have a call expression as the argument");
|
|
214
|
+
return { errors };
|
|
215
|
+
}
|
|
216
|
+
return { errors };
|
|
217
|
+
}
|
|
218
|
+
if (!_babel_types.isCallExpression(onlyArg)) {
|
|
219
|
+
errors.push("derive() must have a call expression as the argument");
|
|
220
|
+
return { errors };
|
|
221
|
+
}
|
|
222
|
+
return { errors };
|
|
332
223
|
}
|
|
333
224
|
/**
|
|
334
|
-
|
|
335
|
-
|
|
225
|
+
* Validate that an expression is a number literal
|
|
226
|
+
*/
|
|
336
227
|
function validateExpressionIsNumericLiteral(expr) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (candidateValue !== undefined && !Number.isInteger(candidateValue)) {
|
|
347
|
-
return { errors: ['Expression is not an integer'] };
|
|
348
|
-
}
|
|
349
|
-
// no value found
|
|
350
|
-
if (candidateValue === undefined) {
|
|
351
|
-
return { errors: ['Expression is not a number literal'] };
|
|
352
|
-
}
|
|
353
|
-
return { errors: [], value: candidateValue };
|
|
228
|
+
let candidateValue;
|
|
229
|
+
if (_babel_types.isNumericLiteral(expr)) candidateValue = expr.value;
|
|
230
|
+
else if (_babel_types.isUnaryExpression(expr) && _babel_types.isNumericLiteral(expr.argument)) candidateValue = expr.argument.value;
|
|
231
|
+
if (candidateValue !== void 0 && !Number.isInteger(candidateValue)) return { errors: ["Expression is not an integer"] };
|
|
232
|
+
if (candidateValue === void 0) return { errors: ["Expression is not a number literal"] };
|
|
233
|
+
return {
|
|
234
|
+
errors: [],
|
|
235
|
+
value: candidateValue
|
|
236
|
+
};
|
|
354
237
|
}
|
|
238
|
+
//#endregion
|
|
239
|
+
exports.validateDerive = validateDerive;
|
|
240
|
+
exports.validateTranslationFunction = validateTranslationFunction;
|
|
241
|
+
exports.validateUseMessagesCallback = validateUseMessagesCallback;
|
|
242
|
+
exports.validateUseTranslationsCallback = validateUseTranslationsCallback;
|
|
243
|
+
|
|
355
244
|
//# sourceMappingURL=validateTranslationFunction.js.map
|