@wyw-in-js/transform 0.1.0
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/LICENSE +21 -0
- package/esm/babel.js +2 -0
- package/esm/babel.js.map +1 -0
- package/esm/cache.js +80 -0
- package/esm/cache.js.map +1 -0
- package/esm/debug/fileReporter.js +144 -0
- package/esm/debug/fileReporter.js.map +1 -0
- package/esm/evaluators/index.js +14 -0
- package/esm/evaluators/index.js.map +1 -0
- package/esm/index.js +24 -0
- package/esm/index.js.map +1 -0
- package/esm/module.js +316 -0
- package/esm/module.js.map +1 -0
- package/esm/options/babel-merge.d.js +2 -0
- package/esm/options/babel-merge.d.js.map +1 -0
- package/esm/options/buildOptions.js +28 -0
- package/esm/options/buildOptions.js.map +1 -0
- package/esm/options/loadBabelOptions.js +24 -0
- package/esm/options/loadBabelOptions.js.map +1 -0
- package/esm/plugins/babel-transform.js +53 -0
- package/esm/plugins/babel-transform.js.map +1 -0
- package/esm/plugins/collector.js +66 -0
- package/esm/plugins/collector.js.map +1 -0
- package/esm/plugins/dynamic-import.js +28 -0
- package/esm/plugins/dynamic-import.js.map +1 -0
- package/esm/plugins/preeval.js +75 -0
- package/esm/plugins/preeval.js.map +1 -0
- package/esm/plugins/shaker.js +296 -0
- package/esm/plugins/shaker.js.map +1 -0
- package/esm/shaker.js +50 -0
- package/esm/shaker.js.map +1 -0
- package/esm/transform/BaseEntrypoint.js +164 -0
- package/esm/transform/BaseEntrypoint.js.map +1 -0
- package/esm/transform/Entrypoint.helpers.js +168 -0
- package/esm/transform/Entrypoint.helpers.js.map +1 -0
- package/esm/transform/Entrypoint.js +212 -0
- package/esm/transform/Entrypoint.js.map +1 -0
- package/esm/transform/Entrypoint.types.js +2 -0
- package/esm/transform/Entrypoint.types.js.map +1 -0
- package/esm/transform/EvaluatedEntrypoint.js +6 -0
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -0
- package/esm/transform/actions/AbortError.js +8 -0
- package/esm/transform/actions/AbortError.js.map +1 -0
- package/esm/transform/actions/BaseAction.js +134 -0
- package/esm/transform/actions/BaseAction.js.map +1 -0
- package/esm/transform/actions/UnprocessedEntrypointError.js +8 -0
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -0
- package/esm/transform/actions/actionRunner.js +73 -0
- package/esm/transform/actions/actionRunner.js.map +1 -0
- package/esm/transform/actions/types.js +2 -0
- package/esm/transform/actions/types.js.map +1 -0
- package/esm/transform/generators/baseProcessingHandlers.js +22 -0
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -0
- package/esm/transform/generators/collect.js +58 -0
- package/esm/transform/generators/collect.js.map +1 -0
- package/esm/transform/generators/evalFile.js +50 -0
- package/esm/transform/generators/evalFile.js.map +1 -0
- package/esm/transform/generators/explodeReexports.js +63 -0
- package/esm/transform/generators/explodeReexports.js.map +1 -0
- package/esm/transform/generators/extract.js +120 -0
- package/esm/transform/generators/extract.js.map +1 -0
- package/esm/transform/generators/getExports.js +73 -0
- package/esm/transform/generators/getExports.js.map +1 -0
- package/esm/transform/generators/index.js +13 -0
- package/esm/transform/generators/index.js.map +1 -0
- package/esm/transform/generators/processEntrypoint.js +43 -0
- package/esm/transform/generators/processEntrypoint.js.map +1 -0
- package/esm/transform/generators/processImports.js +23 -0
- package/esm/transform/generators/processImports.js.map +1 -0
- package/esm/transform/generators/resolveImports.js +148 -0
- package/esm/transform/generators/resolveImports.js.map +1 -0
- package/esm/transform/generators/transform.js +117 -0
- package/esm/transform/generators/transform.js.map +1 -0
- package/esm/transform/generators/workflow.js +82 -0
- package/esm/transform/generators/workflow.js.map +1 -0
- package/esm/transform/helpers/loadLinariaOptions.js +66 -0
- package/esm/transform/helpers/loadLinariaOptions.js.map +1 -0
- package/esm/transform/helpers/withDefaultServices.js +21 -0
- package/esm/transform/helpers/withDefaultServices.js.map +1 -0
- package/esm/transform/rootLog.js +3 -0
- package/esm/transform/rootLog.js.map +1 -0
- package/esm/transform/types.js +2 -0
- package/esm/transform/types.js.map +1 -0
- package/esm/transform.js +121 -0
- package/esm/transform.js.map +1 -0
- package/esm/types.js +2 -0
- package/esm/types.js.map +1 -0
- package/esm/utils/EventEmitter.js +52 -0
- package/esm/utils/EventEmitter.js.map +1 -0
- package/esm/utils/ShakerMetadata.js +2 -0
- package/esm/utils/ShakerMetadata.js.map +1 -0
- package/esm/utils/TransformMetadata.js +11 -0
- package/esm/utils/TransformMetadata.js.map +1 -0
- package/esm/utils/addIdentifierToLinariaPreval.js +68 -0
- package/esm/utils/addIdentifierToLinariaPreval.js.map +1 -0
- package/esm/utils/collectExportsAndImports.js +974 -0
- package/esm/utils/collectExportsAndImports.js.map +1 -0
- package/esm/utils/collectTemplateDependencies.js +219 -0
- package/esm/utils/collectTemplateDependencies.js.map +1 -0
- package/esm/utils/createId.js +6 -0
- package/esm/utils/createId.js.map +1 -0
- package/esm/utils/dispose-polyfill.js +6 -0
- package/esm/utils/dispose-polyfill.js.map +1 -0
- package/esm/utils/findIdentifiers.js +62 -0
- package/esm/utils/findIdentifiers.js.map +1 -0
- package/esm/utils/findPackageJSON.js +22 -0
- package/esm/utils/findPackageJSON.js.map +1 -0
- package/esm/utils/getFileIdx.js +10 -0
- package/esm/utils/getFileIdx.js.map +1 -0
- package/esm/utils/getPluginKey.js +13 -0
- package/esm/utils/getPluginKey.js.map +1 -0
- package/esm/utils/getScope.js +6 -0
- package/esm/utils/getScope.js.map +1 -0
- package/esm/utils/getSource.js +15 -0
- package/esm/utils/getSource.js.map +1 -0
- package/esm/utils/getTagProcessor.js +304 -0
- package/esm/utils/getTagProcessor.js.map +1 -0
- package/esm/utils/getVisitorKeys.js +5 -0
- package/esm/utils/getVisitorKeys.js.map +1 -0
- package/esm/utils/hasLinariaPreval.js +7 -0
- package/esm/utils/hasLinariaPreval.js.map +1 -0
- package/esm/utils/isExports.js +22 -0
- package/esm/utils/isExports.js.map +1 -0
- package/esm/utils/isGlobal.js +6 -0
- package/esm/utils/isGlobal.js.map +1 -0
- package/esm/utils/isNode.js +2 -0
- package/esm/utils/isNode.js.map +1 -0
- package/esm/utils/isNodePath.js +4 -0
- package/esm/utils/isNodePath.js.map +1 -0
- package/esm/utils/isNotNull.js +4 -0
- package/esm/utils/isNotNull.js.map +1 -0
- package/esm/utils/isRemoved.js +46 -0
- package/esm/utils/isRemoved.js.map +1 -0
- package/esm/utils/isRequire.js +13 -0
- package/esm/utils/isRequire.js.map +1 -0
- package/esm/utils/isSerializable.js +13 -0
- package/esm/utils/isSerializable.js.map +1 -0
- package/esm/utils/isTypedNode.js +6 -0
- package/esm/utils/isTypedNode.js.map +1 -0
- package/esm/utils/isUnnecessaryReactCall.js +72 -0
- package/esm/utils/isUnnecessaryReactCall.js.map +1 -0
- package/esm/utils/peek.js +2 -0
- package/esm/utils/peek.js.map +1 -0
- package/esm/utils/processTemplateExpression.js +11 -0
- package/esm/utils/processTemplateExpression.js.map +1 -0
- package/esm/utils/removeDangerousCode.js +127 -0
- package/esm/utils/removeDangerousCode.js.map +1 -0
- package/esm/utils/scopeHelpers.js +514 -0
- package/esm/utils/scopeHelpers.js.map +1 -0
- package/esm/utils/traversalCache.js +28 -0
- package/esm/utils/traversalCache.js.map +1 -0
- package/esm/utils/unwrapSequence.js +14 -0
- package/esm/utils/unwrapSequence.js.map +1 -0
- package/esm/utils/valueToLiteral.js +59 -0
- package/esm/utils/valueToLiteral.js.map +1 -0
- package/esm/utils/visitors/JSXElementsRemover.js +51 -0
- package/esm/utils/visitors/JSXElementsRemover.js.map +1 -0
- package/esm/vm/createVmContext.js +72 -0
- package/esm/vm/createVmContext.js.map +1 -0
- package/esm/vm/process.js +29 -0
- package/esm/vm/process.js.map +1 -0
- package/lib/babel.js +2 -0
- package/lib/babel.js.map +1 -0
- package/lib/cache.js +87 -0
- package/lib/cache.js.map +1 -0
- package/lib/debug/fileReporter.js +153 -0
- package/lib/debug/fileReporter.js.map +1 -0
- package/lib/evaluators/index.js +20 -0
- package/lib/evaluators/index.js.map +1 -0
- package/lib/index.js +225 -0
- package/lib/index.js.map +1 -0
- package/lib/module.js +327 -0
- package/lib/module.js.map +1 -0
- package/lib/options/babel-merge.d.js +2 -0
- package/lib/options/babel-merge.d.js.map +1 -0
- package/lib/options/buildOptions.js +35 -0
- package/lib/options/buildOptions.js.map +1 -0
- package/lib/options/loadBabelOptions.js +31 -0
- package/lib/options/loadBabelOptions.js.map +1 -0
- package/lib/plugins/babel-transform.js +60 -0
- package/lib/plugins/babel-transform.js.map +1 -0
- package/lib/plugins/collector.js +76 -0
- package/lib/plugins/collector.js.map +1 -0
- package/lib/plugins/dynamic-import.js +34 -0
- package/lib/plugins/dynamic-import.js.map +1 -0
- package/lib/plugins/preeval.js +82 -0
- package/lib/plugins/preeval.js.map +1 -0
- package/lib/plugins/shaker.js +303 -0
- package/lib/plugins/shaker.js.map +1 -0
- package/lib/shaker.js +58 -0
- package/lib/shaker.js.map +1 -0
- package/lib/transform/BaseEntrypoint.js +175 -0
- package/lib/transform/BaseEntrypoint.js.map +1 -0
- package/lib/transform/Entrypoint.helpers.js +182 -0
- package/lib/transform/Entrypoint.helpers.js.map +1 -0
- package/lib/transform/Entrypoint.js +226 -0
- package/lib/transform/Entrypoint.js.map +1 -0
- package/lib/transform/Entrypoint.types.js +2 -0
- package/lib/transform/Entrypoint.types.js.map +1 -0
- package/lib/transform/EvaluatedEntrypoint.js +13 -0
- package/lib/transform/EvaluatedEntrypoint.js.map +1 -0
- package/lib/transform/actions/AbortError.js +16 -0
- package/lib/transform/actions/AbortError.js.map +1 -0
- package/lib/transform/actions/BaseAction.js +144 -0
- package/lib/transform/actions/BaseAction.js.map +1 -0
- package/lib/transform/actions/UnprocessedEntrypointError.js +16 -0
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +1 -0
- package/lib/transform/actions/actionRunner.js +82 -0
- package/lib/transform/actions/actionRunner.js.map +1 -0
- package/lib/transform/actions/types.js +2 -0
- package/lib/transform/actions/types.js.map +1 -0
- package/lib/transform/generators/baseProcessingHandlers.js +27 -0
- package/lib/transform/generators/baseProcessingHandlers.js.map +1 -0
- package/lib/transform/generators/collect.js +66 -0
- package/lib/transform/generators/collect.js.map +1 -0
- package/lib/transform/generators/evalFile.js +57 -0
- package/lib/transform/generators/evalFile.js.map +1 -0
- package/lib/transform/generators/explodeReexports.js +70 -0
- package/lib/transform/generators/explodeReexports.js.map +1 -0
- package/lib/transform/generators/extract.js +128 -0
- package/lib/transform/generators/extract.js.map +1 -0
- package/lib/transform/generators/getExports.js +80 -0
- package/lib/transform/generators/getExports.js.map +1 -0
- package/lib/transform/generators/index.js +19 -0
- package/lib/transform/generators/index.js.map +1 -0
- package/lib/transform/generators/processEntrypoint.js +49 -0
- package/lib/transform/generators/processEntrypoint.js.map +1 -0
- package/lib/transform/generators/processImports.js +29 -0
- package/lib/transform/generators/processImports.js.map +1 -0
- package/lib/transform/generators/resolveImports.js +158 -0
- package/lib/transform/generators/resolveImports.js.map +1 -0
- package/lib/transform/generators/transform.js +130 -0
- package/lib/transform/generators/transform.js.map +1 -0
- package/lib/transform/generators/workflow.js +90 -0
- package/lib/transform/generators/workflow.js.map +1 -0
- package/lib/transform/helpers/loadLinariaOptions.js +73 -0
- package/lib/transform/helpers/loadLinariaOptions.js.map +1 -0
- package/lib/transform/helpers/withDefaultServices.js +30 -0
- package/lib/transform/helpers/withDefaultServices.js.map +1 -0
- package/lib/transform/rootLog.js +9 -0
- package/lib/transform/rootLog.js.map +1 -0
- package/lib/transform/types.js +8 -0
- package/lib/transform/types.js.map +1 -0
- package/lib/transform.js +128 -0
- package/lib/transform.js.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/EventEmitter.js +61 -0
- package/lib/utils/EventEmitter.js.map +1 -0
- package/lib/utils/ShakerMetadata.js +9 -0
- package/lib/utils/ShakerMetadata.js.map +1 -0
- package/lib/utils/TransformMetadata.js +19 -0
- package/lib/utils/TransformMetadata.js.map +1 -0
- package/lib/utils/addIdentifierToLinariaPreval.js +75 -0
- package/lib/utils/addIdentifierToLinariaPreval.js.map +1 -0
- package/lib/utils/collectExportsAndImports.js +990 -0
- package/lib/utils/collectExportsAndImports.js.map +1 -0
- package/lib/utils/collectTemplateDependencies.js +233 -0
- package/lib/utils/collectTemplateDependencies.js.map +1 -0
- package/lib/utils/createId.js +13 -0
- package/lib/utils/createId.js.map +1 -0
- package/lib/utils/dispose-polyfill.js +9 -0
- package/lib/utils/dispose-polyfill.js.map +1 -0
- package/lib/utils/findIdentifiers.js +73 -0
- package/lib/utils/findIdentifiers.js.map +1 -0
- package/lib/utils/findPackageJSON.js +29 -0
- package/lib/utils/findPackageJSON.js.map +1 -0
- package/lib/utils/getFileIdx.js +16 -0
- package/lib/utils/getFileIdx.js.map +1 -0
- package/lib/utils/getPluginKey.js +21 -0
- package/lib/utils/getPluginKey.js.map +1 -0
- package/lib/utils/getScope.js +12 -0
- package/lib/utils/getScope.js.map +1 -0
- package/lib/utils/getSource.js +24 -0
- package/lib/utils/getSource.js.map +1 -0
- package/lib/utils/getTagProcessor.js +318 -0
- package/lib/utils/getTagProcessor.js.map +1 -0
- package/lib/utils/getVisitorKeys.js +11 -0
- package/lib/utils/getVisitorKeys.js.map +1 -0
- package/lib/utils/hasLinariaPreval.js +13 -0
- package/lib/utils/hasLinariaPreval.js.map +1 -0
- package/lib/utils/isExports.js +27 -0
- package/lib/utils/isExports.js.map +1 -0
- package/lib/utils/isGlobal.js +13 -0
- package/lib/utils/isGlobal.js.map +1 -0
- package/lib/utils/isNode.js +9 -0
- package/lib/utils/isNode.js.map +1 -0
- package/lib/utils/isNodePath.js +10 -0
- package/lib/utils/isNodePath.js.map +1 -0
- package/lib/utils/isNotNull.js +10 -0
- package/lib/utils/isNotNull.js.map +1 -0
- package/lib/utils/isRemoved.js +52 -0
- package/lib/utils/isRemoved.js.map +1 -0
- package/lib/utils/isRequire.js +18 -0
- package/lib/utils/isRequire.js.map +1 -0
- package/lib/utils/isSerializable.js +19 -0
- package/lib/utils/isSerializable.js.map +1 -0
- package/lib/utils/isTypedNode.js +13 -0
- package/lib/utils/isTypedNode.js.map +1 -0
- package/lib/utils/isUnnecessaryReactCall.js +81 -0
- package/lib/utils/isUnnecessaryReactCall.js.map +1 -0
- package/lib/utils/peek.js +9 -0
- package/lib/utils/peek.js.map +1 -0
- package/lib/utils/processTemplateExpression.js +18 -0
- package/lib/utils/processTemplateExpression.js.map +1 -0
- package/lib/utils/removeDangerousCode.js +134 -0
- package/lib/utils/removeDangerousCode.js.map +1 -0
- package/lib/utils/scopeHelpers.js +544 -0
- package/lib/utils/scopeHelpers.js.map +1 -0
- package/lib/utils/traversalCache.js +38 -0
- package/lib/utils/traversalCache.js.map +1 -0
- package/lib/utils/unwrapSequence.js +20 -0
- package/lib/utils/unwrapSequence.js.map +1 -0
- package/lib/utils/valueToLiteral.js +65 -0
- package/lib/utils/valueToLiteral.js.map +1 -0
- package/lib/utils/visitors/JSXElementsRemover.js +57 -0
- package/lib/utils/visitors/JSXElementsRemover.js.map +1 -0
- package/lib/vm/createVmContext.js +80 -0
- package/lib/vm/createVmContext.js.map +1 -0
- package/lib/vm/process.js +38 -0
- package/lib/vm/process.js.map +1 -0
- package/package.json +63 -0
- package/types/babel.d.ts +2 -0
- package/types/babel.js +2 -0
- package/types/cache.d.ts +24 -0
- package/types/cache.js +85 -0
- package/types/debug/fileReporter.d.ts +27 -0
- package/types/debug/fileReporter.js +151 -0
- package/types/evaluators/index.d.ts +10 -0
- package/types/evaluators/index.js +15 -0
- package/types/index.d.ts +30 -0
- package/types/index.js +69 -0
- package/types/module.d.ts +62 -0
- package/types/module.js +318 -0
- package/types/options/buildOptions.d.ts +7 -0
- package/types/options/buildOptions.js +35 -0
- package/types/options/loadBabelOptions.d.ts +3 -0
- package/types/options/loadBabelOptions.js +27 -0
- package/types/plugins/babel-transform.d.ts +4 -0
- package/types/plugins/babel-transform.js +49 -0
- package/types/plugins/collector.d.ts +16 -0
- package/types/plugins/collector.js +67 -0
- package/types/plugins/dynamic-import.d.ts +6 -0
- package/types/plugins/dynamic-import.js +32 -0
- package/types/plugins/preeval.d.ts +16 -0
- package/types/plugins/preeval.js +69 -0
- package/types/plugins/shaker.d.ts +11 -0
- package/types/plugins/shaker.js +299 -0
- package/types/shaker.d.ts +3 -0
- package/types/shaker.js +64 -0
- package/types/transform/BaseEntrypoint.d.ts +23 -0
- package/types/transform/BaseEntrypoint.js +182 -0
- package/types/transform/Entrypoint.d.ts +50 -0
- package/types/transform/Entrypoint.helpers.d.ts +14 -0
- package/types/transform/Entrypoint.helpers.js +169 -0
- package/types/transform/Entrypoint.js +223 -0
- package/types/transform/Entrypoint.types.d.ts +23 -0
- package/types/transform/Entrypoint.types.js +2 -0
- package/types/transform/EvaluatedEntrypoint.d.ts +16 -0
- package/types/transform/EvaluatedEntrypoint.js +9 -0
- package/types/transform/actions/AbortError.d.ts +4 -0
- package/types/transform/actions/AbortError.js +12 -0
- package/types/transform/actions/BaseAction.d.ts +40 -0
- package/types/transform/actions/BaseAction.js +149 -0
- package/types/transform/actions/UnprocessedEntrypointError.d.ts +6 -0
- package/types/transform/actions/UnprocessedEntrypointError.js +13 -0
- package/types/transform/actions/actionRunner.d.ts +4 -0
- package/types/transform/actions/actionRunner.js +86 -0
- package/types/transform/actions/types.d.ts +15 -0
- package/types/transform/actions/types.js +2 -0
- package/types/transform/generators/baseProcessingHandlers.d.ts +17 -0
- package/types/transform/generators/baseProcessingHandlers.js +23 -0
- package/types/transform/generators/collect.d.ts +6 -0
- package/types/transform/generators/collect.js +57 -0
- package/types/transform/generators/evalFile.d.ts +6 -0
- package/types/transform/generators/evalFile.js +56 -0
- package/types/transform/generators/explodeReexports.d.ts +7 -0
- package/types/transform/generators/explodeReexports.js +67 -0
- package/types/transform/generators/extract.d.ts +8 -0
- package/types/transform/generators/extract.js +116 -0
- package/types/transform/generators/getExports.d.ts +8 -0
- package/types/transform/generators/getExports.js +65 -0
- package/types/transform/generators/index.d.ts +15 -0
- package/types/transform/generators/index.js +15 -0
- package/types/transform/generators/processEntrypoint.d.ts +9 -0
- package/types/transform/generators/processEntrypoint.js +88 -0
- package/types/transform/generators/processImports.d.ts +5 -0
- package/types/transform/generators/processImports.js +21 -0
- package/types/transform/generators/resolveImports.d.ts +9 -0
- package/types/transform/generators/resolveImports.js +124 -0
- package/types/transform/generators/transform.d.ts +17 -0
- package/types/transform/generators/transform.js +115 -0
- package/types/transform/generators/workflow.d.ts +7 -0
- package/types/transform/generators/workflow.js +77 -0
- package/types/transform/helpers/loadLinariaOptions.d.ts +6 -0
- package/types/transform/helpers/loadLinariaOptions.js +86 -0
- package/types/transform/helpers/withDefaultServices.d.ts +5 -0
- package/types/transform/helpers/withDefaultServices.js +40 -0
- package/types/transform/rootLog.d.ts +3 -0
- package/types/transform/rootLog.js +5 -0
- package/types/transform/types.d.ts +137 -0
- package/types/transform/types.js +4 -0
- package/types/transform.d.ts +20 -0
- package/types/transform.js +121 -0
- package/types/types.d.ts +72 -0
- package/types/types.js +5 -0
- package/types/utils/EventEmitter.d.ts +58 -0
- package/types/utils/EventEmitter.js +61 -0
- package/types/utils/ShakerMetadata.d.ts +7 -0
- package/types/utils/ShakerMetadata.js +5 -0
- package/types/utils/TransformMetadata.d.ts +13 -0
- package/types/utils/TransformMetadata.js +17 -0
- package/types/utils/addIdentifierToLinariaPreval.d.ts +4 -0
- package/types/utils/addIdentifierToLinariaPreval.js +75 -0
- package/types/utils/collectExportsAndImports.d.ts +31 -0
- package/types/utils/collectExportsAndImports.js +962 -0
- package/types/utils/collectTemplateDependencies.d.ts +17 -0
- package/types/utils/collectTemplateDependencies.js +212 -0
- package/types/utils/createId.d.ts +2 -0
- package/types/utils/createId.js +9 -0
- package/types/utils/dispose-polyfill.d.ts +0 -0
- package/types/utils/dispose-polyfill.js +5 -0
- package/types/utils/findIdentifiers.d.ts +6 -0
- package/types/utils/findIdentifiers.js +68 -0
- package/types/utils/findPackageJSON.d.ts +1 -0
- package/types/utils/findPackageJSON.js +29 -0
- package/types/utils/getFileIdx.d.ts +1 -0
- package/types/utils/getFileIdx.js +13 -0
- package/types/utils/getPluginKey.d.ts +2 -0
- package/types/utils/getPluginKey.js +16 -0
- package/types/utils/getScope.d.ts +2 -0
- package/types/utils/getScope.js +11 -0
- package/types/utils/getSource.d.ts +2 -0
- package/types/utils/getSource.js +22 -0
- package/types/utils/getTagProcessor.d.ts +6 -0
- package/types/utils/getTagProcessor.js +315 -0
- package/types/utils/getVisitorKeys.d.ts +5 -0
- package/types/utils/getVisitorKeys.js +8 -0
- package/types/utils/hasLinariaPreval.d.ts +4 -0
- package/types/utils/hasLinariaPreval.js +9 -0
- package/types/utils/isExports.d.ts +6 -0
- package/types/utils/isExports.js +20 -0
- package/types/utils/isGlobal.d.ts +2 -0
- package/types/utils/isGlobal.js +9 -0
- package/types/utils/isNode.d.ts +2 -0
- package/types/utils/isNode.js +7 -0
- package/types/utils/isNodePath.d.ts +3 -0
- package/types/utils/isNodePath.js +7 -0
- package/types/utils/isNotNull.d.ts +1 -0
- package/types/utils/isNotNull.js +7 -0
- package/types/utils/isRemoved.d.ts +5 -0
- package/types/utils/isRemoved.js +42 -0
- package/types/utils/isRequire.d.ts +6 -0
- package/types/utils/isRequire.js +15 -0
- package/types/utils/isSerializable.d.ts +2 -0
- package/types/utils/isSerializable.js +18 -0
- package/types/utils/isTypedNode.d.ts +5 -0
- package/types/utils/isTypedNode.js +9 -0
- package/types/utils/isUnnecessaryReactCall.d.ts +3 -0
- package/types/utils/isUnnecessaryReactCall.js +76 -0
- package/types/utils/peek.d.ts +1 -0
- package/types/utils/peek.js +5 -0
- package/types/utils/processTemplateExpression.d.ts +5 -0
- package/types/utils/processTemplateExpression.js +17 -0
- package/types/utils/removeDangerousCode.d.ts +3 -0
- package/types/utils/removeDangerousCode.js +144 -0
- package/types/utils/scopeHelpers.d.ts +12 -0
- package/types/utils/scopeHelpers.js +568 -0
- package/types/utils/traversalCache.d.ts +5 -0
- package/types/utils/traversalCache.js +36 -0
- package/types/utils/unwrapSequence.d.ts +8 -0
- package/types/utils/unwrapSequence.js +17 -0
- package/types/utils/valueToLiteral.d.ts +3 -0
- package/types/utils/valueToLiteral.js +64 -0
- package/types/utils/visitors/JSXElementsRemover.d.ts +3 -0
- package/types/utils/visitors/JSXElementsRemover.js +52 -0
- package/types/vm/createVmContext.d.ts +7 -0
- package/types/vm/createVmContext.js +92 -0
- package/types/vm/process.d.ts +25 -0
- package/types/vm/process.js +32 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectExportsAndImports.js","names":["_shared","require","_getScope","_isExports","_isNotNull","_isRequire","_isTypedNode","_traversalCache","sideEffectImport","item","imported","exports","explicitImport","getValue","node","type","name","value","isType","p","importKind","exportKind","collectors","ImportSpecifier","path","source","get","local","ImportDefaultSpecifier","ImportNamespaceSpecifier","unfoldNamespaceImport","collectFromImportDeclaration","state","specifiers","length","imports","push","forEach","specifier","isImportSpecifier","collector","getAncestorsWhile","cond","result","current","parentPath","whatIsDestructed","objectPattern","destructedProps","traverse","Identifier","identifier","isBindingIdentifier","parent","isObjectProperty","chain","filter","isTypedNode","map","key","isIdentifier","isNotNull","reverse","what","as","isRestElement","argument","debug","logger","extend","importFromVariableDeclarator","isSync","id","isObjectPattern","findIIFE","isCallExpression","isFunctionExpression","exportFromVariableDeclarator","init","binding","getScope","getBinding","iife","referencePaths","constantViolations","find","isExpression","reduce","acc","destructed","collectFromDynamicImport","callExpression","sourcePath","isStringLiteral","container","isAwaited","isAwaitExpression","isVariableDeclarator","prop","getCalleeName","callee","isMemberExpression","property","undefined","getImportExportTypeByInteropFunction","startsWith","isAlreadyProcessed","collectFromRequire","isRequire","processedRequires","has","add","reexports","exported","variableDeclarator","unfolded","isExpressionStatement","collectFromVariableDeclarator","found","identifierPath","skip","isChainOfVoidAssignment","right","isUnaryExpression","operator","isAssignmentExpression","getReturnValue","params","body","_body$get","returnStatement","isReturnStatement","getGetterValueFromDescriptor","descriptor","props","getter","isArrowFunctionExpression","valueProp","valueValue","addExport","getRelatedImport","object","objectBinding","scope","i","some","isAncestor","computed","import","relatedImport","collectFromExports","isExports","memberExpression","exportName","saveRef","exportRefs","set","assignmentExpression","left","isEsModule","matchesPattern","obj","isObjectExpression","collectFromRequireOrExports","importItem","referenced","referencePath","_binding$referencePat","ancestor","isTSType","isFlowType","listKey","importType","isExportSpecifier","isExportDefaultDeclaration","collectFromExportAllDeclaration","_path$get","collectFromExportSpecifier","isExportDefaultSpecifier","isExportNamespaceSpecifier","collectFromExportNamedDeclaration","_path$get2","declaration","isVariableDeclaration","declarator","isTSEnumDeclaration","isFunctionDeclaration","isClassDeclaration","collectFromExportDefaultDeclaration","default","collectFromAssignmentExpression","_right$get","collectFromExportStarCall","_requireCall$get","requireCall","collectFromMap","properties","isFunction","returnValue","collectFromEsbuildExportCall","sourceExports","collectFromEsbuildReExportCall","_requireCall$get2","collectFromSwcExportCall","collectFromCallExpression","maybeExportStart","collectExportsAndImports","cacheMode","localState","deadExports","Map","sourceType","WeakSet","cache","getTraversalCache","_cache$get","AssignmentExpression","CallExpression","ExportAllDeclaration","ExportDefaultDeclaration","ExportNamedDeclaration","ImportDeclaration","Import","VariableDeclarator"],"sources":["../../src/utils/collectExportsAndImports.ts"],"sourcesContent":["/* eslint @typescript-eslint/no-use-before-define: [\"error\", { \"functions\": false }] */\n/* eslint-disable no-restricted-syntax,no-continue */\n\nimport type { NodePath } from '@babel/traverse';\nimport type {\n AssignmentExpression,\n BlockStatement,\n CallExpression,\n ExportAllDeclaration,\n ExportDefaultDeclaration,\n ExportDefaultSpecifier,\n ExportNamedDeclaration,\n ExportNamespaceSpecifier,\n ExportSpecifier,\n Expression,\n Function as FunctionNode,\n Identifier,\n Import,\n ImportDeclaration,\n ImportDefaultSpecifier,\n ImportNamespaceSpecifier,\n ImportSpecifier,\n MemberExpression,\n ObjectExpression,\n ObjectPattern,\n Program,\n StringLiteral,\n VariableDeclarator,\n} from '@babel/types';\n\nimport { logger } from '@wyw-in-js/shared';\n\nimport { getScope } from './getScope';\nimport { isExports } from './isExports';\nimport { isNotNull } from './isNotNull';\nimport { isRequire } from './isRequire';\nimport { isTypedNode } from './isTypedNode';\nimport { getTraversalCache } from './traversalCache';\n\nexport interface ISideEffectImport {\n imported: 'side-effect';\n local: NodePath;\n source: string;\n}\n\nexport interface IImport {\n imported: string | 'default' | '*';\n local: NodePath<Identifier | MemberExpression>;\n source: string;\n type: 'cjs' | 'dynamic' | 'esm';\n}\n\nexport type Exports = Record<string | 'default' | '*', NodePath>; // '*' means re-export all\n\nexport interface IReexport {\n exported: string | 'default' | '*';\n imported: string | 'default' | '*';\n local: NodePath;\n source: string;\n}\n\nexport interface IState {\n deadExports: string[];\n exportRefs: Map<string, NodePath<MemberExpression>[]>;\n exports: Exports;\n imports: (IImport | ISideEffectImport)[];\n isEsModule: boolean;\n reexports: IReexport[];\n}\n\ninterface ILocalState extends IState {\n processedRequires: WeakSet<NodePath>;\n}\n\nexport const sideEffectImport = (\n item: IImport | ISideEffectImport\n): item is ISideEffectImport => item.imported === 'side-effect';\n\nexport const explicitImport = (\n item: IImport | ISideEffectImport\n): item is IImport => item.imported !== 'side-effect';\n\nfunction getValue({ node }: { node: Identifier | StringLiteral }): string {\n return node.type === 'Identifier' ? node.name : node.value;\n}\n\n// We ignore imports and exports of types\nconst isType = (p: {\n node: { importKind?: 'type' | unknown } | { exportKind?: 'type' | unknown };\n}): boolean =>\n ('importKind' in p.node && p.node.importKind === 'type') ||\n ('exportKind' in p.node && p.node.exportKind === 'type');\n\n// Force TypeScript to check, that we have implementation for every possible specifier\ntype SpecifierTypes = ImportDeclaration['specifiers'][number];\nconst collectors: {\n [K in SpecifierTypes['type']]: (\n path: NodePath<SpecifierTypes & { type: K }>,\n source: string\n ) => IImport[];\n} = {\n ImportSpecifier(path: NodePath<ImportSpecifier>, source): IImport[] {\n if (isType(path)) return [];\n const imported = getValue(path.get('imported'));\n const local = path.get('local');\n return [{ imported, local, source, type: 'esm' }];\n },\n\n ImportDefaultSpecifier(\n path: NodePath<ImportDefaultSpecifier>,\n source\n ): IImport[] {\n const local = path.get('local');\n return [{ imported: 'default', local, source, type: 'esm' }];\n },\n\n ImportNamespaceSpecifier(\n path: NodePath<ImportNamespaceSpecifier>,\n source\n ): IImport[] {\n const local = path.get('local');\n return unfoldNamespaceImport({ imported: '*', local, source, type: 'esm' });\n },\n};\n\nfunction collectFromImportDeclaration(\n path: NodePath<ImportDeclaration>,\n state: ILocalState\n): void {\n // If importKind is specified, and it's not a value, ignore that import\n if (isType(path)) return;\n\n const source = getValue(path.get('source'));\n const specifiers = path.get('specifiers');\n\n if (specifiers.length === 0) {\n state.imports.push({ imported: 'side-effect', local: path, source });\n }\n\n specifiers.forEach(<T extends SpecifierTypes>(specifier: NodePath<T>) => {\n if (specifier.isImportSpecifier() && isType(specifier)) return;\n\n const collector = collectors[\n specifier.node.type\n ] as (typeof collectors)[T['type']];\n\n state.imports.push(...collector(specifier, source));\n });\n}\n\ninterface IDestructed {\n as: NodePath<Identifier>;\n what: string | '*';\n}\n\nfunction getAncestorsWhile(path: NodePath, cond: (p: NodePath) => boolean) {\n const result: NodePath[] = [];\n let current: NodePath | null = path;\n while (current && cond(current)) {\n result.push(current);\n current = current.parentPath;\n }\n\n return result;\n}\n\nfunction whatIsDestructed(\n objectPattern: NodePath<ObjectPattern>\n): IDestructed[] {\n const destructedProps: IDestructed[] = [];\n objectPattern.traverse({\n Identifier(identifier) {\n if (identifier.isBindingIdentifier()) {\n const parent = identifier.parentPath;\n if (parent.isObjectProperty({ value: identifier.node })) {\n const chain = getAncestorsWhile(parent, (p) => p !== objectPattern)\n .filter(isTypedNode('ObjectProperty'))\n .map((p) => {\n const key = p.get('key');\n if (!key.isIdentifier()) {\n // TODO: try to process other type of keys or at least warn about this\n return null;\n }\n\n return key;\n })\n .filter(isNotNull);\n chain.reverse();\n\n if (chain.length > 0) {\n destructedProps.push({\n what: chain[0].node.name,\n as: identifier,\n });\n }\n\n return;\n }\n\n if (parent.isRestElement({ argument: identifier.node })) {\n destructedProps.push({\n what: '*',\n as: identifier,\n });\n }\n }\n },\n });\n\n return destructedProps;\n}\n\nconst debug = logger.extend('evaluator:collectExportsAndImports');\n\nfunction importFromVariableDeclarator(\n path: NodePath<VariableDeclarator>,\n isSync: boolean\n): IDestructed[] {\n const id = path.get('id');\n if (id.isIdentifier()) {\n // It's the simplest case when the full namespace is imported\n return [\n {\n as: id,\n what: '*',\n },\n ];\n }\n\n if (!isSync) {\n // Something went wrong\n // Is it something like `const { … } = import(…)`?\n debug('`import` should be awaited');\n return [];\n }\n\n if (id.isObjectPattern()) {\n return whatIsDestructed(id);\n }\n\n // What else it can be?\n debug('importFromVariableDeclarator: unknown type of id %o', id.node.type);\n\n return [];\n}\n\nconst findIIFE = (path: NodePath): NodePath<CallExpression> | null => {\n if (path.isCallExpression() && path.get('callee').isFunctionExpression()) {\n return path;\n }\n\n if (!path.parentPath) {\n return null;\n }\n\n return findIIFE(path.parentPath);\n};\n\nfunction exportFromVariableDeclarator(\n path: NodePath<VariableDeclarator>\n): Exports {\n const id = path.get('id');\n const init = path.get('init');\n\n // If there is no init and id is an identifier, we should find IIFE\n if (!init.node && id.isIdentifier()) {\n const binding = getScope(path).getBinding(id.node.name);\n if (!binding) {\n return {};\n }\n\n const iife = [\n ...binding.referencePaths,\n ...binding.constantViolations,\n binding.path,\n ]\n .map(findIIFE)\n .find(isNotNull);\n\n if (!iife) {\n return {};\n }\n\n return {\n [id.node.name]: iife,\n };\n }\n\n if (!init || !init.isExpression()) {\n return {};\n }\n\n if (id.isIdentifier()) {\n // It is `export const a = 1;`\n return {\n [id.node.name]: init,\n };\n }\n\n if (id.isObjectPattern()) {\n // It is `export const { a, ...rest } = obj;`\n return whatIsDestructed(id).reduce<Exports>(\n (acc, destructed) => ({\n ...acc,\n [destructed.as.node.name]: init,\n }),\n {}\n );\n }\n\n // What else it can be?\n debug('exportFromVariableDeclarator: unknown type of id %o', id.node.type);\n\n return {};\n}\n\nfunction collectFromDynamicImport(\n path: NodePath<Import>,\n state: ILocalState\n): void {\n const { parentPath: callExpression } = path;\n if (!callExpression.isCallExpression()) {\n // It's wrong `import`\n return;\n }\n\n const [sourcePath] = callExpression.get('arguments');\n if (!sourcePath || !sourcePath.isStringLiteral()) {\n // Import should have at least one argument, and it should be StringLiteral\n return;\n }\n\n const source = sourcePath.node.value;\n\n let { parentPath: container, key } = callExpression;\n let isAwaited = false;\n\n if (container.isAwaitExpression()) {\n // If it's not awaited import, it imports the full namespace\n isAwaited = true;\n key = container.key;\n container = container.parentPath!;\n }\n\n // Is it `const something = await import(\"something\")`?\n if (key === 'init' && container.isVariableDeclarator()) {\n importFromVariableDeclarator(container, isAwaited).map((prop) =>\n state.imports.push({\n imported: prop.what,\n local: prop.as,\n source,\n type: 'dynamic',\n })\n );\n }\n}\n\nfunction getCalleeName(path: NodePath<CallExpression>): string | undefined {\n const callee = path.get('callee');\n if (callee.isIdentifier()) {\n return callee.node.name;\n }\n\n if (callee.isMemberExpression()) {\n const property = callee.get('property');\n if (property.isIdentifier()) {\n return property.node.name;\n }\n }\n\n return undefined;\n}\n\nfunction getImportExportTypeByInteropFunction(\n path: NodePath<CallExpression>\n): 'import:*' | 're-export:*' | 'default' | undefined {\n const name = getCalleeName(path);\n\n if (name === undefined) {\n return undefined;\n }\n\n if (name.startsWith('__exportStar')) {\n return 're-export:*';\n }\n\n if (\n name.startsWith('_interopRequireDefault') ||\n name.startsWith('__importDefault')\n ) {\n return 'default';\n }\n\n if (\n name.startsWith('_interopRequireWildcard') ||\n name.startsWith('__importStar') ||\n name.startsWith('__toESM')\n ) {\n return 'import:*';\n }\n\n if (\n name.startsWith('__rest') ||\n name.startsWith('__objRest') ||\n name.startsWith('_objectDestructuringEmpty')\n ) {\n return 'import:*';\n }\n\n return undefined;\n}\n\nfunction isAlreadyProcessed(path: NodePath): boolean {\n if (\n path.isCallExpression() &&\n path.get('callee').isIdentifier({ name: '__toCommonJS' })\n ) {\n // because its esbuild and we already processed all exports\n return true;\n }\n\n return false;\n}\n\nfunction collectFromRequire(\n path: NodePath<Identifier>,\n state: ILocalState\n): void {\n if (!isRequire(path)) return;\n\n // This method can be reached many times from multiple visitors for the same path\n // So we need to check if we already processed it\n if (state.processedRequires.has(path)) return;\n state.processedRequires.add(path);\n\n const { parentPath: callExpression } = path;\n if (!callExpression.isCallExpression()) {\n // It's wrong `require`\n return;\n }\n\n const [sourcePath] = callExpression.get('arguments');\n if (!sourcePath || !sourcePath.isStringLiteral()) {\n // Import should have at least one argument, and it should be StringLiteral\n return;\n }\n\n const source = sourcePath.node.value;\n\n const { parentPath: container, key } = callExpression;\n\n if (container.isCallExpression() && key === 0) {\n // It may be transpiled import such as\n // `var _atomic = _interopRequireDefault(require(\"@linaria/atomic\"));`\n const imported = getImportExportTypeByInteropFunction(container);\n if (!imported) {\n // It's not a transpiled import.\n // TODO: Can we guess that it's a namespace import?\n debug('Unknown wrapper of require: %o', container.node.callee);\n return;\n }\n\n if (imported === 're-export:*') {\n state.reexports.push({\n exported: '*',\n imported: '*',\n local: path,\n source,\n });\n\n return;\n }\n\n let { parentPath: variableDeclarator } = container;\n if (variableDeclarator.isCallExpression()) {\n if (variableDeclarator.get('callee').isIdentifier({ name: '_extends' })) {\n variableDeclarator = variableDeclarator.parentPath!;\n }\n }\n\n if (!variableDeclarator.isVariableDeclarator()) {\n // TODO: Where else it can be?\n debug('Unexpected require inside %o', variableDeclarator.node.type);\n return;\n }\n\n const id = variableDeclarator.get('id');\n if (!id.isIdentifier()) {\n debug('Id should be Identifier %o', variableDeclarator.node.type);\n return;\n }\n\n if (imported === 'import:*') {\n const unfolded = unfoldNamespaceImport({\n imported: '*',\n local: id,\n source,\n type: 'cjs',\n });\n state.imports.push(...unfolded);\n } else {\n state.imports.push({\n imported,\n local: id,\n source,\n type: 'cjs',\n });\n }\n }\n\n if (container.isMemberExpression()) {\n // It is `require('@linaria/shaker').dep`\n const property = container.get('property');\n if (!property.isIdentifier() && !property.isStringLiteral()) {\n debug(\n 'Property should be Identifier or StringLiteral %s',\n property.node.type\n );\n\n return;\n }\n\n const { parentPath: variableDeclarator } = container;\n\n if (variableDeclarator.isVariableDeclarator()) {\n // It is `const … = require('@linaria/shaker').dep`;\n const id = variableDeclarator.get('id');\n if (id.isIdentifier()) {\n state.imports.push({\n imported: getValue(property),\n local: id,\n source,\n type: 'cjs',\n });\n } else {\n debug('Id should be Identifier %o', variableDeclarator.node.type);\n }\n } else {\n // Maybe require is passed as an argument to some function?\n // Just use the whole MemberExpression as a local\n state.imports.push({\n imported: getValue(property),\n local: container,\n source,\n type: 'cjs',\n });\n }\n\n return;\n }\n\n // Is it `const something = require(\"something\")`?\n if (key === 'init' && container.isVariableDeclarator()) {\n importFromVariableDeclarator(container, true).forEach((prop) => {\n if (prop.what === '*') {\n const unfolded = unfoldNamespaceImport({\n imported: '*',\n local: prop.as,\n source,\n type: 'cjs',\n });\n\n state.imports.push(...unfolded);\n } else {\n state.imports.push({\n imported: prop.what,\n local: prop.as,\n source,\n type: 'cjs',\n });\n }\n });\n }\n\n if (container.isExpressionStatement()) {\n // Looks like standalone require\n state.imports.push({\n imported: 'side-effect',\n local: container,\n source,\n });\n }\n}\n\nfunction collectFromVariableDeclarator(\n path: NodePath<VariableDeclarator>,\n state: ILocalState\n): void {\n let found = false;\n path.traverse({\n Identifier(identifierPath) {\n if (isRequire(identifierPath)) {\n collectFromRequire(identifierPath, state);\n found = true;\n }\n },\n });\n\n if (found) {\n path.skip();\n }\n}\n\nfunction isChainOfVoidAssignment(\n path: NodePath<AssignmentExpression>\n): boolean {\n const right = path.get('right');\n if (right.isUnaryExpression({ operator: 'void' })) {\n return true;\n }\n\n if (right.isAssignmentExpression()) {\n return isChainOfVoidAssignment(right);\n }\n\n return false;\n}\n\nfunction getReturnValue(\n path: NodePath<FunctionNode>\n): NodePath<Expression> | undefined {\n if (path.node.params.length !== 0) return undefined;\n\n const body = path.get('body') as\n | NodePath<BlockStatement>\n | NodePath<Expression>;\n if (body.isExpression()) {\n return body;\n }\n\n if (body.node.body.length === 1) {\n const returnStatement = body.get('body')?.[0];\n if (!returnStatement.isReturnStatement()) return undefined;\n const argument = returnStatement.get('argument');\n if (!argument.isExpression()) return undefined;\n return argument;\n }\n\n return undefined;\n}\n\nfunction getGetterValueFromDescriptor(\n descriptor: NodePath<ObjectExpression>\n): NodePath<Expression> | undefined {\n const props = descriptor\n .get('properties')\n .filter(isTypedNode('ObjectProperty'));\n\n const getter = props.find((p) => p.get('key').isIdentifier({ name: 'get' }));\n const value = getter?.get('value');\n\n if (value?.isFunctionExpression() || value?.isArrowFunctionExpression()) {\n return getReturnValue(value);\n }\n\n const valueProp = props.find((p) =>\n p.get('key').isIdentifier({ name: 'value' })\n );\n\n const valueValue = valueProp?.get('value');\n\n return valueValue?.isExpression() ? valueValue : undefined;\n}\n\nfunction addExport(path: NodePath, exported: string, state: ILocalState): void {\n function getRelatedImport() {\n if (path.isMemberExpression()) {\n const object = path.get('object');\n if (!object.isIdentifier()) {\n return undefined;\n }\n\n const objectBinding = object.scope.getBinding(object.node.name);\n if (!objectBinding) {\n return undefined;\n }\n\n if (objectBinding.path.isVariableDeclarator()) {\n collectFromVariableDeclarator(objectBinding.path, state);\n }\n\n const found = state.imports.find(\n (i) =>\n objectBinding.identifier === i.local.node ||\n objectBinding.referencePaths.some((p) => i.local.isAncestor(p))\n );\n\n if (!found) {\n return undefined;\n }\n\n const property = path.get('property');\n let what = '*';\n if (path.node.computed && property.isStringLiteral()) {\n what = property.node.value;\n } else if (!path.node.computed && property.isIdentifier()) {\n what = property.node.name;\n }\n\n return {\n import: { ...found, local: path },\n what,\n };\n }\n\n return undefined;\n }\n\n const relatedImport = getRelatedImport();\n if (relatedImport) {\n // eslint-disable-next-line no-param-reassign\n state.reexports.push({\n local: relatedImport.import.local,\n imported: relatedImport.import.imported,\n source: relatedImport.import.source,\n exported,\n });\n } else {\n // eslint-disable-next-line no-param-reassign\n state.exports[exported] = path;\n }\n}\n\nfunction collectFromExports(\n path: NodePath<Identifier>,\n state: ILocalState\n): void {\n if (!isExports(path)) return;\n\n if (path.parentPath.isMemberExpression({ object: path.node })) {\n // It is `exports.prop = …`\n const memberExpression = path.parentPath;\n const property = memberExpression.get('property');\n if (!property.isIdentifier() || memberExpression.node.computed) {\n return;\n }\n\n const exportName = property.node.name;\n\n const saveRef = () => {\n // Save all export.____ usages for later\n if (!state.exportRefs.has(exportName)) {\n state.exportRefs.set(exportName, []);\n }\n\n state.exportRefs.get(exportName)!.push(memberExpression);\n };\n\n const assignmentExpression = memberExpression.parentPath;\n\n if (\n !assignmentExpression.isAssignmentExpression({\n left: memberExpression.node,\n })\n ) {\n // If it's not `exports.prop = …`. Just save it.\n saveRef();\n return;\n }\n\n const right = assignmentExpression.get('right');\n\n if (isChainOfVoidAssignment(assignmentExpression)) {\n // It is `exports.foo = void 0`\n return;\n }\n\n const { name } = property.node;\n if (name === '__esModule') {\n // eslint-disable-next-line no-param-reassign\n state.isEsModule = true;\n return;\n }\n\n saveRef();\n // eslint-disable-next-line no-param-reassign\n state.exports[property.node.name] = right;\n\n return;\n }\n\n if (\n path.parentPath.isCallExpression() &&\n path.parentPath.get('callee').matchesPattern('Object.defineProperty')\n ) {\n const [obj, prop, descriptor] = path.parentPath.get('arguments');\n if (\n obj?.isIdentifier(path.node) &&\n prop?.isStringLiteral() &&\n descriptor?.isObjectExpression()\n ) {\n if (prop.node.value === '__esModule') {\n // eslint-disable-next-line no-param-reassign\n state.isEsModule = true;\n } else {\n /**\n * Object.defineProperty(exports, \"token\", {\n * enumerable: true,\n * get: function get() {\n * return _unknownPackage.token;\n * }\n * });\n */\n const exported = prop.node.value;\n const local = getGetterValueFromDescriptor(descriptor);\n if (local) {\n addExport(local, exported, state);\n }\n }\n } else if (\n obj?.isIdentifier(path.node) &&\n prop?.isIdentifier() &&\n descriptor?.isObjectExpression()\n ) {\n /**\n * Object.defineProperty(exports, key, {\n * enumerable: true,\n * get: function get() {\n * return _unknownPackage[key];\n * }\n * });\n */\n const local = getGetterValueFromDescriptor(descriptor);\n if (local) {\n addExport(local, '*', state);\n }\n }\n }\n}\n\nfunction collectFromRequireOrExports(\n path: NodePath<Identifier>,\n state: ILocalState\n): void {\n if (isRequire(path)) {\n collectFromRequire(path, state);\n } else if (isExports(path)) {\n collectFromExports(path, state);\n }\n}\n\nfunction unfoldNamespaceImport(\n importItem: IImport & { imported: '*' }\n): IImport[] {\n const result: IImport[] = [];\n const { local } = importItem;\n if (!local.isIdentifier()) {\n // TODO: handle it\n return [importItem];\n }\n\n const binding = getScope(local).getBinding(local.node.name);\n if (!binding?.referenced) {\n // Imported namespace is not referenced and probably not used,\n // but it can have side effects, so we should keep it as is\n return [importItem];\n }\n\n for (const referencePath of binding?.referencePaths ?? []) {\n if (\n referencePath.find(\n (ancestor) => ancestor.isTSType() || ancestor.isFlowType()\n )\n ) {\n continue;\n }\n\n const { parentPath } = referencePath;\n if (parentPath?.isMemberExpression() && referencePath.key === 'object') {\n const property = parentPath.get('property');\n const object = parentPath.get('object');\n let imported: string | null;\n if (parentPath.node.computed && property.isStringLiteral()) {\n imported = property.node.value;\n } else if (!parentPath.node.computed && property.isIdentifier()) {\n imported = property.node.name;\n } else {\n imported = null;\n }\n\n if (object.isIdentifier() && imported) {\n result.push({\n ...importItem,\n imported,\n local: parentPath,\n });\n } else {\n result.push(importItem);\n break;\n }\n\n continue;\n }\n\n if (parentPath?.isVariableDeclarator() && referencePath.key === 'init') {\n importFromVariableDeclarator(parentPath, true).map((prop) =>\n result.push({ ...importItem, imported: prop.what, local: prop.as })\n );\n\n continue;\n }\n\n if (\n parentPath?.isCallExpression() &&\n referencePath.listKey === 'arguments'\n ) {\n // The defined variable is used as a function argument. Let's try to figure out what is imported.\n const importType = getImportExportTypeByInteropFunction(parentPath);\n\n if (!importType) {\n // Imported value is used as an unknown function argument,\n // so we can't predict usage and import it as is.\n result.push(importItem);\n break;\n }\n\n if (importType === 'default') {\n result.push({\n ...importItem,\n imported: 'default',\n local: parentPath.get('id') as NodePath<Identifier>,\n });\n\n continue;\n }\n\n if (importType === 'import:*') {\n result.push(importItem);\n break;\n }\n\n debug('unfoldNamespaceImports: unknown import type %o', importType);\n\n result.push(importItem);\n continue;\n }\n\n if (\n parentPath?.isExportSpecifier() ||\n parentPath?.isExportDefaultDeclaration()\n ) {\n // The whole namespace is re-exported\n result.push(importItem);\n break;\n }\n\n // Otherwise, we can't predict usage and import it as is\n // TODO: handle more cases\n debug(\n 'unfoldNamespaceImports: unknown reference %o',\n referencePath.node.type\n );\n result.push(importItem);\n break;\n }\n\n return result;\n}\n\nfunction collectFromExportAllDeclaration(\n path: NodePath<ExportAllDeclaration>,\n state: ILocalState\n): void {\n if (isType(path)) return;\n const source = path.get('source')?.node?.value;\n if (!source) return;\n\n // It is `export * from './css';`\n state.reexports.push({\n exported: '*',\n imported: '*',\n local: path,\n source,\n });\n}\n\nfunction collectFromExportSpecifier(\n path: NodePath<\n ExportSpecifier | ExportDefaultSpecifier | ExportNamespaceSpecifier\n >,\n source: string | undefined,\n state: ILocalState\n): void {\n if (path.isExportSpecifier()) {\n const exported = getValue(path.get('exported'));\n if (source) {\n // It is `export { foo } from './css';`\n const imported = path.get('local').node.name;\n state.reexports.push({\n exported,\n imported,\n local: path,\n source,\n });\n } else {\n const local = path.get('local');\n // eslint-disable-next-line no-param-reassign\n state.exports[exported] = local;\n }\n\n return;\n }\n\n if (path.isExportDefaultSpecifier() && source) {\n // It is `export default from './css';`\n state.reexports.push({\n exported: 'default',\n imported: 'default',\n local: path,\n source,\n });\n }\n\n if (path.isExportNamespaceSpecifier() && source) {\n const exported = path.get('exported').node.name;\n // It is `export * as foo from './css';`\n state.reexports.push({\n exported,\n imported: '*',\n local: path,\n source,\n });\n }\n\n // TODO: handle other cases\n debug(\n 'collectFromExportSpecifier: unprocessed ExportSpecifier %o',\n path.node.type\n );\n}\n\nfunction collectFromExportNamedDeclaration(\n path: NodePath<ExportNamedDeclaration>,\n state: ILocalState\n): void {\n if (isType(path)) return;\n\n const source = path.get('source')?.node?.value;\n const specifiers = path.get('specifiers');\n if (specifiers) {\n specifiers.forEach((specifier) =>\n collectFromExportSpecifier(specifier, source, state)\n );\n }\n\n const declaration = path.get('declaration');\n if (declaration.isVariableDeclaration()) {\n declaration.get('declarations').forEach((declarator) => {\n // eslint-disable-next-line no-param-reassign\n state.exports = {\n ...state.exports,\n ...exportFromVariableDeclarator(declarator),\n };\n });\n }\n\n if (declaration.isTSEnumDeclaration()) {\n // eslint-disable-next-line no-param-reassign\n state.exports[declaration.get('id').node.name] = declaration;\n }\n\n if (declaration.isFunctionDeclaration()) {\n const id = declaration.get('id');\n if (id.isIdentifier()) {\n // eslint-disable-next-line no-param-reassign\n state.exports[id.node.name] = id;\n }\n }\n\n if (declaration.isClassDeclaration()) {\n const id = declaration.get('id');\n if (id.isIdentifier()) {\n // eslint-disable-next-line no-param-reassign\n state.exports[id.node.name] = id;\n }\n }\n}\n\nfunction collectFromExportDefaultDeclaration(\n path: NodePath<ExportDefaultDeclaration>,\n state: ILocalState\n): void {\n if (isType(path)) return;\n\n // eslint-disable-next-line no-param-reassign\n state.exports.default = path.get('declaration');\n}\n\nfunction collectFromAssignmentExpression(\n path: NodePath<AssignmentExpression>,\n state: ILocalState\n): void {\n if (isChainOfVoidAssignment(path)) {\n return;\n }\n\n const left = path.get('left');\n const right = path.get('right');\n\n let exported: IReexport['exported'] | undefined;\n\n if (left.isMemberExpression() && isExports(left.get('object'))) {\n const property = left.get('property');\n if (property.isIdentifier()) {\n exported = property.node.name;\n }\n } else if (isExports(left)) {\n // module.exports = ...\n if (!isAlreadyProcessed(right)) {\n exported = 'default';\n }\n }\n\n if (!exported) return;\n\n if (!right.isCallExpression() || !isRequire(right.get('callee'))) {\n // eslint-disable-next-line no-param-reassign\n state.exports[exported] = right;\n return;\n }\n\n const sourcePath = right.get('arguments')?.[0];\n const source = sourcePath.isStringLiteral()\n ? sourcePath.node.value\n : undefined;\n if (!source) return;\n\n // It is `exports.foo = require('./css');`\n\n if (state.exports[exported]) {\n // eslint-disable-next-line no-param-reassign\n delete state.exports[exported];\n }\n\n state.reexports.push({\n exported,\n imported: '*',\n local: path,\n source,\n });\n\n path.skip();\n}\n\nfunction collectFromExportStarCall(\n path: NodePath<CallExpression>,\n state: ILocalState\n) {\n const [requireCall, exports] = path.get('arguments');\n if (!isExports(exports)) return;\n if (!requireCall.isCallExpression()) return;\n const callee = requireCall.get('callee');\n const sourcePath = requireCall.get('arguments')?.[0];\n if (!isRequire(callee) || !sourcePath.isStringLiteral()) return;\n\n const source = sourcePath.node.value;\n if (!source) return;\n\n state.reexports.push({\n exported: '*',\n imported: '*',\n local: path,\n source,\n });\n\n path.skip();\n}\n\nfunction collectFromMap(map: NodePath<ObjectExpression>, state: ILocalState) {\n const properties = map.get('properties');\n properties.forEach((property) => {\n if (!property.isObjectProperty()) return;\n const key = property.get('key');\n const value = property.get('value');\n if (!key.isIdentifier()) return;\n const exported = key.node.name;\n\n if (!value.isFunction()) return;\n if (value.node.params.length !== 0) return;\n\n const returnValue = getReturnValue(value);\n if (!returnValue) return;\n\n addExport(returnValue, exported, state);\n });\n}\n\nfunction collectFromEsbuildExportCall(\n path: NodePath<CallExpression>,\n state: ILocalState\n) {\n const [sourceExports, map] = path.get('arguments');\n if (!sourceExports.isIdentifier({ name: 'source_exports' })) return;\n if (!map.isObjectExpression()) return;\n\n collectFromMap(map, state);\n\n path.skip();\n}\n\nfunction collectFromEsbuildReExportCall(\n path: NodePath<CallExpression>,\n state: ILocalState\n) {\n const [sourceExports, requireCall, exports] = path.get('arguments');\n if (!sourceExports.isIdentifier({ name: 'source_exports' })) return;\n if (!requireCall.isCallExpression()) return;\n if (!isExports(exports)) return;\n\n const callee = requireCall.get('callee');\n if (!isRequire(callee)) return;\n const sourcePath = requireCall.get('arguments')?.[0];\n if (!sourcePath.isStringLiteral()) return;\n\n state.reexports.push({\n exported: '*',\n imported: '*',\n local: path,\n source: sourcePath.node.value,\n });\n\n path.skip();\n}\n\nfunction collectFromSwcExportCall(\n path: NodePath<CallExpression>,\n state: ILocalState\n) {\n const [exports, map] = path.get('arguments');\n if (!isExports(exports)) return;\n if (!map.isObjectExpression()) return;\n\n collectFromMap(map, state);\n\n path.skip();\n}\n\nfunction collectFromCallExpression(\n path: NodePath<CallExpression>,\n state: ILocalState\n) {\n const maybeExportStart = path.get('callee');\n if (!maybeExportStart.isIdentifier()) {\n return;\n }\n\n const { name } = maybeExportStart.node;\n\n // TypeScript\n if (name.startsWith('__exportStar')) {\n collectFromExportStarCall(path, state);\n return;\n }\n\n // swc\n if (name === '_exportStar') {\n collectFromExportStarCall(path, state);\n }\n\n if (name === '_export') {\n collectFromSwcExportCall(path, state);\n }\n\n // esbuild\n if (name === '__export') {\n collectFromEsbuildExportCall(path, state);\n }\n\n if (name === '__reExport') {\n collectFromEsbuildReExportCall(path, state);\n }\n}\n\nexport function collectExportsAndImports(\n path: NodePath<Program>,\n cacheMode: 'disabled' | 'force' | 'enabled' = 'enabled'\n): IState {\n const localState: ILocalState = {\n deadExports: [],\n exportRefs: new Map(),\n exports: {},\n imports: [],\n reexports: [],\n isEsModule: path.node.sourceType === 'module',\n processedRequires: new WeakSet(),\n };\n\n const cache =\n cacheMode !== 'disabled'\n ? getTraversalCache<IState>(path, 'collectExportsAndImports')\n : undefined;\n\n if (cacheMode === 'enabled' && cache?.has(path)) {\n return cache.get(path) ?? localState;\n }\n\n path.traverse(\n {\n AssignmentExpression: collectFromAssignmentExpression,\n CallExpression: collectFromCallExpression,\n ExportAllDeclaration: collectFromExportAllDeclaration,\n ExportDefaultDeclaration: collectFromExportDefaultDeclaration,\n ExportNamedDeclaration: collectFromExportNamedDeclaration,\n ImportDeclaration: collectFromImportDeclaration,\n Import: collectFromDynamicImport,\n Identifier: collectFromRequireOrExports,\n VariableDeclarator: collectFromVariableDeclarator,\n },\n localState\n );\n\n const { processedRequires, ...state } = localState;\n\n cache?.set(path, state);\n\n return state;\n}\n"],"mappings":";;;;;;;AA8BA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IA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AE,EAAE;IACX6E,SAAS,EAAE,EAAE;IACb+C,UAAU,EAAEvI,IAAI,CAACV,IAAI,CAACqM,UAAU,KAAK,QAAQ;IAC7CtG,iBAAiB,EAAE,IAAIuG,OAAO,CAAC;EACjC,CAAC;EAED,MAAMC,KAAK,GACTN,SAAS,KAAK,UAAU,GACpB,IAAAO,iCAAiB,EAAS9L,IAAI,EAAE,0BAA0B,CAAC,GAC3D+E,SAAS;EAEf,IAAIwG,SAAS,KAAK,SAAS,IAAIM,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEvG,GAAG,CAACtF,IAAI,CAAC,EAAE;IAAA,IAAA+L,UAAA;IAC/C,QAAAA,UAAA,GAAOF,KAAK,CAAC3L,GAAG,CAACF,IAAI,CAAC,cAAA+L,UAAA,cAAAA,UAAA,GAAIP,UAAU;EACtC;EAEAxL,IAAI,CAACyB,QAAQ,CACX;IACEuK,oBAAoB,EAAE1B,+BAA+B;IACrD2B,cAAc,EAAEb,yBAAyB;IACzCc,oBAAoB,EAAE3C,+BAA+B;IACrD4C,wBAAwB,EAAE/B,mCAAmC;IAC7DgC,sBAAsB,EAAExC,iCAAiC;IACzDyC,iBAAiB,EAAE9L,4BAA4B;IAC/C+L,MAAM,EAAEpI,wBAAwB;IAChCxC,UAAU,EAAEiH,2BAA2B;IACvC4D,kBAAkB,EAAE1G;EACtB,CAAC,EACD2F,UACF,CAAC;EAED,MAAM;IAAEnG,iBAAiB;IAAE,GAAG7E;EAAM,CAAC,GAAGgL,UAAU;EAElDK,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEzD,GAAG,CAACpI,IAAI,EAAEQ,KAAK,CAAC;EAEvB,OAAOA,KAAK;AACd"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collectTemplateDependencies = collectTemplateDependencies;
|
|
7
|
+
exports.extractExpression = extractExpression;
|
|
8
|
+
var _template = require("@babel/template");
|
|
9
|
+
var _types = require("@babel/types");
|
|
10
|
+
var _shared = require("@wyw-in-js/shared");
|
|
11
|
+
var _createId = require("./createId");
|
|
12
|
+
var _findIdentifiers = require("./findIdentifiers");
|
|
13
|
+
var _getSource = require("./getSource");
|
|
14
|
+
var _scopeHelpers = require("./scopeHelpers");
|
|
15
|
+
var _valueToLiteral = require("./valueToLiteral");
|
|
16
|
+
/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This file is a visitor that checks TaggedTemplateExpressions and look for Linaria css or styled templates.
|
|
20
|
+
* For each template it makes a list of dependencies, try to evaluate expressions, and if it is not possible, mark them as lazy dependencies.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function staticEval(ex, evaluate = false) {
|
|
24
|
+
if (!evaluate) return undefined;
|
|
25
|
+
const result = ex.evaluate();
|
|
26
|
+
if (result.confident && !(0, _shared.hasEvalMeta)(result.value)) {
|
|
27
|
+
return [result.value];
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const expressionDeclarationTpl = (0, _template.statement)('const %%expId%% = /*#__PURE__*/ () => %%expression%%', {
|
|
32
|
+
preserveComments: true
|
|
33
|
+
});
|
|
34
|
+
const unsupported = (ex, reason) => ex.buildCodeFrameError(`This ${ex.isIdentifier() ? 'identifier' : 'expression'} cannot be used in the template${reason ? `, because it ${reason}` : ''}.`);
|
|
35
|
+
function getUidInRootScope(path) {
|
|
36
|
+
const {
|
|
37
|
+
name
|
|
38
|
+
} = path.node;
|
|
39
|
+
const rootScope = path.scope.getProgramParent();
|
|
40
|
+
if (rootScope.hasBinding(name)) {
|
|
41
|
+
return rootScope.generateUid(name);
|
|
42
|
+
}
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
function hoistVariableDeclarator(ex) {
|
|
46
|
+
if (!ex.scope.parent) {
|
|
47
|
+
// It is already in the root scope
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const referencedIdentifiers = (0, _findIdentifiers.findIdentifiers)([ex], 'reference');
|
|
51
|
+
referencedIdentifiers.forEach(identifier => {
|
|
52
|
+
if (identifier.isIdentifier()) {
|
|
53
|
+
hoistIdentifier(identifier);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const bindingIdentifiers = (0, _findIdentifiers.findIdentifiers)([ex], 'declaration');
|
|
57
|
+
bindingIdentifiers.forEach(path => {
|
|
58
|
+
const newName = getUidInRootScope(path);
|
|
59
|
+
if (newName !== path.node.name) {
|
|
60
|
+
path.scope.rename(path.node.name, newName);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const rootScope = ex.scope.getProgramParent();
|
|
64
|
+
const statementInRoot = ex.findParent(p => {
|
|
65
|
+
var _p$parentPath;
|
|
66
|
+
return ((_p$parentPath = p.parentPath) === null || _p$parentPath === void 0 ? void 0 : _p$parentPath.isProgram()) === true;
|
|
67
|
+
});
|
|
68
|
+
const declaration = {
|
|
69
|
+
type: 'VariableDeclaration',
|
|
70
|
+
kind: 'let',
|
|
71
|
+
declarations: [(0, _types.cloneNode)(ex.node)]
|
|
72
|
+
};
|
|
73
|
+
const [inserted] = statementInRoot.insertBefore(declaration);
|
|
74
|
+
(0, _scopeHelpers.referenceAll)(inserted);
|
|
75
|
+
rootScope.registerDeclaration(inserted);
|
|
76
|
+
}
|
|
77
|
+
function hoistIdentifier(idPath) {
|
|
78
|
+
if (!idPath.isReferenced()) {
|
|
79
|
+
throw unsupported(idPath);
|
|
80
|
+
}
|
|
81
|
+
const binding = idPath.scope.getBinding(idPath.node.name);
|
|
82
|
+
if (!binding) {
|
|
83
|
+
// It's something strange
|
|
84
|
+
throw unsupported(idPath, 'is undefined');
|
|
85
|
+
}
|
|
86
|
+
if (binding.kind === 'module') {
|
|
87
|
+
// Modules are global by default
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!['var', 'let', 'const', 'hoisted'].includes(binding.kind)) {
|
|
91
|
+
// This is not a variable, we can't hoist it
|
|
92
|
+
throw unsupported(binding.path, 'is a function parameter');
|
|
93
|
+
}
|
|
94
|
+
const {
|
|
95
|
+
scope,
|
|
96
|
+
path: bindingPath
|
|
97
|
+
} = binding;
|
|
98
|
+
// parent here can be null or undefined in different versions of babel
|
|
99
|
+
if (!scope.parent) {
|
|
100
|
+
// The variable is already in the root scope
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (bindingPath.isVariableDeclarator()) {
|
|
104
|
+
hoistVariableDeclarator(bindingPath);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
throw unsupported(idPath);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Only an expression that can be evaluated in the root scope can be
|
|
112
|
+
* used in a Linaria template. This function tries to hoist the expression.
|
|
113
|
+
* @param ex The expression to hoist.
|
|
114
|
+
* @param evaluate If true, we try to statically evaluate the expression.
|
|
115
|
+
* @param imports All the imports of the file.
|
|
116
|
+
*/
|
|
117
|
+
function extractExpression(ex, evaluate = false, imports = []) {
|
|
118
|
+
if (ex.isLiteral() && ('value' in ex.node || ex.node.type === 'NullLiteral')) {
|
|
119
|
+
return {
|
|
120
|
+
ex: ex.node,
|
|
121
|
+
kind: _shared.ValueType.CONST,
|
|
122
|
+
value: ex.node.type === 'NullLiteral' ? null : ex.node.value
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const {
|
|
126
|
+
loc
|
|
127
|
+
} = ex.node;
|
|
128
|
+
const rootScope = ex.scope.getProgramParent();
|
|
129
|
+
const statementInRoot = ex.findParent(p => {
|
|
130
|
+
var _p$parentPath2;
|
|
131
|
+
return ((_p$parentPath2 = p.parentPath) === null || _p$parentPath2 === void 0 ? void 0 : _p$parentPath2.isProgram()) === true;
|
|
132
|
+
});
|
|
133
|
+
const isFunction = ex.isFunctionExpression() || ex.isArrowFunctionExpression();
|
|
134
|
+
|
|
135
|
+
// Generate next _expN name
|
|
136
|
+
const expUid = rootScope.generateUid('exp');
|
|
137
|
+
const evaluated = staticEval(ex, evaluate);
|
|
138
|
+
if (!evaluated) {
|
|
139
|
+
// If expression is not statically evaluable,
|
|
140
|
+
// we need to hoist all its referenced identifiers
|
|
141
|
+
|
|
142
|
+
// Collect all referenced identifiers
|
|
143
|
+
(0, _findIdentifiers.findIdentifiers)([ex], 'reference').forEach(id => {
|
|
144
|
+
if (!id.isIdentifier()) return;
|
|
145
|
+
|
|
146
|
+
// Try to evaluate and inline them…
|
|
147
|
+
const evaluatedId = staticEval(id, evaluate);
|
|
148
|
+
if (evaluatedId) {
|
|
149
|
+
(0, _scopeHelpers.mutate)(id, p => {
|
|
150
|
+
p.replaceWith((0, _valueToLiteral.valueToLiteral)(evaluatedId[0], ex));
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
// … or hoist them to the root scope
|
|
154
|
+
hoistIdentifier(id);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const kind = isFunction ? _shared.ValueType.FUNCTION : _shared.ValueType.LAZY;
|
|
159
|
+
|
|
160
|
+
// Declare _expN const with the lazy expression
|
|
161
|
+
const declaration = expressionDeclarationTpl({
|
|
162
|
+
expId: (0, _createId.createId)(expUid),
|
|
163
|
+
expression: evaluated ? (0, _valueToLiteral.valueToLiteral)(evaluated[0], ex) : (0, _types.cloneNode)(ex.node)
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Insert the declaration as close as possible to the original expression
|
|
167
|
+
const [inserted] = statementInRoot.insertBefore(declaration);
|
|
168
|
+
(0, _scopeHelpers.referenceAll)(inserted);
|
|
169
|
+
rootScope.registerDeclaration(inserted);
|
|
170
|
+
const importedFrom = [];
|
|
171
|
+
function findImportSourceOfIdentifier(idPath) {
|
|
172
|
+
var _idPath$scope$getBind, _imports$find;
|
|
173
|
+
const exBindingIdentifier = (_idPath$scope$getBind = idPath.scope.getBinding(idPath.node.name)) === null || _idPath$scope$getBind === void 0 ? void 0 : _idPath$scope$getBind.identifier;
|
|
174
|
+
const exImport = (_imports$find = imports.find(i => i.local.node === exBindingIdentifier)) !== null && _imports$find !== void 0 ? _imports$find : null;
|
|
175
|
+
if (exImport) {
|
|
176
|
+
importedFrom.push(exImport.source);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (ex.isIdentifier()) {
|
|
180
|
+
findImportSourceOfIdentifier(ex);
|
|
181
|
+
} else {
|
|
182
|
+
ex.traverse({
|
|
183
|
+
Identifier: findImportSourceOfIdentifier
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Replace the expression with the _expN() call
|
|
188
|
+
(0, _scopeHelpers.mutate)(ex, p => {
|
|
189
|
+
p.replaceWith({
|
|
190
|
+
type: 'CallExpression',
|
|
191
|
+
callee: (0, _createId.createId)(expUid),
|
|
192
|
+
arguments: []
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// eslint-disable-next-line no-param-reassign
|
|
197
|
+
ex.node.loc = loc;
|
|
198
|
+
|
|
199
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
200
|
+
const result = {
|
|
201
|
+
kind,
|
|
202
|
+
ex: (0, _createId.createId)(expUid, loc),
|
|
203
|
+
importedFrom
|
|
204
|
+
};
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
const debug = _shared.logger.extend('template-parse:identify-expressions');
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Collects, hoists, and makes lazy all expressions in the given template
|
|
211
|
+
* If evaluate is true, it will try to evaluate the expressions
|
|
212
|
+
*/
|
|
213
|
+
function collectTemplateDependencies(path, evaluate = false) {
|
|
214
|
+
const quasi = path.get('quasi');
|
|
215
|
+
const quasis = quasi.get('quasis');
|
|
216
|
+
const expressions = quasi.get('expressions');
|
|
217
|
+
debug('Found: %s', expressions.length);
|
|
218
|
+
const expressionValues = expressions.map(ex => {
|
|
219
|
+
const buildCodeFrameError = ex.buildCodeFrameError.bind(ex);
|
|
220
|
+
const source = (0, _getSource.getSource)(ex);
|
|
221
|
+
if (!ex.isExpression()) {
|
|
222
|
+
throw buildCodeFrameError(`The expression '${source}' is not supported.`);
|
|
223
|
+
}
|
|
224
|
+
const extracted = extractExpression(ex, evaluate);
|
|
225
|
+
return {
|
|
226
|
+
...extracted,
|
|
227
|
+
source,
|
|
228
|
+
buildCodeFrameError
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
return [quasis.map(p => p.node), expressionValues];
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=collectTemplateDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectTemplateDependencies.js","names":["_template","require","_types","_shared","_createId","_findIdentifiers","_getSource","_scopeHelpers","_valueToLiteral","staticEval","ex","evaluate","undefined","result","confident","hasEvalMeta","value","expressionDeclarationTpl","statement","preserveComments","unsupported","reason","buildCodeFrameError","isIdentifier","getUidInRootScope","path","name","node","rootScope","scope","getProgramParent","hasBinding","generateUid","hoistVariableDeclarator","parent","referencedIdentifiers","findIdentifiers","forEach","identifier","hoistIdentifier","bindingIdentifiers","newName","rename","statementInRoot","findParent","p","_p$parentPath","parentPath","isProgram","declaration","type","kind","declarations","cloneNode","inserted","insertBefore","referenceAll","registerDeclaration","idPath","isReferenced","binding","getBinding","includes","bindingPath","isVariableDeclarator","extractExpression","imports","isLiteral","ValueType","CONST","loc","_p$parentPath2","isFunction","isFunctionExpression","isArrowFunctionExpression","expUid","evaluated","id","evaluatedId","mutate","replaceWith","valueToLiteral","FUNCTION","LAZY","expId","createId","expression","importedFrom","findImportSourceOfIdentifier","_idPath$scope$getBind","_imports$find","exBindingIdentifier","exImport","find","i","local","push","source","traverse","Identifier","callee","arguments","debug","logger","extend","collectTemplateDependencies","quasi","get","quasis","expressions","length","expressionValues","map","bind","getSource","isExpression","extracted"],"sources":["../../src/utils/collectTemplateDependencies.ts"],"sourcesContent":["/* eslint @typescript-eslint/no-use-before-define: [\"error\", { \"functions\": false }] */\n\n/**\n * This file is a visitor that checks TaggedTemplateExpressions and look for Linaria css or styled templates.\n * For each template it makes a list of dependencies, try to evaluate expressions, and if it is not possible, mark them as lazy dependencies.\n */\n\nimport { statement } from '@babel/template';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n Identifier,\n JSXIdentifier,\n Statement,\n TaggedTemplateExpression,\n TemplateElement,\n TSType,\n VariableDeclaration,\n VariableDeclarator,\n} from '@babel/types';\nimport { cloneNode } from '@babel/types';\n\nimport type {\n ConstValue,\n ExpressionValue,\n FunctionValue,\n LazyValue,\n} from '@wyw-in-js/shared';\nimport { hasEvalMeta, ValueType, logger } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport { createId } from './createId';\nimport { findIdentifiers } from './findIdentifiers';\nimport { getSource } from './getSource';\nimport { mutate, referenceAll } from './scopeHelpers';\nimport { valueToLiteral } from './valueToLiteral';\n\nfunction staticEval(\n ex: NodePath<Expression>,\n evaluate = false\n): [unknown] | undefined {\n if (!evaluate) return undefined;\n\n const result = ex.evaluate();\n if (result.confident && !hasEvalMeta(result.value)) {\n return [result.value];\n }\n\n return undefined;\n}\n\nconst expressionDeclarationTpl = statement(\n 'const %%expId%% = /*#__PURE__*/ () => %%expression%%',\n {\n preserveComments: true,\n }\n);\n\nconst unsupported = (ex: NodePath, reason?: string): Error =>\n ex.buildCodeFrameError(\n `This ${\n ex.isIdentifier() ? 'identifier' : 'expression'\n } cannot be used in the template${reason ? `, because it ${reason}` : ''}.`\n );\n\nfunction getUidInRootScope(path: NodePath<Identifier | JSXIdentifier>): string {\n const { name } = path.node;\n const rootScope = path.scope.getProgramParent();\n if (rootScope.hasBinding(name)) {\n return rootScope.generateUid(name);\n }\n\n return name;\n}\n\nfunction hoistVariableDeclarator(ex: NodePath<VariableDeclarator>) {\n if (!ex.scope.parent) {\n // It is already in the root scope\n return;\n }\n\n const referencedIdentifiers = findIdentifiers([ex], 'reference');\n referencedIdentifiers.forEach((identifier) => {\n if (identifier.isIdentifier()) {\n hoistIdentifier(identifier);\n }\n });\n\n const bindingIdentifiers = findIdentifiers([ex], 'declaration');\n\n bindingIdentifiers.forEach((path) => {\n const newName = getUidInRootScope(path);\n if (newName !== path.node.name) {\n path.scope.rename(path.node.name, newName);\n }\n });\n\n const rootScope = ex.scope.getProgramParent();\n\n const statementInRoot = ex.findParent(\n (p) => p.parentPath?.isProgram() === true\n ) as NodePath<Statement>;\n\n const declaration: VariableDeclaration = {\n type: 'VariableDeclaration',\n kind: 'let',\n declarations: [cloneNode(ex.node)],\n };\n\n const [inserted] = statementInRoot.insertBefore(declaration);\n referenceAll(inserted);\n rootScope.registerDeclaration(inserted);\n}\n\nfunction hoistIdentifier(idPath: NodePath<Identifier>): void {\n if (!idPath.isReferenced()) {\n throw unsupported(idPath);\n }\n\n const binding = idPath.scope.getBinding(idPath.node.name);\n if (!binding) {\n // It's something strange\n throw unsupported(idPath, 'is undefined');\n }\n\n if (binding.kind === 'module') {\n // Modules are global by default\n return;\n }\n\n if (!['var', 'let', 'const', 'hoisted'].includes(binding.kind)) {\n // This is not a variable, we can't hoist it\n throw unsupported(binding.path, 'is a function parameter');\n }\n\n const { scope, path: bindingPath } = binding;\n // parent here can be null or undefined in different versions of babel\n if (!scope.parent) {\n // The variable is already in the root scope\n return;\n }\n\n if (bindingPath.isVariableDeclarator()) {\n hoistVariableDeclarator(bindingPath);\n\n return;\n }\n\n throw unsupported(idPath);\n}\n\n/**\n * Only an expression that can be evaluated in the root scope can be\n * used in a Linaria template. This function tries to hoist the expression.\n * @param ex The expression to hoist.\n * @param evaluate If true, we try to statically evaluate the expression.\n * @param imports All the imports of the file.\n */\nexport function extractExpression(\n ex: NodePath<Expression>,\n evaluate = false,\n imports: IImport[] = []\n): Omit<ExpressionValue, 'buildCodeFrameError' | 'source'> {\n if (\n ex.isLiteral() &&\n ('value' in ex.node || ex.node.type === 'NullLiteral')\n ) {\n return {\n ex: ex.node,\n kind: ValueType.CONST,\n value: ex.node.type === 'NullLiteral' ? null : ex.node.value,\n } as Omit<ConstValue, 'buildCodeFrameError' | 'source'>;\n }\n\n const { loc } = ex.node;\n\n const rootScope = ex.scope.getProgramParent();\n const statementInRoot = ex.findParent(\n (p) => p.parentPath?.isProgram() === true\n ) as NodePath<Statement>;\n\n const isFunction =\n ex.isFunctionExpression() || ex.isArrowFunctionExpression();\n\n // Generate next _expN name\n const expUid = rootScope.generateUid('exp');\n\n const evaluated = staticEval(ex, evaluate);\n\n if (!evaluated) {\n // If expression is not statically evaluable,\n // we need to hoist all its referenced identifiers\n\n // Collect all referenced identifiers\n findIdentifiers([ex], 'reference').forEach((id) => {\n if (!id.isIdentifier()) return;\n\n // Try to evaluate and inline them…\n const evaluatedId = staticEval(id, evaluate);\n if (evaluatedId) {\n mutate(id, (p) => {\n p.replaceWith(valueToLiteral(evaluatedId[0], ex));\n });\n } else {\n // … or hoist them to the root scope\n hoistIdentifier(id);\n }\n });\n }\n\n const kind = isFunction ? ValueType.FUNCTION : ValueType.LAZY;\n\n // Declare _expN const with the lazy expression\n const declaration = expressionDeclarationTpl({\n expId: createId(expUid),\n expression: evaluated\n ? valueToLiteral(evaluated[0], ex)\n : cloneNode(ex.node),\n }) as VariableDeclaration;\n\n // Insert the declaration as close as possible to the original expression\n const [inserted] = statementInRoot.insertBefore(declaration);\n referenceAll(inserted);\n rootScope.registerDeclaration(inserted);\n\n const importedFrom: string[] = [];\n function findImportSourceOfIdentifier(idPath: NodePath<Identifier>) {\n const exBindingIdentifier = idPath.scope.getBinding(idPath.node.name)\n ?.identifier;\n const exImport =\n imports.find((i) => i.local.node === exBindingIdentifier) ?? null;\n if (exImport) {\n importedFrom.push(exImport.source);\n }\n }\n\n if (ex.isIdentifier()) {\n findImportSourceOfIdentifier(ex);\n } else {\n ex.traverse({\n Identifier: findImportSourceOfIdentifier,\n });\n }\n\n // Replace the expression with the _expN() call\n mutate(ex, (p) => {\n p.replaceWith({\n type: 'CallExpression',\n callee: createId(expUid),\n arguments: [],\n });\n });\n\n // eslint-disable-next-line no-param-reassign\n ex.node.loc = loc;\n\n // noinspection UnnecessaryLocalVariableJS\n const result: Omit<\n LazyValue | FunctionValue,\n 'buildCodeFrameError' | 'source'\n > = {\n kind,\n ex: createId(expUid, loc),\n importedFrom,\n };\n\n return result;\n}\n\nconst debug = logger.extend('template-parse:identify-expressions');\n\n/**\n * Collects, hoists, and makes lazy all expressions in the given template\n * If evaluate is true, it will try to evaluate the expressions\n */\nexport function collectTemplateDependencies(\n path: NodePath<TaggedTemplateExpression>,\n evaluate = false\n): [quasis: TemplateElement[], expressionValues: ExpressionValue[]] {\n const quasi = path.get('quasi');\n const quasis = quasi.get('quasis');\n const expressions = quasi.get('expressions');\n\n debug('Found: %s', expressions.length);\n\n const expressionValues: ExpressionValue[] = expressions.map(\n (ex: NodePath<Expression | TSType>): ExpressionValue => {\n const buildCodeFrameError = ex.buildCodeFrameError.bind(ex);\n const source = getSource(ex);\n\n if (!ex.isExpression()) {\n throw buildCodeFrameError(\n `The expression '${source}' is not supported.`\n );\n }\n\n const extracted = extractExpression(ex, evaluate);\n\n return {\n ...extracted,\n source,\n buildCodeFrameError,\n } as ExpressionValue;\n }\n );\n\n return [quasis.map((p) => p.node), expressionValues];\n}\n"],"mappings":";;;;;;;AAOA,IAAAA,SAAA,GAAAC,OAAA;AAaA,IAAAC,MAAA,GAAAD,OAAA;AAQA,IAAAE,OAAA,GAAAF,OAAA;AAGA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AAnCA;;AAEA;AACA;AACA;AACA;;AAgCA,SAASQ,UAAUA,CACjBC,EAAwB,EACxBC,QAAQ,GAAG,KAAK,EACO;EACvB,IA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ACN3E;IACF,CAAC;EACH,CACF,CAAC;EAED,OAAO,CAACsF,MAAM,CAACI,GAAG,CAAEnE,CAAC,IAAKA,CAAC,CAAClB,IAAI,CAAC,EAAEoF,gBAAgB,CAAC;AACtD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createId = void 0;
|
|
7
|
+
const createId = (name, loc) => ({
|
|
8
|
+
type: 'Identifier',
|
|
9
|
+
name,
|
|
10
|
+
loc
|
|
11
|
+
});
|
|
12
|
+
exports.createId = createId;
|
|
13
|
+
//# sourceMappingURL=createId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createId.js","names":["createId","name","loc","type","exports"],"sources":["../../src/utils/createId.ts"],"sourcesContent":["import type { Identifier, SourceLocation } from '@babel/types';\n\nexport const createId = (\n name: string,\n loc?: SourceLocation | null\n): Identifier => ({\n type: 'Identifier',\n name,\n loc,\n});\n"],"mappings":";;;;;;AAEO,MAAMA,QAAQ,GAAGA,CACtBC,IAAY,EACZC,GAA2B,MACX;EAChBC,IAAI,EAAE,YAAY;EAClBF,IAAI;EACJC;AACF,CAAC,CAAC;AAACE,OAAA,CAAAJ,QAAA,GAAAA,QAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Symbol$dispose, _Symbol$asyncDispose;
|
|
4
|
+
// @ts-expect-error
|
|
5
|
+
(_Symbol$dispose = Symbol.dispose) !== null && _Symbol$dispose !== void 0 ? _Symbol$dispose : Symbol.dispose = Symbol('Symbol.dispose');
|
|
6
|
+
|
|
7
|
+
// @ts-expect-error
|
|
8
|
+
(_Symbol$asyncDispose = Symbol.asyncDispose) !== null && _Symbol$asyncDispose !== void 0 ? _Symbol$asyncDispose : Symbol.asyncDispose = Symbol('Symbol.asyncDispose');
|
|
9
|
+
//# sourceMappingURL=dispose-polyfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispose-polyfill.js","names":["_Symbol$dispose","Symbol","dispose","_Symbol$asyncDispose","asyncDispose"],"sources":["../../src/utils/dispose-polyfill.ts"],"sourcesContent":["// @ts-expect-error\nSymbol.dispose ??= Symbol('Symbol.dispose');\n\n// @ts-expect-error\nSymbol.asyncDispose ??= Symbol('Symbol.asyncDispose');\n"],"mappings":";;;AAAA;AACA,CAAAA,eAAA,GAAAC,MAAM,CAACC,OAAO,cAAAF,eAAA,cAAAA,eAAA,GAAdC,MAAM,CAACC,OAAO,GAAKD,MAAM,CAAC,gBAAgB,CAAC;;AAE3C;AACA,CAAAE,oBAAA,GAAAF,MAAM,CAACG,YAAY,cAAAD,oBAAA,cAAAA,oBAAA,GAAnBF,MAAM,CAACG,YAAY,GAAKH,MAAM,CAAC,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findIdentifiers = findIdentifiers;
|
|
7
|
+
exports.nonType = nonType;
|
|
8
|
+
var _getScope = require("./getScope");
|
|
9
|
+
function isInUnary(path) {
|
|
10
|
+
var _path$parentPath$isUn, _path$parentPath;
|
|
11
|
+
return (_path$parentPath$isUn = (_path$parentPath = path.parentPath) === null || _path$parentPath === void 0 ? void 0 : _path$parentPath.isUnaryExpression()) !== null && _path$parentPath$isUn !== void 0 ? _path$parentPath$isUn : false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// It's possible for non-strict mode code to have variable deletions.
|
|
15
|
+
function isInDelete(path) {
|
|
16
|
+
return path.parentPath.node.operator === 'delete';
|
|
17
|
+
}
|
|
18
|
+
function isBindingIdentifier(path) {
|
|
19
|
+
return path.isBindingIdentifier() && (!isInUnary(path) || isInDelete(path));
|
|
20
|
+
}
|
|
21
|
+
function isReferencedIdentifier(path) {
|
|
22
|
+
return path.isReferencedIdentifier() || isInUnary(path) && !isInDelete(path);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// For some reasons, `isBindingIdentifier` returns true for identifiers inside unary expressions.
|
|
26
|
+
const checkers = {
|
|
27
|
+
any: ex => isBindingIdentifier(ex) || isReferencedIdentifier(ex),
|
|
28
|
+
binding: ex => isBindingIdentifier(ex),
|
|
29
|
+
declaration: ex => {
|
|
30
|
+
var _ex$scope$getBinding;
|
|
31
|
+
return isBindingIdentifier(ex) && ((_ex$scope$getBinding = ex.scope.getBinding(ex.node.name)) === null || _ex$scope$getBinding === void 0 ? void 0 : _ex$scope$getBinding.identifier) === ex.node;
|
|
32
|
+
},
|
|
33
|
+
reference: ex => isReferencedIdentifier(ex)
|
|
34
|
+
};
|
|
35
|
+
function nonType(path) {
|
|
36
|
+
return !path.find(p => p.isTSTypeReference() || p.isTSTypeQuery() || p.isFlowType() || p.isFlowDeclaration() || p.isTSInterfaceDeclaration());
|
|
37
|
+
}
|
|
38
|
+
function findIdentifiers(expressions, type = 'reference') {
|
|
39
|
+
const identifiers = [];
|
|
40
|
+
expressions.forEach(ex => {
|
|
41
|
+
const emit = path => {
|
|
42
|
+
if (!path.node || path.removed || !checkers[type](path)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// TODO: Is there a better way to check that it's a local variable?
|
|
47
|
+
|
|
48
|
+
const binding = (0, _getScope.getScope)(path).getBinding(path.node.name);
|
|
49
|
+
if (!binding) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (type === 'reference' && ex.isAncestor(binding.path)) {
|
|
53
|
+
// This identifier is declared inside the expression. We don't need it.
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
identifiers.push(path);
|
|
57
|
+
};
|
|
58
|
+
if (ex.isIdentifier() || ex.isJSXIdentifier()) {
|
|
59
|
+
emit(ex);
|
|
60
|
+
} else {
|
|
61
|
+
ex.traverse({
|
|
62
|
+
Identifier(path) {
|
|
63
|
+
emit(path);
|
|
64
|
+
},
|
|
65
|
+
JSXIdentifier(path) {
|
|
66
|
+
emit(path);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return identifiers;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=findIdentifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findIdentifiers.js","names":["_getScope","require","isInUnary","path","_path$parentPath$isUn","_path$parentPath","parentPath","isUnaryExpression","isInDelete","node","operator","isBindingIdentifier","isReferencedIdentifier","checkers","any","ex","binding","declaration","_ex$scope$getBinding","scope","getBinding","name","identifier","reference","nonType","find","p","isTSTypeReference","isTSTypeQuery","isFlowType","isFlowDeclaration","isTSInterfaceDeclaration","findIdentifiers","expressions","type","identifiers","forEach","emit","removed","getScope","isAncestor","push","isIdentifier","isJSXIdentifier","traverse","Identifier","JSXIdentifier"],"sources":["../../src/utils/findIdentifiers.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type {\n Node,\n Identifier,\n JSXIdentifier,\n UnaryExpression,\n} from '@babel/types';\n\nimport { getScope } from './getScope';\n\ntype FindType = 'any' | 'binding' | 'declaration' | 'reference';\n\nfunction isInUnary<T extends NodePath>(\n path: T\n): path is T & { parentPath: NodePath<UnaryExpression> } {\n return path.parentPath?.isUnaryExpression() ?? false;\n}\n\n// It's possible for non-strict mode code to have variable deletions.\nfunction isInDelete(path: { parentPath: NodePath<UnaryExpression> }): boolean {\n return path.parentPath.node.operator === 'delete';\n}\n\nfunction isBindingIdentifier(path: NodePath): path is NodePath<Identifier> {\n return path.isBindingIdentifier() && (!isInUnary(path) || isInDelete(path));\n}\n\nfunction isReferencedIdentifier(\n path: NodePath\n): path is NodePath<Identifier | JSXIdentifier> {\n return (\n path.isReferencedIdentifier() || (isInUnary(path) && !isInDelete(path))\n );\n}\n\n// For some reasons, `isBindingIdentifier` returns true for identifiers inside unary expressions.\nconst checkers: Record<\n FindType,\n (ex: NodePath<Identifier | JSXIdentifier>) => boolean\n> = {\n any: (ex) => isBindingIdentifier(ex) || isReferencedIdentifier(ex),\n binding: (ex) => isBindingIdentifier(ex),\n declaration: (ex) =>\n isBindingIdentifier(ex) &&\n ex.scope.getBinding(ex.node.name)?.identifier === ex.node,\n reference: (ex) => isReferencedIdentifier(ex),\n};\n\nexport function nonType(path: NodePath): boolean {\n return !path.find(\n (p) =>\n p.isTSTypeReference() ||\n p.isTSTypeQuery() ||\n p.isFlowType() ||\n p.isFlowDeclaration() ||\n p.isTSInterfaceDeclaration()\n );\n}\n\nexport function findIdentifiers(\n expressions: NodePath<Node | null | undefined>[],\n type: FindType = 'reference'\n): NodePath<Identifier | JSXIdentifier>[] {\n const identifiers: NodePath<Identifier | JSXIdentifier>[] = [];\n\n expressions.forEach((ex) => {\n const emit = (path: NodePath<Identifier | JSXIdentifier>) => {\n if (!path.node || path.removed || !checkers[type](path)) {\n return;\n }\n\n // TODO: Is there a better way to check that it's a local variable?\n\n const binding = getScope(path).getBinding(path.node.name);\n if (!binding) {\n return;\n }\n\n if (type === 'reference' && ex.isAncestor(binding.path)) {\n // This identifier is declared inside the expression. We don't need it.\n return;\n }\n\n identifiers.push(path);\n };\n\n if (ex.isIdentifier() || ex.isJSXIdentifier()) {\n emit(ex);\n } else {\n ex.traverse({\n Identifier(path: NodePath<Identifier>) {\n emit(path);\n },\n JSXIdentifier(path: NodePath<JSXIdentifier>) {\n emit(path);\n },\n });\n }\n });\n\n return identifiers;\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,SAAA,GAAAC,OAAA;AAIA,SAASC,SAASA,CAChBC,IAAO,EACgD;EAAA,IAAAC,qBAAA,EAAAC,gBAAA;EACvD,QAAAD,qBAAA,IAAAC,gBAAA,GAAOF,IAAI,CAACG,UAAU,cAAAD,gBAAA,uBAAfA,gBAAA,CAAi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3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findPackageJSON = findPackageJSON;
|
|
7
|
+
var _path = require("path");
|
|
8
|
+
var _findUp = _interopRequireDefault(require("find-up"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
function findPackageJSON(pkgName, filename) {
|
|
12
|
+
try {
|
|
13
|
+
const pkgPath = pkgName === '.' && filename && (0, _path.isAbsolute)(filename) ? filename : require.resolve(pkgName, filename ? {
|
|
14
|
+
paths: [(0, _path.dirname)(filename)]
|
|
15
|
+
} : {});
|
|
16
|
+
if (!cache.has(pkgPath)) {
|
|
17
|
+
cache.set(pkgPath, _findUp.default.sync('package.json', {
|
|
18
|
+
cwd: pkgPath
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
return cache.get(pkgPath);
|
|
22
|
+
} catch (er) {
|
|
23
|
+
if (typeof er === 'object' && er !== null && er.code === 'MODULE_NOT_FOUND') {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
throw er;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=findPackageJSON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findPackageJSON.js","names":["_path","require","_findUp","_interopRequireDefault","obj","__esModule","default","cache","Map","findPackageJSON","pkgName","filename","pkgPath","isAbsolute","resolve","paths","dirname","has","set","findUp","sync","cwd","get","er","code","undefined"],"sources":["../../src/utils/findPackageJSON.ts"],"sourcesContent":["import { dirname, isAbsolute } from 'path';\n\nimport findUp from 'find-up';\n\nconst cache = new Map<string, string | undefined>();\n\nexport function findPackageJSON(\n pkgName: string,\n filename: string | null | undefined\n) {\n try {\n const pkgPath =\n pkgName === '.' && filename && isAbsolute(filename)\n ? filename\n : require.resolve(\n pkgName,\n filename ? { paths: [dirname(filename)] } : {}\n );\n if (!cache.has(pkgPath)) {\n cache.set(pkgPath, findUp.sync('package.json', { cwd: pkgPath }));\n }\n\n return cache.get(pkgPath);\n } catch (er: unknown) {\n if (\n typeof er === 'object' &&\n er !== null &&\n (er as { code?: unknown }).code === 'MODULE_NOT_FOUND'\n ) {\n return undefined;\n }\n\n throw er;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA6B,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE7B,MAAMG,KAAK,GAAG,IAAIC,GAAG,CAA6B,CAAC;AAE5C,SAASC,eAAeA,CAC7BC,OAAe,EACfC,QAAmC,EACnC;EACA,IAAI;IACF,MAAMC,OAAO,GACXF,OAAO,KAAK,GAAG,IAAIC,QAAQ,IAAI,IAAAE,gBAAU,EAACF,QAAQ,CAAC,GAC/CA,QAAQ,GACRV,OAAO,CAACa,OAAO,CACbJ,OAAO,EACPC,QAAQ,GAAG;MAAEI,KAAK,EAAE,CAAC,IAAAC,aAAO,EAACL,QAAQ,CAAC;IAAE,CAAC,GAAG,CAAC,CAC/C,CAAC;IACP,IAAI,CAACJ,KAAK,CAACU,GAAG,CAACL,OAAO,CAAC,EAAE;MACvBL,KAAK,CAACW,GAAG,CAACN,OAAO,EAAEO,eAAM,CAACC,IAAI,CAAC,cAAc,EAAE;QAAEC,GAAG,EAAET;MAAQ,CAAC,CAAC,CAAC;IACnE;IAEA,OAAOL,KAAK,CAACe,GAAG,CAACV,OAAO,CAAC;EAC3B,CAAC,CAAC,OAAOW,EAAW,EAAE;IACpB,IACE,OAAOA,EAAE,KAAK,QAAQ,IACtBA,EAAE,KAAK,IAAI,IACVA,EAAE,CAAwBC,IAAI,KAAK,kBAAkB,EACtD;MACA,OAAOC,SAAS;IAClB;IAEA,MAAMF,EAAE;EACV;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFileIdx = getFileIdx;
|
|
7
|
+
let nextIdx = 1;
|
|
8
|
+
const processed = new Map();
|
|
9
|
+
function getFileIdx(name) {
|
|
10
|
+
if (!processed.has(name)) {
|
|
11
|
+
// eslint-disable-next-line no-plusplus
|
|
12
|
+
processed.set(name, nextIdx++);
|
|
13
|
+
}
|
|
14
|
+
return processed.get(name).toString().padStart(5, '0');
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getFileIdx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFileIdx.js","names":["nextIdx","processed","Map","getFileIdx","name","has","set","get","toString","padStart"],"sources":["../../src/utils/getFileIdx.ts"],"sourcesContent":["let nextIdx = 1;\nconst processed = new Map<string, number>();\n\nexport function getFileIdx(name: string): string {\n if (!processed.has(name)) {\n // eslint-disable-next-line no-plusplus\n processed.set(name, nextIdx++);\n }\n\n return processed.get(name)!.toString().padStart(5, '0');\n}\n"],"mappings":";;;;;;AAAA,IAAIA,OAAO,GAAG,CAAC;AACf,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAiB,CAAC;AAEpC,SAASC,UAAUA,CAACC,IAAY,EAAU;EAC/C,IAAI,CAACH,SAAS,CAACI,GAAG,CAACD,IAAI,CAAC,EAAE;IACxB;IACAH,SAAS,CAACK,GAAG,CAACF,IAAI,EAAEJ,OAAO,EAAE,CAAC;EAChC;EAEA,OAAOC,SAAS,CAACM,GAAG,CAACH,IAAI,CAAC,CAAEI,QAAQ,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;AACzD"}
|