@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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.loadBabelOptions = loadBabelOptions;
|
|
7
|
+
const cache = new WeakMap();
|
|
8
|
+
const empty = {};
|
|
9
|
+
function loadBabelOptions(babel, filename, overrides = empty) {
|
|
10
|
+
var _cache$get, _babel$loadOptions;
|
|
11
|
+
const fileCache = (_cache$get = cache.get(overrides)) !== null && _cache$get !== void 0 ? _cache$get : new Map();
|
|
12
|
+
if (fileCache.has(filename)) {
|
|
13
|
+
return fileCache.get(filename);
|
|
14
|
+
}
|
|
15
|
+
const babelOptions = (_babel$loadOptions = babel.loadOptions({
|
|
16
|
+
...overrides,
|
|
17
|
+
filename,
|
|
18
|
+
caller: {
|
|
19
|
+
name: 'linaria',
|
|
20
|
+
// Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed
|
|
21
|
+
supportsStaticESM: true,
|
|
22
|
+
supportsDynamicImport: true,
|
|
23
|
+
supportsTopLevelAwait: true,
|
|
24
|
+
supportsExportNamespaceFrom: true
|
|
25
|
+
}
|
|
26
|
+
})) !== null && _babel$loadOptions !== void 0 ? _babel$loadOptions : {};
|
|
27
|
+
fileCache.set(filename, babelOptions);
|
|
28
|
+
cache.set(overrides, fileCache);
|
|
29
|
+
return babelOptions;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=loadBabelOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadBabelOptions.js","names":["cache","WeakMap","empty","loadBabelOptions","babel","filename","overrides","_cache$get","_babel$loadOptions","fileCache","get","Map","has","babelOptions","loadOptions","caller","name","supportsStaticESM","supportsDynamicImport","supportsTopLevelAwait","supportsExportNamespaceFrom","set"],"sources":["../../src/options/loadBabelOptions.ts"],"sourcesContent":["import type { TransformOptions } from '@babel/core';\n\nimport type { Core } from '../babel';\n\nconst cache = new WeakMap<\n Partial<TransformOptions>,\n Map<string, TransformOptions>\n>();\n\nconst empty = {};\n\nexport function loadBabelOptions(\n babel: Core,\n filename: string,\n overrides: TransformOptions = empty\n) {\n const fileCache = cache.get(overrides) ?? new Map<string, TransformOptions>();\n if (fileCache.has(filename)) {\n return fileCache.get(filename)!;\n }\n\n const babelOptions: TransformOptions =\n babel.loadOptions({\n ...overrides,\n filename,\n caller: {\n name: 'linaria',\n\n // Indicates for @babel/preset-env to support all ESM syntax and avoid transforms before it's needed\n supportsStaticESM: true,\n supportsDynamicImport: true,\n supportsTopLevelAwait: true,\n supportsExportNamespaceFrom: true,\n },\n }) ?? {};\n\n fileCache.set(filename, babelOptions);\n cache.set(overrides, fileCache);\n\n return babelOptions;\n}\n"],"mappings":";;;;;;AAIA,MAAMA,KAAK,GAAG,IAAIC,OAAO,CAGvB,CAAC;AAEH,MAAMC,KAAK,GAAG,CAAC,CAAC;AAET,SAASC,gBAAgBA,CAC9BC,KAAW,EACXC,QAAgB,EAChBC,SAA2B,GAAGJ,KAAK,EACnC;EAAA,IAAAK,UAAA,EAAAC,kBAAA;EACA,MAAMC,SAAS,IAAAF,UAAA,GAAGP,KAAK,CAACU,GAAG,CAACJ,SAAS,CAAC,cAAAC,UAAA,cAAAA,UAAA,GAAI,IAAII,GAAG,CAA2B,CAAC;EAC7E,IAAIF,SAAS,CAACG,GAAG,CAACP,QAAQ,CAAC,EAAE;IAC3B,OAAOI,SAAS,CAACC,GAAG,CAACL,QAAQ,CAAC;EAChC;EAEA,MAAMQ,YAA8B,IAAAL,kBAAA,GAClCJ,KAAK,CAACU,WAAW,CAAC;IAChB,GAAGR,SAAS;IACZD,QAAQ;IACRU,MAAM,EAAE;MACNC,IAAI,EAAE,SAAS;MAEf;MACAC,iBAAiB,EAAE,IAAI;MACvBC,qBAAqB,EAAE,IAAI;MAC3BC,qBAAqB,EAAE,IAAI;MAC3BC,2BAA2B,EAAE;IAC/B;EACF,CAAC,CAAC,cAAAZ,kBAAA,cAAAA,kBAAA,GAAI,CAAC,CAAC;EAEVC,SAAS,CAACY,GAAG,CAAChB,QAAQ,EAAEQ,YAAY,CAAC;EACrCb,KAAK,CAACqB,GAAG,CAACf,SAAS,EAAEG,SAAS,CAAC;EAE/B,OAAOI,YAAY;AACrB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = babelTransform;
|
|
7
|
+
var _shared = require("@wyw-in-js/shared");
|
|
8
|
+
var _cache = require("../cache");
|
|
9
|
+
var _transform = require("../transform");
|
|
10
|
+
var _loadLinariaOptions = require("../transform/helpers/loadLinariaOptions");
|
|
11
|
+
var _collector = require("./collector");
|
|
12
|
+
function babelTransform(babel, options) {
|
|
13
|
+
const cache = new _cache.TransformCacheCollection();
|
|
14
|
+
const debug = _shared.logger.extend('babel-transform');
|
|
15
|
+
return {
|
|
16
|
+
name: '@wyw-in-js/transform/babel-transform',
|
|
17
|
+
pre(file) {
|
|
18
|
+
var _file$opts$root, _file$opts$inputSourc;
|
|
19
|
+
// eslint-disable-next-line require-yield
|
|
20
|
+
function* collect() {
|
|
21
|
+
const {
|
|
22
|
+
valueCache
|
|
23
|
+
} = this.data;
|
|
24
|
+
const {
|
|
25
|
+
loadedAndParsed
|
|
26
|
+
} = this.entrypoint;
|
|
27
|
+
const {
|
|
28
|
+
pluginOptions
|
|
29
|
+
} = this.services.options;
|
|
30
|
+
if (loadedAndParsed.evaluator === 'ignored') {
|
|
31
|
+
throw new Error('entrypoint was ignored');
|
|
32
|
+
}
|
|
33
|
+
(0, _collector.collector)(file, pluginOptions, valueCache);
|
|
34
|
+
return {
|
|
35
|
+
ast: loadedAndParsed.ast,
|
|
36
|
+
code: loadedAndParsed.code
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
debug('start %s', file.opts.filename);
|
|
40
|
+
const pluginOptions = (0, _loadLinariaOptions.loadLinariaOptions)(options);
|
|
41
|
+
(0, _transform.transformSync)({
|
|
42
|
+
babel,
|
|
43
|
+
cache,
|
|
44
|
+
options: {
|
|
45
|
+
filename: file.opts.filename,
|
|
46
|
+
root: (_file$opts$root = file.opts.root) !== null && _file$opts$root !== void 0 ? _file$opts$root : undefined,
|
|
47
|
+
inputSourceMap: (_file$opts$inputSourc = file.opts.inputSourceMap) !== null && _file$opts$inputSourc !== void 0 ? _file$opts$inputSourc : undefined,
|
|
48
|
+
pluginOptions
|
|
49
|
+
}
|
|
50
|
+
}, file.code, _shared.syncResolve, {
|
|
51
|
+
collect
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
visitor: {},
|
|
55
|
+
post(file) {
|
|
56
|
+
debug('end %s', file.opts.filename);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=babel-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babel-transform.js","names":["_shared","require","_cache","_transform","_loadLinariaOptions","_collector","babelTransform","babel","options","cache","TransformCacheCollection","debug","logger","extend","name","pre","file","_file$opts$root","_file$opts$inputSourc","collect","valueCache","data","loadedAndParsed","entrypoint","pluginOptions","services","evaluator","Error","collector","ast","code","opts","filename","loadLinariaOptions","transformSync","root","undefined","inputSourceMap","syncResolve","visitor","post"],"sources":["../../src/plugins/babel-transform.ts"],"sourcesContent":["import type { BabelFile, PluginObj } from '@babel/core';\n\nimport { logger, syncResolve } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport { TransformCacheCollection } from '../cache';\nimport { transformSync } from '../transform';\nimport { loadLinariaOptions } from '../transform/helpers/loadLinariaOptions';\nimport type { ICollectAction, SyncScenarioForAction } from '../transform/types';\nimport type { IPluginState, PluginOptions } from '../types';\n\nimport { collector } from './collector';\n\nexport default function babelTransform(\n babel: Core,\n options: Partial<PluginOptions>\n): PluginObj<IPluginState> {\n const cache = new TransformCacheCollection();\n const debug = logger.extend('babel-transform');\n\n return {\n name: '@wyw-in-js/transform/babel-transform',\n pre(file: BabelFile) {\n // eslint-disable-next-line require-yield\n function* collect(\n this: ICollectAction\n ): SyncScenarioForAction<ICollectAction> {\n const { valueCache } = this.data;\n const { loadedAndParsed } = this.entrypoint;\n const { pluginOptions } = this.services.options;\n if (loadedAndParsed.evaluator === 'ignored') {\n throw new Error('entrypoint was ignored');\n }\n\n collector(file, pluginOptions, valueCache);\n\n return {\n ast: loadedAndParsed.ast,\n code: loadedAndParsed.code,\n };\n }\n\n debug('start %s', file.opts.filename);\n\n const pluginOptions = loadLinariaOptions(options);\n\n transformSync(\n {\n babel,\n cache,\n options: {\n filename: file.opts.filename!,\n root: file.opts.root ?? undefined,\n inputSourceMap: file.opts.inputSourceMap ?? undefined,\n pluginOptions,\n },\n },\n file.code,\n syncResolve,\n {\n collect,\n }\n );\n },\n visitor: {},\n post(file: BabelFile) {\n debug('end %s', file.opts.filename);\n },\n };\n}\n"],"mappings":";;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AAIA,IAAAI,UAAA,GAAAJ,OAAA;AAEe,SAASK,cAAcA,CACpCC,KAAW,EACXC,OAA+B,EACN;EACzB,MAAMC,KAAK,GAAG,IAAIC,+BAAwB,CAAC,CAAC;EAC5C,MAAMC,KAAK,GAAGC,cAAM,CAACC,MAAM,CAAC,iBAAiB,CAAC;EAE9C,OAAO;IACLC,IAAI,EAAE,sCAAsC;IAC5CC,GAAGA,CAACC,IAAe,EAAE;MAAA,IAAAC,eAAA,EAAAC,qBAAA;MACnB;MACA,UAAUC,OAAOA,CAAA,EAEwB;QACvC,MAAM;UAAEC;QAAW,CAAC,GAAG,IAAI,CAACC,IAAI;QAChC,MAAM;UAAEC;QAAgB,CAAC,GAAG,IAAI,CAACC,UAAU;QAC3C,MAAM;UAAEC;QAAc,CAAC,GAAG,IAAI,CAACC,QAAQ,CAACjB,OAAO;QAC/C,IAAIc,eAAe,CAACI,SAAS,KAAK,SAAS,EAAE;UAC3C,MAAM,IAAIC,KAAK,CAAC,wBAAwB,CAAC;QAC3C;QAEA,IAAAC,oBAAS,EAACZ,IAAI,EAAEQ,aAAa,EAAEJ,UAAU,CAAC;QAE1C,OAAO;UACLS,GAAG,EAAEP,eAAe,CAACO,GAAG;UACxBC,IAAI,EAAER,eAAe,CAACQ;QACxB,CAAC;MACH;MAEAnB,KAAK,CAAC,UAAU,EAAEK,IAAI,CAACe,IAAI,CAACC,QAAQ,CAAC;MAErC,MAAMR,aAAa,GAAG,IAAAS,sCAAkB,EAACzB,OAAO,CAAC;MAEjD,IAAA0B,wBAAa,EACX;QACE3B,KAAK;QACLE,KAAK;QACLD,OAAO,EAAE;UACPwB,QAAQ,EAAEhB,IAAI,CAACe,IAAI,CAACC,QAAS;UAC7BG,IAAI,GAAAlB,eAAA,GAAED,IAAI,CAACe,IAAI,CAACI,IAAI,cAAAlB,eAAA,cAAAA,eAAA,GAAImB,SAAS;UACjCC,cAAc,GAAAnB,qBAAA,GAAEF,IAAI,CAACe,IAAI,CAACM,cAAc,cAAAnB,qBAAA,cAAAA,qBAAA,GAAIkB,SAAS;UACrDZ;QACF;MACF,CAAC,EACDR,IAAI,CAACc,IAAI,EACTQ,mBAAW,EACX;QACEnB;MACF,CACF,CAAC;IACH,CAAC;IACDoB,OAAO,EAAE,CAAC,CAAC;IACXC,IAAIA,CAACxB,IAAe,EAAE;MACpBL,KAAK,CAAC,QAAQ,EAAEK,IAAI,CAACe,IAAI,CAACC,QAAQ,CAAC;IACrC;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.collector = collector;
|
|
7
|
+
exports.default = collectorPlugin;
|
|
8
|
+
exports.filename = void 0;
|
|
9
|
+
var _shared = require("@wyw-in-js/shared");
|
|
10
|
+
var _processTemplateExpression = require("../utils/processTemplateExpression");
|
|
11
|
+
var _scopeHelpers = require("../utils/scopeHelpers");
|
|
12
|
+
var _traversalCache = require("../utils/traversalCache");
|
|
13
|
+
/**
|
|
14
|
+
* Collector traverses the AST and collects information about imports and
|
|
15
|
+
* all usages of WYW-processors.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const filename = exports.filename = __filename;
|
|
19
|
+
function collector(file, options, values) {
|
|
20
|
+
var _file$path$scope$getD;
|
|
21
|
+
const processors = [];
|
|
22
|
+
const identifiers = [];
|
|
23
|
+
file.path.traverse({
|
|
24
|
+
Identifier: p => {
|
|
25
|
+
identifiers.push(p);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// TODO: process transformed literals
|
|
30
|
+
identifiers.forEach(p => {
|
|
31
|
+
(0, _processTemplateExpression.processTemplateExpression)(p, file.opts, options, processor => {
|
|
32
|
+
processor.build(values);
|
|
33
|
+
processor.doRuntimeReplacement();
|
|
34
|
+
processors.push(processor);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
if (processors.length === 0) {
|
|
38
|
+
// We didn't find any processors.
|
|
39
|
+
return processors;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// We can remove __linariaPreval export and all related code
|
|
43
|
+
const prevalExport = (_file$path$scope$getD = file.path.scope.getData('__linariaPreval')) === null || _file$path$scope$getD === void 0 ? void 0 : _file$path$scope$getD.findParent(p => p.isExpressionStatement());
|
|
44
|
+
if (prevalExport) {
|
|
45
|
+
(0, _scopeHelpers.removeWithRelated)([prevalExport]);
|
|
46
|
+
}
|
|
47
|
+
return processors;
|
|
48
|
+
}
|
|
49
|
+
function collectorPlugin(babel, options) {
|
|
50
|
+
var _options$values;
|
|
51
|
+
const values = (_options$values = options.values) !== null && _options$values !== void 0 ? _options$values : new Map();
|
|
52
|
+
const debug = _shared.logger.extend('collector');
|
|
53
|
+
return {
|
|
54
|
+
name: '@wyw-in-js/transform/collector',
|
|
55
|
+
pre(file) {
|
|
56
|
+
debug('start %s', file.opts.filename);
|
|
57
|
+
const processors = collector(file, options, values);
|
|
58
|
+
if (processors.length === 0) {
|
|
59
|
+
// We didn't find any Linaria template literals.
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.file.metadata.linaria = {
|
|
63
|
+
processors,
|
|
64
|
+
replacements: [],
|
|
65
|
+
rules: {},
|
|
66
|
+
dependencies: []
|
|
67
|
+
};
|
|
68
|
+
debug('end %s', file.opts.filename);
|
|
69
|
+
},
|
|
70
|
+
visitor: {},
|
|
71
|
+
post(file) {
|
|
72
|
+
(0, _traversalCache.invalidateTraversalCache)(file.path);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.js","names":["_shared","require","_processTemplateExpression","_scopeHelpers","_traversalCache","filename","exports","__filename","collector","file","options","values","_file$path$scope$getD","processors","identifiers","path","traverse","Identifier","p","push","forEach","processTemplateExpression","opts","processor","build","doRuntimeReplacement","length","prevalExport","scope","getData","findParent","isExpressionStatement","removeWithRelated","collectorPlugin","babel","_options$values","Map","debug","logger","extend","name","pre","metadata","linaria","replacements","rules","dependencies","visitor","post","invalidateTraversalCache"],"sources":["../../src/plugins/collector.ts"],"sourcesContent":["/**\n * Collector traverses the AST and collects information about imports and\n * all usages of WYW-processors.\n */\n\nimport type { BabelFile, PluginObj } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { Identifier } from '@babel/types';\n\nimport type { ValueCache } from '@wyw-in-js/processor-utils';\nimport { logger } from '@wyw-in-js/shared';\nimport type { StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport type { WYWTransformMetadata } from '../utils/TransformMetadata';\nimport { processTemplateExpression } from '../utils/processTemplateExpression';\nimport { removeWithRelated } from '../utils/scopeHelpers';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport const filename = __filename;\n\nexport function collector(\n file: BabelFile,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >,\n values: ValueCache\n) {\n const processors: WYWTransformMetadata['processors'] = [];\n\n const identifiers: NodePath<Identifier>[] = [];\n file.path.traverse({\n Identifier: (p) => {\n identifiers.push(p);\n },\n });\n\n // TODO: process transformed literals\n identifiers.forEach((p) => {\n processTemplateExpression(p, file.opts, options, (processor) => {\n processor.build(values);\n processor.doRuntimeReplacement();\n processors.push(processor);\n });\n });\n\n if (processors.length === 0) {\n // We didn't find any processors.\n return processors;\n }\n\n // We can remove __linariaPreval export and all related code\n const prevalExport = (\n file.path.scope.getData('__linariaPreval') as NodePath | undefined\n )?.findParent((p) => p.isExpressionStatement());\n if (prevalExport) {\n removeWithRelated([prevalExport]);\n }\n\n return processors;\n}\n\nexport default function collectorPlugin(\n babel: Core,\n options: StrictOptions & { values?: ValueCache }\n): PluginObj<IPluginState> {\n const values = options.values ?? new Map<string, unknown>();\n const debug = logger.extend('collector');\n return {\n name: '@wyw-in-js/transform/collector',\n pre(file: BabelFile) {\n debug('start %s', file.opts.filename);\n\n const processors = collector(file, options, values);\n\n if (processors.length === 0) {\n // We didn't find any Linaria template literals.\n return;\n }\n\n this.file.metadata.linaria = {\n processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n debug('end %s', file.opts.filename);\n },\n visitor: {},\n post(file: BabelFile) {\n invalidateTraversalCache(file.path);\n },\n };\n}\n"],"mappings":";;;;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AAMA,IAAAC,0BAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAlBA;AACA;AACA;AACA;;AAiBO,MAAMI,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAGE,UAAU;AAE3B,SAASC,SAASA,CACvBC,IAAe,EACfC,OAGC,EACDC,MAAkB,EAClB;EAAA,IAAAC,qBAAA;EACA,MAAMC,UAA8C,GAAG,EAAE;EAEzD,MAAMC,WAAmC,GAAG,EAAE;EAC9CL,IAAI,CAACM,IAAI,CAACC,QAAQ,CAAC;IACjBC,UAAU,EAAGC,CAAC,IAAK;MACjBJ,WAAW,CAACK,IAAI,CAACD,CAAC,CAAC;IACrB;EACF,CAAC,CAAC;;EAEF;EACAJ,WAAW,CAACM,OAAO,CAAEF,CAAC,IAAK;IACzB,IAAAG,oDAAyB,EAACH,CAAC,EAAET,IAAI,CAACa,IAAI,EAAEZ,OAAO,EAAGa,SAAS,IAAK;MAC9DA,SAAS,CAACC,KAAK,CAACb,MAAM,CAAC;MACvBY,SAAS,CAACE,oBAAoB,CAAC,CAAC;MAChCZ,UAAU,CAACM,IAAI,CAACI,SAAS,CAAC;IAC5B,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,IAAIV,UAAU,CAACa,MAAM,KAAK,CAAC,EAAE;IAC3B;IACA,OAAOb,UAAU;EACnB;;EAEA;EACA,MAAMc,YAAY,IAAAf,qBAAA,GAChBH,IAAI,CAACM,IAAI,CAACa,KAAK,CAACC,OAAO,CAAC,iBAAiB,CAAC,cAAAjB,qBAAA,uBADvBA,qBAAA,CAElBkB,UAAU,CAAEZ,CAAC,IAAKA,CAAC,CAACa,qBAAqB,CAAC,CAAC,CAAC;EAC/C,IAAIJ,YAAY,EAAE;IAChB,IAAAK,+BAAiB,EAAC,CAACL,YAAY,CAAC,CAAC;EACnC;EAEA,OAAOd,UAAU;AACnB;AAEe,SAASoB,eAAeA,CACrCC,KAAW,EACXxB,OAAgD,EACvB;EAAA,IAAAyB,eAAA;EACzB,MAAMxB,MAAM,IAAAwB,eAAA,GAAGzB,OAAO,CAACC,MAAM,cAAAwB,eAAA,cAAAA,eAAA,GAAI,IAAIC,GAAG,CAAkB,CAAC;EAC3D,MAAMC,KAAK,GAAGC,cAAM,CAACC,MAAM,CAAC,WAAW,CAAC;EACxC,OAAO;IACLC,IAAI,EAAE,gCAAgC;IACtCC,GAAGA,CAAChC,IAAe,EAAE;MACnB4B,KAAK,CAAC,UAAU,EAAE5B,IAAI,CAACa,IAAI,CAACjB,QAAQ,CAAC;MAErC,MAAMQ,UAAU,GAAGL,SAAS,CAACC,IAAI,EAAEC,OAAO,EAAEC,MAAM,CAAC;MAEnD,IAAIE,UAAU,CAACa,MAAM,KAAK,CAAC,EAAE;QAC3B;QACA;MACF;MAEA,IAAI,CAACjB,IAAI,CAACiC,QAAQ,CAACC,OAAO,GAAG;QAC3B9B,UAAU;QACV+B,YAAY,EAAE,EAAE;QAChBC,KAAK,EAAE,CAAC,CAAC;QACTC,YAAY,EAAE;MAChB,CAAC;MAEDT,KAAK,CAAC,QAAQ,EAAE5B,IAAI,CAACa,IAAI,CAACjB,QAAQ,CAAC;IACrC,CAAC;IACD0C,OAAO,EAAE,CAAC,CAAC;IACXC,IAAIA,CAACvC,IAAe,EAAE;MACpB,IAAAwC,wCAAwB,EAACxC,IAAI,CAACM,IAAI,CAAC;IACrC;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = dynamicImport;
|
|
7
|
+
/**
|
|
8
|
+
* The plugin that replaces `import()` with `__wyw_dynamic_import` as Node VM does not support dynamic imports yet.
|
|
9
|
+
*/
|
|
10
|
+
function dynamicImport(babel) {
|
|
11
|
+
const {
|
|
12
|
+
types: t
|
|
13
|
+
} = babel;
|
|
14
|
+
return {
|
|
15
|
+
name: '@wyw-in-js/transform/dynamic-import',
|
|
16
|
+
visitor: {
|
|
17
|
+
CallExpression(path) {
|
|
18
|
+
if (path.get('callee').isImport()) {
|
|
19
|
+
const moduleName = path.get('arguments.0');
|
|
20
|
+
if (moduleName.isStringLiteral()) {
|
|
21
|
+
path.replaceWith(t.callExpression(t.identifier('__wyw_dynamic_import'), [t.stringLiteral(moduleName.node.value)]));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (moduleName.isTemplateLiteral()) {
|
|
25
|
+
path.replaceWith(t.callExpression(t.identifier('__wyw_dynamic_import'), [t.cloneNode(moduleName.node, true, true)]));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
throw new Error('Dynamic import argument must be a string or a template literal');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=dynamic-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-import.js","names":["dynamicImport","babel","types","t","name","visitor","CallExpression","path","get","isImport","moduleName","isStringLiteral","replaceWith","callExpression","identifier","stringLiteral","node","value","isTemplateLiteral","cloneNode","Error"],"sources":["../../src/plugins/dynamic-import.ts"],"sourcesContent":["import type { NodePath, PluginObj } from '@babel/core';\n\nimport type { Core } from '../babel';\n\n/**\n * The plugin that replaces `import()` with `__wyw_dynamic_import` as Node VM does not support dynamic imports yet.\n */\nexport default function dynamicImport(babel: Core): PluginObj {\n const { types: t } = babel;\n\n return {\n name: '@wyw-in-js/transform/dynamic-import',\n visitor: {\n CallExpression(path) {\n if (path.get('callee').isImport()) {\n const moduleName = path.get('arguments.0') as NodePath;\n\n if (moduleName.isStringLiteral()) {\n path.replaceWith(\n t.callExpression(t.identifier('__wyw_dynamic_import'), [\n t.stringLiteral(moduleName.node.value),\n ])\n );\n return;\n }\n\n if (moduleName.isTemplateLiteral()) {\n path.replaceWith(\n t.callExpression(t.identifier('__wyw_dynamic_import'), [\n t.cloneNode(moduleName.node, true, true),\n ])\n );\n return;\n }\n\n throw new Error(\n 'Dynamic import argument must be a string or a template literal'\n );\n }\n },\n },\n };\n}\n"],"mappings":";;;;;;AAIA;AACA;AACA;AACe,SAASA,aAAaA,CAACC,KAAW,EAAa;EAC5D,MAAM;IAAEC,KAAK,EAAEC;EAAE,CAAC,GAAGF,KAAK;EAE1B,OAAO;IACLG,IAAI,EAAE,qCAAqC;IAC3CC,OAAO,EAAE;MACPC,cAAcA,CAACC,IAAI,EAAE;QACnB,IAAIA,IAAI,CAACC,GAAG,CAAC,QAAQ,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE;UACjC,MAAMC,UAAU,GAAGH,IAAI,CAACC,GAAG,CAAC,aAAa,CAAa;UAEtD,IAAIE,UAAU,CAACC,eAAe,CAAC,CAAC,EAAE;YAChCJ,IAAI,CAACK,WAAW,CACdT,CAAC,CAACU,cAAc,CAACV,CAAC,CAACW,UAAU,CAAC,sBAAsB,CAAC,EAAE,CACrDX,CAAC,CAACY,aAAa,CAACL,UAAU,CAACM,IAAI,CAACC,KAAK,CAAC,CACvC,CACH,CAAC;YACD;UACF;UAEA,IAAIP,UAAU,CAACQ,iBAAiB,CAAC,CAAC,EAAE;YAClCX,IAAI,CAACK,WAAW,CACdT,CAAC,CAACU,cAAc,CAACV,CAAC,CAACW,UAAU,CAAC,sBAAsB,CAAC,EAAE,CACrDX,CAAC,CAACgB,SAAS,CAACT,UAAU,CAACM,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CACzC,CACH,CAAC;YACD;UACF;UAEA,MAAM,IAAII,KAAK,CACb,gEACF,CAAC;QACH;MACF;IACF;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.preeval = preeval;
|
|
8
|
+
var _shared = require("@wyw-in-js/shared");
|
|
9
|
+
var _EventEmitter = require("../utils/EventEmitter");
|
|
10
|
+
var _addIdentifierToLinariaPreval = require("../utils/addIdentifierToLinariaPreval");
|
|
11
|
+
var _getFileIdx = require("../utils/getFileIdx");
|
|
12
|
+
var _processTemplateExpression = require("../utils/processTemplateExpression");
|
|
13
|
+
var _removeDangerousCode = require("../utils/removeDangerousCode");
|
|
14
|
+
var _traversalCache = require("../utils/traversalCache");
|
|
15
|
+
/**
|
|
16
|
+
* This file is a babel preset used to transform files inside evaluators.
|
|
17
|
+
* It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function preeval(babel, {
|
|
21
|
+
eventEmitter = _EventEmitter.EventEmitter.dummy,
|
|
22
|
+
...options
|
|
23
|
+
}) {
|
|
24
|
+
const {
|
|
25
|
+
types: t
|
|
26
|
+
} = babel;
|
|
27
|
+
return {
|
|
28
|
+
name: '@wyw-in-js/transform/preeval',
|
|
29
|
+
pre(file) {
|
|
30
|
+
const filename = file.opts.filename;
|
|
31
|
+
const log = _shared.logger.extend('preeval').extend((0, _getFileIdx.getFileIdx)(filename));
|
|
32
|
+
log('start', 'Looking for template literals…');
|
|
33
|
+
const rootScope = file.scope;
|
|
34
|
+
this.processors = [];
|
|
35
|
+
eventEmitter.perf('transform:preeval:processTemplate', () => {
|
|
36
|
+
file.path.traverse({
|
|
37
|
+
Identifier: p => {
|
|
38
|
+
(0, _processTemplateExpression.processTemplateExpression)(p, file.opts, options, processor => {
|
|
39
|
+
processor.dependencies.forEach(dependency => {
|
|
40
|
+
if (dependency.ex.type === 'Identifier') {
|
|
41
|
+
(0, _addIdentifierToLinariaPreval.addIdentifierToLinariaPreval)(rootScope, dependency.ex.name);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
processor.doEvaltimeReplacement();
|
|
45
|
+
this.processors.push(processor);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
if ((0, _shared.isFeatureEnabled)(options.features, 'dangerousCodeRemover', filename)) {
|
|
51
|
+
log('start', 'Strip all JSX and browser related stuff');
|
|
52
|
+
eventEmitter.perf('transform:preeval:removeDangerousCode', () => (0, _removeDangerousCode.removeDangerousCode)(file.path));
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
visitor: {},
|
|
56
|
+
post(file) {
|
|
57
|
+
const log = _shared.logger.extend('preeval').extend((0, _getFileIdx.getFileIdx)(file.opts.filename));
|
|
58
|
+
(0, _traversalCache.invalidateTraversalCache)(file.path);
|
|
59
|
+
if (this.processors.length === 0) {
|
|
60
|
+
log('end', "We didn't find any Linaria template literals");
|
|
61
|
+
|
|
62
|
+
// We didn't find any Linaria template literals.
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.file.metadata.linaria = {
|
|
66
|
+
processors: this.processors,
|
|
67
|
+
replacements: [],
|
|
68
|
+
rules: {},
|
|
69
|
+
dependencies: []
|
|
70
|
+
};
|
|
71
|
+
const linariaPreval = file.path.getData('__linariaPreval');
|
|
72
|
+
if (!linariaPreval) {
|
|
73
|
+
// Event if there is no dependencies, we still need to add __linariaPreval
|
|
74
|
+
const linariaExport = t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), t.identifier('__linariaPreval')), t.objectExpression([])));
|
|
75
|
+
file.path.pushContainer('body', linariaExport);
|
|
76
|
+
}
|
|
77
|
+
log('end', '__linariaPreval has been added');
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var _default = exports.default = preeval;
|
|
82
|
+
//# sourceMappingURL=preeval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preeval.js","names":["_shared","require","_EventEmitter","_addIdentifierToLinariaPreval","_getFileIdx","_processTemplateExpression","_removeDangerousCode","_traversalCache","preeval","babel","eventEmitter","EventEmitter","dummy","options","types","t","name","pre","file","filename","opts","log","logger","extend","getFileIdx","rootScope","scope","processors","perf","path","traverse","Identifier","p","processTemplateExpression","processor","dependencies","forEach","dependency","ex","type","addIdentifierToLinariaPreval","doEvaltimeReplacement","push","isFeatureEnabled","features","removeDangerousCode","visitor","post","invalidateTraversalCache","length","metadata","linaria","replacements","rules","linariaPreval","getData","linariaExport","expressionStatement","assignmentExpression","memberExpression","identifier","objectExpression","pushContainer","_default","exports","default"],"sources":["../../src/plugins/preeval.ts"],"sourcesContent":["/**\n * This file is a babel preset used to transform files inside evaluators.\n * It works the same as main `babel/extract` preset, but do not evaluate lazy dependencies.\n */\nimport type { BabelFile, PluginObj } from '@babel/core';\n\nimport type { StrictOptions } from '@wyw-in-js/shared';\nimport { isFeatureEnabled, logger } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport type { IPluginState } from '../types';\nimport { EventEmitter } from '../utils/EventEmitter';\nimport { addIdentifierToLinariaPreval } from '../utils/addIdentifierToLinariaPreval';\nimport { getFileIdx } from '../utils/getFileIdx';\nimport { processTemplateExpression } from '../utils/processTemplateExpression';\nimport { removeDangerousCode } from '../utils/removeDangerousCode';\nimport { invalidateTraversalCache } from '../utils/traversalCache';\n\nexport type PreevalOptions = Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'features'\n> & { eventEmitter: EventEmitter };\n\nexport function preeval(\n babel: Core,\n { eventEmitter = EventEmitter.dummy, ...options }: PreevalOptions\n): PluginObj<IPluginState & { onFinish: () => void }> {\n const { types: t } = babel;\n return {\n name: '@wyw-in-js/transform/preeval',\n pre(file: BabelFile) {\n const filename = file.opts.filename!;\n const log = logger.extend('preeval').extend(getFileIdx(filename));\n\n log('start', 'Looking for template literals…');\n\n const rootScope = file.scope;\n this.processors = [];\n\n eventEmitter.perf('transform:preeval:processTemplate', () => {\n file.path.traverse({\n Identifier: (p) => {\n processTemplateExpression(p, file.opts, options, (processor) => {\n processor.dependencies.forEach((dependency) => {\n if (dependency.ex.type === 'Identifier') {\n addIdentifierToLinariaPreval(rootScope, dependency.ex.name);\n }\n });\n\n processor.doEvaltimeReplacement();\n this.processors.push(processor);\n });\n },\n });\n });\n\n if (\n isFeatureEnabled(options.features, 'dangerousCodeRemover', filename)\n ) {\n log('start', 'Strip all JSX and browser related stuff');\n eventEmitter.perf('transform:preeval:removeDangerousCode', () =>\n removeDangerousCode(file.path)\n );\n }\n },\n visitor: {},\n post(file: BabelFile) {\n const log = logger\n .extend('preeval')\n .extend(getFileIdx(file.opts.filename!));\n\n invalidateTraversalCache(file.path);\n\n if (this.processors.length === 0) {\n log('end', \"We didn't find any Linaria template literals\");\n\n // We didn't find any Linaria template literals.\n return;\n }\n\n this.file.metadata.linaria = {\n processors: this.processors,\n replacements: [],\n rules: {},\n dependencies: [],\n };\n\n const linariaPreval = file.path.getData('__linariaPreval');\n if (!linariaPreval) {\n // Event if there is no dependencies, we still need to add __linariaPreval\n const linariaExport = t.expressionStatement(\n t.assignmentExpression(\n '=',\n t.memberExpression(\n t.identifier('exports'),\n t.identifier('__linariaPreval')\n ),\n t.objectExpression([])\n )\n );\n\n file.path.pushContainer('body', linariaExport);\n }\n\n log('end', '__linariaPreval has been added');\n },\n };\n}\n\nexport default preeval;\n"],"mappings":";;;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,6BAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,0BAAA,GAAAJ,OAAA;AACA,IAAAK,oBAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAhBA;AACA;AACA;AACA;;AAoBO,SAASO,OAAOA,CACrBC,KAAW,EACX;EAAEC,YAAY,GAAGC,0BAAY,CAACC,KAAK;EAAE,GAAGC;AAAwB,CAAC,EACb;EACpD,MAAM;IAAEC,KAAK,EAAEC;EAAE,CAAC,GAAGN,KAAK;EAC1B,OAAO;IACLO,IAAI,EAAE,8BAA8B;IACpCC,GAAGA,CAACC,IAAe,EAAE;MACnB,MAAMC,QAAQ,GAAGD,IAAI,CAACE,IAAI,CAACD,QAAS;MACpC,MAAME,GAAG,GAAGC,cAAM,CAACC,MAAM,CAAC,SAAS,CAAC,CAACA,MAAM,CAAC,IAAAC,sBAAU,EAACL,QAAQ,CAAC,CAAC;MAEjEE,GAAG,CAAC,OAAO,EAAE,gCAAgC,CAAC;MAE9C,MAAMI,SAAS,GAAGP,IAAI,CAACQ,KAAK;MAC5B,IAAI,CAACC,UAAU,GAAG,EAAE;MAEpBjB,YAAY,CAACkB,IAAI,CAAC,mCAAmC,EAAE,MAAM;QAC3DV,IAAI,CAACW,IAAI,CAACC,QAAQ,CAAC;UACjBC,UAAU,EAAGC,CAAC,IAAK;YACjB,IAAAC,oDAAyB,EAACD,CAAC,EAAEd,IAAI,CAACE,IAAI,EAAEP,OAAO,EAAGqB,SAAS,IAAK;cAC9DA,SAAS,CAACC,YAAY,CAACC,OAAO,CAAEC,UAAU,IAAK;gBAC7C,IAAIA,UAAU,CAACC,EAAE,CAACC,IAAI,KAAK,YAAY,EAAE;kBACvC,IAAAC,0DAA4B,EAACf,SAAS,EAAEY,UAAU,CAACC,EAAE,CAACtB,IAAI,CAAC;gBAC7D;cACF,CAAC,CAAC;cAEFkB,SAAS,CAACO,qBAAqB,CAAC,CAAC;cACjC,IAAI,CAACd,UAAU,CAACe,IAAI,CAACR,SAAS,CAAC;YACjC,CAAC,CAAC;UACJ;QACF,CAAC,CAAC;MACJ,CAAC,CAAC;MAEF,IACE,IAAAS,wBAAgB,EAAC9B,OAAO,CAAC+B,QAAQ,EAAE,sBAAsB,EAAEzB,QAAQ,CAAC,EACpE;QACAE,GAAG,CAAC,OAAO,EAAE,yCAAyC,CAAC;QACvDX,YAAY,CAACkB,IAAI,CAAC,uCAAuC,EAAE,MACzD,IAAAiB,wCAAmB,EAAC3B,IAAI,CAACW,IAAI,CAC/B,CAAC;MACH;IACF,CAAC;IACDiB,OAAO,EAAE,CAAC,CAAC;IACXC,IAAIA,CAAC7B,IAAe,EAAE;MACpB,MAAMG,GAAG,GAAGC,cAAM,CACfC,MAAM,CAAC,SAAS,CAAC,CACjBA,MAAM,CAAC,IAAAC,sBAAU,EAACN,IAAI,CAACE,IAAI,CAACD,QAAS,CAAC,CAAC;MAE1C,IAAA6B,wCAAwB,EAAC9B,IAAI,CAACW,IAAI,CAAC;MAEnC,IAAI,IAAI,CAACF,UAAU,CAACsB,MAAM,KAAK,CAAC,EAAE;QAChC5B,GAAG,CAAC,KAAK,EAAE,8CAA8C,CAAC;;QAE1D;QACA;MACF;MAEA,IAAI,CAACH,IAAI,CAACgC,QAAQ,CAACC,OAAO,GAAG;QAC3BxB,UAAU,EAAE,IAAI,CAACA,UAAU;QAC3ByB,YAAY,EAAE,EAAE;QAChBC,KAAK,EAAE,CAAC,CAAC;QACTlB,YAAY,EAAE;MAChB,CAAC;MAED,MAAMmB,aAAa,GAAGpC,IAAI,CAACW,IAAI,CAAC0B,OAAO,CAAC,iBAAiB,CAAC;MAC1D,IAAI,CAACD,aAAa,EAAE;QAClB;QACA,MAAME,aAAa,GAAGzC,CAAC,CAAC0C,mBAAmB,CACzC1C,CAAC,CAAC2C,oBAAoB,CACpB,GAAG,EACH3C,CAAC,CAAC4C,gBAAgB,CAChB5C,CAAC,CAAC6C,UAAU,CAAC,SAAS,CAAC,EACvB7C,CAAC,CAAC6C,UAAU,CAAC,iBAAiB,CAChC,CAAC,EACD7C,CAAC,CAAC8C,gBAAgB,CAAC,EAAE,CACvB,CACF,CAAC;QAED3C,IAAI,CAACW,IAAI,CAACiC,aAAa,CAAC,MAAM,EAAEN,aAAa,CAAC;MAChD;MAEAnC,GAAG,CAAC,KAAK,EAAE,gCAAgC,CAAC;IAC9C;EACF,CAAC;AACH;AAAC,IAAA0C,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEczD,OAAO"}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = shakerPlugin;
|
|
7
|
+
var _shared = require("@wyw-in-js/shared");
|
|
8
|
+
var _collectExportsAndImports = require("../utils/collectExportsAndImports");
|
|
9
|
+
var _getFileIdx = require("../utils/getFileIdx");
|
|
10
|
+
var _isRemoved = require("../utils/isRemoved");
|
|
11
|
+
var _scopeHelpers = require("../utils/scopeHelpers");
|
|
12
|
+
var _traversalCache = require("../utils/traversalCache");
|
|
13
|
+
const EXT_REGEX = /\.[0-9a-z]+$/;
|
|
14
|
+
const ALLOWED_EXTENSIONS = ['.js', '.cjs', '.mjs'];
|
|
15
|
+
function shouldKeepSideEffect(importPath) {
|
|
16
|
+
const [ext] = importPath.match(EXT_REGEX) || [''];
|
|
17
|
+
return ext === '' || ALLOWED_EXTENSIONS.includes(ext);
|
|
18
|
+
}
|
|
19
|
+
function getBindingForExport(exportPath) {
|
|
20
|
+
if (exportPath.isIdentifier()) {
|
|
21
|
+
return exportPath.scope.getBinding(exportPath.node.name);
|
|
22
|
+
}
|
|
23
|
+
const variableDeclarator = exportPath.findParent(p => p.isVariableDeclarator());
|
|
24
|
+
if (variableDeclarator) {
|
|
25
|
+
const id = variableDeclarator.get('id');
|
|
26
|
+
if (id.isIdentifier()) {
|
|
27
|
+
return variableDeclarator.scope.getBinding(id.node.name);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (exportPath.isAssignmentExpression()) {
|
|
31
|
+
const left = exportPath.get('left');
|
|
32
|
+
if (left.isIdentifier()) {
|
|
33
|
+
return exportPath.scope.getBinding(left.node.name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (exportPath.isFunctionDeclaration() || exportPath.isClassDeclaration()) {
|
|
37
|
+
return exportPath.scope.getBinding(exportPath.node.id.name);
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const withoutRemoved = items => items.filter(({
|
|
42
|
+
local
|
|
43
|
+
}) => !(0, _isRemoved.isRemoved)(local));
|
|
44
|
+
function rearrangeExports({
|
|
45
|
+
types: t
|
|
46
|
+
}, root, exportRefs, exports) {
|
|
47
|
+
const rearranged = {
|
|
48
|
+
...exports
|
|
49
|
+
};
|
|
50
|
+
const rootScope = root.scope;
|
|
51
|
+
exportRefs.forEach((refs, name) => {
|
|
52
|
+
if (refs.length <= 1) {
|
|
53
|
+
if (refs.length === 1) {
|
|
54
|
+
// Maybe exports is assigned to another variable?
|
|
55
|
+
const declarator = refs[0].findParent(p => p.isVariableDeclarator());
|
|
56
|
+
if (!declarator) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const uid = rootScope.generateUid(name);
|
|
64
|
+
// Define variable in the beginning
|
|
65
|
+
const [declaration] = root.unshiftContainer('body', [t.variableDeclaration('var', [t.variableDeclarator(t.identifier(uid))])]);
|
|
66
|
+
rootScope.registerDeclaration(declaration);
|
|
67
|
+
|
|
68
|
+
// Replace every reference with defined variable
|
|
69
|
+
refs.forEach(ref => {
|
|
70
|
+
const [replaced] = ref.replaceWith(t.identifier(uid));
|
|
71
|
+
if (replaced.isBindingIdentifier()) {
|
|
72
|
+
var _replaced$parentPath;
|
|
73
|
+
rootScope.registerConstantViolation(replaced);
|
|
74
|
+
if ((_replaced$parentPath = replaced.parentPath) !== null && _replaced$parentPath !== void 0 && (_replaced$parentPath = _replaced$parentPath.parentPath) !== null && _replaced$parentPath !== void 0 && _replaced$parentPath.isVariableDeclarator()) {
|
|
75
|
+
// This is `const foo = exports.foo = "value"` case
|
|
76
|
+
(0, _scopeHelpers.reference)(replaced, replaced, true);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
(0, _scopeHelpers.reference)(replaced);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Assign defined variable to the export
|
|
84
|
+
const [pushed] = root.pushContainer('body', [t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('exports'), t.identifier(name)), t.identifier(uid)))]);
|
|
85
|
+
const local = pushed.get('expression.right');
|
|
86
|
+
(0, _scopeHelpers.reference)(local);
|
|
87
|
+
rearranged[name] = local;
|
|
88
|
+
});
|
|
89
|
+
return rearranged;
|
|
90
|
+
}
|
|
91
|
+
function shakerPlugin(babel, {
|
|
92
|
+
keepSideEffects = false,
|
|
93
|
+
ifUnknownExport = 'skip-shaking',
|
|
94
|
+
onlyExports
|
|
95
|
+
}) {
|
|
96
|
+
const shakerLogger = _shared.logger.extend('shaker');
|
|
97
|
+
return {
|
|
98
|
+
name: '@wyw-in-js/transform/shaker',
|
|
99
|
+
pre(file) {
|
|
100
|
+
this.filename = file.opts.filename;
|
|
101
|
+
const log = shakerLogger.extend((0, _getFileIdx.getFileIdx)(this.filename));
|
|
102
|
+
log('start', `${this.filename}, onlyExports: ${onlyExports.join(',')}`);
|
|
103
|
+
const onlyExportsSet = new Set(onlyExports);
|
|
104
|
+
const collected = (0, _collectExportsAndImports.collectExportsAndImports)(file.path);
|
|
105
|
+
const sideEffectImports = collected.imports.filter(_collectExportsAndImports.sideEffectImport);
|
|
106
|
+
log('import-and-exports', [`imports: ${collected.imports.length} (side-effects: ${sideEffectImports.length})`, `exports: ${Object.values(collected.exports).length}`, `reexports: ${collected.reexports.length}`].join(', '));
|
|
107
|
+
|
|
108
|
+
// We cannot just throw out exports if they are referred in the code
|
|
109
|
+
// Let's dome some replacements
|
|
110
|
+
const exports = rearrangeExports(babel, file.path, collected.exportRefs, collected.exports);
|
|
111
|
+
Object.values(exports).forEach(local => {
|
|
112
|
+
if (local.isAssignmentExpression()) {
|
|
113
|
+
const left = local.get('left');
|
|
114
|
+
if (left.isIdentifier()) {
|
|
115
|
+
// For some reason babel does not mark id in AssignmentExpression as a reference
|
|
116
|
+
// So we need to do it manually
|
|
117
|
+
(0, _scopeHelpers.reference)(left, left, true);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const hasLinariaPreval = exports.__linariaPreval !== undefined;
|
|
122
|
+
const hasDefault = exports.default !== undefined;
|
|
123
|
+
|
|
124
|
+
// If __linariaPreval is not exported, we can remove it from onlyExports
|
|
125
|
+
if (onlyExportsSet.has('__linariaPreval') && !hasLinariaPreval) {
|
|
126
|
+
onlyExportsSet.delete('__linariaPreval');
|
|
127
|
+
}
|
|
128
|
+
if (onlyExportsSet.size === 0) {
|
|
129
|
+
// Fast-lane: if there are no exports to keep, we can just shake out the whole file
|
|
130
|
+
this.imports = [];
|
|
131
|
+
this.exports = {};
|
|
132
|
+
this.reexports = [];
|
|
133
|
+
this.deadExports = Object.keys(exports);
|
|
134
|
+
file.path.get('body').forEach(p => {
|
|
135
|
+
p.remove();
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const importedAsSideEffect = onlyExportsSet.has('side-effect');
|
|
140
|
+
onlyExportsSet.delete('side-effect');
|
|
141
|
+
|
|
142
|
+
// Hackaround for packages which include a 'default' export without specifying __esModule; such packages cannot be
|
|
143
|
+
// shaken as they will break interopRequireDefault babel helper
|
|
144
|
+
// See example in shaker-plugin.test.ts
|
|
145
|
+
// Real-world example was found in preact/compat npm package
|
|
146
|
+
if (onlyExportsSet.has('default') && hasDefault && !collected.isEsModule) {
|
|
147
|
+
this.imports = collected.imports;
|
|
148
|
+
this.exports = exports;
|
|
149
|
+
this.reexports = collected.reexports;
|
|
150
|
+
this.deadExports = [];
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!onlyExportsSet.has('*')) {
|
|
154
|
+
// __esModule should be kept alive
|
|
155
|
+
onlyExportsSet.add('__esModule');
|
|
156
|
+
const aliveExports = new Set();
|
|
157
|
+
const importNames = collected.imports.map(({
|
|
158
|
+
imported
|
|
159
|
+
}) => imported);
|
|
160
|
+
Object.entries(exports).forEach(([exported, local]) => {
|
|
161
|
+
if (onlyExportsSet.has(exported)) {
|
|
162
|
+
aliveExports.add(local);
|
|
163
|
+
} else if (importNames.includes(local.node.name || '')) {
|
|
164
|
+
aliveExports.add(local);
|
|
165
|
+
} else if ([...aliveExports].some(alive => alive === local)) {
|
|
166
|
+
// It's possible to export multiple values from a single variable initializer, e.g
|
|
167
|
+
// export const { foo, bar } = baz();
|
|
168
|
+
// We need to treat all of them as used if any of them are used, since otherwise
|
|
169
|
+
// we'll attempt to delete the baz() call
|
|
170
|
+
aliveExports.add(local);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
collected.reexports.forEach(exp => {
|
|
174
|
+
if (onlyExportsSet.has(exp.exported)) {
|
|
175
|
+
aliveExports.add(exp.local);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
const exportToPath = new Map();
|
|
179
|
+
Object.entries(exports).forEach(([exported, local]) => {
|
|
180
|
+
exportToPath.set(exported, local);
|
|
181
|
+
});
|
|
182
|
+
collected.reexports.forEach(exp => {
|
|
183
|
+
exportToPath.set(exp.exported, exp.local);
|
|
184
|
+
});
|
|
185
|
+
const notFoundExports = [...onlyExportsSet].filter(exp => exp !== '__esModule' && !aliveExports.has(exportToPath.get(exp)));
|
|
186
|
+
exportToPath.clear();
|
|
187
|
+
const isAllExportsFound = notFoundExports.length === 0;
|
|
188
|
+
if (!isAllExportsFound && ifUnknownExport !== 'ignore') {
|
|
189
|
+
if (ifUnknownExport === 'error') {
|
|
190
|
+
throw new Error(`Unknown export(s) requested: ${onlyExports.join(',')}`);
|
|
191
|
+
}
|
|
192
|
+
if (ifUnknownExport === 'reexport-all') {
|
|
193
|
+
// If there are unknown exports, we have keep alive all re-exports.
|
|
194
|
+
if (exports['*'] !== undefined) {
|
|
195
|
+
aliveExports.add(exports['*']);
|
|
196
|
+
}
|
|
197
|
+
collected.reexports.forEach(exp => {
|
|
198
|
+
if (exp.exported === '*') {
|
|
199
|
+
aliveExports.add(exp.local);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (ifUnknownExport === 'skip-shaking') {
|
|
204
|
+
this.imports = collected.imports;
|
|
205
|
+
this.exports = exports;
|
|
206
|
+
this.reexports = collected.reexports;
|
|
207
|
+
this.deadExports = [];
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
const forDeleting = [...Object.values(exports), ...collected.reexports.map(i => i.local)].filter(exp => !aliveExports.has(exp));
|
|
212
|
+
if (!keepSideEffects && !importedAsSideEffect) {
|
|
213
|
+
// Remove all imports that don't import something explicitly and should not be kept
|
|
214
|
+
sideEffectImports.forEach(i => {
|
|
215
|
+
if (!shouldKeepSideEffect(i.source)) {
|
|
216
|
+
forDeleting.push(i.local);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const deleted = new Set();
|
|
221
|
+
let dereferenced = [];
|
|
222
|
+
let changed = true;
|
|
223
|
+
while (changed && deleted.size < forDeleting.length) {
|
|
224
|
+
changed = false;
|
|
225
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
226
|
+
for (const path of forDeleting) {
|
|
227
|
+
if (deleted.has(path)) {
|
|
228
|
+
// eslint-disable-next-line no-continue
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const binding = getBindingForExport(path);
|
|
232
|
+
const action = (0, _scopeHelpers.findActionForNode)(path);
|
|
233
|
+
const parent = action === null || action === void 0 ? void 0 : action[1];
|
|
234
|
+
const outerReferences = ((binding === null || binding === void 0 ? void 0 : binding.referencePaths) || []).filter(ref => ref !== parent && !(parent !== null && parent !== void 0 && parent.isAncestor(ref)));
|
|
235
|
+
if (outerReferences.length > 0 && path.isIdentifier()) {
|
|
236
|
+
// Temporary deref it in order to simplify further checks.
|
|
237
|
+
(0, _scopeHelpers.dereference)(path);
|
|
238
|
+
dereferenced.push(path);
|
|
239
|
+
}
|
|
240
|
+
if (!deleted.has(path) && (!binding || outerReferences.length === 0)) {
|
|
241
|
+
if (action) {
|
|
242
|
+
(0, _scopeHelpers.applyAction)(action);
|
|
243
|
+
} else {
|
|
244
|
+
(0, _scopeHelpers.removeWithRelated)([path]);
|
|
245
|
+
}
|
|
246
|
+
deleted.add(path);
|
|
247
|
+
changed = true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
dereferenced.forEach(path => {
|
|
251
|
+
// If path is still alive, we need to reference it back
|
|
252
|
+
if (!(0, _isRemoved.isRemoved)(path)) {
|
|
253
|
+
(0, _scopeHelpers.reference)(path);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
dereferenced = [];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
this.imports = withoutRemoved(collected.imports);
|
|
260
|
+
this.exports = {};
|
|
261
|
+
this.deadExports = [];
|
|
262
|
+
Object.entries(exports).forEach(([exported, local]) => {
|
|
263
|
+
if ((0, _isRemoved.isRemoved)(local)) {
|
|
264
|
+
this.deadExports.push(exported);
|
|
265
|
+
} else {
|
|
266
|
+
this.exports[exported] = local;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
this.reexports = withoutRemoved(collected.reexports);
|
|
270
|
+
},
|
|
271
|
+
visitor: {},
|
|
272
|
+
post(file) {
|
|
273
|
+
const log = shakerLogger.extend((0, _getFileIdx.getFileIdx)(file.opts.filename));
|
|
274
|
+
const processedImports = new Set();
|
|
275
|
+
const imports = new Map();
|
|
276
|
+
const addImport = ({
|
|
277
|
+
imported,
|
|
278
|
+
source
|
|
279
|
+
}) => {
|
|
280
|
+
if (processedImports.has(`${source}:${imported}`)) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (!imports.has(source)) {
|
|
284
|
+
imports.set(source, []);
|
|
285
|
+
}
|
|
286
|
+
if (imported) {
|
|
287
|
+
imports.get(source).push(imported);
|
|
288
|
+
}
|
|
289
|
+
processedImports.add(`${source}:${imported}`);
|
|
290
|
+
};
|
|
291
|
+
this.imports.forEach(addImport);
|
|
292
|
+
this.reexports.forEach(addImport);
|
|
293
|
+
log('end', `remaining imports: %O`, imports);
|
|
294
|
+
|
|
295
|
+
// eslint-disable-next-line no-param-reassign
|
|
296
|
+
file.metadata.linariaEvaluator = {
|
|
297
|
+
imports
|
|
298
|
+
};
|
|
299
|
+
(0, _traversalCache.invalidateTraversalCache)(file.path);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=shaker.js.map
|