@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":["logger","getScope","isExports","isNotNull","isRequire","isTypedNode","getTraversalCache","sideEffectImport","item","imported","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","map","key","isIdentifier","reverse","what","as","isRestElement","argument","debug","extend","importFromVariableDeclarator","isSync","id","isObjectPattern","findIIFE","isCallExpression","isFunctionExpression","exportFromVariableDeclarator","init","binding","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","processedRequires","has","add","reexports","exported","variableDeclarator","unfolded","isExpressionStatement","collectFromVariableDeclarator","found","identifierPath","skip","isChainOfVoidAssignment","right","isUnaryExpression","operator","isAssignmentExpression","getReturnValue","params","body","returnStatement","isReturnStatement","getGetterValueFromDescriptor","descriptor","props","getter","isArrowFunctionExpression","valueProp","valueValue","addExport","getRelatedImport","object","objectBinding","scope","i","some","isAncestor","computed","import","relatedImport","exports","collectFromExports","memberExpression","exportName","saveRef","exportRefs","set","assignmentExpression","left","isEsModule","matchesPattern","obj","isObjectExpression","collectFromRequireOrExports","importItem","referenced","referencePath","ancestor","isTSType","isFlowType","listKey","importType","isExportSpecifier","isExportDefaultDeclaration","collectFromExportAllDeclaration","collectFromExportSpecifier","isExportDefaultSpecifier","isExportNamespaceSpecifier","collectFromExportNamedDeclaration","declaration","isVariableDeclaration","declarator","isTSEnumDeclaration","isFunctionDeclaration","isClassDeclaration","collectFromExportDefaultDeclaration","default","collectFromAssignmentExpression","collectFromExportStarCall","requireCall","collectFromMap","properties","isFunction","returnValue","collectFromEsbuildExportCall","sourceExports","collectFromEsbuildReExportCall","collectFromSwcExportCall","collectFromCallExpression","maybeExportStart","collectExportsAndImports","cacheMode","localState","deadExports","Map","sourceType","WeakSet","cache","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":"AAAA;AACA;;AA6BA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ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Q;IAC7C/F,iBAAiB,EAAE,IAAIgG,OAAO,CAAC;EACjC,CAAC;EAED,MAAMC,KAAK,GACTN,SAAS,KAAK,UAAU,GACpB3L,iBAAiB,CAASgB,IAAI,EAAE,0BAA0B,CAAC,GAC3D2E,SAAS;EAEf,IAAIgG,SAAS,KAAK,SAAS,IAAIM,KAAK,EAAEhG,GAAG,CAACjF,IAAI,CAAC,EAAE;IAC/C,OAAOiL,KAAK,CAAC/K,GAAG,CAACF,IAAI,CAAC,IAAI4K,UAAU;EACtC;EAEA5K,IAAI,CAACyB,QAAQ,CACX;IACEyJ,oBAAoB,EAAErB,+BAA+B;IACrDsB,cAAc,EAAEX,yBAAyB;IACzCY,oBAAoB,EAAEpC,+BAA+B;IACrDqC,wBAAwB,EAAE1B,mCAAmC;IAC7D2B,sBAAsB,EAAElC,iCAAiC;IACzDmC,iBAAiB,EAAEhL,4BAA4B;IAC/CiL,MAAM,EAAE1H,wBAAwB;IAChCpC,UAAU,EAAE2G,2BAA2B;IACvCoD,kBAAkB,EAAEjG;EACtB,CAAC,EACDoF,UACF,CAAC;EAED,MAAM;IAAE5F,iBAAiB;IAAE,GAAGxE;EAAM,CAAC,GAAGoK,UAAU;EAElDK,KAAK,EAAEnD,GAAG,CAAC9H,IAAI,EAAEQ,KAAK,CAAC;EAEvB,OAAOA,KAAK;AACd"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This file is a visitor that checks TaggedTemplateExpressions and look for Linaria css or styled templates.
|
|
5
|
+
* For each template it makes a list of dependencies, try to evaluate expressions, and if it is not possible, mark them as lazy dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { statement } from '@babel/template';
|
|
9
|
+
import { cloneNode } from '@babel/types';
|
|
10
|
+
import { hasEvalMeta, ValueType, logger } from '@wyw-in-js/shared';
|
|
11
|
+
import { createId } from './createId';
|
|
12
|
+
import { findIdentifiers } from './findIdentifiers';
|
|
13
|
+
import { getSource } from './getSource';
|
|
14
|
+
import { mutate, referenceAll } from './scopeHelpers';
|
|
15
|
+
import { valueToLiteral } from './valueToLiteral';
|
|
16
|
+
function staticEval(ex, evaluate = false) {
|
|
17
|
+
if (!evaluate) return undefined;
|
|
18
|
+
const result = ex.evaluate();
|
|
19
|
+
if (result.confident && !hasEvalMeta(result.value)) {
|
|
20
|
+
return [result.value];
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const expressionDeclarationTpl = statement('const %%expId%% = /*#__PURE__*/ () => %%expression%%', {
|
|
25
|
+
preserveComments: true
|
|
26
|
+
});
|
|
27
|
+
const unsupported = (ex, reason) => ex.buildCodeFrameError(`This ${ex.isIdentifier() ? 'identifier' : 'expression'} cannot be used in the template${reason ? `, because it ${reason}` : ''}.`);
|
|
28
|
+
function getUidInRootScope(path) {
|
|
29
|
+
const {
|
|
30
|
+
name
|
|
31
|
+
} = path.node;
|
|
32
|
+
const rootScope = path.scope.getProgramParent();
|
|
33
|
+
if (rootScope.hasBinding(name)) {
|
|
34
|
+
return rootScope.generateUid(name);
|
|
35
|
+
}
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
function hoistVariableDeclarator(ex) {
|
|
39
|
+
if (!ex.scope.parent) {
|
|
40
|
+
// It is already in the root scope
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const referencedIdentifiers = findIdentifiers([ex], 'reference');
|
|
44
|
+
referencedIdentifiers.forEach(identifier => {
|
|
45
|
+
if (identifier.isIdentifier()) {
|
|
46
|
+
hoistIdentifier(identifier);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const bindingIdentifiers = findIdentifiers([ex], 'declaration');
|
|
50
|
+
bindingIdentifiers.forEach(path => {
|
|
51
|
+
const newName = getUidInRootScope(path);
|
|
52
|
+
if (newName !== path.node.name) {
|
|
53
|
+
path.scope.rename(path.node.name, newName);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const rootScope = ex.scope.getProgramParent();
|
|
57
|
+
const statementInRoot = ex.findParent(p => p.parentPath?.isProgram() === true);
|
|
58
|
+
const declaration = {
|
|
59
|
+
type: 'VariableDeclaration',
|
|
60
|
+
kind: 'let',
|
|
61
|
+
declarations: [cloneNode(ex.node)]
|
|
62
|
+
};
|
|
63
|
+
const [inserted] = statementInRoot.insertBefore(declaration);
|
|
64
|
+
referenceAll(inserted);
|
|
65
|
+
rootScope.registerDeclaration(inserted);
|
|
66
|
+
}
|
|
67
|
+
function hoistIdentifier(idPath) {
|
|
68
|
+
if (!idPath.isReferenced()) {
|
|
69
|
+
throw unsupported(idPath);
|
|
70
|
+
}
|
|
71
|
+
const binding = idPath.scope.getBinding(idPath.node.name);
|
|
72
|
+
if (!binding) {
|
|
73
|
+
// It's something strange
|
|
74
|
+
throw unsupported(idPath, 'is undefined');
|
|
75
|
+
}
|
|
76
|
+
if (binding.kind === 'module') {
|
|
77
|
+
// Modules are global by default
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!['var', 'let', 'const', 'hoisted'].includes(binding.kind)) {
|
|
81
|
+
// This is not a variable, we can't hoist it
|
|
82
|
+
throw unsupported(binding.path, 'is a function parameter');
|
|
83
|
+
}
|
|
84
|
+
const {
|
|
85
|
+
scope,
|
|
86
|
+
path: bindingPath
|
|
87
|
+
} = binding;
|
|
88
|
+
// parent here can be null or undefined in different versions of babel
|
|
89
|
+
if (!scope.parent) {
|
|
90
|
+
// The variable is already in the root scope
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (bindingPath.isVariableDeclarator()) {
|
|
94
|
+
hoistVariableDeclarator(bindingPath);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
throw unsupported(idPath);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Only an expression that can be evaluated in the root scope can be
|
|
102
|
+
* used in a Linaria template. This function tries to hoist the expression.
|
|
103
|
+
* @param ex The expression to hoist.
|
|
104
|
+
* @param evaluate If true, we try to statically evaluate the expression.
|
|
105
|
+
* @param imports All the imports of the file.
|
|
106
|
+
*/
|
|
107
|
+
export function extractExpression(ex, evaluate = false, imports = []) {
|
|
108
|
+
if (ex.isLiteral() && ('value' in ex.node || ex.node.type === 'NullLiteral')) {
|
|
109
|
+
return {
|
|
110
|
+
ex: ex.node,
|
|
111
|
+
kind: ValueType.CONST,
|
|
112
|
+
value: ex.node.type === 'NullLiteral' ? null : ex.node.value
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const {
|
|
116
|
+
loc
|
|
117
|
+
} = ex.node;
|
|
118
|
+
const rootScope = ex.scope.getProgramParent();
|
|
119
|
+
const statementInRoot = ex.findParent(p => p.parentPath?.isProgram() === true);
|
|
120
|
+
const isFunction = ex.isFunctionExpression() || ex.isArrowFunctionExpression();
|
|
121
|
+
|
|
122
|
+
// Generate next _expN name
|
|
123
|
+
const expUid = rootScope.generateUid('exp');
|
|
124
|
+
const evaluated = staticEval(ex, evaluate);
|
|
125
|
+
if (!evaluated) {
|
|
126
|
+
// If expression is not statically evaluable,
|
|
127
|
+
// we need to hoist all its referenced identifiers
|
|
128
|
+
|
|
129
|
+
// Collect all referenced identifiers
|
|
130
|
+
findIdentifiers([ex], 'reference').forEach(id => {
|
|
131
|
+
if (!id.isIdentifier()) return;
|
|
132
|
+
|
|
133
|
+
// Try to evaluate and inline them…
|
|
134
|
+
const evaluatedId = staticEval(id, evaluate);
|
|
135
|
+
if (evaluatedId) {
|
|
136
|
+
mutate(id, p => {
|
|
137
|
+
p.replaceWith(valueToLiteral(evaluatedId[0], ex));
|
|
138
|
+
});
|
|
139
|
+
} else {
|
|
140
|
+
// … or hoist them to the root scope
|
|
141
|
+
hoistIdentifier(id);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const kind = isFunction ? ValueType.FUNCTION : ValueType.LAZY;
|
|
146
|
+
|
|
147
|
+
// Declare _expN const with the lazy expression
|
|
148
|
+
const declaration = expressionDeclarationTpl({
|
|
149
|
+
expId: createId(expUid),
|
|
150
|
+
expression: evaluated ? valueToLiteral(evaluated[0], ex) : cloneNode(ex.node)
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Insert the declaration as close as possible to the original expression
|
|
154
|
+
const [inserted] = statementInRoot.insertBefore(declaration);
|
|
155
|
+
referenceAll(inserted);
|
|
156
|
+
rootScope.registerDeclaration(inserted);
|
|
157
|
+
const importedFrom = [];
|
|
158
|
+
function findImportSourceOfIdentifier(idPath) {
|
|
159
|
+
const exBindingIdentifier = idPath.scope.getBinding(idPath.node.name)?.identifier;
|
|
160
|
+
const exImport = imports.find(i => i.local.node === exBindingIdentifier) ?? null;
|
|
161
|
+
if (exImport) {
|
|
162
|
+
importedFrom.push(exImport.source);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (ex.isIdentifier()) {
|
|
166
|
+
findImportSourceOfIdentifier(ex);
|
|
167
|
+
} else {
|
|
168
|
+
ex.traverse({
|
|
169
|
+
Identifier: findImportSourceOfIdentifier
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Replace the expression with the _expN() call
|
|
174
|
+
mutate(ex, p => {
|
|
175
|
+
p.replaceWith({
|
|
176
|
+
type: 'CallExpression',
|
|
177
|
+
callee: createId(expUid),
|
|
178
|
+
arguments: []
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// eslint-disable-next-line no-param-reassign
|
|
183
|
+
ex.node.loc = loc;
|
|
184
|
+
|
|
185
|
+
// noinspection UnnecessaryLocalVariableJS
|
|
186
|
+
const result = {
|
|
187
|
+
kind,
|
|
188
|
+
ex: createId(expUid, loc),
|
|
189
|
+
importedFrom
|
|
190
|
+
};
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
const debug = logger.extend('template-parse:identify-expressions');
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Collects, hoists, and makes lazy all expressions in the given template
|
|
197
|
+
* If evaluate is true, it will try to evaluate the expressions
|
|
198
|
+
*/
|
|
199
|
+
export function collectTemplateDependencies(path, evaluate = false) {
|
|
200
|
+
const quasi = path.get('quasi');
|
|
201
|
+
const quasis = quasi.get('quasis');
|
|
202
|
+
const expressions = quasi.get('expressions');
|
|
203
|
+
debug('Found: %s', expressions.length);
|
|
204
|
+
const expressionValues = expressions.map(ex => {
|
|
205
|
+
const buildCodeFrameError = ex.buildCodeFrameError.bind(ex);
|
|
206
|
+
const source = getSource(ex);
|
|
207
|
+
if (!ex.isExpression()) {
|
|
208
|
+
throw buildCodeFrameError(`The expression '${source}' is not supported.`);
|
|
209
|
+
}
|
|
210
|
+
const extracted = extractExpression(ex, evaluate);
|
|
211
|
+
return {
|
|
212
|
+
...extracted,
|
|
213
|
+
source,
|
|
214
|
+
buildCodeFrameError
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
return [quasis.map(p => p.node), expressionValues];
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=collectTemplateDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectTemplateDependencies.js","names":["statement","cloneNode","hasEvalMeta","ValueType","logger","createId","findIdentifiers","getSource","mutate","referenceAll","valueToLiteral","staticEval","ex","evaluate","undefined","result","confident","value","expressionDeclarationTpl","preserveComments","unsupported","reason","buildCodeFrameError","isIdentifier","getUidInRootScope","path","name","node","rootScope","scope","getProgramParent","hasBinding","generateUid","hoistVariableDeclarator","parent","referencedIdentifiers","forEach","identifier","hoistIdentifier","bindingIdentifiers","newName","rename","statementInRoot","findParent","p","parentPath","isProgram","declaration","type","kind","declarations","inserted","insertBefore","registerDeclaration","idPath","isReferenced","binding","getBinding","includes","bindingPath","isVariableDeclarator","extractExpression","imports","isLiteral","CONST","loc","isFunction","isFunctionExpression","isArrowFunctionExpression","expUid","evaluated","id","evaluatedId","replaceWith","FUNCTION","LAZY","expId","expression","importedFrom","findImportSourceOfIdentifier","exBindingIdentifier","exImport","find","i","local","push","source","traverse","Identifier","callee","arguments","debug","extend","collectTemplateDependencies","quasi","get","quasis","expressions","length","expressionValues","map","bind","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":"AAAA;;AAEA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,QAAQ,iBAAiB;AAa3C,SAASC,SAAS,QAAQ,cAAc;AAQxC,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,mBAAmB;AAGlE,SAASC,QAAQ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1
|
+
{"version":3,"file":"createId.js","names":["createId","name","loc","type"],"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":"AAEA,OAAO,MAAMA,QAAQ,GAAGA,CACtBC,IAAY,EACZC,GAA2B,MACX;EAChBC,IAAI,EAAE,YAAY;EAClBF,IAAI;EACJC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispose-polyfill.js","names":["Symbol","dispose","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;AACAA,MAAM,CAACC,OAAO,KAAKD,MAAM,CAAC,gBAAgB,CAAC;;AAE3C;AACAA,MAAM,CAACE,YAAY,KAAKF,MAAM,CAAC,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getScope } from './getScope';
|
|
2
|
+
function isInUnary(path) {
|
|
3
|
+
return path.parentPath?.isUnaryExpression() ?? false;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// It's possible for non-strict mode code to have variable deletions.
|
|
7
|
+
function isInDelete(path) {
|
|
8
|
+
return path.parentPath.node.operator === 'delete';
|
|
9
|
+
}
|
|
10
|
+
function isBindingIdentifier(path) {
|
|
11
|
+
return path.isBindingIdentifier() && (!isInUnary(path) || isInDelete(path));
|
|
12
|
+
}
|
|
13
|
+
function isReferencedIdentifier(path) {
|
|
14
|
+
return path.isReferencedIdentifier() || isInUnary(path) && !isInDelete(path);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// For some reasons, `isBindingIdentifier` returns true for identifiers inside unary expressions.
|
|
18
|
+
const checkers = {
|
|
19
|
+
any: ex => isBindingIdentifier(ex) || isReferencedIdentifier(ex),
|
|
20
|
+
binding: ex => isBindingIdentifier(ex),
|
|
21
|
+
declaration: ex => isBindingIdentifier(ex) && ex.scope.getBinding(ex.node.name)?.identifier === ex.node,
|
|
22
|
+
reference: ex => isReferencedIdentifier(ex)
|
|
23
|
+
};
|
|
24
|
+
export function nonType(path) {
|
|
25
|
+
return !path.find(p => p.isTSTypeReference() || p.isTSTypeQuery() || p.isFlowType() || p.isFlowDeclaration() || p.isTSInterfaceDeclaration());
|
|
26
|
+
}
|
|
27
|
+
export function findIdentifiers(expressions, type = 'reference') {
|
|
28
|
+
const identifiers = [];
|
|
29
|
+
expressions.forEach(ex => {
|
|
30
|
+
const emit = path => {
|
|
31
|
+
if (!path.node || path.removed || !checkers[type](path)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TODO: Is there a better way to check that it's a local variable?
|
|
36
|
+
|
|
37
|
+
const binding = getScope(path).getBinding(path.node.name);
|
|
38
|
+
if (!binding) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (type === 'reference' && ex.isAncestor(binding.path)) {
|
|
42
|
+
// This identifier is declared inside the expression. We don't need it.
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
identifiers.push(path);
|
|
46
|
+
};
|
|
47
|
+
if (ex.isIdentifier() || ex.isJSXIdentifier()) {
|
|
48
|
+
emit(ex);
|
|
49
|
+
} else {
|
|
50
|
+
ex.traverse({
|
|
51
|
+
Identifier(path) {
|
|
52
|
+
emit(path);
|
|
53
|
+
},
|
|
54
|
+
JSXIdentifier(path) {
|
|
55
|
+
emit(path);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return identifiers;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=findIdentifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findIdentifiers.js","names":["getScope","isInUnary","path","parentPath","isUnaryExpression","isInDelete","node","operator","isBindingIdentifier","isReferencedIdentifier","checkers","any","ex","binding","declaration","scope","getBinding","name","identifier","reference","nonType","find","p","isTSTypeReference","isTSTypeQuery","isFlowType","isFlowDeclaration","isTSInterfaceDeclaration","findIdentifiers","expressions","type","identifiers","forEach","emit","removed","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,SAASA,QAAQ,QAAQ,YAAY;AAIrC,SAASC,SAASA,CAChBC,IAAO,EACgD;EACvD,OAAOA,IAAI,CAACC,UAAU,EAAEC,iBAAiB,CAAC,CAAC,IAAI,KAAK;AACtD;;AAEA;AACA,SAASC,UAAUA,CAACH,IAA+C,EAAW;EAC5E,OAAOA,IAAI,CAACC,UAAU,CAACG,IAAI,CAACC,QAAQ,KAAK,QAAQ;AACnD;AAEA,SAASC,mBAAmBA,CAACN,IAAc,EAAgC;EACzE,OAAOA,IAAI,CAACM,mBAAmB,CAAC,CAAC,KAAK,CAACP,SAAS,CAACC,IAAI,CAAC,IAAIG,UAAU,CAACH,IAAI,CAAC,CAAC;AAC7E;AAEA,SAASO,sBAAsBA,CAC7BP,IAAc,EACgC;EAC9C,OACEA,IAAI,CAACO,sBAAsB,CAAC,CAAC,IAAKR,SAAS,CAACC,IAAI,CAAC,IAAI,CAACG,UAAU,CAACH,IAA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QACZ;MACF;MAEA,IAAIiB,IAAI,KAAK,WAAW,IAAIlB,EAAE,CAACuB,UAAU,CAACtB,OAAO,CAACX,IAAI,CAAC,EAAE;QACvD;QACA;MACF;MAEA6B,WAAW,CAACK,IAAI,CAAClC,IAAI,CAAC;IACxB,CAAC;IAED,IAAIU,EAAE,CAACyB,YAAY,CAAC,CAAC,IAAIzB,EAAE,CAAC0B,eAAe,CAAC,CAAC,EAAE;MAC7CL,IAAI,CAACrB,EAAE,CAAC;IACV,CAAC,MAAM;MACLA,EAAE,CAAC2B,QAAQ,CAAC;QACVC,UAAUA,CAACtC,IAA0B,EAAE;UACrC+B,IAAI,CAAC/B,IAAI,CAAC;QACZ,CAAC;QACDuC,aAAaA,CAACvC,IAA6B,EAAE;UAC3C+B,IAAI,CAAC/B,IAAI,CAAC;QACZ;MACF,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EAEF,OAAO6B,WAAW;AACpB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dirname, isAbsolute } from 'path';
|
|
2
|
+
import findUp from 'find-up';
|
|
3
|
+
const cache = new Map();
|
|
4
|
+
export function findPackageJSON(pkgName, filename) {
|
|
5
|
+
try {
|
|
6
|
+
const pkgPath = pkgName === '.' && filename && isAbsolute(filename) ? filename : require.resolve(pkgName, filename ? {
|
|
7
|
+
paths: [dirname(filename)]
|
|
8
|
+
} : {});
|
|
9
|
+
if (!cache.has(pkgPath)) {
|
|
10
|
+
cache.set(pkgPath, findUp.sync('package.json', {
|
|
11
|
+
cwd: pkgPath
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
return cache.get(pkgPath);
|
|
15
|
+
} catch (er) {
|
|
16
|
+
if (typeof er === 'object' && er !== null && er.code === 'MODULE_NOT_FOUND') {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
throw er;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=findPackageJSON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findPackageJSON.js","names":["dirname","isAbsolute","findUp","cache","Map","findPackageJSON","pkgName","filename","pkgPath","require","resolve","paths","has","set","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,SAASA,OAAO,EAAEC,UAAU,QAAQ,MAAM;AAE1C,OAAOC,MAAM,MAAM,SAAS;AAE5B,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAA6B,CAAC;AAEnD,OAAO,SAASC,eAAeA,CAC7BC,OAAe,EACfC,QAAmC,EACnC;EACA,IAAI;IACF,MAAMC,OAAO,GACXF,OAAO,KAAK,GAAG,IAAIC,QAAQ,IAAIN,UAAU,CAACM,QAAQ,CAAC,GAC/CA,QAAQ,GACRE,OAAO,CAACC,OAAO,CACbJ,OAAO,EACPC,QAAQ,GAAG;MAAEI,KAAK,EAAE,CAACX,OAAO,CAACO,QAAQ,CAAC;IAAE,CAAC,GAAG,CAAC,CAC/C,CAAC;IACP,IAAI,CAACJ,KAAK,CAACS,GAAG,CAACJ,OAAO,CAAC,EAAE;MACvBL,KAAK,CAACU,GAAG,CAACL,OAAO,EAAEN,MAAM,CAACY,IAAI,CAAC,cAAc,EAAE;QAAEC,GAAG,EAAEP;MAAQ,CAAC,CAAC,CAAC;IACnE;IAEA,OAAOL,KAAK,CAACa,GAAG,CAACR,OAAO,CAAC;EAC3B,CAAC,CAAC,OAAOS,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,10 @@
|
|
|
1
|
+
let nextIdx = 1;
|
|
2
|
+
const processed = new Map();
|
|
3
|
+
export function getFileIdx(name) {
|
|
4
|
+
if (!processed.has(name)) {
|
|
5
|
+
// eslint-disable-next-line no-plusplus
|
|
6
|
+
processed.set(name, nextIdx++);
|
|
7
|
+
}
|
|
8
|
+
return processed.get(name).toString().padStart(5, '0');
|
|
9
|
+
}
|
|
10
|
+
//# 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;AAE3C,OAAO,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getPluginKey = plugin => {
|
|
2
|
+
if (typeof plugin === 'string') {
|
|
3
|
+
return plugin;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(plugin)) {
|
|
6
|
+
return getPluginKey(plugin[0]);
|
|
7
|
+
}
|
|
8
|
+
if (typeof plugin === 'object' && plugin !== null && 'key' in plugin) {
|
|
9
|
+
return plugin.key ?? null;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=getPluginKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPluginKey.js","names":["getPluginKey","plugin","Array","isArray","key"],"sources":["../../src/utils/getPluginKey.ts"],"sourcesContent":["import type { PluginItem } from '@babel/core';\n\nexport const getPluginKey = (plugin: PluginItem): string | null => {\n if (typeof plugin === 'string') {\n return plugin;\n }\n\n if (Array.isArray(plugin)) {\n return getPluginKey(plugin[0]);\n }\n\n if (typeof plugin === 'object' && plugin !== null && 'key' in plugin) {\n return (plugin as { key?: string | null }).key ?? null;\n }\n\n return null;\n};\n"],"mappings":"AAEA,OAAO,MAAMA,YAAY,GAAIC,MAAkB,IAAoB;EACjE,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EAEA,IAAIC,KAAK,CAACC,OAAO,CAACF,MAAM,CAAC,EAAE;IACzB,OAAOD,YAAY,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC;EAChC;EAEA,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAIA,MAAM,KAAK,IAAI,IAAI,KAAK,IAAIA,MAAM,EAAE;IACpE,OAAQA,MAAM,CAA6BG,GAAG,IAAI,IAAI;EACxD;EAEA,OAAO,IAAI;AACb,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function getScope(path) {
|
|
2
|
+
// In some nodes (like FunctionDeclaration) `scope` for `id` returns
|
|
3
|
+
// local function scope instead of a scope where function is declared.
|
|
4
|
+
return path.key === 'id' && path.parent === path.scope.block ? path.scope.parent : path.scope;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=getScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getScope.js","names":["getScope","path","key","parent","scope","block"],"sources":["../../src/utils/getScope.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\n\nexport function getScope(path: NodePath) {\n // In some nodes (like FunctionDeclaration) `scope` for `id` returns\n // local function scope instead of a scope where function is declared.\n return path.key === 'id' && path.parent === path.scope.block\n ? path.scope.parent\n : path.scope;\n}\n"],"mappings":"AAEA,OAAO,SAASA,QAAQA,CAACC,IAAc,EAAE;EACvC;EACA;EACA,OAAOA,IAAI,CAACC,GAAG,KAAK,IAAI,IAAID,IAAI,CAACE,MAAM,KAAKF,IAAI,CAACG,KAAK,CAACC,KAAK,GACxDJ,IAAI,CAACG,KAAK,CAACD,MAAM,GACjBF,IAAI,CAACG,KAAK;AAChB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import generator from '@babel/generator';
|
|
2
|
+
export const getSource = (path, force = false) => {
|
|
3
|
+
if (path.isIdentifier()) {
|
|
4
|
+
// Fast-lane for identifiers
|
|
5
|
+
return path.node.name;
|
|
6
|
+
}
|
|
7
|
+
let source;
|
|
8
|
+
try {
|
|
9
|
+
source = force ? undefined : path.getSource();
|
|
10
|
+
// eslint-disable-next-line no-empty
|
|
11
|
+
} catch {}
|
|
12
|
+
source = source || generator(path.node).code;
|
|
13
|
+
return path.node.extra?.parenthesized ? `(${source})` : source;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=getSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSource.js","names":["generator","getSource","path","force","isIdentifier","node","name","source","undefined","code","extra","parenthesized"],"sources":["../../src/utils/getSource.ts"],"sourcesContent":["import generator from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\n\nexport const getSource = (path: NodePath, force = false): string => {\n if (path.isIdentifier()) {\n // Fast-lane for identifiers\n return path.node.name;\n }\n\n let source: string | undefined;\n try {\n source = force ? undefined : path.getSource();\n // eslint-disable-next-line no-empty\n } catch {}\n\n source = source || generator(path.node).code;\n\n return path.node.extra?.parenthesized ? `(${source})` : source;\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,kBAAkB;AAGxC,OAAO,MAAMC,SAAS,GAAGA,CAACC,IAAc,EAAEC,KAAK,GAAG,KAAK,KAAa;EAClE,IAAID,IAAI,CAACE,YAAY,CAAC,CAAC,EAAE;IACvB;IACA,OAAOF,IAAI,CAACG,IAAI,CAACC,IAAI;EACvB;EAEA,IAAIC,MAA0B;EAC9B,IAAI;IACFA,MAAM,GAAGJ,KAAK,GAAGK,SAAS,GAAGN,IAAI,CAACD,SAAS,CAAC,CAAC;IAC7C;EACF,CAAC,CAAC,MAAM,CAAC;EAETM,MAAM,GAAGA,MAAM,IAAIP,SAAS,CAACE,IAAI,CAACG,IAAI,CAAC,CAACI,IAAI;EAE5C,OAAOP,IAAI,CAACG,IAAI,CAACK,KAAK,EAAEC,aAAa,GAAI,IAAGJ,MAAO,GAAE,GAAGA,MAAM;AAChE,CAAC"}
|