@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,304 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { basename, dirname, join } from 'path';
|
|
3
|
+
import { types as t } from '@babel/core';
|
|
4
|
+
import { addDefault, addNamed } from '@babel/helper-module-imports';
|
|
5
|
+
import { BaseProcessor } from '@wyw-in-js/processor-utils';
|
|
6
|
+
import { collectExportsAndImports, explicitImport } from './collectExportsAndImports';
|
|
7
|
+
import { collectTemplateDependencies, extractExpression } from './collectTemplateDependencies';
|
|
8
|
+
import { findPackageJSON } from './findPackageJSON';
|
|
9
|
+
import { getSource } from './getSource';
|
|
10
|
+
import { isNotNull } from './isNotNull';
|
|
11
|
+
import { mutate } from './scopeHelpers';
|
|
12
|
+
import { getTraversalCache } from './traversalCache';
|
|
13
|
+
const last = arr => arr[arr.length - 1];
|
|
14
|
+
function zip(arr1, arr2) {
|
|
15
|
+
const result = [];
|
|
16
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
17
|
+
result.push(arr1[i]);
|
|
18
|
+
if (arr2[i]) result.push(arr2[i]);
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
function buildCodeFrameError(path, message) {
|
|
23
|
+
try {
|
|
24
|
+
return path.buildCodeFrameError(message);
|
|
25
|
+
} catch {
|
|
26
|
+
return new Error(message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const definedTagsCache = new Map();
|
|
30
|
+
const getDefinedTagsFromPackage = (pkgName, filename) => {
|
|
31
|
+
if (definedTagsCache.has(pkgName)) {
|
|
32
|
+
return definedTagsCache.get(pkgName);
|
|
33
|
+
}
|
|
34
|
+
const packageJSONPath = findPackageJSON(pkgName, filename);
|
|
35
|
+
if (!packageJSONPath) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const packageDir = dirname(packageJSONPath);
|
|
39
|
+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));
|
|
40
|
+
const definedTags = packageJSON['wyw-in-js']?.tags;
|
|
41
|
+
const normalizedTags = definedTags ? Object.entries(definedTags).reduce((acc, [key, value]) => ({
|
|
42
|
+
...acc,
|
|
43
|
+
[key]: value.startsWith('.') ? join(packageDir, value) : require.resolve(value, {
|
|
44
|
+
paths: [packageDir]
|
|
45
|
+
})
|
|
46
|
+
}), {}) : undefined;
|
|
47
|
+
definedTagsCache.set(pkgName, normalizedTags);
|
|
48
|
+
return normalizedTags;
|
|
49
|
+
};
|
|
50
|
+
function isValidProcessorClass(module) {
|
|
51
|
+
return module instanceof BaseProcessor.constructor;
|
|
52
|
+
}
|
|
53
|
+
function getProcessorFromPackage(packageName, tagName, filename) {
|
|
54
|
+
const definedTags = getDefinedTagsFromPackage(packageName, filename);
|
|
55
|
+
const processorPath = definedTags?.[tagName];
|
|
56
|
+
if (!processorPath) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const Processor = require(processorPath).default;
|
|
60
|
+
if (!isValidProcessorClass(Processor)) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return Processor;
|
|
64
|
+
}
|
|
65
|
+
function getProcessorFromFile(processorPath) {
|
|
66
|
+
const Processor = require(processorPath).default;
|
|
67
|
+
if (!isValidProcessorClass(Processor)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return Processor;
|
|
71
|
+
}
|
|
72
|
+
function getProcessorForIdentifier(path, imports, filename, options) {
|
|
73
|
+
const pathBinding = path.scope.getBinding(path.node.name);
|
|
74
|
+
if (!pathBinding) {
|
|
75
|
+
// It's not a binding, so it's not a tag
|
|
76
|
+
return [null, null, null];
|
|
77
|
+
}
|
|
78
|
+
const tagResolver = options.tagResolver ?? (() => null);
|
|
79
|
+
|
|
80
|
+
// FIXME: can be simplified
|
|
81
|
+
const relatedImports = imports.map(i => {
|
|
82
|
+
const {
|
|
83
|
+
local
|
|
84
|
+
} = i;
|
|
85
|
+
if (local === path) {
|
|
86
|
+
return [i, null];
|
|
87
|
+
}
|
|
88
|
+
if (!local.isIdentifier()) {
|
|
89
|
+
if (path.isDescendant(local)) {
|
|
90
|
+
return [i, local];
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const binding = local.scope.getBinding(local.node.name);
|
|
95
|
+
if (pathBinding === binding) {
|
|
96
|
+
return [i, path];
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}).filter(isNotNull).filter(i => i[1] === null || i[1].isExpression());
|
|
100
|
+
if (relatedImports.length === 0) {
|
|
101
|
+
return [null, null, null];
|
|
102
|
+
}
|
|
103
|
+
const [Processor = null, tagSource = null, tagPath = null] = relatedImports.map(([{
|
|
104
|
+
imported,
|
|
105
|
+
source
|
|
106
|
+
}, p]) => {
|
|
107
|
+
const customFile = tagResolver(source, imported);
|
|
108
|
+
const processor = customFile ? getProcessorFromFile(customFile) : getProcessorFromPackage(source, imported, filename);
|
|
109
|
+
return [processor, {
|
|
110
|
+
imported,
|
|
111
|
+
source
|
|
112
|
+
}, p];
|
|
113
|
+
}).find(([proc]) => proc) ?? [];
|
|
114
|
+
return Processor === null || tagSource === null || tagPath === null ? [null, null, null] : [Processor, tagSource, tagPath];
|
|
115
|
+
}
|
|
116
|
+
function getBuilderForIdentifier(path, imports, filename, options) {
|
|
117
|
+
const [Processor, tagSource, tagPath] = getProcessorForIdentifier(path, imports, filename, options);
|
|
118
|
+
if (!Processor || !tagSource || !tagPath) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const params = [['callee', tagPath.node]];
|
|
122
|
+
let prev = tagPath;
|
|
123
|
+
let current = tagPath.parentPath;
|
|
124
|
+
while (current && current !== path) {
|
|
125
|
+
if (current?.isSequenceExpression() && last(current.node.expressions) === prev.node) {
|
|
126
|
+
prev = current;
|
|
127
|
+
current = current.parentPath;
|
|
128
|
+
// eslint-disable-next-line no-continue
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (current?.isCallExpression({
|
|
132
|
+
callee: prev.node
|
|
133
|
+
})) {
|
|
134
|
+
const args = current.get('arguments');
|
|
135
|
+
const cookedArgs = args.map(arg => {
|
|
136
|
+
const buildError = arg.buildCodeFrameError.bind(arg);
|
|
137
|
+
if (!arg.isExpression()) {
|
|
138
|
+
throw buildError(`Unexpected type of an argument ${arg.type}`);
|
|
139
|
+
}
|
|
140
|
+
const source = getSource(arg);
|
|
141
|
+
const extracted = extractExpression(arg, options.evaluate, imports);
|
|
142
|
+
return {
|
|
143
|
+
...extracted,
|
|
144
|
+
source,
|
|
145
|
+
buildCodeFrameError: buildError
|
|
146
|
+
};
|
|
147
|
+
}).filter(isNotNull);
|
|
148
|
+
params.push(['call', ...cookedArgs]);
|
|
149
|
+
prev = current;
|
|
150
|
+
current = current.parentPath;
|
|
151
|
+
// eslint-disable-next-line no-continue
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (current?.isMemberExpression({
|
|
155
|
+
object: prev.node
|
|
156
|
+
})) {
|
|
157
|
+
const property = current.get('property');
|
|
158
|
+
if (property.isIdentifier() && !current.node.computed) {
|
|
159
|
+
params.push(['member', property.node.name]);
|
|
160
|
+
} else if (property.isStringLiteral()) {
|
|
161
|
+
params.push(['member', property.node.value]);
|
|
162
|
+
} else {
|
|
163
|
+
throw property.buildCodeFrameError(`Unexpected type of a property`);
|
|
164
|
+
}
|
|
165
|
+
prev = current;
|
|
166
|
+
current = current.parentPath;
|
|
167
|
+
// eslint-disable-next-line no-continue
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (current?.isTaggedTemplateExpression({
|
|
171
|
+
tag: prev.node
|
|
172
|
+
})) {
|
|
173
|
+
const [quasis, expressionValues] = collectTemplateDependencies(current, options.evaluate);
|
|
174
|
+
params.push(['template', zip(quasis, expressionValues)]);
|
|
175
|
+
prev = current;
|
|
176
|
+
current = current.parentPath;
|
|
177
|
+
// eslint-disable-next-line no-continue
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
const replacer = (replacement, isPure) => {
|
|
183
|
+
mutate(prev, p => {
|
|
184
|
+
p.replaceWith(replacement);
|
|
185
|
+
if (isPure) {
|
|
186
|
+
p.addComment('leading', '#__PURE__');
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
const astService = {
|
|
191
|
+
...t,
|
|
192
|
+
addDefaultImport: (importedSource, nameHint) => addDefault(path, importedSource, {
|
|
193
|
+
nameHint
|
|
194
|
+
}),
|
|
195
|
+
addNamedImport: (name, importedSource, nameHint = name) => addNamed(path, name, importedSource, {
|
|
196
|
+
nameHint
|
|
197
|
+
})
|
|
198
|
+
};
|
|
199
|
+
return (...args) => new Processor(params, tagSource, astService, tagPath.node.loc ?? null, replacer, ...args);
|
|
200
|
+
}
|
|
201
|
+
function getDisplayName(path, idx, filename) {
|
|
202
|
+
let displayName;
|
|
203
|
+
const parent = path.findParent(p => p.isObjectProperty() || p.isJSXOpeningElement() || p.isVariableDeclarator());
|
|
204
|
+
if (parent) {
|
|
205
|
+
if (parent.isObjectProperty()) {
|
|
206
|
+
if ('name' in parent.node.key) {
|
|
207
|
+
displayName = parent.node.key.name;
|
|
208
|
+
} else if ('value' in parent.node.key) {
|
|
209
|
+
displayName = parent.node.key.value.toString();
|
|
210
|
+
} else {
|
|
211
|
+
const keyPath = parent.get('key');
|
|
212
|
+
displayName = getSource(keyPath);
|
|
213
|
+
}
|
|
214
|
+
} else if (parent.isJSXOpeningElement()) {
|
|
215
|
+
const name = parent.get('name');
|
|
216
|
+
if (name.isJSXIdentifier()) {
|
|
217
|
+
displayName = name.node.name;
|
|
218
|
+
}
|
|
219
|
+
} else if (parent.isVariableDeclarator()) {
|
|
220
|
+
const id = parent.get('id');
|
|
221
|
+
if (id.isIdentifier()) {
|
|
222
|
+
displayName = id.node.name;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!displayName) {
|
|
227
|
+
// Try to derive the path from the filename
|
|
228
|
+
displayName = basename(filename ?? 'unknown');
|
|
229
|
+
if (filename && /^index\.[a-z\d]+$/.test(displayName)) {
|
|
230
|
+
// If the file name is 'index', better to get name from parent folder
|
|
231
|
+
displayName = basename(dirname(filename));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Remove the file extension
|
|
235
|
+
displayName = displayName.replace(/\.[a-z\d]+$/, '');
|
|
236
|
+
if (displayName) {
|
|
237
|
+
displayName += idx;
|
|
238
|
+
} else {
|
|
239
|
+
throw new Error("Couldn't determine a name for the component. Ensure that it's either:\n" + '- Assigned to a variable\n' + '- Is an object property\n' + '- Is a prop in a JSX element\n');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return displayName;
|
|
243
|
+
}
|
|
244
|
+
function isTagReferenced(path) {
|
|
245
|
+
// Check if the variable is referenced anywhere for basic DCE
|
|
246
|
+
// Only works when it's assigned to a variable
|
|
247
|
+
let isReferenced = true;
|
|
248
|
+
const parent = path.findParent(p => p.isObjectProperty() || p.isJSXOpeningElement() || p.isVariableDeclarator());
|
|
249
|
+
if (parent) {
|
|
250
|
+
if (parent.isVariableDeclarator()) {
|
|
251
|
+
const id = parent.get('id');
|
|
252
|
+
// FIXME: replace with id.isReferencedIdentifier()
|
|
253
|
+
if (id.isIdentifier()) {
|
|
254
|
+
const {
|
|
255
|
+
referencePaths
|
|
256
|
+
} = path.scope.getBinding(id.node.name) || {
|
|
257
|
+
referencePaths: []
|
|
258
|
+
};
|
|
259
|
+
isReferenced = referencePaths.length !== 0;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return isReferenced;
|
|
264
|
+
}
|
|
265
|
+
const counters = new WeakMap();
|
|
266
|
+
const getNextIndex = state => {
|
|
267
|
+
const counter = counters.get(state) ?? 0;
|
|
268
|
+
counters.set(state, counter + 1);
|
|
269
|
+
return counter;
|
|
270
|
+
};
|
|
271
|
+
export function getTagProcessor(path, fileContext, options) {
|
|
272
|
+
const cache = getTraversalCache(path, 'getTagProcessor');
|
|
273
|
+
if (!cache.has(path.node)) {
|
|
274
|
+
const root = path.scope.getProgramParent().path;
|
|
275
|
+
const {
|
|
276
|
+
imports
|
|
277
|
+
} = collectExportsAndImports(root);
|
|
278
|
+
try {
|
|
279
|
+
const builder = getBuilderForIdentifier(path, imports.filter(explicitImport), fileContext.filename, options);
|
|
280
|
+
if (builder) {
|
|
281
|
+
// Increment the index of the style we're processing
|
|
282
|
+
// This is used for slug generation to prevent collision
|
|
283
|
+
// Also used for display name if it couldn't be determined
|
|
284
|
+
const idx = getNextIndex(fileContext);
|
|
285
|
+
const displayName = getDisplayName(path, idx, fileContext.filename);
|
|
286
|
+
const processor = builder(displayName, isTagReferenced(path), idx, options, fileContext);
|
|
287
|
+
cache.set(path.node, processor);
|
|
288
|
+
} else {
|
|
289
|
+
cache.set(path.node, null);
|
|
290
|
+
}
|
|
291
|
+
} catch (e) {
|
|
292
|
+
if (e === BaseProcessor.SKIP) {
|
|
293
|
+
cache.set(path.node, null);
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
if (e instanceof Error) {
|
|
297
|
+
throw buildCodeFrameError(path, e.message);
|
|
298
|
+
}
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return cache.get(path.node) ?? null;
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=getTagProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTagProcessor.js","names":["readFileSync","basename","dirname","join","types","t","addDefault","addNamed","BaseProcessor","collectExportsAndImports","explicitImport","collectTemplateDependencies","extractExpression","findPackageJSON","getSource","isNotNull","mutate","getTraversalCache","last","arr","length","zip","arr1","arr2","result","i","push","buildCodeFrameError","path","message","Error","definedTagsCache","Map","getDefinedTagsFromPackage","pkgName","filename","has","get","packageJSONPath","undefined","packageDir","packageJSON","JSON","parse","definedTags","tags","normalizedTags","Object","entries","reduce","acc","key","value","startsWith","require","resolve","paths","set","isValidProcessorClass","module","constructor","getProcessorFromPackage","packageName","tagName","processorPath","Processor","default","getProcessorFromFile","getProcessorForIdentifier","imports","options","pathBinding","scope","getBinding","node","name","tagResolver","relatedImports","map","local","isIdentifier","isDescendant","binding","filter","isExpression","tagSource","tagPath","imported","source","p","customFile","processor","find","proc","getBuilderForIdentifier","params","prev","current","parentPath","isSequenceExpression","expressions","isCallExpression","callee","args","cookedArgs","arg","buildError","bind","type","extracted","evaluate","isMemberExpression","object","property","computed","isStringLiteral","isTaggedTemplateExpression","tag","quasis","expressionValues","replacer","replacement","isPure","replaceWith","addComment","astService","addDefaultImport","importedSource","nameHint","addNamedImport","loc","getDisplayName","idx","displayName","parent","findParent","isObjectProperty","isJSXOpeningElement","isVariableDeclarator","toString","keyPath","isJSXIdentifier","id","test","replace","isTagReferenced","isReferenced","referencePaths","counters","WeakMap","getNextIndex","state","counter","getTagProcessor","fileContext","cache","root","getProgramParent","builder","e","SKIP"],"sources":["../../src/utils/getTagProcessor.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { basename, dirname, join } from 'path';\n\nimport { types as t } from '@babel/core';\nimport { addDefault, addNamed } from '@babel/helper-module-imports';\nimport type { NodePath } from '@babel/traverse';\nimport type {\n Expression,\n SourceLocation,\n Identifier,\n MemberExpression,\n Program,\n} from '@babel/types';\n\nimport { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Param,\n Params,\n IFileContext,\n TagSource,\n} from '@wyw-in-js/processor-utils';\nimport type { ExpressionValue, StrictOptions } from '@wyw-in-js/shared';\n\nimport type { IImport } from './collectExportsAndImports';\nimport {\n collectExportsAndImports,\n explicitImport,\n} from './collectExportsAndImports';\nimport {\n collectTemplateDependencies,\n extractExpression,\n} from './collectTemplateDependencies';\nimport { findPackageJSON } from './findPackageJSON';\nimport { getSource } from './getSource';\nimport { isNotNull } from './isNotNull';\nimport { mutate } from './scopeHelpers';\nimport { getTraversalCache } from './traversalCache';\n\ntype BuilderArgs = ConstructorParameters<typeof BaseProcessor> extends [\n Params,\n TagSource,\n typeof t,\n SourceLocation | null,\n (replacement: Expression, isPure: boolean) => void,\n ...infer T,\n]\n ? T\n : never;\n\ntype Builder = (...args: BuilderArgs) => BaseProcessor;\n\ntype ProcessorClass = new (\n ...args: ConstructorParameters<typeof BaseProcessor>\n) => BaseProcessor;\n\nconst last = <T>(arr: T[]): T | undefined => arr[arr.length - 1];\n\nfunction zip<T1, T2>(arr1: T1[], arr2: T2[]) {\n const result: (T1 | T2)[] = [];\n for (let i = 0; i < arr1.length; i++) {\n result.push(arr1[i]);\n if (arr2[i]) result.push(arr2[i]);\n }\n\n return result;\n}\n\nfunction buildCodeFrameError(path: NodePath, message: string): Error {\n try {\n return path.buildCodeFrameError(message);\n } catch {\n return new Error(message);\n }\n}\n\nconst definedTagsCache = new Map<string, Record<string, string> | undefined>();\nconst getDefinedTagsFromPackage = (\n pkgName: string,\n filename: string | null | undefined\n): Record<string, string> | undefined => {\n if (definedTagsCache.has(pkgName)) {\n return definedTagsCache.get(pkgName);\n }\n\n const packageJSONPath = findPackageJSON(pkgName, filename);\n if (!packageJSONPath) {\n return undefined;\n }\n\n const packageDir = dirname(packageJSONPath);\n const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf8'));\n const definedTags: Record<string, string> | undefined =\n packageJSON['wyw-in-js']?.tags;\n\n const normalizedTags = definedTags\n ? Object.entries(definedTags).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: value.startsWith('.')\n ? join(packageDir, value)\n : require.resolve(value, { paths: [packageDir] }),\n }),\n {} as Record<string, string>\n )\n : undefined;\n\n definedTagsCache.set(pkgName, normalizedTags);\n\n return normalizedTags;\n};\n\nfunction isValidProcessorClass(module: unknown): module is ProcessorClass {\n return module instanceof BaseProcessor.constructor;\n}\n\nfunction getProcessorFromPackage(\n packageName: string,\n tagName: string,\n filename: string | null | undefined\n): ProcessorClass | null {\n const definedTags = getDefinedTagsFromPackage(packageName, filename);\n const processorPath = definedTags?.[tagName];\n if (!processorPath) {\n return null;\n }\n\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorFromFile(processorPath: string): ProcessorClass | null {\n const Processor = require(processorPath).default;\n if (!isValidProcessorClass(Processor)) {\n return null;\n }\n\n return Processor;\n}\n\nfunction getProcessorForIdentifier(\n path: NodePath<Identifier>,\n imports: IImport[],\n filename: string | null | undefined,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n):\n | [ProcessorClass, TagSource, NodePath<Identifier | MemberExpression>]\n | [null, null, null] {\n const pathBinding = path.scope.getBinding(path.node.name);\n if (!pathBinding) {\n // It's not a binding, so it's not a tag\n return [null, null, null];\n }\n\n const tagResolver = options.tagResolver ?? (() => null);\n\n // FIXME: can be simplified\n const relatedImports = imports\n .map(\n (i): [IImport, NodePath<Identifier | MemberExpression> | null] | null => {\n const { local } = i;\n\n if (local === path) {\n return [i, null];\n }\n\n if (!local.isIdentifier()) {\n if (path.isDescendant(local)) {\n return [i, local];\n }\n\n return null;\n }\n\n const binding = local.scope.getBinding(local.node.name);\n if (pathBinding === binding) {\n return [i, path];\n }\n\n return null;\n }\n )\n .filter(isNotNull)\n .filter((i) => i[1] === null || i[1].isExpression());\n\n if (relatedImports.length === 0) {\n return [null, null, null];\n }\n\n const [Processor = null, tagSource = null, tagPath = null] =\n relatedImports\n .map(\n ([{ imported, source }, p]): [\n ProcessorClass | null,\n TagSource,\n NodePath<Identifier | MemberExpression> | null,\n ] => {\n const customFile = tagResolver(source, imported);\n const processor = customFile\n ? getProcessorFromFile(customFile)\n : getProcessorFromPackage(source, imported, filename);\n return [processor, { imported, source }, p];\n }\n )\n .find(([proc]) => proc) ?? [];\n\n return Processor === null || tagSource === null || tagPath === null\n ? [null, null, null]\n : [Processor, tagSource, tagPath];\n}\n\nfunction getBuilderForIdentifier(\n path: NodePath<Identifier>,\n imports: IImport[],\n filename: string | null | undefined,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): Builder | null {\n const [Processor, tagSource, tagPath] = getProcessorForIdentifier(\n path,\n imports,\n filename,\n options\n );\n\n if (!Processor || !tagSource || !tagPath) {\n return null;\n }\n\n const params: Param[] = [['callee', tagPath.node]];\n let prev: NodePath = tagPath;\n let current: NodePath | null = tagPath.parentPath;\n while (current && current !== path) {\n if (\n current?.isSequenceExpression() &&\n last(current.node.expressions) === prev.node\n ) {\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isCallExpression({ callee: prev.node })) {\n const args = current.get('arguments');\n const cookedArgs = args\n .map((arg) => {\n const buildError = arg.buildCodeFrameError.bind(arg);\n if (!arg.isExpression()) {\n throw buildError(`Unexpected type of an argument ${arg.type}`);\n }\n const source = getSource(arg);\n const extracted = extractExpression(arg, options.evaluate, imports);\n return {\n ...extracted,\n source,\n buildCodeFrameError: buildError,\n } as ExpressionValue;\n })\n .filter(isNotNull);\n\n params.push(['call', ...cookedArgs]);\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isMemberExpression({ object: prev.node })) {\n const property = current.get('property');\n if (property.isIdentifier() && !current.node.computed) {\n params.push(['member', property.node.name]);\n } else if (property.isStringLiteral()) {\n params.push(['member', property.node.value]);\n } else {\n throw property.buildCodeFrameError(`Unexpected type of a property`);\n }\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (current?.isTaggedTemplateExpression({ tag: prev.node })) {\n const [quasis, expressionValues] = collectTemplateDependencies(\n current,\n options.evaluate\n );\n params.push(['template', zip(quasis, expressionValues)]);\n\n prev = current;\n current = current.parentPath;\n // eslint-disable-next-line no-continue\n continue;\n }\n\n break;\n }\n\n const replacer = (replacement: Expression, isPure: boolean) => {\n mutate(prev, (p) => {\n p.replaceWith(replacement);\n if (isPure) {\n p.addComment('leading', '#__PURE__');\n }\n });\n };\n\n const astService = {\n ...t,\n addDefaultImport: (importedSource: string, nameHint?: string) =>\n addDefault(path, importedSource, { nameHint }),\n addNamedImport: (\n name: string,\n importedSource: string,\n nameHint: string = name\n ) => addNamed(path, name, importedSource, { nameHint }),\n };\n\n return (...args: BuilderArgs) =>\n new Processor(\n params,\n tagSource,\n astService,\n tagPath.node.loc ?? null,\n replacer,\n ...args\n );\n}\n\nfunction getDisplayName(\n path: NodePath<Identifier>,\n idx: number,\n filename?: string | null\n): string {\n let displayName: string | undefined;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isObjectProperty()) {\n if ('name' in parent.node.key) {\n displayName = parent.node.key.name;\n } else if ('value' in parent.node.key) {\n displayName = parent.node.key.value.toString();\n } else {\n const keyPath = parent.get('key');\n displayName = getSource(keyPath);\n }\n } else if (parent.isJSXOpeningElement()) {\n const name = parent.get('name');\n if (name.isJSXIdentifier()) {\n displayName = name.node.name;\n }\n } else if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n if (id.isIdentifier()) {\n displayName = id.node.name;\n }\n }\n }\n\n if (!displayName) {\n // Try to derive the path from the filename\n displayName = basename(filename ?? 'unknown');\n\n if (filename && /^index\\.[a-z\\d]+$/.test(displayName)) {\n // If the file name is 'index', better to get name from parent folder\n displayName = basename(dirname(filename));\n }\n\n // Remove the file extension\n displayName = displayName.replace(/\\.[a-z\\d]+$/, '');\n\n if (displayName) {\n displayName += idx;\n } else {\n throw new Error(\n \"Couldn't determine a name for the component. Ensure that it's either:\\n\" +\n '- Assigned to a variable\\n' +\n '- Is an object property\\n' +\n '- Is a prop in a JSX element\\n'\n );\n }\n }\n\n return displayName;\n}\n\nfunction isTagReferenced(path: NodePath): boolean {\n // Check if the variable is referenced anywhere for basic DCE\n // Only works when it's assigned to a variable\n let isReferenced = true;\n\n const parent = path.findParent(\n (p) =>\n p.isObjectProperty() ||\n p.isJSXOpeningElement() ||\n p.isVariableDeclarator()\n );\n\n if (parent) {\n if (parent.isVariableDeclarator()) {\n const id = parent.get('id');\n // FIXME: replace with id.isReferencedIdentifier()\n if (id.isIdentifier()) {\n const { referencePaths } = path.scope.getBinding(id.node.name) || {\n referencePaths: [],\n };\n\n isReferenced = referencePaths.length !== 0;\n }\n }\n }\n\n return isReferenced;\n}\n\nconst counters = new WeakMap<IFileContext, number>();\nconst getNextIndex = (state: IFileContext) => {\n const counter = counters.get(state) ?? 0;\n counters.set(state, counter + 1);\n return counter;\n};\n\nexport function getTagProcessor(\n path: NodePath<Identifier>,\n fileContext: IFileContext,\n options: Pick<\n StrictOptions,\n 'classNameSlug' | 'displayName' | 'evaluate' | 'tagResolver'\n >\n): BaseProcessor | null {\n const cache = getTraversalCache<BaseProcessor | null, Identifier>(\n path,\n 'getTagProcessor'\n );\n\n if (!cache.has(path.node)) {\n const root = path.scope.getProgramParent().path as NodePath<Program>;\n const { imports } = collectExportsAndImports(root);\n try {\n const builder = getBuilderForIdentifier(\n path,\n imports.filter(explicitImport),\n fileContext.filename,\n options\n );\n if (builder) {\n // Increment the index of the style we're processing\n // This is used for slug generation to prevent collision\n // Also used for display name if it couldn't be determined\n const idx = getNextIndex(fileContext);\n\n const displayName = getDisplayName(path, idx, fileContext.filename);\n\n const processor = builder(\n displayName,\n isTagReferenced(path),\n idx,\n options,\n fileContext\n );\n\n cache.set(path.node, processor);\n } else {\n cache.set(path.node, null);\n }\n } catch (e) {\n if (e === BaseProcessor.SKIP) {\n cache.set(path.node, null);\n return null;\n }\n\n if (e instanceof Error) {\n throw buildCodeFrameError(path, e.message);\n }\n\n throw e;\n }\n }\n\n return cache.get(path.node) ?? null;\n}\n"],"mappings":"AAAA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,MAAM;AAE9C,SAASC,KAAK,IAAIC,CAAC,QAAQ,aAAa;AACxC,SAASC,UAAU,EAAEC,QAAQ,QAAQ,8BAA8B;AAUnE,SAASC,aAAa,QAAQ,4BAA4B;AAU1D,SACEC,wBAAwB,EACxBC,cAAc,QACT,4BAA4B;AACnC,SACEC,2BAA2B,EAC3BC,iBAAiB,QACZ,+BAA+B;AACtC,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,iBAAiB,QAAQ,kBAAkB;AAmBpD,MAAMC,IAAI,GAAOC,GAAQ,IAAoBA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC;AAEhE,SAASC,GAAGA,CAASC,IAAU,EAAEC,IAAU,EAAE;EAC3C,MAAMC,MAAmB,GAAG,EAAE;EAC9B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACF,MAAM,EAAEK,CAAC,EAAE,EAAE;IACpCD,MAAM,CAACE,IAAI,CAACJ,IAAI,CAACG,CAAC,CAAC,CAAC;IACpB,IAAIF,IAAI,CAACE,CAAC,CAAC,EAAED,MAAM,CAACE,IAAI,CAACH,IAAI,CAACE,CAAC,CAAC,CAAC;EACnC;EAEA,OAAOD,MAAM;AACf;AAEA,SAASG,mBAAmBA,CAACC,IAAc,EAAEC,OAAe,EAAS;EACnE,IAAI;IACF,OAAOD,IAAI,CAACD,mBAAmB,CAACE,OAAO,CAAC;EAC1C,CAAC,CAAC,M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wG,GAAG,EACH9D,OAAO,EACPoF,WACF,CAAC;QAEDC,KAAK,CAAClG,GAAG,CAAC7B,IAAI,CAAC8C,IAAI,EAAEiB,SAAS,CAAC;MACjC,CAAC,MAAM;QACLgE,KAAK,CAAClG,GAAG,CAAC7B,IAAI,CAAC8C,IAAI,EAAE,IAAI,CAAC;MAC5B;IACF,CAAC,CAAC,OAAOqF,CAAC,EAAE;MACV,IAAIA,CAAC,KAAKvJ,aAAa,CAACwJ,IAAI,EAAE;QAC5BL,KAAK,CAAClG,GAAG,CAAC7B,IAAI,CAAC8C,IAAI,EAAE,IAAI,CAAC;QAC1B,OAAO,IAAI;MACb;MAEA,IAAIqF,CAAC,YAAYjI,KAAK,EAAE;QACtB,MAAMH,mBAAmB,CAACC,IAAI,EAAEmI,CAAC,CAAClI,OAAO,CAAC;MAC5C;MAEA,MAAMkI,CAAC;IACT;EACF;EAEA,OAAOJ,KAAK,CAACtH,GAAG,CAACT,IAAI,CAAC8C,IAAI,CAAC,IAAI,IAAI;AACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVisitorKeys.js","names":["types","t","getVisitorKeys","node","VISITOR_KEYS","type"],"sources":["../../src/utils/getVisitorKeys.ts"],"sourcesContent":["import { types as t } from '@babel/core';\nimport type { Node } from '@babel/types';\n\nexport type VisitorKeys<T extends Node> = {\n [K in keyof T]: Exclude<T[K], undefined> extends Node | Node[] | null\n ? K\n : never;\n}[keyof T] &\n string;\n\nexport function getVisitorKeys<TNode extends Node>(\n node: TNode\n): VisitorKeys<TNode>[] {\n return t.VISITOR_KEYS[node.type] as VisitorKeys<TNode>[];\n}\n"],"mappings":"AAAA,SAASA,KAAK,IAAIC,CAAC,QAAQ,aAAa;AAUxC,OAAO,SAASC,cAAcA,CAC5BC,IAAW,EACW;EACtB,OAAOF,CAAC,CAACG,YAAY,CAACD,IAAI,CAACE,IAAI,CAAC;AAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasLinariaPreval.js","names":["hasLinariaPreval","exports"],"sources":["../../src/utils/hasLinariaPreval.ts"],"sourcesContent":["import type { Value } from '@wyw-in-js/processor-utils';\n\nexport default function hasLinariaPreval(exports: unknown): exports is {\n __linariaPreval: Record<string, () => Value> | null | undefined;\n} {\n if (!exports || typeof exports !== 'object') {\n return false;\n }\n\n return '__linariaPreval' in exports;\n}\n"],"mappings":"AAEA,eAAe,SAASA,gBAAgBA,CAACC,OAAgB,EAEvD;EACA,IAAI,CAACA,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC3C,OAAO,KAAK;EACd;EAEA,OAAO,iBAAiB,IAAIA,OAAO;AACrC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isGlobal } from './isGlobal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks that specified Identifier is a global `exports` or `module.exports`
|
|
5
|
+
* @param node
|
|
6
|
+
*/
|
|
7
|
+
export function isExports(node) {
|
|
8
|
+
if (node?.isIdentifier({
|
|
9
|
+
name: 'exports'
|
|
10
|
+
})) {
|
|
11
|
+
return isGlobal(node, 'exports');
|
|
12
|
+
}
|
|
13
|
+
if (node?.isMemberExpression() && node.get('object').isIdentifier({
|
|
14
|
+
name: 'module'
|
|
15
|
+
}) && node.get('property').isIdentifier({
|
|
16
|
+
name: 'exports'
|
|
17
|
+
})) {
|
|
18
|
+
return isGlobal(node, 'module');
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=isExports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isExports.js","names":["isGlobal","isExports","node","isIdentifier","name","isMemberExpression","get"],"sources":["../../src/utils/isExports.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\n\nimport { isGlobal } from './isGlobal';\n\n/**\n * Checks that specified Identifier is a global `exports` or `module.exports`\n * @param node\n */\nexport function isExports(node: NodePath | null | undefined) {\n if (node?.isIdentifier({ name: 'exports' })) {\n return isGlobal(node, 'exports');\n }\n\n if (\n node?.isMemberExpression() &&\n node.get('object').isIdentifier({ name: 'module' }) &&\n node.get('property').isIdentifier({ name: 'exports' })\n ) {\n return isGlobal(node, 'module');\n }\n\n return false;\n}\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,IAAiC,EAAE;EAC3D,IAAIA,IAAI,EAAEC,YAAY,CAAC;IAAEC,IAAI,EAAE;EAAU,CAAC,CAAC,EAAE;IAC3C,OAAOJ,QAAQ,CAACE,IAAI,EAAE,SAAS,CAAC;EAClC;EAEA,IACEA,IAAI,EAAEG,kBAAkB,CAAC,CAAC,IAC1BH,IAAI,CAACI,GAAG,CAAC,QAAQ,CAAC,CAACH,YAAY,CAAC;IAAEC,IAAI,EAAE;EAAS,CAAC,CAAC,IACnDF,IAAI,CAACI,GAAG,CAAC,UAAU,CAAC,CAACH,YAAY,CAAC;IAAEC,IAAI,EAAE;EAAU,CAAC,CAAC,EACtD;IACA,OAAOJ,QAAQ,CAACE,IAAI,EAAE,QAAQ,CAAC;EACjC;EAEA,OAAO,KAAK;AACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isGlobal.js","names":["getScope","isGlobal","node","name","scope","getBinding","undefined","hasGlobal"],"sources":["../../src/utils/isGlobal.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\n\nimport { getScope } from './getScope';\n\nexport const isGlobal = (node: NodePath, name: string) => {\n const scope = getScope(node);\n\n return scope.getBinding(name) === undefined && scope.hasGlobal(name);\n};\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,YAAY;AAErC,OAAO,MAAMC,QAAQ,GAAGA,CAACC,IAAc,EAAEC,IAAY,KAAK;EACxD,MAAMC,KAAK,GAAGJ,QAAQ,CAACE,IAAI,CAAC;EAE5B,OAAOE,KAAK,CAACC,UAAU,CAACF,IAAI,CAAC,KAAKG,SAAS,IAAIF,KAAK,CAACG,SAAS,CAACJ,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNode.js","names":["isNode","obj","type","undefined"],"sources":["../../src/utils/isNode.ts"],"sourcesContent":["import type { Node } from '@babel/types';\n\nexport const isNode = (obj: unknown): obj is Node =>\n typeof obj === 'object' &&\n obj !== null &&\n (obj as { type: unknown })?.type !== undefined;\n"],"mappings":"AAEA,OAAO,MAAMA,MAAM,GAAIC,GAAY,IACjC,OAAOA,GAAG,KAAK,QAAQ,IACvBA,GAAG,KAAK,IAAI,IACXA,GAAG,EAAwBC,IAAI,KAAKC,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNodePath.js","names":["isNodePath","obj","node","undefined"],"sources":["../../src/utils/isNodePath.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Node } from '@babel/types';\n\nexport function isNodePath<T extends Node>(\n obj: NodePath<T> | T\n): obj is NodePath<T> {\n return 'node' in obj && obj?.node !== undefined;\n}\n"],"mappings":"AAGA,OAAO,SAASA,UAAUA,CACxBC,GAAoB,EACA;EACpB,OAAO,MAAM,IAAIA,GAAG,IAAIA,GAAG,EAAEC,IAAI,KAAKC,SAAS;AACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNotNull.js","names":["isNotNull","x"],"sources":["../../src/utils/isNotNull.ts"],"sourcesContent":["export function isNotNull<T>(x: T | null): x is T {\n return x !== null;\n}\n"],"mappings":"AAAA,OAAO,SAASA,SAASA,CAAIC,CAAW,EAAU;EAChD,OAAOA,CAAC,KAAK,IAAI;AACnB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given path has been removed from the AST.
|
|
3
|
+
*/
|
|
4
|
+
export function isRemoved(path) {
|
|
5
|
+
// Check if the input path has already been removed
|
|
6
|
+
if (path.removed) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Check if any of the parent paths have been removed
|
|
11
|
+
let currentPath = path;
|
|
12
|
+
while (currentPath) {
|
|
13
|
+
const parent = currentPath.parentPath;
|
|
14
|
+
if (parent) {
|
|
15
|
+
// If the parent path has been removed, return true
|
|
16
|
+
if (parent.removed || parent.node === null) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
listKey,
|
|
21
|
+
key,
|
|
22
|
+
node
|
|
23
|
+
} = currentPath;
|
|
24
|
+
if (listKey) {
|
|
25
|
+
// If the current path is part of a list and the current node
|
|
26
|
+
// is not presented in this list, return true
|
|
27
|
+
const found = parent.get(listKey).find(p => p.node === node);
|
|
28
|
+
if (!found) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// If the current path is not part of a list and its node is not the same
|
|
33
|
+
// as the node in the parent object at the same key, return true
|
|
34
|
+
else if (parent.get(key).node !== node) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Set the current path to its parent path and continue the loop
|
|
40
|
+
currentPath = parent;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// If the function has not returned true by this point, return false
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=isRemoved.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isRemoved.js","names":["isRemoved","path","removed","currentPath","parent","parentPath","node","listKey","key","found","get","find","p"],"sources":["../../src/utils/isRemoved.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\n\n/**\n * Checks if a given path has been removed from the AST.\n */\nexport function isRemoved(path: NodePath): boolean {\n // Check if the input path has already been removed\n if (path.removed) {\n return true;\n }\n\n // Check if any of the parent paths have been removed\n let currentPath: NodePath | null = path;\n while (currentPath) {\n const parent: NodePath | null = currentPath.parentPath;\n\n if (parent) {\n // If the parent path has been removed, return true\n if (parent.removed || parent.node === null) {\n return true;\n }\n\n const { listKey, key, node } = currentPath;\n if (listKey) {\n // If the current path is part of a list and the current node\n // is not presented in this list, return true\n const found = parent.get(listKey).find((p) => p.node === node);\n if (!found) {\n return true;\n }\n }\n // If the current path is not part of a list and its node is not the same\n // as the node in the parent object at the same key, return true\n else if ((parent.get(key as string) as NodePath).node !== node) {\n return true;\n }\n }\n\n // Set the current path to its parent path and continue the loop\n currentPath = parent;\n }\n\n // If the function has not returned true by this point, return false\n return false;\n}\n"],"mappings":"AAEA;AACA;AACA;AACA,OAAO,SAASA,SAASA,CAACC,IAAc,EAAW;EACjD;EACA,IAAIA,IAAI,CAACC,OAAO,EAAE;IAChB,OAAO,IAAI;EACb;;EAEA;EACA,IAAIC,WAA4B,GAAGF,IAAI;EACvC,OAAOE,WAAW,EAAE;IAClB,MAAMC,MAAuB,GAAGD,WAAW,CAACE,UAAU;IAEtD,IAAID,MAAM,EAAE;MACV;MACA,IAAIA,MAAM,CAACF,OAAO,IAAIE,MAAM,CAACE,IAAI,KAAK,IAAI,EAAE;QAC1C,OAAO,IAAI;MACb;MAEA,MAAM;QAAEC,OAAO;QAAEC,GAAG;QAAEF;MAAK,CAAC,GAAGH,WAAW;MAC1C,IAAII,OAAO,EAAE;QACX;QACA;QACA,MAAME,KAAK,GAAGL,MAAM,CAACM,GAAG,CAACH,OAAO,CAAC,CAACI,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACN,IAAI,KAAKA,IAAI,CAAC;QAC9D,IAAI,CAACG,KAAK,EAAE;UACV,OAAO,IAAI;QACb;MACF;MACA;MACA;MAAA,KACK,IAAKL,MAAM,CAACM,GAAG,CAACF,GAAa,CAAC,CAAcF,IAAI,KAAKA,IAAI,EAAE;QAC9D,OAAO,IAAI;MACb;IACF;;IAEA;IACAH,WAAW,GAAGC,MAAM;EACtB;;EAEA;EACA,OAAO,KAAK;AACd"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isGlobal } from './isGlobal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks that specified Identifier is a global `require`
|
|
5
|
+
* @param id
|
|
6
|
+
*/
|
|
7
|
+
export function isRequire(id) {
|
|
8
|
+
if (!id?.isIdentifier() || id.node.name !== 'require') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return isGlobal(id, 'require');
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=isRequire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isRequire.js","names":["isGlobal","isRequire","id","isIdentifier","node","name"],"sources":["../../src/utils/isRequire.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\n\nimport { isGlobal } from './isGlobal';\n\n/**\n * Checks that specified Identifier is a global `require`\n * @param id\n */\nexport function isRequire(id: NodePath | null | undefined) {\n if (!id?.isIdentifier() || id.node.name !== 'require') {\n return false;\n }\n\n return isGlobal(id, 'require');\n}\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,YAAY;;AAErC;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,EAA+B,EAAE;EACzD,IAAI,CAACA,EAAE,EAAEC,YAAY,CAAC,CAAC,IAAID,EAAE,CAACE,IAAI,CAACC,IAAI,KAAK,SAAS,EAAE;IACrD,OAAO,KAAK;EACd;EAEA,OAAOL,QAAQ,CAACE,EAAE,EAAE,SAAS,CAAC;AAChC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isBoxedPrimitive } from '@wyw-in-js/shared';
|
|
2
|
+
export function isSerializable(o) {
|
|
3
|
+
if (Array.isArray(o)) {
|
|
4
|
+
return o.every(isSerializable);
|
|
5
|
+
}
|
|
6
|
+
if (o === null) return true;
|
|
7
|
+
if (isBoxedPrimitive(o)) return true;
|
|
8
|
+
if (typeof o === 'object') {
|
|
9
|
+
return Object.values(o).every(isSerializable);
|
|
10
|
+
}
|
|
11
|
+
return typeof o === 'string' || typeof o === 'number' || typeof o === 'boolean';
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=isSerializable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSerializable.js","names":["isBoxedPrimitive","isSerializable","o","Array","isArray","every","Object","values"],"sources":["../../src/utils/isSerializable.ts"],"sourcesContent":["import { isBoxedPrimitive } from '@wyw-in-js/shared';\n\nimport type { Serializable } from '../types';\n\nexport function isSerializable(o: unknown): o is Serializable {\n if (Array.isArray(o)) {\n return o.every(isSerializable);\n }\n\n if (o === null) return true;\n\n if (isBoxedPrimitive(o)) return true;\n\n if (typeof o === 'object') {\n return Object.values(o).every(isSerializable);\n }\n\n return (\n typeof o === 'string' || typeof o === 'number' || typeof o === 'boolean'\n );\n}\n"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,mBAAmB;AAIpD,OAAO,SAASC,cAAcA,CAACC,CAAU,EAAqB;EAC5D,IAAIC,KAAK,CAACC,OAAO,CAACF,CAAC,CAAC,EAAE;IACpB,OAAOA,CAAC,CAACG,KAAK,CAACJ,cAAc,CAAC;EAChC;EAEA,IAAIC,CAAC,KAAK,IAAI,EAAE,OAAO,IAAI;EAE3B,IAAIF,gBAAgB,CAACE,CAAC,CAAC,EAAE,OAAO,IAAI;EAEpC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;IACzB,OAAOI,MAAM,CAACC,MAAM,CAACL,CAAC,CAAC,CAACG,KAAK,CAACJ,cAAc,CAAC;EAC/C;EAEA,OACE,OAAOC,CAAC,KAAK,QAAQ,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,OAAOA,CAAC,KAAK,SAAS;AAE5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isTypedNode.js","names":["isTypedNode","type","p"],"sources":["../../src/utils/isTypedNode.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Node } from '@babel/types';\n\nexport const isTypedNode: <T extends NodePath['type']>(\n type: T\n) => (p: NodePath) => p is NodePath<\n Extract<\n Node,\n {\n type: T;\n }\n >\n> = <T extends NodePath['type']>(type: T) => {\n return (p: NodePath): p is NodePath<Extract<Node, { type: T }>> => {\n return p.type === type;\n };\n};\n"],"mappings":"AAGA,OAAO,MAAMA,WASZ,GAAgCC,IAAO,IAAK;EAC3C,OAAQC,CAAW,IAAgD;IACjE,OAAOA,CAAC,CAACD,IAAI,KAAKA,IAAI;EACxB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { collectExportsAndImports } from './collectExportsAndImports';
|
|
2
|
+
import { getScope } from './getScope';
|
|
3
|
+
function getCallee(p) {
|
|
4
|
+
const callee = p.get('callee');
|
|
5
|
+
if (callee.isSequenceExpression()) {
|
|
6
|
+
const expressions = callee.get('expressions');
|
|
7
|
+
if (expressions.length === 2 && expressions[0].isNumericLiteral({
|
|
8
|
+
value: 0
|
|
9
|
+
})) {
|
|
10
|
+
return expressions[1];
|
|
11
|
+
}
|
|
12
|
+
return callee;
|
|
13
|
+
}
|
|
14
|
+
return callee;
|
|
15
|
+
}
|
|
16
|
+
const JSXRuntimeSource = 'react/jsx-runtime';
|
|
17
|
+
function isJSXRuntime(p, imports) {
|
|
18
|
+
const jsxRuntime = imports.find(i => i.source === JSXRuntimeSource);
|
|
19
|
+
const jsxRuntimeName = jsxRuntime?.local?.isIdentifier() && jsxRuntime?.local?.node?.name;
|
|
20
|
+
if (jsxRuntime) {
|
|
21
|
+
const callee = getCallee(p);
|
|
22
|
+
if (jsxRuntimeName && callee.isIdentifier({
|
|
23
|
+
name: jsxRuntimeName
|
|
24
|
+
})) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (callee.isMemberExpression() && imports.find(i => i.source === JSXRuntimeSource && i.local === callee)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
function isHookOrCreateElement(name) {
|
|
34
|
+
return name === 'createElement' || /use[A-Z]/.test(name);
|
|
35
|
+
}
|
|
36
|
+
function isClassicReactRuntime(p, imports) {
|
|
37
|
+
const reactImports = imports.filter(i => i.source === 'react' && (i.imported === 'default' || i.imported && isHookOrCreateElement(i.imported)));
|
|
38
|
+
if (reactImports.length === 0) return false;
|
|
39
|
+
const callee = getCallee(p);
|
|
40
|
+
if (callee.isIdentifier() && isHookOrCreateElement(callee.node.name)) {
|
|
41
|
+
const bindingPath = getScope(callee).getBinding(callee.node.name)?.path;
|
|
42
|
+
return reactImports.some(i => bindingPath?.isAncestor(i.local));
|
|
43
|
+
}
|
|
44
|
+
if (callee.isMemberExpression()) {
|
|
45
|
+
if (reactImports.some(i => i.local === callee)) {
|
|
46
|
+
// It's React.createElement in CJS
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
const object = callee.get('object');
|
|
50
|
+
const property = callee.get('property');
|
|
51
|
+
const defaultImport = reactImports.find(i => i.imported === 'default');
|
|
52
|
+
if (!defaultImport || !defaultImport.local.isIdentifier() || !property.isIdentifier() || !isHookOrCreateElement(property.node.name) || !object.isIdentifier({
|
|
53
|
+
name: defaultImport.local.node.name
|
|
54
|
+
})) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const bindingPath = getScope(object).getBinding(object.node.name)?.path;
|
|
58
|
+
return bindingPath?.isAncestor(defaultImport.local) ?? false;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
export function isUnnecessaryReactCall(path) {
|
|
63
|
+
const programPath = path.findParent(p => p.isProgram());
|
|
64
|
+
if (!programPath) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const {
|
|
68
|
+
imports
|
|
69
|
+
} = collectExportsAndImports(programPath);
|
|
70
|
+
return isJSXRuntime(path, imports) || isClassicReactRuntime(path, imports);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=isUnnecessaryReactCall.js.map
|