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,1124 +1,760 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
1
|
+
import { isStaticExpression } from "../evaluateJsx.js";
|
|
2
|
+
import "./constants.js";
|
|
3
|
+
import { warnDeriveCircularSpreadSync, warnDeriveDestructuringSync, warnDeriveFunctionNoResultsSync, warnDeriveNonConstVariableSync, warnDeriveOptionalChainingSync, warnDeriveUnresolvableValueSync, warnFunctionNotFoundSync, warnInvalidDeclareVarNameSync } from "../../../console/index.js";
|
|
4
|
+
import { resolveImportPath } from "./resolveImportPath.js";
|
|
5
|
+
import { buildImportMap } from "./buildImportMap.js";
|
|
6
|
+
import { GT_LIBRARIES } from "../../../types/libraries.js";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import * as t from "@babel/types";
|
|
9
|
+
import { parse } from "@babel/parser";
|
|
10
|
+
import generateModule from "@babel/generator";
|
|
11
|
+
import { declareVar } from "generaltranslation/internal";
|
|
12
|
+
import traverseModule from "@babel/traverse";
|
|
13
|
+
//#region src/react/jsx/utils/parseString.ts
|
|
14
14
|
const traverse = traverseModule.default || traverseModule;
|
|
15
15
|
const generate = generateModule.default || generateModule;
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const resolveImportPathCache = new Map();
|
|
17
|
+
* Cache for resolved import paths to avoid redundant I/O operations.
|
|
18
|
+
*/
|
|
19
|
+
const resolveImportPathCache = /* @__PURE__ */ new Map();
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const processFunctionCache = new Map();
|
|
21
|
+
* Cache for processed functions to avoid re-parsing the same files.
|
|
22
|
+
*/
|
|
23
|
+
const processFunctionCache = /* @__PURE__ */ new Map();
|
|
24
24
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const resolveObjectNodeCache = new Map();
|
|
25
|
+
* Cache for resolved object nodes to avoid re-parsing the same files.
|
|
26
|
+
*/
|
|
27
|
+
const resolveObjectNodeCache = /* @__PURE__ */ new Map();
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const resolvingIdentifiers = new Set();
|
|
29
|
+
* Guard against infinite recursion when resolving identifier chains.
|
|
30
|
+
* Tracks AST nodes currently being resolved to detect circular references.
|
|
31
|
+
*/
|
|
32
|
+
const resolvingIdentifiers = /* @__PURE__ */ new Set();
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
* Unwraps TypeScript type annotations to get the underlying expression.
|
|
35
|
+
* Handles: as, satisfies, non-null assertion (!), and angle-bracket assertions.
|
|
36
|
+
*/
|
|
37
37
|
function unwrapTypeAnnotation(node) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return node.expression;
|
|
44
|
-
if (t.isTSTypeAssertion(node))
|
|
45
|
-
return node.expression;
|
|
46
|
-
return node;
|
|
38
|
+
if (t.isTSAsExpression(node)) return node.expression;
|
|
39
|
+
if (t.isTSSatisfiesExpression(node)) return node.expression;
|
|
40
|
+
if (t.isTSNonNullExpression(node)) return node.expression;
|
|
41
|
+
if (t.isTSTypeAssertion(node)) return node.expression;
|
|
42
|
+
return node;
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
* Collects all resolvable property entries from an ObjectExpression,
|
|
46
|
+
* including entries from spread sources.
|
|
47
|
+
*/
|
|
52
48
|
function collectObjectProperties(objExpr, tPath, file, parsingOptions, errors = []) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const programPath = tPath.scope.getProgramParent().path;
|
|
106
|
-
const importMap = buildImportMap(programPath);
|
|
107
|
-
const importPath = importMap.get(prop.argument.name);
|
|
108
|
-
if (!importPath)
|
|
109
|
-
continue;
|
|
110
|
-
let originalName = prop.argument.name;
|
|
111
|
-
if (spreadBinding.path.isImportSpecifier()) {
|
|
112
|
-
const imported = spreadBinding.path.node.imported;
|
|
113
|
-
originalName = t.isIdentifier(imported)
|
|
114
|
-
? imported.name
|
|
115
|
-
: imported.value;
|
|
116
|
-
}
|
|
117
|
-
const resolvedFilePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
118
|
-
if (!resolvedFilePath)
|
|
119
|
-
continue;
|
|
120
|
-
const crossFileObjects = resolveObjectNodesInFile(resolvedFilePath, originalName, parsingOptions);
|
|
121
|
-
for (const crossObj of crossFileObjects) {
|
|
122
|
-
const crossEntries = t.isArrayExpression(crossObj.objExpr)
|
|
123
|
-
? collectArrayElements(crossObj.objExpr, crossObj.tPath, crossObj.file, parsingOptions)
|
|
124
|
-
: collectObjectProperties(crossObj.objExpr, crossObj.tPath, crossObj.file, parsingOptions, errors);
|
|
125
|
-
entries.push(...crossEntries);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// Skip ObjectMethod (getters, setters, methods)
|
|
130
|
-
}
|
|
131
|
-
return entries;
|
|
49
|
+
const entries = [];
|
|
50
|
+
for (const prop of objExpr.properties) if (t.isObjectProperty(prop)) {
|
|
51
|
+
const key = !prop.computed && t.isIdentifier(prop.key) ? prop.key.name : t.isStringLiteral(prop.key) ? prop.key.value : t.isNumericLiteral(prop.key) ? String(prop.key.value) : null;
|
|
52
|
+
if (t.isExpression(prop.value)) entries.push({
|
|
53
|
+
key,
|
|
54
|
+
value: prop.value
|
|
55
|
+
});
|
|
56
|
+
} else if (t.isSpreadElement(prop)) {
|
|
57
|
+
const spreadArg = unwrapTypeAnnotation(prop.argument);
|
|
58
|
+
if (t.isObjectExpression(spreadArg)) {
|
|
59
|
+
entries.push(...collectObjectProperties(spreadArg, tPath, file, parsingOptions, errors));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!t.isIdentifier(prop.argument)) continue;
|
|
63
|
+
const spreadBinding = tPath.scope.getBinding(prop.argument.name);
|
|
64
|
+
if (!spreadBinding) continue;
|
|
65
|
+
if (spreadBinding.path.isVariableDeclarator()) {
|
|
66
|
+
const spreadDecl = spreadBinding.path.parentPath;
|
|
67
|
+
if (spreadDecl?.isVariableDeclaration() && spreadDecl.node.kind !== "const") continue;
|
|
68
|
+
const spreadInit = spreadBinding.path.node.init;
|
|
69
|
+
if (!spreadInit) continue;
|
|
70
|
+
if (resolvingIdentifiers.has(spreadInit)) {
|
|
71
|
+
errors.push(warnDeriveCircularSpreadSync(file, prop.argument.name, `${prop.loc?.start?.line}:${prop.loc?.start?.column}`));
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
resolvingIdentifiers.add(spreadInit);
|
|
75
|
+
const spreadObj = unwrapTypeAnnotation(spreadInit);
|
|
76
|
+
if (!t.isObjectExpression(spreadObj)) {
|
|
77
|
+
resolvingIdentifiers.delete(spreadInit);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
entries.push(...collectObjectProperties(spreadObj, spreadBinding.path, file, parsingOptions, errors));
|
|
81
|
+
resolvingIdentifiers.delete(spreadInit);
|
|
82
|
+
} else if (spreadBinding.path.isImportSpecifier() || spreadBinding.path.isImportDefaultSpecifier()) {
|
|
83
|
+
const programPath = tPath.scope.getProgramParent().path;
|
|
84
|
+
const importPath = buildImportMap(programPath).get(prop.argument.name);
|
|
85
|
+
if (!importPath) continue;
|
|
86
|
+
let originalName = prop.argument.name;
|
|
87
|
+
if (spreadBinding.path.isImportSpecifier()) {
|
|
88
|
+
const imported = spreadBinding.path.node.imported;
|
|
89
|
+
originalName = t.isIdentifier(imported) ? imported.name : imported.value;
|
|
90
|
+
}
|
|
91
|
+
const resolvedFilePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
92
|
+
if (!resolvedFilePath) continue;
|
|
93
|
+
const crossFileObjects = resolveObjectNodesInFile(resolvedFilePath, originalName, parsingOptions);
|
|
94
|
+
for (const crossObj of crossFileObjects) {
|
|
95
|
+
const crossEntries = t.isArrayExpression(crossObj.objExpr) ? collectArrayElements(crossObj.objExpr, crossObj.tPath, crossObj.file, parsingOptions) : collectObjectProperties(crossObj.objExpr, crossObj.tPath, crossObj.file, parsingOptions, errors);
|
|
96
|
+
entries.push(...crossEntries);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return entries;
|
|
132
101
|
}
|
|
133
102
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
103
|
+
* Collects elements from an ArrayExpression as ObjectEntry[] with index as key.
|
|
104
|
+
* Handles spread elements by resolving the source array.
|
|
105
|
+
*/
|
|
137
106
|
function collectArrayElements(arrExpr, tPath, file, parsingOptions, errors = []) {
|
|
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
|
-
entries.push({ key: String(index++), value: e.value });
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
if (t.isExpression(el)) {
|
|
203
|
-
entries.push({ key: String(index), value: unwrapTypeAnnotation(el) });
|
|
204
|
-
}
|
|
205
|
-
index++;
|
|
206
|
-
}
|
|
207
|
-
return entries;
|
|
107
|
+
const entries = [];
|
|
108
|
+
let index = 0;
|
|
109
|
+
for (const el of arrExpr.elements) {
|
|
110
|
+
if (!el) {
|
|
111
|
+
index++;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (t.isSpreadElement(el)) {
|
|
115
|
+
if (!t.isIdentifier(el.argument)) continue;
|
|
116
|
+
const spreadBinding = tPath.scope.getBinding(el.argument.name);
|
|
117
|
+
if (!spreadBinding) continue;
|
|
118
|
+
if (spreadBinding.path.isVariableDeclarator()) {
|
|
119
|
+
const spreadDecl = spreadBinding.path.parentPath;
|
|
120
|
+
if (spreadDecl?.isVariableDeclaration() && spreadDecl.node.kind !== "const") {
|
|
121
|
+
errors.push(warnDeriveNonConstVariableSync(file, el.argument.name, spreadDecl.node.kind, `${el.loc?.start?.line}:${el.loc?.start?.column}`));
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const spreadInit = spreadBinding.path.node.init;
|
|
125
|
+
if (!spreadInit) continue;
|
|
126
|
+
const spreadUnwrapped = unwrapTypeAnnotation(spreadInit);
|
|
127
|
+
if (t.isArrayExpression(spreadUnwrapped)) {
|
|
128
|
+
const spreadEntries = collectArrayElements(spreadUnwrapped, spreadBinding.path, file, parsingOptions);
|
|
129
|
+
for (const e of spreadEntries) entries.push({
|
|
130
|
+
key: String(index++),
|
|
131
|
+
value: e.value
|
|
132
|
+
});
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
} else if (spreadBinding.path.isImportSpecifier() || spreadBinding.path.isImportDefaultSpecifier()) {
|
|
136
|
+
const programPath = tPath.scope.getProgramParent().path;
|
|
137
|
+
const importPath = buildImportMap(programPath).get(el.argument.name);
|
|
138
|
+
if (!importPath) continue;
|
|
139
|
+
let originalName = el.argument.name;
|
|
140
|
+
if (spreadBinding.path.isImportSpecifier()) {
|
|
141
|
+
const imported = spreadBinding.path.node.imported;
|
|
142
|
+
originalName = t.isIdentifier(imported) ? imported.name : imported.value;
|
|
143
|
+
}
|
|
144
|
+
const resolvedFilePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
145
|
+
if (!resolvedFilePath) continue;
|
|
146
|
+
const crossFileNodes = resolveObjectNodesInFile(resolvedFilePath, originalName, parsingOptions);
|
|
147
|
+
for (const crossNode of crossFileNodes) if (t.isArrayExpression(crossNode.objExpr)) {
|
|
148
|
+
const spreadEntries = collectArrayElements(crossNode.objExpr, crossNode.tPath, crossNode.file, parsingOptions);
|
|
149
|
+
for (const e of spreadEntries) entries.push({
|
|
150
|
+
key: String(index++),
|
|
151
|
+
value: e.value
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (t.isExpression(el)) entries.push({
|
|
158
|
+
key: String(index),
|
|
159
|
+
value: unwrapTypeAnnotation(el)
|
|
160
|
+
});
|
|
161
|
+
index++;
|
|
162
|
+
}
|
|
163
|
+
return entries;
|
|
208
164
|
}
|
|
209
165
|
/**
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
166
|
+
* Resolves an expression to ObjectExpression or ArrayExpression AST node(s).
|
|
167
|
+
* Handles Identifier (local + imported) and MemberExpression (nested access chains).
|
|
168
|
+
*/
|
|
213
169
|
function resolveToObjectNodes(node, tPath, file, parsingOptions, warnings, errors = []) {
|
|
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
|
-
// Determine if this is a static access (known key)
|
|
295
|
-
let staticKey = null;
|
|
296
|
-
if (!node.computed && t.isIdentifier(node.property)) {
|
|
297
|
-
staticKey = node.property.name;
|
|
298
|
-
}
|
|
299
|
-
else if (node.computed && t.isStringLiteral(node.property)) {
|
|
300
|
-
staticKey = node.property.value;
|
|
301
|
-
}
|
|
302
|
-
else if (node.computed && t.isNumericLiteral(node.property)) {
|
|
303
|
-
staticKey = String(node.property.value);
|
|
304
|
-
}
|
|
305
|
-
if (staticKey !== null) {
|
|
306
|
-
// Static: narrow to matching key(s) — don't break, spreads may duplicate keys
|
|
307
|
-
for (const entry of entries) {
|
|
308
|
-
if (entry.key === staticKey) {
|
|
309
|
-
const unwrapped = unwrapTypeAnnotation(entry.value);
|
|
310
|
-
if (t.isObjectExpression(unwrapped) ||
|
|
311
|
-
t.isArrayExpression(unwrapped)) {
|
|
312
|
-
results.push({
|
|
313
|
-
objExpr: unwrapped,
|
|
314
|
-
tPath: parent.tPath,
|
|
315
|
-
file: parent.file,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
// Dynamic: collect ALL entries whose values are ObjectExpressions or ArrayExpressions
|
|
323
|
-
for (const entry of entries) {
|
|
324
|
-
const unwrapped = unwrapTypeAnnotation(entry.value);
|
|
325
|
-
if (t.isObjectExpression(unwrapped) ||
|
|
326
|
-
t.isArrayExpression(unwrapped)) {
|
|
327
|
-
results.push({
|
|
328
|
-
objExpr: unwrapped,
|
|
329
|
-
tPath: parent.tPath,
|
|
330
|
-
file: parent.file,
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return results;
|
|
337
|
-
}
|
|
338
|
-
return [];
|
|
170
|
+
if (t.isIdentifier(node)) {
|
|
171
|
+
const binding = tPath.scope.getBinding(node.name);
|
|
172
|
+
if (!binding) return [];
|
|
173
|
+
if (binding.path.isVariableDeclarator()) {
|
|
174
|
+
const declaration = binding.path.parentPath;
|
|
175
|
+
if (declaration?.isVariableDeclaration() && declaration.node.kind !== "const") {
|
|
176
|
+
warnings.add(warnDeriveNonConstVariableSync(file, node.name, declaration.node.kind, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
177
|
+
return [];
|
|
178
|
+
}
|
|
179
|
+
const init = binding.path.node.init;
|
|
180
|
+
if (!init) return [];
|
|
181
|
+
const unwrapped = unwrapTypeAnnotation(init);
|
|
182
|
+
if (t.isObjectExpression(unwrapped) || t.isArrayExpression(unwrapped)) return [{
|
|
183
|
+
objExpr: unwrapped,
|
|
184
|
+
tPath: binding.path,
|
|
185
|
+
file
|
|
186
|
+
}];
|
|
187
|
+
if (t.isIdentifier(unwrapped)) return resolveToObjectNodes(unwrapped, binding.path, file, parsingOptions, warnings, errors);
|
|
188
|
+
if (t.isConditionalExpression(unwrapped)) {
|
|
189
|
+
const collectConditionalLeaves = (expr) => {
|
|
190
|
+
const inner = unwrapTypeAnnotation(expr);
|
|
191
|
+
if (t.isConditionalExpression(inner)) return [...collectConditionalLeaves(inner.consequent), ...collectConditionalLeaves(inner.alternate)];
|
|
192
|
+
if (t.isObjectExpression(inner) || t.isArrayExpression(inner)) return [{
|
|
193
|
+
objExpr: inner,
|
|
194
|
+
tPath: binding.path,
|
|
195
|
+
file
|
|
196
|
+
}];
|
|
197
|
+
return [];
|
|
198
|
+
};
|
|
199
|
+
return [...collectConditionalLeaves(unwrapped.consequent), ...collectConditionalLeaves(unwrapped.alternate)];
|
|
200
|
+
}
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
if (binding.path.isImportSpecifier() || binding.path.isImportDefaultSpecifier()) {
|
|
204
|
+
const programPath = tPath.scope.getProgramParent().path;
|
|
205
|
+
const importPath = buildImportMap(programPath).get(node.name);
|
|
206
|
+
if (!importPath) return [];
|
|
207
|
+
let originalName = node.name;
|
|
208
|
+
if (binding.path.isImportSpecifier()) {
|
|
209
|
+
const imported = binding.path.node.imported;
|
|
210
|
+
originalName = t.isIdentifier(imported) ? imported.name : imported.value;
|
|
211
|
+
}
|
|
212
|
+
const resolvedFilePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
213
|
+
if (!resolvedFilePath) return [];
|
|
214
|
+
return resolveObjectNodesInFile(resolvedFilePath, originalName, parsingOptions);
|
|
215
|
+
}
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
if (t.isMemberExpression(node)) {
|
|
219
|
+
if (!t.isExpression(node.object)) return [];
|
|
220
|
+
const parentObjects = resolveToObjectNodes(node.object, tPath, file, parsingOptions, warnings, errors);
|
|
221
|
+
if (parentObjects.length === 0) return [];
|
|
222
|
+
const results = [];
|
|
223
|
+
for (const parent of parentObjects) {
|
|
224
|
+
const entries = t.isArrayExpression(parent.objExpr) ? collectArrayElements(parent.objExpr, parent.tPath, parent.file, parsingOptions) : collectObjectProperties(parent.objExpr, parent.tPath, parent.file, parsingOptions, errors);
|
|
225
|
+
let staticKey = null;
|
|
226
|
+
if (!node.computed && t.isIdentifier(node.property)) staticKey = node.property.name;
|
|
227
|
+
else if (node.computed && t.isStringLiteral(node.property)) staticKey = node.property.value;
|
|
228
|
+
else if (node.computed && t.isNumericLiteral(node.property)) staticKey = String(node.property.value);
|
|
229
|
+
if (staticKey !== null) {
|
|
230
|
+
for (const entry of entries) if (entry.key === staticKey) {
|
|
231
|
+
const unwrapped = unwrapTypeAnnotation(entry.value);
|
|
232
|
+
if (t.isObjectExpression(unwrapped) || t.isArrayExpression(unwrapped)) results.push({
|
|
233
|
+
objExpr: unwrapped,
|
|
234
|
+
tPath: parent.tPath,
|
|
235
|
+
file: parent.file
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
} else for (const entry of entries) {
|
|
239
|
+
const unwrapped = unwrapTypeAnnotation(entry.value);
|
|
240
|
+
if (t.isObjectExpression(unwrapped) || t.isArrayExpression(unwrapped)) results.push({
|
|
241
|
+
objExpr: unwrapped,
|
|
242
|
+
tPath: parent.tPath,
|
|
243
|
+
file: parent.file
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return results;
|
|
248
|
+
}
|
|
249
|
+
return [];
|
|
339
250
|
}
|
|
340
251
|
/**
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
252
|
+
* Resolves an object declaration from an external file.
|
|
253
|
+
* Finds a const VariableDeclarator with ObjectExpression init.
|
|
254
|
+
* Follows re-export chains.
|
|
255
|
+
*/
|
|
345
256
|
function resolveObjectNodesInFile(filePath, name, parsingOptions) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const reexportPath = path.node.source.value;
|
|
406
|
-
const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
|
|
407
|
-
if (resolvedPath) {
|
|
408
|
-
const specifier = path.node.specifiers.find((spec) => {
|
|
409
|
-
if (t.isExportSpecifier(spec)) {
|
|
410
|
-
const exportedName = t.isIdentifier(spec.exported)
|
|
411
|
-
? spec.exported.name
|
|
412
|
-
: spec.exported.value;
|
|
413
|
-
return exportedName === name;
|
|
414
|
-
}
|
|
415
|
-
return false;
|
|
416
|
-
});
|
|
417
|
-
let originalName = name;
|
|
418
|
-
if (specifier &&
|
|
419
|
-
t.isExportSpecifier(specifier) &&
|
|
420
|
-
t.isIdentifier(specifier.local)) {
|
|
421
|
-
originalName = specifier.local.name;
|
|
422
|
-
}
|
|
423
|
-
results.push(...resolveObjectNodesInFile(resolvedPath, originalName, parsingOptions));
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
resolveObjectNodeCache.set(cacheKey, results);
|
|
430
|
-
return results;
|
|
431
|
-
}
|
|
432
|
-
catch {
|
|
433
|
-
resolveObjectNodeCache.set(cacheKey, []);
|
|
434
|
-
return [];
|
|
435
|
-
}
|
|
257
|
+
const cacheKey = `${filePath}::${name}`;
|
|
258
|
+
if (resolveObjectNodeCache.has(cacheKey)) return resolveObjectNodeCache.get(cacheKey);
|
|
259
|
+
try {
|
|
260
|
+
const ast = parse(fs.readFileSync(filePath, "utf8"), {
|
|
261
|
+
sourceType: "module",
|
|
262
|
+
plugins: ["jsx", "typescript"]
|
|
263
|
+
});
|
|
264
|
+
const results = [];
|
|
265
|
+
traverse(ast, {
|
|
266
|
+
VariableDeclarator(path) {
|
|
267
|
+
if (t.isIdentifier(path.node.id) && path.node.id.name === name && results.length === 0) {
|
|
268
|
+
const init = path.node.init;
|
|
269
|
+
if (!init) return;
|
|
270
|
+
const declaration = path.parentPath;
|
|
271
|
+
if (declaration?.isVariableDeclaration() && declaration.node.kind !== "const") return;
|
|
272
|
+
const unwrapped = unwrapTypeAnnotation(init);
|
|
273
|
+
if (t.isObjectExpression(unwrapped) || t.isArrayExpression(unwrapped)) results.push({
|
|
274
|
+
objExpr: unwrapped,
|
|
275
|
+
tPath: path,
|
|
276
|
+
file: filePath
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
ExportAllDeclaration(path) {
|
|
281
|
+
if (results.length > 0) return;
|
|
282
|
+
if (t.isStringLiteral(path.node.source)) {
|
|
283
|
+
const reexportPath = path.node.source.value;
|
|
284
|
+
const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
|
|
285
|
+
if (resolvedPath) results.push(...resolveObjectNodesInFile(resolvedPath, name, parsingOptions));
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
ExportNamedDeclaration(path) {
|
|
289
|
+
if (results.length > 0) return;
|
|
290
|
+
if (path.node.source && t.isStringLiteral(path.node.source)) {
|
|
291
|
+
if (path.node.specifiers.some((spec) => {
|
|
292
|
+
if (t.isExportSpecifier(spec)) return (t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value) === name;
|
|
293
|
+
return false;
|
|
294
|
+
})) {
|
|
295
|
+
const reexportPath = path.node.source.value;
|
|
296
|
+
const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
|
|
297
|
+
if (resolvedPath) {
|
|
298
|
+
const specifier = path.node.specifiers.find((spec) => {
|
|
299
|
+
if (t.isExportSpecifier(spec)) return (t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value) === name;
|
|
300
|
+
return false;
|
|
301
|
+
});
|
|
302
|
+
let originalName = name;
|
|
303
|
+
if (specifier && t.isExportSpecifier(specifier) && t.isIdentifier(specifier.local)) originalName = specifier.local.name;
|
|
304
|
+
results.push(...resolveObjectNodesInFile(resolvedPath, originalName, parsingOptions));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
resolveObjectNodeCache.set(cacheKey, results);
|
|
311
|
+
return results;
|
|
312
|
+
} catch {
|
|
313
|
+
resolveObjectNodeCache.set(cacheKey, []);
|
|
314
|
+
return [];
|
|
315
|
+
}
|
|
436
316
|
}
|
|
437
317
|
/**
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
if (branches.length === 0)
|
|
644
|
-
return null;
|
|
645
|
-
if (branches.length === 1)
|
|
646
|
-
return branches[0];
|
|
647
|
-
return { type: 'choice', nodes: branches };
|
|
648
|
-
}
|
|
649
|
-
// Handle function calls (e.g., getName())
|
|
650
|
-
if (t.isCallExpression(node) && t.isIdentifier(node.callee)) {
|
|
651
|
-
const functionName = node.callee.name;
|
|
652
|
-
const calleeBinding = tPath.scope.getBinding(functionName);
|
|
653
|
-
if (!calleeBinding) {
|
|
654
|
-
// Function not found in scope
|
|
655
|
-
warnings.add(warnFunctionNotFoundSync(file, functionName, `${node.callee.loc?.start?.line}:${node.callee.loc?.start?.column}`));
|
|
656
|
-
return null;
|
|
657
|
-
}
|
|
658
|
-
// Check if this is an imported function
|
|
659
|
-
const programPath = tPath.scope.getProgramParent().path;
|
|
660
|
-
const importedFunctionsMap = buildImportMap(programPath);
|
|
661
|
-
if (importedFunctionsMap.has(functionName)) {
|
|
662
|
-
// Function is imported - resolve cross-file
|
|
663
|
-
let originalName;
|
|
664
|
-
if (calleeBinding.path.isImportSpecifier()) {
|
|
665
|
-
originalName = t.isIdentifier(calleeBinding.path.node.imported)
|
|
666
|
-
? calleeBinding.path.node.imported.name
|
|
667
|
-
: calleeBinding.path.node.imported.value;
|
|
668
|
-
}
|
|
669
|
-
else if (calleeBinding.path.isImportDefaultSpecifier()) {
|
|
670
|
-
originalName = calleeBinding.path.node.local.name;
|
|
671
|
-
}
|
|
672
|
-
else if (calleeBinding.path.isImportNamespaceSpecifier()) {
|
|
673
|
-
originalName = calleeBinding.path.node.local.name;
|
|
674
|
-
}
|
|
675
|
-
const importPath = importedFunctionsMap.get(functionName);
|
|
676
|
-
// Handle declareVar function
|
|
677
|
-
if (originalName === DECLARE_VAR_FUNCTION &&
|
|
678
|
-
GT_LIBRARIES.includes(importPath)) {
|
|
679
|
-
// check for name field eg declareVar('test', { $name: 'test' })
|
|
680
|
-
if (node.arguments.length > 1 &&
|
|
681
|
-
t.isObjectExpression(node.arguments[1])) {
|
|
682
|
-
const name = node.arguments[1].properties
|
|
683
|
-
.filter((prop) => t.isObjectProperty(prop))
|
|
684
|
-
.find((prop) => t.isIdentifier(prop.key) && prop.key.name === '$name')?.value;
|
|
685
|
-
if (name) {
|
|
686
|
-
if (!t.isExpression(name)) {
|
|
687
|
-
warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
|
|
688
|
-
return null;
|
|
689
|
-
}
|
|
690
|
-
const staticResult = isStaticExpression(name);
|
|
691
|
-
if (!staticResult.isStatic) {
|
|
692
|
-
warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
|
|
693
|
-
return null;
|
|
694
|
-
}
|
|
695
|
-
return {
|
|
696
|
-
type: 'text',
|
|
697
|
-
text: declareVar('', { $name: staticResult.value }),
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return {
|
|
702
|
-
type: 'text',
|
|
703
|
-
text: declareVar(''),
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
const filePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
707
|
-
if (filePath && originalName) {
|
|
708
|
-
return resolveFunctionInFile(filePath, originalName, parsingOptions, warnings, errors);
|
|
709
|
-
}
|
|
710
|
-
return null;
|
|
711
|
-
}
|
|
712
|
-
// Resolve the function locally and get its return values
|
|
713
|
-
return resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings, errors);
|
|
714
|
-
}
|
|
715
|
-
// Handle parenthesized expressions
|
|
716
|
-
if (t.isParenthesizedExpression(node)) {
|
|
717
|
-
return parseStringExpression(node.expression, tPath, file, parsingOptions, warnings, errors);
|
|
718
|
-
}
|
|
719
|
-
// Handle unary expressions (e.g., -123)
|
|
720
|
-
if (t.isUnaryExpression(node)) {
|
|
721
|
-
let operator = '';
|
|
722
|
-
if (node.operator === '-') {
|
|
723
|
-
operator = node.operator;
|
|
724
|
-
}
|
|
725
|
-
if (t.isNumericLiteral(node.argument)) {
|
|
726
|
-
if (node.argument.value === 0) {
|
|
727
|
-
return { type: 'text', text: '0' };
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
return {
|
|
731
|
-
type: 'text',
|
|
732
|
-
text: operator + node.argument.value.toString(),
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
return null;
|
|
737
|
-
}
|
|
738
|
-
// Unsupported expression type
|
|
739
|
-
return null;
|
|
318
|
+
* Processes a string expression node and resolves any function calls within it
|
|
319
|
+
* This handles cases like:
|
|
320
|
+
* - "hello" (string literal)
|
|
321
|
+
* - "hello" + world() (binary expression with function call)
|
|
322
|
+
* - Math.random() > 0.5 ? "day" : "night" (conditional expression)
|
|
323
|
+
* - greeting() (function call that returns string or conditional)
|
|
324
|
+
*
|
|
325
|
+
* @param node - The AST node to process
|
|
326
|
+
* @param tPath - NodePath for scope resolution
|
|
327
|
+
* @param file - Current file path
|
|
328
|
+
* @param parsingOptions - Parsing configuration
|
|
329
|
+
* @param warnings - Set to collect warning messages
|
|
330
|
+
* @returns Node | null
|
|
331
|
+
*/
|
|
332
|
+
function parseStringExpression(node, tPath, file, parsingOptions, warnings, errors) {
|
|
333
|
+
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTSTypeAssertion(node)) return parseStringExpression(node.expression, tPath, file, parsingOptions, warnings, errors);
|
|
334
|
+
if (t.isStringLiteral(node)) return {
|
|
335
|
+
type: "text",
|
|
336
|
+
text: node.value
|
|
337
|
+
};
|
|
338
|
+
if (t.isNumericLiteral(node)) return {
|
|
339
|
+
type: "text",
|
|
340
|
+
text: String(node.value)
|
|
341
|
+
};
|
|
342
|
+
if (t.isBooleanLiteral(node)) return {
|
|
343
|
+
type: "text",
|
|
344
|
+
text: String(node.value)
|
|
345
|
+
};
|
|
346
|
+
if (t.isNullLiteral(node)) return {
|
|
347
|
+
type: "text",
|
|
348
|
+
text: "null"
|
|
349
|
+
};
|
|
350
|
+
if (t.isTemplateLiteral(node)) {
|
|
351
|
+
const parts = [];
|
|
352
|
+
for (let index = 0; index < node.quasis.length; index++) {
|
|
353
|
+
const quasi = node.quasis[index];
|
|
354
|
+
const text = quasi.value.cooked ?? quasi.value.raw ?? "";
|
|
355
|
+
if (text) parts.push({
|
|
356
|
+
type: "text",
|
|
357
|
+
text
|
|
358
|
+
});
|
|
359
|
+
const exprNode = node.expressions[index];
|
|
360
|
+
if (exprNode && t.isExpression(exprNode)) {
|
|
361
|
+
const result = parseStringExpression(exprNode, tPath, file, parsingOptions, warnings, errors);
|
|
362
|
+
if (result === null) return null;
|
|
363
|
+
parts.push(result);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (parts.length === 0) return {
|
|
367
|
+
type: "text",
|
|
368
|
+
text: ""
|
|
369
|
+
};
|
|
370
|
+
if (parts.length === 1) return parts[0];
|
|
371
|
+
return {
|
|
372
|
+
type: "sequence",
|
|
373
|
+
nodes: parts
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (t.isBinaryExpression(node) && node.operator === "+") {
|
|
377
|
+
if (!t.isExpression(node.left) || !t.isExpression(node.right)) return null;
|
|
378
|
+
const leftResult = parseStringExpression(node.left, tPath, file, parsingOptions, warnings, errors);
|
|
379
|
+
const rightResult = parseStringExpression(node.right, tPath, file, parsingOptions, warnings, errors);
|
|
380
|
+
if (leftResult === null || rightResult === null) return null;
|
|
381
|
+
return {
|
|
382
|
+
type: "sequence",
|
|
383
|
+
nodes: [leftResult, rightResult]
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
if (t.isConditionalExpression(node)) {
|
|
387
|
+
if (!t.isExpression(node.consequent) || !t.isExpression(node.alternate)) return null;
|
|
388
|
+
const consequentResult = parseStringExpression(node.consequent, tPath, file, parsingOptions, warnings, errors);
|
|
389
|
+
const alternateResult = parseStringExpression(node.alternate, tPath, file, parsingOptions, warnings, errors);
|
|
390
|
+
if (consequentResult === null || alternateResult === null) return null;
|
|
391
|
+
return {
|
|
392
|
+
type: "choice",
|
|
393
|
+
nodes: [consequentResult, alternateResult]
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (t.isIdentifier(node)) {
|
|
397
|
+
const binding = tPath.scope.getBinding(node.name);
|
|
398
|
+
if (!binding) return null;
|
|
399
|
+
if (binding.path.isVariableDeclarator() && binding.path.node.init) {
|
|
400
|
+
if (t.isObjectPattern(binding.path.node.id) || t.isArrayPattern(binding.path.node.id)) {
|
|
401
|
+
errors.push(warnDeriveDestructuringSync(file, node.name, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
const init = binding.path.node.init;
|
|
405
|
+
if (resolvingIdentifiers.has(init)) return null;
|
|
406
|
+
const declaration = binding.path.parentPath;
|
|
407
|
+
if (declaration?.isVariableDeclaration() && declaration.node.kind !== "const") {
|
|
408
|
+
warnings.add(warnDeriveNonConstVariableSync(file, node.name, declaration.node.kind, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
const unwrapped = unwrapTypeAnnotation(init);
|
|
412
|
+
if (t.isExpression(unwrapped)) {
|
|
413
|
+
resolvingIdentifiers.add(init);
|
|
414
|
+
try {
|
|
415
|
+
return parseStringExpression(unwrapped, binding.path, file, parsingOptions, warnings, errors);
|
|
416
|
+
} finally {
|
|
417
|
+
resolvingIdentifiers.delete(init);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (binding.path.isObjectProperty() || binding.path.isArrayPattern() || binding.path.isRestElement()) {
|
|
422
|
+
errors.push(warnDeriveDestructuringSync(file, node.name, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
if (t.isOptionalMemberExpression(node)) {
|
|
428
|
+
errors.push(warnDeriveOptionalChainingSync(file, generate(node).code, `${node.loc?.start?.line}:${node.loc?.start?.column}`));
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
if (t.isMemberExpression(node)) {
|
|
432
|
+
if (!t.isExpression(node.object)) return null;
|
|
433
|
+
const objectNodes = resolveToObjectNodes(node.object, tPath, file, parsingOptions, warnings, errors);
|
|
434
|
+
if (objectNodes.length === 0) return null;
|
|
435
|
+
const branches = [];
|
|
436
|
+
for (const { objExpr, tPath: objPath, file: objFile } of objectNodes) {
|
|
437
|
+
const entries = t.isArrayExpression(objExpr) ? collectArrayElements(objExpr, objPath, objFile, parsingOptions, errors) : collectObjectProperties(objExpr, objPath, objFile, parsingOptions, errors);
|
|
438
|
+
let staticLiteralKey = null;
|
|
439
|
+
if (node.computed && t.isStringLiteral(node.property)) staticLiteralKey = node.property.value;
|
|
440
|
+
else if (node.computed && t.isNumericLiteral(node.property)) staticLiteralKey = String(node.property.value);
|
|
441
|
+
const propName = staticLiteralKey ?? (!node.computed && t.isIdentifier(node.property) ? node.property.name : null);
|
|
442
|
+
const hasUnresolvableKeys = entries.some((e) => e.key === null);
|
|
443
|
+
if (propName !== null && !hasUnresolvableKeys) {
|
|
444
|
+
for (const entry of entries) if (entry.key === propName) {
|
|
445
|
+
const resolved = parseStringExpression(entry.value, objPath, objFile, parsingOptions, warnings, errors);
|
|
446
|
+
if (resolved) branches.push(resolved);
|
|
447
|
+
else errors.push(warnDeriveUnresolvableValueSync(objFile, propName, `${entry.value.loc?.start?.line}:${entry.value.loc?.start?.column}`));
|
|
448
|
+
}
|
|
449
|
+
} else for (const entry of entries) {
|
|
450
|
+
const resolved = parseStringExpression(entry.value, objPath, objFile, parsingOptions, warnings, errors);
|
|
451
|
+
if (resolved) branches.push(resolved);
|
|
452
|
+
else if (entry.key !== null) errors.push(warnDeriveUnresolvableValueSync(objFile, entry.key, `${entry.value.loc?.start?.line}:${entry.value.loc?.start?.column}`));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (branches.length === 0) return null;
|
|
456
|
+
if (branches.length === 1) return branches[0];
|
|
457
|
+
return {
|
|
458
|
+
type: "choice",
|
|
459
|
+
nodes: branches
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (t.isCallExpression(node) && t.isIdentifier(node.callee)) {
|
|
463
|
+
const functionName = node.callee.name;
|
|
464
|
+
const calleeBinding = tPath.scope.getBinding(functionName);
|
|
465
|
+
if (!calleeBinding) {
|
|
466
|
+
warnings.add(warnFunctionNotFoundSync(file, functionName, `${node.callee.loc?.start?.line}:${node.callee.loc?.start?.column}`));
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
const programPath = tPath.scope.getProgramParent().path;
|
|
470
|
+
const importedFunctionsMap = buildImportMap(programPath);
|
|
471
|
+
if (importedFunctionsMap.has(functionName)) {
|
|
472
|
+
let originalName;
|
|
473
|
+
if (calleeBinding.path.isImportSpecifier()) originalName = t.isIdentifier(calleeBinding.path.node.imported) ? calleeBinding.path.node.imported.name : calleeBinding.path.node.imported.value;
|
|
474
|
+
else if (calleeBinding.path.isImportDefaultSpecifier()) originalName = calleeBinding.path.node.local.name;
|
|
475
|
+
else if (calleeBinding.path.isImportNamespaceSpecifier()) originalName = calleeBinding.path.node.local.name;
|
|
476
|
+
const importPath = importedFunctionsMap.get(functionName);
|
|
477
|
+
if (originalName === "declareVar" && GT_LIBRARIES.includes(importPath)) {
|
|
478
|
+
if (node.arguments.length > 1 && t.isObjectExpression(node.arguments[1])) {
|
|
479
|
+
const name = node.arguments[1].properties.filter((prop) => t.isObjectProperty(prop)).find((prop) => t.isIdentifier(prop.key) && prop.key.name === "$name")?.value;
|
|
480
|
+
if (name) {
|
|
481
|
+
if (!t.isExpression(name)) {
|
|
482
|
+
warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
const staticResult = isStaticExpression(name);
|
|
486
|
+
if (!staticResult.isStatic) {
|
|
487
|
+
warnings.add(warnInvalidDeclareVarNameSync(file, generate(name).code, `${node.arguments[1].loc?.start?.line}:${node.arguments[1].loc?.start?.column}`));
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
type: "text",
|
|
492
|
+
text: declareVar("", { $name: staticResult.value })
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
type: "text",
|
|
498
|
+
text: declareVar("")
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
const filePath = resolveImportPath(file, importPath, parsingOptions, resolveImportPathCache);
|
|
502
|
+
if (filePath && originalName) return resolveFunctionInFile(filePath, originalName, parsingOptions, warnings, errors);
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
return resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings, errors);
|
|
506
|
+
}
|
|
507
|
+
if (t.isParenthesizedExpression(node)) return parseStringExpression(node.expression, tPath, file, parsingOptions, warnings, errors);
|
|
508
|
+
if (t.isUnaryExpression(node)) {
|
|
509
|
+
let operator = "";
|
|
510
|
+
if (node.operator === "-") operator = node.operator;
|
|
511
|
+
if (t.isNumericLiteral(node.argument)) if (node.argument.value === 0) return {
|
|
512
|
+
type: "text",
|
|
513
|
+
text: "0"
|
|
514
|
+
};
|
|
515
|
+
else return {
|
|
516
|
+
type: "text",
|
|
517
|
+
text: operator + node.argument.value.toString()
|
|
518
|
+
};
|
|
519
|
+
return null;
|
|
520
|
+
}
|
|
521
|
+
return null;
|
|
740
522
|
}
|
|
741
523
|
/**
|
|
742
|
-
|
|
743
|
-
|
|
524
|
+
* Resolves a function call by traversing its body and collecting return values
|
|
525
|
+
*/
|
|
744
526
|
function resolveFunctionCall(calleeBinding, tPath, file, parsingOptions, warnings, errors) {
|
|
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
|
-
const body = init.get('body');
|
|
780
|
-
// Handle expression body: () => "day"
|
|
781
|
-
if (body.isExpression()) {
|
|
782
|
-
const bodyResult = parseStringExpression(body.node, body, file, parsingOptions, warnings, errors);
|
|
783
|
-
if (bodyResult !== null) {
|
|
784
|
-
branches.push(bodyResult);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
// Handle block body: () => { return "day"; }
|
|
788
|
-
else if (body.isBlockStatement()) {
|
|
789
|
-
const arrowFunction = init.node;
|
|
790
|
-
body.traverse({
|
|
791
|
-
// Don't skip nested functions - let parseStringExpression handle function calls
|
|
792
|
-
ReturnStatement(returnPath) {
|
|
793
|
-
// Only process return statements that are direct children of this function
|
|
794
|
-
// Skip return statements from nested functions (they'll be handled when those functions are called)
|
|
795
|
-
const parentFunction = returnPath.getFunctionParent();
|
|
796
|
-
if (parentFunction?.node !== arrowFunction) {
|
|
797
|
-
// This return belongs to a nested function, skip it
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
const returnArg = returnPath.node.argument;
|
|
801
|
-
if (!returnArg || !t.isExpression(returnArg)) {
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings, errors);
|
|
805
|
-
if (returnResult !== null) {
|
|
806
|
-
branches.push(returnResult);
|
|
807
|
-
}
|
|
808
|
-
},
|
|
809
|
-
});
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
if (branches.length === 0) {
|
|
813
|
-
return null;
|
|
814
|
-
}
|
|
815
|
-
if (branches.length === 1) {
|
|
816
|
-
return branches[0];
|
|
817
|
-
}
|
|
818
|
-
return { type: 'choice', nodes: branches };
|
|
527
|
+
if (!calleeBinding) return null;
|
|
528
|
+
const bindingPath = calleeBinding.path;
|
|
529
|
+
const branches = [];
|
|
530
|
+
if (bindingPath.isFunctionDeclaration()) bindingPath.traverse({ ReturnStatement(returnPath) {
|
|
531
|
+
if (returnPath.getFunctionParent()?.node !== bindingPath.node) return;
|
|
532
|
+
const returnArg = returnPath.node.argument;
|
|
533
|
+
if (!returnArg || !t.isExpression(returnArg)) return;
|
|
534
|
+
const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings, errors);
|
|
535
|
+
if (returnResult !== null) branches.push(returnResult);
|
|
536
|
+
} });
|
|
537
|
+
else if (bindingPath.isVariableDeclarator()) {
|
|
538
|
+
const init = bindingPath.get("init");
|
|
539
|
+
if (!init.isArrowFunctionExpression()) return null;
|
|
540
|
+
const body = init.get("body");
|
|
541
|
+
if (body.isExpression()) {
|
|
542
|
+
const bodyResult = parseStringExpression(body.node, body, file, parsingOptions, warnings, errors);
|
|
543
|
+
if (bodyResult !== null) branches.push(bodyResult);
|
|
544
|
+
} else if (body.isBlockStatement()) {
|
|
545
|
+
const arrowFunction = init.node;
|
|
546
|
+
body.traverse({ ReturnStatement(returnPath) {
|
|
547
|
+
if (returnPath.getFunctionParent()?.node !== arrowFunction) return;
|
|
548
|
+
const returnArg = returnPath.node.argument;
|
|
549
|
+
if (!returnArg || !t.isExpression(returnArg)) return;
|
|
550
|
+
const returnResult = parseStringExpression(returnArg, returnPath, file, parsingOptions, warnings, errors);
|
|
551
|
+
if (returnResult !== null) branches.push(returnResult);
|
|
552
|
+
} });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (branches.length === 0) return null;
|
|
556
|
+
if (branches.length === 1) return branches[0];
|
|
557
|
+
return {
|
|
558
|
+
type: "choice",
|
|
559
|
+
nodes: branches
|
|
560
|
+
};
|
|
819
561
|
}
|
|
820
562
|
/**
|
|
821
|
-
|
|
822
|
-
|
|
563
|
+
* Resolves a function definition in an external file
|
|
564
|
+
*/
|
|
823
565
|
function resolveFunctionInFile(filePath, functionName, parsingOptions, warnings, errors) {
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
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
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
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
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
if (branches.length === 1) {
|
|
986
|
-
result = branches[0];
|
|
987
|
-
}
|
|
988
|
-
else if (branches.length > 1) {
|
|
989
|
-
result = { type: 'choice', nodes: branches };
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
// Handle string/numeric/boolean/null constants
|
|
993
|
-
else if (t.isStringLiteral(init)) {
|
|
994
|
-
result = { type: 'text', text: init.value };
|
|
995
|
-
}
|
|
996
|
-
else if (t.isNumericLiteral(init)) {
|
|
997
|
-
result = { type: 'text', text: String(init.value) };
|
|
998
|
-
}
|
|
999
|
-
else if (t.isBooleanLiteral(init)) {
|
|
1000
|
-
result = { type: 'text', text: String(init.value) };
|
|
1001
|
-
}
|
|
1002
|
-
// Handle template literals
|
|
1003
|
-
else if (t.isTemplateLiteral(init)) {
|
|
1004
|
-
const parts = [];
|
|
1005
|
-
let failed = false;
|
|
1006
|
-
for (let index = 0; index < init.quasis.length; index++) {
|
|
1007
|
-
const quasi = init.quasis[index];
|
|
1008
|
-
const text = quasi.value.cooked ?? quasi.value.raw ?? '';
|
|
1009
|
-
if (text) {
|
|
1010
|
-
parts.push({ type: 'text', text });
|
|
1011
|
-
}
|
|
1012
|
-
const exprNode = init.expressions[index];
|
|
1013
|
-
if (exprNode && t.isExpression(exprNode)) {
|
|
1014
|
-
const exprResult = parseStringExpression(exprNode, path, filePath, parsingOptions, warnings, errors);
|
|
1015
|
-
if (exprResult === null) {
|
|
1016
|
-
failed = true;
|
|
1017
|
-
break;
|
|
1018
|
-
}
|
|
1019
|
-
parts.push(exprResult);
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
if (!failed) {
|
|
1023
|
-
if (parts.length === 0) {
|
|
1024
|
-
result = { type: 'text', text: '' };
|
|
1025
|
-
}
|
|
1026
|
-
else if (parts.length === 1) {
|
|
1027
|
-
result = parts[0];
|
|
1028
|
-
}
|
|
1029
|
-
else {
|
|
1030
|
-
result = { type: 'sequence', nodes: parts };
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
// Handle object expressions (and `as const` / `satisfies`)
|
|
1035
|
-
else if (t.isObjectExpression(init) ||
|
|
1036
|
-
t.isObjectExpression(unwrapTypeAnnotation(init))) {
|
|
1037
|
-
const objExpr = unwrapTypeAnnotation(init);
|
|
1038
|
-
const branches = [];
|
|
1039
|
-
for (const prop of objExpr.properties) {
|
|
1040
|
-
if (!t.isObjectProperty(prop) || !t.isExpression(prop.value))
|
|
1041
|
-
continue;
|
|
1042
|
-
const resolved = parseStringExpression(prop.value, path, filePath, parsingOptions, warnings, errors);
|
|
1043
|
-
if (resolved)
|
|
1044
|
-
branches.push(resolved);
|
|
1045
|
-
}
|
|
1046
|
-
if (branches.length === 1)
|
|
1047
|
-
result = branches[0];
|
|
1048
|
-
else if (branches.length > 1)
|
|
1049
|
-
result = { type: 'choice', nodes: branches };
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
},
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
catch (error) {
|
|
1056
|
-
// File read or parse error - return null
|
|
1057
|
-
warnings.add(warnDeriveFunctionNoResultsSync(filePath, functionName, 'file read/parse error: ' + error));
|
|
1058
|
-
result = null;
|
|
1059
|
-
}
|
|
1060
|
-
// Cache the result
|
|
1061
|
-
processFunctionCache.set(cacheKey, result);
|
|
1062
|
-
return result;
|
|
566
|
+
const cacheKey = `${filePath}::${functionName}`;
|
|
567
|
+
if (processFunctionCache.has(cacheKey)) return processFunctionCache.get(cacheKey) ?? null;
|
|
568
|
+
let result = null;
|
|
569
|
+
try {
|
|
570
|
+
traverse(parse(fs.readFileSync(filePath, "utf8"), {
|
|
571
|
+
sourceType: "module",
|
|
572
|
+
plugins: ["jsx", "typescript"]
|
|
573
|
+
}), {
|
|
574
|
+
ExportAllDeclaration(path) {
|
|
575
|
+
if (result !== null) return;
|
|
576
|
+
if (t.isStringLiteral(path.node.source)) {
|
|
577
|
+
const reexportPath = path.node.source.value;
|
|
578
|
+
const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
|
|
579
|
+
if (resolvedPath) {
|
|
580
|
+
const reexportResult = resolveFunctionInFile(resolvedPath, functionName, parsingOptions, warnings, errors);
|
|
581
|
+
if (reexportResult) result = reexportResult;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
ExportNamedDeclaration(path) {
|
|
586
|
+
if (result !== null) return;
|
|
587
|
+
if (path.node.source && t.isStringLiteral(path.node.source)) {
|
|
588
|
+
if (path.node.specifiers.some((spec) => {
|
|
589
|
+
if (t.isExportSpecifier(spec)) return (t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value) === functionName;
|
|
590
|
+
return false;
|
|
591
|
+
})) {
|
|
592
|
+
const reexportPath = path.node.source.value;
|
|
593
|
+
const resolvedPath = resolveImportPath(filePath, reexportPath, parsingOptions, resolveImportPathCache);
|
|
594
|
+
if (resolvedPath) {
|
|
595
|
+
const specifier = path.node.specifiers.find((spec) => {
|
|
596
|
+
if (t.isExportSpecifier(spec)) return (t.isIdentifier(spec.exported) ? spec.exported.name : spec.exported.value) === functionName;
|
|
597
|
+
return false;
|
|
598
|
+
});
|
|
599
|
+
let originalName = functionName;
|
|
600
|
+
if (specifier && t.isExportSpecifier(specifier) && t.isIdentifier(specifier.local)) originalName = specifier.local.name;
|
|
601
|
+
const reexportResult = resolveFunctionInFile(resolvedPath, originalName, parsingOptions, warnings, errors);
|
|
602
|
+
if (reexportResult) result = reexportResult;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
FunctionDeclaration(path) {
|
|
608
|
+
if (path.node.id?.name === functionName && result === null) {
|
|
609
|
+
const branches = [];
|
|
610
|
+
path.traverse({
|
|
611
|
+
Function(innerPath) {
|
|
612
|
+
innerPath.skip();
|
|
613
|
+
},
|
|
614
|
+
ReturnStatement(returnPath) {
|
|
615
|
+
if (!t.isReturnStatement(returnPath.node)) return;
|
|
616
|
+
const returnArg = returnPath.node.argument;
|
|
617
|
+
if (!returnArg || !t.isExpression(returnArg)) return;
|
|
618
|
+
const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings, errors);
|
|
619
|
+
if (returnResult !== null) branches.push(returnResult);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
if (branches.length === 1) result = branches[0];
|
|
623
|
+
else if (branches.length > 1) result = {
|
|
624
|
+
type: "choice",
|
|
625
|
+
nodes: branches
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
VariableDeclarator(path) {
|
|
630
|
+
if (t.isIdentifier(path.node.id) && path.node.id.name === functionName && result === null) {
|
|
631
|
+
const init = path.node.init;
|
|
632
|
+
if (!init) return;
|
|
633
|
+
if (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)) {
|
|
634
|
+
const initPath = path.get("init");
|
|
635
|
+
if (!initPath.isArrowFunctionExpression() && !initPath.isFunctionExpression()) return;
|
|
636
|
+
const bodyPath = initPath.get("body");
|
|
637
|
+
const branches = [];
|
|
638
|
+
if (!Array.isArray(bodyPath) && t.isExpression(bodyPath.node)) {
|
|
639
|
+
const bodyResult = parseStringExpression(bodyPath.node, bodyPath, filePath, parsingOptions, warnings, errors);
|
|
640
|
+
if (bodyResult !== null) branches.push(bodyResult);
|
|
641
|
+
} else if (!Array.isArray(bodyPath) && t.isBlockStatement(bodyPath.node)) {
|
|
642
|
+
const arrowFunction = initPath.node;
|
|
643
|
+
bodyPath.traverse({
|
|
644
|
+
Function(innerPath) {
|
|
645
|
+
innerPath.skip();
|
|
646
|
+
},
|
|
647
|
+
ReturnStatement(returnPath) {
|
|
648
|
+
if (returnPath.getFunctionParent()?.node !== arrowFunction) return;
|
|
649
|
+
if (!t.isReturnStatement(returnPath.node)) return;
|
|
650
|
+
const returnArg = returnPath.node.argument;
|
|
651
|
+
if (!returnArg || !t.isExpression(returnArg)) return;
|
|
652
|
+
const returnResult = parseStringExpression(returnArg, returnPath, filePath, parsingOptions, warnings, errors);
|
|
653
|
+
if (returnResult !== null) branches.push(returnResult);
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
if (branches.length === 1) result = branches[0];
|
|
658
|
+
else if (branches.length > 1) result = {
|
|
659
|
+
type: "choice",
|
|
660
|
+
nodes: branches
|
|
661
|
+
};
|
|
662
|
+
} else if (t.isStringLiteral(init)) result = {
|
|
663
|
+
type: "text",
|
|
664
|
+
text: init.value
|
|
665
|
+
};
|
|
666
|
+
else if (t.isNumericLiteral(init)) result = {
|
|
667
|
+
type: "text",
|
|
668
|
+
text: String(init.value)
|
|
669
|
+
};
|
|
670
|
+
else if (t.isBooleanLiteral(init)) result = {
|
|
671
|
+
type: "text",
|
|
672
|
+
text: String(init.value)
|
|
673
|
+
};
|
|
674
|
+
else if (t.isTemplateLiteral(init)) {
|
|
675
|
+
const parts = [];
|
|
676
|
+
let failed = false;
|
|
677
|
+
for (let index = 0; index < init.quasis.length; index++) {
|
|
678
|
+
const quasi = init.quasis[index];
|
|
679
|
+
const text = quasi.value.cooked ?? quasi.value.raw ?? "";
|
|
680
|
+
if (text) parts.push({
|
|
681
|
+
type: "text",
|
|
682
|
+
text
|
|
683
|
+
});
|
|
684
|
+
const exprNode = init.expressions[index];
|
|
685
|
+
if (exprNode && t.isExpression(exprNode)) {
|
|
686
|
+
const exprResult = parseStringExpression(exprNode, path, filePath, parsingOptions, warnings, errors);
|
|
687
|
+
if (exprResult === null) {
|
|
688
|
+
failed = true;
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
parts.push(exprResult);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
if (!failed) if (parts.length === 0) result = {
|
|
695
|
+
type: "text",
|
|
696
|
+
text: ""
|
|
697
|
+
};
|
|
698
|
+
else if (parts.length === 1) result = parts[0];
|
|
699
|
+
else result = {
|
|
700
|
+
type: "sequence",
|
|
701
|
+
nodes: parts
|
|
702
|
+
};
|
|
703
|
+
} else if (t.isObjectExpression(init) || t.isObjectExpression(unwrapTypeAnnotation(init))) {
|
|
704
|
+
const objExpr = unwrapTypeAnnotation(init);
|
|
705
|
+
const branches = [];
|
|
706
|
+
for (const prop of objExpr.properties) {
|
|
707
|
+
if (!t.isObjectProperty(prop) || !t.isExpression(prop.value)) continue;
|
|
708
|
+
const resolved = parseStringExpression(prop.value, path, filePath, parsingOptions, warnings, errors);
|
|
709
|
+
if (resolved) branches.push(resolved);
|
|
710
|
+
}
|
|
711
|
+
if (branches.length === 1) result = branches[0];
|
|
712
|
+
else if (branches.length > 1) result = {
|
|
713
|
+
type: "choice",
|
|
714
|
+
nodes: branches
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
} catch (error) {
|
|
721
|
+
warnings.add(warnDeriveFunctionNoResultsSync(filePath, functionName, "file read/parse error: " + error));
|
|
722
|
+
result = null;
|
|
723
|
+
}
|
|
724
|
+
processFunctionCache.set(cacheKey, result);
|
|
725
|
+
return result;
|
|
1063
726
|
}
|
|
1064
727
|
/**
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
}
|
|
1079
|
-
// Handle SequenceNode - concatenate all parts
|
|
1080
|
-
if (typeof node === 'object' &&
|
|
1081
|
-
node !== null &&
|
|
1082
|
-
'type' in node &&
|
|
1083
|
-
node.type === 'sequence') {
|
|
1084
|
-
const partResults = node.nodes.map((n) => nodeToStrings(n));
|
|
1085
|
-
return cartesianProduct(partResults);
|
|
1086
|
-
}
|
|
1087
|
-
// Handle ChoiceNode - flatten all branches
|
|
1088
|
-
if (typeof node === 'object' &&
|
|
1089
|
-
node !== null &&
|
|
1090
|
-
'type' in node &&
|
|
1091
|
-
node.type === 'choice') {
|
|
1092
|
-
const allStrings = [];
|
|
1093
|
-
for (const branch of node.nodes) {
|
|
1094
|
-
allStrings.push(...nodeToStrings(branch));
|
|
1095
|
-
}
|
|
1096
|
-
return [...new Set(allStrings)]; // Deduplicate
|
|
1097
|
-
}
|
|
1098
|
-
return [];
|
|
728
|
+
* Converts a Node tree to an array of all possible string combinations
|
|
729
|
+
* This is a helper function for compatibility with existing code
|
|
730
|
+
*/
|
|
731
|
+
function nodeToStrings(node) {
|
|
732
|
+
if (node === null) return [];
|
|
733
|
+
if (typeof node === "object" && node !== null && "type" in node && node.type === "text") return [node.text];
|
|
734
|
+
if (typeof node === "object" && node !== null && "type" in node && node.type === "sequence") return cartesianProduct(node.nodes.map((n) => nodeToStrings(n)));
|
|
735
|
+
if (typeof node === "object" && node !== null && "type" in node && node.type === "choice") {
|
|
736
|
+
const allStrings = [];
|
|
737
|
+
for (const branch of node.nodes) allStrings.push(...nodeToStrings(branch));
|
|
738
|
+
return [...new Set(allStrings)];
|
|
739
|
+
}
|
|
740
|
+
return [];
|
|
1099
741
|
}
|
|
1100
742
|
/**
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
743
|
+
* Creates cartesian product of string arrays and concatenates them
|
|
744
|
+
* @example cartesianProduct([["Hello "], ["day", "night"]]) → ["Hello day", "Hello night"]
|
|
745
|
+
*/
|
|
1104
746
|
function cartesianProduct(arrays) {
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
for (let i = 1; i < arrays.length; i++) {
|
|
1115
|
-
const newResult = [];
|
|
1116
|
-
for (const prev of result) {
|
|
1117
|
-
for (const curr of arrays[i]) {
|
|
1118
|
-
newResult.push(prev + curr);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
result = newResult;
|
|
1122
|
-
}
|
|
1123
|
-
return result;
|
|
747
|
+
if (arrays.length === 0) return [];
|
|
748
|
+
if (arrays.length === 1) return arrays[0];
|
|
749
|
+
let result = arrays[0];
|
|
750
|
+
for (let i = 1; i < arrays.length; i++) {
|
|
751
|
+
const newResult = [];
|
|
752
|
+
for (const prev of result) for (const curr of arrays[i]) newResult.push(prev + curr);
|
|
753
|
+
result = newResult;
|
|
754
|
+
}
|
|
755
|
+
return result;
|
|
1124
756
|
}
|
|
757
|
+
//#endregion
|
|
758
|
+
export { nodeToStrings, parseStringExpression };
|
|
759
|
+
|
|
760
|
+
//# sourceMappingURL=parseString.js.map
|