@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,168 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, extname, isAbsolute } from 'path';
|
|
3
|
+
import { logger, isFeatureEnabled } from '@wyw-in-js/shared';
|
|
4
|
+
import { buildOptions } from '../options/buildOptions';
|
|
5
|
+
import { loadBabelOptions } from '../options/loadBabelOptions';
|
|
6
|
+
import { getFileIdx } from '../utils/getFileIdx';
|
|
7
|
+
import { getPluginKey } from '../utils/getPluginKey';
|
|
8
|
+
export function getMatchedRule(rules, filename, code) {
|
|
9
|
+
for (let i = rules.length - 1; i >= 0; i--) {
|
|
10
|
+
const rule = rules[i];
|
|
11
|
+
if (!rule.test) {
|
|
12
|
+
return rule;
|
|
13
|
+
}
|
|
14
|
+
if (typeof rule.test === 'function' && rule.test(filename, code)) {
|
|
15
|
+
return rule;
|
|
16
|
+
}
|
|
17
|
+
if (rule.test instanceof RegExp && rule.test.test(filename)) {
|
|
18
|
+
return rule;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
action: 'ignore'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function parseFile(babel, filename, originalCode, parseConfig) {
|
|
26
|
+
const log = logger.extend('transform:parse').extend(getFileIdx(filename));
|
|
27
|
+
const parseResult = babel.parseSync(originalCode, parseConfig);
|
|
28
|
+
if (!parseResult) {
|
|
29
|
+
throw new Error(`Failed to parse ${filename}`);
|
|
30
|
+
}
|
|
31
|
+
log('stage-1', `${filename} has been parsed`);
|
|
32
|
+
return parseResult;
|
|
33
|
+
}
|
|
34
|
+
const isModuleResolver = plugin => {
|
|
35
|
+
const key = getPluginKey(plugin);
|
|
36
|
+
if (!key) return false;
|
|
37
|
+
if (['module-resolver', 'babel-plugin-module-resolver'].includes(key)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return /([\\/])babel-plugin-module-resolver\1/.test(key);
|
|
41
|
+
};
|
|
42
|
+
let moduleResolverWarned = false;
|
|
43
|
+
function buildConfigs(services, name, pluginOptions, babelOptions) {
|
|
44
|
+
const {
|
|
45
|
+
babel,
|
|
46
|
+
options
|
|
47
|
+
} = services;
|
|
48
|
+
const commonOptions = {
|
|
49
|
+
ast: true,
|
|
50
|
+
filename: name,
|
|
51
|
+
inputSourceMap: options.inputSourceMap,
|
|
52
|
+
root: options.root,
|
|
53
|
+
sourceFileName: name,
|
|
54
|
+
sourceMaps: true
|
|
55
|
+
};
|
|
56
|
+
const rawConfig = buildOptions(pluginOptions?.babelOptions, babelOptions, commonOptions);
|
|
57
|
+
const useBabelConfigs = isFeatureEnabled(pluginOptions.features, 'useBabelConfigs', name);
|
|
58
|
+
if (!useBabelConfigs) {
|
|
59
|
+
rawConfig.configFile = false;
|
|
60
|
+
}
|
|
61
|
+
const parseConfig = loadBabelOptions(babel, name, {
|
|
62
|
+
babelrc: useBabelConfigs,
|
|
63
|
+
...rawConfig
|
|
64
|
+
});
|
|
65
|
+
const parseHasModuleResolver = parseConfig.plugins?.some(isModuleResolver);
|
|
66
|
+
const rawHasModuleResolver = rawConfig.plugins?.some(isModuleResolver);
|
|
67
|
+
if (parseHasModuleResolver && !rawHasModuleResolver) {
|
|
68
|
+
if (!moduleResolverWarned) {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.warn(`[linaria] ${name} has a module-resolver plugin in its babelrc, but it is not present ` + `in the babelOptions for the linaria plugin. This works for now but will be an error in the future. ` + `Please add the module-resolver plugin to the babelOptions for the linaria plugin.`);
|
|
71
|
+
moduleResolverWarned = true;
|
|
72
|
+
}
|
|
73
|
+
rawConfig.plugins = [...(parseConfig.plugins?.filter(plugin => isModuleResolver(plugin)) ?? []), ...(rawConfig.plugins ?? [])];
|
|
74
|
+
}
|
|
75
|
+
const evalConfig = loadBabelOptions(babel, name, {
|
|
76
|
+
babelrc: false,
|
|
77
|
+
...rawConfig
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
evalConfig,
|
|
81
|
+
parseConfig
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function loadAndParse(services, name, loadedCode, log) {
|
|
85
|
+
const {
|
|
86
|
+
babel,
|
|
87
|
+
eventEmitter,
|
|
88
|
+
options: {
|
|
89
|
+
pluginOptions
|
|
90
|
+
}
|
|
91
|
+
} = services;
|
|
92
|
+
const extension = extname(name);
|
|
93
|
+
if (!pluginOptions.extensions.includes(extension)) {
|
|
94
|
+
log('[createEntrypoint] %s is ignored. If you want it to be processed, you should add \'%s\' to the "extensions" option.', name, extension);
|
|
95
|
+
return {
|
|
96
|
+
get code() {
|
|
97
|
+
if (isAbsolute(name)) {
|
|
98
|
+
return loadedCode ?? readFileSync(name, 'utf-8');
|
|
99
|
+
}
|
|
100
|
+
return ''; // it is a built-in module
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
evaluator: 'ignored',
|
|
104
|
+
reason: 'extension'
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const code = loadedCode ?? readFileSync(name, 'utf-8');
|
|
108
|
+
const {
|
|
109
|
+
action,
|
|
110
|
+
babelOptions
|
|
111
|
+
} = getMatchedRule(pluginOptions.rules, name, code);
|
|
112
|
+
let ast;
|
|
113
|
+
const {
|
|
114
|
+
evalConfig,
|
|
115
|
+
parseConfig
|
|
116
|
+
} = buildConfigs(services, name, pluginOptions, babelOptions);
|
|
117
|
+
const getOrParse = () => {
|
|
118
|
+
if (ast) return ast;
|
|
119
|
+
ast = eventEmitter.perf('parseFile', () => parseFile(babel, name, code, parseConfig));
|
|
120
|
+
return ast;
|
|
121
|
+
};
|
|
122
|
+
if (action === 'ignore') {
|
|
123
|
+
log('[createEntrypoint] %s is ignored by rule', name);
|
|
124
|
+
return {
|
|
125
|
+
get ast() {
|
|
126
|
+
return getOrParse();
|
|
127
|
+
},
|
|
128
|
+
code,
|
|
129
|
+
evaluator: 'ignored',
|
|
130
|
+
reason: 'rule'
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const evaluator = typeof action === 'function' ? action : require(require.resolve(action, {
|
|
134
|
+
paths: [dirname(name)]
|
|
135
|
+
})).default;
|
|
136
|
+
return {
|
|
137
|
+
get ast() {
|
|
138
|
+
return getOrParse();
|
|
139
|
+
},
|
|
140
|
+
code,
|
|
141
|
+
evaluator,
|
|
142
|
+
evalConfig
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export function getStack(entrypoint) {
|
|
146
|
+
if (!entrypoint) return [];
|
|
147
|
+
const stack = [entrypoint.name];
|
|
148
|
+
let {
|
|
149
|
+
parents
|
|
150
|
+
} = entrypoint;
|
|
151
|
+
while (parents.length) {
|
|
152
|
+
stack.push(parents[0].name);
|
|
153
|
+
parents = parents[0].parents;
|
|
154
|
+
}
|
|
155
|
+
return stack;
|
|
156
|
+
}
|
|
157
|
+
export function mergeOnly(a, b) {
|
|
158
|
+
const result = new Set(a);
|
|
159
|
+
b.forEach(item => result.add(item));
|
|
160
|
+
return [...result].filter(i => i).sort();
|
|
161
|
+
}
|
|
162
|
+
export const isSuperSet = (a, b) => {
|
|
163
|
+
if (a.includes('*')) return true;
|
|
164
|
+
if (b.length === 0) return true;
|
|
165
|
+
const aSet = new Set(a);
|
|
166
|
+
return b.every(item => aSet.has(item));
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=Entrypoint.helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Entrypoint.helpers.js","names":["readFileSync","dirname","extname","isAbsolute","logger","isFeatureEnabled","buildOptions","loadBabelOptions","getFileIdx","getPluginKey","getMatchedRule","rules","filename","code","i","length","rule","test","RegExp","action","parseFile","babel","originalCode","parseConfig","log","extend","parseResult","parseSync","Error","isModuleResolver","plugin","key","includes","moduleResolverWarned","buildConfigs","services","name","pluginOptions","babelOptions","options","commonOptions","ast","inputSourceMap","root","sourceFileName","sourceMaps","rawConfig","useBabelConfigs","features","configFile","babelrc","parseHasModuleResolver","plugins","some","rawHasModuleResolver","console","warn","filter","evalConfig","loadAndParse","loadedCode","eventEmitter","extension","extensions","evaluator","reason","getOrParse","perf","require","resolve","paths","default","getStack","entrypoint","stack","parents","push","mergeOnly","a","b","result","Set","forEach","item","add","sort","isSuperSet","aSet","every","has"],"sources":["../../src/transform/Entrypoint.helpers.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, extname, isAbsolute } from 'path';\n\nimport type { TransformOptions, PluginItem } from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type {\n Debugger,\n EvalRule,\n Evaluator,\n StrictOptions,\n} from '@wyw-in-js/shared';\nimport { logger, isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport type { Core } from '../babel';\nimport { buildOptions } from '../options/buildOptions';\nimport { loadBabelOptions } from '../options/loadBabelOptions';\nimport type { ParentEntrypoint } from '../types';\nimport { getFileIdx } from '../utils/getFileIdx';\nimport { getPluginKey } from '../utils/getPluginKey';\n\nimport type { IEntrypointCode, IIgnoredEntrypoint } from './Entrypoint.types';\nimport type { Services } from './types';\n\nexport function getMatchedRule(\n rules: EvalRule[],\n filename: string,\n code: string\n): EvalRule {\n for (let i = rules.length - 1; i >= 0; i--) {\n const rule = rules[i];\n if (!rule.test) {\n return rule;\n }\n\n if (typeof rule.test === 'function' && rule.test(filename, code)) {\n return rule;\n }\n\n if (rule.test instanceof RegExp && rule.test.test(filename)) {\n return rule;\n }\n }\n\n return { action: 'ignore' };\n}\n\nexport function parseFile(\n babel: Core,\n filename: string,\n originalCode: string,\n parseConfig: TransformOptions\n): File {\n const log = logger.extend('transform:parse').extend(getFileIdx(filename));\n\n const parseResult = babel.parseSync(originalCode, parseConfig);\n if (!parseResult) {\n throw new Error(`Failed to parse ${filename}`);\n }\n\n log('stage-1', `${filename} has been parsed`);\n\n return parseResult;\n}\n\nconst isModuleResolver = (plugin: PluginItem) => {\n const key = getPluginKey(plugin);\n if (!key) return false;\n\n if (['module-resolver', 'babel-plugin-module-resolver'].includes(key)) {\n return true;\n }\n\n return /([\\\\/])babel-plugin-module-resolver\\1/.test(key);\n};\n\nlet moduleResolverWarned = false;\n\nfunction buildConfigs(\n services: Services,\n name: string,\n pluginOptions: StrictOptions,\n babelOptions: TransformOptions | undefined\n): {\n evalConfig: TransformOptions;\n parseConfig: TransformOptions;\n} {\n const { babel, options } = services;\n\n const commonOptions = {\n ast: true,\n filename: name,\n inputSourceMap: options.inputSourceMap,\n root: options.root,\n sourceFileName: name,\n sourceMaps: true,\n };\n\n const rawConfig = buildOptions(\n pluginOptions?.babelOptions,\n babelOptions,\n commonOptions\n );\n\n const useBabelConfigs = isFeatureEnabled(\n pluginOptions.features,\n 'useBabelConfigs',\n name\n );\n\n if (!useBabelConfigs) {\n rawConfig.configFile = false;\n }\n\n const parseConfig = loadBabelOptions(babel, name, {\n babelrc: useBabelConfigs,\n ...rawConfig,\n });\n\n const parseHasModuleResolver = parseConfig.plugins?.some(isModuleResolver);\n const rawHasModuleResolver = rawConfig.plugins?.some(isModuleResolver);\n\n if (parseHasModuleResolver && !rawHasModuleResolver) {\n if (!moduleResolverWarned) {\n // eslint-disable-next-line no-console\n console.warn(\n `[linaria] ${name} has a module-resolver plugin in its babelrc, but it is not present ` +\n `in the babelOptions for the linaria plugin. This works for now but will be an error in the future. ` +\n `Please add the module-resolver plugin to the babelOptions for the linaria plugin.`\n );\n\n moduleResolverWarned = true;\n }\n\n rawConfig.plugins = [\n ...(parseConfig.plugins?.filter((plugin) => isModuleResolver(plugin)) ??\n []),\n ...(rawConfig.plugins ?? []),\n ];\n }\n\n const evalConfig = loadBabelOptions(babel, name, {\n babelrc: false,\n ...rawConfig,\n });\n\n return {\n evalConfig,\n parseConfig,\n };\n}\n\nexport function loadAndParse(\n services: Services,\n name: string,\n loadedCode: string | undefined,\n log: Debugger\n): IEntrypointCode | IIgnoredEntrypoint {\n const {\n babel,\n eventEmitter,\n options: { pluginOptions },\n } = services;\n\n const extension = extname(name);\n\n if (!pluginOptions.extensions.includes(extension)) {\n log(\n '[createEntrypoint] %s is ignored. If you want it to be processed, you should add \\'%s\\' to the \"extensions\" option.',\n name,\n extension\n );\n\n return {\n get code() {\n if (isAbsolute(name)) {\n return loadedCode ?? readFileSync(name, 'utf-8');\n }\n\n return ''; // it is a built-in module\n },\n evaluator: 'ignored',\n reason: 'extension',\n };\n }\n\n const code = loadedCode ?? readFileSync(name, 'utf-8');\n\n const { action, babelOptions } = getMatchedRule(\n pluginOptions.rules,\n name,\n code\n );\n\n let ast: File | undefined;\n\n const { evalConfig, parseConfig } = buildConfigs(\n services,\n name,\n pluginOptions,\n babelOptions\n );\n\n const getOrParse = () => {\n if (ast) return ast;\n ast = eventEmitter.perf('parseFile', () =>\n parseFile(babel, name, code, parseConfig)\n );\n\n return ast;\n };\n\n if (action === 'ignore') {\n log('[createEntrypoint] %s is ignored by rule', name);\n return {\n get ast() {\n return getOrParse();\n },\n code,\n evaluator: 'ignored',\n reason: 'rule',\n };\n }\n\n const evaluator: Evaluator =\n typeof action === 'function'\n ? action\n : require(\n require.resolve(action, {\n paths: [dirname(name)],\n })\n ).default;\n\n return {\n get ast() {\n return getOrParse();\n },\n code,\n evaluator,\n evalConfig,\n };\n}\n\nexport function getStack(entrypoint: ParentEntrypoint) {\n if (!entrypoint) return [];\n\n const stack = [entrypoint.name];\n\n let { parents } = entrypoint;\n while (parents.length) {\n stack.push(parents[0].name);\n parents = parents[0].parents;\n }\n\n return stack;\n}\n\nexport function mergeOnly(a: string[], b: string[]) {\n const result = new Set(a);\n b.forEach((item) => result.add(item));\n return [...result].filter((i) => i).sort();\n}\n\nexport const isSuperSet = <T>(a: (T | '*')[], b: (T | '*')[]) => {\n if (a.includes('*')) return true;\n if (b.length === 0) return true;\n const aSet = new Set(a);\n return b.every((item) => aSet.has(item));\n};\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,OAAO,EAAEC,OAAO,EAAEC,UAAU,QAAQ,MAAM;AAWnD,SAASC,MAAM,EAAEC,gBAAgB,QAAQ,mBAAmB;AAG5D,SAASC,YAAY,QAAQ,yBAAyB;AACtD,SAASC,gBAAgB,QAAQ,6BAA6B;AAE9D,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,YAAY,QAAQ,uBAAuB;AAKpD,OAAO,SAASC,cAAcA,CAC5BC,KAAiB,EACjBC,QAAgB,EAChBC,IAAY,EACF;EACV,KAAK,IAAIC,CAAC,GAAGH,KAAK,CAACI,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;IAC1C,MAAME,IAAI,GAAGL,KAAK,CAACG,CAAC,CAAC;IACrB,IAAI,CAACE,IAAI,CAACC,IAAI,EAAE;MACd,OAAOD,IAAI;IACb;IAEA,IAAI,OAAOA,IAAI,CAACC,IAAI,KAAK,UAAU,IAAID,IAAI,CAACC,IAAI,CAACL,QAAQ,EAAEC,IAAI,CAAC,EAAE;MAChE,OAAOG,IAAI;IACb;IAEA,IAAIA,IAAI,CAACC,IAAI,YAAYC,MAAM,IAAIF,IAAI,CAACC,IAAI,CAACA,IAAI,CAACL,QAAQ,CAAC,EAAE;MAC3D,OAAOI,IAAI;IACb;EACF;EAEA,OAAO;IAAEG,MAAM,EAAE;EAAS,CAAC;AAC7B;AAEA,OAAO,SAASC,SAASA,CACvBC,KAAW,EACXT,QAAgB,EAChBU,YAAoB,EACpBC,WAA6B,EACvB;EACN,MAAMC,GAAG,GAAGpB,MAAM,CAACqB,MAAM,CAAC,iBAAiB,CAAC,CAACA,MAAM,CAACjB,UAAU,CAACI,QAAQ,CAAC,CAAC;EAEzE,MAA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C,CAACS,KAAK,CAAEL,IAAI,IAAKI,IAAI,CAACE,GAAG,CAACN,IAAI,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { invariant } from 'ts-invariant';
|
|
2
|
+
import { BaseEntrypoint } from './BaseEntrypoint';
|
|
3
|
+
import { isSuperSet, mergeOnly } from './Entrypoint.helpers';
|
|
4
|
+
import { EvaluatedEntrypoint } from './EvaluatedEntrypoint';
|
|
5
|
+
import { AbortError } from './actions/AbortError';
|
|
6
|
+
import { BaseAction } from './actions/BaseAction';
|
|
7
|
+
import { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';
|
|
8
|
+
const EMPTY_FILE = '=== empty file ===';
|
|
9
|
+
function hasLoop(name, parent, processed = []) {
|
|
10
|
+
if (parent.name === name || processed.includes(parent.name)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
for (const p of parent.parents) {
|
|
14
|
+
const found = hasLoop(name, p, [...processed, parent.name]);
|
|
15
|
+
if (found) {
|
|
16
|
+
return found;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
export class Entrypoint extends BaseEntrypoint {
|
|
22
|
+
evaluated = false;
|
|
23
|
+
onSupersedeHandlers = [];
|
|
24
|
+
actionsCache = new Map();
|
|
25
|
+
#hasLinariaMetadata = false;
|
|
26
|
+
#supersededWith = null;
|
|
27
|
+
#transformResultCode = null;
|
|
28
|
+
constructor(services, parents, initialCode, name, only, exports, evaluatedOnly, loadedAndParsed, resolveTasks = new Map(), dependencies = new Map(), generation = 1) {
|
|
29
|
+
super(services, evaluatedOnly, exports, generation, name, only, parents);
|
|
30
|
+
this.initialCode = initialCode;
|
|
31
|
+
this.resolveTasks = resolveTasks;
|
|
32
|
+
this.dependencies = dependencies;
|
|
33
|
+
this.loadedAndParsed = loadedAndParsed ?? services.loadAndParseFn(services, name, initialCode, parents[0]?.log ?? services.log);
|
|
34
|
+
if (this.loadedAndParsed.code !== undefined) {
|
|
35
|
+
services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);
|
|
36
|
+
}
|
|
37
|
+
this.log.extend('source')('created %s (%o)\n%s', name, only, this.originalCode || EMPTY_FILE);
|
|
38
|
+
}
|
|
39
|
+
get ignored() {
|
|
40
|
+
return this.loadedAndParsed.evaluator === 'ignored';
|
|
41
|
+
}
|
|
42
|
+
get originalCode() {
|
|
43
|
+
return this.loadedAndParsed.code;
|
|
44
|
+
}
|
|
45
|
+
get supersededWith() {
|
|
46
|
+
return this.#supersededWith?.supersededWith ?? this.#supersededWith;
|
|
47
|
+
}
|
|
48
|
+
get transformedCode() {
|
|
49
|
+
return this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null;
|
|
50
|
+
}
|
|
51
|
+
static createRoot(services, name, only, loadedCode) {
|
|
52
|
+
const created = Entrypoint.create(services, null, name, only, loadedCode);
|
|
53
|
+
invariant(created !== 'loop', 'loop detected');
|
|
54
|
+
return created;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates an entrypoint for the specified file.
|
|
59
|
+
* If there is already an entrypoint for this file, there will be four possible outcomes:
|
|
60
|
+
* 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,
|
|
61
|
+
* the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.
|
|
62
|
+
* It can happen if the file was changed and the watcher notified us about it, or we received a new version
|
|
63
|
+
* of the file from a loader whereas the previous one was loaded from the filesystem.
|
|
64
|
+
* The new entrypoint will be returned.
|
|
65
|
+
* 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.
|
|
66
|
+
* 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.
|
|
67
|
+
* 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.
|
|
68
|
+
*/
|
|
69
|
+
static create(services, parent, name, only, loadedCode) {
|
|
70
|
+
const {
|
|
71
|
+
cache,
|
|
72
|
+
eventEmitter
|
|
73
|
+
} = services;
|
|
74
|
+
return eventEmitter.perf('createEntrypoint', () => {
|
|
75
|
+
const [status, entrypoint] = Entrypoint.innerCreate(services, parent ? {
|
|
76
|
+
evaluated: parent.evaluated,
|
|
77
|
+
log: parent.log,
|
|
78
|
+
name: parent.name,
|
|
79
|
+
parents: parent.parents,
|
|
80
|
+
seqId: parent.seqId
|
|
81
|
+
} : null, name, only, loadedCode);
|
|
82
|
+
if (status !== 'cached') {
|
|
83
|
+
cache.add('entrypoints', name, entrypoint);
|
|
84
|
+
}
|
|
85
|
+
return status === 'loop' ? 'loop' : entrypoint;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static innerCreate(services, parent, name, only, loadedCode) {
|
|
89
|
+
const {
|
|
90
|
+
cache
|
|
91
|
+
} = services;
|
|
92
|
+
const cached = cache.get('entrypoints', name);
|
|
93
|
+
const changed = loadedCode !== undefined ? cache.invalidateIfChanged(name, loadedCode) : false;
|
|
94
|
+
if (!cached?.evaluated && cached?.ignored) {
|
|
95
|
+
return ['cached', cached];
|
|
96
|
+
}
|
|
97
|
+
const exports = cached?.exports;
|
|
98
|
+
const evaluatedOnly = cached?.evaluatedOnly ?? [];
|
|
99
|
+
const mergedOnly = !changed && cached?.only ? mergeOnly(cached.only, only).filter(i => !evaluatedOnly.includes(i)) : only;
|
|
100
|
+
if (cached?.evaluated) {
|
|
101
|
+
cached.log('is already evaluated with', cached.evaluatedOnly);
|
|
102
|
+
}
|
|
103
|
+
if (!changed && cached && !cached.evaluated) {
|
|
104
|
+
const isLoop = parent && hasLoop(name, parent);
|
|
105
|
+
if (isLoop) {
|
|
106
|
+
parent.log('[createEntrypoint] %s is a loop', name);
|
|
107
|
+
}
|
|
108
|
+
if (parent && !cached.parents.map(p => p.name).includes(parent.name)) {
|
|
109
|
+
cached.parents.push(parent);
|
|
110
|
+
}
|
|
111
|
+
if (isSuperSet(cached.only, mergedOnly)) {
|
|
112
|
+
cached.log('is cached', name);
|
|
113
|
+
return [isLoop ? 'loop' : 'cached', cached];
|
|
114
|
+
}
|
|
115
|
+
cached.log('is cached, but with different `only` %o (the cached one %o)', only, cached?.only);
|
|
116
|
+
return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];
|
|
117
|
+
}
|
|
118
|
+
const newEntrypoint = new Entrypoint(services, parent ? [parent] : [], loadedCode, name, mergedOnly, exports, evaluatedOnly, undefined, cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined, cached && 'dependencies' in cached ? cached.dependencies : undefined, cached ? cached.generation + 1 : 1);
|
|
119
|
+
if (cached && !cached.evaluated) {
|
|
120
|
+
cached.log('is cached, but with different code');
|
|
121
|
+
cached.supersede(newEntrypoint);
|
|
122
|
+
}
|
|
123
|
+
return ['created', newEntrypoint];
|
|
124
|
+
}
|
|
125
|
+
addDependency(dependency) {
|
|
126
|
+
this.resolveTasks.delete(dependency.source);
|
|
127
|
+
this.dependencies.set(dependency.source, dependency);
|
|
128
|
+
}
|
|
129
|
+
addResolveTask(name, dependency) {
|
|
130
|
+
this.resolveTasks.set(name, dependency);
|
|
131
|
+
}
|
|
132
|
+
assertNotSuperseded() {
|
|
133
|
+
if (this.supersededWith) {
|
|
134
|
+
this.log('superseded');
|
|
135
|
+
throw new AbortError('superseded');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
assertTransformed() {
|
|
139
|
+
if (this.transformedCode === null) {
|
|
140
|
+
this.log('not transformed');
|
|
141
|
+
throw new UnprocessedEntrypointError(this.supersededWith ?? this);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
createAction(actionType, data, abortSignal = null) {
|
|
145
|
+
if (!this.actionsCache.has(actionType)) {
|
|
146
|
+
this.actionsCache.set(actionType, new Map());
|
|
147
|
+
}
|
|
148
|
+
const cache = this.actionsCache.get(actionType);
|
|
149
|
+
const cached = cache.get(data);
|
|
150
|
+
if (cached && !cached.abortSignal?.aborted) {
|
|
151
|
+
return cached;
|
|
152
|
+
}
|
|
153
|
+
const newAction = new BaseAction(actionType, this.services, this, data, abortSignal);
|
|
154
|
+
cache.set(data, newAction);
|
|
155
|
+
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
156
|
+
type: 'actionCreated',
|
|
157
|
+
actionType,
|
|
158
|
+
actionIdx: newAction.idx
|
|
159
|
+
});
|
|
160
|
+
return newAction;
|
|
161
|
+
}
|
|
162
|
+
createChild(name, only, loadedCode) {
|
|
163
|
+
return Entrypoint.create(this.services, this, name, only, loadedCode);
|
|
164
|
+
}
|
|
165
|
+
createEvaluated() {
|
|
166
|
+
const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);
|
|
167
|
+
this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);
|
|
168
|
+
return new EvaluatedEntrypoint(this.services, evaluatedOnly, this.exportsProxy, this.generation + 1, this.name, this.only, this.parents);
|
|
169
|
+
}
|
|
170
|
+
getDependency(name) {
|
|
171
|
+
return this.dependencies.get(name);
|
|
172
|
+
}
|
|
173
|
+
getResolveTask(name) {
|
|
174
|
+
return this.resolveTasks.get(name);
|
|
175
|
+
}
|
|
176
|
+
hasLinariaMetadata() {
|
|
177
|
+
return this.#hasLinariaMetadata;
|
|
178
|
+
}
|
|
179
|
+
onSupersede(callback) {
|
|
180
|
+
if (this.#supersededWith) {
|
|
181
|
+
callback(this.#supersededWith);
|
|
182
|
+
return () => {};
|
|
183
|
+
}
|
|
184
|
+
this.onSupersedeHandlers.push(callback);
|
|
185
|
+
return () => {
|
|
186
|
+
const index = this.onSupersedeHandlers.indexOf(callback);
|
|
187
|
+
if (index >= 0) {
|
|
188
|
+
this.onSupersedeHandlers.splice(index, 1);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
setTransformResult(res) {
|
|
193
|
+
this.#hasLinariaMetadata = Boolean(res?.metadata);
|
|
194
|
+
this.#transformResultCode = res?.code ?? null;
|
|
195
|
+
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
196
|
+
isNull: res === null,
|
|
197
|
+
type: 'setTransformResult'
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
supersede(newOnlyOrEntrypoint) {
|
|
201
|
+
const newEntrypoint = newOnlyOrEntrypoint instanceof Entrypoint ? newOnlyOrEntrypoint : new Entrypoint(this.services, this.parents, this.initialCode, this.name, newOnlyOrEntrypoint, this.exports, this.evaluatedOnly, this.loadedAndParsed, this.resolveTasks, this.dependencies, this.generation + 1);
|
|
202
|
+
this.services.eventEmitter.entrypointEvent(this.seqId, {
|
|
203
|
+
type: 'superseded',
|
|
204
|
+
with: newEntrypoint.seqId
|
|
205
|
+
});
|
|
206
|
+
this.log('superseded by %s (%o -> %o)', newEntrypoint.name, this.only, newEntrypoint.only);
|
|
207
|
+
this.#supersededWith = newEntrypoint;
|
|
208
|
+
this.onSupersedeHandlers.forEach(handler => handler(newEntrypoint));
|
|
209
|
+
return newEntrypoint;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=Entrypoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Entrypoint.js","names":["invariant","BaseEntrypoint","isSuperSet","mergeOnly","EvaluatedEntrypoint","AbortError","BaseAction","UnprocessedEntrypointError","EMPTY_FILE","hasLoop","name","parent","processed","includes","p","parents","found","Entrypoint","evaluated","onSupersedeHandlers","actionsCache","Map","hasLinariaMetadata","supersededWith","transformResultCode","constructor","services","initialCode","only","exports","evaluatedOnly","loadedAndParsed","resolveTasks","dependencies","generation","loadAndParseFn","log","code","undefined","cache","invalidateIfChanged","extend","originalCode","ignored","evaluator","transformedCode","createRoot","loadedCode","created","create","eventEmitter","perf","status","entrypoint","innerCreate","seqId","add","cached","get","changed","mergedOnly","filter","i","isLoop","map","push","supersede","newEntrypoint","addDependency","dependency","delete","source","set","addResolveTask","assertNotSuperseded","assertTransformed","createAction","actionType","data","abortSignal","has","aborted","newAction","entrypointEvent","type","actionIdx","idx","createChild","createEvaluated","exportsProxy","getDependency","getResolveTask","onSupersede","callback","index","indexOf","splice","setTransformResult","res","Boolean","metadata","isNull","newOnlyOrEntrypoint","with","forEach","handler"],"sources":["../../src/transform/Entrypoint.ts"],"sourcesContent":["import { invariant } from 'ts-invariant';\n\nimport type { ParentEntrypoint, ITransformFileResult } from '../types';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\nimport { isSuperSet, mergeOnly } from './Entrypoint.helpers';\nimport type {\n IEntrypointCode,\n IEntrypointDependency,\n IIgnoredEntrypoint,\n} from './Entrypoint.types';\nimport { EvaluatedEntrypoint } from './EvaluatedEntrypoint';\nimport { AbortError } from './actions/AbortError';\nimport type { ActionByType } from './actions/BaseAction';\nimport { BaseAction } from './actions/BaseAction';\nimport { UnprocessedEntrypointError } from './actions/UnprocessedEntrypointError';\nimport type { Services, ActionTypes, ActionQueueItem } from './types';\n\nconst EMPTY_FILE = '=== empty file ===';\n\nfunction hasLoop(\n name: string,\n parent: ParentEntrypoint,\n processed: string[] = []\n): boolean {\n if (parent.name === name || processed.includes(parent.name)) {\n return true;\n }\n\n for (const p of parent.parents) {\n const found = hasLoop(name, p, [...processed, parent.name]);\n if (found) {\n return found;\n }\n }\n\n return false;\n}\n\nexport class Entrypoint extends BaseEntrypoint {\n public readonly evaluated = false;\n\n public readonly loadedAndParsed: IEntrypointCode | IIgnoredEntrypoint;\n\n protected onSupersedeHandlers: Array<(newEntrypoint: Entrypoint) => void> =\n [];\n\n private actionsCache: Map<\n ActionTypes,\n Map<unknown, BaseAction<ActionQueueItem>>\n > = new Map();\n\n #hasLinariaMetadata: boolean = false;\n\n #supersededWith: Entrypoint | null = null;\n\n #transformResultCode: string | null = null;\n\n private constructor(\n services: Services,\n parents: ParentEntrypoint[],\n public readonly initialCode: string | undefined,\n name: string,\n only: string[],\n exports: Record<string | symbol, unknown> | undefined,\n evaluatedOnly: string[],\n loadedAndParsed?: IEntrypointCode | IIgnoredEntrypoint,\n protected readonly resolveTasks = new Map<\n string,\n Promise<IEntrypointDependency>\n >(),\n protected readonly dependencies = new Map<string, IEntrypointDependency>(),\n generation = 1\n ) {\n super(services, evaluatedOnly, exports, generation, name, only, parents);\n\n this.loadedAndParsed =\n loadedAndParsed ??\n services.loadAndParseFn(\n services,\n name,\n initialCode,\n parents[0]?.log ?? services.log\n );\n\n if (this.loadedAndParsed.code !== undefined) {\n services.cache.invalidateIfChanged(name, this.loadedAndParsed.code);\n }\n\n this.log.extend('source')(\n 'created %s (%o)\\n%s',\n name,\n only,\n this.originalCode || EMPTY_FILE\n );\n }\n\n public get ignored() {\n return this.loadedAndParsed.evaluator === 'ignored';\n }\n\n public get originalCode() {\n return this.loadedAndParsed.code;\n }\n\n public get supersededWith(): Entrypoint | null {\n return this.#supersededWith?.supersededWith ?? this.#supersededWith;\n }\n\n public get transformedCode(): string | null {\n return (\n this.#transformResultCode ?? this.supersededWith?.transformedCode ?? null\n );\n }\n\n public static createRoot(\n services: Services,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint {\n const created = Entrypoint.create(services, null, name, only, loadedCode);\n invariant(created !== 'loop', 'loop detected');\n\n return created;\n }\n\n /**\n * Creates an entrypoint for the specified file.\n * If there is already an entrypoint for this file, there will be four possible outcomes:\n * 1. If `loadedCode` is specified and is different from the one that was used to create the existing entrypoint,\n * the existing entrypoint will be superseded by a new one and all cached results for it will be invalidated.\n * It can happen if the file was changed and the watcher notified us about it, or we received a new version\n * of the file from a loader whereas the previous one was loaded from the filesystem.\n * The new entrypoint will be returned.\n * 2. If `only` is subset of the existing entrypoint's `only`, the existing entrypoint will be returned.\n * 3. If `only` is superset of the existing entrypoint's `only`, the existing entrypoint will be superseded and the new one will be returned.\n * 4. If a loop is detected, 'ignored' will be returned, the existing entrypoint will be superseded or not depending on the `only` value.\n */\n protected static create(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): Entrypoint | 'loop' {\n const { cache, eventEmitter } = services;\n return eventEmitter.perf('createEntrypoint', () => {\n const [status, entrypoint] = Entrypoint.innerCreate(\n services,\n parent\n ? {\n evaluated: parent.evaluated,\n log: parent.log,\n name: parent.name,\n parents: parent.parents,\n seqId: parent.seqId,\n }\n : null,\n name,\n only,\n loadedCode\n );\n\n if (status !== 'cached') {\n cache.add('entrypoints', name, entrypoint);\n }\n\n return status === 'loop' ? 'loop' : entrypoint;\n });\n }\n\n private static innerCreate(\n services: Services,\n parent: ParentEntrypoint | null,\n name: string,\n only: string[],\n loadedCode: string | undefined\n ): ['loop' | 'created' | 'cached', Entrypoint] {\n const { cache } = services;\n\n const cached = cache.get('entrypoints', name);\n const changed =\n loadedCode !== undefined\n ? cache.invalidateIfChanged(name, loadedCode)\n : false;\n\n if (!cached?.evaluated && cached?.ignored) {\n return ['cached', cached];\n }\n\n const exports = cached?.exports;\n const evaluatedOnly = cached?.evaluatedOnly ?? [];\n const mergedOnly =\n !changed && cached?.only\n ? mergeOnly(cached.only, only).filter((i) => !evaluatedOnly.includes(i))\n : only;\n\n if (cached?.evaluated) {\n cached.log('is already evaluated with', cached.evaluatedOnly);\n }\n\n if (!changed && cached && !cached.evaluated) {\n const isLoop = parent && hasLoop(name, parent);\n if (isLoop) {\n parent.log('[createEntrypoint] %s is a loop', name);\n }\n\n if (parent && !cached.parents.map((p) => p.name).includes(parent.name)) {\n cached.parents.push(parent);\n }\n\n if (isSuperSet(cached.only, mergedOnly)) {\n cached.log('is cached', name);\n return [isLoop ? 'loop' : 'cached', cached];\n }\n\n cached.log(\n 'is cached, but with different `only` %o (the cached one %o)',\n only,\n cached?.only\n );\n\n return [isLoop ? 'loop' : 'created', cached.supersede(mergedOnly)];\n }\n\n const newEntrypoint = new Entrypoint(\n services,\n parent ? [parent] : [],\n loadedCode,\n name,\n mergedOnly,\n exports,\n evaluatedOnly,\n undefined,\n cached && 'resolveTasks' in cached ? cached.resolveTasks : undefined,\n cached && 'dependencies' in cached ? cached.dependencies : undefined,\n cached ? cached.generation + 1 : 1\n );\n\n if (cached && !cached.evaluated) {\n cached.log('is cached, but with different code');\n cached.supersede(newEntrypoint);\n }\n\n return ['created', newEntrypoint];\n }\n\n public addDependency(dependency: IEntrypointDependency): void {\n this.resolveTasks.delete(dependency.source);\n this.dependencies.set(dependency.source, dependency);\n }\n\n public addResolveTask(\n name: string,\n dependency: Promise<IEntrypointDependency>\n ): void {\n this.resolveTasks.set(name, dependency);\n }\n\n public assertNotSuperseded() {\n if (this.supersededWith) {\n this.log('superseded');\n throw new AbortError('superseded');\n }\n }\n\n public assertTransformed() {\n if (this.transformedCode === null) {\n this.log('not transformed');\n throw new UnprocessedEntrypointError(this.supersededWith ?? this);\n }\n }\n\n public createAction<\n TType extends ActionTypes,\n TAction extends ActionByType<TType>,\n >(\n actionType: TType,\n data: TAction['data'],\n abortSignal: AbortSignal | null = null\n ): BaseAction<TAction> {\n if (!this.actionsCache.has(actionType)) {\n this.actionsCache.set(actionType, new Map());\n }\n\n const cache = this.actionsCache.get(actionType)!;\n const cached = cache.get(data);\n if (cached && !cached.abortSignal?.aborted) {\n return cached as BaseAction<TAction>;\n }\n\n const newAction = new BaseAction<TAction>(\n actionType as TAction['type'],\n this.services,\n this,\n data,\n abortSignal\n );\n\n cache.set(data, newAction);\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'actionCreated',\n actionType,\n actionIdx: newAction.idx,\n });\n\n return newAction;\n }\n\n public createChild(\n name: string,\n only: string[],\n loadedCode?: string\n ): Entrypoint | 'loop' {\n return Entrypoint.create(this.services, this, name, only, loadedCode);\n }\n\n public createEvaluated() {\n const evaluatedOnly = mergeOnly(this.evaluatedOnly, this.only);\n this.log('create EvaluatedEntrypoint for %o', evaluatedOnly);\n\n return new EvaluatedEntrypoint(\n this.services,\n evaluatedOnly,\n this.exportsProxy,\n this.generation + 1,\n this.name,\n this.only,\n this.parents\n );\n }\n\n public getDependency(name: string): IEntrypointDependency | undefined {\n return this.dependencies.get(name);\n }\n\n public getResolveTask(\n name: string\n ): Promise<IEntrypointDependency> | undefined {\n return this.resolveTasks.get(name);\n }\n\n public hasLinariaMetadata() {\n return this.#hasLinariaMetadata;\n }\n\n public onSupersede(callback: (newEntrypoint: Entrypoint) => void) {\n if (this.#supersededWith) {\n callback(this.#supersededWith);\n return () => {};\n }\n\n this.onSupersedeHandlers.push(callback);\n\n return () => {\n const index = this.onSupersedeHandlers.indexOf(callback);\n if (index >= 0) {\n this.onSupersedeHandlers.splice(index, 1);\n }\n };\n }\n\n public setTransformResult(res: ITransformFileResult | null) {\n this.#hasLinariaMetadata = Boolean(res?.metadata);\n this.#transformResultCode = res?.code ?? null;\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n isNull: res === null,\n type: 'setTransformResult',\n });\n }\n\n private supersede(newOnlyOrEntrypoint: string[] | Entrypoint): Entrypoint {\n const newEntrypoint =\n newOnlyOrEntrypoint instanceof Entrypoint\n ? newOnlyOrEntrypoint\n : new Entrypoint(\n this.services,\n this.parents,\n this.initialCode,\n this.name,\n newOnlyOrEntrypoint,\n this.exports,\n this.evaluatedOnly,\n this.loadedAndParsed,\n this.resolveTasks,\n this.dependencies,\n this.generation + 1\n );\n\n this.services.eventEmitter.entrypointEvent(this.seqId, {\n type: 'superseded',\n with: newEntrypoint.seqId,\n });\n this.log(\n 'superseded by %s (%o -> %o)',\n newEntrypoint.name,\n this.only,\n newEntrypoint.only\n );\n this.#supersededWith = newEntrypoint;\n this.onSupersedeHandlers.forEach((handler) => handler(newEntrypoint));\n\n return newEntrypoint;\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,cAAc;AAIxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SAASC,UAAU,EAAEC,SAAS,QAAQ,sBAAsB;AAM5D,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,UAAU,QAAQ,sBAAsB;AAEjD,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,0BAA0B,QAAQ,sCAAsC;AAGjF,MAA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
|
+
{"version":3,"file":"Entrypoint.types.js","names":[],"sources":["../../src/transform/Entrypoint.types.ts"],"sourcesContent":["import type { TransformOptions } from '@babel/core';\nimport type { File } from '@babel/types';\n\nimport type { Debugger, Evaluator } from '@wyw-in-js/shared';\n\nimport type { Services } from './types';\n\nexport interface IEntrypointCode {\n readonly ast: File;\n code: string;\n evalConfig: TransformOptions;\n evaluator: Evaluator;\n}\n\nexport interface IIgnoredEntrypoint {\n readonly ast?: File;\n readonly code?: string;\n evaluator: 'ignored';\n reason: 'extension' | 'rule';\n}\n\nexport interface IEntrypointDependency {\n only: string[];\n resolved: string | null;\n source: string;\n}\n\nexport type LoadAndParseFn = (\n services: Services,\n name: string,\n loadedCode: string | undefined,\n log: Debugger\n) => IEntrypointCode | IIgnoredEntrypoint;\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EvaluatedEntrypoint.js","names":["BaseEntrypoint","EvaluatedEntrypoint","evaluated","ignored"],"sources":["../../src/transform/EvaluatedEntrypoint.ts"],"sourcesContent":["import type { Debugger } from '@wyw-in-js/shared';\n\nimport { BaseEntrypoint } from './BaseEntrypoint';\n\nexport interface IEvaluatedEntrypoint {\n evaluated: true;\n evaluatedOnly: string[];\n exports: Record<string | symbol, unknown>;\n generation: number;\n ignored: false;\n log: Debugger;\n only: string[];\n}\n\nexport class EvaluatedEntrypoint\n extends BaseEntrypoint\n implements IEvaluatedEntrypoint\n{\n public readonly evaluated = true;\n\n public readonly ignored = false;\n}\n"],"mappings":"AAEA,SAASA,cAAc,QAAQ,kBAAkB;AAYjD,OAAO,MAAMC,mBAAmB,SACtBD,cAAc,CAExB;EACkBE,SAAS,GAAG,IAAI;EAEhBC,OAAO,GAAG,KAAK;AACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbortError.js","names":["AbortError","Error","constructor","reason","name","isAborted","value"],"sources":["../../../src/transform/actions/AbortError.ts"],"sourcesContent":["export class AbortError extends Error {\n constructor(reason?: string) {\n super(reason);\n this.name = 'AbortError';\n }\n}\n\nexport const isAborted = (value: unknown): value is AbortError =>\n value instanceof AbortError;\n"],"mappings":"AAAA,OAAO,MAAMA,UAAU,SAASC,KAAK,CAAC;EACpCC,WAAWA,CAACC,MAAe,EAAE;IAC3B,KAAK,CAACA,MAAM,CAAC;IACb,IAAI,CAACC,IAAI,GAAG,YAAY;EAC1B;AACF;AAEA,OAAO,MAAMC,SAAS,GAAIC,KAAc,IACtCA,KAAK,YAAYN,UAAU"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* eslint-disable no-plusplus */
|
|
2
|
+
import '../../utils/dispose-polyfill';
|
|
3
|
+
import { Pending } from '../types';
|
|
4
|
+
let actionIdx = 0;
|
|
5
|
+
export class BaseAction {
|
|
6
|
+
result = Pending;
|
|
7
|
+
activeScenario = null;
|
|
8
|
+
activeScenarioNextResults = [];
|
|
9
|
+
constructor(type, services, entrypoint, data, abortSignal) {
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.services = services;
|
|
12
|
+
this.entrypoint = entrypoint;
|
|
13
|
+
this.data = data;
|
|
14
|
+
this.abortSignal = abortSignal;
|
|
15
|
+
actionIdx += 1;
|
|
16
|
+
this.idx = actionIdx.toString(16).padStart(6, '0');
|
|
17
|
+
}
|
|
18
|
+
get log() {
|
|
19
|
+
return this.entrypoint.log.extend(this.ref);
|
|
20
|
+
}
|
|
21
|
+
get ref() {
|
|
22
|
+
return `${this.type}@${this.idx}`;
|
|
23
|
+
}
|
|
24
|
+
createAbortSignal() {
|
|
25
|
+
const abortController = new AbortController();
|
|
26
|
+
const unsubscribeFromParentAbort = this.onAbort(() => {
|
|
27
|
+
this.entrypoint.log('parent aborted');
|
|
28
|
+
abortController.abort();
|
|
29
|
+
});
|
|
30
|
+
const unsubscribeFromSupersede = this.entrypoint.onSupersede(() => {
|
|
31
|
+
this.entrypoint.log('entrypoint superseded, aborting processing');
|
|
32
|
+
abortController.abort();
|
|
33
|
+
});
|
|
34
|
+
const abortSignal = abortController.signal;
|
|
35
|
+
abortSignal[Symbol.dispose] = () => {
|
|
36
|
+
unsubscribeFromParentAbort();
|
|
37
|
+
unsubscribeFromSupersede();
|
|
38
|
+
};
|
|
39
|
+
return abortSignal;
|
|
40
|
+
}
|
|
41
|
+
*getNext(type, entrypoint, data, abortSignal = this.abortSignal) {
|
|
42
|
+
return yield [type, entrypoint, data, abortSignal];
|
|
43
|
+
}
|
|
44
|
+
onAbort(fn) {
|
|
45
|
+
this.abortSignal?.addEventListener('abort', fn);
|
|
46
|
+
return () => {
|
|
47
|
+
this.abortSignal?.removeEventListener('abort', fn);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
run(handler) {
|
|
51
|
+
if (!this.activeScenario) {
|
|
52
|
+
this.activeScenario = handler.call(this);
|
|
53
|
+
this.activeScenarioNextResults = [];
|
|
54
|
+
}
|
|
55
|
+
let nextIdx = 0;
|
|
56
|
+
const throwFn = e => this.emitAction(nextIdx, () => this.activeScenario.throw(e));
|
|
57
|
+
const nextFn = arg => this.emitAction(nextIdx, () => this.activeScenario.next(arg));
|
|
58
|
+
const processNextResult = (result, onError) => {
|
|
59
|
+
if ('then' in result) {
|
|
60
|
+
result.then(r => {
|
|
61
|
+
if (r.done) {
|
|
62
|
+
this.result = r.value;
|
|
63
|
+
}
|
|
64
|
+
}, onError);
|
|
65
|
+
} else if (result.done) {
|
|
66
|
+
this.result = result.value;
|
|
67
|
+
}
|
|
68
|
+
this.activeScenarioNextResults.push(result);
|
|
69
|
+
};
|
|
70
|
+
const processError = e => {
|
|
71
|
+
if (this.activeScenarioNextResults.length > nextIdx) {
|
|
72
|
+
this.log('error was already handled in another branch, result idx is %d', nextIdx);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.log('error processing, result idx is %d', nextIdx);
|
|
76
|
+
try {
|
|
77
|
+
const nextResult = throwFn(e);
|
|
78
|
+
processNextResult(nextResult, processError);
|
|
79
|
+
} catch (errorInGenerator) {
|
|
80
|
+
const {
|
|
81
|
+
recover
|
|
82
|
+
} = handler;
|
|
83
|
+
if (recover) {
|
|
84
|
+
const nextResult = {
|
|
85
|
+
done: false,
|
|
86
|
+
value: recover(errorInGenerator, this)
|
|
87
|
+
};
|
|
88
|
+
processNextResult(nextResult, processError);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.activeScenarioError = errorInGenerator;
|
|
92
|
+
throw errorInGenerator;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const processNext = arg => {
|
|
96
|
+
if (this.activeScenarioNextResults.length > nextIdx) {
|
|
97
|
+
this.log('next was already handled in another branch, result idx is %d', nextIdx);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.log('next processing, result idx is %d', nextIdx);
|
|
101
|
+
try {
|
|
102
|
+
const nextResult = nextFn(arg);
|
|
103
|
+
processNextResult(nextResult, processError);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
processError(e);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return {
|
|
109
|
+
next: arg => {
|
|
110
|
+
this.rethrowActiveScenarioError();
|
|
111
|
+
processNext(arg);
|
|
112
|
+
return this.activeScenarioNextResults[nextIdx++];
|
|
113
|
+
},
|
|
114
|
+
throw: e => {
|
|
115
|
+
this.rethrowActiveScenarioError();
|
|
116
|
+
processError(e);
|
|
117
|
+
return this.activeScenarioNextResults[nextIdx++];
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
emitAction(yieldIdx, fn) {
|
|
122
|
+
return this.services.eventEmitter.action(this.type, `${this.idx}:${yieldIdx + 1}`, this.entrypoint.ref, fn);
|
|
123
|
+
}
|
|
124
|
+
rethrowActiveScenarioError() {
|
|
125
|
+
if (!this.activeScenarioError) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.log('scenario has an unhandled error from another branch, rethrow %o', this.activeScenarioError);
|
|
129
|
+
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
131
|
+
throw this.activeScenarioError;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=BaseAction.js.map
|