gt 2.14.35 → 2.14.36
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/CHANGELOG.md +16 -1
- package/dist/api/collectUserEditDiffs.js +112 -155
- package/dist/api/collectUserEditDiffs.js.map +1 -0
- package/dist/api/downloadFileBatch.js +164 -241
- package/dist/api/downloadFileBatch.js.map +1 -0
- package/dist/api/saveLocalEdits.js +37 -41
- package/dist/api/saveLocalEdits.js.map +1 -0
- package/dist/bin/bin-entry.js +17 -7
- package/dist/bin/bin-entry.js.map +1 -0
- package/dist/bin/bin-main.js +43 -61
- package/dist/bin/bin-main.js.map +1 -0
- package/dist/cli/base.js +382 -497
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/download.js +41 -49
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/enqueue.js +26 -25
- package/dist/cli/commands/enqueue.js.map +1 -0
- package/dist/cli/commands/setupProject.js +33 -36
- package/dist/cli/commands/setupProject.js.map +1 -0
- package/dist/cli/commands/stage.js +53 -61
- package/dist/cli/commands/stage.js.map +1 -0
- package/dist/cli/commands/translate.js +75 -112
- package/dist/cli/commands/translate.js.map +1 -0
- package/dist/cli/commands/upload.js +185 -213
- package/dist/cli/commands/upload.js.map +1 -0
- package/dist/cli/commands/utils/validation.js +39 -34
- package/dist/cli/commands/utils/validation.js.map +1 -0
- package/dist/cli/flags.js +35 -62
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/inline.js +112 -137
- package/dist/cli/inline.js.map +1 -0
- package/dist/cli/next.js +17 -12
- package/dist/cli/next.js.map +1 -0
- package/dist/cli/node.js +19 -15
- package/dist/cli/node.js.map +1 -0
- package/dist/cli/python.js +13 -8
- package/dist/cli/python.js.map +1 -0
- package/dist/cli/react.js +61 -78
- package/dist/cli/react.js.map +1 -0
- package/dist/config/defaults.js +16 -11
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/generateSettings.js +167 -269
- package/dist/config/generateSettings.js.map +1 -0
- package/dist/config/optionPresets.js +78 -96
- package/dist/config/optionPresets.js.map +1 -0
- package/dist/config/resolveConfig.js +27 -32
- package/dist/config/resolveConfig.js.map +1 -0
- package/dist/config/utils.js +7 -3
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validateSettings.js +19 -30
- package/dist/config/validateSettings.js.map +1 -0
- package/dist/console/colors.js +18 -13
- package/dist/console/colors.js.map +1 -0
- package/dist/console/displayTranslateSummary.js +40 -37
- package/dist/console/displayTranslateSummary.js.map +1 -0
- package/dist/console/formatting.js +8 -5
- package/dist/console/formatting.js.map +1 -0
- package/dist/console/index.d.ts +11 -9
- package/dist/console/index.js +53 -50
- package/dist/console/index.js.map +1 -0
- package/dist/console/inkFields.d.ts +23 -0
- package/dist/console/inkFields.js +87 -0
- package/dist/console/inkFields.js.map +1 -0
- package/dist/console/inkLayout.d.ts +7 -0
- package/dist/console/inkLayout.js +139 -0
- package/dist/console/inkLayout.js.map +1 -0
- package/dist/console/inkLocaleData.d.ts +4 -0
- package/dist/console/inkLocaleData.js +32 -0
- package/dist/console/inkLocaleData.js.map +1 -0
- package/dist/console/inkPrompts.d.ts +8 -0
- package/dist/console/inkPrompts.js +496 -0
- package/dist/console/inkPrompts.js.map +1 -0
- package/dist/console/inkSession.d.ts +3 -0
- package/dist/console/inkSession.js +42 -0
- package/dist/console/inkSession.js.map +1 -0
- package/dist/console/inkTerminal.d.ts +4 -0
- package/dist/console/inkTerminal.js +15 -0
- package/dist/console/inkTerminal.js.map +1 -0
- package/dist/console/inkTypes.d.ts +66 -0
- package/dist/console/inkTypes.js +1 -0
- package/dist/console/inkUtils.d.ts +24 -0
- package/dist/console/inkUtils.js +87 -0
- package/dist/console/inkUtils.js.map +1 -0
- package/dist/console/logger.js +209 -249
- package/dist/console/logger.js.map +1 -0
- package/dist/console/logging.d.ts +14 -0
- package/dist/console/logging.js +203 -162
- package/dist/console/logging.js.map +1 -0
- package/dist/console/promptParsing.d.ts +5 -0
- package/dist/console/promptParsing.js +28 -0
- package/dist/console/promptParsing.js.map +1 -0
- package/dist/console/terminalSession.d.ts +5 -0
- package/dist/console/terminalSession.js +38 -0
- package/dist/console/terminalSession.js.map +1 -0
- package/dist/extraction/index.js +3 -2
- package/dist/extraction/mapToUpdates.js +19 -18
- package/dist/extraction/mapToUpdates.js.map +1 -0
- package/dist/extraction/postProcess.js +68 -86
- package/dist/extraction/postProcess.js.map +1 -0
- package/dist/formats/files/aggregateFiles.js +223 -304
- package/dist/formats/files/aggregateFiles.js.map +1 -0
- package/dist/formats/files/collectFiles.js +53 -54
- package/dist/formats/files/collectFiles.js.map +1 -0
- package/dist/formats/files/convertToFileTranslationData.js +21 -19
- package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
- package/dist/formats/files/fileMapping.js +82 -119
- package/dist/formats/files/fileMapping.js.map +1 -0
- package/dist/formats/files/preprocess/mdx.js +15 -12
- package/dist/formats/files/preprocess/mdx.js.map +1 -0
- package/dist/formats/files/preprocess/mintlify.js +15 -13
- package/dist/formats/files/preprocess/mintlify.js.map +1 -0
- package/dist/formats/files/preprocessContent.js +20 -21
- package/dist/formats/files/preprocessContent.js.map +1 -0
- package/dist/formats/files/save.js +18 -15
- package/dist/formats/files/save.js.map +1 -0
- package/dist/formats/files/supportedFiles.js +27 -22
- package/dist/formats/files/supportedFiles.js.map +1 -0
- package/dist/formats/files/transformFormat.js +93 -100
- package/dist/formats/files/transformFormat.js.map +1 -0
- package/dist/formats/json/extractJson.js +83 -110
- package/dist/formats/json/extractJson.js.map +1 -0
- package/dist/formats/json/flattenJson.js +41 -48
- package/dist/formats/json/flattenJson.js.map +1 -0
- package/dist/formats/json/jsonPath.js +20 -15
- package/dist/formats/json/jsonPath.js.map +1 -0
- package/dist/formats/json/jsonPointer.js +17 -17
- package/dist/formats/json/jsonPointer.js.map +1 -0
- package/dist/formats/json/mergeJson.js +230 -371
- package/dist/formats/json/mergeJson.js.map +1 -0
- package/dist/formats/json/parseJson.js +74 -111
- package/dist/formats/json/parseJson.js.map +1 -0
- package/dist/formats/json/transformJson.js +53 -61
- package/dist/formats/json/transformJson.js.map +1 -0
- package/dist/formats/json/utils.js +158 -187
- package/dist/formats/json/utils.js.map +1 -0
- package/dist/formats/parseKeyedMetadata.js +85 -106
- package/dist/formats/parseKeyedMetadata.js.map +1 -0
- package/dist/formats/utils.js +13 -23
- package/dist/formats/utils.js.map +1 -0
- package/dist/formats/yaml/extractYaml.js +32 -31
- package/dist/formats/yaml/extractYaml.js.map +1 -0
- package/dist/formats/yaml/mergeYaml.js +43 -60
- package/dist/formats/yaml/mergeYaml.js.map +1 -0
- package/dist/formats/yaml/parseYaml.js +34 -23
- package/dist/formats/yaml/parseYaml.js.map +1 -0
- package/dist/formats/yaml/utils.js +19 -21
- package/dist/formats/yaml/utils.js.map +1 -0
- package/dist/fs/clearLocaleDirs.js +82 -114
- package/dist/fs/clearLocaleDirs.js.map +1 -0
- package/dist/fs/config/downloadedVersions.js +174 -188
- package/dist/fs/config/downloadedVersions.js.map +1 -0
- package/dist/fs/config/loadConfig.js +12 -8
- package/dist/fs/config/loadConfig.js.map +1 -0
- package/dist/fs/config/parseFilesConfig.js +166 -227
- package/dist/fs/config/parseFilesConfig.js.map +1 -0
- package/dist/fs/config/setupConfig.js +43 -52
- package/dist/fs/config/setupConfig.js.map +1 -0
- package/dist/fs/config/updateConfig.js +44 -56
- package/dist/fs/config/updateConfig.js.map +1 -0
- package/dist/fs/config/updateVersions.js +27 -28
- package/dist/fs/config/updateVersions.js.map +1 -0
- package/dist/fs/copyFile.js +33 -37
- package/dist/fs/copyFile.js.map +1 -0
- package/dist/fs/createLoadTranslationsFile.js +32 -48
- package/dist/fs/createLoadTranslationsFile.js.map +1 -0
- package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
- package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
- package/dist/fs/determineFramework/index.js +46 -64
- package/dist/fs/determineFramework/index.js.map +1 -0
- package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
- package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
- package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
- package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
- package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
- package/dist/fs/findFilepath.js +63 -78
- package/dist/fs/findFilepath.js.map +1 -0
- package/dist/fs/loadJSON.js +18 -15
- package/dist/fs/loadJSON.js.map +1 -0
- package/dist/fs/matchFiles.js +12 -7
- package/dist/fs/matchFiles.js.map +1 -0
- package/dist/fs/saveJSON.js +10 -6
- package/dist/fs/saveJSON.js.map +1 -0
- package/dist/fs/utils.js +19 -15
- package/dist/fs/utils.js.map +1 -0
- package/dist/functions.d.ts +2 -1
- package/dist/functions.js +3 -6
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +6 -2
- package/dist/generated/version.js.map +1 -0
- package/dist/git/branches.js +77 -83
- package/dist/git/branches.js.map +1 -0
- package/dist/hooks/postProcess.js +97 -114
- package/dist/hooks/postProcess.js.map +1 -0
- package/dist/index.js +23 -31
- package/dist/index.js.map +1 -0
- package/dist/locadex/setupFlow.js +11 -8
- package/dist/locadex/setupFlow.js.map +1 -0
- package/dist/main.js +17 -7
- package/dist/main.js.map +1 -0
- package/dist/next/config/parseNextConfig.js +32 -51
- package/dist/next/config/parseNextConfig.js.map +1 -0
- package/dist/next/jsx/utils.js +25 -37
- package/dist/next/jsx/utils.js.map +1 -0
- package/dist/next/parse/handleInitGT.js +87 -154
- package/dist/next/parse/handleInitGT.js.map +1 -0
- package/dist/next/parse/wrapContent.js +136 -158
- package/dist/next/parse/wrapContent.js.map +1 -0
- package/dist/python/parse/createPythonInlineUpdates.js +36 -33
- package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
- package/dist/react/config/createESBuildConfig.js +115 -115
- package/dist/react/config/createESBuildConfig.js.map +1 -0
- package/dist/react/jsx/evaluateJsx.js +90 -124
- package/dist/react/jsx/evaluateJsx.js.map +1 -0
- package/dist/react/jsx/utils/buildImportMap.js +24 -28
- package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
- package/dist/react/jsx/utils/constants.js +79 -87
- package/dist/react/jsx/utils/constants.js.map +1 -0
- package/dist/react/jsx/utils/extractSourceCode.js +36 -37
- package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
- package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
- package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
- package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
- package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
- package/dist/react/jsx/utils/mapAttributeName.js +13 -13
- package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
- package/dist/react/jsx/utils/parseAst.js +142 -272
- package/dist/react/jsx/utils/parseAst.js.map +1 -0
- package/dist/react/jsx/utils/parseString.js +726 -1090
- package/dist/react/jsx/utils/parseString.js.map +1 -0
- package/dist/react/jsx/utils/parseStringFunction.js +274 -401
- package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
- package/dist/react/jsx/utils/resolveImportPath.js +104 -108
- package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
- package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/validateStringFunction.js +21 -29
- package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
- package/dist/react/jsx/wrapJsx.js +192 -375
- package/dist/react/jsx/wrapJsx.js.map +1 -0
- package/dist/react/parse/addVitePlugin/index.js +40 -34
- package/dist/react/parse/addVitePlugin/index.js.map +1 -0
- package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
- package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
- package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
- package/dist/react/parse/createDictionaryUpdates.js +121 -185
- package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
- package/dist/react/parse/createInlineUpdates.js +123 -139
- package/dist/react/parse/createInlineUpdates.js.map +1 -0
- package/dist/react/parse/wrapContent.js +131 -156
- package/dist/react/parse/wrapContent.js.map +1 -0
- package/dist/react/utils/flattenDictionary.js +55 -70
- package/dist/react/utils/flattenDictionary.js.map +1 -0
- package/dist/react/utils/getEntryAndMetadata.js +14 -10
- package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
- package/dist/react/utils/getVariableName.js +36 -33
- package/dist/react/utils/getVariableName.js.map +1 -0
- package/dist/setup/detectFramework.js +85 -102
- package/dist/setup/detectFramework.js.map +1 -0
- package/dist/setup/frameworkUtils.js +17 -28
- package/dist/setup/frameworkUtils.js.map +1 -0
- package/dist/setup/userInput.js +24 -31
- package/dist/setup/userInput.js.map +1 -0
- package/dist/setup/wizard.js +141 -143
- package/dist/setup/wizard.js.map +1 -0
- package/dist/state/mintlifyRefMap.js +12 -9
- package/dist/state/mintlifyRefMap.js.map +1 -0
- package/dist/state/recentDownloads.js +26 -23
- package/dist/state/recentDownloads.js.map +1 -0
- package/dist/state/translateWarnings.js +17 -8
- package/dist/state/translateWarnings.js.map +1 -0
- package/dist/translation/parse.js +77 -98
- package/dist/translation/parse.js.map +1 -0
- package/dist/translation/stage.js +28 -43
- package/dist/translation/stage.js.map +1 -0
- package/dist/translation/validate.js +68 -91
- package/dist/translation/validate.js.map +1 -0
- package/dist/types/libraries.js +93 -91
- package/dist/types/libraries.js.map +1 -0
- package/dist/types/parsing.js +19 -10
- package/dist/types/parsing.js.map +1 -0
- package/dist/utils/addExplicitAnchorIds.js +270 -389
- package/dist/utils/addExplicitAnchorIds.js.map +1 -0
- package/dist/utils/calculateTimeoutMs.js +11 -6
- package/dist/utils/calculateTimeoutMs.js.map +1 -0
- package/dist/utils/constants.js +15 -12
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/credentials.js +67 -114
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/fetch.js +22 -20
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/flattenJsonFiles.js +27 -34
- package/dist/utils/flattenJsonFiles.js.map +1 -0
- package/dist/utils/gitDiff.js +30 -32
- package/dist/utils/gitDiff.js.map +1 -0
- package/dist/utils/gt.js +7 -2
- package/dist/utils/gt.js.map +1 -0
- package/dist/utils/hash.js +14 -9
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.js +10 -13
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/installPackage.js +70 -75
- package/dist/utils/installPackage.js.map +1 -0
- package/dist/utils/localizeRelativeAssets.js +114 -157
- package/dist/utils/localizeRelativeAssets.js.map +1 -0
- package/dist/utils/localizeStaticImports.js +229 -371
- package/dist/utils/localizeStaticImports.js.map +1 -0
- package/dist/utils/localizeStaticUrls.js +241 -424
- package/dist/utils/localizeStaticUrls.js.map +1 -0
- package/dist/utils/mintlifyTitleFallback.js +64 -72
- package/dist/utils/mintlifyTitleFallback.js.map +1 -0
- package/dist/utils/monorepoVersionCheck.js +177 -215
- package/dist/utils/monorepoVersionCheck.js.map +1 -0
- package/dist/utils/packageInfo.js +17 -16
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/packageJson.js +51 -66
- package/dist/utils/packageJson.js.map +1 -0
- package/dist/utils/packageManager.js +237 -260
- package/dist/utils/packageManager.js.map +1 -0
- package/dist/utils/parse/needsCJS.js +36 -69
- package/dist/utils/parse/needsCJS.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.js +30 -32
- package/dist/utils/persistPostprocessHashes.js.map +1 -0
- package/dist/utils/processAnchorIds.js +32 -54
- package/dist/utils/processAnchorIds.js.map +1 -0
- package/dist/utils/processOpenApi.js +469 -578
- package/dist/utils/processOpenApi.js.map +1 -0
- package/dist/utils/resolveMintlifyRefs.js +89 -105
- package/dist/utils/resolveMintlifyRefs.js.map +1 -0
- package/dist/utils/resolvePublish.js +46 -54
- package/dist/utils/resolvePublish.js.map +1 -0
- package/dist/utils/sanitizeFileContent.js +20 -27
- package/dist/utils/sanitizeFileContent.js.map +1 -0
- package/dist/utils/sharedStaticAssets.js +248 -366
- package/dist/utils/sharedStaticAssets.js.map +1 -0
- package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
- package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
- package/dist/utils/validateMdx.js +26 -23
- package/dist/utils/validateMdx.js.map +1 -0
- package/dist/utils/wrapPlainUrls.js +58 -70
- package/dist/utils/wrapPlainUrls.js.map +1 -0
- package/dist/workflows/download.js +92 -126
- package/dist/workflows/download.js.map +1 -0
- package/dist/workflows/enqueue.js +47 -54
- package/dist/workflows/enqueue.js.map +1 -0
- package/dist/workflows/publish.js +29 -29
- package/dist/workflows/publish.js.map +1 -0
- package/dist/workflows/setupProject.js +39 -40
- package/dist/workflows/setupProject.js.map +1 -0
- package/dist/workflows/stage.js +61 -65
- package/dist/workflows/stage.js.map +1 -0
- package/dist/workflows/steps/BranchStep.js +118 -163
- package/dist/workflows/steps/BranchStep.js.map +1 -0
- package/dist/workflows/steps/DownloadStep.js +107 -137
- package/dist/workflows/steps/DownloadStep.js.map +1 -0
- package/dist/workflows/steps/EnqueueStep.js +32 -32
- package/dist/workflows/steps/EnqueueStep.js.map +1 -0
- package/dist/workflows/steps/PollJobsStep.js +208 -292
- package/dist/workflows/steps/PollJobsStep.js.map +1 -0
- package/dist/workflows/steps/PublishStep.js +33 -38
- package/dist/workflows/steps/PublishStep.js.map +1 -0
- package/dist/workflows/steps/SetupStep.js +71 -72
- package/dist/workflows/steps/SetupStep.js.map +1 -0
- package/dist/workflows/steps/TagStep.js +39 -44
- package/dist/workflows/steps/TagStep.js.map +1 -0
- package/dist/workflows/steps/UploadSourcesStep.js +108 -140
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
- package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
- package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
- package/dist/workflows/steps/WorkflowStep.js +6 -2
- package/dist/workflows/steps/WorkflowStep.js.map +1 -0
- package/dist/workflows/upload.js +45 -46
- package/dist/workflows/upload.js.map +1 -0
- package/package.json +14 -7
|
@@ -1,1125 +1,778 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import "../../../../utils/constants.js";
|
|
2
|
+
import { isStaticExpression } from "../../evaluateJsx.js";
|
|
3
|
+
import { VARIABLE_COMPONENTS } from "../constants.js";
|
|
4
|
+
import { warnDataAttrOnBranch, warnDeriveDestructuringSync, warnDeriveNonConstVariableSync, warnDuplicateFunctionDefinitionSync, warnFunctionNotFoundSync, warnHasUnwrappedExpressionSync, warnInvalidDeriveInitSync, warnMissingReturnSync, warnNestedInternalTComponent, warnNestedTComponent, warnRecursiveFunctionCallSync } from "../../../../console/index.js";
|
|
5
|
+
import addGTIdentifierToSyntaxTree from "./addGTIdentifierToSyntaxTree.js";
|
|
6
|
+
import { resolveImportPath } from "../resolveImportPath.js";
|
|
7
|
+
import { buildImportMap } from "../buildImportMap.js";
|
|
8
|
+
import { getPathsAndAliases } from "../getPathsAndAliases.js";
|
|
9
|
+
import { parseTProps } from "./parseTProps.js";
|
|
10
|
+
import { isElementNode } from "./types.js";
|
|
11
|
+
import { handleChildrenWhitespace } from "./handleChildrenWhitespace.js";
|
|
12
|
+
import { multiplyJsxTree } from "./multiplication/multiplyJsxTree.js";
|
|
13
|
+
import { removeNullChildrenFields } from "./removeNullChildrenFields.js";
|
|
14
|
+
import { autoInsertJsxComponents, ensureTAndVarImported } from "./autoInsertion.js";
|
|
15
|
+
import { extractSourceCode } from "../extractSourceCode.js";
|
|
16
|
+
import { nodeToStrings, parseStringExpression } from "../parseString.js";
|
|
17
|
+
import { handleDerivation } from "../stringParsing/derivation/handleDerivation.js";
|
|
18
|
+
import { randomUUID } from "node:crypto";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import fs from "node:fs";
|
|
21
|
+
import * as t from "@babel/types";
|
|
22
|
+
import { parse } from "@babel/parser";
|
|
23
|
+
import generateModule from "@babel/generator";
|
|
24
|
+
import { HTML_CONTENT_PROPS } from "@generaltranslation/format/types";
|
|
25
|
+
import { isAcceptedPluralForm } from "generaltranslation/internal";
|
|
26
|
+
import traverseModule from "@babel/traverse";
|
|
27
|
+
//#region src/react/jsx/utils/jsxParsing/parseJsx.ts
|
|
4
28
|
const generate = generateModule.default || generateModule;
|
|
5
|
-
import * as t from '@babel/types';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import { parse } from '@babel/parser';
|
|
8
|
-
import addGTIdentifierToSyntaxTree from './addGTIdentifierToSyntaxTree.js';
|
|
9
|
-
import { warnHasUnwrappedExpressionSync, warnNestedTComponent, warnFunctionNotFoundSync, warnMissingReturnSync, warnDuplicateFunctionDefinitionSync, warnInvalidDeriveInitSync, warnRecursiveFunctionCallSync, warnDataAttrOnBranch, warnNestedInternalTComponent, warnDeriveNonConstVariableSync, warnDeriveDestructuringSync, } from '../../../../console/index.js';
|
|
10
|
-
import { isAcceptedPluralForm } from 'generaltranslation/internal';
|
|
11
|
-
import { isStaticExpression } from '../../evaluateJsx.js';
|
|
12
|
-
import { DATA_ATTR_PREFIX, STATIC_COMPONENT, DERIVE_COMPONENT, TRANSLATION_COMPONENT, INTERNAL_TRANSLATION_COMPONENT, VARIABLE_COMPONENTS, } from '../constants.js';
|
|
13
|
-
import { HTML_CONTENT_PROPS, } from '@generaltranslation/format/types';
|
|
14
|
-
import { resolveImportPath } from '../resolveImportPath.js';
|
|
15
|
-
import traverseModule from '@babel/traverse';
|
|
16
|
-
import { buildImportMap } from '../buildImportMap.js';
|
|
17
|
-
import { getPathsAndAliases } from '../getPathsAndAliases.js';
|
|
18
|
-
import { parseTProps } from './parseTProps.js';
|
|
19
|
-
import { handleChildrenWhitespace } from './handleChildrenWhitespace.js';
|
|
20
|
-
import { isElementNode } from './types.js';
|
|
21
|
-
import { multiplyJsxTree } from './multiplication/multiplyJsxTree.js';
|
|
22
|
-
import { removeNullChildrenFields } from './removeNullChildrenFields.js';
|
|
23
|
-
import { ensureTAndVarImported, autoInsertJsxComponents, } from './autoInsertion.js';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import { extractSourceCode } from '../extractSourceCode.js';
|
|
26
|
-
import { SURROUNDING_LINE_COUNT } from '../../../../utils/constants.js';
|
|
27
|
-
import { handleDerivation } from '../stringParsing/derivation/handleDerivation.js';
|
|
28
|
-
import { parseStringExpression, nodeToStrings } from '../parseString.js';
|
|
29
|
-
// Handle CommonJS/ESM interop
|
|
30
29
|
const traverse = traverseModule.default || traverseModule;
|
|
31
|
-
// TODO: currently we cover VariableDeclaration and FunctionDeclaration nodes, but are there others we should cover as well?
|
|
32
30
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const resolveImportPathCache = new Map();
|
|
31
|
+
* Cache for resolved import paths to avoid redundant I/O operations.
|
|
32
|
+
* Key: `${currentFile}::${importPath}`
|
|
33
|
+
* Value: resolved absolute path or null
|
|
34
|
+
*/
|
|
35
|
+
const resolveImportPathCache = /* @__PURE__ */ new Map();
|
|
38
36
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const processFunctionCache = new Map();
|
|
37
|
+
* Cache for processed functions to avoid re-parsing the same files.
|
|
38
|
+
* Key: `${filePath}::${functionName}::${argIndex}`
|
|
39
|
+
* Value: boolean indicating whether the function was found and processed
|
|
40
|
+
*/
|
|
41
|
+
const processFunctionCache = /* @__PURE__ */ new Map();
|
|
44
42
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
visited: null,
|
|
69
|
-
callStack: [],
|
|
70
|
-
derivableTracker: { isDerivable: false },
|
|
71
|
-
importedFunctionsMap,
|
|
72
|
-
},
|
|
73
|
-
output,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
43
|
+
* Entry point for JSX parsing
|
|
44
|
+
*/
|
|
45
|
+
function parseTranslationComponent({ originalName, localName, path, updates, config, output }) {
|
|
46
|
+
const importedFunctionsMap = buildImportMap(path.scope.getProgramParent().path);
|
|
47
|
+
const referencePaths = path.scope.bindings[localName]?.referencePaths || [];
|
|
48
|
+
for (const refPath of referencePaths) {
|
|
49
|
+
if (!t.isJSXOpeningElement(refPath.parent) || !refPath.parentPath?.parentPath) continue;
|
|
50
|
+
const jsxElementPath = refPath.parentPath?.parentPath;
|
|
51
|
+
parseJSXElement({
|
|
52
|
+
scopeNode: jsxElementPath,
|
|
53
|
+
node: jsxElementPath.node,
|
|
54
|
+
originalName,
|
|
55
|
+
updates,
|
|
56
|
+
config,
|
|
57
|
+
state: {
|
|
58
|
+
visited: null,
|
|
59
|
+
callStack: [],
|
|
60
|
+
derivableTracker: { isDerivable: false },
|
|
61
|
+
importedFunctionsMap
|
|
62
|
+
},
|
|
63
|
+
output
|
|
64
|
+
});
|
|
65
|
+
}
|
|
76
66
|
}
|
|
77
67
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
function buildJSXTree({ node, helperPath, scopeNode, insideT, inDerive, config, state, output
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
node: child,
|
|
315
|
-
insideT: true,
|
|
316
|
-
inDerive: inDerive,
|
|
317
|
-
scopeNode,
|
|
318
|
-
helperPath: helperPath.get('children')[index],
|
|
319
|
-
config,
|
|
320
|
-
state,
|
|
321
|
-
output,
|
|
322
|
-
});
|
|
323
|
-
// Flatten array results from _T transparency unwrap inside Derive
|
|
324
|
-
if (Array.isArray(result))
|
|
325
|
-
return result;
|
|
326
|
-
return [result];
|
|
327
|
-
})
|
|
328
|
-
.filter((child) => child !== null && child !== '');
|
|
329
|
-
if (children.length === 1) {
|
|
330
|
-
props.children = children[0];
|
|
331
|
-
}
|
|
332
|
-
else if (children.length > 1) {
|
|
333
|
-
props.children = children;
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
336
|
-
nodeType: 'element',
|
|
337
|
-
// if componentType is undefined, use typeName
|
|
338
|
-
// Basically, if componentType is not a GT component, use typeName such as <div>
|
|
339
|
-
type: componentType ?? typeName,
|
|
340
|
-
props,
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
// If it's a JSX fragment
|
|
344
|
-
else if (t.isJSXFragment(node)) {
|
|
345
|
-
const children = node.children
|
|
346
|
-
.flatMap((child, index) => {
|
|
347
|
-
const result = buildJSXTree({
|
|
348
|
-
node: child,
|
|
349
|
-
insideT: true,
|
|
350
|
-
inDerive: inDerive,
|
|
351
|
-
scopeNode,
|
|
352
|
-
helperPath: helperPath.get('children')[index],
|
|
353
|
-
config,
|
|
354
|
-
state,
|
|
355
|
-
output,
|
|
356
|
-
});
|
|
357
|
-
// Flatten array results from _T transparency unwrap inside Derive
|
|
358
|
-
if (Array.isArray(result))
|
|
359
|
-
return result;
|
|
360
|
-
return [result];
|
|
361
|
-
})
|
|
362
|
-
.filter((child) => child !== null && child !== '');
|
|
363
|
-
const props = {};
|
|
364
|
-
if (children.length === 1) {
|
|
365
|
-
props.children = children[0];
|
|
366
|
-
}
|
|
367
|
-
else if (children.length > 1) {
|
|
368
|
-
props.children = children;
|
|
369
|
-
}
|
|
370
|
-
return {
|
|
371
|
-
nodeType: 'element',
|
|
372
|
-
type: '',
|
|
373
|
-
props,
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
// If it's a string literal (standalone)
|
|
377
|
-
else if (t.isStringLiteral(node)) {
|
|
378
|
-
return node.value;
|
|
379
|
-
}
|
|
380
|
-
// If it's a template literal
|
|
381
|
-
else if (t.isTemplateLiteral(node)) {
|
|
382
|
-
// We've already checked that it's derivable, and and added a warning if it's not, this check is just for fallback behavior
|
|
383
|
-
if (!isStaticExpression(node, true).isStatic ||
|
|
384
|
-
node.quasis[0].value.cooked === undefined) {
|
|
385
|
-
return generate(node).code;
|
|
386
|
-
}
|
|
387
|
-
return node.quasis[0].value.cooked;
|
|
388
|
-
}
|
|
389
|
-
else if (t.isNullLiteral(node)) {
|
|
390
|
-
// If it's null, return null
|
|
391
|
-
return null;
|
|
392
|
-
}
|
|
393
|
-
else if (t.isBooleanLiteral(node)) {
|
|
394
|
-
// If it's a boolean, return the boolean
|
|
395
|
-
return node.value;
|
|
396
|
-
}
|
|
397
|
-
else if (t.isNumericLiteral(node)) {
|
|
398
|
-
// If it's a number, return the number
|
|
399
|
-
return node.value.toString();
|
|
400
|
-
}
|
|
401
|
-
// Negative
|
|
402
|
-
else if (t.isUnaryExpression(node)) {
|
|
403
|
-
// If it's a unary expression, return the expression
|
|
404
|
-
const staticAnalysis = isStaticExpression(node, true);
|
|
405
|
-
if (staticAnalysis.isStatic && staticAnalysis.value !== undefined) {
|
|
406
|
-
return staticAnalysis.value;
|
|
407
|
-
}
|
|
408
|
-
return generate(node).code;
|
|
409
|
-
}
|
|
410
|
-
else if ((t.isCallExpression(node) && t.isIdentifier(node.callee)) ||
|
|
411
|
-
(t.isAwaitExpression(node) &&
|
|
412
|
-
t.isCallExpression(node.argument) &&
|
|
413
|
-
t.isIdentifier(node.argument.callee))) {
|
|
414
|
-
if (inDerive) {
|
|
415
|
-
const callExpression = (node.type === 'AwaitExpression' ? node.argument : node);
|
|
416
|
-
const callee = callExpression.callee;
|
|
417
|
-
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
418
|
-
if (!calleeBinding) {
|
|
419
|
-
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
return resolveDeriveFunctionInvocationFromBinding({
|
|
423
|
-
calleeBinding,
|
|
424
|
-
callee,
|
|
425
|
-
config,
|
|
426
|
-
state,
|
|
427
|
-
output,
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
output.unwrappedExpressions.push(generate(node).code);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
else if (t.isParenthesizedExpression(node)) {
|
|
435
|
-
const child = node.expression;
|
|
436
|
-
return buildJSXTree({
|
|
437
|
-
node: child,
|
|
438
|
-
insideT,
|
|
439
|
-
inDerive: inDerive,
|
|
440
|
-
scopeNode,
|
|
441
|
-
helperPath: helperPath.get('expression'),
|
|
442
|
-
config,
|
|
443
|
-
state,
|
|
444
|
-
output,
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
// If it's some other JS expression
|
|
448
|
-
else if (t.isIdentifier(node) ||
|
|
449
|
-
t.isMemberExpression(node) ||
|
|
450
|
-
t.isCallExpression(node) ||
|
|
451
|
-
t.isBinaryExpression(node) ||
|
|
452
|
-
t.isLogicalExpression(node) ||
|
|
453
|
-
t.isConditionalExpression(node)) {
|
|
454
|
-
output.unwrappedExpressions.push(generate(node).code);
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
if (node === undefined || node === null) {
|
|
458
|
-
output.unwrappedExpressions.push(String(node));
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
output.unwrappedExpressions.push(generate(node).code);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return null;
|
|
68
|
+
* Builds a JSX tree from a given node, recursively handling children.
|
|
69
|
+
* @param node - The node to build the tree from
|
|
70
|
+
* @param helperPath - NodePath for AST traversal
|
|
71
|
+
* @param scopeNode - Scope node for binding resolution
|
|
72
|
+
* @param insideT - Whether the current node is inside a <T> component
|
|
73
|
+
* @param inDerive - Whether we're inside a <Derive> component
|
|
74
|
+
* @param config - Immutable configuration options
|
|
75
|
+
* @param state - Mutable state tracking
|
|
76
|
+
* @param output - Error/warning collectors
|
|
77
|
+
* @returns The built JSX tree
|
|
78
|
+
*/
|
|
79
|
+
function buildJSXTree({ node, helperPath, scopeNode, insideT, inDerive, config, state, output }) {
|
|
80
|
+
if (t.isJSXExpressionContainer(node)) {
|
|
81
|
+
if (t.isJSXEmptyExpression(node.expression)) return null;
|
|
82
|
+
if (inDerive) return processDeriveExpression({
|
|
83
|
+
config,
|
|
84
|
+
state,
|
|
85
|
+
output,
|
|
86
|
+
expressionNodePath: helperPath.get("expression"),
|
|
87
|
+
scopeNode
|
|
88
|
+
});
|
|
89
|
+
const expr = node.expression;
|
|
90
|
+
if (t.isJSXElement(expr) || t.isJSXFragment(expr)) return buildJSXTree({
|
|
91
|
+
node: expr,
|
|
92
|
+
insideT,
|
|
93
|
+
inDerive,
|
|
94
|
+
scopeNode,
|
|
95
|
+
helperPath: helperPath.get("expression"),
|
|
96
|
+
config,
|
|
97
|
+
state,
|
|
98
|
+
output
|
|
99
|
+
});
|
|
100
|
+
const staticAnalysis = isStaticExpression(expr, true);
|
|
101
|
+
if (staticAnalysis.isStatic && staticAnalysis.value !== void 0) return {
|
|
102
|
+
nodeType: "expression",
|
|
103
|
+
result: staticAnalysis.value
|
|
104
|
+
};
|
|
105
|
+
const code = generate(node).code;
|
|
106
|
+
output.unwrappedExpressions.push(code);
|
|
107
|
+
return code;
|
|
108
|
+
} else if (t.isJSXText(node)) return node.value;
|
|
109
|
+
else if (t.isJSXElement(node)) {
|
|
110
|
+
const element = node;
|
|
111
|
+
const elementName = element.openingElement.name;
|
|
112
|
+
let typeName;
|
|
113
|
+
if (t.isJSXIdentifier(elementName)) typeName = elementName.name;
|
|
114
|
+
else if (t.isJSXMemberExpression(elementName)) typeName = generate(elementName).code;
|
|
115
|
+
else typeName = null;
|
|
116
|
+
const componentType = config.importAliases[typeName ?? ""];
|
|
117
|
+
if (componentType === "GtInternalTranslateJsx" && inDerive && config.enableAutoJsxInjection) {
|
|
118
|
+
const childResults = [];
|
|
119
|
+
const helperChildren = helperPath.get("children");
|
|
120
|
+
for (let i = 0; i < element.children.length; i++) {
|
|
121
|
+
const child = element.children[i];
|
|
122
|
+
const helperChild = helperChildren[i];
|
|
123
|
+
const result = buildJSXTree({
|
|
124
|
+
node: child,
|
|
125
|
+
helperPath: helperChild,
|
|
126
|
+
scopeNode,
|
|
127
|
+
insideT: true,
|
|
128
|
+
inDerive: true,
|
|
129
|
+
config,
|
|
130
|
+
state,
|
|
131
|
+
output
|
|
132
|
+
});
|
|
133
|
+
if (result !== null) if (Array.isArray(result)) childResults.push(...result);
|
|
134
|
+
else childResults.push(result);
|
|
135
|
+
}
|
|
136
|
+
if (childResults.length === 0) return null;
|
|
137
|
+
if (childResults.length === 1) return childResults[0];
|
|
138
|
+
return childResults;
|
|
139
|
+
}
|
|
140
|
+
if ((componentType === "T" || componentType === "GtInternalTranslateJsx") && insideT) {
|
|
141
|
+
output.warnings.add(warnNestedTComponent(config.file, `${element.loc?.start?.line}:${element.loc?.start?.column}`));
|
|
142
|
+
if (componentType === "GtInternalTranslateJsx") output.errors.push(warnNestedInternalTComponent(config.file, `${element.loc?.start?.line}:${element.loc?.start?.column}`));
|
|
143
|
+
}
|
|
144
|
+
const elementIsVariable = VARIABLE_COMPONENTS.includes(componentType);
|
|
145
|
+
const props = {};
|
|
146
|
+
const elementIsPlural = componentType === "Plural";
|
|
147
|
+
const elementIsBranch = componentType === "Branch";
|
|
148
|
+
element.openingElement.attributes.forEach((attr, index) => {
|
|
149
|
+
const helperAttribute = helperPath.get("openingElement").get("attributes")[index];
|
|
150
|
+
if (t.isJSXAttribute(attr)) {
|
|
151
|
+
const attrName = typeof attr.name.name === "string" ? attr.name.name : attr.name.name.name;
|
|
152
|
+
let attrValue = null;
|
|
153
|
+
if (elementIsBranch && attrName.startsWith("data-")) {
|
|
154
|
+
const location = `${attr.loc?.start?.line}:${attr.loc?.start?.column}`;
|
|
155
|
+
output.errors.push(warnDataAttrOnBranch(config.file, attrName, location));
|
|
156
|
+
}
|
|
157
|
+
if (attr.value) {
|
|
158
|
+
if (t.isStringLiteral(attr.value)) attrValue = attr.value.value;
|
|
159
|
+
else if (t.isJSXExpressionContainer(attr.value)) {
|
|
160
|
+
const helperValue = helperAttribute.get("value");
|
|
161
|
+
const isHtmlContentProp = Object.values(HTML_CONTENT_PROPS).includes(attrName);
|
|
162
|
+
if (elementIsPlural && isAcceptedPluralForm(attrName) || elementIsBranch && attrName !== "branch" && !attrName.startsWith("data-")) {
|
|
163
|
+
if (t.isTemplateLiteral(attr.value.expression) && !isStaticExpression(attr.value.expression, true).isStatic) output.unwrappedExpressions.push(generate(attr.value).code);
|
|
164
|
+
if (t.isArrayExpression(attr.value.expression)) output.unwrappedExpressions.push(generate(attr.value.expression).code);
|
|
165
|
+
attrValue = buildJSXTree({
|
|
166
|
+
node: attr.value,
|
|
167
|
+
insideT: true,
|
|
168
|
+
inDerive,
|
|
169
|
+
scopeNode,
|
|
170
|
+
helperPath: helperValue,
|
|
171
|
+
config,
|
|
172
|
+
state,
|
|
173
|
+
output
|
|
174
|
+
});
|
|
175
|
+
} else if (isHtmlContentProp) {
|
|
176
|
+
const staticAnalysis = isStaticExpression(attr.value.expression, true);
|
|
177
|
+
if (staticAnalysis.isStatic && staticAnalysis.value !== void 0) attrValue = staticAnalysis.value;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
props[attrName] = attrValue;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (elementIsVariable) {
|
|
185
|
+
if (componentType === "Static" || componentType === "Derive") {
|
|
186
|
+
const helperElement = helperPath.get("children");
|
|
187
|
+
const results = {
|
|
188
|
+
nodeType: "element",
|
|
189
|
+
type: componentType,
|
|
190
|
+
props
|
|
191
|
+
};
|
|
192
|
+
const childrenArray = [];
|
|
193
|
+
if (state.visited === null) state.visited = /* @__PURE__ */ new Set();
|
|
194
|
+
for (let index = 0; index < element.children.length; index++) {
|
|
195
|
+
const helperChild = helperElement[index];
|
|
196
|
+
const result = buildJSXTree({
|
|
197
|
+
node: helperChild.node,
|
|
198
|
+
insideT: true,
|
|
199
|
+
inDerive: true,
|
|
200
|
+
scopeNode,
|
|
201
|
+
helperPath: helperChild,
|
|
202
|
+
config,
|
|
203
|
+
state,
|
|
204
|
+
output
|
|
205
|
+
});
|
|
206
|
+
if (Array.isArray(result)) childrenArray.push(...result);
|
|
207
|
+
else childrenArray.push(result);
|
|
208
|
+
}
|
|
209
|
+
if (childrenArray.length) results.props.children = childrenArray;
|
|
210
|
+
return results;
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
nodeType: "element",
|
|
214
|
+
type: componentType ?? typeName ?? "",
|
|
215
|
+
props
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const children = element.children.flatMap((child, index) => {
|
|
219
|
+
const result = buildJSXTree({
|
|
220
|
+
node: child,
|
|
221
|
+
insideT: true,
|
|
222
|
+
inDerive,
|
|
223
|
+
scopeNode,
|
|
224
|
+
helperPath: helperPath.get("children")[index],
|
|
225
|
+
config,
|
|
226
|
+
state,
|
|
227
|
+
output
|
|
228
|
+
});
|
|
229
|
+
if (Array.isArray(result)) return result;
|
|
230
|
+
return [result];
|
|
231
|
+
}).filter((child) => child !== null && child !== "");
|
|
232
|
+
if (children.length === 1) props.children = children[0];
|
|
233
|
+
else if (children.length > 1) props.children = children;
|
|
234
|
+
return {
|
|
235
|
+
nodeType: "element",
|
|
236
|
+
type: componentType ?? typeName,
|
|
237
|
+
props
|
|
238
|
+
};
|
|
239
|
+
} else if (t.isJSXFragment(node)) {
|
|
240
|
+
const children = node.children.flatMap((child, index) => {
|
|
241
|
+
const result = buildJSXTree({
|
|
242
|
+
node: child,
|
|
243
|
+
insideT: true,
|
|
244
|
+
inDerive,
|
|
245
|
+
scopeNode,
|
|
246
|
+
helperPath: helperPath.get("children")[index],
|
|
247
|
+
config,
|
|
248
|
+
state,
|
|
249
|
+
output
|
|
250
|
+
});
|
|
251
|
+
if (Array.isArray(result)) return result;
|
|
252
|
+
return [result];
|
|
253
|
+
}).filter((child) => child !== null && child !== "");
|
|
254
|
+
const props = {};
|
|
255
|
+
if (children.length === 1) props.children = children[0];
|
|
256
|
+
else if (children.length > 1) props.children = children;
|
|
257
|
+
return {
|
|
258
|
+
nodeType: "element",
|
|
259
|
+
type: "",
|
|
260
|
+
props
|
|
261
|
+
};
|
|
262
|
+
} else if (t.isStringLiteral(node)) return node.value;
|
|
263
|
+
else if (t.isTemplateLiteral(node)) {
|
|
264
|
+
if (!isStaticExpression(node, true).isStatic || node.quasis[0].value.cooked === void 0) return generate(node).code;
|
|
265
|
+
return node.quasis[0].value.cooked;
|
|
266
|
+
} else if (t.isNullLiteral(node)) return null;
|
|
267
|
+
else if (t.isBooleanLiteral(node)) return node.value;
|
|
268
|
+
else if (t.isNumericLiteral(node)) return node.value.toString();
|
|
269
|
+
else if (t.isUnaryExpression(node)) {
|
|
270
|
+
const staticAnalysis = isStaticExpression(node, true);
|
|
271
|
+
if (staticAnalysis.isStatic && staticAnalysis.value !== void 0) return staticAnalysis.value;
|
|
272
|
+
return generate(node).code;
|
|
273
|
+
} else if (t.isCallExpression(node) && t.isIdentifier(node.callee) || t.isAwaitExpression(node) && t.isCallExpression(node.argument) && t.isIdentifier(node.argument.callee)) if (inDerive) {
|
|
274
|
+
const callee = (node.type === "AwaitExpression" ? node.argument : node).callee;
|
|
275
|
+
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
276
|
+
if (!calleeBinding) {
|
|
277
|
+
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
return resolveDeriveFunctionInvocationFromBinding({
|
|
281
|
+
calleeBinding,
|
|
282
|
+
callee,
|
|
283
|
+
config,
|
|
284
|
+
state,
|
|
285
|
+
output
|
|
286
|
+
});
|
|
287
|
+
} else output.unwrappedExpressions.push(generate(node).code);
|
|
288
|
+
else if (t.isParenthesizedExpression(node)) {
|
|
289
|
+
const child = node.expression;
|
|
290
|
+
return buildJSXTree({
|
|
291
|
+
node: child,
|
|
292
|
+
insideT,
|
|
293
|
+
inDerive,
|
|
294
|
+
scopeNode,
|
|
295
|
+
helperPath: helperPath.get("expression"),
|
|
296
|
+
config,
|
|
297
|
+
state,
|
|
298
|
+
output
|
|
299
|
+
});
|
|
300
|
+
} else if (t.isIdentifier(node) || t.isMemberExpression(node) || t.isCallExpression(node) || t.isBinaryExpression(node) || t.isLogicalExpression(node) || t.isConditionalExpression(node)) output.unwrappedExpressions.push(generate(node).code);
|
|
301
|
+
else if (node === void 0 || node === null) output.unwrappedExpressions.push(String(node));
|
|
302
|
+
else output.unwrappedExpressions.push(generate(node).code);
|
|
303
|
+
return null;
|
|
465
304
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
: minifiedTree);
|
|
559
|
-
}
|
|
560
|
-
// If we found an unwrapped expression, skip
|
|
561
|
-
if (unwrappedExpressions.length > 0) {
|
|
562
|
-
output.errors.push(warnHasUnwrappedExpressionSync(config.file, unwrappedExpressions, metadata.id, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
// Create a temporary unique flag for derivable content
|
|
566
|
-
const temporaryDeriveId = `derive-temp-id-${randomUUID()}`;
|
|
567
|
-
// Resolve derive context variants if present
|
|
568
|
-
let contextVariants;
|
|
569
|
-
if (metadata._contextDeriveExpr) {
|
|
570
|
-
const contextExpr = metadata._contextDeriveExpr;
|
|
571
|
-
delete metadata._contextDeriveExpr;
|
|
572
|
-
const contextNode = handleDerivation({
|
|
573
|
-
expr: contextExpr,
|
|
574
|
-
tPath: scopeNode,
|
|
575
|
-
file: config.file,
|
|
576
|
-
parsingOptions: config.parsingOptions,
|
|
577
|
-
errors: componentErrors,
|
|
578
|
-
warnings: componentWarnings,
|
|
579
|
-
});
|
|
580
|
-
if (contextNode) {
|
|
581
|
-
contextVariants = nodeToStrings(contextNode);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
// <T> is valid here
|
|
585
|
-
for (const minifiedTree of minifiedTress) {
|
|
586
|
-
// Clean the tree by removing null 'c' fields from JsxElements
|
|
587
|
-
const cleanedTree = removeNullChildrenFields(minifiedTree);
|
|
588
|
-
if (contextVariants) {
|
|
589
|
-
for (const context of contextVariants) {
|
|
590
|
-
updates.push({
|
|
591
|
-
dataFormat: 'JSX',
|
|
592
|
-
source: cleanedTree,
|
|
593
|
-
metadata: {
|
|
594
|
-
...structuredClone(metadata),
|
|
595
|
-
context,
|
|
596
|
-
staticId: temporaryDeriveId,
|
|
597
|
-
},
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
updates.push({
|
|
603
|
-
dataFormat: 'JSX',
|
|
604
|
-
source: cleanedTree,
|
|
605
|
-
metadata: {
|
|
606
|
-
...structuredClone(metadata),
|
|
607
|
-
...(derivableTracker.isDerivable && { staticId: temporaryDeriveId }),
|
|
608
|
-
},
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
}
|
|
305
|
+
function parseJSXElement({ node, originalName, scopeNode, updates, config, state, output }) {
|
|
306
|
+
const openingElement = node.openingElement;
|
|
307
|
+
if (!(openingElement.name.type === "JSXIdentifier" && (originalName === "T" || originalName === "GtInternalTranslateJsx"))) return;
|
|
308
|
+
const componentErrors = [];
|
|
309
|
+
const componentWarnings = /* @__PURE__ */ new Set();
|
|
310
|
+
const metadata = {};
|
|
311
|
+
const relativeFilepath = path.relative(process.cwd(), config.file);
|
|
312
|
+
metadata.filePaths = [relativeFilepath];
|
|
313
|
+
const startLine = node.loc?.start?.line;
|
|
314
|
+
const endLine = node.loc?.end?.line;
|
|
315
|
+
if (config.includeSourceCodeContext && startLine && endLine) {
|
|
316
|
+
const entry = extractSourceCode(config.file, startLine, endLine, 5);
|
|
317
|
+
if (entry && relativeFilepath) metadata.sourceCode = { [relativeFilepath]: [entry] };
|
|
318
|
+
}
|
|
319
|
+
const unwrappedExpressions = [];
|
|
320
|
+
parseTProps({
|
|
321
|
+
openingElement,
|
|
322
|
+
metadata,
|
|
323
|
+
componentErrors,
|
|
324
|
+
file: config.file
|
|
325
|
+
});
|
|
326
|
+
const derivableTracker = { isDerivable: false };
|
|
327
|
+
const treeResult = buildJSXTree({
|
|
328
|
+
node,
|
|
329
|
+
scopeNode,
|
|
330
|
+
insideT: false,
|
|
331
|
+
inDerive: config.autoderive ?? false,
|
|
332
|
+
helperPath: scopeNode,
|
|
333
|
+
config,
|
|
334
|
+
state: {
|
|
335
|
+
visited: null,
|
|
336
|
+
callStack: [],
|
|
337
|
+
derivableTracker,
|
|
338
|
+
importedFunctionsMap: state.importedFunctionsMap
|
|
339
|
+
},
|
|
340
|
+
output: {
|
|
341
|
+
unwrappedExpressions,
|
|
342
|
+
errors: componentErrors,
|
|
343
|
+
warnings: componentWarnings
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
const jsxTree = isElementNode(treeResult) && treeResult.props?.children ? treeResult.props.children : treeResult;
|
|
347
|
+
if (componentWarnings.size > 0) componentWarnings.forEach((warning) => output.warnings.add(warning));
|
|
348
|
+
if (componentErrors.length > 0) {
|
|
349
|
+
output.errors.push(...componentErrors);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const multipliedTrees = multiplyJsxTree(handleChildrenWhitespace(jsxTree));
|
|
353
|
+
const minifiedTress = [];
|
|
354
|
+
for (const multipliedTree of multipliedTrees) {
|
|
355
|
+
const minifiedTree = addGTIdentifierToSyntaxTree(multipliedTree, 0, config.enableAutoJsxInjection ? new Set(Object.values(config.importAliases).filter((name) => VARIABLE_COMPONENTS.includes(name) && name !== "Derive" && name !== "Static")) : void 0);
|
|
356
|
+
minifiedTress.push(Array.isArray(minifiedTree) && minifiedTree.length === 1 ? minifiedTree[0] : minifiedTree);
|
|
357
|
+
}
|
|
358
|
+
if (unwrappedExpressions.length > 0) {
|
|
359
|
+
output.errors.push(warnHasUnwrappedExpressionSync(config.file, unwrappedExpressions, metadata.id, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const temporaryDeriveId = `derive-temp-id-${randomUUID()}`;
|
|
363
|
+
let contextVariants;
|
|
364
|
+
if (metadata._contextDeriveExpr) {
|
|
365
|
+
const contextExpr = metadata._contextDeriveExpr;
|
|
366
|
+
delete metadata._contextDeriveExpr;
|
|
367
|
+
const contextNode = handleDerivation({
|
|
368
|
+
expr: contextExpr,
|
|
369
|
+
tPath: scopeNode,
|
|
370
|
+
file: config.file,
|
|
371
|
+
parsingOptions: config.parsingOptions,
|
|
372
|
+
errors: componentErrors,
|
|
373
|
+
warnings: componentWarnings
|
|
374
|
+
});
|
|
375
|
+
if (contextNode) contextVariants = nodeToStrings(contextNode);
|
|
376
|
+
}
|
|
377
|
+
for (const minifiedTree of minifiedTress) {
|
|
378
|
+
const cleanedTree = removeNullChildrenFields(minifiedTree);
|
|
379
|
+
if (contextVariants) for (const context of contextVariants) updates.push({
|
|
380
|
+
dataFormat: "JSX",
|
|
381
|
+
source: cleanedTree,
|
|
382
|
+
metadata: {
|
|
383
|
+
...structuredClone(metadata),
|
|
384
|
+
context,
|
|
385
|
+
staticId: temporaryDeriveId
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
else updates.push({
|
|
389
|
+
dataFormat: "JSX",
|
|
390
|
+
source: cleanedTree,
|
|
391
|
+
metadata: {
|
|
392
|
+
...structuredClone(metadata),
|
|
393
|
+
...derivableTracker.isDerivable && { staticId: temporaryDeriveId }
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
612
397
|
}
|
|
613
|
-
function resolveDeriveFunctionInvocationFromBinding({ calleeBinding, callee, config, state, output
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const filePath = resolveImportPath(config.file, importPath, config.parsingOptions, resolveImportPathCache);
|
|
677
|
-
if (filePath && originalName) {
|
|
678
|
-
const result = withRecusionGuard({
|
|
679
|
-
filename: filePath,
|
|
680
|
-
functionName: originalName,
|
|
681
|
-
cb: () => processFunctionInFile({
|
|
682
|
-
config,
|
|
683
|
-
state,
|
|
684
|
-
output,
|
|
685
|
-
filePath,
|
|
686
|
-
functionName: originalName,
|
|
687
|
-
}),
|
|
688
|
-
});
|
|
689
|
-
if (result !== null) {
|
|
690
|
-
return result;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
695
|
-
return null;
|
|
398
|
+
function resolveDeriveFunctionInvocationFromBinding({ calleeBinding, callee, config, state, output }) {
|
|
399
|
+
function withRecusionGuard({ cb, filename, functionName }) {
|
|
400
|
+
const cacheKey = `${filename}::${functionName}`;
|
|
401
|
+
if (state.callStack.includes(cacheKey)) {
|
|
402
|
+
output.errors.push(warnRecursiveFunctionCallSync(config.file, functionName));
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
state.callStack.push(cacheKey);
|
|
406
|
+
const result = cb();
|
|
407
|
+
state.callStack.pop();
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
410
|
+
if (calleeBinding.path.isFunctionDeclaration()) {
|
|
411
|
+
const functionName = callee.name;
|
|
412
|
+
const path = calleeBinding.path;
|
|
413
|
+
return withRecusionGuard({
|
|
414
|
+
filename: config.file,
|
|
415
|
+
functionName,
|
|
416
|
+
cb: () => processFunctionDeclarationNodePath({
|
|
417
|
+
config,
|
|
418
|
+
state,
|
|
419
|
+
output,
|
|
420
|
+
path
|
|
421
|
+
})
|
|
422
|
+
});
|
|
423
|
+
} else if (calleeBinding.path.isVariableDeclarator() && calleeBinding.path.node.init && (t.isArrowFunctionExpression(calleeBinding.path.node.init) || t.isFunctionExpression(calleeBinding.path.node.init))) {
|
|
424
|
+
const functionName = callee.name;
|
|
425
|
+
const path = calleeBinding.path;
|
|
426
|
+
return withRecusionGuard({
|
|
427
|
+
filename: config.file,
|
|
428
|
+
functionName,
|
|
429
|
+
cb: () => processVariableDeclarationNodePath({
|
|
430
|
+
config,
|
|
431
|
+
state,
|
|
432
|
+
output,
|
|
433
|
+
functionName,
|
|
434
|
+
path
|
|
435
|
+
})
|
|
436
|
+
});
|
|
437
|
+
} else if (state.importedFunctionsMap.has(callee.name)) {
|
|
438
|
+
let originalName;
|
|
439
|
+
if (calleeBinding.path.isImportSpecifier()) originalName = t.isIdentifier(calleeBinding.path.node.imported) ? calleeBinding.path.node.imported.name : calleeBinding.path.node.imported.value;
|
|
440
|
+
else if (calleeBinding.path.isImportDefaultSpecifier()) originalName = calleeBinding.path.node.local.name;
|
|
441
|
+
else if (calleeBinding.path.isImportNamespaceSpecifier()) originalName = calleeBinding.path.node.local.name;
|
|
442
|
+
const importPath = state.importedFunctionsMap.get(callee.name);
|
|
443
|
+
const filePath = resolveImportPath(config.file, importPath, config.parsingOptions, resolveImportPathCache);
|
|
444
|
+
if (filePath && originalName) {
|
|
445
|
+
const result = withRecusionGuard({
|
|
446
|
+
filename: filePath,
|
|
447
|
+
functionName: originalName,
|
|
448
|
+
cb: () => processFunctionInFile({
|
|
449
|
+
config,
|
|
450
|
+
state,
|
|
451
|
+
output,
|
|
452
|
+
filePath,
|
|
453
|
+
functionName: originalName
|
|
454
|
+
})
|
|
455
|
+
});
|
|
456
|
+
if (result !== null) return result;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
460
|
+
return null;
|
|
696
461
|
}
|
|
697
462
|
/**
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
function processFunctionInFile({ config, state, output, filePath, functionName
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
return exportedName === functionName;
|
|
819
|
-
}
|
|
820
|
-
return false;
|
|
821
|
-
});
|
|
822
|
-
if (exportsFunction) {
|
|
823
|
-
reExports.push(path.node.source.value);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
},
|
|
827
|
-
});
|
|
828
|
-
// If function not found, follow re-exports
|
|
829
|
-
if (result === undefined && reExports.length > 0) {
|
|
830
|
-
for (const reExportPath of reExports) {
|
|
831
|
-
const resolvedPath = resolveImportPath(filePath, reExportPath, config.parsingOptions, resolveImportPathCache);
|
|
832
|
-
if (resolvedPath) {
|
|
833
|
-
const foundResult = processFunctionInFile({
|
|
834
|
-
config: {
|
|
835
|
-
importAliases,
|
|
836
|
-
parsingOptions: config.parsingOptions,
|
|
837
|
-
pkgs: config.pkgs,
|
|
838
|
-
file: filePath,
|
|
839
|
-
enableAutoJsxInjection: config.enableAutoJsxInjection,
|
|
840
|
-
},
|
|
841
|
-
state: {
|
|
842
|
-
...state,
|
|
843
|
-
importedFunctionsMap,
|
|
844
|
-
},
|
|
845
|
-
output,
|
|
846
|
-
filePath: resolvedPath,
|
|
847
|
-
functionName,
|
|
848
|
-
});
|
|
849
|
-
if (foundResult != null) {
|
|
850
|
-
result = foundResult;
|
|
851
|
-
break;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
// Mark this function search as processed in the cache
|
|
857
|
-
processFunctionCache.set(cacheKey, result !== undefined ? result : null);
|
|
858
|
-
}
|
|
859
|
-
catch {
|
|
860
|
-
// Silently skip files that can't be parsed or accessed
|
|
861
|
-
// Still mark as processed to avoid retrying failed parses
|
|
862
|
-
processFunctionCache.set(cacheKey, null);
|
|
863
|
-
}
|
|
864
|
-
return result !== undefined ? result : null;
|
|
463
|
+
* Searches for a specific user-defined function in a file.
|
|
464
|
+
* This is the resolution logic
|
|
465
|
+
*
|
|
466
|
+
* Handles multiple function declaration patterns:
|
|
467
|
+
* - function getInfo() { ... }
|
|
468
|
+
* - export function getInfo() { ... }
|
|
469
|
+
* - const getInfo = () => { ... }
|
|
470
|
+
*
|
|
471
|
+
* If the function is not found in the file, follows re-exports (export * from './other')
|
|
472
|
+
*/
|
|
473
|
+
function processFunctionInFile({ config, state, output, filePath, functionName }) {
|
|
474
|
+
const cacheKey = `${filePath}::${functionName}`;
|
|
475
|
+
if (processFunctionCache.has(cacheKey)) return processFunctionCache.get(cacheKey) ?? null;
|
|
476
|
+
if (state.visited && state.visited.has(filePath)) return null;
|
|
477
|
+
if (state.visited) state.visited.add(filePath);
|
|
478
|
+
let result = void 0;
|
|
479
|
+
try {
|
|
480
|
+
const ast = parse(fs.readFileSync(filePath, "utf8"), {
|
|
481
|
+
sourceType: "module",
|
|
482
|
+
plugins: ["jsx", "typescript"]
|
|
483
|
+
});
|
|
484
|
+
const pathsResult = getPathsAndAliases(ast, config.pkgs);
|
|
485
|
+
const importAliases = { ...pathsResult.importAliases };
|
|
486
|
+
for (const { localName, originalName } of pathsResult.translationComponentPaths) importAliases[localName] = originalName;
|
|
487
|
+
if (config.enableAutoJsxInjection) {
|
|
488
|
+
ensureTAndVarImported(ast, importAliases);
|
|
489
|
+
autoInsertJsxComponents(ast, importAliases);
|
|
490
|
+
}
|
|
491
|
+
let importedFunctionsMap = /* @__PURE__ */ new Map();
|
|
492
|
+
traverse(ast, { Program(path) {
|
|
493
|
+
importedFunctionsMap = buildImportMap(path);
|
|
494
|
+
} });
|
|
495
|
+
const reExports = [];
|
|
496
|
+
const warnDuplicateFuncDef = (path) => {
|
|
497
|
+
output.warnings.add(warnDuplicateFunctionDefinitionSync(filePath, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
|
|
498
|
+
};
|
|
499
|
+
traverse(ast, {
|
|
500
|
+
FunctionDeclaration(path) {
|
|
501
|
+
if (path.node.id?.name === functionName) {
|
|
502
|
+
if (result !== void 0) return warnDuplicateFuncDef(path);
|
|
503
|
+
result = processFunctionDeclarationNodePath({
|
|
504
|
+
config: {
|
|
505
|
+
importAliases,
|
|
506
|
+
parsingOptions: config.parsingOptions,
|
|
507
|
+
pkgs: config.pkgs,
|
|
508
|
+
file: filePath,
|
|
509
|
+
enableAutoJsxInjection: config.enableAutoJsxInjection
|
|
510
|
+
},
|
|
511
|
+
state: {
|
|
512
|
+
...state,
|
|
513
|
+
importedFunctionsMap
|
|
514
|
+
},
|
|
515
|
+
output,
|
|
516
|
+
path
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
VariableDeclarator(path) {
|
|
521
|
+
if (t.isIdentifier(path.node.id) && path.node.id.name === functionName && path.node.init && (t.isArrowFunctionExpression(path.node.init) || t.isFunctionExpression(path.node.init))) {
|
|
522
|
+
if (result !== void 0) return warnDuplicateFuncDef(path);
|
|
523
|
+
result = processVariableDeclarationNodePath({
|
|
524
|
+
config: {
|
|
525
|
+
importAliases,
|
|
526
|
+
parsingOptions: config.parsingOptions,
|
|
527
|
+
pkgs: config.pkgs,
|
|
528
|
+
file: filePath,
|
|
529
|
+
enableAutoJsxInjection: config.enableAutoJsxInjection
|
|
530
|
+
},
|
|
531
|
+
state: {
|
|
532
|
+
...state,
|
|
533
|
+
importedFunctionsMap
|
|
534
|
+
},
|
|
535
|
+
output,
|
|
536
|
+
functionName,
|
|
537
|
+
path
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
ExportAllDeclaration(path) {
|
|
542
|
+
if (t.isStringLiteral(path.node.source)) reExports.push(path.node.source.value);
|
|
543
|
+
},
|
|
544
|
+
ExportNamedDeclaration(path) {
|
|
545
|
+
if (path.node.source && t.isStringLiteral(path.node.source)) {
|
|
546
|
+
if (path.node.specifiers.some((spec) => {
|
|
547
|
+
if (t.isExportSpecifier(spec)) return (t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value) === functionName;
|
|
548
|
+
return false;
|
|
549
|
+
})) reExports.push(path.node.source.value);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
if (result === void 0 && reExports.length > 0) for (const reExportPath of reExports) {
|
|
554
|
+
const resolvedPath = resolveImportPath(filePath, reExportPath, config.parsingOptions, resolveImportPathCache);
|
|
555
|
+
if (resolvedPath) {
|
|
556
|
+
const foundResult = processFunctionInFile({
|
|
557
|
+
config: {
|
|
558
|
+
importAliases,
|
|
559
|
+
parsingOptions: config.parsingOptions,
|
|
560
|
+
pkgs: config.pkgs,
|
|
561
|
+
file: filePath,
|
|
562
|
+
enableAutoJsxInjection: config.enableAutoJsxInjection
|
|
563
|
+
},
|
|
564
|
+
state: {
|
|
565
|
+
...state,
|
|
566
|
+
importedFunctionsMap
|
|
567
|
+
},
|
|
568
|
+
output,
|
|
569
|
+
filePath: resolvedPath,
|
|
570
|
+
functionName
|
|
571
|
+
});
|
|
572
|
+
if (foundResult != null) {
|
|
573
|
+
result = foundResult;
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
processFunctionCache.set(cacheKey, result !== void 0 ? result : null);
|
|
579
|
+
} catch {
|
|
580
|
+
processFunctionCache.set(cacheKey, null);
|
|
581
|
+
}
|
|
582
|
+
return result !== void 0 ? result : null;
|
|
865
583
|
}
|
|
866
584
|
/**
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
function processFunctionDeclarationNodePath({ config, state, output, path
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
result.branches.push(deriveResult);
|
|
896
|
-
}
|
|
897
|
-
},
|
|
898
|
-
});
|
|
899
|
-
if (result.branches.length === 0) {
|
|
900
|
-
return null;
|
|
901
|
-
}
|
|
902
|
-
return result;
|
|
585
|
+
* Process a function declaration
|
|
586
|
+
* function getInfo() { ... }
|
|
587
|
+
*/
|
|
588
|
+
function processFunctionDeclarationNodePath({ config, state, output, path }) {
|
|
589
|
+
const result = {
|
|
590
|
+
nodeType: "multiplication",
|
|
591
|
+
branches: []
|
|
592
|
+
};
|
|
593
|
+
path.traverse({
|
|
594
|
+
Function(path) {
|
|
595
|
+
path.skip();
|
|
596
|
+
},
|
|
597
|
+
ReturnStatement(returnPath) {
|
|
598
|
+
const returnNodePath = returnPath.get("argument");
|
|
599
|
+
if (!returnNodePath.isExpression()) return;
|
|
600
|
+
const deriveResult = processDeriveExpression({
|
|
601
|
+
config,
|
|
602
|
+
state,
|
|
603
|
+
output,
|
|
604
|
+
expressionNodePath: returnNodePath,
|
|
605
|
+
scopeNode: returnPath
|
|
606
|
+
});
|
|
607
|
+
if (Array.isArray(deriveResult)) result.branches.push(...deriveResult);
|
|
608
|
+
else result.branches.push(deriveResult);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
if (result.branches.length === 0) return null;
|
|
612
|
+
return result;
|
|
903
613
|
}
|
|
904
614
|
/**
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
function processVariableDeclarationNodePath({ config, state, output, functionName, path
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
scopeNode: returnPath,
|
|
955
|
-
});
|
|
956
|
-
if (Array.isArray(deriveResult)) {
|
|
957
|
-
result.branches.push(...deriveResult);
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
result.branches.push(deriveResult);
|
|
961
|
-
}
|
|
962
|
-
},
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
if (result.branches.length === 0) {
|
|
966
|
-
output.errors.push(warnMissingReturnSync(config.file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
|
|
967
|
-
return null;
|
|
968
|
-
}
|
|
969
|
-
return result;
|
|
615
|
+
* Process a variable declaration of a function
|
|
616
|
+
* const getInfo = () => { ... }
|
|
617
|
+
*
|
|
618
|
+
* IMPORTANT: the RHand value must be the function definition, or this will fail
|
|
619
|
+
*/
|
|
620
|
+
function processVariableDeclarationNodePath({ config, state, output, functionName, path }) {
|
|
621
|
+
const result = {
|
|
622
|
+
nodeType: "multiplication",
|
|
623
|
+
branches: []
|
|
624
|
+
};
|
|
625
|
+
const arrowFunctionPath = path.get("init");
|
|
626
|
+
if (!arrowFunctionPath.isArrowFunctionExpression()) {
|
|
627
|
+
output.errors.push(warnInvalidDeriveInitSync(config.file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
const bodyNodePath = arrowFunctionPath.get("body");
|
|
631
|
+
if (bodyNodePath.isExpression()) {
|
|
632
|
+
const deriveResult = processDeriveExpression({
|
|
633
|
+
config,
|
|
634
|
+
state,
|
|
635
|
+
output,
|
|
636
|
+
expressionNodePath: bodyNodePath,
|
|
637
|
+
scopeNode: arrowFunctionPath
|
|
638
|
+
});
|
|
639
|
+
if (Array.isArray(deriveResult)) result.branches.push(...deriveResult);
|
|
640
|
+
else result.branches.push(deriveResult);
|
|
641
|
+
} else bodyNodePath.traverse({
|
|
642
|
+
Function(path) {
|
|
643
|
+
path.skip();
|
|
644
|
+
},
|
|
645
|
+
ReturnStatement(returnPath) {
|
|
646
|
+
const returnNodePath = returnPath.get("argument");
|
|
647
|
+
if (!returnNodePath.isExpression()) return;
|
|
648
|
+
const deriveResult = processDeriveExpression({
|
|
649
|
+
config,
|
|
650
|
+
state,
|
|
651
|
+
output,
|
|
652
|
+
expressionNodePath: returnNodePath,
|
|
653
|
+
scopeNode: returnPath
|
|
654
|
+
});
|
|
655
|
+
if (Array.isArray(deriveResult)) result.branches.push(...deriveResult);
|
|
656
|
+
else result.branches.push(deriveResult);
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
if (result.branches.length === 0) {
|
|
660
|
+
output.errors.push(warnMissingReturnSync(config.file, functionName, `${path.node.loc?.start?.line}:${path.node.loc?.start?.column}`));
|
|
661
|
+
return null;
|
|
662
|
+
}
|
|
663
|
+
return result;
|
|
970
664
|
}
|
|
971
665
|
/**
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
function processDeriveExpression({ config, state, output, expressionNodePath, scopeNode
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
const errorsBefore = output.errors.length;
|
|
1081
|
-
const stringNode = parseStringExpression(binding.path.node.init, binding.path, config.file, config.parsingOptions, output.warnings, output.errors);
|
|
1082
|
-
if (stringNode) {
|
|
1083
|
-
const strings = nodeToStrings(stringNode);
|
|
1084
|
-
if (strings.length === 0) {
|
|
1085
|
-
return null;
|
|
1086
|
-
}
|
|
1087
|
-
if (strings.length === 1) {
|
|
1088
|
-
return strings[0];
|
|
1089
|
-
}
|
|
1090
|
-
return {
|
|
1091
|
-
nodeType: 'multiplication',
|
|
1092
|
-
branches: strings.map((s) => s),
|
|
1093
|
-
};
|
|
1094
|
-
}
|
|
1095
|
-
// parseStringExpression returned null — if it already pushed errors,
|
|
1096
|
-
// avoid double-reporting by skipping the buildJSXTree fallthrough.
|
|
1097
|
-
if (output.errors.length > errorsBefore) {
|
|
1098
|
-
return null;
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
// Not resolvable — fall through to existing buildJSXTree behavior
|
|
1102
|
-
return buildJSXTree({
|
|
1103
|
-
node: expressionNodePath.node,
|
|
1104
|
-
helperPath: expressionNodePath,
|
|
1105
|
-
scopeNode,
|
|
1106
|
-
insideT: true,
|
|
1107
|
-
inDerive: true,
|
|
1108
|
-
config,
|
|
1109
|
-
state,
|
|
1110
|
-
output,
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
else {
|
|
1114
|
-
return buildJSXTree({
|
|
1115
|
-
node: expressionNodePath.node,
|
|
1116
|
-
helperPath: expressionNodePath,
|
|
1117
|
-
scopeNode,
|
|
1118
|
-
insideT: true,
|
|
1119
|
-
inDerive: true,
|
|
1120
|
-
config,
|
|
1121
|
-
state,
|
|
1122
|
-
output,
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
666
|
+
* Process a <Derive> expression
|
|
667
|
+
*/
|
|
668
|
+
function processDeriveExpression({ config, state, output, expressionNodePath, scopeNode }) {
|
|
669
|
+
state.derivableTracker.isDerivable = true;
|
|
670
|
+
if (t.isParenthesizedExpression(expressionNodePath.node)) return processDeriveExpression({
|
|
671
|
+
config,
|
|
672
|
+
state,
|
|
673
|
+
output,
|
|
674
|
+
scopeNode,
|
|
675
|
+
expressionNodePath: expressionNodePath.get("expression")
|
|
676
|
+
});
|
|
677
|
+
else if (t.isCallExpression(expressionNodePath.node) && t.isIdentifier(expressionNodePath.node.callee)) {
|
|
678
|
+
const callee = expressionNodePath.node.callee;
|
|
679
|
+
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
680
|
+
if (!calleeBinding) {
|
|
681
|
+
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
return resolveDeriveFunctionInvocationFromBinding({
|
|
685
|
+
calleeBinding,
|
|
686
|
+
callee,
|
|
687
|
+
config,
|
|
688
|
+
state,
|
|
689
|
+
output
|
|
690
|
+
});
|
|
691
|
+
} else if (t.isAwaitExpression(expressionNodePath.node) && t.isCallExpression(expressionNodePath.node.argument) && t.isIdentifier(expressionNodePath.node.argument.callee)) {
|
|
692
|
+
const callee = expressionNodePath.node.argument.callee;
|
|
693
|
+
const calleeBinding = scopeNode.scope.getBinding(callee.name);
|
|
694
|
+
if (!calleeBinding) {
|
|
695
|
+
output.warnings.add(warnFunctionNotFoundSync(config.file, callee.name, `${callee.loc?.start?.line}:${callee.loc?.start?.column}`));
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
return resolveDeriveFunctionInvocationFromBinding({
|
|
699
|
+
calleeBinding,
|
|
700
|
+
callee,
|
|
701
|
+
config,
|
|
702
|
+
state,
|
|
703
|
+
output
|
|
704
|
+
});
|
|
705
|
+
} else if (t.isJSXElement(expressionNodePath.node) || t.isJSXFragment(expressionNodePath.node)) return buildJSXTree({
|
|
706
|
+
node: expressionNodePath.node,
|
|
707
|
+
helperPath: expressionNodePath,
|
|
708
|
+
scopeNode,
|
|
709
|
+
insideT: true,
|
|
710
|
+
inDerive: true,
|
|
711
|
+
config,
|
|
712
|
+
state,
|
|
713
|
+
output
|
|
714
|
+
});
|
|
715
|
+
else if (t.isConditionalExpression(expressionNodePath.node)) return {
|
|
716
|
+
nodeType: "multiplication",
|
|
717
|
+
branches: [expressionNodePath.get("consequent"), expressionNodePath.get("alternate")].flatMap((expressionNodePath) => {
|
|
718
|
+
const r = processDeriveExpression({
|
|
719
|
+
config,
|
|
720
|
+
state,
|
|
721
|
+
output,
|
|
722
|
+
scopeNode,
|
|
723
|
+
expressionNodePath
|
|
724
|
+
});
|
|
725
|
+
return Array.isArray(r) ? r : [r];
|
|
726
|
+
})
|
|
727
|
+
};
|
|
728
|
+
else if (t.isIdentifier(expressionNodePath.node)) {
|
|
729
|
+
const name = expressionNodePath.node.name;
|
|
730
|
+
const binding = scopeNode.scope.getBinding(name);
|
|
731
|
+
if (binding && binding.path.isVariableDeclarator() && binding.path.node.init) {
|
|
732
|
+
if (t.isObjectPattern(binding.path.node.id) || t.isArrayPattern(binding.path.node.id)) {
|
|
733
|
+
output.errors.push(warnDeriveDestructuringSync(config.file, name, `${expressionNodePath.node.loc?.start?.line}:${expressionNodePath.node.loc?.start?.column}`));
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
const declaration = binding.path.parentPath;
|
|
737
|
+
if (declaration?.isVariableDeclaration() && declaration.node.kind !== "const") {
|
|
738
|
+
output.warnings.add(warnDeriveNonConstVariableSync(config.file, name, declaration.node.kind, `${expressionNodePath.node.loc?.start?.line}:${expressionNodePath.node.loc?.start?.column}`));
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
const errorsBefore = output.errors.length;
|
|
742
|
+
const stringNode = parseStringExpression(binding.path.node.init, binding.path, config.file, config.parsingOptions, output.warnings, output.errors);
|
|
743
|
+
if (stringNode) {
|
|
744
|
+
const strings = nodeToStrings(stringNode);
|
|
745
|
+
if (strings.length === 0) return null;
|
|
746
|
+
if (strings.length === 1) return strings[0];
|
|
747
|
+
return {
|
|
748
|
+
nodeType: "multiplication",
|
|
749
|
+
branches: strings.map((s) => s)
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
if (output.errors.length > errorsBefore) return null;
|
|
753
|
+
}
|
|
754
|
+
return buildJSXTree({
|
|
755
|
+
node: expressionNodePath.node,
|
|
756
|
+
helperPath: expressionNodePath,
|
|
757
|
+
scopeNode,
|
|
758
|
+
insideT: true,
|
|
759
|
+
inDerive: true,
|
|
760
|
+
config,
|
|
761
|
+
state,
|
|
762
|
+
output
|
|
763
|
+
});
|
|
764
|
+
} else return buildJSXTree({
|
|
765
|
+
node: expressionNodePath.node,
|
|
766
|
+
helperPath: expressionNodePath,
|
|
767
|
+
scopeNode,
|
|
768
|
+
insideT: true,
|
|
769
|
+
inDerive: true,
|
|
770
|
+
config,
|
|
771
|
+
state,
|
|
772
|
+
output
|
|
773
|
+
});
|
|
1125
774
|
}
|
|
775
|
+
//#endregion
|
|
776
|
+
export { parseTranslationComponent };
|
|
777
|
+
|
|
778
|
+
//# sourceMappingURL=parseJsx.js.map
|