@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,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTagProcessor = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const core_1 = require("@babel/core");
|
|
7
|
+
const helper_module_imports_1 = require("@babel/helper-module-imports");
|
|
8
|
+
const processor_utils_1 = require("@wyw-in-js/processor-utils");
|
|
9
|
+
const collectExportsAndImports_1 = require("./collectExportsAndImports");
|
|
10
|
+
const collectTemplateDependencies_1 = require("./collectTemplateDependencies");
|
|
11
|
+
const findPackageJSON_1 = require("./findPackageJSON");
|
|
12
|
+
const getSource_1 = require("./getSource");
|
|
13
|
+
const isNotNull_1 = require("./isNotNull");
|
|
14
|
+
const scopeHelpers_1 = require("./scopeHelpers");
|
|
15
|
+
const traversalCache_1 = require("./traversalCache");
|
|
16
|
+
const last = (arr) => arr[arr.length - 1];
|
|
17
|
+
function zip(arr1, arr2) {
|
|
18
|
+
const result = [];
|
|
19
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
20
|
+
result.push(arr1[i]);
|
|
21
|
+
if (arr2[i])
|
|
22
|
+
result.push(arr2[i]);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function buildCodeFrameError(path, message) {
|
|
27
|
+
try {
|
|
28
|
+
return path.buildCodeFrameError(message);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return new Error(message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const definedTagsCache = new Map();
|
|
35
|
+
const getDefinedTagsFromPackage = (pkgName, filename) => {
|
|
36
|
+
if (definedTagsCache.has(pkgName)) {
|
|
37
|
+
return definedTagsCache.get(pkgName);
|
|
38
|
+
}
|
|
39
|
+
const packageJSONPath = (0, findPackageJSON_1.findPackageJSON)(pkgName, filename);
|
|
40
|
+
if (!packageJSONPath) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const packageDir = (0, path_1.dirname)(packageJSONPath);
|
|
44
|
+
const packageJSON = JSON.parse((0, fs_1.readFileSync)(packageJSONPath, 'utf8'));
|
|
45
|
+
const definedTags = packageJSON['wyw-in-js']?.tags;
|
|
46
|
+
const normalizedTags = definedTags
|
|
47
|
+
? Object.entries(definedTags).reduce((acc, [key, value]) => ({
|
|
48
|
+
...acc,
|
|
49
|
+
[key]: value.startsWith('.')
|
|
50
|
+
? (0, path_1.join)(packageDir, value)
|
|
51
|
+
: require.resolve(value, { paths: [packageDir] }),
|
|
52
|
+
}), {})
|
|
53
|
+
: undefined;
|
|
54
|
+
definedTagsCache.set(pkgName, normalizedTags);
|
|
55
|
+
return normalizedTags;
|
|
56
|
+
};
|
|
57
|
+
function isValidProcessorClass(module) {
|
|
58
|
+
return module instanceof processor_utils_1.BaseProcessor.constructor;
|
|
59
|
+
}
|
|
60
|
+
function getProcessorFromPackage(packageName, tagName, filename) {
|
|
61
|
+
const definedTags = getDefinedTagsFromPackage(packageName, filename);
|
|
62
|
+
const processorPath = definedTags?.[tagName];
|
|
63
|
+
if (!processorPath) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const Processor = require(processorPath).default;
|
|
67
|
+
if (!isValidProcessorClass(Processor)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return Processor;
|
|
71
|
+
}
|
|
72
|
+
function getProcessorFromFile(processorPath) {
|
|
73
|
+
const Processor = require(processorPath).default;
|
|
74
|
+
if (!isValidProcessorClass(Processor)) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return Processor;
|
|
78
|
+
}
|
|
79
|
+
function getProcessorForIdentifier(path, imports, filename, options) {
|
|
80
|
+
const pathBinding = path.scope.getBinding(path.node.name);
|
|
81
|
+
if (!pathBinding) {
|
|
82
|
+
// It's not a binding, so it's not a tag
|
|
83
|
+
return [null, null, null];
|
|
84
|
+
}
|
|
85
|
+
const tagResolver = options.tagResolver ?? (() => null);
|
|
86
|
+
// FIXME: can be simplified
|
|
87
|
+
const relatedImports = imports
|
|
88
|
+
.map((i) => {
|
|
89
|
+
const { local } = i;
|
|
90
|
+
if (local === path) {
|
|
91
|
+
return [i, null];
|
|
92
|
+
}
|
|
93
|
+
if (!local.isIdentifier()) {
|
|
94
|
+
if (path.isDescendant(local)) {
|
|
95
|
+
return [i, local];
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const binding = local.scope.getBinding(local.node.name);
|
|
100
|
+
if (pathBinding === binding) {
|
|
101
|
+
return [i, path];
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
})
|
|
105
|
+
.filter(isNotNull_1.isNotNull)
|
|
106
|
+
.filter((i) => i[1] === null || i[1].isExpression());
|
|
107
|
+
if (relatedImports.length === 0) {
|
|
108
|
+
return [null, null, null];
|
|
109
|
+
}
|
|
110
|
+
const [Processor = null, tagSource = null, tagPath = null] = relatedImports
|
|
111
|
+
.map(([{ imported, source }, p]) => {
|
|
112
|
+
const customFile = tagResolver(source, imported);
|
|
113
|
+
const processor = customFile
|
|
114
|
+
? getProcessorFromFile(customFile)
|
|
115
|
+
: getProcessorFromPackage(source, imported, filename);
|
|
116
|
+
return [processor, { imported, source }, p];
|
|
117
|
+
})
|
|
118
|
+
.find(([proc]) => proc) ?? [];
|
|
119
|
+
return Processor === null || tagSource === null || tagPath === null
|
|
120
|
+
? [null, null, null]
|
|
121
|
+
: [Processor, tagSource, tagPath];
|
|
122
|
+
}
|
|
123
|
+
function getBuilderForIdentifier(path, imports, filename, options) {
|
|
124
|
+
const [Processor, tagSource, tagPath] = getProcessorForIdentifier(path, imports, filename, options);
|
|
125
|
+
if (!Processor || !tagSource || !tagPath) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const params = [['callee', tagPath.node]];
|
|
129
|
+
let prev = tagPath;
|
|
130
|
+
let current = tagPath.parentPath;
|
|
131
|
+
while (current && current !== path) {
|
|
132
|
+
if (current?.isSequenceExpression() &&
|
|
133
|
+
last(current.node.expressions) === prev.node) {
|
|
134
|
+
prev = current;
|
|
135
|
+
current = current.parentPath;
|
|
136
|
+
// eslint-disable-next-line no-continue
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (current?.isCallExpression({ callee: prev.node })) {
|
|
140
|
+
const args = current.get('arguments');
|
|
141
|
+
const cookedArgs = args
|
|
142
|
+
.map((arg) => {
|
|
143
|
+
const buildError = arg.buildCodeFrameError.bind(arg);
|
|
144
|
+
if (!arg.isExpression()) {
|
|
145
|
+
throw buildError(`Unexpected type of an argument ${arg.type}`);
|
|
146
|
+
}
|
|
147
|
+
const source = (0, getSource_1.getSource)(arg);
|
|
148
|
+
const extracted = (0, collectTemplateDependencies_1.extractExpression)(arg, options.evaluate, imports);
|
|
149
|
+
return {
|
|
150
|
+
...extracted,
|
|
151
|
+
source,
|
|
152
|
+
buildCodeFrameError: buildError,
|
|
153
|
+
};
|
|
154
|
+
})
|
|
155
|
+
.filter(isNotNull_1.isNotNull);
|
|
156
|
+
params.push(['call', ...cookedArgs]);
|
|
157
|
+
prev = current;
|
|
158
|
+
current = current.parentPath;
|
|
159
|
+
// eslint-disable-next-line no-continue
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (current?.isMemberExpression({ object: prev.node })) {
|
|
163
|
+
const property = current.get('property');
|
|
164
|
+
if (property.isIdentifier() && !current.node.computed) {
|
|
165
|
+
params.push(['member', property.node.name]);
|
|
166
|
+
}
|
|
167
|
+
else if (property.isStringLiteral()) {
|
|
168
|
+
params.push(['member', property.node.value]);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw property.buildCodeFrameError(`Unexpected type of a property`);
|
|
172
|
+
}
|
|
173
|
+
prev = current;
|
|
174
|
+
current = current.parentPath;
|
|
175
|
+
// eslint-disable-next-line no-continue
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (current?.isTaggedTemplateExpression({ tag: prev.node })) {
|
|
179
|
+
const [quasis, expressionValues] = (0, collectTemplateDependencies_1.collectTemplateDependencies)(current, options.evaluate);
|
|
180
|
+
params.push(['template', zip(quasis, expressionValues)]);
|
|
181
|
+
prev = current;
|
|
182
|
+
current = current.parentPath;
|
|
183
|
+
// eslint-disable-next-line no-continue
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
const replacer = (replacement, isPure) => {
|
|
189
|
+
(0, scopeHelpers_1.mutate)(prev, (p) => {
|
|
190
|
+
p.replaceWith(replacement);
|
|
191
|
+
if (isPure) {
|
|
192
|
+
p.addComment('leading', '#__PURE__');
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const astService = {
|
|
197
|
+
...core_1.types,
|
|
198
|
+
addDefaultImport: (importedSource, nameHint) => (0, helper_module_imports_1.addDefault)(path, importedSource, { nameHint }),
|
|
199
|
+
addNamedImport: (name, importedSource, nameHint = name) => (0, helper_module_imports_1.addNamed)(path, name, importedSource, { nameHint }),
|
|
200
|
+
};
|
|
201
|
+
return (...args) => new Processor(params, tagSource, astService, tagPath.node.loc ?? null, replacer, ...args);
|
|
202
|
+
}
|
|
203
|
+
function getDisplayName(path, idx, filename) {
|
|
204
|
+
let displayName;
|
|
205
|
+
const parent = path.findParent((p) => p.isObjectProperty() ||
|
|
206
|
+
p.isJSXOpeningElement() ||
|
|
207
|
+
p.isVariableDeclarator());
|
|
208
|
+
if (parent) {
|
|
209
|
+
if (parent.isObjectProperty()) {
|
|
210
|
+
if ('name' in parent.node.key) {
|
|
211
|
+
displayName = parent.node.key.name;
|
|
212
|
+
}
|
|
213
|
+
else if ('value' in parent.node.key) {
|
|
214
|
+
displayName = parent.node.key.value.toString();
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const keyPath = parent.get('key');
|
|
218
|
+
displayName = (0, getSource_1.getSource)(keyPath);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else if (parent.isJSXOpeningElement()) {
|
|
222
|
+
const name = parent.get('name');
|
|
223
|
+
if (name.isJSXIdentifier()) {
|
|
224
|
+
displayName = name.node.name;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (parent.isVariableDeclarator()) {
|
|
228
|
+
const id = parent.get('id');
|
|
229
|
+
if (id.isIdentifier()) {
|
|
230
|
+
displayName = id.node.name;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (!displayName) {
|
|
235
|
+
// Try to derive the path from the filename
|
|
236
|
+
displayName = (0, path_1.basename)(filename ?? 'unknown');
|
|
237
|
+
if (filename && /^index\.[a-z\d]+$/.test(displayName)) {
|
|
238
|
+
// If the file name is 'index', better to get name from parent folder
|
|
239
|
+
displayName = (0, path_1.basename)((0, path_1.dirname)(filename));
|
|
240
|
+
}
|
|
241
|
+
// Remove the file extension
|
|
242
|
+
displayName = displayName.replace(/\.[a-z\d]+$/, '');
|
|
243
|
+
if (displayName) {
|
|
244
|
+
displayName += idx;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
throw new Error("Couldn't determine a name for the component. Ensure that it's either:\n" +
|
|
248
|
+
'- Assigned to a variable\n' +
|
|
249
|
+
'- Is an object property\n' +
|
|
250
|
+
'- Is a prop in a JSX element\n');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return displayName;
|
|
254
|
+
}
|
|
255
|
+
function isTagReferenced(path) {
|
|
256
|
+
// Check if the variable is referenced anywhere for basic DCE
|
|
257
|
+
// Only works when it's assigned to a variable
|
|
258
|
+
let isReferenced = true;
|
|
259
|
+
const parent = path.findParent((p) => p.isObjectProperty() ||
|
|
260
|
+
p.isJSXOpeningElement() ||
|
|
261
|
+
p.isVariableDeclarator());
|
|
262
|
+
if (parent) {
|
|
263
|
+
if (parent.isVariableDeclarator()) {
|
|
264
|
+
const id = parent.get('id');
|
|
265
|
+
// FIXME: replace with id.isReferencedIdentifier()
|
|
266
|
+
if (id.isIdentifier()) {
|
|
267
|
+
const { referencePaths } = path.scope.getBinding(id.node.name) || {
|
|
268
|
+
referencePaths: [],
|
|
269
|
+
};
|
|
270
|
+
isReferenced = referencePaths.length !== 0;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return isReferenced;
|
|
275
|
+
}
|
|
276
|
+
const counters = new WeakMap();
|
|
277
|
+
const getNextIndex = (state) => {
|
|
278
|
+
const counter = counters.get(state) ?? 0;
|
|
279
|
+
counters.set(state, counter + 1);
|
|
280
|
+
return counter;
|
|
281
|
+
};
|
|
282
|
+
function getTagProcessor(path, fileContext, options) {
|
|
283
|
+
const cache = (0, traversalCache_1.getTraversalCache)(path, 'getTagProcessor');
|
|
284
|
+
if (!cache.has(path.node)) {
|
|
285
|
+
const root = path.scope.getProgramParent().path;
|
|
286
|
+
const { imports } = (0, collectExportsAndImports_1.collectExportsAndImports)(root);
|
|
287
|
+
try {
|
|
288
|
+
const builder = getBuilderForIdentifier(path, imports.filter(collectExportsAndImports_1.explicitImport), fileContext.filename, options);
|
|
289
|
+
if (builder) {
|
|
290
|
+
// Increment the index of the style we're processing
|
|
291
|
+
// This is used for slug generation to prevent collision
|
|
292
|
+
// Also used for display name if it couldn't be determined
|
|
293
|
+
const idx = getNextIndex(fileContext);
|
|
294
|
+
const displayName = getDisplayName(path, idx, fileContext.filename);
|
|
295
|
+
const processor = builder(displayName, isTagReferenced(path), idx, options, fileContext);
|
|
296
|
+
cache.set(path.node, processor);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
cache.set(path.node, null);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (e) {
|
|
303
|
+
if (e === processor_utils_1.BaseProcessor.SKIP) {
|
|
304
|
+
cache.set(path.node, null);
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
if (e instanceof Error) {
|
|
308
|
+
throw buildCodeFrameError(path, e.message);
|
|
309
|
+
}
|
|
310
|
+
throw e;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return cache.get(path.node) ?? null;
|
|
314
|
+
}
|
|
315
|
+
exports.getTagProcessor = getTagProcessor;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Node } from '@babel/types';
|
|
2
|
+
export type VisitorKeys<T extends Node> = {
|
|
3
|
+
[K in keyof T]: Exclude<T[K], undefined> extends Node | Node[] | null ? K : never;
|
|
4
|
+
}[keyof T] & string;
|
|
5
|
+
export declare function getVisitorKeys<TNode extends Node>(node: TNode): VisitorKeys<TNode>[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVisitorKeys = void 0;
|
|
4
|
+
const core_1 = require("@babel/core");
|
|
5
|
+
function getVisitorKeys(node) {
|
|
6
|
+
return core_1.types.VISITOR_KEYS[node.type];
|
|
7
|
+
}
|
|
8
|
+
exports.getVisitorKeys = getVisitorKeys;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function hasLinariaPreval(exports) {
|
|
4
|
+
if (!exports || typeof exports !== 'object') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
return '__linariaPreval' in exports;
|
|
8
|
+
}
|
|
9
|
+
exports.default = hasLinariaPreval;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isExports = void 0;
|
|
4
|
+
const isGlobal_1 = require("./isGlobal");
|
|
5
|
+
/**
|
|
6
|
+
* Checks that specified Identifier is a global `exports` or `module.exports`
|
|
7
|
+
* @param node
|
|
8
|
+
*/
|
|
9
|
+
function isExports(node) {
|
|
10
|
+
if (node?.isIdentifier({ name: 'exports' })) {
|
|
11
|
+
return (0, isGlobal_1.isGlobal)(node, 'exports');
|
|
12
|
+
}
|
|
13
|
+
if (node?.isMemberExpression() &&
|
|
14
|
+
node.get('object').isIdentifier({ name: 'module' }) &&
|
|
15
|
+
node.get('property').isIdentifier({ name: 'exports' })) {
|
|
16
|
+
return (0, isGlobal_1.isGlobal)(node, 'module');
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
exports.isExports = isExports;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isGlobal = void 0;
|
|
4
|
+
const getScope_1 = require("./getScope");
|
|
5
|
+
const isGlobal = (node, name) => {
|
|
6
|
+
const scope = (0, getScope_1.getScope)(node);
|
|
7
|
+
return scope.getBinding(name) === undefined && scope.hasGlobal(name);
|
|
8
|
+
};
|
|
9
|
+
exports.isGlobal = isGlobal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNotNull<T>(x: T | null): x is T;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRemoved = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given path has been removed from the AST.
|
|
6
|
+
*/
|
|
7
|
+
function isRemoved(path) {
|
|
8
|
+
// Check if the input path has already been removed
|
|
9
|
+
if (path.removed) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
// Check if any of the parent paths have been removed
|
|
13
|
+
let currentPath = path;
|
|
14
|
+
while (currentPath) {
|
|
15
|
+
const parent = currentPath.parentPath;
|
|
16
|
+
if (parent) {
|
|
17
|
+
// If the parent path has been removed, return true
|
|
18
|
+
if (parent.removed || parent.node === null) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
const { listKey, key, node } = currentPath;
|
|
22
|
+
if (listKey) {
|
|
23
|
+
// If the current path is part of a list and the current node
|
|
24
|
+
// is not presented in this list, return true
|
|
25
|
+
const found = parent.get(listKey).find((p) => p.node === node);
|
|
26
|
+
if (!found) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// If the current path is not part of a list and its node is not the same
|
|
31
|
+
// as the node in the parent object at the same key, return true
|
|
32
|
+
else if (parent.get(key).node !== node) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Set the current path to its parent path and continue the loop
|
|
37
|
+
currentPath = parent;
|
|
38
|
+
}
|
|
39
|
+
// If the function has not returned true by this point, return false
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
exports.isRemoved = isRemoved;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRequire = void 0;
|
|
4
|
+
const isGlobal_1 = require("./isGlobal");
|
|
5
|
+
/**
|
|
6
|
+
* Checks that specified Identifier is a global `require`
|
|
7
|
+
* @param id
|
|
8
|
+
*/
|
|
9
|
+
function isRequire(id) {
|
|
10
|
+
if (!id?.isIdentifier() || id.node.name !== 'require') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return (0, isGlobal_1.isGlobal)(id, 'require');
|
|
14
|
+
}
|
|
15
|
+
exports.isRequire = isRequire;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSerializable = void 0;
|
|
4
|
+
const shared_1 = require("@wyw-in-js/shared");
|
|
5
|
+
function isSerializable(o) {
|
|
6
|
+
if (Array.isArray(o)) {
|
|
7
|
+
return o.every(isSerializable);
|
|
8
|
+
}
|
|
9
|
+
if (o === null)
|
|
10
|
+
return true;
|
|
11
|
+
if ((0, shared_1.isBoxedPrimitive)(o))
|
|
12
|
+
return true;
|
|
13
|
+
if (typeof o === 'object') {
|
|
14
|
+
return Object.values(o).every(isSerializable);
|
|
15
|
+
}
|
|
16
|
+
return (typeof o === 'string' || typeof o === 'number' || typeof o === 'boolean');
|
|
17
|
+
}
|
|
18
|
+
exports.isSerializable = isSerializable;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUnnecessaryReactCall = void 0;
|
|
4
|
+
const collectExportsAndImports_1 = require("./collectExportsAndImports");
|
|
5
|
+
const getScope_1 = require("./getScope");
|
|
6
|
+
function getCallee(p) {
|
|
7
|
+
const callee = p.get('callee');
|
|
8
|
+
if (callee.isSequenceExpression()) {
|
|
9
|
+
const expressions = callee.get('expressions');
|
|
10
|
+
if (expressions.length === 2 &&
|
|
11
|
+
expressions[0].isNumericLiteral({ value: 0 })) {
|
|
12
|
+
return expressions[1];
|
|
13
|
+
}
|
|
14
|
+
return callee;
|
|
15
|
+
}
|
|
16
|
+
return callee;
|
|
17
|
+
}
|
|
18
|
+
const JSXRuntimeSource = 'react/jsx-runtime';
|
|
19
|
+
function isJSXRuntime(p, imports) {
|
|
20
|
+
const jsxRuntime = imports.find((i) => i.source === JSXRuntimeSource);
|
|
21
|
+
const jsxRuntimeName = jsxRuntime?.local?.isIdentifier() && jsxRuntime?.local?.node?.name;
|
|
22
|
+
if (jsxRuntime) {
|
|
23
|
+
const callee = getCallee(p);
|
|
24
|
+
if (jsxRuntimeName && callee.isIdentifier({ name: jsxRuntimeName })) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (callee.isMemberExpression() &&
|
|
28
|
+
imports.find((i) => i.source === JSXRuntimeSource && i.local === callee)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
function isHookOrCreateElement(name) {
|
|
35
|
+
return name === 'createElement' || /use[A-Z]/.test(name);
|
|
36
|
+
}
|
|
37
|
+
function isClassicReactRuntime(p, imports) {
|
|
38
|
+
const reactImports = imports.filter((i) => i.source === 'react' &&
|
|
39
|
+
(i.imported === 'default' ||
|
|
40
|
+
(i.imported && isHookOrCreateElement(i.imported))));
|
|
41
|
+
if (reactImports.length === 0)
|
|
42
|
+
return false;
|
|
43
|
+
const callee = getCallee(p);
|
|
44
|
+
if (callee.isIdentifier() && isHookOrCreateElement(callee.node.name)) {
|
|
45
|
+
const bindingPath = (0, getScope_1.getScope)(callee).getBinding(callee.node.name)?.path;
|
|
46
|
+
return reactImports.some((i) => bindingPath?.isAncestor(i.local));
|
|
47
|
+
}
|
|
48
|
+
if (callee.isMemberExpression()) {
|
|
49
|
+
if (reactImports.some((i) => i.local === callee)) {
|
|
50
|
+
// It's React.createElement in CJS
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const object = callee.get('object');
|
|
54
|
+
const property = callee.get('property');
|
|
55
|
+
const defaultImport = reactImports.find((i) => i.imported === 'default');
|
|
56
|
+
if (!defaultImport ||
|
|
57
|
+
!defaultImport.local.isIdentifier() ||
|
|
58
|
+
!property.isIdentifier() ||
|
|
59
|
+
!isHookOrCreateElement(property.node.name) ||
|
|
60
|
+
!object.isIdentifier({ name: defaultImport.local.node.name })) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const bindingPath = (0, getScope_1.getScope)(object).getBinding(object.node.name)?.path;
|
|
64
|
+
return bindingPath?.isAncestor(defaultImport.local) ?? false;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
function isUnnecessaryReactCall(path) {
|
|
69
|
+
const programPath = path.findParent((p) => p.isProgram());
|
|
70
|
+
if (!programPath) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const { imports } = (0, collectExportsAndImports_1.collectExportsAndImports)(programPath);
|
|
74
|
+
return isJSXRuntime(path, imports) || isClassicReactRuntime(path, imports);
|
|
75
|
+
}
|
|
76
|
+
exports.isUnnecessaryReactCall = isUnnecessaryReactCall;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const peek: <T>(stack: T[], offset?: number) => T;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { NodePath } from '@babel/traverse';
|
|
2
|
+
import type { Identifier } from '@babel/types';
|
|
3
|
+
import type { BaseProcessor, IFileContext } from '@wyw-in-js/processor-utils';
|
|
4
|
+
import type { StrictOptions } from '@wyw-in-js/shared';
|
|
5
|
+
export declare const processTemplateExpression: (p: NodePath<Identifier>, fileContext: IFileContext, options: Pick<StrictOptions, 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'>, emit: (processor: BaseProcessor) => void) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processTemplateExpression = void 0;
|
|
4
|
+
const getTagProcessor_1 = require("./getTagProcessor");
|
|
5
|
+
const processed = new WeakSet();
|
|
6
|
+
const processTemplateExpression = (p, fileContext, options, emit) => {
|
|
7
|
+
if (p.parentPath.isExportSpecifier())
|
|
8
|
+
return;
|
|
9
|
+
if (processed.has(p.node))
|
|
10
|
+
return;
|
|
11
|
+
const tagProcessor = (0, getTagProcessor_1.getTagProcessor)(p, fileContext, options);
|
|
12
|
+
processed.add(p.node);
|
|
13
|
+
if (tagProcessor === null)
|
|
14
|
+
return;
|
|
15
|
+
emit(tagProcessor);
|
|
16
|
+
};
|
|
17
|
+
exports.processTemplateExpression = processTemplateExpression;
|