@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,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file exposes transform function that:
|
|
4
|
+
* - parse the passed code to AST
|
|
5
|
+
* - transforms the AST using Linaria babel preset ('./babel/index.js) and additional config defined in Linaria config file or passed to bundler configuration.
|
|
6
|
+
* - runs generated CSS files through default of user-defined preprocessor
|
|
7
|
+
* - generates source maps for CSS files
|
|
8
|
+
* - return transformed code (without Linaria template literals), generated CSS, source maps and babel metadata from transform step.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.transform = exports.transformSync = void 0;
|
|
12
|
+
const shared_1 = require("@wyw-in-js/shared");
|
|
13
|
+
const cache_1 = require("./cache");
|
|
14
|
+
const Entrypoint_1 = require("./transform/Entrypoint");
|
|
15
|
+
const actionRunner_1 = require("./transform/actions/actionRunner");
|
|
16
|
+
const generators_1 = require("./transform/generators");
|
|
17
|
+
const resolveImports_1 = require("./transform/generators/resolveImports");
|
|
18
|
+
const loadLinariaOptions_1 = require("./transform/helpers/loadLinariaOptions");
|
|
19
|
+
const withDefaultServices_1 = require("./transform/helpers/withDefaultServices");
|
|
20
|
+
function transformSync(partialServices, originalCode, syncResolve, customHandlers = {}) {
|
|
21
|
+
const { options } = partialServices;
|
|
22
|
+
const pluginOptions = (0, loadLinariaOptions_1.loadLinariaOptions)(options.pluginOptions);
|
|
23
|
+
const services = (0, withDefaultServices_1.withDefaultServices)({
|
|
24
|
+
...partialServices,
|
|
25
|
+
options: {
|
|
26
|
+
...options,
|
|
27
|
+
pluginOptions,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (!(0, shared_1.isFeatureEnabled)(pluginOptions.features, 'globalCache', options.filename)) {
|
|
31
|
+
// If global cache is disabled, we need to create a new cache for each file
|
|
32
|
+
services.cache = new cache_1.TransformCacheCollection();
|
|
33
|
+
}
|
|
34
|
+
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['__linariaPreval'], originalCode);
|
|
35
|
+
if (entrypoint.ignored) {
|
|
36
|
+
return {
|
|
37
|
+
code: originalCode,
|
|
38
|
+
sourceMap: options.inputSourceMap,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const workflowAction = entrypoint.createAction('workflow', undefined);
|
|
42
|
+
try {
|
|
43
|
+
const result = (0, actionRunner_1.syncActionRunner)(workflowAction, {
|
|
44
|
+
...generators_1.baseHandlers,
|
|
45
|
+
...customHandlers,
|
|
46
|
+
resolveImports() {
|
|
47
|
+
return resolveImports_1.syncResolveImports.call(this, syncResolve);
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
entrypoint.log('%s is ready', entrypoint.name);
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
entrypoint.log('Unhandled error %O', err);
|
|
55
|
+
if ((0, shared_1.isFeatureEnabled)(pluginOptions.features, 'softErrors', options.filename)) {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.error(`Error during transform of ${entrypoint.name}:`, err);
|
|
58
|
+
return {
|
|
59
|
+
code: originalCode,
|
|
60
|
+
sourceMap: options.inputSourceMap,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.transformSync = transformSync;
|
|
67
|
+
async function transform(partialServices, originalCode, asyncResolve, customHandlers = {}) {
|
|
68
|
+
const { options } = partialServices;
|
|
69
|
+
const pluginOptions = (0, loadLinariaOptions_1.loadLinariaOptions)(options.pluginOptions);
|
|
70
|
+
const services = (0, withDefaultServices_1.withDefaultServices)({
|
|
71
|
+
...partialServices,
|
|
72
|
+
options: {
|
|
73
|
+
...options,
|
|
74
|
+
pluginOptions,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
if (!(0, shared_1.isFeatureEnabled)(pluginOptions.features, 'globalCache', options.filename)) {
|
|
78
|
+
// If global cache is disabled, we need to create a new cache for each file
|
|
79
|
+
services.cache = new cache_1.TransformCacheCollection();
|
|
80
|
+
}
|
|
81
|
+
/*
|
|
82
|
+
* This method can be run simultaneously for multiple files.
|
|
83
|
+
* A shared cache is accessible for all runs, but each run has its own queue
|
|
84
|
+
* to maintain the correct processing order. The cache stores the outcome
|
|
85
|
+
* of tree-shaking, and if the result is already stored in the cache
|
|
86
|
+
* but the "only" option has changed, the file will be re-processed using
|
|
87
|
+
* the combined "only" option.
|
|
88
|
+
*/
|
|
89
|
+
const entrypoint = Entrypoint_1.Entrypoint.createRoot(services, options.filename, ['__linariaPreval'], originalCode);
|
|
90
|
+
if (entrypoint.ignored) {
|
|
91
|
+
return {
|
|
92
|
+
code: originalCode,
|
|
93
|
+
sourceMap: options.inputSourceMap,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const workflowAction = entrypoint.createAction('workflow', undefined);
|
|
97
|
+
try {
|
|
98
|
+
const result = await (0, actionRunner_1.asyncActionRunner)(workflowAction, {
|
|
99
|
+
...generators_1.baseHandlers,
|
|
100
|
+
...customHandlers,
|
|
101
|
+
resolveImports() {
|
|
102
|
+
return resolveImports_1.asyncResolveImports.call(this, asyncResolve);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
entrypoint.log('%s is ready', entrypoint.name);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
entrypoint.log('Unhandled error %O', err);
|
|
110
|
+
if ((0, shared_1.isFeatureEnabled)(pluginOptions.features, 'softErrors', options.filename)) {
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
console.error(`Error during transform of ${entrypoint.name}:`, err);
|
|
113
|
+
return {
|
|
114
|
+
code: originalCode,
|
|
115
|
+
sourceMap: options.inputSourceMap,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
throw err;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.transform = transform;
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/// <reference types="debug" />
|
|
2
|
+
import type { BabelFile, PluginPass } from '@babel/core';
|
|
3
|
+
import type { NodePath } from '@babel/traverse';
|
|
4
|
+
import type { File, Program } from '@babel/types';
|
|
5
|
+
import type { RawSourceMap } from 'source-map';
|
|
6
|
+
import type { BaseProcessor } from '@wyw-in-js/processor-utils';
|
|
7
|
+
import type { Debugger, Replacement, Rules, StrictOptions } from '@wyw-in-js/shared';
|
|
8
|
+
import type { WYWTransformMetadata } from './utils/TransformMetadata';
|
|
9
|
+
export type PluginOptions = StrictOptions & {
|
|
10
|
+
configFile?: string | false;
|
|
11
|
+
stage?: Stage;
|
|
12
|
+
};
|
|
13
|
+
export type ParentEntrypoint = {
|
|
14
|
+
evaluated: boolean;
|
|
15
|
+
log: Debugger;
|
|
16
|
+
name: string;
|
|
17
|
+
parents: ParentEntrypoint[];
|
|
18
|
+
seqId: number;
|
|
19
|
+
};
|
|
20
|
+
export type Dependencies = string[];
|
|
21
|
+
export interface IPluginState extends PluginPass {
|
|
22
|
+
dependencies: Dependencies;
|
|
23
|
+
file: BabelFile & {
|
|
24
|
+
metadata: {
|
|
25
|
+
linaria?: WYWTransformMetadata;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
processors: BaseProcessor[];
|
|
29
|
+
}
|
|
30
|
+
export interface ITransformFileResult {
|
|
31
|
+
code: string;
|
|
32
|
+
metadata: WYWTransformMetadata | null;
|
|
33
|
+
}
|
|
34
|
+
export type Stage = 'preeval' | 'collect';
|
|
35
|
+
export type Result = {
|
|
36
|
+
code: string;
|
|
37
|
+
cssSourceMapText?: string;
|
|
38
|
+
cssText?: string;
|
|
39
|
+
dependencies?: string[];
|
|
40
|
+
replacements?: Replacement[];
|
|
41
|
+
rules?: Rules;
|
|
42
|
+
sourceMap?: RawSourceMap | null;
|
|
43
|
+
};
|
|
44
|
+
export type Options = {
|
|
45
|
+
filename: string;
|
|
46
|
+
inputSourceMap?: RawSourceMap;
|
|
47
|
+
outputFilename?: string;
|
|
48
|
+
pluginOptions?: Partial<PluginOptions>;
|
|
49
|
+
preprocessor?: Preprocessor;
|
|
50
|
+
root?: string;
|
|
51
|
+
};
|
|
52
|
+
export type PreprocessorFn = (selector: string, cssText: string) => string;
|
|
53
|
+
export type Preprocessor = 'none' | 'stylis' | PreprocessorFn | void;
|
|
54
|
+
export type MissedBabelCoreTypes = {
|
|
55
|
+
File: new (options: {
|
|
56
|
+
filename: string;
|
|
57
|
+
}, file: {
|
|
58
|
+
ast: File;
|
|
59
|
+
code: string;
|
|
60
|
+
}) => {
|
|
61
|
+
path: NodePath<Program>;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type JSONValue = null | string | number | boolean | JSONObject | JSONArray;
|
|
65
|
+
export interface JSONObject {
|
|
66
|
+
[x: string]: JSONValue;
|
|
67
|
+
}
|
|
68
|
+
export type JSONArray = Array<JSONValue>;
|
|
69
|
+
export type Serializable = JSONValue;
|
|
70
|
+
/**
|
|
71
|
+
* CSS-related types
|
|
72
|
+
*/
|
package/types/types.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type OnEvent = (labels: Record<string, unknown>, type: 'start' | 'finish' | 'single', event?: unknown) => void;
|
|
2
|
+
export interface IActionCreated {
|
|
3
|
+
actionIdx: string;
|
|
4
|
+
actionType: string;
|
|
5
|
+
type: 'actionCreated';
|
|
6
|
+
}
|
|
7
|
+
export interface ICreatedEvent {
|
|
8
|
+
class: string;
|
|
9
|
+
evaluatedOnly: string[];
|
|
10
|
+
filename: string;
|
|
11
|
+
generation: number;
|
|
12
|
+
idx: string;
|
|
13
|
+
isExportsInherited: boolean;
|
|
14
|
+
only: string[];
|
|
15
|
+
parentId: number | null;
|
|
16
|
+
type: 'created';
|
|
17
|
+
}
|
|
18
|
+
export interface ISupersededEvent {
|
|
19
|
+
type: 'superseded';
|
|
20
|
+
with: number;
|
|
21
|
+
}
|
|
22
|
+
export interface ISetTransformResultEvent {
|
|
23
|
+
isNull: boolean;
|
|
24
|
+
type: 'setTransformResult';
|
|
25
|
+
}
|
|
26
|
+
export type EntrypointEvent = IActionCreated | ICreatedEvent | ISupersededEvent | ISetTransformResultEvent;
|
|
27
|
+
export type OnEntrypointEvent = (idx: number, timestamp: number, event: EntrypointEvent) => void;
|
|
28
|
+
export type OnActionStartArgs = [
|
|
29
|
+
phase: 'start',
|
|
30
|
+
timestamp: number,
|
|
31
|
+
type: string,
|
|
32
|
+
idx: string,
|
|
33
|
+
entrypointRef: string
|
|
34
|
+
];
|
|
35
|
+
export type OnActionFinishArgs = [
|
|
36
|
+
phase: 'finish' | 'fail',
|
|
37
|
+
timestamp: number,
|
|
38
|
+
id: number,
|
|
39
|
+
isAsync: boolean,
|
|
40
|
+
error?: unknown
|
|
41
|
+
];
|
|
42
|
+
export declare const isOnActionStartArgs: (args: OnActionStartArgs | OnActionFinishArgs) => args is OnActionStartArgs;
|
|
43
|
+
export declare const isOnActionFinishArgs: (args: OnActionStartArgs | OnActionFinishArgs) => args is OnActionFinishArgs;
|
|
44
|
+
export interface OnAction {
|
|
45
|
+
(...args: OnActionStartArgs): number;
|
|
46
|
+
(...args: OnActionFinishArgs): void;
|
|
47
|
+
}
|
|
48
|
+
export declare class EventEmitter {
|
|
49
|
+
protected onEvent: OnEvent;
|
|
50
|
+
protected onAction: OnAction;
|
|
51
|
+
protected onEntrypointEvent: OnEntrypointEvent;
|
|
52
|
+
static dummy: EventEmitter;
|
|
53
|
+
constructor(onEvent: OnEvent, onAction: OnAction, onEntrypointEvent: OnEntrypointEvent);
|
|
54
|
+
action<TRes>(actonType: string, idx: string, entrypointRef: string, fn: () => TRes): TRes;
|
|
55
|
+
entrypointEvent(sequenceId: number, event: EntrypointEvent): void;
|
|
56
|
+
perf<TRes>(method: string, fn: () => TRes): TRes;
|
|
57
|
+
single(labels: Record<string, unknown>): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventEmitter = exports.isOnActionFinishArgs = exports.isOnActionStartArgs = void 0;
|
|
4
|
+
const isOnActionStartArgs = (args) => {
|
|
5
|
+
return args[0] === 'start';
|
|
6
|
+
};
|
|
7
|
+
exports.isOnActionStartArgs = isOnActionStartArgs;
|
|
8
|
+
const isOnActionFinishArgs = (args) => {
|
|
9
|
+
return args[0] === 'finish' || args[0] === 'fail';
|
|
10
|
+
};
|
|
11
|
+
exports.isOnActionFinishArgs = isOnActionFinishArgs;
|
|
12
|
+
class EventEmitter {
|
|
13
|
+
onEvent;
|
|
14
|
+
onAction;
|
|
15
|
+
onEntrypointEvent;
|
|
16
|
+
static dummy = new EventEmitter(() => { }, () => 0, () => { });
|
|
17
|
+
constructor(onEvent, onAction, onEntrypointEvent) {
|
|
18
|
+
this.onEvent = onEvent;
|
|
19
|
+
this.onAction = onAction;
|
|
20
|
+
this.onEntrypointEvent = onEntrypointEvent;
|
|
21
|
+
}
|
|
22
|
+
action(actonType, idx, entrypointRef, fn) {
|
|
23
|
+
const id = this.onAction('start', performance.now(), actonType, idx, entrypointRef);
|
|
24
|
+
try {
|
|
25
|
+
const result = fn();
|
|
26
|
+
if (result instanceof Promise) {
|
|
27
|
+
result.then(() => this.onAction('finish', performance.now(), id, true), (e) => this.onAction('fail', performance.now(), id, true, e));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.onAction('finish', performance.now(), id, false);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
this.onAction('fail', performance.now(), id, false, e);
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
entrypointEvent(sequenceId, event) {
|
|
40
|
+
this.onEntrypointEvent(sequenceId, performance.now(), event);
|
|
41
|
+
}
|
|
42
|
+
perf(method, fn) {
|
|
43
|
+
const labels = { method };
|
|
44
|
+
this.onEvent(labels, 'start');
|
|
45
|
+
const result = fn();
|
|
46
|
+
if (result instanceof Promise) {
|
|
47
|
+
result.then(() => this.onEvent(labels, 'finish'), () => this.onEvent(labels, 'finish'));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.onEvent(labels, 'finish');
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
single(labels) {
|
|
55
|
+
this.onEvent({
|
|
56
|
+
...labels,
|
|
57
|
+
datetime: new Date(),
|
|
58
|
+
}, 'single');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.EventEmitter = EventEmitter;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Artifact, Replacement, Rules } from '@wyw-in-js/shared';
|
|
2
|
+
export type WYWTransformMetadata = {
|
|
3
|
+
dependencies: string[];
|
|
4
|
+
processors: {
|
|
5
|
+
artifacts: Artifact[];
|
|
6
|
+
}[];
|
|
7
|
+
replacements: Replacement[];
|
|
8
|
+
rules: Rules;
|
|
9
|
+
};
|
|
10
|
+
export declare const withTransformMetadata: (value: unknown) => value is {
|
|
11
|
+
wywInJS: WYWTransformMetadata;
|
|
12
|
+
};
|
|
13
|
+
export declare const getTransformMetadata: (value: unknown) => WYWTransformMetadata | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTransformMetadata = exports.withTransformMetadata = void 0;
|
|
4
|
+
const withTransformMetadata = (value) => typeof value === 'object' &&
|
|
5
|
+
value !== null &&
|
|
6
|
+
typeof value.wywInJS === 'object';
|
|
7
|
+
exports.withTransformMetadata = withTransformMetadata;
|
|
8
|
+
const getTransformMetadata = (value) => {
|
|
9
|
+
if ((0, exports.withTransformMetadata)(value) && value.wywInJS !== null) {
|
|
10
|
+
const metadata = value.wywInJS;
|
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
|
12
|
+
delete value.wywInJS;
|
|
13
|
+
return metadata;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
};
|
|
17
|
+
exports.getTransformMetadata = getTransformMetadata;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePath, Scope } from '@babel/traverse';
|
|
2
|
+
import type { ObjectExpression } from '@babel/types';
|
|
3
|
+
export declare function getOrAddLinariaPreval(scope: Scope): NodePath<ObjectExpression>;
|
|
4
|
+
export declare function addIdentifierToLinariaPreval(scope: Scope, name: string): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addIdentifierToLinariaPreval = exports.getOrAddLinariaPreval = void 0;
|
|
4
|
+
const createId_1 = require("./createId");
|
|
5
|
+
const scopeHelpers_1 = require("./scopeHelpers");
|
|
6
|
+
function getOrAddLinariaPreval(scope) {
|
|
7
|
+
const rootScope = scope.getProgramParent();
|
|
8
|
+
const programPath = rootScope.path;
|
|
9
|
+
let object = programPath.getData('__linariaPreval');
|
|
10
|
+
if (object) {
|
|
11
|
+
return object;
|
|
12
|
+
}
|
|
13
|
+
if (programPath.node.sourceType === 'script') {
|
|
14
|
+
// CJS exports.__linariaPreval = {};
|
|
15
|
+
const prevalExport = {
|
|
16
|
+
expression: {
|
|
17
|
+
type: 'AssignmentExpression',
|
|
18
|
+
operator: '=',
|
|
19
|
+
left: {
|
|
20
|
+
computed: false,
|
|
21
|
+
object: (0, createId_1.createId)('exports'),
|
|
22
|
+
property: (0, createId_1.createId)('__linariaPreval'),
|
|
23
|
+
type: 'MemberExpression',
|
|
24
|
+
},
|
|
25
|
+
right: {
|
|
26
|
+
properties: [],
|
|
27
|
+
type: 'ObjectExpression',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
type: 'ExpressionStatement',
|
|
31
|
+
};
|
|
32
|
+
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
33
|
+
object = inserted.get('expression.right');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// ESM export const __linariaPreval = {};
|
|
37
|
+
const prevalExport = {
|
|
38
|
+
declaration: {
|
|
39
|
+
declarations: [
|
|
40
|
+
{
|
|
41
|
+
id: (0, createId_1.createId)('__linariaPreval'),
|
|
42
|
+
init: {
|
|
43
|
+
properties: [],
|
|
44
|
+
type: 'ObjectExpression',
|
|
45
|
+
},
|
|
46
|
+
type: 'VariableDeclarator',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
kind: 'const',
|
|
50
|
+
type: 'VariableDeclaration',
|
|
51
|
+
},
|
|
52
|
+
specifiers: [],
|
|
53
|
+
type: 'ExportNamedDeclaration',
|
|
54
|
+
};
|
|
55
|
+
const [inserted] = programPath.pushContainer('body', [prevalExport]);
|
|
56
|
+
object = inserted.get('declaration.declarations.0.init');
|
|
57
|
+
}
|
|
58
|
+
programPath.setData('__linariaPreval', object);
|
|
59
|
+
return object;
|
|
60
|
+
}
|
|
61
|
+
exports.getOrAddLinariaPreval = getOrAddLinariaPreval;
|
|
62
|
+
function addIdentifierToLinariaPreval(scope, name) {
|
|
63
|
+
const rootScope = scope.getProgramParent();
|
|
64
|
+
const object = getOrAddLinariaPreval(rootScope);
|
|
65
|
+
const newProperty = {
|
|
66
|
+
type: 'ObjectProperty',
|
|
67
|
+
key: (0, createId_1.createId)(name),
|
|
68
|
+
value: (0, createId_1.createId)(name),
|
|
69
|
+
computed: false,
|
|
70
|
+
shorthand: false,
|
|
71
|
+
};
|
|
72
|
+
const [inserted] = object.pushContainer('properties', [newProperty]);
|
|
73
|
+
(0, scopeHelpers_1.reference)(inserted.get('value'));
|
|
74
|
+
}
|
|
75
|
+
exports.addIdentifierToLinariaPreval = addIdentifierToLinariaPreval;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import type { Identifier, MemberExpression, Program } from '@babel/types';
|
|
3
|
+
export interface ISideEffectImport {
|
|
4
|
+
imported: 'side-effect';
|
|
5
|
+
local: NodePath;
|
|
6
|
+
source: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IImport {
|
|
9
|
+
imported: string | 'default' | '*';
|
|
10
|
+
local: NodePath<Identifier | MemberExpression>;
|
|
11
|
+
source: string;
|
|
12
|
+
type: 'cjs' | 'dynamic' | 'esm';
|
|
13
|
+
}
|
|
14
|
+
export type Exports = Record<string | 'default' | '*', NodePath>;
|
|
15
|
+
export interface IReexport {
|
|
16
|
+
exported: string | 'default' | '*';
|
|
17
|
+
imported: string | 'default' | '*';
|
|
18
|
+
local: NodePath;
|
|
19
|
+
source: string;
|
|
20
|
+
}
|
|
21
|
+
export interface IState {
|
|
22
|
+
deadExports: string[];
|
|
23
|
+
exportRefs: Map<string, NodePath<MemberExpression>[]>;
|
|
24
|
+
exports: Exports;
|
|
25
|
+
imports: (IImport | ISideEffectImport)[];
|
|
26
|
+
isEsModule: boolean;
|
|
27
|
+
reexports: IReexport[];
|
|
28
|
+
}
|
|
29
|
+
export declare const sideEffectImport: (item: IImport | ISideEffectImport) => item is ISideEffectImport;
|
|
30
|
+
export declare const explicitImport: (item: IImport | ISideEffectImport) => item is IImport;
|
|
31
|
+
export declare function collectExportsAndImports(path: NodePath<Program>, cacheMode?: 'disabled' | 'force' | 'enabled'): IState;
|