@generaltranslation/compiler 1.3.27 → 1.3.29
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/config.d.ts +12 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -6
- package/dist/index.js.map +1 -1
- package/dist/passes/basePass.d.ts.map +1 -1
- package/dist/passes/basePass.js +9 -10
- package/dist/passes/basePass.js.map +1 -1
- package/dist/processing/collection/processCallExpression.js +0 -1
- package/dist/processing/collection/processCallExpression.js.map +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.d.ts +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.js +1 -1
- package/dist/processing/collection/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processCallExpression.js.map +1 -1
- package/dist/processing/jsx-insertion/processProgram.d.ts.map +1 -1
- package/dist/processing/jsx-insertion/processProgram.js +1 -1
- package/dist/processing/jsx-insertion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processProgram.js +1 -1
- package/dist/processing/macro-expansion/processProgram.js.map +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.d.ts +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js +1 -1
- package/dist/processing/macro-expansion/processTaggedTemplateExpression.js.map +1 -1
- package/dist/processing/processFunctionDeclaration.js +1 -1
- package/dist/processing/processFunctionExpression.js +1 -1
- package/dist/processing/runtime-translate/processProgram.d.ts.map +1 -1
- package/dist/processing/runtime-translate/processProgram.js +2 -1
- package/dist/processing/runtime-translate/processProgram.js.map +1 -1
- package/dist/state/StringCollector.d.ts +3 -3
- package/dist/state/StringCollector.d.ts.map +1 -1
- package/dist/state/StringCollector.js.map +1 -1
- package/dist/state/utils/initializeState.d.ts.map +1 -1
- package/dist/state/utils/initializeState.js +8 -5
- package/dist/state/utils/initializeState.js.map +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.d.ts +1 -1
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js +6 -5
- package/dist/transform/injection/injectCallbackDeclaratorFunctionParameters.js.map +1 -1
- package/dist/transform/jsx-children/constructJsxChildren.js.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts +2 -2
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.d.ts.map +1 -1
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js +4 -3
- package/dist/transform/jsx-insertion/injectJsxInsertionImport.js.map +1 -1
- package/dist/transform/macro-expansion/injectMacroImport.d.ts +2 -2
- package/dist/transform/macro-expansion/injectMacroImport.d.ts.map +1 -1
- package/dist/transform/macro-expansion/injectMacroImport.js +4 -3
- package/dist/transform/macro-expansion/injectMacroImport.js.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.d.ts.map +1 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js +0 -1
- package/dist/transform/registration/callbacks/registerUseGTCallback.js.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.d.ts.map +1 -1
- package/dist/transform/registration/registerStandaloneTranslation.js +0 -1
- package/dist/transform/registration/registerStandaloneTranslation.js.map +1 -1
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.d.ts +3 -2
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.d.ts.map +1 -1
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.js +4 -3
- package/dist/transform/runtime-translate/injectRuntimeTranslateImport.js.map +1 -1
- package/dist/transform/validation/validateTranslationComponentArgs.js +0 -1
- package/dist/transform/validation/validateTranslationComponentArgs.js.map +1 -1
- package/dist/transform/validation/validateTranslationFunction.d.ts.map +1 -1
- package/dist/transform/validation/validateTranslationFunction.js +3 -3
- package/dist/transform/validation/validateTranslationFunction.js.map +1 -1
- package/dist/utils/calculateHash.d.ts +1 -2
- package/dist/utils/calculateHash.d.ts.map +1 -1
- package/dist/utils/calculateHash.js +1 -3
- package/dist/utils/calculateHash.js.map +1 -1
- package/dist/utils/constants/gt/constants.d.ts +1 -5
- package/dist/utils/constants/gt/constants.d.ts.map +1 -1
- package/dist/utils/constants/gt/constants.js +1 -5
- package/dist/utils/constants/gt/constants.js.map +1 -1
- package/dist/utils/constants/gt/helpers.d.ts +2 -1
- package/dist/utils/constants/gt/helpers.d.ts.map +1 -1
- package/dist/utils/constants/gt/helpers.js +15 -5
- package/dist/utils/constants/gt/helpers.js.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.d.ts.map +1 -1
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js +2 -3
- package/dist/utils/constants/resolveIdentifier/isGTComponent.js.map +1 -1
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.d.ts +1 -1
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.js +3 -3
- package/dist/utils/parsing/isStringTranslationTaggedTemplate.js.map +1 -1
- package/package.json +3 -3
- package/dist/processing/index.d.ts +0 -15
- package/dist/processing/index.d.ts.map +0 -1
- package/dist/processing/index.js +0 -29
- package/dist/transform/jsx-children/index.d.ts +0 -2
- package/dist/transform/jsx-children/index.d.ts.map +0 -1
- package/dist/transform/jsx-children/index.js +0 -3
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
3
|
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_constants_gt_helpers = require("../../utils/constants/gt/helpers.js");
|
|
4
5
|
let _babel_types = require("@babel/types");
|
|
5
6
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
7
|
//#region src/transform/macro-expansion/injectMacroImport.ts
|
|
7
8
|
/**
|
|
8
|
-
* Inject `import { t } from 'gt-react
|
|
9
|
+
* Inject `import { t } from 'gt-react'` as the first statement in the program.
|
|
9
10
|
*/
|
|
10
|
-
function injectMacroImport(path) {
|
|
11
|
+
function injectMacroImport(path, legacyGtReactImportSource) {
|
|
11
12
|
const tName = "t";
|
|
12
|
-
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName))], _babel_types.stringLiteral(
|
|
13
|
+
const importDecl = _babel_types.importDeclaration([_babel_types.importSpecifier(_babel_types.identifier(tName), _babel_types.identifier(tName))], _babel_types.stringLiteral(require_utils_constants_gt_helpers.getGtReactImportSource(legacyGtReactImportSource)));
|
|
13
14
|
path.unshiftContainer("body", importDecl);
|
|
14
15
|
}
|
|
15
16
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectMacroImport.js","names":["t"],"sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport {
|
|
1
|
+
{"version":3,"file":"injectMacroImport.js","names":["t","getGtReactImportSource"],"sources":["../../../src/transform/macro-expansion/injectMacroImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { GT_OTHER_FUNCTIONS } from '../../utils/constants/gt/constants';\nimport { getGtReactImportSource } from '../../utils/constants/gt/helpers';\n\n/**\n * Inject `import { t } from 'gt-react'` as the first statement in the program.\n */\nexport function injectMacroImport(\n path: NodePath<t.Program>,\n legacyGtReactImportSource: boolean\n): void {\n const tName = GT_OTHER_FUNCTIONS.t;\n\n const importDecl = t.importDeclaration(\n [t.importSpecifier(t.identifier(tName), t.identifier(tName))],\n t.stringLiteral(getGtReactImportSource(legacyGtReactImportSource))\n );\n\n path.unshiftContainer('body', importDecl);\n}\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,kBACd,MACA,2BACM;CACN,MAAM,QAAA;CAEN,MAAM,aAAaA,aAAE,kBACnB,CAACA,aAAE,gBAAgBA,aAAE,WAAW,MAAM,EAAEA,aAAE,WAAW,MAAM,CAAC,CAAC,EAC7DA,aAAE,cAAcC,mCAAAA,uBAAuB,0BAA0B,CAAC,CACnE;AAED,MAAK,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerUseGTCallback.d.ts","sourceRoot":"","sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,MAAM,GACP,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"registerUseGTCallback.d.ts","sourceRoot":"","sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,MAAM,GACP,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,IAAI,CA4BP"}
|
|
@@ -8,7 +8,6 @@ const require_utils_calculateHash = require("../../../utils/calculateHash.js");
|
|
|
8
8
|
function registerUseGTCallback({ identifier, state, content, context, id, maxChars, requiresReview, hash, format }) {
|
|
9
9
|
hash ??= require_utils_calculateHash.default({
|
|
10
10
|
source: content,
|
|
11
|
-
id,
|
|
12
11
|
context,
|
|
13
12
|
maxChars,
|
|
14
13
|
requiresReview,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerUseGTCallback.js","names":["hashSource"],"sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"sourcesContent":["import { TransformState } from '../../../state/types';\nimport hashSource from '../../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerUseGTCallback({\n identifier,\n state,\n content,\n context,\n id,\n maxChars,\n requiresReview,\n hash,\n format,\n}: {\n identifier: number;\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n hash?: string;\n format?: string;\n}): void {\n // Calculate hash for the call expression (skip if already set, including empty string for derive context)\n hash ??= hashSource({\n source: content,\n
|
|
1
|
+
{"version":3,"file":"registerUseGTCallback.js","names":["hashSource"],"sources":["../../../../src/transform/registration/callbacks/registerUseGTCallback.ts"],"sourcesContent":["import { TransformState } from '../../../state/types';\nimport hashSource from '../../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track gt() function invocations\n * - Adds the translation content to the string collector\n */\nexport function registerUseGTCallback({\n identifier,\n state,\n content,\n context,\n id,\n maxChars,\n requiresReview,\n hash,\n format,\n}: {\n identifier: number;\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n hash?: string;\n format?: string;\n}): void {\n // Calculate hash for the call expression (skip if already set, including empty string for derive context)\n hash ??= hashSource({\n source: content,\n context,\n maxChars,\n requiresReview,\n dataFormat: (format || 'ICU') as DataFormat,\n });\n\n // Add the translation content to the string collector (under identifier mapping to useGT call)\n state.stringCollector.pushTranslationContent(identifier, {\n message: content,\n hash,\n id,\n context,\n maxChars,\n requiresReview,\n format,\n });\n\n // Increment counter so we can revisit this same invocation on second pass\n const counterId = state.stringCollector.incrementCounter();\n\n // Register the hash under this counter\n state.stringCollector.setTranslationHash(counterId, {\n hash,\n });\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,sBAAsB,EACpC,YACA,OACA,SACA,SACA,IACA,UACA,gBACA,MACA,UAWO;AAEP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR;EACA;EACA;EACA,YAAa,UAAU;EACxB,CAAC;AAGF,OAAM,gBAAgB,uBAAuB,YAAY;EACvD,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAG1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerStandaloneTranslation.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"registerStandaloneTranslation.d.ts","sourceRoot":"","sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAInD;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,OAAO,EACP,OAAO,EACP,EAAE,EACF,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,MAAM,EACN,UAAU,GACX,EAAE;IACD,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,IAAI,CA6BP"}
|
|
@@ -7,7 +7,6 @@ const require_utils_calculateHash = require("../../utils/calculateHash.js");
|
|
|
7
7
|
function registerStandaloneTranslation({ state, content, context, id, maxChars, requiresReview, hash, format, injectHash }) {
|
|
8
8
|
hash ??= require_utils_calculateHash.default({
|
|
9
9
|
source: content,
|
|
10
|
-
...id && { id },
|
|
11
10
|
...context && { context },
|
|
12
11
|
...maxChars != null && { maxChars },
|
|
13
12
|
...requiresReview === true && { requiresReview: true },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerStandaloneTranslation.js","names":["hashSource"],"sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport hashSource from '../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track standalone string translation invocations such as t() and msg().\n */\nexport function registerStandaloneTranslation({\n state,\n content,\n context,\n id,\n maxChars,\n requiresReview,\n hash,\n format,\n injectHash,\n}: {\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n hash?: string;\n format?: string;\n injectHash?: boolean;\n}): void {\n hash ??= hashSource({\n source: content,\n ...(
|
|
1
|
+
{"version":3,"file":"registerStandaloneTranslation.js","names":["hashSource"],"sources":["../../../src/transform/registration/registerStandaloneTranslation.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport hashSource from '../../utils/calculateHash';\nimport type { DataFormat } from '@generaltranslation/format/types';\n\n/**\n * Track standalone string translation invocations such as t() and msg().\n */\nexport function registerStandaloneTranslation({\n state,\n content,\n context,\n id,\n maxChars,\n requiresReview,\n hash,\n format,\n injectHash,\n}: {\n state: TransformState;\n content: string;\n context?: string;\n id?: string;\n maxChars?: number;\n requiresReview?: boolean;\n hash?: string;\n format?: string;\n injectHash?: boolean;\n}): void {\n hash ??= hashSource({\n source: content,\n ...(context && { context }),\n ...(maxChars != null && { maxChars }),\n ...(requiresReview === true && { requiresReview: true }),\n dataFormat: (format || 'ICU') as DataFormat,\n });\n\n state.stringCollector.pushRuntimeOnlyContent({\n message: content,\n hash,\n id,\n context,\n maxChars,\n requiresReview,\n format,\n });\n\n // Runtime-only entries, including msg() and t`...`, stop here. Only\n // standalone t() sets injectHash so the injection pass sees a matching slot.\n if (!injectHash) {\n return;\n }\n\n const counterId = state.stringCollector.incrementCounter();\n state.stringCollector.setTranslationHash(counterId, {\n hash,\n });\n}\n"],"mappings":";;;;;;AAOA,SAAgB,8BAA8B,EAC5C,OACA,SACA,SACA,IACA,UACA,gBACA,MACA,QACA,cAWO;AACP,UAASA,4BAAAA,QAAW;EAClB,QAAQ;EACR,GAAI,WAAW,EAAE,SAAS;EAC1B,GAAI,YAAY,QAAQ,EAAE,UAAU;EACpC,GAAI,mBAAmB,QAAQ,EAAE,gBAAgB,MAAM;EACvD,YAAa,UAAU;EACxB,CAAC;AAEF,OAAM,gBAAgB,uBAAuB;EAC3C,SAAS;EACT;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAIF,KAAI,CAAC,WACH;CAGF,MAAM,YAAY,MAAM,gBAAgB,kBAAkB;AAC1D,OAAM,gBAAgB,mBAAmB,WAAW,EAClD,MACD,CAAC"}
|
|
@@ -2,10 +2,11 @@ import * as t from '@babel/types';
|
|
|
2
2
|
import { NodePath } from '@babel/traverse';
|
|
3
3
|
/**
|
|
4
4
|
* Inject runtime translate import with only the specifiers needed.
|
|
5
|
-
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react
|
|
5
|
+
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`
|
|
6
6
|
*/
|
|
7
|
-
export declare function injectRuntimeTranslateImport(path: NodePath<t.Program>, { needsString, needsJsx }: {
|
|
7
|
+
export declare function injectRuntimeTranslateImport(path: NodePath<t.Program>, { needsString, needsJsx, legacyGtReactImportSource, }: {
|
|
8
8
|
needsString: boolean;
|
|
9
9
|
needsJsx: boolean;
|
|
10
|
+
legacyGtReactImportSource: boolean;
|
|
10
11
|
}): NodePath<t.ImportDeclaration> | null;
|
|
11
12
|
//# sourceMappingURL=injectRuntimeTranslateImport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRuntimeTranslateImport.d.ts","sourceRoot":"","sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"injectRuntimeTranslateImport.d.ts","sourceRoot":"","sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EACzB,EACE,WAAW,EACX,QAAQ,EACR,yBAAyB,GAC1B,EAAE;IACD,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,yBAAyB,EAAE,OAAO,CAAC;CACpC,GACA,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAsBtC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
3
3
|
require("../../utils/constants/gt/constants.js");
|
|
4
|
+
const require_utils_constants_gt_helpers = require("../../utils/constants/gt/helpers.js");
|
|
4
5
|
let _babel_types = require("@babel/types");
|
|
5
6
|
_babel_types = require_runtime.__toESM(_babel_types);
|
|
6
7
|
//#region src/transform/runtime-translate/injectRuntimeTranslateImport.ts
|
|
7
8
|
/**
|
|
8
9
|
* Inject runtime translate import with only the specifiers needed.
|
|
9
|
-
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react
|
|
10
|
+
* `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`
|
|
10
11
|
*/
|
|
11
|
-
function injectRuntimeTranslateImport(path, { needsString, needsJsx }) {
|
|
12
|
+
function injectRuntimeTranslateImport(path, { needsString, needsJsx, legacyGtReactImportSource }) {
|
|
12
13
|
const specifiers = [];
|
|
13
14
|
if (needsString) {
|
|
14
15
|
const name = "GtInternalRuntimeTranslateString";
|
|
@@ -19,7 +20,7 @@ function injectRuntimeTranslateImport(path, { needsString, needsJsx }) {
|
|
|
19
20
|
specifiers.push(_babel_types.importSpecifier(_babel_types.identifier(name), _babel_types.identifier(name)));
|
|
20
21
|
}
|
|
21
22
|
if (specifiers.length === 0) return null;
|
|
22
|
-
const importDecl = _babel_types.importDeclaration(specifiers, _babel_types.stringLiteral(
|
|
23
|
+
const importDecl = _babel_types.importDeclaration(specifiers, _babel_types.stringLiteral(require_utils_constants_gt_helpers.getGtReactImportSource(legacyGtReactImportSource)));
|
|
23
24
|
const [inserted] = path.unshiftContainer("body", importDecl);
|
|
24
25
|
return inserted;
|
|
25
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectRuntimeTranslateImport.js","names":["t"],"sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport {
|
|
1
|
+
{"version":3,"file":"injectRuntimeTranslateImport.js","names":["t","getGtReactImportSource"],"sources":["../../../src/transform/runtime-translate/injectRuntimeTranslateImport.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport { NodePath } from '@babel/traverse';\nimport { GT_OTHER_FUNCTIONS } from '../../utils/constants/gt/constants';\nimport { getGtReactImportSource } from '../../utils/constants/gt/helpers';\n\n/**\n * Inject runtime translate import with only the specifiers needed.\n * `import { GtInternalRuntimeTranslateString, GtInternalRuntimeTranslateJsx } from 'gt-react'`\n */\nexport function injectRuntimeTranslateImport(\n path: NodePath<t.Program>,\n {\n needsString,\n needsJsx,\n legacyGtReactImportSource,\n }: {\n needsString: boolean;\n needsJsx: boolean;\n legacyGtReactImportSource: boolean;\n }\n): NodePath<t.ImportDeclaration> | null {\n const specifiers: t.ImportSpecifier[] = [];\n\n if (needsString) {\n const name = GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateString;\n specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));\n }\n\n if (needsJsx) {\n const name = GT_OTHER_FUNCTIONS.GtInternalRuntimeTranslateJsx;\n specifiers.push(t.importSpecifier(t.identifier(name), t.identifier(name)));\n }\n\n if (specifiers.length === 0) return null;\n\n const importDecl = t.importDeclaration(\n specifiers,\n t.stringLiteral(getGtReactImportSource(legacyGtReactImportSource))\n );\n\n const [inserted] = path.unshiftContainer('body', importDecl);\n return inserted as NodePath<t.ImportDeclaration>;\n}\n"],"mappings":";;;;;;;;;;;AASA,SAAgB,6BACd,MACA,EACE,aACA,UACA,6BAMoC;CACtC,MAAM,aAAkC,EAAE;AAE1C,KAAI,aAAa;EACf,MAAM,OAAA;AACN,aAAW,KAAKA,aAAE,gBAAgBA,aAAE,WAAW,KAAK,EAAEA,aAAE,WAAW,KAAK,CAAC,CAAC;;AAG5E,KAAI,UAAU;EACZ,MAAM,OAAA;AACN,aAAW,KAAKA,aAAE,gBAAgBA,aAAE,WAAW,KAAK,EAAEA,aAAE,WAAW,KAAK,CAAC,CAAC;;AAG5E,KAAI,WAAW,WAAW,EAAG,QAAO;CAEpC,MAAM,aAAaA,aAAE,kBACnB,YACAA,aAAE,cAAcC,mCAAAA,uBAAuB,0BAA0B,CAAC,CACnE;CAED,MAAM,CAAC,YAAY,KAAK,iBAAiB,QAAQ,WAAW;AAC5D,QAAO"}
|
|
@@ -6,7 +6,6 @@ const require_utils_parsing_getObjectPropertyFromObjectExpression = require("../
|
|
|
6
6
|
const require_utils_validation_validateExpressionIsStringLiteral = require("../../utils/validation/validateExpressionIsStringLiteral.js");
|
|
7
7
|
const require_utils_validation_validateChildrenFromObjectExpression = require("../../utils/validation/validateChildrenFromObjectExpression.js");
|
|
8
8
|
const require_transform_jsx_children_constructJsxChildren = require("../jsx-children/constructJsxChildren.js");
|
|
9
|
-
require("../jsx-children/index.js");
|
|
10
9
|
const require_utils_validation_validateExpressionIsNumericLiteral = require("../../utils/validation/validateExpressionIsNumericLiteral.js");
|
|
11
10
|
const require_utils_validation_validateExpressionIsBooleanLiteral = require("../../utils/validation/validateExpressionIsBooleanLiteral.js");
|
|
12
11
|
let _babel_types = require("@babel/types");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationComponentArgs.js","names":["t","validateChildrenPropertyFromObjectExpression","constructJsxChildren","getObjectPropertyFromObjectExpression","validateExpressionIsStringLiteral","validateExpressionIsNumericLiteral","validateExpressionIsBooleanLiteral"],"sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { getObjectPropertyFromObjectExpression } from '../../utils/parsing/getObjectPropertyFromObjectExpression';\nimport { validateExpressionIsStringLiteral } from '../../utils/validation/validateExpressionIsStringLiteral';\nimport type { JsxChildren } from '@generaltranslation/format/types';\nimport { constructJsxChildren } from '../jsx-children';\nimport { validateChildrenPropertyFromObjectExpression } from '../../utils/validation/validateChildrenFromObjectExpression';\nimport { validateExpressionIsNumericLiteral } from '../../utils/validation/validateExpressionIsNumericLiteral';\nimport { validateExpressionIsBooleanLiteral } from '../../utils/validation/validateExpressionIsBooleanLiteral';\nimport { validateDerive } from './validateTranslationFunction';\nimport { JsxValidationError } from '../jsx-children/errors';\n/**\n * Given a translation component, validate the arguments\n */\nexport function validateTranslationComponentArgs(\n callExprPath: NodePath<t.CallExpression>,\n canonicalName: string,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n // Check that there are at least 2 arguments (identifier, args)\n if (callExpr.arguments.length < 2) {\n const errors = [\n 'Translation component must have at least 2 arguments (identifier, args)',\n ];\n return { errors };\n }\n\n // Get the component args\n const args = callExpr.arguments[1];\n if (!t.isObjectExpression(args)) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n const argsPath = callExprPath.get('arguments')[1];\n if (!argsPath?.isObjectExpression()) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n\n // Map to appropriate validation function\n switch (canonicalName) {\n case GT_COMPONENT_TYPES.T:\n case GT_COMPONENT_TYPES.GtInternalTranslateJsx:\n return validateTComponentArgs(\n argsPath as NodePath<t.ObjectExpression>,\n state\n );\n default:\n const errors = [\n `Invalid translation component: ${canonicalName}. You likely passed a non-translation component to validateTranslationComponentArgs`,\n ];\n return { errors };\n }\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction validateTComponentArgs(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const errors: string[] = [];\n const args = argsPath.node;\n\n // Validate id\n const idValidation = validateStringProperty(args, 'id');\n errors.push(...idValidation.errors);\n const id = idValidation.value;\n\n // Validate context (with derive fallback)\n const contextValidation = validateStringProperty(args, 'context', state);\n errors.push(...contextValidation.errors);\n const context = contextValidation.value;\n // Validate maxChars\n const maxCharsValidation = validateNumberProperty(args, 'maxChars');\n errors.push(...maxCharsValidation.errors);\n const maxChars = maxCharsValidation.value;\n\n // Validate requiresReview\n const requiresReviewValidation = validateBooleanProperty(\n args,\n 'requiresReview'\n );\n errors.push(...requiresReviewValidation.errors);\n const requiresReview = requiresReviewValidation.value;\n\n // Validate hash\n const hashValidation = validateStringProperty(args, '_hash');\n errors.push(...hashValidation.errors);\n const _hash = hashValidation.value;\n\n // Validate children\n const childrenValidation = validateChildrenProperty(argsPath, state);\n errors.push(...childrenValidation.errors);\n const children = childrenValidation.value;\n\n const hasDeriveContext =\n contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive;\n\n return {\n errors,\n id,\n context,\n _hash,\n maxChars,\n requiresReview,\n children,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate that the children property is a string literal\n */\nexport function validateChildrenProperty(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n value?: JsxChildren;\n hasAutoderive?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the children property\n const childrenValidation =\n validateChildrenPropertyFromObjectExpression(argsPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(...childrenValidation.errors);\n return { errors };\n }\n const children = childrenValidation.value;\n if (children === undefined) {\n errors.push(`The <${GT_COMPONENT_TYPES.T}> component must have children`);\n return { errors };\n }\n\n // constructJsxChildren now returns JsxValidationError[]\n const validation = constructJsxChildren(children, state);\n\n // Autoderive: filter out dynamic-content errors\n let hasAutoderive = false;\n let filteredErrors: JsxValidationError[] = validation.errors;\n if (state.settings.autoderive.jsx) {\n filteredErrors = validation.errors.filter(\n (e) => e.type !== 'dynamic-content'\n );\n hasAutoderive = filteredErrors.length < validation.errors.length;\n }\n\n // Convert structured errors back to strings\n errors.push(...filteredErrors.map((e) => e.message));\n const value = validation.value;\n\n return { errors, value, hasAutoderive };\n}\n\n// String Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n *\n */\nfunction validateStringProperty(\n args: t.ObjectExpression,\n name: string,\n state?: TransformState\n): {\n errors: string[];\n value?: string;\n hasDeriveExpression?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsStringLiteral(property, name);\n if (validation.errors.length === 0) {\n return { errors, value: validation.value };\n }\n\n // String validation failed — check if it's a valid derive() expression\n if (state && t.isObjectProperty(property) && t.isExpression(property.value)) {\n const deriveErrors: string[] = [];\n validateDerive(property.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n return { errors, hasDeriveExpression: true };\n }\n }\n\n // Neither string nor derive — return original errors\n errors.push(...validation.errors);\n return { errors };\n}\n\n/**\n * Validate that an object property is a string literal\n */\nfunction validateObjectPropertyIsStringLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: string;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsStringLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a string literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the string literal\n const value = getStringLiteralFromExpression(arg.value);\n return { errors, value };\n}\n\n/**\n * Given an expression, return the string literal (throws an error if not a string literal)\n */\nfunction getStringLiteralFromExpression(\n expr: t.Expression\n): string | undefined {\n if (t.isStringLiteral(expr)) {\n return expr.value;\n }\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return expr.quasis[0]?.value.cooked || '';\n }\n }\n}\n\n// Number Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n */\nfunction validateNumberProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsNumberLiteral(property, name);\n errors.push(...validation.errors);\n const value = validation.value;\n\n return { errors, value };\n}\n\n/**\n * Validate that an object property is a number literal\n */\nfunction validateObjectPropertyIsNumberLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsNumericLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a number literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the number literal\n const value = getNumberLiteralFromExpression(arg.value);\n\n // Validate it is an integer\n if (value !== undefined && !validateNumberLiteralIsInteger(value)) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have an integer in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given an expression, return the number literal (throws an error if not a number literal)\n */\nfunction getNumberLiteralFromExpression(\n expr: t.Expression\n): number | undefined {\n if (t.isNumericLiteral(expr)) {\n return expr.value;\n }\n // handle numbers with unary operators\n if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // On purpose, we are taking the absolute value of the number literal\n return expr.argument.value;\n }\n}\n\n/**\n * Validate that a number literal is an integer\n */\nfunction validateNumberLiteralIsInteger(value: number): boolean {\n return Number.isInteger(value);\n}\n\n// Boolean Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $.\n * Only boolean literals are accepted — string \"true\"/\"false\" and dynamic\n * expressions are rejected because the value is hash-changing.\n */\nfunction validateBooleanProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n if (\n !t.isObjectProperty(property) ||\n !t.isExpression(property.value) ||\n !validateExpressionIsBooleanLiteral(property.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a boolean literal (true or false) in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value: (property.value as t.BooleanLiteral).value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,iCACd,cACA,eACA,OAUA;CACA,MAAM,WAAW,aAAa;AAE9B,KAAI,SAAS,UAAU,SAAS,EAI9B,QAAO,EAAE,QAAA,CAFP,0EAEa,EAAE;CAIn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,EAAE,QAAQ;;AAGnB,QAAO;EAAE;EAAQ;EAAO;;;;;AAM1B,SAAS,+BACP,MACoB;AACpB,KAAIL,aAAE,iBAAiB,KAAK,CAC1B,QAAO,KAAK;AAGd,KAAIA,aAAE,kBAAkB,KAAK,IAAIA,aAAE,iBAAiB,KAAK,SAAS,CAEhE,QAAO,KAAK,SAAS;;;;;AAOzB,SAAS,+BAA+B,OAAwB;AAC9D,QAAO,OAAO,UAAU,MAAM;;;;;;;AAUhC,SAAS,wBACP,MACA,MAIA;CACA,MAAM,SAAmB,EAAE;CAG3B,MAAM,WACJG,4DAAAA,sCAAsC,MAAM,KAAK,IACjDA,4DAAAA,sCAAsC,MAAM,MAAM,KAAK;AACzD,KAAI,CAAC,SACH,QAAO,EAAE,QAAQ;AAGnB,KACE,CAACH,aAAE,iBAAiB,SAAS,IAC7B,CAACA,aAAE,aAAa,SAAS,MAAM,IAC/B,CAACM,4DAAAA,mCAAmC,SAAS,MAAM,EACnD;AACA,SAAO,KACL,wEAA8F,KAAK,QACpG;AACD,SAAO,EAAE,QAAQ;;AAGnB,QAAO;EAAE;EAAQ,OAAQ,SAAS,MAA2B;EAAO"}
|
|
1
|
+
{"version":3,"file":"validateTranslationComponentArgs.js","names":["t","validateChildrenPropertyFromObjectExpression","constructJsxChildren","getObjectPropertyFromObjectExpression","validateExpressionIsStringLiteral","validateExpressionIsNumericLiteral","validateExpressionIsBooleanLiteral"],"sources":["../../../src/transform/validation/validateTranslationComponentArgs.ts"],"sourcesContent":["import { TransformState } from '../../state/types';\nimport { GT_COMPONENT_TYPES } from '../../utils/constants/gt/constants';\nimport * as t from '@babel/types';\nimport type { NodePath } from '@babel/traverse';\nimport { getObjectPropertyFromObjectExpression } from '../../utils/parsing/getObjectPropertyFromObjectExpression';\nimport { validateExpressionIsStringLiteral } from '../../utils/validation/validateExpressionIsStringLiteral';\nimport type { JsxChildren } from '@generaltranslation/format/types';\nimport { constructJsxChildren } from '../jsx-children/constructJsxChildren';\nimport { validateChildrenPropertyFromObjectExpression } from '../../utils/validation/validateChildrenFromObjectExpression';\nimport { validateExpressionIsNumericLiteral } from '../../utils/validation/validateExpressionIsNumericLiteral';\nimport { validateExpressionIsBooleanLiteral } from '../../utils/validation/validateExpressionIsBooleanLiteral';\nimport { validateDerive } from './validateTranslationFunction';\nimport { JsxValidationError } from '../jsx-children/errors';\n/**\n * Given a translation component, validate the arguments\n */\nexport function validateTranslationComponentArgs(\n callExprPath: NodePath<t.CallExpression>,\n canonicalName: string,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n // Check that there are at least 2 arguments (identifier, args)\n if (callExpr.arguments.length < 2) {\n const errors = [\n 'Translation component must have at least 2 arguments (identifier, args)',\n ];\n return { errors };\n }\n\n // Get the component args\n const args = callExpr.arguments[1];\n if (!t.isObjectExpression(args)) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n const argsPath = callExprPath.get('arguments')[1];\n if (!argsPath?.isObjectExpression()) {\n const errors = [\n 'Translation component must have an object expression as the second argument',\n ];\n return { errors };\n }\n\n // Map to appropriate validation function\n switch (canonicalName) {\n case GT_COMPONENT_TYPES.T:\n case GT_COMPONENT_TYPES.GtInternalTranslateJsx:\n return validateTComponentArgs(\n argsPath as NodePath<t.ObjectExpression>,\n state\n );\n default:\n const errors = [\n `Invalid translation component: ${canonicalName}. You likely passed a non-translation component to validateTranslationComponentArgs`,\n ];\n return { errors };\n }\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction validateTComponentArgs(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n _hash?: string;\n id?: string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n children?: JsxChildren;\n hasDeriveContext?: boolean;\n} {\n const errors: string[] = [];\n const args = argsPath.node;\n\n // Validate id\n const idValidation = validateStringProperty(args, 'id');\n errors.push(...idValidation.errors);\n const id = idValidation.value;\n\n // Validate context (with derive fallback)\n const contextValidation = validateStringProperty(args, 'context', state);\n errors.push(...contextValidation.errors);\n const context = contextValidation.value;\n // Validate maxChars\n const maxCharsValidation = validateNumberProperty(args, 'maxChars');\n errors.push(...maxCharsValidation.errors);\n const maxChars = maxCharsValidation.value;\n\n // Validate requiresReview\n const requiresReviewValidation = validateBooleanProperty(\n args,\n 'requiresReview'\n );\n errors.push(...requiresReviewValidation.errors);\n const requiresReview = requiresReviewValidation.value;\n\n // Validate hash\n const hashValidation = validateStringProperty(args, '_hash');\n errors.push(...hashValidation.errors);\n const _hash = hashValidation.value;\n\n // Validate children\n const childrenValidation = validateChildrenProperty(argsPath, state);\n errors.push(...childrenValidation.errors);\n const children = childrenValidation.value;\n\n const hasDeriveContext =\n contextValidation.hasDeriveExpression || childrenValidation.hasAutoderive;\n\n return {\n errors,\n id,\n context,\n _hash,\n maxChars,\n requiresReview,\n children,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate that the children property is a string literal\n */\nexport function validateChildrenProperty(\n argsPath: NodePath<t.ObjectExpression>,\n state: TransformState\n): {\n errors: string[];\n value?: JsxChildren;\n hasAutoderive?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the children property\n const childrenValidation =\n validateChildrenPropertyFromObjectExpression(argsPath);\n if (childrenValidation.errors.length > 0) {\n errors.push(...childrenValidation.errors);\n return { errors };\n }\n const children = childrenValidation.value;\n if (children === undefined) {\n errors.push(`The <${GT_COMPONENT_TYPES.T}> component must have children`);\n return { errors };\n }\n\n // constructJsxChildren now returns JsxValidationError[]\n const validation = constructJsxChildren(children, state);\n\n // Autoderive: filter out dynamic-content errors\n let hasAutoderive = false;\n let filteredErrors: JsxValidationError[] = validation.errors;\n if (state.settings.autoderive.jsx) {\n filteredErrors = validation.errors.filter(\n (e) => e.type !== 'dynamic-content'\n );\n hasAutoderive = filteredErrors.length < validation.errors.length;\n }\n\n // Convert structured errors back to strings\n errors.push(...filteredErrors.map((e) => e.message));\n const value = validation.value;\n\n return { errors, value, hasAutoderive };\n}\n\n// String Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n *\n */\nfunction validateStringProperty(\n args: t.ObjectExpression,\n name: string,\n state?: TransformState\n): {\n errors: string[];\n value?: string;\n hasDeriveExpression?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsStringLiteral(property, name);\n if (validation.errors.length === 0) {\n return { errors, value: validation.value };\n }\n\n // String validation failed — check if it's a valid derive() expression\n if (state && t.isObjectProperty(property) && t.isExpression(property.value)) {\n const deriveErrors: string[] = [];\n validateDerive(property.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n return { errors, hasDeriveExpression: true };\n }\n }\n\n // Neither string nor derive — return original errors\n errors.push(...validation.errors);\n return { errors };\n}\n\n/**\n * Validate that an object property is a string literal\n */\nfunction validateObjectPropertyIsStringLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: string;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsStringLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a string literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the string literal\n const value = getStringLiteralFromExpression(arg.value);\n return { errors, value };\n}\n\n/**\n * Given an expression, return the string literal (throws an error if not a string literal)\n */\nfunction getStringLiteralFromExpression(\n expr: t.Expression\n): string | undefined {\n if (t.isStringLiteral(expr)) {\n return expr.value;\n }\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return expr.quasis[0]?.value.cooked || '';\n }\n }\n}\n\n// Number Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $\n */\nfunction validateNumberProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n // Validate property\n const validation = validateObjectPropertyIsNumberLiteral(property, name);\n errors.push(...validation.errors);\n const value = validation.value;\n\n return { errors, value };\n}\n\n/**\n * Validate that an object property is a number literal\n */\nfunction validateObjectPropertyIsNumberLiteral(\n arg: t.SpreadElement | t.ObjectMethod | t.ObjectProperty,\n name: string\n): {\n errors: string[];\n value?: number;\n} {\n const errors: string[] = [];\n\n // Validate the property is a string literal from an expression\n if (\n !t.isObjectProperty(arg) ||\n !t.isExpression(arg.value) ||\n !validateExpressionIsNumericLiteral(arg.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a number literal in its ${name} field`\n );\n return { errors };\n }\n\n // Get the number literal\n const value = getNumberLiteralFromExpression(arg.value);\n\n // Validate it is an integer\n if (value !== undefined && !validateNumberLiteralIsInteger(value)) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have an integer in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value };\n}\n\n/**\n * Given an expression, return the number literal (throws an error if not a number literal)\n */\nfunction getNumberLiteralFromExpression(\n expr: t.Expression\n): number | undefined {\n if (t.isNumericLiteral(expr)) {\n return expr.value;\n }\n // handle numbers with unary operators\n if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // On purpose, we are taking the absolute value of the number literal\n return expr.argument.value;\n }\n}\n\n/**\n * Validate that a number literal is an integer\n */\nfunction validateNumberLiteralIsInteger(value: number): boolean {\n return Number.isInteger(value);\n}\n\n// Boolean Literal Functions\n\n/**\n * Will validate and retrieve property from object expression and also try prefixing with a $.\n * Only boolean literals are accepted — string \"true\"/\"false\" and dynamic\n * expressions are rejected because the value is hash-changing.\n */\nfunction validateBooleanProperty(\n args: t.ObjectExpression,\n name: string\n): {\n errors: string[];\n value?: boolean;\n} {\n const errors: string[] = [];\n\n // Get the property\n const property =\n getObjectPropertyFromObjectExpression(args, name) ||\n getObjectPropertyFromObjectExpression(args, '$' + name);\n if (!property) {\n return { errors };\n }\n\n if (\n !t.isObjectProperty(property) ||\n !t.isExpression(property.value) ||\n !validateExpressionIsBooleanLiteral(property.value)\n ) {\n errors.push(\n `The <${GT_COMPONENT_TYPES.T}> component must have a boolean literal (true or false) in its ${name} field`\n );\n return { errors };\n }\n\n return { errors, value: (property.value as t.BooleanLiteral).value };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,iCACd,cACA,eACA,OAUA;CACA,MAAM,WAAW,aAAa;AAE9B,KAAI,SAAS,UAAU,SAAS,EAI9B,QAAO,EAAE,QAAA,CAFP,0EAEa,EAAE;CAInB,MAAM,OAAO,SAAS,UAAU;AAChC,KAAI,CAACA,aAAE,mBAAmB,KAAK,CAI7B,QAAO,EAAE,QAAA,CAFP,8EAEa,EAAE;CAEnB,MAAM,WAAW,aAAa,IAAI,YAAY,CAAC;AAC/C,KAAI,EAAA,aAAA,QAAA,aAAA,KAAA,IAAA,KAAA,IAAC,SAAU,oBAAoB,EAIjC,QAAO,EAAE,QAAA,CAFP,8EAEa,EAAE;AAInB,SAAQ,eAAR;EACE,KAAA;EACA,KAAA,yBACE,QAAO,uBACL,UACA,MACD;EACH,QAIE,QAAO,EAAE,QAAA,CAFP,kCAAkC,cAAc,qFAEnC,EAAE;;;AAQvB,SAAS,uBACP,UACA,OAUA;CACA,MAAM,SAAmB,EAAE;CAC3B,MAAM,OAAO,SAAS;CAGtB,MAAM,eAAe,uBAAuB,MAAM,KAAK;AACvD,QAAO,KAAK,GAAG,aAAa,OAAO;CACnC,MAAM,KAAK,aAAa;CAGxB,MAAM,oBAAoB,uBAAuB,MA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L,wEAA8F,KAAK,QACpG;AACD,SAAO,EAAE,QAAQ;;AAGnB,QAAO;EAAE;EAAQ,OAAQ,SAAS,MAA2B;EAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationFunction.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EACxC,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAmIA;AAED;;;GAGG;AAEH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IAC5E,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAED;;;GAGG;AAEH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAgJD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,CAAC,CAAC,UAAU,EAClB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,MAAM,EAAE,GACf;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"validateTranslationFunction.d.ts","sourceRoot":"","sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,EACxC,KAAK,EAAE,cAAc,GACpB;IACD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAmIA;AAED;;;GAGG;AAEH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IAC5E,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAED;;;GAGG;AAEH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,CAAC,CAAC,cAAc,GAAG;IACxE,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAGA;AAgJD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,CAAC,CAAC,UAAU,EAClB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,MAAM,EAAE,GACf;IAAE,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAmFtB"}
|
|
@@ -173,11 +173,11 @@ function validateDerive(expr, state, errors) {
|
|
|
173
173
|
errors.push("Expression does not use an allowed call expression");
|
|
174
174
|
return { errors };
|
|
175
175
|
}
|
|
176
|
-
if (type !== "generaltranslation" || canonicalName !== "
|
|
176
|
+
if (type !== "generaltranslation" || canonicalName !== "derive") {
|
|
177
177
|
errors.push("Expression does not use an allowed call expression");
|
|
178
178
|
return { errors };
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
validateDeriveCallExpression(expr, errors);
|
|
181
181
|
return { errors };
|
|
182
182
|
}
|
|
183
183
|
if (_babel_types.isBinaryExpression(expr) && expr.operator === "+") {
|
|
@@ -207,7 +207,7 @@ function validateDerive(expr, state, errors) {
|
|
|
207
207
|
* - the argument is a call expression
|
|
208
208
|
* Example: derive(getName())
|
|
209
209
|
*/
|
|
210
|
-
function
|
|
210
|
+
function validateDeriveCallExpression(expr, errors) {
|
|
211
211
|
if (expr.arguments.length !== 1) {
|
|
212
212
|
errors.push("derive() must have one argument");
|
|
213
213
|
return { errors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateTranslationFunction.js","names":["t","resolveStaticExpression","getCalleeNameFromExpression","getTrackedVariable"],"sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\nimport { TransformState } from '../../state/types';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n resolveStaticExpression,\n type ResolveStaticExpressionError,\n} from '../../utils/string-expressions/resolveStaticExpression';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { NodePath } from '@babel/traverse';\n\n/**\n * Validate useGT_callback / getGT_callback / msg() / t()\n * - first argument must be a statically resolvable string expression\n * (string literal, template literal, binary '+' concatenation, or derive() call)\n * - second argument, if present, $id field + $context field must be a string literal\n */\nexport function validateTranslationFunction(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n): {\n errors: string[];\n content?: string;\n context?: string;\n hash?: string;\n id?: string;\n maxChars?: number;\n format?: string;\n requiresReview?: boolean;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n const errors: string[] = [];\n\n // Validate that the function has at least 1 argument\n if (callExpr.arguments.length < 1) {\n errors.push('registration function must have at least 1 argument');\n return { errors };\n }\n\n // Validate first argument\n if (!t.isExpression(callExpr.arguments[0])) {\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n\n // Try to resolve the expression to a static string (handles concat, nested templates, etc.)\n const resolvedStaticExpression = resolveStaticExpression(\n callExprPath.get('arguments')[0] as NodePath<t.Expression>\n );\n // TODO: until we implement derivation, we will only need to check the first value\n const content = resolvedStaticExpression.values?.[0];\n const resolutionErrors = getResolutionErrorMessages(\n resolvedStaticExpression.errors,\n false\n );\n\n if (resolutionErrors.length > 0) {\n return { errors: resolutionErrors };\n }\n\n if (content === undefined && !state.settings.autoderive.strings) {\n // Not a static expression — check if it contains a derive() function invocation\n validateDerive(callExpr.arguments[0], state, errors);\n if (errors.length > 0) {\n errors.push(\n ...getResolutionErrorMessages(resolvedStaticExpression.errors)\n );\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n }\n\n // TODO: hasDeriveContext should be refactored to enforce no hash generated HERE in this function\n // instead of passing that information outside of this function.\n // We skip hash gen with autoderive, derive in content, and derive in $context. This flag is being\n // reused for all 3 cases.\n const contentHasAutoderive =\n state.settings.autoderive.strings && content === undefined;\n\n // Validate second argument\n let context: string | undefined;\n let id: string | undefined;\n let hash: string | undefined;\n let maxChars: number | undefined;\n let format: string | undefined;\n let requiresReview: boolean | undefined;\n let hasDeriveContext: boolean | undefined;\n if (callExpr.arguments.length === 1) {\n return {\n errors,\n content,\n hasDeriveContext: contentHasAutoderive || undefined,\n };\n }\n if (t.isObjectExpression(callExpr.arguments[1])) {\n const objExprPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n const contextProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$context,\n 'string-or-derive',\n state\n );\n errors.push(...contextProperty.errors);\n context = contextProperty.value as string | undefined;\n hasDeriveContext =\n contentHasAutoderive || contextProperty.hasDeriveExpression;\n const idProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$id,\n 'string'\n );\n errors.push(...idProperty.errors);\n id = idProperty.value;\n const maxCharsProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$maxChars,\n 'number'\n );\n errors.push(...maxCharsProperty.errors);\n maxChars = maxCharsProperty.value;\n const hashProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$_hash,\n 'string'\n );\n errors.push(...hashProperty.errors);\n hash = hashProperty.value;\n const formatProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$format,\n 'string'\n );\n errors.push(...formatProperty.errors);\n format = formatProperty.value;\n const requiresReviewProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$requiresReview,\n 'boolean'\n );\n errors.push(...requiresReviewProperty.errors);\n requiresReview = requiresReviewProperty.value;\n }\n\n return {\n errors,\n content,\n context,\n id,\n hash,\n maxChars,\n format,\n requiresReview,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate useTranslations_callback / getTranslations_callback\n * - always valid (arguments can be dynamic)\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseTranslationsCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/**\n * Validate useMessages_callback / getMessages_callback\n * - always valid\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseMessagesCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction getResolutionErrorMessages(\n errors: ResolveStaticExpressionError[],\n includeDynamic = true\n): string[] {\n return errors\n .filter((error) => includeDynamic || error.kind !== 'dynamic-expression')\n .map(({ message }) => message);\n}\n\n/**\n * Validate a property from an object expression\n * @param objExpr - The object expression to validate\n * @param name - The name of the property to validate\n * @returns The validated property\n */\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string'\n): { errors: string[]; value?: string };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'number'\n): { errors: string[]; value?: number };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'boolean'\n): { errors: string[]; value?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string-or-derive',\n state: TransformState\n): { errors: string[]; value?: string; hasDeriveExpression?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string' | 'number' | 'boolean' | 'string-or-derive',\n state?: TransformState\n): {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n} {\n const result: {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n } = { errors: [] };\n let valuePath: NodePath<t.ObjectProperty> | undefined;\n for (const propertyPath of objExprPath.get('properties')) {\n if (!propertyPath.isObjectProperty()) {\n continue;\n }\n const property = propertyPath.node;\n if (t.isIdentifier(property.key) && property.key.name === name) {\n valuePath = propertyPath;\n break;\n }\n if (t.isStringLiteral(property.key) && property.key.value === name) {\n valuePath = propertyPath;\n break;\n }\n }\n\n // return result if no value found\n if (!valuePath) {\n return result;\n }\n\n const value = valuePath.node;\n\n // validate value\n if (!t.isExpression(value.value)) {\n result.errors.push(\n `registration function must use a string literal for its ${name} field. Variable content is not allowed.`\n );\n return result;\n }\n\n // extract value\n if (type === 'string-or-derive') {\n const resolved = resolveStaticExpression(\n valuePath.get('value') as NodePath<t.Expression>\n );\n const resolutionErrors = getResolutionErrorMessages(resolved.errors, false);\n // TODO: until we implement derivation, we will only need to check the first value\n if (resolved.values?.[0] !== undefined) {\n result.value = resolved.values[0];\n } else if (resolutionErrors.length > 0) {\n result.errors.push(...resolutionErrors);\n } else if (state) {\n // Static resolution failed — check if it's a valid derive() expression\n const deriveErrors: string[] = [];\n validateDerive(value.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n result.hasDeriveExpression = true;\n } else {\n result.errors.push(\n ...getResolutionErrorMessages(resolved.errors),\n ...deriveErrors\n );\n }\n } else {\n result.errors.push(...getResolutionErrorMessages(resolved.errors));\n }\n } else {\n const validatedValue =\n type === 'string'\n ? validateExpressionIsStringLiteral(value.value)\n : type === 'boolean'\n ? validateExpressionIsBooleanLiteral(value.value)\n : validateExpressionIsNumericLiteral(value.value);\n result.errors.push(...validatedValue.errors);\n result.value = validatedValue.value;\n }\n\n return result;\n}\n\n/**\n * Validate that an expression is a string literal\n */\nfunction validateExpressionIsStringLiteral(expr: t.Expression): {\n errors: string[];\n value?: string;\n} {\n if (t.isStringLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {\n return { errors: [], value: expr.quasis[0]?.value.cooked };\n }\n return { errors: ['Expression is not a string literal'] };\n}\n\n/**\n * Validates if an expression uses the derive() function correctly\n */\nexport function validateDerive(\n expr: t.Expression,\n state: TransformState,\n errors: string[]\n): { errors: string[] } {\n if (!expr) {\n errors.push('Expression is empty');\n return { errors };\n }\n\n // 1. Direct call: derive(node)\n if (t.isCallExpression(expr)) {\n // Find the canonical function name\n const { namespaceName, functionName } = getCalleeNameFromExpression(expr);\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate the function is actually the GT derive function\n if (\n type !== 'generaltranslation' ||\n (canonicalName !== GT_OTHER_FUNCTIONS.declareStatic &&\n canonicalName !== GT_OTHER_FUNCTIONS.derive)\n ) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate that the call expression has exactly one argument and the argument is a call expression\n validateDeclareStaticExpression(expr, errors);\n return { errors };\n }\n\n // 2. String concatenation: \"Hello there \" + derive(getName())\n if (t.isBinaryExpression(expr) && expr.operator === '+') {\n if (!t.isExpression(expr.left) || !t.isExpression(expr.right)) {\n errors.push('Operands must be expressions');\n return { errors };\n }\n validateDerive(expr.right, state, errors);\n validateDerive(expr.left, state, errors);\n return { errors };\n }\n\n // 3. Template literal: `Hello there ${derive(getName())}` or `static text`\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return { errors };\n }\n if (\n !expr.expressions.some(\n (expression) =>\n t.isExpression(expression) &&\n validateDerive(expression, state, errors).errors.length === 0\n )\n ) {\n errors.push('Expression does not use an allowed call expression');\n }\n return {\n errors,\n };\n }\n\n // 4. Static literals (string, number, boolean, null)\n if (t.isStringLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNumericLiteral(expr)) {\n return { errors };\n }\n\n if (t.isBooleanLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNullLiteral(expr)) {\n return { errors };\n }\n\n // Fallthrough: expression type not supported (e.g., plain identifiers/variables)\n errors.push('Variables are not allowed');\n return { errors };\n}\n\n/**\n * Takes in a call expression to check if:\n * - it has exactly one argument\n * - the argument is a call expression\n * Example: derive(getName())\n */\nfunction validateDeclareStaticExpression(\n expr: t.CallExpression,\n errors: string[]\n): {\n errors: string[];\n} {\n // Validate that the function has 1 argument\n if (expr.arguments.length !== 1) {\n errors.push('derive() must have one argument');\n return { errors };\n }\n const [onlyArg] = expr.arguments;\n\n // Await expression: derive(await ...)\n if (t.isAwaitExpression(onlyArg)) {\n // Validate that the awaited expression is a call expression\n if (!t.isCallExpression(onlyArg.argument)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n // Valid: derive(await someFunction())\n return { errors };\n }\n\n // Validate that the argument is a call expression\n if (!t.isCallExpression(onlyArg)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n\n return { errors };\n}\n\n/**\n * Validate that an expression is a boolean literal (strictly `true` or\n * `false` — never string \"true\"/\"false\" or a dynamic expression).\n *\n * NOTE: a standalone predicate with the same logic exists at\n * `../../utils/validation/validateExpressionIsBooleanLiteral` (returns a\n * plain boolean). This local copy returns `{ errors, value }` to match the\n * interface of the sibling string/number validators in this file — the same\n * local-vs-utility duality those validators already have.\n */\nfunction validateExpressionIsBooleanLiteral(expr: t.Expression): {\n errors: string[];\n value?: boolean;\n} {\n if (t.isBooleanLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n return { errors: ['Expression is not a boolean literal'] };\n}\n\n/**\n * Validate that an expression is a number literal\n */\nfunction validateExpressionIsNumericLiteral(expr: t.Expression): {\n errors: string[];\n value?: number;\n} {\n let candidateValue: number | undefined;\n if (t.isNumericLiteral(expr)) {\n candidateValue = expr.value;\n } else if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // Note: taking the absolute value of the number literal\n candidateValue = expr.argument.value;\n }\n\n // validate is integer\n if (candidateValue !== undefined && !Number.isInteger(candidateValue)) {\n return { errors: ['Expression is not an integer'] };\n }\n\n // no value found\n if (candidateValue === undefined) {\n return { errors: ['Expression is not a number literal'] };\n }\n\n return { errors: [], value: candidateValue };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,4BACd,cACA,OAWA;;CACA,MAAM,WAAW,aAAa;CAC9B,MAAM,SAAmB,EAAE;AAG3B,KAAI,SAAS,UAAU,SAAS,GAAG;AACjC,SAAO,KAAK,sDAAsD;AAClE,SAAO,EAAE,QAAQ;;AAInB,KAAI,CAACA,aAAE,aAAa,SAAS,UAAU,GAAG,EAAE;AAC1C,SAAO,KACL,2HACD;AACD,SA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AG;AAC/B,SAAO,KAAK,kCAAkC;AAC9C,SAAO,EAAE,QAAQ;;CAEnB,MAAM,CAAC,WAAW,KAAK;AAGvB,KAAIA,aAAE,kBAAkB,QAAQ,EAAE;AAEhC,MAAI,CAACA,aAAE,iBAAiB,QAAQ,SAAS,EAAE;AACzC,UAAO,KAAK,uDAAuD;AACnE,UAAO,EAAE,QAAQ;;AAGnB,SAAO,EAAE,QAAQ;;AAInB,KAAI,CAACA,aAAE,iBAAiB,QAAQ,EAAE;AAChC,SAAO,KAAK,uDAAuD;AACnE,SAAO,EAAE,QAAQ;;AAGnB,QAAO,EAAE,QAAQ;;;;;;;;;;;;AAanB,SAAS,mCAAmC,MAG1C;AACA,KAAIA,aAAE,iBAAiB,KAAK,CAC1B,QAAO;EAAE,QAAQ,EAAE;EAAE,OAAO,KAAK;EAAO;AAE1C,QAAO,EAAE,QAAQ,CAAC,sCAAsC,EAAE;;;;;AAM5D,SAAS,mCAAmC,MAG1C;CACA,IAAI;AACJ,KAAIA,aAAE,iBAAiB,KAAK,CAC1B,kBAAiB,KAAK;UACbA,aAAE,kBAAkB,KAAK,IAAIA,aAAE,iBAAiB,KAAK,SAAS,CAEvE,kBAAiB,KAAK,SAAS;AAIjC,KAAI,mBAAmB,KAAA,KAAa,CAAC,OAAO,UAAU,eAAe,CACnE,QAAO,EAAE,QAAQ,CAAC,+BAA+B,EAAE;AAIrD,KAAI,mBAAmB,KAAA,EACrB,QAAO,EAAE,QAAQ,CAAC,qCAAqC,EAAE;AAG3D,QAAO;EAAE,QAAQ,EAAE;EAAE,OAAO;EAAgB"}
|
|
1
|
+
{"version":3,"file":"validateTranslationFunction.js","names":["t","resolveStaticExpression","getCalleeNameFromExpression","getTrackedVariable"],"sources":["../../../src/transform/validation/validateTranslationFunction.ts"],"sourcesContent":["import * as t from '@babel/types';\nimport {\n GT_OTHER_FUNCTIONS,\n USEGT_CALLBACK_OPTIONS,\n} from '../../utils/constants/gt/constants';\nimport { TransformState } from '../../state/types';\nimport { getCalleeNameFromExpression } from '../../utils/parsing/getCalleeNameFromExpression';\nimport {\n resolveStaticExpression,\n type ResolveStaticExpressionError,\n} from '../../utils/string-expressions/resolveStaticExpression';\nimport { getTrackedVariable } from '../getTrackedVariable';\nimport { NodePath } from '@babel/traverse';\n\n/**\n * Validate useGT_callback / getGT_callback / msg() / t()\n * - first argument must be a statically resolvable string expression\n * (string literal, template literal, binary '+' concatenation, or derive() call)\n * - second argument, if present, $id field + $context field must be a string literal\n */\nexport function validateTranslationFunction(\n callExprPath: NodePath<t.CallExpression>,\n state: TransformState\n): {\n errors: string[];\n content?: string;\n context?: string;\n hash?: string;\n id?: string;\n maxChars?: number;\n format?: string;\n requiresReview?: boolean;\n hasDeriveContext?: boolean;\n} {\n const callExpr = callExprPath.node;\n const errors: string[] = [];\n\n // Validate that the function has at least 1 argument\n if (callExpr.arguments.length < 1) {\n errors.push('registration function must have at least 1 argument');\n return { errors };\n }\n\n // Validate first argument\n if (!t.isExpression(callExpr.arguments[0])) {\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n\n // Try to resolve the expression to a static string (handles concat, nested templates, etc.)\n const resolvedStaticExpression = resolveStaticExpression(\n callExprPath.get('arguments')[0] as NodePath<t.Expression>\n );\n // TODO: until we implement derivation, we will only need to check the first value\n const content = resolvedStaticExpression.values?.[0];\n const resolutionErrors = getResolutionErrorMessages(\n resolvedStaticExpression.errors,\n false\n );\n\n if (resolutionErrors.length > 0) {\n return { errors: resolutionErrors };\n }\n\n if (content === undefined && !state.settings.autoderive.strings) {\n // Not a static expression — check if it contains a derive() function invocation\n validateDerive(callExpr.arguments[0], state, errors);\n if (errors.length > 0) {\n errors.push(\n ...getResolutionErrorMessages(resolvedStaticExpression.errors)\n );\n errors.push(\n 'registration function must use a string literal or derive() call as the first argument. Variable content is not allowed.'\n );\n return { errors };\n }\n }\n\n // TODO: hasDeriveContext should be refactored to enforce no hash generated HERE in this function\n // instead of passing that information outside of this function.\n // We skip hash gen with autoderive, derive in content, and derive in $context. This flag is being\n // reused for all 3 cases.\n const contentHasAutoderive =\n state.settings.autoderive.strings && content === undefined;\n\n // Validate second argument\n let context: string | undefined;\n let id: string | undefined;\n let hash: string | undefined;\n let maxChars: number | undefined;\n let format: string | undefined;\n let requiresReview: boolean | undefined;\n let hasDeriveContext: boolean | undefined;\n if (callExpr.arguments.length === 1) {\n return {\n errors,\n content,\n hasDeriveContext: contentHasAutoderive || undefined,\n };\n }\n if (t.isObjectExpression(callExpr.arguments[1])) {\n const objExprPath = callExprPath.get(\n 'arguments'\n )[1] as NodePath<t.ObjectExpression>;\n const contextProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$context,\n 'string-or-derive',\n state\n );\n errors.push(...contextProperty.errors);\n context = contextProperty.value as string | undefined;\n hasDeriveContext =\n contentHasAutoderive || contextProperty.hasDeriveExpression;\n const idProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$id,\n 'string'\n );\n errors.push(...idProperty.errors);\n id = idProperty.value;\n const maxCharsProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$maxChars,\n 'number'\n );\n errors.push(...maxCharsProperty.errors);\n maxChars = maxCharsProperty.value;\n const hashProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$_hash,\n 'string'\n );\n errors.push(...hashProperty.errors);\n hash = hashProperty.value;\n const formatProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$format,\n 'string'\n );\n errors.push(...formatProperty.errors);\n format = formatProperty.value;\n const requiresReviewProperty = validatePropertyFromObjectExpression(\n objExprPath,\n USEGT_CALLBACK_OPTIONS.$requiresReview,\n 'boolean'\n );\n errors.push(...requiresReviewProperty.errors);\n requiresReview = requiresReviewProperty.value;\n }\n\n return {\n errors,\n content,\n context,\n id,\n hash,\n maxChars,\n format,\n requiresReview,\n hasDeriveContext,\n };\n}\n\n/**\n * Validate useTranslations_callback / getTranslations_callback\n * - always valid (arguments can be dynamic)\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseTranslationsCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/**\n * Validate useMessages_callback / getMessages_callback\n * - always valid\n */\n// eslint-disable-next-line no-unused-vars\nexport function validateUseMessagesCallback(_callExpr: t.CallExpression): {\n errors: string[];\n} {\n const errors: string[] = [];\n return { errors };\n}\n\n/* =============================== */\n/* Helper Functions */\n/* =============================== */\n\nfunction getResolutionErrorMessages(\n errors: ResolveStaticExpressionError[],\n includeDynamic = true\n): string[] {\n return errors\n .filter((error) => includeDynamic || error.kind !== 'dynamic-expression')\n .map(({ message }) => message);\n}\n\n/**\n * Validate a property from an object expression\n * @param objExpr - The object expression to validate\n * @param name - The name of the property to validate\n * @returns The validated property\n */\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string'\n): { errors: string[]; value?: string };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'number'\n): { errors: string[]; value?: number };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'boolean'\n): { errors: string[]; value?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string-or-derive',\n state: TransformState\n): { errors: string[]; value?: string; hasDeriveExpression?: boolean };\nfunction validatePropertyFromObjectExpression(\n objExprPath: NodePath<t.ObjectExpression>,\n name: string,\n type: 'string' | 'number' | 'boolean' | 'string-or-derive',\n state?: TransformState\n): {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n} {\n const result: {\n errors: string[];\n value?: string | number | boolean;\n hasDeriveExpression?: boolean;\n } = { errors: [] };\n let valuePath: NodePath<t.ObjectProperty> | undefined;\n for (const propertyPath of objExprPath.get('properties')) {\n if (!propertyPath.isObjectProperty()) {\n continue;\n }\n const property = propertyPath.node;\n if (t.isIdentifier(property.key) && property.key.name === name) {\n valuePath = propertyPath;\n break;\n }\n if (t.isStringLiteral(property.key) && property.key.value === name) {\n valuePath = propertyPath;\n break;\n }\n }\n\n // return result if no value found\n if (!valuePath) {\n return result;\n }\n\n const value = valuePath.node;\n\n // validate value\n if (!t.isExpression(value.value)) {\n result.errors.push(\n `registration function must use a string literal for its ${name} field. Variable content is not allowed.`\n );\n return result;\n }\n\n // extract value\n if (type === 'string-or-derive') {\n const resolved = resolveStaticExpression(\n valuePath.get('value') as NodePath<t.Expression>\n );\n const resolutionErrors = getResolutionErrorMessages(resolved.errors, false);\n // TODO: until we implement derivation, we will only need to check the first value\n if (resolved.values?.[0] !== undefined) {\n result.value = resolved.values[0];\n } else if (resolutionErrors.length > 0) {\n result.errors.push(...resolutionErrors);\n } else if (state) {\n // Static expression resolution failed; check if it's a valid derive() expression.\n const deriveErrors: string[] = [];\n validateDerive(value.value, state, deriveErrors);\n if (deriveErrors.length === 0) {\n result.hasDeriveExpression = true;\n } else {\n result.errors.push(\n ...getResolutionErrorMessages(resolved.errors),\n ...deriveErrors\n );\n }\n } else {\n result.errors.push(...getResolutionErrorMessages(resolved.errors));\n }\n } else {\n const validatedValue =\n type === 'string'\n ? validateExpressionIsStringLiteral(value.value)\n : type === 'boolean'\n ? validateExpressionIsBooleanLiteral(value.value)\n : validateExpressionIsNumericLiteral(value.value);\n result.errors.push(...validatedValue.errors);\n result.value = validatedValue.value;\n }\n\n return result;\n}\n\n/**\n * Validate that an expression is a string literal\n */\nfunction validateExpressionIsStringLiteral(expr: t.Expression): {\n errors: string[];\n value?: string;\n} {\n if (t.isStringLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n if (t.isTemplateLiteral(expr) && expr.expressions.length === 0) {\n return { errors: [], value: expr.quasis[0]?.value.cooked };\n }\n return { errors: ['Expression is not a string literal'] };\n}\n\n/**\n * Validates if an expression uses the derive() function correctly\n */\nexport function validateDerive(\n expr: t.Expression,\n state: TransformState,\n errors: string[]\n): { errors: string[] } {\n if (!expr) {\n errors.push('Expression is empty');\n return { errors };\n }\n\n // 1. Direct call: derive(node)\n if (t.isCallExpression(expr)) {\n // Find the canonical function name\n const { namespaceName, functionName } = getCalleeNameFromExpression(expr);\n // Get the canonical function name\n const { canonicalName, type } = getTrackedVariable(\n state.scopeTracker,\n namespaceName,\n functionName\n );\n if (!canonicalName) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate the function is actually the GT derive function\n if (\n type !== 'generaltranslation' ||\n canonicalName !== GT_OTHER_FUNCTIONS.derive\n ) {\n errors.push('Expression does not use an allowed call expression');\n return { errors };\n }\n // Validate that the call expression has exactly one argument and the argument is a call expression\n validateDeriveCallExpression(expr, errors);\n return { errors };\n }\n\n // 2. String concatenation: \"Hello there \" + derive(getName())\n if (t.isBinaryExpression(expr) && expr.operator === '+') {\n if (!t.isExpression(expr.left) || !t.isExpression(expr.right)) {\n errors.push('Operands must be expressions');\n return { errors };\n }\n validateDerive(expr.right, state, errors);\n validateDerive(expr.left, state, errors);\n return { errors };\n }\n\n // 3. Template literal: `Hello there ${derive(getName())}` or `static text`\n if (t.isTemplateLiteral(expr)) {\n if (expr.expressions.length === 0) {\n return { errors };\n }\n if (\n !expr.expressions.some(\n (expression) =>\n t.isExpression(expression) &&\n validateDerive(expression, state, errors).errors.length === 0\n )\n ) {\n errors.push('Expression does not use an allowed call expression');\n }\n return {\n errors,\n };\n }\n\n // 4. Static literals (string, number, boolean, null)\n if (t.isStringLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNumericLiteral(expr)) {\n return { errors };\n }\n\n if (t.isBooleanLiteral(expr)) {\n return { errors };\n }\n\n if (t.isNullLiteral(expr)) {\n return { errors };\n }\n\n // Fallthrough: expression type not supported (e.g., plain identifiers/variables)\n errors.push('Variables are not allowed');\n return { errors };\n}\n\n/**\n * Takes in a call expression to check if:\n * - it has exactly one argument\n * - the argument is a call expression\n * Example: derive(getName())\n */\nfunction validateDeriveCallExpression(\n expr: t.CallExpression,\n errors: string[]\n): {\n errors: string[];\n} {\n // Validate that the function has 1 argument\n if (expr.arguments.length !== 1) {\n errors.push('derive() must have one argument');\n return { errors };\n }\n const [onlyArg] = expr.arguments;\n\n // Await expression: derive(await ...)\n if (t.isAwaitExpression(onlyArg)) {\n // Validate that the awaited expression is a call expression\n if (!t.isCallExpression(onlyArg.argument)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n // Valid: derive(await someFunction())\n return { errors };\n }\n\n // Validate that the argument is a call expression\n if (!t.isCallExpression(onlyArg)) {\n errors.push('derive() must have a call expression as the argument');\n return { errors };\n }\n\n return { errors };\n}\n\n/**\n * Validate that an expression is a boolean literal (strictly `true` or\n * `false` — never string \"true\"/\"false\" or a dynamic expression).\n *\n * NOTE: a standalone predicate with the same logic exists at\n * `../../utils/validation/validateExpressionIsBooleanLiteral` (returns a\n * plain boolean). This local copy returns `{ errors, value }` to match the\n * interface of the sibling string/number validators in this file — the same\n * local-vs-utility duality those validators already have.\n */\nfunction validateExpressionIsBooleanLiteral(expr: t.Expression): {\n errors: string[];\n value?: boolean;\n} {\n if (t.isBooleanLiteral(expr)) {\n return { errors: [], value: expr.value };\n }\n return { errors: ['Expression is not a boolean literal'] };\n}\n\n/**\n * Validate that an expression is a number literal\n */\nfunction validateExpressionIsNumericLiteral(expr: t.Expression): {\n errors: string[];\n value?: number;\n} {\n let candidateValue: number | undefined;\n if (t.isNumericLiteral(expr)) {\n candidateValue = expr.value;\n } else if (t.isUnaryExpression(expr) && t.isNumericLiteral(expr.argument)) {\n // Note: taking the absolute value of the number literal\n candidateValue = expr.argument.value;\n }\n\n // validate is integer\n if (candidateValue !== undefined && !Number.isInteger(candidateValue)) {\n return { errors: ['Expression is not an integer'] };\n }\n\n // no value found\n if (candidateValue === undefined) {\n return { errors: ['Expression is not a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AqC,EAAE;AAG3D,QAAO;EAAE,QAAQ,EAAE;EAAE,OAAO;EAAgB"}
|
|
@@ -2,10 +2,9 @@ import type { DataFormat, JsxChildren } from '@generaltranslation/format/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Given jsx children, calculate hash
|
|
4
4
|
*/
|
|
5
|
-
export default function hashSource({ source, context,
|
|
5
|
+
export default function hashSource({ source, context, maxChars, requiresReview, dataFormat, }: {
|
|
6
6
|
source: JsxChildren | string;
|
|
7
7
|
context?: string;
|
|
8
|
-
id?: string;
|
|
9
8
|
maxChars?: number;
|
|
10
9
|
requiresReview?: boolean;
|
|
11
10
|
dataFormat: DataFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHash.d.ts","sourceRoot":"","sources":["../../src/utils/calculateHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,WAAW,EAIZ,MAAM,kCAAkC,CAAC;AAG1C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,MAAM,EACN,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"calculateHash.d.ts","sourceRoot":"","sources":["../../src/utils/calculateHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,WAAW,EAIZ,MAAM,kCAAkC,CAAC;AAG1C;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,cAAc,EACd,UAAU,GACX,EAAE;IACD,MAAM,EAAE,WAAW,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,MAAM,CAgBT"}
|
|
@@ -8,11 +8,10 @@ let generaltranslation_id = require("generaltranslation/id");
|
|
|
8
8
|
/**
|
|
9
9
|
* Given jsx children, calculate hash
|
|
10
10
|
*/
|
|
11
|
-
function hashSource({ source, context,
|
|
11
|
+
function hashSource({ source, context, maxChars, requiresReview, dataFormat }) {
|
|
12
12
|
if (dataFormat === "ICU" || dataFormat === "I18NEXT") return (0, generaltranslation_id.hashSource)({
|
|
13
13
|
source,
|
|
14
14
|
context,
|
|
15
|
-
id,
|
|
16
15
|
maxChars,
|
|
17
16
|
requiresReview,
|
|
18
17
|
dataFormat
|
|
@@ -21,7 +20,6 @@ function hashSource({ source, context, id, maxChars, requiresReview, dataFormat
|
|
|
21
20
|
return (0, generaltranslation_id.hashSource)({
|
|
22
21
|
source,
|
|
23
22
|
context,
|
|
24
|
-
id,
|
|
25
23
|
maxChars,
|
|
26
24
|
requiresReview,
|
|
27
25
|
dataFormat
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n
|
|
1
|
+
{"version":3,"file":"calculateHash.js","names":[],"sources":["../../src/utils/calculateHash.ts"],"sourcesContent":["import type {\n DataFormat,\n JsxChild,\n JsxChildren,\n JsxElement,\n Variable,\n VariableType,\n} from '@generaltranslation/format/types';\nimport { hashSource as _hashSource } from 'generaltranslation/id';\n\n/**\n * Given jsx children, calculate hash\n */\nexport default function hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n}: {\n source: JsxChildren | string;\n context?: string;\n maxChars?: number;\n requiresReview?: boolean;\n dataFormat: DataFormat;\n}): string {\n // Delegate to the shared hasher without custom ids; ids are metadata only.\n if (dataFormat === 'ICU' || dataFormat === 'I18NEXT') {\n return _hashSource({\n source,\n context,\n maxChars,\n requiresReview,\n dataFormat,\n });\n }\n // For Jsx, we set hash to empty string if it contains a static component\n if (containsStatic(source)) {\n return '';\n }\n return _hashSource({ source, context, maxChars, requiresReview, dataFormat });\n}\n\n/* =============================================== */\n/* =============== HELPER FUNCTIONS ============== */\n/* =============================================== */\n\n/**\n * Check if the given source contains a static component\n * @param source\n */\nfunction containsStatic(source: JsxChildren): boolean {\n return handleChildren(source);\n}\n\nfunction handleChildren(source: JsxChildren): boolean {\n if (Array.isArray(source)) {\n return source.some((child) => handleChild(child));\n }\n return handleChild(source);\n}\n\nfunction handleChild(child: JsxChild): boolean {\n if (typeof child === 'string') {\n return false;\n }\n if (isVariable(child)) {\n return handleVariable(child);\n }\n return handleElement(child);\n}\n\nfunction handleVariable(variable: Variable): boolean {\n if (variable.v === ('s' as VariableType)) {\n return true;\n }\n return false;\n}\n\nfunction handleElement(element: JsxElement): boolean {\n // branches\n if (\n element.d &&\n element.d.t &&\n ['p', 'b'].includes(element.d.t) &&\n element.d.b\n ) {\n return Object.values(element.d.b).some((branch) => handleChildren(branch));\n }\n // children\n if (element.c) {\n return handleChildren(element.c);\n }\n return false;\n}\n\nfunction isVariable(obj: unknown): obj is Variable {\n const variableObj = obj as Variable;\n if (\n variableObj &&\n typeof variableObj === 'object' &&\n typeof (variableObj as Variable).k === 'string'\n ) {\n const k = Object.keys(variableObj);\n if (k.length === 1) return true;\n if (k.length === 2) {\n if (typeof variableObj.i === 'number') return true;\n if (typeof variableObj.v === 'string') return true;\n }\n if (k.length === 3) {\n if (\n typeof variableObj.v === 'string' &&\n typeof variableObj.i === 'number'\n )\n return true;\n }\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAwB,WAAW,EACjC,QACA,SACA,UACA,gBACA,cAOS;AAET,KAAI,eAAe,SAAS,eAAe,UACzC,SAAA,GAAA,sBAAA,YAAmB;EACjB;EACA;EACA;EACA;EACA;EACD,CAAC;AAGJ,KAAI,eAAe,OAAO,CACxB,QAAO;AAET,SAAA,GAAA,sBAAA,YA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eTime",
|
|
11
11
|
Num = "Num",
|
|
12
|
-
Static = "Static",
|
|
13
12
|
Derive = "Derive",
|
|
14
13
|
Branch = "Branch",
|
|
15
14
|
Plural = "Plural",
|
|
@@ -36,7 +35,6 @@ export declare enum GT_FUNCTIONS_WITH_CALLBACKS {
|
|
|
36
35
|
*/
|
|
37
36
|
export declare enum GT_OTHER_FUNCTIONS {
|
|
38
37
|
msg = "msg",
|
|
39
|
-
declareStatic = "declareStatic",
|
|
40
38
|
t = "t",
|
|
41
39
|
derive = "derive",
|
|
42
40
|
GtInternalRuntimeTranslateString = "GtInternalRuntimeTranslateString",
|
|
@@ -64,7 +62,7 @@ export declare const GT_FUNCTIONS_TO_CALLBACKS: Record<GT_FUNCTIONS_WITH_CALLBAC
|
|
|
64
62
|
/**
|
|
65
63
|
* GT derive functions
|
|
66
64
|
*/
|
|
67
|
-
export declare const GT_DERIVE_STRING_FUNCTIONS: readonly [GT_OTHER_FUNCTIONS.
|
|
65
|
+
export declare const GT_DERIVE_STRING_FUNCTIONS: readonly [GT_OTHER_FUNCTIONS.derive];
|
|
68
66
|
/**
|
|
69
67
|
* All gt functions (both regular and callback functions)
|
|
70
68
|
*/
|
|
@@ -74,7 +72,6 @@ export type GT_ALL_FUNCTIONS = GT_FUNCTIONS | GT_CALLBACK_FUNCTIONS | GT_COMPONE
|
|
|
74
72
|
*/
|
|
75
73
|
export declare enum GT_IMPORT_SOURCES {
|
|
76
74
|
GT_NEXT = "gt-next",
|
|
77
|
-
GT_NEXT_CLIENT = "gt-next/client",
|
|
78
75
|
GT_NEXT_SERVER = "gt-next/server",
|
|
79
76
|
GT_REACT = "gt-react",
|
|
80
77
|
GT_REACT_CLIENT = "gt-react/client",
|
|
@@ -120,7 +117,6 @@ export declare const MINIFY_CANONICAL_NAME_MAP: {
|
|
|
120
117
|
readonly DateTime: "d";
|
|
121
118
|
readonly GtInternalDateTime: "d";
|
|
122
119
|
readonly RelativeTime: "rt";
|
|
123
|
-
readonly Static: "s";
|
|
124
120
|
readonly Derive: "s";
|
|
125
121
|
readonly Branch: "b";
|
|
126
122
|
readonly Plural: "p";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/utils/constants/gt/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,CAAC,MAAM;IACP,EAAE,OAAO;IACT,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/utils/constants/gt/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,CAAC,MAAM;IACP,EAAE,OAAO;IACT,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,YAAY,iBAAiB;IAC7B,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,cAAc,mBAAmB;IACjC,sBAAsB,2BAA2B;IACjD,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;IAC/B,kBAAkB,uBAAuB;IACzC,kBAAkB,uBAAuB;CAC1C;AAED;;GAEG;AACH,oBAAY,2BAA2B;IACrC,KAAK,UAAU;IACf,KAAK,UAAU;IACf,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;CAC5B;AAED;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,GAAG,QAAQ;IACX,CAAC,MAAM;IACP,MAAM,WAAW;IACjB,gCAAgC,qCAAqC;IACrE,6BAA6B,kCAAkC;CAChE;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,2BAA2B,GAAG,kBAAkB,CAAC;AAC5E;;GAEG;AACH,oBAAY,qBAAqB;IAC/B,cAAc,mBAAmB;IACjC,cAAc,mBAAmB;IACjC,wBAAwB,6BAA6B;IACrD,wBAAwB,6BAA6B;IACrD,oBAAoB,yBAAyB;IAC7C,oBAAoB,yBAAyB;CAC9C;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAC5C,2BAA2B,EAC3B,qBAAqB,CAYtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,sCAAuC,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACxB,YAAY,GACZ,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,cAAc,mBAAmB;IACjC,QAAQ,aAAa;IACrB,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,OAAO,YAAY;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAAsB,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,aAA4B,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,YAAY,aAUvB,CAAC;AAEH;;GAEG;AACH,oBAAY,sBAAsB;IAChC,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,eAAe,oBAAoB;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;CAa5B,CAAC"}
|
|
@@ -11,7 +11,6 @@ let GT_COMPONENT_TYPES = /* @__PURE__ */ function(GT_COMPONENT_TYPES) {
|
|
|
11
11
|
GT_COMPONENT_TYPES["DateTime"] = "DateTime";
|
|
12
12
|
GT_COMPONENT_TYPES["RelativeTime"] = "RelativeTime";
|
|
13
13
|
GT_COMPONENT_TYPES["Num"] = "Num";
|
|
14
|
-
GT_COMPONENT_TYPES["Static"] = "Static";
|
|
15
14
|
GT_COMPONENT_TYPES["Derive"] = "Derive";
|
|
16
15
|
GT_COMPONENT_TYPES["Branch"] = "Branch";
|
|
17
16
|
GT_COMPONENT_TYPES["Plural"] = "Plural";
|
|
@@ -40,7 +39,6 @@ let GT_FUNCTIONS_WITH_CALLBACKS = /* @__PURE__ */ function(GT_FUNCTIONS_WITH_CAL
|
|
|
40
39
|
*/
|
|
41
40
|
let GT_OTHER_FUNCTIONS = /* @__PURE__ */ function(GT_OTHER_FUNCTIONS) {
|
|
42
41
|
GT_OTHER_FUNCTIONS["msg"] = "msg";
|
|
43
|
-
GT_OTHER_FUNCTIONS["declareStatic"] = "declareStatic";
|
|
44
42
|
GT_OTHER_FUNCTIONS["t"] = "t";
|
|
45
43
|
GT_OTHER_FUNCTIONS["derive"] = "derive";
|
|
46
44
|
GT_OTHER_FUNCTIONS["GtInternalRuntimeTranslateString"] = "GtInternalRuntimeTranslateString";
|
|
@@ -73,13 +71,12 @@ const GT_FUNCTIONS_TO_CALLBACKS = {
|
|
|
73
71
|
/**
|
|
74
72
|
* GT derive functions
|
|
75
73
|
*/
|
|
76
|
-
const GT_DERIVE_STRING_FUNCTIONS = ["
|
|
74
|
+
const GT_DERIVE_STRING_FUNCTIONS = ["derive"];
|
|
77
75
|
/**
|
|
78
76
|
* GT import sources
|
|
79
77
|
*/
|
|
80
78
|
let GT_IMPORT_SOURCES = /* @__PURE__ */ function(GT_IMPORT_SOURCES) {
|
|
81
79
|
GT_IMPORT_SOURCES["GT_NEXT"] = "gt-next";
|
|
82
|
-
GT_IMPORT_SOURCES["GT_NEXT_CLIENT"] = "gt-next/client";
|
|
83
80
|
GT_IMPORT_SOURCES["GT_NEXT_SERVER"] = "gt-next/server";
|
|
84
81
|
GT_IMPORT_SOURCES["GT_REACT"] = "gt-react";
|
|
85
82
|
GT_IMPORT_SOURCES["GT_REACT_CLIENT"] = "gt-react/client";
|
|
@@ -137,7 +134,6 @@ const MINIFY_CANONICAL_NAME_MAP = {
|
|
|
137
134
|
["DateTime"]: "d",
|
|
138
135
|
["GtInternalDateTime"]: "d",
|
|
139
136
|
["RelativeTime"]: "rt",
|
|
140
|
-
["Static"]: "s",
|
|
141
137
|
["Derive"]: "s",
|
|
142
138
|
["Branch"]: "b",
|
|
143
139
|
["Plural"]: "p"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../../../src/utils/constants/gt/constants.ts"],"sourcesContent":["/**\n * Different gt components\n */\nexport enum GT_COMPONENT_TYPES {\n T = 'T',\n Tx = 'Tx',\n Var = 'Var',\n Currency = 'Currency',\n DateTime = 'DateTime',\n RelativeTime = 'RelativeTime',\n Num = 'Num',\n
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../../src/utils/constants/gt/constants.ts"],"sourcesContent":["/**\n * Different gt components\n */\nexport enum GT_COMPONENT_TYPES {\n T = 'T',\n Tx = 'Tx',\n Var = 'Var',\n Currency = 'Currency',\n DateTime = 'DateTime',\n RelativeTime = 'RelativeTime',\n Num = 'Num',\n Derive = 'Derive',\n Branch = 'Branch',\n Plural = 'Plural',\n LocaleSelector = 'LocaleSelector',\n GtInternalTranslateJsx = 'GtInternalTranslateJsx',\n GtInternalVar = 'GtInternalVar',\n GtInternalNum = 'GtInternalNum',\n GtInternalCurrency = 'GtInternalCurrency',\n GtInternalDateTime = 'GtInternalDateTime',\n}\n\n/**\n * GT functions that produce callbacks\n */\nexport enum GT_FUNCTIONS_WITH_CALLBACKS {\n useGT = 'useGT',\n getGT = 'getGT',\n useTranslations = 'useTranslations',\n getTranslations = 'getTranslations',\n useMessages = 'useMessages',\n getMessages = 'getMessages',\n}\n\n/**\n * Other GT functions\n */\nexport enum GT_OTHER_FUNCTIONS {\n msg = 'msg',\n t = 't',\n derive = 'derive',\n GtInternalRuntimeTranslateString = 'GtInternalRuntimeTranslateString',\n GtInternalRuntimeTranslateJsx = 'GtInternalRuntimeTranslateJsx',\n}\n\n/**\n * Different gt functions\n */\nexport type GT_FUNCTIONS = GT_FUNCTIONS_WITH_CALLBACKS | GT_OTHER_FUNCTIONS;\n/**\n * gt callback functions\n */\nexport enum GT_CALLBACK_FUNCTIONS {\n useGT_callback = 'useGT_callback',\n getGT_callback = 'getGT_callback',\n useTranslations_callback = 'useTranslations_callback',\n getTranslations_callback = 'getTranslations_callback',\n useMessages_callback = 'useMessages_callback',\n getMessages_callback = 'getMessages_callback',\n}\n\n/**\n * Maps GT Functions to their callback functions\n */\nexport const GT_FUNCTIONS_TO_CALLBACKS: Record<\n GT_FUNCTIONS_WITH_CALLBACKS,\n GT_CALLBACK_FUNCTIONS\n> = {\n [GT_FUNCTIONS_WITH_CALLBACKS.useGT]: GT_CALLBACK_FUNCTIONS.useGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getGT]: GT_CALLBACK_FUNCTIONS.getGT_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useTranslations]:\n GT_CALLBACK_FUNCTIONS.useTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getTranslations]:\n GT_CALLBACK_FUNCTIONS.getTranslations_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.useMessages]:\n GT_CALLBACK_FUNCTIONS.useMessages_callback,\n [GT_FUNCTIONS_WITH_CALLBACKS.getMessages]:\n GT_CALLBACK_FUNCTIONS.getMessages_callback,\n};\n\n/**\n * GT derive functions\n */\nexport const GT_DERIVE_STRING_FUNCTIONS = [GT_OTHER_FUNCTIONS.derive] as const;\n\n/**\n * All gt functions (both regular and callback functions)\n */\nexport type GT_ALL_FUNCTIONS =\n | GT_FUNCTIONS\n | GT_CALLBACK_FUNCTIONS\n | GT_COMPONENT_TYPES;\n\n/**\n * GT import sources\n */\nexport enum GT_IMPORT_SOURCES {\n GT_NEXT = 'gt-next',\n GT_NEXT_SERVER = 'gt-next/server',\n GT_REACT = 'gt-react',\n GT_REACT_CLIENT = 'gt-react/client',\n GT_REACT_BROWSER = 'gt-react/browser',\n GT_I18N = 'gt-i18n',\n}\n\n/**\n * Branch control props — not translatable content.\n * `branch` is the selector key; `data-*` props are HTML attributes ignored at runtime.\n * `data-*` is handled as a prefix check, not listed here.\n */\nexport const BRANCH_CONTROL_PROPS = new Set(['branch']);\n\n/**\n * Plural control props — not translatable content.\n * `n` is the count, `locales` is the locale hint.\n */\nexport const PLURAL_CONTROL_PROPS = new Set(['n', 'locales']);\n\n/**\n * Set of valid plural forms for Plural components\n */\nexport const PLURAL_FORMS = new Set([\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n]);\n\n/**\n * Fields that must be string literals for useGT_callback / getGT_callback\n */\nexport enum USEGT_CALLBACK_OPTIONS {\n $id = '$id',\n $context = '$context',\n $maxChars = '$maxChars',\n $_hash = '$_hash',\n $format = '$format',\n $requiresReview = '$requiresReview',\n}\n\n/**\n * Maps GT Component Types to their minified names\n */\nexport const MINIFY_CANONICAL_NAME_MAP = {\n [GT_COMPONENT_TYPES.Var]: 'v',\n [GT_COMPONENT_TYPES.GtInternalVar]: 'v',\n [GT_COMPONENT_TYPES.Num]: 'n',\n [GT_COMPONENT_TYPES.GtInternalNum]: 'n',\n [GT_COMPONENT_TYPES.Currency]: 'c',\n [GT_COMPONENT_TYPES.GtInternalCurrency]: 'c',\n [GT_COMPONENT_TYPES.DateTime]: 'd',\n [GT_COMPONENT_TYPES.GtInternalDateTime]: 'd',\n [GT_COMPONENT_TYPES.RelativeTime]: 'rt',\n [GT_COMPONENT_TYPES.Derive]: 's',\n [GT_COMPONENT_TYPES.Branch]: 'b',\n [GT_COMPONENT_TYPES.Plural]: 'p',\n} as const;\n"],"mappings":";;;;;AAGA,IAAY,qBAAL,yBAAA,oBAAA;AACL,oBAAA,OAAA;AACA,oBAAA,QAAA;AACA,oBAAA,SAAA;AACA,oBAAA,cAAA;AACA,oBAAA,cAAA;AACA,oBAAA,kBAAA;AACA,oBAAA,SAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AACA,oBAAA,YAAA;AAC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;aACN;aACA;aACA;CAC9B"}
|
|
@@ -49,6 +49,8 @@ export declare function isTranslationFunctionCallback(name: string): name is GT_
|
|
|
49
49
|
* Check if it's a GT import source
|
|
50
50
|
*/
|
|
51
51
|
export declare function isGTImportSource(name: string): name is GT_IMPORT_SOURCES;
|
|
52
|
+
export declare function isGTReactImportSource(name: string): name is GT_IMPORT_SOURCES.GT_REACT | GT_IMPORT_SOURCES.GT_REACT_CLIENT | GT_IMPORT_SOURCES.GT_REACT_BROWSER;
|
|
53
|
+
export declare function getGtReactImportSource(legacyGtReactImportSource: boolean): GT_IMPORT_SOURCES.GT_REACT | GT_IMPORT_SOURCES.GT_REACT_BROWSER;
|
|
52
54
|
/**
|
|
53
55
|
* Check if is a html content prop
|
|
54
56
|
*/
|
|
@@ -71,7 +73,6 @@ export declare const defaultVariableNames: {
|
|
|
71
73
|
readonly Currency: "cost";
|
|
72
74
|
readonly GtInternalCurrency: "cost";
|
|
73
75
|
readonly Derive: "static";
|
|
74
|
-
readonly Static: "static";
|
|
75
76
|
};
|
|
76
77
|
/**
|
|
77
78
|
* Get the variable name
|