@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,43 @@
|
|
|
1
|
+
function dispose_SuppressedError(r, e) { return "undefined" != typeof SuppressedError ? dispose_SuppressedError = SuppressedError : (dispose_SuppressedError = function (r, e) { this.suppressed = r, this.error = e, this.stack = new Error().stack; }, dispose_SuppressedError.prototype = Object.create(Error.prototype, { constructor: { value: dispose_SuppressedError, writable: !0, configurable: !0 } })), new dispose_SuppressedError(r, e); }
|
|
2
|
+
function _dispose(r, e, s) { function next() { for (; r.length > 0;) try { var o = r.pop(), p = o.d.call(o.v); if (o.a) return Promise.resolve(p).then(next, err); } catch (r) { return err(r); } if (s) throw e; } function err(r) { return e = s ? new dispose_SuppressedError(r, e) : r, s = !0, next(); } return next(); }
|
|
3
|
+
function _using(o, e, n) { if (null == e) return e; if ("object" != typeof e) throw new TypeError("using declarations can only be used with objects, null, or undefined."); if (n) var r = e[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")]; if (null == r && (r = e[Symbol.dispose || Symbol.for("Symbol.dispose")]), "function" != typeof r) throw new TypeError("Property [Symbol.dispose] is not a function."); return o.push({ v: e, d: r, a: n }), e; }
|
|
4
|
+
import { isAborted } from '../actions/AbortError';
|
|
5
|
+
/**
|
|
6
|
+
* The first stage of processing an entrypoint.
|
|
7
|
+
* This stage is responsible for:
|
|
8
|
+
* - scheduling the explodeReexports action
|
|
9
|
+
* - scheduling the transform action
|
|
10
|
+
* - rescheduling itself if the entrypoint is superseded
|
|
11
|
+
*/
|
|
12
|
+
export function* processEntrypoint() {
|
|
13
|
+
const {
|
|
14
|
+
only,
|
|
15
|
+
log
|
|
16
|
+
} = this.entrypoint;
|
|
17
|
+
log('start processing (only: %o)', only);
|
|
18
|
+
try {
|
|
19
|
+
try {
|
|
20
|
+
var _stack = [];
|
|
21
|
+
const abortSignal = _using(_stack, this.createAbortSignal());
|
|
22
|
+
yield ['explodeReexports', this.entrypoint, undefined, abortSignal];
|
|
23
|
+
const result = yield* this.getNext('transform', this.entrypoint, undefined, abortSignal);
|
|
24
|
+
this.entrypoint.assertNotSuperseded();
|
|
25
|
+
this.entrypoint.setTransformResult(result);
|
|
26
|
+
log('entrypoint processing finished');
|
|
27
|
+
} catch (_) {
|
|
28
|
+
var _error = _;
|
|
29
|
+
var _hasError = true;
|
|
30
|
+
} finally {
|
|
31
|
+
_dispose(_stack, _error, _hasError);
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (isAborted(e) && this.entrypoint.supersededWith) {
|
|
35
|
+
log('processing aborted, schedule the next attempt');
|
|
36
|
+
yield* this.getNext('processEntrypoint', this.entrypoint.supersededWith, undefined, null);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
log(`Unhandled error: %O`, e);
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=processEntrypoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processEntrypoint.js","names":["isAborted","processEntrypoint","only","log","entrypoint","_stack","abortSignal","_using","createAbortSignal","undefined","result","getNext","assertNotSuperseded","setTransformResult","_","_error","_hasError","_dispose","e","supersededWith"],"sources":["../../../src/transform/generators/processEntrypoint.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IProcessEntrypointAction, SyncScenarioForAction } from '../types';\n\n/**\n * The first stage of processing an entrypoint.\n * This stage is responsible for:\n * - scheduling the explodeReexports action\n * - scheduling the transform action\n * - rescheduling itself if the entrypoint is superseded\n */\nexport function* processEntrypoint(\n this: IProcessEntrypointAction\n): SyncScenarioForAction<IProcessEntrypointAction> {\n const { only, log } = this.entrypoint;\n log('start processing (only: %o)', only);\n\n try {\n using abortSignal = this.createAbortSignal();\n\n yield ['explodeReexports', this.entrypoint, undefined, abortSignal];\n const result = yield* this.getNext(\n 'transform',\n this.entrypoint,\n undefined,\n abortSignal\n );\n\n this.entrypoint.assertNotSuperseded();\n\n this.entrypoint.setTransformResult(result);\n\n log('entrypoint processing finished');\n } catch (e) {\n if (isAborted(e) && this.entrypoint.supersededWith) {\n log('processing aborted, schedule the next attempt');\n yield* this.getNext(\n 'processEntrypoint',\n this.entrypoint.supersededWith,\n undefined,\n null\n );\n\n return;\n }\n\n log(`Unhandled error: %O`, e);\n throw e;\n }\n}\n"],"mappings":";;;AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAGjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,iBAAiBA,CAAA,EAEiB;EACjD,MAAM;IAAEC,IAAI;IAAEC;EAAI,CAAC,GAAG,IAAI,CAACC,UAAU;EACrCD,GAAG,CAAC,6BAA6B,EAAED,IAAI,CAAC;EAExC;IAAA,IAAI;MAAA,IAAAG,MAAA;MACF,MAAMC,WAAW,GAAAC,MAAA,CAAAF,MAAA,EAAG,IAAI,CAACG,iBAAiB,CAAC,CAAC;MAE5C,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAACJ,UAAU,EAAEK,SAAS,EAAEH,WAAW,CAAC;MACnE,MAAMI,MAAM,GAAG,OAAO,IAAI,CAACC,OAAO,CAChC,WAAW,EACX,IAAI,CAACP,UAAU,EACfK,SAAS,EACTH,WACF,CAAC;MAED,IAAI,CAACF,UAAU,CAACQ,mBAAmB,CAAC,CAAC;MAErC,IAAI,CAACR,UAAU,CAACS,kBAAkB,CAACH,MAAM,CAAC;MAE1CP,GAAG,CAAC,gCAAgC,CAAC;IACvC,CAAC,QAAAW,CAAA;MAAA,IAAAC,MAAA,GAAAD,CAAA;MAAA,IAAAE,SAAA;IAAA;MAAAC,QAAA,CAAAZ,MAAA,EAAAU,MAAA,EAAAC,SAAA;IAAA;EAAA,EAAC,OAAOE,CAAC,EAAE;IACV,IAAIlB,SAAS,CAACkB,CAAC,CAAC,IAAI,IAAI,CAACd,UAAU,CAACe,cAAc,EAAE;MAClDhB,GAAG,CAAC,+CAA+C,CAAC;MACpD,OAAO,IAAI,CAACQ,OAAO,CACjB,mBAAmB,EACnB,IAAI,CAACP,UAAU,CAACe,cAAc,EAC9BV,SAAS,EACT,IACF,CAAC;MAED;IACF;IAEAN,GAAG,CAAE,qBAAoB,EAAEe,CAAC,CAAC;IAC7B,MAAMA,CAAC;EACT;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates new entrypoints and emits processEntrypoint for each resolved import
|
|
5
|
+
*/
|
|
6
|
+
export function* processImports() {
|
|
7
|
+
for (const dependency of this.data.resolved) {
|
|
8
|
+
const {
|
|
9
|
+
resolved,
|
|
10
|
+
only
|
|
11
|
+
} = dependency;
|
|
12
|
+
if (!resolved) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
this.entrypoint.addDependency(dependency);
|
|
16
|
+
const nextEntrypoint = this.entrypoint.createChild(resolved, only);
|
|
17
|
+
if (nextEntrypoint === 'loop' || nextEntrypoint.ignored) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
yield* this.getNext('processEntrypoint', nextEntrypoint, undefined, null);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=processImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processImports.js","names":["processImports","dependency","data","resolved","only","entrypoint","addDependency","nextEntrypoint","createChild","ignored","getNext","undefined"],"sources":["../../../src/transform/generators/processImports.ts"],"sourcesContent":["/* eslint-disable no-continue */\nimport type { IProcessImportsAction, SyncScenarioForAction } from '../types';\n\n/**\n * Creates new entrypoints and emits processEntrypoint for each resolved import\n */\nexport function* processImports(\n this: IProcessImportsAction\n): SyncScenarioForAction<IProcessImportsAction> {\n for (const dependency of this.data.resolved) {\n const { resolved, only } = dependency;\n if (!resolved) {\n continue;\n }\n\n this.entrypoint.addDependency(dependency);\n\n const nextEntrypoint = this.entrypoint.createChild(resolved, only);\n if (nextEntrypoint === 'loop' || nextEntrypoint.ignored) {\n continue;\n }\n\n yield* this.getNext('processEntrypoint', nextEntrypoint, undefined, null);\n }\n}\n"],"mappings":"AAAA;;AAGA;AACA;AACA;AACA,OAAO,UAAUA,cAAcA,CAAA,EAEiB;EAC9C,KAAK,MAAMC,UAAU,IAAI,IAAI,CAACC,IAAI,CAACC,QAAQ,EAAE;IAC3C,MAAM;MAAEA,QAAQ;MAAEC;IAAK,CAAC,GAAGH,UAAU;IACrC,IAAI,CAACE,QAAQ,EAAE;MACb;IACF;IAEA,IAAI,CAACE,UAAU,CAACC,aAAa,CAACL,UAAU,CAAC;IAEzC,MAAMM,cAAc,GAAG,IAAI,CAACF,UAAU,CAACG,WAAW,CAACL,QAAQ,EAAEC,IAAI,CAAC;IAClE,IAAIG,cAAc,KAAK,MAAM,IAAIA,cAAc,CAACE,OAAO,EAAE;MACvD;IACF;IAEA,OAAO,IAAI,CAACC,OAAO,CAAC,mBAAmB,EAAEH,cAAc,EAAEI,SAAS,EAAE,IAAI,CAAC;EAC3E;AACF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/* eslint-disable no-continue,no-await-in-loop,require-yield */
|
|
2
|
+
import { getFileIdx } from '../../utils/getFileIdx';
|
|
3
|
+
import { getStack, isSuperSet, mergeOnly } from '../Entrypoint.helpers';
|
|
4
|
+
function emitDependency(emitter, entrypoint, imports) {
|
|
5
|
+
emitter.single({
|
|
6
|
+
type: 'dependency',
|
|
7
|
+
file: entrypoint.name,
|
|
8
|
+
only: entrypoint.only,
|
|
9
|
+
imports: imports.map(({
|
|
10
|
+
resolved,
|
|
11
|
+
only
|
|
12
|
+
}) => ({
|
|
13
|
+
from: resolved,
|
|
14
|
+
what: only
|
|
15
|
+
})),
|
|
16
|
+
fileIdx: getFileIdx(entrypoint.name)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function filterUnresolved(entrypoint, resolvedImports) {
|
|
20
|
+
return resolvedImports.filter(i => {
|
|
21
|
+
if (i.resolved === null) {
|
|
22
|
+
entrypoint.log(`[resolve] ✅ %s in %s is ignored`, i.source, entrypoint.name);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Synchronously resolves specified imports with a provided resolver.
|
|
31
|
+
*/
|
|
32
|
+
export function* syncResolveImports(resolve) {
|
|
33
|
+
const {
|
|
34
|
+
data: {
|
|
35
|
+
imports
|
|
36
|
+
},
|
|
37
|
+
entrypoint,
|
|
38
|
+
services: {
|
|
39
|
+
eventEmitter
|
|
40
|
+
}
|
|
41
|
+
} = this;
|
|
42
|
+
const listOfImports = Array.from(imports?.entries() ?? []);
|
|
43
|
+
const {
|
|
44
|
+
log
|
|
45
|
+
} = entrypoint;
|
|
46
|
+
if (listOfImports.length === 0) {
|
|
47
|
+
emitDependency(eventEmitter, entrypoint, []);
|
|
48
|
+
log('%s has no imports', entrypoint.name);
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
const resolvedImports = listOfImports.map(([source, only]) => {
|
|
52
|
+
let resolved = null;
|
|
53
|
+
try {
|
|
54
|
+
resolved = resolve(source, entrypoint.name, getStack(entrypoint));
|
|
55
|
+
log('[sync-resolve] ✅ %s -> %s (only: %o)', source, resolved, only);
|
|
56
|
+
} catch (err) {
|
|
57
|
+
log('[sync-resolve] ❌ cannot resolve %s: %O', source, err);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
source,
|
|
61
|
+
only,
|
|
62
|
+
resolved
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const filteredImports = filterUnresolved(entrypoint, resolvedImports);
|
|
66
|
+
emitDependency(eventEmitter, entrypoint, filteredImports);
|
|
67
|
+
return filteredImports;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Asynchronously resolves specified imports with a provided resolver.
|
|
72
|
+
*/
|
|
73
|
+
export async function* asyncResolveImports(resolve) {
|
|
74
|
+
const {
|
|
75
|
+
data: {
|
|
76
|
+
imports
|
|
77
|
+
},
|
|
78
|
+
entrypoint,
|
|
79
|
+
services: {
|
|
80
|
+
eventEmitter
|
|
81
|
+
}
|
|
82
|
+
} = this;
|
|
83
|
+
const listOfImports = Array.from(imports?.entries() ?? []);
|
|
84
|
+
const {
|
|
85
|
+
log
|
|
86
|
+
} = entrypoint;
|
|
87
|
+
if (listOfImports.length === 0) {
|
|
88
|
+
emitDependency(eventEmitter, entrypoint, []);
|
|
89
|
+
log('%s has no imports', entrypoint.name);
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
log('resolving %d imports', listOfImports.length);
|
|
93
|
+
const getResolveTask = async (source, only) => {
|
|
94
|
+
let resolved = null;
|
|
95
|
+
try {
|
|
96
|
+
resolved = await resolve(source, entrypoint.name, getStack(entrypoint));
|
|
97
|
+
} catch (err) {
|
|
98
|
+
log('[async-resolve] ❌ cannot resolve %s in %s: %O', source, entrypoint.name, err);
|
|
99
|
+
}
|
|
100
|
+
if (resolved !== null) {
|
|
101
|
+
log('[async-resolve] ✅ %s (%o) in %s -> %s', source, only, entrypoint.name, resolved);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
source,
|
|
105
|
+
only,
|
|
106
|
+
resolved
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
const resolvedImports = await Promise.all(listOfImports.map(([source, importsOnly]) => {
|
|
110
|
+
const cached = entrypoint.getDependency(source);
|
|
111
|
+
if (cached) {
|
|
112
|
+
return {
|
|
113
|
+
source,
|
|
114
|
+
only: mergeOnly(cached.only, importsOnly),
|
|
115
|
+
resolved: cached.resolved
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const task = entrypoint.getResolveTask(source);
|
|
119
|
+
if (task) {
|
|
120
|
+
// If we have cached task, we need to merge only…
|
|
121
|
+
const newTask = task.then(res => {
|
|
122
|
+
if (isSuperSet(res.only, importsOnly)) {
|
|
123
|
+
return res;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Is this branch even possible?
|
|
127
|
+
const merged = mergeOnly(res.only, importsOnly);
|
|
128
|
+
log('merging imports %o and %o: %o', importsOnly, res.only, merged);
|
|
129
|
+
return {
|
|
130
|
+
...res,
|
|
131
|
+
only: merged
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// … and update the cache
|
|
136
|
+
entrypoint.addResolveTask(source, newTask);
|
|
137
|
+
return newTask;
|
|
138
|
+
}
|
|
139
|
+
const resolveTask = getResolveTask(source, importsOnly);
|
|
140
|
+
entrypoint.addResolveTask(source, resolveTask);
|
|
141
|
+
return resolveTask;
|
|
142
|
+
}));
|
|
143
|
+
log('resolved %d imports', resolvedImports.length);
|
|
144
|
+
const filteredImports = filterUnresolved(entrypoint, resolvedImports);
|
|
145
|
+
emitDependency(eventEmitter, entrypoint, filteredImports);
|
|
146
|
+
return filteredImports;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=resolveImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveImports.js","names":["getFileIdx","getStack","isSuperSet","mergeOnly","emitDependency","emitter","entrypoint","imports","single","type","file","name","only","map","resolved","from","what","fileIdx","filterUnresolved","resolvedImports","filter","i","log","source","syncResolveImports","resolve","data","services","eventEmitter","listOfImports","Array","entries","length","err","filteredImports","asyncResolveImports","getResolveTask","Promise","all","importsOnly","cached","getDependency","task","newTask","then","res","merged","addResolveTask","resolveTask"],"sources":["../../../src/transform/generators/resolveImports.ts"],"sourcesContent":["/* eslint-disable no-continue,no-await-in-loop,require-yield */\nimport { getFileIdx } from '../../utils/getFileIdx';\nimport type { Entrypoint } from '../Entrypoint';\nimport { getStack, isSuperSet, mergeOnly } from '../Entrypoint.helpers';\nimport type { IEntrypointDependency } from '../Entrypoint.types';\nimport type {\n AsyncScenarioForAction,\n IResolveImportsAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nfunction emitDependency(\n emitter: Services['eventEmitter'],\n entrypoint: IResolveImportsAction['entrypoint'],\n imports: IEntrypointDependency[]\n) {\n emitter.single({\n type: 'dependency',\n file: entrypoint.name,\n only: entrypoint.only,\n imports: imports.map(({ resolved, only }) => ({\n from: resolved,\n what: only,\n })),\n fileIdx: getFileIdx(entrypoint.name),\n });\n}\n\nfunction filterUnresolved(\n entrypoint: Entrypoint,\n resolvedImports: IEntrypointDependency[]\n): IEntrypointDependency[] {\n return resolvedImports.filter((i): i is IEntrypointDependency => {\n if (i.resolved === null) {\n entrypoint.log(\n `[resolve] ✅ %s in %s is ignored`,\n i.source,\n entrypoint.name\n );\n return false;\n }\n\n return true;\n });\n}\n\n/**\n * Synchronously resolves specified imports with a provided resolver.\n */\nexport function* syncResolveImports(\n this: IResolveImportsAction,\n resolve: (what: string, importer: string, stack: string[]) => string\n): SyncScenarioForAction<IResolveImportsAction> {\n const {\n data: { imports },\n entrypoint,\n services: { eventEmitter },\n } = this;\n const listOfImports = Array.from(imports?.entries() ?? []);\n const { log } = entrypoint;\n\n if (listOfImports.length === 0) {\n emitDependency(eventEmitter, entrypoint, []);\n\n log('%s has no imports', entrypoint.name);\n return [];\n }\n\n const resolvedImports = listOfImports.map(([source, only]) => {\n let resolved: string | null = null;\n try {\n resolved = resolve(source, entrypoint.name, getStack(entrypoint));\n log('[sync-resolve] ✅ %s -> %s (only: %o)', source, resolved, only);\n } catch (err) {\n log('[sync-resolve] ❌ cannot resolve %s: %O', source, err);\n }\n\n return {\n source,\n only,\n resolved,\n };\n });\n\n const filteredImports = filterUnresolved(entrypoint, resolvedImports);\n emitDependency(eventEmitter, entrypoint, filteredImports);\n\n return filteredImports;\n}\n\n/**\n * Asynchronously resolves specified imports with a provided resolver.\n */\nexport async function* asyncResolveImports(\n this: IResolveImportsAction,\n resolve: (\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>\n): AsyncScenarioForAction<IResolveImportsAction> {\n const {\n data: { imports },\n entrypoint,\n services: { eventEmitter },\n } = this;\n const listOfImports = Array.from(imports?.entries() ?? []);\n const { log } = entrypoint;\n\n if (listOfImports.length === 0) {\n emitDependency(eventEmitter, entrypoint, []);\n\n log('%s has no imports', entrypoint.name);\n return [];\n }\n\n log('resolving %d imports', listOfImports.length);\n\n const getResolveTask = async (\n source: string,\n only: string[]\n ): Promise<IEntrypointDependency> => {\n let resolved: string | null = null;\n try {\n resolved = await resolve(source, entrypoint.name, getStack(entrypoint));\n } catch (err) {\n log(\n '[async-resolve] ❌ cannot resolve %s in %s: %O',\n source,\n entrypoint.name,\n err\n );\n }\n\n if (resolved !== null) {\n log(\n '[async-resolve] ✅ %s (%o) in %s -> %s',\n source,\n only,\n entrypoint.name,\n resolved\n );\n }\n\n return {\n source,\n only,\n resolved,\n };\n };\n\n const resolvedImports = await Promise.all<IEntrypointDependency>(\n listOfImports.map(([source, importsOnly]) => {\n const cached = entrypoint.getDependency(source);\n if (cached) {\n return {\n source,\n only: mergeOnly(cached.only, importsOnly),\n resolved: cached.resolved,\n };\n }\n\n const task = entrypoint.getResolveTask(source);\n if (task) {\n // If we have cached task, we need to merge only…\n const newTask = task.then((res) => {\n if (isSuperSet(res.only, importsOnly)) {\n return res;\n }\n\n // Is this branch even possible?\n const merged = mergeOnly(res.only, importsOnly);\n\n log('merging imports %o and %o: %o', importsOnly, res.only, merged);\n\n return { ...res, only: merged };\n });\n\n // … and update the cache\n entrypoint.addResolveTask(source, newTask);\n return newTask;\n }\n\n const resolveTask = getResolveTask(source, importsOnly);\n\n entrypoint.addResolveTask(source, resolveTask);\n\n return resolveTask;\n })\n );\n\n log('resolved %d imports', resolvedImports.length);\n\n const filteredImports = filterUnresolved(entrypoint, resolvedImports);\n emitDependency(eventEmitter, entrypoint, filteredImports);\n return filteredImports;\n}\n"],"mappings":"AAAA;AACA,SAASA,UAAU,QAAQ,wBAAwB;AAEnD,SAASC,QAAQ,EAAEC,UAAU,EAAEC,SAAS,QAAQ,uBAAuB;AASvE,SAASC,cAAcA,CACrBC,OAAiC,EACjCC,UAA+C,EAC/CC,OAAgC,EAChC;EACAF,OAAO,CAACG,MAAM,CAAC;IACbC,IAAI,EAAE,YAAY;IAClBC,IAAI,EAAEJ,UAAU,CAACK,IAAI;IACrBC,IAAI,EAAEN,UAAU,CAACM,IAAI;IACrBL,OAAO,EAAEA,OAAO,CAACM,GAAG,CAAC,CAAC;MAAEC,QAAQ;MAAEF;IAAK,CAAC,MAAM;MAC5CG,IAAI,EAAED,QAAQ;MACdE,IAAI,EAAEJ;IACR,CAAC,CAAC,CAAC;IACHK,OAAO,EAAEjB,UAAU,CAACM,UAAU,CAACK,IAAI;EACrC,CAAC,CAAC;AACJ;AAEA,SAASO,gBAAgBA,CACvBZ,UAAsB,EACtBa,eAAwC,EACf;EACzB,OAAOA,eAAe,CAACC,MAAM,CAAEC,CAAC,IAAiC;IAC/D,IAAIA,CAAC,CAACP,QAAQ,KAAK,IAAI,EAAE;MACvBR,UAAU,CAACgB,GAAG,CACX,iCAAgC,EACjCD,CAAC,CAACE,MAAM,EACRjB,UAAU,CAACK,IACb,CAAC;MACD,OAAO,KAAK;IACd;IAEA,OAAO,IAAI;EACb,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA,OAAO,UAAUa,kBAAkBA,CAEjCC,OAAoE,EACtB;EAC9C,MAAM;IACJC,IAAI,EAAE;MAAEnB;IAAQ,CAAC;IACjBD,UAAU;IACVqB,QAAQ,EAAE;MAAEC;IAAa;EAC3B,CAAC,GAAG,IAAI;EACR,MAAMC,aAAa,GAAGC,KAAK,CAACf,IAAI,CAACR,OAAO,EAAEwB,OAAO,CAAC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C,UAAU,CAAC8B,cAAc,CAACb,MAAM,CAAC;IAC9C,IAAImB,IAAI,EAAE;MACR;MACA,MAAMC,OAAO,GAAGD,IAAI,CAACE,IAAI,CAAEC,GAAG,IAAK;QACjC,IAAI3C,UAAU,CAAC2C,GAAG,CAACjC,IAAI,EAAE2B,WAAW,CAAC,EAAE;UACrC,OAAOM,GAAG;QACZ;;QAEA;QACA,MAAMC,MAAM,GAAG3C,SAAS,CAAC0C,GAAG,CAACjC,IAAI,EAAE2B,WAAW,CAAC;QAE/CjB,GAAG,CAAC,+BAA+B,EAAEiB,WAAW,EAAEM,GAAG,CAACjC,IAAI,EAAEkC,MAAM,CAAC;QAEnE,OAAO;UAAE,GAAGD,GAAG;UAAEjC,IAAI,EAAEkC;QAAO,CAAC;MACjC,CAAC,CAAC;;MAEF;MACAxC,UAAU,CAACyC,cAAc,CAACxB,MAAM,EAAEoB,OAAO,CAAC;MAC1C,OAAOA,OAAO;IAChB;IAEA,MAAMK,WAAW,GAAGZ,cAAc,CAACb,MAAM,EAAEgB,WAAW,CAAC;IAEvDjC,UAAU,CAACyC,cAAc,CAACxB,MAAM,EAAEyB,WAAW,CAAC;IAE9C,OAAOA,WAAW;EACpB,CAAC,CACH,CAAC;EAED1B,GAAG,CAAC,qBAAqB,EAAEH,eAAe,CAACa,MAAM,CAAC;EAElD,MAAME,eAAe,GAAGhB,gBAAgB,CAACZ,UAAU,EAAEa,eAAe,CAAC;EACrEf,cAAc,CAACwB,YAAY,EAAEtB,UAAU,EAAE4B,eAAe,CAAC;EACzD,OAAOA,eAAe;AACxB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { buildOptions } from '../../options/buildOptions';
|
|
2
|
+
import { getTransformMetadata } from '../../utils/TransformMetadata';
|
|
3
|
+
import { getPluginKey } from '../../utils/getPluginKey';
|
|
4
|
+
const EMPTY_FILE = '=== empty file ===';
|
|
5
|
+
const hasKeyInList = (plugin, list) => {
|
|
6
|
+
const pluginKey = getPluginKey(plugin);
|
|
7
|
+
return pluginKey ? list.some(i => pluginKey.includes(i)) : false;
|
|
8
|
+
};
|
|
9
|
+
function runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, eventEmitter) {
|
|
10
|
+
const preShakePlugins = evalConfig.plugins?.filter(i => hasKeyInList(i, pluginOptions.highPriorityPlugins)) ?? [];
|
|
11
|
+
const plugins = [...preShakePlugins, [require.resolve('../../plugins/preeval'), {
|
|
12
|
+
...pluginOptions,
|
|
13
|
+
eventEmitter
|
|
14
|
+
}], [require.resolve('../../plugins/dynamic-import')], ...(evalConfig.plugins ?? []).filter(i => !hasKeyInList(i, pluginOptions.highPriorityPlugins))];
|
|
15
|
+
const transformConfig = buildOptions({
|
|
16
|
+
...evalConfig,
|
|
17
|
+
envName: 'linaria',
|
|
18
|
+
plugins
|
|
19
|
+
});
|
|
20
|
+
const result = babel.transformFromAstSync(originalAst, code, transformConfig);
|
|
21
|
+
if (!result || !result.ast?.program) {
|
|
22
|
+
throw new Error('Babel transform failed');
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
export const prepareCode = (services, item, originalAst) => {
|
|
27
|
+
const {
|
|
28
|
+
log,
|
|
29
|
+
only,
|
|
30
|
+
loadedAndParsed
|
|
31
|
+
} = item;
|
|
32
|
+
if (loadedAndParsed.evaluator === 'ignored') {
|
|
33
|
+
log('is ignored');
|
|
34
|
+
return [loadedAndParsed.code ?? '', null, null];
|
|
35
|
+
}
|
|
36
|
+
const {
|
|
37
|
+
code,
|
|
38
|
+
evalConfig,
|
|
39
|
+
evaluator
|
|
40
|
+
} = loadedAndParsed;
|
|
41
|
+
const {
|
|
42
|
+
options,
|
|
43
|
+
babel,
|
|
44
|
+
eventEmitter
|
|
45
|
+
} = services;
|
|
46
|
+
const {
|
|
47
|
+
pluginOptions
|
|
48
|
+
} = options;
|
|
49
|
+
const preevalStageResult = eventEmitter.perf('transform:preeval', () => runPreevalStage(babel, evalConfig, pluginOptions, code, originalAst, eventEmitter));
|
|
50
|
+
const transformMetadata = getTransformMetadata(preevalStageResult.metadata);
|
|
51
|
+
if (only.length === 1 && only[0] === '__linariaPreval' && !transformMetadata) {
|
|
52
|
+
log('[evaluator:end] no metadata');
|
|
53
|
+
return [preevalStageResult.code, null, null];
|
|
54
|
+
}
|
|
55
|
+
log('[preeval] metadata %O', transformMetadata);
|
|
56
|
+
log('[evaluator:start] using %s', evaluator.name);
|
|
57
|
+
const evaluatorConfig = {
|
|
58
|
+
onlyExports: only,
|
|
59
|
+
highPriorityPlugins: pluginOptions.highPriorityPlugins,
|
|
60
|
+
features: pluginOptions.features
|
|
61
|
+
};
|
|
62
|
+
const [, transformedCode, imports] = eventEmitter.perf('transform:evaluator', () => evaluator(evalConfig, preevalStageResult.ast, preevalStageResult.code, evaluatorConfig, babel));
|
|
63
|
+
log('[evaluator:end]');
|
|
64
|
+
return [transformedCode, imports, transformMetadata ?? null];
|
|
65
|
+
};
|
|
66
|
+
export function* internalTransform(prepareFn) {
|
|
67
|
+
const {
|
|
68
|
+
only,
|
|
69
|
+
loadedAndParsed,
|
|
70
|
+
log
|
|
71
|
+
} = this.entrypoint;
|
|
72
|
+
if (loadedAndParsed.evaluator === 'ignored') {
|
|
73
|
+
log('is ignored');
|
|
74
|
+
return {
|
|
75
|
+
code: loadedAndParsed.code ?? '',
|
|
76
|
+
metadata: null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
log('>> (%o)', only);
|
|
80
|
+
const [preparedCode, imports, metadata] = prepareFn(this.services, this.entrypoint, loadedAndParsed.ast);
|
|
81
|
+
if (loadedAndParsed.code === preparedCode) {
|
|
82
|
+
log('<< (%o)\n === no changes ===', only);
|
|
83
|
+
} else {
|
|
84
|
+
log('<< (%o)', only);
|
|
85
|
+
log.extend('source')('%s', preparedCode || EMPTY_FILE);
|
|
86
|
+
}
|
|
87
|
+
if (preparedCode === '') {
|
|
88
|
+
log('is skipped');
|
|
89
|
+
return {
|
|
90
|
+
code: loadedAndParsed.code ?? '',
|
|
91
|
+
metadata: null
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (imports !== null && imports.size > 0) {
|
|
95
|
+
const resolvedImports = yield* this.getNext('resolveImports', this.entrypoint, {
|
|
96
|
+
imports
|
|
97
|
+
});
|
|
98
|
+
if (resolvedImports.length !== 0) {
|
|
99
|
+
yield ['processImports', this.entrypoint, {
|
|
100
|
+
resolved: resolvedImports
|
|
101
|
+
}];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
code: preparedCode,
|
|
106
|
+
metadata
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Prepares the code for evaluation. This includes removing dead and potentially unsafe code.
|
|
112
|
+
* Emits resolveImports and processImports events.
|
|
113
|
+
*/
|
|
114
|
+
export function transform() {
|
|
115
|
+
return internalTransform.call(this, prepareCode);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":["buildOptions","getTransformMetadata","getPluginKey","EMPTY_FILE","hasKeyInList","plugin","list","pluginKey","some","i","includes","runPreevalStage","babel","evalConfig","pluginOptions","code","originalAst","eventEmitter","preShakePlugins","plugins","filter","highPriorityPlugins","require","resolve","transformConfig","envName","result","transformFromAstSync","ast","program","Error","prepareCode","services","item","log","only","loadedAndParsed","evaluator","options","preevalStageResult","perf","transformMetadata","metadata","length","name","evaluatorConfig","onlyExports","features","transformedCode","imports","internalTransform","prepareFn","entrypoint","preparedCode","extend","size","resolvedImports","getNext","resolved","transform","call"],"sources":["../../../src/transform/generators/transform.ts"],"sourcesContent":["import type {\n BabelFileResult,\n PluginItem,\n TransformOptions,\n} from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { EvaluatorConfig, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../../babel';\nimport { buildOptions } from '../../options/buildOptions';\nimport type { EventEmitter } from '../../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../../utils/TransformMetadata';\nimport { getTransformMetadata } from '../../utils/TransformMetadata';\nimport { getPluginKey } from '../../utils/getPluginKey';\nimport type { Entrypoint } from '../Entrypoint';\nimport type {\n ITransformAction,\n Services,\n SyncScenarioForAction,\n} from '../types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nconst hasKeyInList = (plugin: PluginItem, list: string[]): boolean => {\n const pluginKey = getPluginKey(plugin);\n return pluginKey ? list.some((i) => pluginKey.includes(i)) : false;\n};\n\nfunction runPreevalStage(\n babel: Core,\n evalConfig: TransformOptions,\n pluginOptions: StrictOptions,\n code: string,\n originalAst: File,\n eventEmitter: EventEmitter\n): BabelFileResult {\n const preShakePlugins =\n evalConfig.plugins?.filter((i) =>\n hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ) ?? [];\n\n const plugins = [\n ...preShakePlugins,\n [\n require.resolve('../../plugins/preeval'),\n { ...pluginOptions, eventEmitter },\n ],\n [require.resolve('../../plugins/dynamic-import')],\n ...(evalConfig.plugins ?? []).filter(\n (i) => !hasKeyInList(i, pluginOptions.highPriorityPlugins)\n ),\n ];\n\n const transformConfig = buildOptions({\n ...evalConfig,\n envName: 'linaria',\n plugins,\n });\n\n const result = babel.transformFromAstSync(originalAst, code, transformConfig);\n\n if (!result || !result.ast?.program) {\n throw new Error('Babel transform failed');\n }\n\n return result;\n}\n\ntype PrepareCodeFn = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n) => [\n code: string,\n imports: Map<string, string[]> | null,\n metadata: WYWTransformMetadata | null,\n];\n\nexport const prepareCode = (\n services: Services,\n item: Entrypoint,\n originalAst: File\n): ReturnType<PrepareCodeFn> => {\n const { log, only, loadedAndParsed } = item;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return [loadedAndParsed.code ?? '', null, null];\n }\n\n const { code, evalConfig, evaluator } = loadedAndParsed;\n const { options, babel, eventEmitter } = services;\n const { pluginOptions } = options;\n\n const preevalStageResult = eventEmitter.perf('transform:preeval', () =>\n runPreevalStage(\n babel,\n evalConfig,\n pluginOptions,\n code,\n originalAst,\n eventEmitter\n )\n );\n\n const transformMetadata = getTransformMetadata(preevalStageResult.metadata);\n\n if (\n only.length === 1 &&\n only[0] === '__linariaPreval' &&\n !transformMetadata\n ) {\n log('[evaluator:end] no metadata');\n return [preevalStageResult.code!, null, null];\n }\n\n log('[preeval] metadata %O', transformMetadata);\n log('[evaluator:start] using %s', evaluator.name);\n\n const evaluatorConfig: EvaluatorConfig = {\n onlyExports: only,\n highPriorityPlugins: pluginOptions.highPriorityPlugins,\n features: pluginOptions.features,\n };\n\n const [, transformedCode, imports] = eventEmitter.perf(\n 'transform:evaluator',\n () =>\n evaluator(\n evalConfig,\n preevalStageResult.ast!,\n preevalStageResult.code!,\n evaluatorConfig,\n babel\n )\n );\n\n log('[evaluator:end]');\n\n return [transformedCode, imports, transformMetadata ?? null];\n};\n\nexport function* internalTransform(\n this: ITransformAction,\n prepareFn: PrepareCodeFn\n): SyncScenarioForAction<ITransformAction> {\n const { only, loadedAndParsed, log } = this.entrypoint;\n if (loadedAndParsed.evaluator === 'ignored') {\n log('is ignored');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n log('>> (%o)', only);\n\n const [preparedCode, imports, metadata] = prepareFn(\n this.services,\n this.entrypoint,\n loadedAndParsed.ast\n );\n\n if (loadedAndParsed.code === preparedCode) {\n log('<< (%o)\\n === no changes ===', only);\n } else {\n log('<< (%o)', only);\n log.extend('source')('%s', preparedCode || EMPTY_FILE);\n }\n\n if (preparedCode === '') {\n log('is skipped');\n return {\n code: loadedAndParsed.code ?? '',\n metadata: null,\n };\n }\n\n if (imports !== null && imports.size > 0) {\n const resolvedImports = yield* this.getNext(\n 'resolveImports',\n this.entrypoint,\n {\n imports,\n }\n );\n\n if (resolvedImports.length !== 0) {\n yield [\n 'processImports',\n this.entrypoint,\n {\n resolved: resolvedImports,\n },\n ];\n }\n }\n\n return {\n code: preparedCode,\n metadata,\n };\n}\n\n/**\n * Prepares the code for evaluation. This includes removing dead and potentially unsafe code.\n * Emits resolveImports and processImports events.\n */\nexport function transform(this: ITransformAction) {\n return internalTransform.call(this, prepareCode);\n}\n"],"mappings":"AAUA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD,SAASC,oBAAoB,QAAQ,+BAA+B;AACpE,SAASC,YAAY,QAAQ,0BAA0B;AAQvD,MAAMC,UAAU,GAAG,oBAAoB;AAEvC,MAAMC,YAAY,GAAGA,CAACC,MAAkB,EAAEC,IAAc,KAAc;EACpE,MAAMC,SAAS,GAAGL,YAAY,CAACG,MAAM,CAAC;EACtC,OAAOE,SAAS,GAAGD,IAAI,CAACE,IAAI,CAAEC,CAAC,IAAKF,SAAS,CAACG,QAAQ,CAACD,CAAC,CAAC,CAAC,GAAG,KAAK;AACpE,CAAC;AAED,SAASE,eAAeA,CACtBC,KAAW,EACXC,UAA4B,EAC5BC,aAA4B,EAC5BC,IAAY,EACZC,WAAiB,EACjBC,YAA0B,EACT;EACjB,MAAMC,eAAe,GACnBL,UAAU,CAACM,OAAO,EAAEC,MAAM,CAAEX,CAAC,IAC3BL,YAAY,CAACK,CAAC,EAAEK,aAAa,CAACO,mBAAmB,CACnD,CAAC,IAAI,EAAE;EAET,MAAMF,OAAO,GAAG,CACd,GAAGD,eAAe,EAClB,CACEI,OAAO,CAACC,OAAO,CAAC,uBAAuB,CAAC,EACxC;IAAE,GAAGT,aAAa;IAAEG;EAAa,CAAC,CACnC,EACD,CAACK,OAAO,CAACC,OAAO,CAAC,8BAA8B,CAAC,CAAC,EACjD,GAAG,CAACV,UAAU,CAACM,OAAO,IAAI,EAAE,EAAEC,MAAM,CACjCX,CAAC,IAAK,CAACL,YAAY,CAACK,CAAC,EAAEK,aAAa,CAACO,mBAAmB,CAC3D,CAAC,CACF;EAED,MAAMG,eAAe,GAAGxB,YAAY,CAAC;IACnC,GAAGa,UAAU;IACbY,OAA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IAAI,CAAC;EAC3C,CAAC,MAAM;IACLD,GAAG,CAAC,SAAS,EAAEC,IAAI,CAAC;IACpBD,GAAG,CAACoB,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAED,YAAY,IAAIlD,UAAU,CAAC;EACxD;EAEA,IAAIkD,YAAY,KAAK,EAAE,EAAE;IACvBnB,GAAG,CAAC,YAAY,CAAC;IACjB,OAAO;MACLnB,IAAI,EAAEqB,eAAe,CAACrB,IAAI,IAAI,EAAE;MAChC2B,QAAQ,EAAE;IACZ,CAAC;EACH;EAEA,IAAIO,OAAO,KAAK,IAAI,IAAIA,OAAO,CAACM,IAAI,GAAG,CAAC,EAAE;IACxC,MAAMC,eAAe,GAAG,OAAO,IAAI,CAACC,OAAO,CACzC,gBAAgB,EAChB,IAAI,CAACL,UAAU,EACf;MACEH;IACF,CACF,CAAC;IAED,IAAIO,eAAe,CAACb,MAAM,KAAK,CAAC,EAAE;MAChC,MAAM,CACJ,gBAAgB,EAChB,IAAI,CAACS,UAAU,EACf;QACEM,QAAQ,EAAEF;MACZ,CAAC,CACF;IACH;EACF;EAEA,OAAO;IACLzC,IAAI,EAAEsC,YAAY;IAClBX;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASiB,SAASA,CAAA,EAAyB;EAChD,OAAOT,iBAAiB,CAACU,IAAI,CAAC,IAAI,EAAE7B,WAAW,CAAC;AAClD"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isAborted } from '../actions/AbortError';
|
|
2
|
+
/**
|
|
3
|
+
* The entry point for file processing. Sequentially calls `processEntrypoint`,
|
|
4
|
+
* `evalFile`, `collect`, and `extract`. Returns the result of transforming
|
|
5
|
+
* the source code as well as all artifacts obtained from code execution.
|
|
6
|
+
*/
|
|
7
|
+
export function* workflow() {
|
|
8
|
+
const {
|
|
9
|
+
cache,
|
|
10
|
+
options
|
|
11
|
+
} = this.services;
|
|
12
|
+
const {
|
|
13
|
+
entrypoint
|
|
14
|
+
} = this;
|
|
15
|
+
if (entrypoint.ignored) {
|
|
16
|
+
return {
|
|
17
|
+
code: entrypoint.loadedAndParsed.code ?? '',
|
|
18
|
+
sourceMap: options.inputSourceMap
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
yield* this.getNext('processEntrypoint', entrypoint, undefined, null);
|
|
23
|
+
entrypoint.assertNotSuperseded();
|
|
24
|
+
} catch (e) {
|
|
25
|
+
if (isAborted(e) && entrypoint.supersededWith) {
|
|
26
|
+
entrypoint.log('workflow aborted, schedule the next attempt');
|
|
27
|
+
return yield* this.getNext('workflow', entrypoint.supersededWith, undefined, null);
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
const originalCode = entrypoint.loadedAndParsed.code ?? '';
|
|
32
|
+
|
|
33
|
+
// File is ignored or does not contain any tags. Return original code.
|
|
34
|
+
if (!entrypoint.hasLinariaMetadata()) {
|
|
35
|
+
if (entrypoint.generation === 1) {
|
|
36
|
+
// 1st generation here means that it's __linariaPreval entrypoint
|
|
37
|
+
// without __linariaPreval, so we don't need it cached
|
|
38
|
+
cache.delete('entrypoints', entrypoint.name);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
code: originalCode,
|
|
42
|
+
sourceMap: options.inputSourceMap
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// *** 2nd stage ***
|
|
47
|
+
|
|
48
|
+
const evalStageResult = yield* this.getNext('evalFile', entrypoint, undefined, null);
|
|
49
|
+
if (evalStageResult === null) {
|
|
50
|
+
return {
|
|
51
|
+
code: originalCode,
|
|
52
|
+
sourceMap: options.inputSourceMap
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const [valueCache, dependencies] = evalStageResult;
|
|
56
|
+
|
|
57
|
+
// *** 3rd stage ***
|
|
58
|
+
|
|
59
|
+
const collectStageResult = yield* this.getNext('collect', entrypoint, {
|
|
60
|
+
valueCache
|
|
61
|
+
}, null);
|
|
62
|
+
if (!collectStageResult.metadata) {
|
|
63
|
+
return {
|
|
64
|
+
code: collectStageResult.code,
|
|
65
|
+
sourceMap: collectStageResult.map
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// *** 4th stage
|
|
70
|
+
|
|
71
|
+
const extractStageResult = yield* this.getNext('extract', entrypoint, {
|
|
72
|
+
processors: collectStageResult.metadata.processors
|
|
73
|
+
}, null);
|
|
74
|
+
return {
|
|
75
|
+
...extractStageResult,
|
|
76
|
+
code: collectStageResult.code ?? '',
|
|
77
|
+
dependencies,
|
|
78
|
+
replacements: [...extractStageResult.replacements, ...collectStageResult.metadata.replacements],
|
|
79
|
+
sourceMap: collectStageResult.map
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.js","names":["isAborted","workflow","cache","options","services","entrypoint","ignored","code","loadedAndParsed","sourceMap","inputSourceMap","getNext","undefined","assertNotSuperseded","e","supersededWith","log","originalCode","hasLinariaMetadata","generation","delete","name","evalStageResult","valueCache","dependencies","collectStageResult","metadata","map","extractStageResult","processors","replacements"],"sources":["../../../src/transform/generators/workflow.ts"],"sourcesContent":["import { isAborted } from '../actions/AbortError';\nimport type { IWorkflowAction, SyncScenarioForAction } from '../types';\n\n/**\n * The entry point for file processing. Sequentially calls `processEntrypoint`,\n * `evalFile`, `collect`, and `extract`. Returns the result of transforming\n * the source code as well as all artifacts obtained from code execution.\n */\nexport function* workflow(\n this: IWorkflowAction\n): SyncScenarioForAction<IWorkflowAction> {\n const { cache, options } = this.services;\n const { entrypoint } = this;\n\n if (entrypoint.ignored) {\n return {\n code: entrypoint.loadedAndParsed.code ?? '',\n sourceMap: options.inputSourceMap,\n };\n }\n\n try {\n yield* this.getNext('processEntrypoint', entrypoint, undefined, null);\n entrypoint.assertNotSuperseded();\n } catch (e) {\n if (isAborted(e) && entrypoint.supersededWith) {\n entrypoint.log('workflow aborted, schedule the next attempt');\n return yield* this.getNext(\n 'workflow',\n entrypoint.supersededWith,\n undefined,\n null\n );\n }\n\n throw e;\n }\n\n const originalCode = entrypoint.loadedAndParsed.code ?? '';\n\n // File is ignored or does not contain any tags. Return original code.\n if (!entrypoint.hasLinariaMetadata()) {\n if (entrypoint.generation === 1) {\n // 1st generation here means that it's __linariaPreval entrypoint\n // without __linariaPreval, so we don't need it cached\n cache.delete('entrypoints', entrypoint.name);\n }\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n // *** 2nd stage ***\n\n const evalStageResult = yield* this.getNext(\n 'evalFile',\n entrypoint,\n undefined,\n null\n );\n\n if (evalStageResult === null) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const [valueCache, dependencies] = evalStageResult;\n\n // *** 3rd stage ***\n\n const collectStageResult = yield* this.getNext(\n 'collect',\n entrypoint,\n {\n valueCache,\n },\n null\n );\n\n if (!collectStageResult.metadata) {\n return {\n code: collectStageResult.code!,\n sourceMap: collectStageResult.map,\n };\n }\n\n // *** 4th stage\n\n const extractStageResult = yield* this.getNext(\n 'extract',\n entrypoint,\n {\n processors: collectStageResult.metadata.processors,\n },\n null\n );\n\n return {\n ...extractStageResult,\n code: collectStageResult.code ?? '',\n dependencies,\n replacements: [\n ...extractStageResult.replacements,\n ...collectStageResult.metadata.replacements,\n ],\n sourceMap: collectStageResult.map,\n };\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAGjD;AACA;AACA;AACA;AACA;AACA,OAAO,UAAUC,QAAQA,CAAA,EAEiB;EACxC,MAAM;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAI,CAACC,QAAQ;EACxC,MAAM;IAAEC;EAAW,CAAC,GAAG,IAAI;EAE3B,IAAIA,UAAU,CAACC,OAAO,EAAE;IACtB,OAAO;MACLC,IAAI,EAAEF,UAAU,CAACG,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AAU,EACV;IACEkB;EACF,CAAC,EACD,IACF,CAAC;EAED,IAAI,CAACE,kBAAkB,CAACC,QAAQ,EAAE;IAChC,OAAO;MACLnB,IAAI,EAAEkB,kBAAkB,CAAClB,IAAK;MAC9BE,SAAS,EAAEgB,kBAAkB,CAACE;IAChC,CAAC;EACH;;EAEA;;EAEA,MAAMC,kBAAkB,GAAG,OAAO,IAAI,CAACjB,OAAO,CAC5C,SAAS,EACTN,UAAU,EACV;IACEwB,UAAU,EAAEJ,kBAAkB,CAACC,QAAQ,CAACG;EAC1C,CAAC,EACD,IACF,CAAC;EAED,OAAO;IACL,GAAGD,kBAAkB;IACrBrB,IAAI,EAAEkB,kBAAkB,CAAClB,IAAI,IAAI,EAAE;IACnCiB,YAAY;IACZM,YAAY,EAAE,CACZ,GAAGF,kBAAkB,CAACE,YAAY,EAClC,GAAGL,kBAAkB,CAACC,QAAQ,CAACI,YAAY,CAC5C;IACDrB,SAAS,EAAEgB,kBAAkB,CAACE;EAChC,CAAC;AACH"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { cosmiconfigSync } from 'cosmiconfig';
|
|
2
|
+
import shaker from '../../shaker';
|
|
3
|
+
const searchPlaces = [`.linariarc`, `.linariarc.json`, `.linariarc.yaml`, `.linariarc.yml`, `.linariarc.js`, `.linariarc.cjs`, `.config/linariarc`, `.config/linariarc.json`, `.config/linariarc.yaml`, `.config/linariarc.yml`, `.config/linariarc.js`, `.config/linariarc.cjs`, `linaria.config.js`, `linaria.config.cjs`];
|
|
4
|
+
const explorerSync = cosmiconfigSync('linaria', {
|
|
5
|
+
searchPlaces
|
|
6
|
+
});
|
|
7
|
+
const cache = new WeakMap();
|
|
8
|
+
const defaultOverrides = {};
|
|
9
|
+
const nodeModulesRegExp = /[\\/]node_modules[\\/]/;
|
|
10
|
+
export function loadLinariaOptions(overrides = defaultOverrides) {
|
|
11
|
+
if (cache.has(overrides)) {
|
|
12
|
+
return cache.get(overrides);
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
configFile,
|
|
16
|
+
ignore,
|
|
17
|
+
rules,
|
|
18
|
+
babelOptions = {},
|
|
19
|
+
...rest
|
|
20
|
+
} = overrides;
|
|
21
|
+
const result =
|
|
22
|
+
// eslint-disable-next-line no-nested-ternary
|
|
23
|
+
configFile === false ? undefined : configFile !== undefined ? explorerSync.load(configFile) : explorerSync.search();
|
|
24
|
+
const defaultFeatures = {
|
|
25
|
+
dangerousCodeRemover: true,
|
|
26
|
+
globalCache: true,
|
|
27
|
+
happyDOM: true,
|
|
28
|
+
softErrors: false,
|
|
29
|
+
useBabelConfigs: true
|
|
30
|
+
};
|
|
31
|
+
const options = {
|
|
32
|
+
displayName: false,
|
|
33
|
+
evaluate: true,
|
|
34
|
+
extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],
|
|
35
|
+
rules: rules ?? [{
|
|
36
|
+
action: shaker
|
|
37
|
+
}, {
|
|
38
|
+
// The old `ignore` option is used as a default value for `ignore` rule.
|
|
39
|
+
test: ignore ?? nodeModulesRegExp,
|
|
40
|
+
action: 'ignore'
|
|
41
|
+
}, {
|
|
42
|
+
// Do not ignore ES-modules
|
|
43
|
+
test: (filename, code) => {
|
|
44
|
+
if (!nodeModulesRegExp.test(filename)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If a file contains `export` or `import` keywords, we assume it's an ES-module
|
|
49
|
+
return /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(code);
|
|
50
|
+
},
|
|
51
|
+
action: shaker
|
|
52
|
+
}],
|
|
53
|
+
babelOptions,
|
|
54
|
+
highPriorityPlugins: ['module-resolver'],
|
|
55
|
+
...(result ? result.config : {}),
|
|
56
|
+
...rest,
|
|
57
|
+
features: {
|
|
58
|
+
...defaultFeatures,
|
|
59
|
+
...(result ? result.config.features : {}),
|
|
60
|
+
...rest.features
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
cache.set(overrides, options);
|
|
64
|
+
return options;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=loadLinariaOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadLinariaOptions.js","names":["cosmiconfigSync","shaker","searchPlaces","explorerSync","cache","WeakMap","defaultOverrides","nodeModulesRegExp","loadLinariaOptions","overrides","has","get","configFile","ignore","rules","babelOptions","rest","result","undefined","load","search","defaultFeatures","dangerousCodeRemover","globalCache","happyDOM","softErrors","useBabelConfigs","options","displayName","evaluate","extensions","action","test","filename","code","highPriorityPlugins","config","features","set"],"sources":["../../../src/transform/helpers/loadLinariaOptions.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig';\n\nimport type { FeatureFlags, StrictOptions } from '@wyw-in-js/shared';\n\nimport shaker from '../../shaker';\nimport type { PluginOptions } from '../../types';\n\nconst searchPlaces = [\n `.linariarc`,\n `.linariarc.json`,\n `.linariarc.yaml`,\n `.linariarc.yml`,\n `.linariarc.js`,\n `.linariarc.cjs`,\n `.config/linariarc`,\n `.config/linariarc.json`,\n `.config/linariarc.yaml`,\n `.config/linariarc.yml`,\n `.config/linariarc.js`,\n `.config/linariarc.cjs`,\n `linaria.config.js`,\n `linaria.config.cjs`,\n];\n\nconst explorerSync = cosmiconfigSync('linaria', { searchPlaces });\n\nexport type PartialOptions = Partial<Omit<PluginOptions, 'features'>> & {\n features?: Partial<FeatureFlags>;\n};\n\nconst cache = new WeakMap<Partial<PartialOptions>, StrictOptions>();\nconst defaultOverrides = {};\nconst nodeModulesRegExp = /[\\\\/]node_modules[\\\\/]/;\n\nexport function loadLinariaOptions(\n overrides: PartialOptions = defaultOverrides\n): StrictOptions {\n if (cache.has(overrides)) {\n return cache.get(overrides)!;\n }\n\n const { configFile, ignore, rules, babelOptions = {}, ...rest } = overrides;\n\n const result =\n // eslint-disable-next-line no-nested-ternary\n configFile === false\n ? undefined\n : configFile !== undefined\n ? explorerSync.load(configFile)\n : explorerSync.search();\n\n const defaultFeatures: FeatureFlags = {\n dangerousCodeRemover: true,\n globalCache: true,\n happyDOM: true,\n softErrors: false,\n useBabelConfigs: true,\n };\n\n const options: StrictOptions = {\n displayName: false,\n evaluate: true,\n extensions: ['.cjs', '.cts', '.js', '.jsx', '.mjs', '.mts', '.ts', '.tsx'],\n rules: rules ?? [\n {\n action: shaker,\n },\n {\n // The old `ignore` option is used as a default value for `ignore` rule.\n test: ignore ?? nodeModulesRegExp,\n action: 'ignore',\n },\n {\n // Do not ignore ES-modules\n test: (filename, code) => {\n if (!nodeModulesRegExp.test(filename)) {\n return false;\n }\n\n // If a file contains `export` or `import` keywords, we assume it's an ES-module\n return /(?:^|\\*\\/|;)\\s*(?:export|import)\\s/m.test(code);\n },\n action: shaker,\n },\n ],\n babelOptions,\n highPriorityPlugins: ['module-resolver'],\n ...(result ? result.config : {}),\n ...rest,\n features: {\n ...defaultFeatures,\n ...(result ? result.config.features : {}),\n ...rest.features,\n },\n };\n\n cache.set(overrides, options);\n\n return options;\n}\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,aAAa;AAI7C,OAAOC,MAAM,MAAM,cAAc;AAGjC,MAAMC,YAAY,GAAG,CAClB,YAAW,EACX,iBAAgB,EAChB,iBAAgB,EAChB,gBAAe,EACf,eAAc,EACd,gBAAe,EACf,mBAAkB,EAClB,wBAAuB,EACvB,wBAAuB,EACvB,uBAAsB,EACtB,sBAAqB,EACrB,uBAAsB,EACtB,mBAAkB,EAClB,oBAAmB,CACrB;AAED,MAAMC,YAAY,GAAGH,eAAe,CAAC,SAAS,EAAE;EAAEE;AAAa,CAAC,CAAC;AAMjE,MAAME,KAAK,GAAG,IAAIC,OAAO,CAAyC,CAAC;AACnE,MAAMC,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAMC,iBAAiB,GAAG,wBAAwB;AAElD,OAAO,SAASC,kBAAkBA,CAChCC,SAAyB,GAAGH,gBAAgB,EAC7B;EACf,IAAIF,KAAK,CAACM,GAA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A,MAAM,CAACmB,MAAM,GAAG,CAAC,CAAC,CAAC;IAChC,GAAGpB,IAAI;IACPqB,QAAQ,EAAE;MACR,GAAGhB,eAAe;MAClB,IAAIJ,MAAM,GAAGA,MAAM,CAACmB,MAAM,CAACC,QAAQ,GAAG,CAAC,CAAC,CAAC;MACzC,GAAGrB,IAAI,CAACqB;IACV;EACF,CAAC;EAEDjC,KAAK,CAACkC,GAAG,CAAC7B,SAAS,EAAEkB,OAAO,CAAC;EAE7B,OAAOA,OAAO;AAChB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as babelCore from '@babel/core';
|
|
2
|
+
import { TransformCacheCollection } from '../../cache';
|
|
3
|
+
import { EventEmitter } from '../../utils/EventEmitter';
|
|
4
|
+
import { loadAndParse } from '../Entrypoint.helpers';
|
|
5
|
+
import { rootLog } from '../rootLog';
|
|
6
|
+
export const withDefaultServices = ({
|
|
7
|
+
babel = babelCore,
|
|
8
|
+
cache = new TransformCacheCollection(),
|
|
9
|
+
eventEmitter = EventEmitter.dummy,
|
|
10
|
+
loadAndParseFn = loadAndParse,
|
|
11
|
+
log = rootLog,
|
|
12
|
+
options
|
|
13
|
+
}) => ({
|
|
14
|
+
babel,
|
|
15
|
+
cache,
|
|
16
|
+
eventEmitter,
|
|
17
|
+
loadAndParseFn,
|
|
18
|
+
log,
|
|
19
|
+
options
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=withDefaultServices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withDefaultServices.js","names":["babelCore","TransformCacheCollection","EventEmitter","loadAndParse","rootLog","withDefaultServices","babel","cache","eventEmitter","dummy","loadAndParseFn","log","options"],"sources":["../../../src/transform/helpers/withDefaultServices.ts"],"sourcesContent":["import * as babelCore from '@babel/core';\n\nimport { TransformCacheCollection } from '../../cache';\nimport { EventEmitter } from '../../utils/EventEmitter';\nimport { loadAndParse } from '../Entrypoint.helpers';\nimport { rootLog } from '../rootLog';\nimport type { Services } from '../types';\n\ntype RequiredServices = 'options';\nexport type PartialServices = Partial<Omit<Services, RequiredServices>> &\n Pick<Services, RequiredServices>;\n\nexport const withDefaultServices = ({\n babel = babelCore,\n cache = new TransformCacheCollection(),\n eventEmitter = EventEmitter.dummy,\n loadAndParseFn = loadAndParse,\n log = rootLog,\n options,\n}: PartialServices): Services => ({\n babel,\n cache,\n eventEmitter,\n loadAndParseFn,\n log,\n options,\n});\n"],"mappings":"AAAA,OAAO,KAAKA,SAAS,MAAM,aAAa;AAExC,SAASC,wBAAwB,QAAQ,aAAa;AACtD,SAASC,YAAY,QAAQ,0BAA0B;AACvD,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,OAAO,QAAQ,YAAY;AAOpC,OAAO,MAAMC,mBAAmB,GAAGA,CAAC;EAClCC,KAAK,GAAGN,SAAS;EACjBO,KAAK,GAAG,IAAIN,wBAAwB,CAAC,CAAC;EACtCO,YAAY,GAAGN,YAAY,CAACO,KAAK;EACjCC,cAAc,GAAGP,YAAY;EAC7BQ,GAAG,GAAGP,OAAO;EACbQ;AACe,CAAC,MAAgB;EAChCN,KAAK;EACLC,KAAK;EACLC,YAAY;EACZE,cAAc;EACdC,GAAG;EACHC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootLog.js","names":["logger","rootLog","extend"],"sources":["../../src/transform/rootLog.ts"],"sourcesContent":["import type { Debugger } from '@wyw-in-js/shared';\nimport { logger } from '@wyw-in-js/shared';\n\nexport const rootLog: Debugger = logger.extend('transform');\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,mBAAmB;AAE1C,OAAO,MAAMC,OAAiB,GAAGD,MAAM,CAACE,MAAM,CAAC,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":["Pending","Symbol"],"sources":["../../src/transform/types.ts"],"sourcesContent":["import type { BabelFileResult } from '@babel/core';\n\nimport type { ValueCache } from '@wyw-in-js/processor-utils';\nimport type { Debugger, Artifact, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport type { TransformCacheCollection } from '../cache';\nimport type { Options, ITransformFileResult } from '../types';\nimport type { EventEmitter } from '../utils/EventEmitter';\nimport type { WYWTransformMetadata } from '../utils/TransformMetadata';\n\nimport type { Entrypoint } from './Entrypoint';\nimport type { LoadAndParseFn, IEntrypointDependency } from './Entrypoint.types';\nimport type { BaseAction } from './actions/BaseAction';\nimport type {\n IExtracted,\n IWorkflowActionLinariaResult,\n IWorkflowActionNonLinariaResult,\n} from './actions/types';\n\nexport type Services = {\n babel: Core;\n cache: TransformCacheCollection;\n eventEmitter: EventEmitter;\n loadAndParseFn: LoadAndParseFn;\n log: Debugger;\n options: Options & {\n pluginOptions: StrictOptions;\n };\n};\n\nexport interface IBaseNode {\n type: ActionTypes;\n}\n\nexport type ActionByType<TType extends ActionQueueItem['type']> = Extract<\n ActionQueueItem,\n {\n type: TType;\n }\n>;\n\nexport const Pending = Symbol('pending');\n\nexport type YieldResult = Exclude<ActionQueueItem['result'], typeof Pending>;\n\nexport type AnyIteratorResult<TMode extends 'async' | 'sync', TResult> = {\n async: Promise<IteratorResult<YieldArg, TResult>>;\n sync: IteratorResult<YieldArg, TResult>;\n}[TMode];\n\nexport interface IBaseAction<TAction extends ActionQueueItem, TResult, TData>\n extends IBaseNode {\n abortSignal: AbortSignal | null;\n createAbortSignal: () => AbortSignal & Disposable;\n data: TData;\n entrypoint: Entrypoint;\n getNext: GetNext;\n idx: string;\n result: TResult | typeof Pending;\n run: <TMode extends 'async' | 'sync'>(\n handler: Handler<TMode, TAction>\n ) => {\n next: (arg: YieldResult) => AnyIteratorResult<TMode, TResult>;\n throw(e: unknown): AnyIteratorResult<TMode, TResult>;\n };\n services: Services;\n}\n\ntype NextParams<\n TType extends ActionTypes,\n TNextAction extends ActionByType<TType> = ActionByType<TType>,\n> = [\n type: TType,\n entrypoint: Entrypoint,\n data: TNextAction['data'],\n abortSignal?: AbortSignal | null,\n];\n\nexport type YieldArg = {\n [K in ActionQueueItem['type']]: NextParams<K>;\n}[ActionQueueItem['type']];\n\nexport type SyncScenarioFor<TResult> = {\n [Symbol.iterator](): SyncScenarioFor<TResult>;\n next(arg: YieldResult): IteratorResult<YieldArg, TResult>;\n return(value: TResult): IteratorResult<YieldArg, TResult>;\n throw(e: unknown): IteratorResult<YieldArg, TResult>;\n};\n\nexport type AsyncScenarioFor<TResult> = {\n [Symbol.asyncIterator](): AsyncScenarioFor<TResult>;\n next(arg: YieldResult): Promise<IteratorResult<YieldArg, TResult>>;\n return(\n value: TResult | PromiseLike<TResult>\n ): Promise<IteratorResult<YieldArg, TResult>>;\n throw(e: unknown): Promise<IteratorResult<YieldArg, TResult>>;\n};\n\nexport type SyncScenarioForAction<TAction extends ActionQueueItem> =\n SyncScenarioFor<TypeOfResult<TAction>>;\n\nexport type AsyncScenarioForAction<TAction extends ActionQueueItem> =\n AsyncScenarioFor<TypeOfResult<TAction>>;\n\nexport type Handler<\n TMode extends 'async' | 'sync',\n TAction extends ActionQueueItem,\n> = ((this: BaseAction<TAction>) => {\n async: AsyncScenarioForAction<TAction>;\n sync: SyncScenarioForAction<TAction>;\n}[TMode]) & {\n recover?: (e: unknown, action: BaseAction<TAction>) => YieldArg;\n};\n\nexport type Handlers<TMode extends 'async' | 'sync'> = {\n [TAction in ActionQueueItem as TAction['type']]: Handler<TMode, TAction>;\n};\n\nexport type TypeOfResult<T extends ActionQueueItem> = Exclude<\n T['result'],\n typeof Pending\n>;\n\nexport type GetNext = <\n TType extends ActionTypes,\n TNextAction extends ActionByType<TType> = ActionByType<TType>,\n>(\n ...args: NextParams<TType, TNextAction>\n) => Generator<\n [TType, Entrypoint, TNextAction['data'], AbortSignal | null],\n TypeOfResult<TNextAction>,\n YieldResult\n>;\n\nexport interface ICollectActionResult {\n ast: BabelFileResult['ast']; // FIXME: looks like this is not used\n code: BabelFileResult['code'];\n map?: BabelFileResult['map'];\n metadata?: WYWTransformMetadata | null;\n}\n\nexport interface ICollectAction\n extends IBaseAction<\n ICollectAction,\n ICollectActionResult,\n { valueCache: ValueCache }\n > {\n type: 'collect';\n}\n\nexport interface IEvalAction\n extends IBaseAction<IEvalAction, [ValueCache, string[]] | null, undefined> {\n type: 'evalFile';\n}\n\nexport interface IExplodeReexportsAction\n extends IBaseAction<IExplodeReexportsAction, void, undefined> {\n type: 'explodeReexports';\n}\n\nexport interface IExtractAction\n extends IBaseAction<\n IExtractAction,\n IExtracted,\n { processors: { artifacts: Artifact[] }[] }\n > {\n type: 'extract';\n}\n\nexport interface IGetExportsAction\n extends IBaseAction<IGetExportsAction, string[], undefined> {\n type: 'getExports';\n}\n\nexport interface IProcessEntrypointAction\n extends IBaseAction<IProcessEntrypointAction, void, undefined> {\n type: 'processEntrypoint';\n}\n\nexport interface IProcessImportsAction\n extends IBaseAction<\n IProcessImportsAction,\n void,\n {\n resolved: IEntrypointDependency[];\n }\n > {\n type: 'processImports';\n}\n\nexport interface IResolveImportsAction\n extends IBaseAction<\n IResolveImportsAction,\n IEntrypointDependency[],\n {\n imports: Map<string, string[]> | null;\n }\n > {\n type: 'resolveImports';\n}\n\nexport interface ITransformAction\n extends IBaseAction<ITransformAction, ITransformFileResult, undefined> {\n type: 'transform';\n}\n\nexport interface IWorkflowAction\n extends IBaseAction<\n IWorkflowAction,\n IWorkflowActionLinariaResult | IWorkflowActionNonLinariaResult,\n undefined\n > {\n type: 'workflow';\n}\n\nexport type ActionQueueItem =\n | IEvalAction\n | IExplodeReexportsAction\n | IExtractAction\n | IGetExportsAction\n | ICollectAction\n | IProcessEntrypointAction\n | IProcessImportsAction\n | IResolveImportsAction\n | ITransformAction\n | IWorkflowAction;\n\nexport type ActionTypes = ActionQueueItem['type'];\n"],"mappings":"AA0CA,OAAO,MAAMA,OAAO,GAAGC,MAAM,CAAC,SAAS,CAAC"}
|