@wyw-in-js/transform 1.1.0 → 2.0.0-alpha.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/esm/cache.js +426 -289
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js +137 -134
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/eval/broker.js +2134 -0
- package/esm/eval/broker.js.map +1 -0
- package/esm/eval/lru.js +36 -0
- package/esm/eval/lru.js.map +1 -0
- package/esm/eval/prepareModuleOnDemand.js +21 -0
- package/esm/eval/prepareModuleOnDemand.js.map +1 -0
- package/esm/eval/protocol.js +2 -0
- package/esm/eval/protocol.js.map +1 -0
- package/esm/eval/resolverStrategy.js +51 -0
- package/esm/eval/resolverStrategy.js.map +1 -0
- package/esm/eval/runner.js +1759 -0
- package/esm/eval/runner.js.map +1 -0
- package/esm/eval/serialize.js +333 -0
- package/esm/eval/serialize.js.map +1 -0
- package/esm/eval/writeQueue.js +81 -0
- package/esm/eval/writeQueue.js.map +1 -0
- package/esm/evaluators/index.js +11 -12
- package/esm/evaluators/index.js.map +1 -1
- package/esm/index.js +25 -29
- package/esm/index.js.map +1 -1
- package/esm/module.js +896 -520
- package/esm/module.js.map +1 -1
- package/esm/shaker.js +14 -80
- package/esm/shaker.js.map +1 -1
- package/esm/transform/BaseEntrypoint.js +162 -164
- package/esm/transform/BaseEntrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +96 -253
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +336 -270
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.types.js +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.js +10 -4
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
- package/esm/transform/actions/AbortError.js +6 -6
- package/esm/transform/actions/AbortError.js.map +1 -1
- package/esm/transform/actions/BaseAction.js +140 -136
- package/esm/transform/actions/BaseAction.js.map +1 -1
- package/esm/transform/actions/UnprocessedEntrypointError.js +6 -6
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
- package/esm/transform/actions/actionRunner.js +63 -66
- package/esm/transform/actions/actionRunner.js.map +1 -1
- package/esm/transform/actions/types.js +1 -1
- package/esm/transform/actions/types.js.map +1 -1
- package/esm/transform/barrelManifest.types.js +2 -0
- package/esm/transform/barrelManifest.types.js.map +1 -0
- package/esm/transform/generators/baseProcessingHandlers.js +15 -17
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
- package/esm/transform/generators/collect.js +27 -55
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +353 -321
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/transform/generators/evalFile.js +48 -47
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/extract.js +78 -90
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/getExports.js +57 -74
- package/esm/transform/generators/getExports.js.map +1 -1
- package/esm/transform/generators/index.js +11 -11
- package/esm/transform/generators/index.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +78 -67
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/processImports.js +102 -67
- package/esm/transform/generators/processImports.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +165 -196
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/resolveStaticOxcValues.js +2911 -0
- package/esm/transform/generators/resolveStaticOxcValues.js.map +1 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js +822 -0
- package/esm/transform/generators/rewriteOxcBarrelImports.js.map +1 -0
- package/esm/transform/generators/transform.js +239 -248
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js +87 -90
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +154 -74
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform/helpers/withDefaultServices.js +13 -22
- package/esm/transform/helpers/withDefaultServices.js.map +1 -1
- package/esm/transform/isStaticallyEvaluatableModule.js +140 -152
- package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -1
- package/esm/transform/oxcBarrelManifest.js +349 -0
- package/esm/transform/oxcBarrelManifest.js.map +1 -0
- package/esm/transform/rootLog.js +3 -3
- package/esm/transform/rootLog.js.map +1 -1
- package/esm/transform/syntax.js +2 -0
- package/esm/transform/syntax.js.map +1 -0
- package/esm/transform/types.js +2 -2
- package/esm/transform/types.js.map +1 -1
- package/esm/transform.js +123 -147
- package/esm/transform.js.map +1 -1
- package/esm/types.js +4 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/EventEmitter.js +46 -48
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/ShakerMetadata.js +2 -2
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/TransformDiagnostics.js +9 -9
- package/esm/utils/TransformDiagnostics.js.map +1 -1
- package/esm/utils/TransformMetadata.js +24 -26
- package/esm/utils/TransformMetadata.js.map +1 -1
- package/esm/utils/applyOxcProcessors.js +1217 -0
- package/esm/utils/applyOxcProcessors.js.map +1 -0
- package/esm/utils/collectOxcExportsAndImports.js +934 -0
- package/esm/utils/collectOxcExportsAndImports.js.map +1 -0
- package/esm/utils/collectOxcRuntime.js +220 -0
- package/esm/utils/collectOxcRuntime.js.map +1 -0
- package/esm/utils/collectOxcTemplateDependencies.js +1398 -0
- package/esm/utils/collectOxcTemplateDependencies.js.map +1 -0
- package/esm/utils/dispose-polyfill.js +3 -4
- package/esm/utils/dispose-polyfill.js.map +1 -1
- package/esm/utils/getFileIdx.js +6 -6
- package/esm/utils/getFileIdx.js.map +1 -1
- package/esm/utils/getPluginKey.js +12 -12
- package/esm/utils/getPluginKey.js.map +1 -1
- package/esm/utils/getVisitorKeys.js +9 -3
- package/esm/utils/getVisitorKeys.js.map +1 -1
- package/esm/utils/hasCachedWywPrevalExport.js +23 -0
- package/esm/utils/hasCachedWywPrevalExport.js.map +1 -0
- package/esm/utils/hasWywPreval.js +5 -5
- package/esm/utils/hasWywPreval.js.map +1 -1
- package/esm/utils/importOverrides.js +75 -90
- package/esm/utils/importOverrides.js.map +1 -1
- package/esm/utils/isNode.js +2 -2
- package/esm/utils/isNode.js.map +1 -1
- package/esm/utils/isNotNull.js +2 -2
- package/esm/utils/isNotNull.js.map +1 -1
- package/esm/utils/isSerializable.js +11 -11
- package/esm/utils/isSerializable.js.map +1 -1
- package/esm/utils/oxcAstService.js +121 -0
- package/esm/utils/oxcAstService.js.map +1 -0
- package/esm/utils/oxcEmit.js +447 -0
- package/esm/utils/oxcEmit.js.map +1 -0
- package/esm/utils/oxcPreevalStage.js +97 -0
- package/esm/utils/oxcPreevalStage.js.map +1 -0
- package/esm/utils/oxcPreevalTransforms.js +1054 -0
- package/esm/utils/oxcPreevalTransforms.js.map +1 -0
- package/esm/utils/oxcShaker.js +662 -0
- package/esm/utils/oxcShaker.js.map +1 -0
- package/esm/utils/parseOxc.js +37 -0
- package/esm/utils/parseOxc.js.map +1 -0
- package/esm/utils/parseRequest.js +27 -27
- package/esm/utils/parseRequest.js.map +1 -1
- package/esm/utils/peek.js +1 -1
- package/esm/utils/peek.js.map +1 -1
- package/esm/utils/processorLookup.js +125 -0
- package/esm/utils/processorLookup.js.map +1 -0
- package/esm/utils/resolveWithConditions.js +99 -0
- package/esm/utils/resolveWithConditions.js.map +1 -0
- package/esm/vm/createVmContext.js +140 -141
- package/esm/vm/createVmContext.js.map +1 -1
- package/esm/vm/process.js +11 -13
- package/esm/vm/process.js.map +1 -1
- package/package.json +18 -26
- package/types/cache.d.ts +17 -8
- package/types/cache.js +237 -95
- package/types/debug/fileReporter.js +22 -22
- package/types/eval/broker.d.ts +88 -0
- package/types/eval/broker.js +2262 -0
- package/types/eval/lru.d.ts +10 -0
- package/types/eval/lru.js +36 -0
- package/types/eval/prepareModuleOnDemand.d.ts +7 -0
- package/types/eval/prepareModuleOnDemand.js +24 -0
- package/types/eval/protocol.d.ts +97 -0
- package/types/eval/protocol.js +1 -0
- package/types/eval/resolverStrategy.d.ts +13 -0
- package/types/eval/resolverStrategy.js +46 -0
- package/types/eval/serialize.d.ts +78 -0
- package/types/eval/serialize.js +357 -0
- package/types/eval/writeQueue.d.ts +13 -0
- package/types/eval/writeQueue.js +80 -0
- package/types/evaluators/index.d.ts +2 -2
- package/types/evaluators/index.js +6 -9
- package/types/index.d.ts +3 -6
- package/types/index.js +24 -82
- package/types/module.d.ts +35 -7
- package/types/module.js +535 -163
- package/types/shaker.d.ts +2 -10
- package/types/shaker.js +10 -100
- package/types/transform/BaseEntrypoint.js +6 -11
- package/types/transform/Entrypoint.d.ts +15 -15
- package/types/transform/Entrypoint.helpers.d.ts +2 -5
- package/types/transform/Entrypoint.helpers.js +43 -203
- package/types/transform/Entrypoint.js +130 -53
- package/types/transform/Entrypoint.types.d.ts +28 -6
- package/types/transform/Entrypoint.types.js +1 -2
- package/types/transform/EvaluatedEntrypoint.d.ts +13 -2
- package/types/transform/EvaluatedEntrypoint.js +7 -6
- package/types/transform/actions/AbortError.js +2 -7
- package/types/transform/actions/BaseAction.js +4 -8
- package/types/transform/actions/UnprocessedEntrypointError.js +2 -7
- package/types/transform/actions/actionRunner.js +8 -12
- package/types/transform/actions/types.d.ts +2 -2
- package/types/transform/actions/types.js +1 -2
- package/types/transform/{barrelManifest.d.ts → barrelManifest.types.d.ts} +0 -2
- package/types/transform/barrelManifest.types.js +1 -0
- package/types/transform/generators/baseProcessingHandlers.d.ts +4 -5
- package/types/transform/generators/baseProcessingHandlers.js +10 -14
- package/types/transform/generators/collect.js +13 -39
- package/types/transform/generators/createStylisPreprocessor.js +19 -60
- package/types/transform/generators/evalFile.d.ts +2 -2
- package/types/transform/generators/evalFile.js +26 -28
- package/types/transform/generators/extract.js +5 -8
- package/types/transform/generators/getExports.js +23 -30
- package/types/transform/generators/index.d.ts +2 -2
- package/types/transform/generators/index.js +11 -14
- package/types/transform/generators/processEntrypoint.d.ts +2 -2
- package/types/transform/generators/processEntrypoint.js +60 -26
- package/types/transform/generators/processImports.d.ts +0 -3
- package/types/transform/generators/processImports.js +60 -20
- package/types/transform/generators/resolveImports.js +18 -22
- package/types/transform/generators/resolveStaticOxcValues.d.ts +2 -0
- package/types/transform/generators/resolveStaticOxcValues.js +3235 -0
- package/types/transform/generators/{rewriteBarrelImports.d.ts → rewriteOxcBarrelImports.d.ts} +2 -3
- package/types/transform/generators/{rewriteBarrelImports.js → rewriteOxcBarrelImports.js} +282 -225
- package/types/transform/generators/transform.d.ts +3 -7
- package/types/transform/generators/transform.js +203 -199
- package/types/transform/generators/workflow.js +62 -45
- package/types/transform/helpers/loadWywOptions.js +94 -20
- package/types/transform/helpers/withDefaultServices.d.ts +1 -1
- package/types/transform/helpers/withDefaultServices.js +6 -44
- package/types/transform/isStaticallyEvaluatableModule.d.ts +1 -2
- package/types/transform/isStaticallyEvaluatableModule.js +125 -126
- package/types/transform/oxcBarrelManifest.d.ts +2 -0
- package/types/transform/{barrelManifest.js → oxcBarrelManifest.js} +156 -97
- package/types/transform/rootLog.js +2 -5
- package/types/transform/syntax.d.ts +38 -0
- package/types/transform/syntax.js +1 -0
- package/types/transform/types.d.ts +9 -6
- package/types/transform/types.js +1 -4
- package/types/transform.d.ts +2 -2
- package/types/transform.js +88 -101
- package/types/types.d.ts +0 -23
- package/types/types.js +1 -2
- package/types/utils/EventEmitter.js +3 -9
- package/types/utils/ShakerMetadata.js +1 -5
- package/types/utils/TransformDiagnostics.js +3 -7
- package/types/utils/TransformMetadata.js +8 -16
- package/types/utils/applyOxcProcessors.d.ts +16 -0
- package/types/utils/applyOxcProcessors.js +1391 -0
- package/types/utils/collectOxcExportsAndImports.d.ts +35 -0
- package/types/utils/collectOxcExportsAndImports.js +957 -0
- package/types/utils/collectOxcRuntime.d.ts +14 -0
- package/types/utils/collectOxcRuntime.js +250 -0
- package/types/utils/collectOxcTemplateDependencies.d.ts +38 -0
- package/types/utils/collectOxcTemplateDependencies.js +1580 -0
- package/types/utils/getFileIdx.js +1 -4
- package/types/utils/getPluginKey.d.ts +5 -2
- package/types/utils/getPluginKey.js +2 -6
- package/types/utils/getVisitorKeys.d.ts +4 -4
- package/types/utils/getVisitorKeys.js +9 -6
- package/types/utils/hasCachedWywPrevalExport.d.ts +14 -0
- package/types/utils/hasCachedWywPrevalExport.js +30 -0
- package/types/utils/hasWywPreval.js +1 -4
- package/types/utils/importOverrides.js +17 -27
- package/types/utils/isNode.d.ts +2 -2
- package/types/utils/isNode.js +2 -6
- package/types/utils/isNotNull.js +1 -4
- package/types/utils/isSerializable.js +3 -6
- package/types/utils/oxcAstService.d.ts +11 -0
- package/types/utils/oxcAstService.js +79 -0
- package/types/utils/oxcEmit.d.ts +19 -0
- package/types/utils/oxcEmit.js +506 -0
- package/types/utils/oxcPreevalStage.d.ts +20 -0
- package/types/utils/oxcPreevalStage.js +102 -0
- package/types/utils/oxcPreevalTransforms.d.ts +13 -0
- package/types/utils/oxcPreevalTransforms.js +1179 -0
- package/types/utils/oxcShaker.d.ts +13 -0
- package/types/utils/oxcShaker.js +751 -0
- package/types/utils/parseOxc.d.ts +11 -0
- package/types/utils/parseOxc.js +38 -0
- package/types/utils/parseRequest.js +2 -7
- package/types/utils/peek.js +1 -5
- package/types/utils/processorLookup.d.ts +8 -0
- package/types/utils/processorLookup.js +135 -0
- package/types/utils/resolveWithConditions.d.ts +12 -0
- package/types/utils/resolveWithConditions.js +103 -0
- package/types/vm/createVmContext.d.ts +2 -2
- package/types/vm/createVmContext.js +25 -62
- package/types/vm/process.js +20 -26
- package/esm/babel.js +0 -2
- package/esm/babel.js.map +0 -1
- package/esm/options/buildOptions.js +0 -168
- package/esm/options/buildOptions.js.map +0 -1
- package/esm/options/buildOptions.test.js +0 -138
- package/esm/options/buildOptions.test.js.map +0 -1
- package/esm/options/loadBabelOptions.js +0 -24
- package/esm/options/loadBabelOptions.js.map +0 -1
- package/esm/plugins/babel-transform.js +0 -53
- package/esm/plugins/babel-transform.js.map +0 -1
- package/esm/plugins/collector.js +0 -60
- package/esm/plugins/collector.js.map +0 -1
- package/esm/plugins/dynamic-import.js +0 -56
- package/esm/plugins/dynamic-import.js.map +0 -1
- package/esm/plugins/preeval.js +0 -73
- package/esm/plugins/preeval.js.map +0 -1
- package/esm/plugins/shaker.js +0 -680
- package/esm/plugins/shaker.js.map +0 -1
- package/esm/transform/barrelManifest.js +0 -291
- package/esm/transform/barrelManifest.js.map +0 -1
- package/esm/transform/generators/explodeReexports.js +0 -64
- package/esm/transform/generators/explodeReexports.js.map +0 -1
- package/esm/transform/generators/rewriteBarrelImports.js +0 -733
- package/esm/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/esm/utils/addIdentifierToWywPreval.js +0 -68
- package/esm/utils/addIdentifierToWywPreval.js.map +0 -1
- package/esm/utils/collectExportsAndImports.js +0 -1157
- package/esm/utils/collectExportsAndImports.js.map +0 -1
- package/esm/utils/collectTemplateDependencies.js +0 -228
- package/esm/utils/collectTemplateDependencies.js.map +0 -1
- package/esm/utils/createId.js +0 -6
- package/esm/utils/createId.js.map +0 -1
- package/esm/utils/findIdentifiers.js +0 -62
- package/esm/utils/findIdentifiers.js.map +0 -1
- package/esm/utils/getConstantStringValue.js +0 -58
- package/esm/utils/getConstantStringValue.js.map +0 -1
- package/esm/utils/getMemberExpressionPropertyName.js +0 -11
- package/esm/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/esm/utils/getScope.js +0 -6
- package/esm/utils/getScope.js.map +0 -1
- package/esm/utils/getSource.js +0 -15
- package/esm/utils/getSource.js.map +0 -1
- package/esm/utils/getTagProcessor.js +0 -404
- package/esm/utils/getTagProcessor.js.map +0 -1
- package/esm/utils/isExports.js +0 -22
- package/esm/utils/isExports.js.map +0 -1
- package/esm/utils/isGlobal.js +0 -6
- package/esm/utils/isGlobal.js.map +0 -1
- package/esm/utils/isNodePath.js +0 -4
- package/esm/utils/isNodePath.js.map +0 -1
- package/esm/utils/isRemoved.js +0 -46
- package/esm/utils/isRemoved.js.map +0 -1
- package/esm/utils/isRequire.js +0 -13
- package/esm/utils/isRequire.js.map +0 -1
- package/esm/utils/isTypedNode.js +0 -6
- package/esm/utils/isTypedNode.js.map +0 -1
- package/esm/utils/isUnnecessaryReactCall.js +0 -72
- package/esm/utils/isUnnecessaryReactCall.js.map +0 -1
- package/esm/utils/removeDangerousCode.js +0 -276
- package/esm/utils/removeDangerousCode.js.map +0 -1
- package/esm/utils/replaceImportMetaEnv.js +0 -44
- package/esm/utils/replaceImportMetaEnv.js.map +0 -1
- package/esm/utils/scopeHelpers.js +0 -527
- package/esm/utils/scopeHelpers.js.map +0 -1
- package/esm/utils/traversalCache.js +0 -23
- package/esm/utils/traversalCache.js.map +0 -1
- package/esm/utils/unwrapExpression.js +0 -18
- package/esm/utils/unwrapExpression.js.map +0 -1
- package/esm/utils/unwrapSequence.js +0 -14
- package/esm/utils/unwrapSequence.js.map +0 -1
- package/esm/utils/valueToLiteral.js +0 -59
- package/esm/utils/valueToLiteral.js.map +0 -1
- package/esm/utils/visitors/JSXElementsRemover.js +0 -51
- package/esm/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/babel.js +0 -2
- package/lib/babel.js.map +0 -1
- package/lib/cache.js +0 -308
- package/lib/cache.js.map +0 -1
- package/lib/debug/fileReporter.js +0 -153
- package/lib/debug/fileReporter.js.map +0 -1
- package/lib/evaluators/index.js +0 -20
- package/lib/evaluators/index.js.map +0 -1
- package/lib/index.js +0 -286
- package/lib/index.js.map +0 -1
- package/lib/module.js +0 -552
- package/lib/module.js.map +0 -1
- package/lib/options/buildOptions.js +0 -176
- package/lib/options/buildOptions.js.map +0 -1
- package/lib/options/buildOptions.test.js +0 -141
- package/lib/options/buildOptions.test.js.map +0 -1
- package/lib/options/loadBabelOptions.js +0 -31
- package/lib/options/loadBabelOptions.js.map +0 -1
- package/lib/plugins/babel-transform.js +0 -60
- package/lib/plugins/babel-transform.js.map +0 -1
- package/lib/plugins/collector.js +0 -70
- package/lib/plugins/collector.js.map +0 -1
- package/lib/plugins/dynamic-import.js +0 -61
- package/lib/plugins/dynamic-import.js.map +0 -1
- package/lib/plugins/preeval.js +0 -81
- package/lib/plugins/preeval.js.map +0 -1
- package/lib/plugins/shaker.js +0 -691
- package/lib/plugins/shaker.js.map +0 -1
- package/lib/shaker.js +0 -95
- package/lib/shaker.js.map +0 -1
- package/lib/transform/BaseEntrypoint.js +0 -179
- package/lib/transform/BaseEntrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.helpers.js +0 -279
- package/lib/transform/Entrypoint.helpers.js.map +0 -1
- package/lib/transform/Entrypoint.js +0 -289
- package/lib/transform/Entrypoint.js.map +0 -1
- package/lib/transform/Entrypoint.types.js +0 -2
- package/lib/transform/Entrypoint.types.js.map +0 -1
- package/lib/transform/EvaluatedEntrypoint.js +0 -13
- package/lib/transform/EvaluatedEntrypoint.js.map +0 -1
- package/lib/transform/actions/AbortError.js +0 -16
- package/lib/transform/actions/AbortError.js.map +0 -1
- package/lib/transform/actions/BaseAction.js +0 -150
- package/lib/transform/actions/BaseAction.js.map +0 -1
- package/lib/transform/actions/UnprocessedEntrypointError.js +0 -16
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +0 -1
- package/lib/transform/actions/actionRunner.js +0 -82
- package/lib/transform/actions/actionRunner.js.map +0 -1
- package/lib/transform/actions/types.js +0 -2
- package/lib/transform/actions/types.js.map +0 -1
- package/lib/transform/barrelManifest.js +0 -300
- package/lib/transform/barrelManifest.js.map +0 -1
- package/lib/transform/generators/baseProcessingHandlers.js +0 -27
- package/lib/transform/generators/baseProcessingHandlers.js.map +0 -1
- package/lib/transform/generators/collect.js +0 -66
- package/lib/transform/generators/collect.js.map +0 -1
- package/lib/transform/generators/createStylisPreprocessor.js +0 -372
- package/lib/transform/generators/createStylisPreprocessor.js.map +0 -1
- package/lib/transform/generators/evalFile.js +0 -57
- package/lib/transform/generators/evalFile.js.map +0 -1
- package/lib/transform/generators/explodeReexports.js +0 -71
- package/lib/transform/generators/explodeReexports.js.map +0 -1
- package/lib/transform/generators/extract.js +0 -102
- package/lib/transform/generators/extract.js.map +0 -1
- package/lib/transform/generators/getExports.js +0 -85
- package/lib/transform/generators/getExports.js.map +0 -1
- package/lib/transform/generators/index.js +0 -19
- package/lib/transform/generators/index.js.map +0 -1
- package/lib/transform/generators/processEntrypoint.js +0 -76
- package/lib/transform/generators/processEntrypoint.js.map +0 -1
- package/lib/transform/generators/processImports.js +0 -82
- package/lib/transform/generators/processImports.js.map +0 -1
- package/lib/transform/generators/resolveImports.js +0 -221
- package/lib/transform/generators/resolveImports.js.map +0 -1
- package/lib/transform/generators/rewriteBarrelImports.js +0 -743
- package/lib/transform/generators/rewriteBarrelImports.js.map +0 -1
- package/lib/transform/generators/transform.js +0 -272
- package/lib/transform/generators/transform.js.map +0 -1
- package/lib/transform/generators/workflow.js +0 -100
- package/lib/transform/generators/workflow.js.map +0 -1
- package/lib/transform/helpers/loadWywOptions.js +0 -88
- package/lib/transform/helpers/loadWywOptions.js.map +0 -1
- package/lib/transform/helpers/withDefaultServices.js +0 -31
- package/lib/transform/helpers/withDefaultServices.js.map +0 -1
- package/lib/transform/isStaticallyEvaluatableModule.js +0 -159
- package/lib/transform/isStaticallyEvaluatableModule.js.map +0 -1
- package/lib/transform/rootLog.js +0 -9
- package/lib/transform/rootLog.js.map +0 -1
- package/lib/transform/types.js +0 -8
- package/lib/transform/types.js.map +0 -1
- package/lib/transform.js +0 -160
- package/lib/transform.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/utils/EventEmitter.js +0 -61
- package/lib/utils/EventEmitter.js.map +0 -1
- package/lib/utils/ShakerMetadata.js +0 -9
- package/lib/utils/ShakerMetadata.js.map +0 -1
- package/lib/utils/TransformDiagnostics.js +0 -20
- package/lib/utils/TransformDiagnostics.js.map +0 -1
- package/lib/utils/TransformMetadata.js +0 -45
- package/lib/utils/TransformMetadata.js.map +0 -1
- package/lib/utils/addIdentifierToWywPreval.js +0 -75
- package/lib/utils/addIdentifierToWywPreval.js.map +0 -1
- package/lib/utils/collectExportsAndImports.js +0 -1173
- package/lib/utils/collectExportsAndImports.js.map +0 -1
- package/lib/utils/collectTemplateDependencies.js +0 -242
- package/lib/utils/collectTemplateDependencies.js.map +0 -1
- package/lib/utils/createId.js +0 -13
- package/lib/utils/createId.js.map +0 -1
- package/lib/utils/dispose-polyfill.js +0 -9
- package/lib/utils/dispose-polyfill.js.map +0 -1
- package/lib/utils/findIdentifiers.js +0 -73
- package/lib/utils/findIdentifiers.js.map +0 -1
- package/lib/utils/getConstantStringValue.js +0 -66
- package/lib/utils/getConstantStringValue.js.map +0 -1
- package/lib/utils/getFileIdx.js +0 -16
- package/lib/utils/getFileIdx.js.map +0 -1
- package/lib/utils/getMemberExpressionPropertyName.js +0 -18
- package/lib/utils/getMemberExpressionPropertyName.js.map +0 -1
- package/lib/utils/getPluginKey.js +0 -21
- package/lib/utils/getPluginKey.js.map +0 -1
- package/lib/utils/getScope.js +0 -12
- package/lib/utils/getScope.js.map +0 -1
- package/lib/utils/getSource.js +0 -24
- package/lib/utils/getSource.js.map +0 -1
- package/lib/utils/getTagProcessor.js +0 -424
- package/lib/utils/getTagProcessor.js.map +0 -1
- package/lib/utils/getVisitorKeys.js +0 -11
- package/lib/utils/getVisitorKeys.js.map +0 -1
- package/lib/utils/hasWywPreval.js +0 -13
- package/lib/utils/hasWywPreval.js.map +0 -1
- package/lib/utils/importOverrides.js +0 -119
- package/lib/utils/importOverrides.js.map +0 -1
- package/lib/utils/isExports.js +0 -27
- package/lib/utils/isExports.js.map +0 -1
- package/lib/utils/isGlobal.js +0 -13
- package/lib/utils/isGlobal.js.map +0 -1
- package/lib/utils/isNode.js +0 -9
- package/lib/utils/isNode.js.map +0 -1
- package/lib/utils/isNodePath.js +0 -10
- package/lib/utils/isNodePath.js.map +0 -1
- package/lib/utils/isNotNull.js +0 -10
- package/lib/utils/isNotNull.js.map +0 -1
- package/lib/utils/isRemoved.js +0 -52
- package/lib/utils/isRemoved.js.map +0 -1
- package/lib/utils/isRequire.js +0 -18
- package/lib/utils/isRequire.js.map +0 -1
- package/lib/utils/isSerializable.js +0 -19
- package/lib/utils/isSerializable.js.map +0 -1
- package/lib/utils/isTypedNode.js +0 -13
- package/lib/utils/isTypedNode.js.map +0 -1
- package/lib/utils/isUnnecessaryReactCall.js +0 -81
- package/lib/utils/isUnnecessaryReactCall.js.map +0 -1
- package/lib/utils/parseRequest.js +0 -37
- package/lib/utils/parseRequest.js.map +0 -1
- package/lib/utils/peek.js +0 -9
- package/lib/utils/peek.js.map +0 -1
- package/lib/utils/removeDangerousCode.js +0 -284
- package/lib/utils/removeDangerousCode.js.map +0 -1
- package/lib/utils/replaceImportMetaEnv.js +0 -50
- package/lib/utils/replaceImportMetaEnv.js.map +0 -1
- package/lib/utils/scopeHelpers.js +0 -557
- package/lib/utils/scopeHelpers.js.map +0 -1
- package/lib/utils/traversalCache.js +0 -31
- package/lib/utils/traversalCache.js.map +0 -1
- package/lib/utils/unwrapExpression.js +0 -25
- package/lib/utils/unwrapExpression.js.map +0 -1
- package/lib/utils/unwrapSequence.js +0 -20
- package/lib/utils/unwrapSequence.js.map +0 -1
- package/lib/utils/valueToLiteral.js +0 -65
- package/lib/utils/valueToLiteral.js.map +0 -1
- package/lib/utils/visitors/JSXElementsRemover.js +0 -57
- package/lib/utils/visitors/JSXElementsRemover.js.map +0 -1
- package/lib/vm/createVmContext.js +0 -166
- package/lib/vm/createVmContext.js.map +0 -1
- package/lib/vm/process.js +0 -38
- package/lib/vm/process.js.map +0 -1
- package/types/babel.d.ts +0 -2
- package/types/babel.js +0 -2
- package/types/options/buildOptions.d.ts +0 -6
- package/types/options/buildOptions.js +0 -178
- package/types/options/loadBabelOptions.d.ts +0 -3
- package/types/options/loadBabelOptions.js +0 -26
- package/types/plugins/babel-transform.d.ts +0 -4
- package/types/plugins/babel-transform.js +0 -49
- package/types/plugins/collector.d.ts +0 -23
- package/types/plugins/collector.js +0 -62
- package/types/plugins/dynamic-import.d.ts +0 -6
- package/types/plugins/dynamic-import.js +0 -60
- package/types/plugins/preeval.d.ts +0 -16
- package/types/plugins/preeval.js +0 -69
- package/types/plugins/shaker.d.ts +0 -14
- package/types/plugins/shaker.js +0 -724
- package/types/transform/generators/explodeReexports.d.ts +0 -7
- package/types/transform/generators/explodeReexports.js +0 -65
- package/types/utils/addIdentifierToWywPreval.d.ts +0 -4
- package/types/utils/addIdentifierToWywPreval.js +0 -74
- package/types/utils/collectExportsAndImports.d.ts +0 -31
- package/types/utils/collectExportsAndImports.js +0 -1147
- package/types/utils/collectTemplateDependencies.d.ts +0 -17
- package/types/utils/collectTemplateDependencies.js +0 -220
- package/types/utils/createId.d.ts +0 -2
- package/types/utils/createId.js +0 -9
- package/types/utils/findIdentifiers.d.ts +0 -6
- package/types/utils/findIdentifiers.js +0 -67
- package/types/utils/getConstantStringValue.d.ts +0 -2
- package/types/utils/getConstantStringValue.js +0 -94
- package/types/utils/getMemberExpressionPropertyName.d.ts +0 -2
- package/types/utils/getMemberExpressionPropertyName.js +0 -46
- package/types/utils/getScope.d.ts +0 -2
- package/types/utils/getScope.js +0 -10
- package/types/utils/getSource.d.ts +0 -2
- package/types/utils/getSource.js +0 -22
- package/types/utils/getTagProcessor.d.ts +0 -13
- package/types/utils/getTagProcessor.js +0 -411
- package/types/utils/isExports.d.ts +0 -6
- package/types/utils/isExports.js +0 -19
- package/types/utils/isGlobal.d.ts +0 -2
- package/types/utils/isGlobal.js +0 -9
- package/types/utils/isNodePath.d.ts +0 -3
- package/types/utils/isNodePath.js +0 -6
- package/types/utils/isRemoved.d.ts +0 -5
- package/types/utils/isRemoved.js +0 -41
- package/types/utils/isRequire.d.ts +0 -6
- package/types/utils/isRequire.js +0 -14
- package/types/utils/isTypedNode.d.ts +0 -5
- package/types/utils/isTypedNode.js +0 -9
- package/types/utils/isUnnecessaryReactCall.d.ts +0 -3
- package/types/utils/isUnnecessaryReactCall.js +0 -75
- package/types/utils/removeDangerousCode.d.ts +0 -4
- package/types/utils/removeDangerousCode.js +0 -326
- package/types/utils/replaceImportMetaEnv.d.ts +0 -3
- package/types/utils/replaceImportMetaEnv.js +0 -39
- package/types/utils/scopeHelpers.d.ts +0 -12
- package/types/utils/scopeHelpers.js +0 -580
- package/types/utils/traversalCache.d.ts +0 -4
- package/types/utils/traversalCache.js +0 -27
- package/types/utils/unwrapExpression.d.ts +0 -2
- package/types/utils/unwrapExpression.js +0 -57
- package/types/utils/unwrapSequence.d.ts +0 -8
- package/types/utils/unwrapSequence.js +0 -16
- package/types/utils/valueToLiteral.d.ts +0 -3
- package/types/utils/valueToLiteral.js +0 -63
- package/types/utils/visitors/JSXElementsRemover.d.ts +0 -3
- package/types/utils/visitors/JSXElementsRemover.js +0 -51
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-syntax */
|
|
2
|
-
/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
|
|
3
|
-
|
|
4
|
-
import { NODE_FIELDS } from '@babel/types';
|
|
5
|
-
import { findIdentifiers, nonType } from './findIdentifiers';
|
|
6
|
-
import { getScope } from './getScope';
|
|
7
|
-
import { isNotNull } from './isNotNull';
|
|
8
|
-
import { isRemoved } from './isRemoved';
|
|
9
|
-
function validateField(node, key, val, field) {
|
|
10
|
-
if (!(field != null && field.validate)) return true;
|
|
11
|
-
if (field.optional && val == null) return true;
|
|
12
|
-
try {
|
|
13
|
-
field.validate(node, key, val);
|
|
14
|
-
return true;
|
|
15
|
-
} catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function getBinding(path) {
|
|
20
|
-
const binding = getScope(path).getBinding(path.node.name);
|
|
21
|
-
if (!binding) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
return binding;
|
|
25
|
-
}
|
|
26
|
-
export function reference(path, referencePath = path, force = false) {
|
|
27
|
-
if (!force && !path.isReferencedIdentifier()) return;
|
|
28
|
-
const binding = getBinding(path);
|
|
29
|
-
if (!binding) return;
|
|
30
|
-
if (binding.referencePaths.includes(referencePath)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
binding.referenced = true;
|
|
34
|
-
binding.referencePaths.push(referencePath ?? path);
|
|
35
|
-
binding.references = binding.referencePaths.length;
|
|
36
|
-
}
|
|
37
|
-
function isReferenced(binding) {
|
|
38
|
-
const {
|
|
39
|
-
kind,
|
|
40
|
-
referenced,
|
|
41
|
-
referencePaths,
|
|
42
|
-
path
|
|
43
|
-
} = binding;
|
|
44
|
-
if (path.isFunctionExpression() && path.key === 'init' && path.parentPath.isVariableDeclarator()) {
|
|
45
|
-
// It is a function expression in a variable declarator
|
|
46
|
-
const id = path.parentPath.get('id');
|
|
47
|
-
if (id.isIdentifier()) {
|
|
48
|
-
const idBinding = getBinding(id);
|
|
49
|
-
return idBinding ? isReferenced(idBinding) : true;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
if (!referenced) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// If it's a param binding, we can't just remove it
|
|
58
|
-
// because it brakes the function signature. Keep it alive for now.
|
|
59
|
-
if (kind === 'param') {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// If all remaining references are in TS/Flow types, binding is unreferenced
|
|
64
|
-
return referencePaths.length > 0 || referencePaths.every(i => i.find(ancestor => ancestor.isTSType() || ancestor.isFlowType()));
|
|
65
|
-
}
|
|
66
|
-
function isReferencedConstantViolation(path, binding) {
|
|
67
|
-
if (path.find(p => p === binding.path)) {
|
|
68
|
-
// function a(flag) { return (a = function(flag) { flag ? 1 : 2 }) }
|
|
69
|
-
// ^ Looks crazy, yeh? Welcome to the wonderful world of transpilers!
|
|
70
|
-
// `a = …` here isn't a reference.
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
if (!path.isReferenced()) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
if (path.isAssignmentExpression() && path.parentPath.isExpressionStatement()) {
|
|
77
|
-
// A root assignment without a parent expression statement is not a reference
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
export function dereference(path) {
|
|
83
|
-
const binding = getBinding(path);
|
|
84
|
-
if (!binding) return null;
|
|
85
|
-
const isReference = binding.referencePaths.includes(path);
|
|
86
|
-
let referencesInConstantViolations = binding.constantViolations.filter(i => isReferencedConstantViolation(i, binding));
|
|
87
|
-
const isConstantViolation = referencesInConstantViolations.includes(path);
|
|
88
|
-
if (!isReference && !isConstantViolation) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
if (isReference) {
|
|
92
|
-
binding.referencePaths = binding.referencePaths.filter(i => i !== path);
|
|
93
|
-
binding.references -= 1;
|
|
94
|
-
} else {
|
|
95
|
-
referencesInConstantViolations = referencesInConstantViolations.filter(i => i !== path);
|
|
96
|
-
}
|
|
97
|
-
const nonTypeReferences = binding.referencePaths.filter(nonType);
|
|
98
|
-
binding.referenced = nonTypeReferences.length + referencesInConstantViolations.length > 0;
|
|
99
|
-
return binding;
|
|
100
|
-
}
|
|
101
|
-
function dereferenceAll(path) {
|
|
102
|
-
return findIdentifiers([path]).map(identifierPath => dereference(identifierPath)).filter(isNotNull);
|
|
103
|
-
}
|
|
104
|
-
export function referenceAll(path) {
|
|
105
|
-
findIdentifiers([path]).forEach(identifierPath => reference(identifierPath));
|
|
106
|
-
}
|
|
107
|
-
const deletingNodes = new WeakSet();
|
|
108
|
-
const isEmptyList = list => list.length === 0 || list.every(i => deletingNodes.has(i));
|
|
109
|
-
const getPathFromAction = action => {
|
|
110
|
-
if (!Array.isArray(action)) {
|
|
111
|
-
return action;
|
|
112
|
-
}
|
|
113
|
-
if (action[0] === 'replace' || action[0] === 'remove') {
|
|
114
|
-
return action[1];
|
|
115
|
-
}
|
|
116
|
-
throw new Error(`Unknown action type: ${action[0]}`);
|
|
117
|
-
};
|
|
118
|
-
function isPrototypeAssignment(path) {
|
|
119
|
-
if (!path.isAssignmentExpression()) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
const {
|
|
123
|
-
left
|
|
124
|
-
} = path.node;
|
|
125
|
-
if (!left) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
if (left.type !== 'MemberExpression') {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
const {
|
|
132
|
-
object,
|
|
133
|
-
property
|
|
134
|
-
} = left;
|
|
135
|
-
if (!object || !property) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
return object.type === 'MemberExpression' && object.property.type === 'Identifier' && object.property.name === 'prototype';
|
|
139
|
-
}
|
|
140
|
-
function canFunctionBeDelete(fnPath) {
|
|
141
|
-
if (isPrototypeAssignment(fnPath.parentPath)) {
|
|
142
|
-
// It is a prototype assignment, we can't delete it since we can't find all usages
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
const fnScope = fnPath.scope;
|
|
146
|
-
const parentScope = fnScope.parent;
|
|
147
|
-
if (parentScope.parent) {
|
|
148
|
-
// It isn't a top-level function, so we can't delete it
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
if (fnPath.listKey === 'arguments') {
|
|
152
|
-
// It is passed as an argument to another function, we can't delete it
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
export function findActionForNode(path) {
|
|
158
|
-
if (isRemoved(path)) return null;
|
|
159
|
-
deletingNodes.add(path);
|
|
160
|
-
const parent = path.parentPath;
|
|
161
|
-
if (!parent) return ['remove', path];
|
|
162
|
-
if (parent.isProgram()) {
|
|
163
|
-
// Do not delete Program node
|
|
164
|
-
return ['remove', path];
|
|
165
|
-
}
|
|
166
|
-
if (parent.isClassDeclaration() || parent.isClassExpression()) {
|
|
167
|
-
if (path.key === 'body') {
|
|
168
|
-
return ['replace', path, {
|
|
169
|
-
type: 'ClassBody',
|
|
170
|
-
body: []
|
|
171
|
-
}];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (parent.isFunction()) {
|
|
175
|
-
if (path.listKey === 'params') {
|
|
176
|
-
// Do not remove params of functions
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
if (path.isBlockStatement() && isEmptyList(path.get('body')) || path === parent.get('body')) {
|
|
180
|
-
if (!canFunctionBeDelete(parent)) {
|
|
181
|
-
return ['replace', parent, {
|
|
182
|
-
...parent.node,
|
|
183
|
-
async: false,
|
|
184
|
-
body: {
|
|
185
|
-
type: 'BlockStatement',
|
|
186
|
-
body: [],
|
|
187
|
-
directives: []
|
|
188
|
-
},
|
|
189
|
-
generator: false,
|
|
190
|
-
params: []
|
|
191
|
-
}];
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (parent.isConditionalExpression()) {
|
|
196
|
-
if (path.key === 'test') {
|
|
197
|
-
return ['replace', parent, parent.node.alternate];
|
|
198
|
-
}
|
|
199
|
-
if (path.key === 'consequent') {
|
|
200
|
-
return ['replace', path, {
|
|
201
|
-
type: 'Identifier',
|
|
202
|
-
name: 'undefined'
|
|
203
|
-
}];
|
|
204
|
-
}
|
|
205
|
-
if (path.key === 'alternate') {
|
|
206
|
-
return ['replace', path, {
|
|
207
|
-
type: 'Identifier',
|
|
208
|
-
name: 'undefined'
|
|
209
|
-
}];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (parent.isLogicalExpression({
|
|
213
|
-
operator: '&&'
|
|
214
|
-
})) {
|
|
215
|
-
return ['replace', parent, {
|
|
216
|
-
type: 'BooleanLiteral',
|
|
217
|
-
value: false
|
|
218
|
-
}];
|
|
219
|
-
}
|
|
220
|
-
if (parent.isLogicalExpression({
|
|
221
|
-
operator: '||'
|
|
222
|
-
})) {
|
|
223
|
-
return ['replace', parent, path.key === 'left' ? parent.node.right : parent.node.left];
|
|
224
|
-
}
|
|
225
|
-
if (parent.isObjectProperty()) {
|
|
226
|
-
// let's check if it is a special case with Object.defineProperty
|
|
227
|
-
const key = parent.get('key');
|
|
228
|
-
if (key.isIdentifier({
|
|
229
|
-
name: 'get'
|
|
230
|
-
})) {
|
|
231
|
-
const maybeDefineProperty = parent.parentPath.parentPath;
|
|
232
|
-
if (maybeDefineProperty?.isCallExpression() && maybeDefineProperty.get('callee').matchesPattern('Object.defineProperty')) {
|
|
233
|
-
return findActionForNode(maybeDefineProperty);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return findActionForNode(parent);
|
|
237
|
-
}
|
|
238
|
-
if (parent.isTemplateLiteral()) {
|
|
239
|
-
return ['replace', path, {
|
|
240
|
-
type: 'StringLiteral',
|
|
241
|
-
value: ''
|
|
242
|
-
}];
|
|
243
|
-
}
|
|
244
|
-
if (parent.isAssignmentExpression()) {
|
|
245
|
-
if (path.isAssignmentExpression()) {
|
|
246
|
-
// `foo = bar = 42` should be replaced with `foo = 42`
|
|
247
|
-
return ['replace', path, path.node.right];
|
|
248
|
-
}
|
|
249
|
-
return findActionForNode(parent);
|
|
250
|
-
}
|
|
251
|
-
if (parent.isCallExpression()) {
|
|
252
|
-
return findActionForNode(parent);
|
|
253
|
-
}
|
|
254
|
-
if (parent.isForInStatement({
|
|
255
|
-
left: path.node
|
|
256
|
-
})) {
|
|
257
|
-
return findActionForNode(parent);
|
|
258
|
-
}
|
|
259
|
-
if (parent.isFunctionExpression({
|
|
260
|
-
body: path.node
|
|
261
|
-
}) || parent.isFunctionDeclaration() || parent.isObjectMethod() || parent.isClassMethod()) {
|
|
262
|
-
return findActionForNode(parent);
|
|
263
|
-
}
|
|
264
|
-
if (parent.isBlockStatement()) {
|
|
265
|
-
const body = parent.get('body');
|
|
266
|
-
if (isEmptyList(body)) {
|
|
267
|
-
return findActionForNode(parent);
|
|
268
|
-
}
|
|
269
|
-
if (path.listKey === 'body' && typeof path.key === 'number') {
|
|
270
|
-
if (path.key > 0) {
|
|
271
|
-
// We can check whether the previous one can be removed
|
|
272
|
-
const prevStatement = body[path.key - 1];
|
|
273
|
-
if (prevStatement.isIfStatement() && prevStatement.get('consequent').isReturnStatement()) {
|
|
274
|
-
// It's `if (…) return …`, we can remove it.
|
|
275
|
-
return findActionForNode(prevStatement);
|
|
276
|
-
}
|
|
277
|
-
} else if (body.slice(1).every(statement => deletingNodes.has(statement))) {
|
|
278
|
-
// If it is the first statement and all other statements
|
|
279
|
-
// are marked for deletion, we can remove the whole block.
|
|
280
|
-
return findActionForNode(parent);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
if (parent.isVariableDeclarator()) {
|
|
285
|
-
if (path.key === 'init' && path.isAssignmentExpression()) {
|
|
286
|
-
// We are removing `bar` in `var foo = bar = 42`. Path should be replaced with `var foo = 42`
|
|
287
|
-
return ['replace', path, path.node.right];
|
|
288
|
-
}
|
|
289
|
-
const init = parent.get('init');
|
|
290
|
-
if (path.key === 'id' && init.isAssignmentExpression()) {
|
|
291
|
-
// We are removing `foo` in `var foo = bar = 42`. Ignore it.
|
|
292
|
-
return null;
|
|
293
|
-
}
|
|
294
|
-
return findActionForNode(parent);
|
|
295
|
-
}
|
|
296
|
-
if (parent.isExportNamedDeclaration() && (path.key === 'specifiers' && isEmptyList(parent.get('specifiers')) || path.key === 'declaration' && parent.node.declaration === path.node)) {
|
|
297
|
-
return findActionForNode(parent);
|
|
298
|
-
}
|
|
299
|
-
for (const key of ['body', 'declarations', 'specifiers']) {
|
|
300
|
-
if (path.listKey === key && typeof path.key === 'number') {
|
|
301
|
-
const list = parent.get(key);
|
|
302
|
-
if (isEmptyList(list)) {
|
|
303
|
-
return findActionForNode(parent);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (parent.isTryStatement()) {
|
|
308
|
-
return findActionForNode(parent);
|
|
309
|
-
}
|
|
310
|
-
if (!path.listKey && path.key) {
|
|
311
|
-
const field = NODE_FIELDS[parent.type][path.key];
|
|
312
|
-
if (!validateField(parent.node, path.key, null, field)) {
|
|
313
|
-
// The parent node isn't valid without this field, so we should remove it also.
|
|
314
|
-
return findActionForNode(parent);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
for (const key of ['argument', 'block', 'body', 'callee', 'discriminant', 'expression', 'id', 'left', 'object', 'property', 'right', 'test']) {
|
|
318
|
-
if (path.key === key && parent.get(key) === path) {
|
|
319
|
-
return findActionForNode(parent);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return ['remove', path];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// @babel/preset-typescript transpiles enums, but doesn't reference used identifiers.
|
|
326
|
-
function referenceEnums(program) {
|
|
327
|
-
/*
|
|
328
|
-
* We are looking for transpiled enums.
|
|
329
|
-
* (function (Colors) {
|
|
330
|
-
* Colors["BLUE"] = "#27509A";
|
|
331
|
-
* })(Colors || (Colors = {}));
|
|
332
|
-
*/
|
|
333
|
-
program.traverse({
|
|
334
|
-
ExpressionStatement(expressionStatement) {
|
|
335
|
-
const expression = expressionStatement.get('expression');
|
|
336
|
-
if (!expression.isCallExpression()) return;
|
|
337
|
-
const callee = expression.get('callee');
|
|
338
|
-
const args = expression.get('arguments');
|
|
339
|
-
if (!callee.isFunctionExpression() || args.length !== 1) return;
|
|
340
|
-
const [arg] = args;
|
|
341
|
-
if (arg.isLogicalExpression({
|
|
342
|
-
operator: '||'
|
|
343
|
-
})) {
|
|
344
|
-
referenceAll(arg);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
const fixed = new WeakSet();
|
|
350
|
-
function removeUnreferenced(items) {
|
|
351
|
-
const referenced = new Set();
|
|
352
|
-
items.forEach(item => {
|
|
353
|
-
if (!item.node || isRemoved(item)) return;
|
|
354
|
-
const binding = getScope(item).getBinding(item.node.name);
|
|
355
|
-
if (!binding) return;
|
|
356
|
-
const hasReferences = binding.referencePaths.filter(i => !isRemoved(i)).length > 0;
|
|
357
|
-
if (hasReferences) {
|
|
358
|
-
referenced.add(item);
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
const forDeleting = [binding.path, ...binding.constantViolations].map(findActionForNode).filter(isNotNull).map(getPathFromAction);
|
|
362
|
-
if (forDeleting.length === 0) return;
|
|
363
|
-
findIdentifiers(forDeleting).forEach(identifier => {
|
|
364
|
-
referenced.add(identifier);
|
|
365
|
-
});
|
|
366
|
-
removeWithRelated(forDeleting);
|
|
367
|
-
});
|
|
368
|
-
const result = [...referenced];
|
|
369
|
-
result.sort((a, b) => a.node?.name.localeCompare(b.node?.name));
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
function getNodeForValue(value) {
|
|
373
|
-
if (typeof value === 'string') {
|
|
374
|
-
return {
|
|
375
|
-
type: 'StringLiteral',
|
|
376
|
-
value
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
if (typeof value === 'number') {
|
|
380
|
-
return {
|
|
381
|
-
type: 'NumericLiteral',
|
|
382
|
-
value
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
if (typeof value === 'boolean') {
|
|
386
|
-
return {
|
|
387
|
-
type: 'BooleanLiteral',
|
|
388
|
-
value
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
if (value === null) {
|
|
392
|
-
return {
|
|
393
|
-
type: 'NullLiteral'
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
if (value === undefined) {
|
|
397
|
-
return {
|
|
398
|
-
type: 'Identifier',
|
|
399
|
-
name: 'undefined'
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
return undefined;
|
|
403
|
-
}
|
|
404
|
-
function staticEvaluate(path) {
|
|
405
|
-
if (!path) return;
|
|
406
|
-
const evaluated = path.evaluate();
|
|
407
|
-
if (evaluated.confident) {
|
|
408
|
-
const node = getNodeForValue(evaluated.value);
|
|
409
|
-
if (node) {
|
|
410
|
-
applyAction(['replace', path, node]);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (path.isIfStatement()) {
|
|
415
|
-
const test = path.get('test');
|
|
416
|
-
if (!test.isBooleanLiteral()) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
const {
|
|
420
|
-
consequent,
|
|
421
|
-
alternate
|
|
422
|
-
} = path.node;
|
|
423
|
-
if (test.node.value) {
|
|
424
|
-
applyAction(['replace', path, consequent]);
|
|
425
|
-
} else if (alternate) {
|
|
426
|
-
applyAction(['replace', path, alternate]);
|
|
427
|
-
} else {
|
|
428
|
-
applyAction(['remove', path]);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
function applyAction(action) {
|
|
433
|
-
mutate(action[1], p => {
|
|
434
|
-
if (isRemoved(p)) return;
|
|
435
|
-
const parent = p.parentPath;
|
|
436
|
-
if (action[0] === 'remove') {
|
|
437
|
-
p.remove();
|
|
438
|
-
}
|
|
439
|
-
if (action[0] === 'replace') {
|
|
440
|
-
p.replaceWith(action[2]);
|
|
441
|
-
}
|
|
442
|
-
staticEvaluate(parent);
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
function removeWithRelated(paths) {
|
|
446
|
-
if (paths.length === 0) return;
|
|
447
|
-
const rootPath = getScope(paths[0]).getProgramParent().path;
|
|
448
|
-
if (!fixed.has(rootPath)) {
|
|
449
|
-
// Some libraries don't care about bindings, references, and other staff
|
|
450
|
-
// So we have to fix the scope before we can detect unused code
|
|
451
|
-
referenceEnums(rootPath);
|
|
452
|
-
fixed.add(rootPath);
|
|
453
|
-
}
|
|
454
|
-
const actions = paths.map(findActionForNode).filter(isNotNull);
|
|
455
|
-
const affectedPaths = actions.map(getPathFromAction);
|
|
456
|
-
let referencedIdentifiers = findIdentifiers(affectedPaths, 'reference');
|
|
457
|
-
referencedIdentifiers.sort((a, b) => a.node?.name.localeCompare(b.node?.name));
|
|
458
|
-
const referencesOfBinding = findIdentifiers(affectedPaths, 'declaration').map(i => (i.node && getScope(i).getBinding(i.node.name)) ?? null).filter(isNotNull).reduce((acc, i) => [...acc, ...i.referencePaths.filter(nonType)], []).filter(ref =>
|
|
459
|
-
// Do not remove `export default function`
|
|
460
|
-
!ref.isExportDefaultDeclaration() || !ref.get('declaration').isFunctionDeclaration());
|
|
461
|
-
actions.forEach(applyAction);
|
|
462
|
-
removeWithRelated(referencesOfBinding);
|
|
463
|
-
let clean = false;
|
|
464
|
-
while (!clean && referencedIdentifiers.length > 0) {
|
|
465
|
-
const referenced = removeUnreferenced(referencedIdentifiers);
|
|
466
|
-
clean = referenced.map(i => i.node?.name).join('|') === referencedIdentifiers.map(i => i.node?.name).join('|');
|
|
467
|
-
referencedIdentifiers = referenced;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function mutate(path, fn) {
|
|
471
|
-
const dereferenced = dereferenceAll(path);
|
|
472
|
-
const mutated = fn(path);
|
|
473
|
-
referenceAll(path);
|
|
474
|
-
mutated?.forEach(p => referenceAll(p));
|
|
475
|
-
const dead = dereferenced.filter(p => !isReferenced(p));
|
|
476
|
-
const forDeleting = [];
|
|
477
|
-
dead.forEach(binding => {
|
|
478
|
-
const assignments = [binding.path, ...binding.constantViolations];
|
|
479
|
-
assignments.forEach(assignment => {
|
|
480
|
-
const {
|
|
481
|
-
scope
|
|
482
|
-
} = assignment;
|
|
483
|
-
const declared = Object.values(assignment.getOuterBindingIdentifiers(false));
|
|
484
|
-
if (declared.length === 1 && 'name' in declared[0] && declared[0].name === binding.identifier.name) {
|
|
485
|
-
const init = assignment.get('init');
|
|
486
|
-
if (!Array.isArray(init) && init?.isAssignmentExpression()) {
|
|
487
|
-
// `const a = b = 1` → `b = 1`
|
|
488
|
-
assignment.parentPath?.replaceWith({
|
|
489
|
-
type: 'ExpressionStatement',
|
|
490
|
-
expression: init.node
|
|
491
|
-
});
|
|
492
|
-
const left = init.get('left');
|
|
493
|
-
if (left.isIdentifier()) {
|
|
494
|
-
// If it was forcefully referenced in the shaker
|
|
495
|
-
dereference(left);
|
|
496
|
-
}
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
// Only one identifier is declared, so we can remove the whole declaration
|
|
500
|
-
forDeleting.push(assignment);
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
if (declared.every(identifier => identifier.type === 'Identifier' && !scope.getBinding(identifier.name)?.referenced)) {
|
|
504
|
-
// No other identifier is referenced, so we can remove the whole declaration
|
|
505
|
-
forDeleting.push(assignment);
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// We can't remove the binding, but we can remove the part of it
|
|
510
|
-
assignment.traverse({
|
|
511
|
-
Identifier(identifier) {
|
|
512
|
-
if (identifier.node.name === binding.identifier.name) {
|
|
513
|
-
const parent = identifier.parentPath;
|
|
514
|
-
if (parent.isArrayPattern() && identifier.listKey === 'elements' && typeof identifier.key === 'number') {
|
|
515
|
-
parent.node.elements[identifier.key] = null;
|
|
516
|
-
} else if (parent.isObjectProperty()) {
|
|
517
|
-
forDeleting.push(parent);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
removeWithRelated(forDeleting);
|
|
525
|
-
}
|
|
526
|
-
export { applyAction, mutate, removeWithRelated };
|
|
527
|
-
//# sourceMappingURL=scopeHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopeHelpers.js","names":["NODE_FIELDS","findIdentifiers","nonType","getScope","isNotNull","isRemoved","validateField","node","key","val","field","validate","optional","getBinding","path","binding","name","undefined","reference","referencePath","force","isReferencedIdentifier","referencePaths","includes","referenced","push","references","length","isReferenced","kind","isFunctionExpression","parentPath","isVariableDeclarator","id","get","isIdentifier","idBinding","every","i","find","ancestor","isTSType","isFlowType","isReferencedConstantViolation","p","isAssignmentExpression","isExpressionStatement","dereference","isReference","referencesInConstantViolations","constantViolations","filter","isConstantViolation","nonTypeReferences","dereferenceAll","map","identifierPath","referenceAll","forEach","deletingNodes","WeakSet","isEmptyList","list","has","getPathFromAction","action","Array","isArray","Error","isPrototypeAssignment","left","type","object","property","canFunctionBeDelete","fnPath","fnScope","scope","parentScope","parent","listKey","findActionForNode","add","isProgram","isClassDeclaration","isClassExpression","body","isFunction","isBlockStatement","async","directives","generator","params","isConditionalExpression","alternate","isLogicalExpression","operator","value","right","isObjectProperty","maybeDefineProperty","isCallExpression","matchesPattern","isTemplateLiteral","isForInStatement","isFunctionDeclaration","isObjectMethod","isClassMethod","prevStatement","isIfStatement","isReturnStatement","slice","statement","init","isExportNamedDeclaration","declaration","isTryStatement","referenceEnums","program","traverse","ExpressionStatement","expressionStatement","expression","callee","args","arg","fixed","removeUnreferenced","items","Set","item","hasReferences","forDeleting","identifier","removeWithRelated","result","sort","a","b","localeCompare","getNodeForValue","staticEvaluate","evaluated","evaluate","confident","applyAction","test","isBooleanLiteral","consequent","mutate","remove","replaceWith","paths","rootPath","getProgramParent","actions","affectedPaths","referencedIdentifiers","referencesOfBinding","reduce","acc","ref","isExportDefaultDeclaration","clean","join","fn","dereferenced","mutated","dead","assignments","assignment","declared","Object","values","getOuterBindingIdentifiers","Identifier","isArrayPattern","elements"],"sources":["../../src/utils/scopeHelpers.ts"],"sourcesContent":["/* eslint-disable no-restricted-syntax */\n/* eslint @typescript-eslint/no-use-before-define: [\"error\", { \"functions\": false }] */\n\nimport type { Binding, NodePath } from '@babel/traverse';\nimport type {\n FieldOptions,\n Function as FunctionNode,\n Identifier,\n JSXIdentifier,\n Node,\n Program,\n} from '@babel/types';\nimport { NODE_FIELDS } from '@babel/types';\n\nimport { findIdentifiers, nonType } from './findIdentifiers';\nimport { getScope } from './getScope';\nimport { isNotNull } from './isNotNull';\nimport { isRemoved } from './isRemoved';\n\nfunction validateField(\n node: Node,\n key: string,\n val: unknown,\n field: FieldOptions\n) {\n if (!(field != null && field.validate)) return true;\n if (field.optional && val == null) return true;\n try {\n field.validate(node, key, val);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction getBinding(path: NodePath<Identifier | JSXIdentifier>) {\n const binding = getScope(path).getBinding(path.node.name);\n if (!binding) {\n return undefined;\n }\n\n return binding;\n}\n\nexport function reference(\n path: NodePath<Identifier | JSXIdentifier>,\n referencePath: NodePath = path,\n force = false\n): void {\n if (!force && !path.isReferencedIdentifier()) return;\n\n const binding = getBinding(path);\n if (!binding) return;\n\n if (binding.referencePaths.includes(referencePath)) {\n return;\n }\n\n binding.referenced = true;\n binding.referencePaths.push(referencePath ?? path);\n binding.references = binding.referencePaths.length;\n}\n\nfunction isReferenced(binding: Binding): boolean {\n const { kind, referenced, referencePaths, path } = binding;\n\n if (\n path.isFunctionExpression() &&\n path.key === 'init' &&\n path.parentPath.isVariableDeclarator()\n ) {\n // It is a function expression in a variable declarator\n const id = path.parentPath.get('id');\n if (id.isIdentifier()) {\n const idBinding = getBinding(id);\n return idBinding ? isReferenced(idBinding) : true;\n }\n\n return true;\n }\n\n if (!referenced) {\n return false;\n }\n\n // If it's a param binding, we can't just remove it\n // because it brakes the function signature. Keep it alive for now.\n if ((kind as string) === 'param') {\n return true;\n }\n\n // If all remaining references are in TS/Flow types, binding is unreferenced\n return (\n referencePaths.length > 0 ||\n referencePaths.every((i) =>\n i.find((ancestor) => ancestor.isTSType() || ancestor.isFlowType())\n )\n );\n}\n\nfunction isReferencedConstantViolation(path: NodePath, binding: Binding) {\n if (path.find((p) => p === binding.path)) {\n // function a(flag) { return (a = function(flag) { flag ? 1 : 2 }) }\n // ^ Looks crazy, yeh? Welcome to the wonderful world of transpilers!\n // `a = …` here isn't a reference.\n return false;\n }\n\n if (!path.isReferenced()) {\n return false;\n }\n\n if (\n path.isAssignmentExpression() &&\n path.parentPath.isExpressionStatement()\n ) {\n // A root assignment without a parent expression statement is not a reference\n return false;\n }\n\n return true;\n}\n\nexport function dereference(\n path: NodePath<Identifier | JSXIdentifier>\n): Binding | null {\n const binding = getBinding(path);\n if (!binding) return null;\n\n const isReference = binding.referencePaths.includes(path);\n let referencesInConstantViolations = binding.constantViolations.filter((i) =>\n isReferencedConstantViolation(i, binding)\n );\n\n const isConstantViolation = referencesInConstantViolations.includes(path);\n\n if (!isReference && !isConstantViolation) {\n return null;\n }\n\n if (isReference) {\n binding.referencePaths = binding.referencePaths.filter((i) => i !== path);\n binding.references -= 1;\n } else {\n referencesInConstantViolations = referencesInConstantViolations.filter(\n (i) => i !== path\n );\n }\n\n const nonTypeReferences = binding.referencePaths.filter(nonType);\n binding.referenced =\n nonTypeReferences.length + referencesInConstantViolations.length > 0;\n\n return binding;\n}\n\nfunction dereferenceAll(path: NodePath): Binding[] {\n return findIdentifiers([path])\n .map((identifierPath) => dereference(identifierPath))\n .filter(isNotNull);\n}\n\nexport function referenceAll(path: NodePath): void {\n findIdentifiers([path]).forEach((identifierPath) =>\n reference(identifierPath)\n );\n}\n\nconst deletingNodes = new WeakSet<NodePath>();\n\nconst isEmptyList = (list: NodePath[]) =>\n list.length === 0 || list.every((i) => deletingNodes.has(i));\n\ntype ReplaceAction = [action: 'replace', what: NodePath, by: Node];\ntype RemoveAction = [action: 'remove', what: NodePath];\n\nconst getPathFromAction = (action: RemoveAction | ReplaceAction) => {\n if (!Array.isArray(action)) {\n return action;\n }\n\n if (action[0] === 'replace' || action[0] === 'remove') {\n return action[1];\n }\n\n throw new Error(`Unknown action type: ${action[0]}`);\n};\n\nfunction isPrototypeAssignment(path: NodePath) {\n if (!path.isAssignmentExpression()) {\n return false;\n }\n\n const { left } = path.node;\n if (!left) {\n return false;\n }\n\n if (left.type !== 'MemberExpression') {\n return false;\n }\n\n const { object, property } = left;\n if (!object || !property) {\n return false;\n }\n\n return (\n object.type === 'MemberExpression' &&\n object.property.type === 'Identifier' &&\n object.property.name === 'prototype'\n );\n}\n\nfunction canFunctionBeDelete(fnPath: NodePath<FunctionNode>) {\n if (isPrototypeAssignment(fnPath.parentPath)) {\n // It is a prototype assignment, we can't delete it since we can't find all usages\n return false;\n }\n\n const fnScope = fnPath.scope;\n const parentScope = fnScope.parent;\n if (parentScope.parent) {\n // It isn't a top-level function, so we can't delete it\n return true;\n }\n\n if (fnPath.listKey === 'arguments') {\n // It is passed as an argument to another function, we can't delete it\n return true;\n }\n\n return false;\n}\n\nexport function findActionForNode(\n path: NodePath\n): RemoveAction | ReplaceAction | null {\n if (isRemoved(path)) return null;\n\n deletingNodes.add(path);\n\n const parent = path.parentPath;\n\n if (!parent) return ['remove', path];\n\n if (parent.isProgram()) {\n // Do not delete Program node\n return ['remove', path];\n }\n\n if (parent.isClassDeclaration() || parent.isClassExpression()) {\n if (path.key === 'body') {\n return ['replace', path, { type: 'ClassBody', body: [] }];\n }\n }\n\n if (parent.isFunction()) {\n if (path.listKey === 'params') {\n // Do not remove params of functions\n return null;\n }\n\n if (\n (path.isBlockStatement() && isEmptyList(path.get('body'))) ||\n path === parent.get('body')\n ) {\n if (!canFunctionBeDelete(parent)) {\n return [\n 'replace',\n parent,\n {\n ...parent.node,\n async: false,\n body: {\n type: 'BlockStatement',\n body: [],\n directives: [],\n },\n generator: false,\n params: [],\n },\n ];\n }\n }\n }\n\n if (parent.isConditionalExpression()) {\n if (path.key === 'test') {\n return ['replace', parent, parent.node.alternate];\n }\n\n if (path.key === 'consequent') {\n return ['replace', path, { type: 'Identifier', name: 'undefined' }];\n }\n\n if (path.key === 'alternate') {\n return ['replace', path, { type: 'Identifier', name: 'undefined' }];\n }\n }\n\n if (parent.isLogicalExpression({ operator: '&&' })) {\n return [\n 'replace',\n parent,\n {\n type: 'BooleanLiteral',\n value: false,\n },\n ];\n }\n\n if (parent.isLogicalExpression({ operator: '||' })) {\n return [\n 'replace',\n parent,\n path.key === 'left' ? parent.node.right : parent.node.left,\n ];\n }\n\n if (parent.isObjectProperty()) {\n // let's check if it is a special case with Object.defineProperty\n const key = parent.get('key');\n if (key.isIdentifier({ name: 'get' })) {\n const maybeDefineProperty = parent.parentPath.parentPath;\n if (\n maybeDefineProperty?.isCallExpression() &&\n maybeDefineProperty\n .get('callee')\n .matchesPattern('Object.defineProperty')\n ) {\n return findActionForNode(maybeDefineProperty);\n }\n }\n\n return findActionForNode(parent);\n }\n\n if (parent.isTemplateLiteral()) {\n return [\n 'replace',\n path,\n {\n type: 'StringLiteral',\n value: '',\n },\n ];\n }\n\n if (parent.isAssignmentExpression()) {\n if (path.isAssignmentExpression()) {\n // `foo = bar = 42` should be replaced with `foo = 42`\n return ['replace', path, path.node.right];\n }\n\n return findActionForNode(parent);\n }\n\n if (parent.isCallExpression()) {\n return findActionForNode(parent);\n }\n\n if (parent.isForInStatement({ left: path.node })) {\n return findActionForNode(parent);\n }\n\n if (\n parent.isFunctionExpression({ body: path.node }) ||\n parent.isFunctionDeclaration() ||\n parent.isObjectMethod() ||\n parent.isClassMethod()\n ) {\n return findActionForNode(parent);\n }\n\n if (parent.isBlockStatement()) {\n const body = parent.get('body');\n if (isEmptyList(body)) {\n return findActionForNode(parent);\n }\n\n if (path.listKey === 'body' && typeof path.key === 'number') {\n if (path.key > 0) {\n // We can check whether the previous one can be removed\n const prevStatement = body[path.key - 1];\n if (\n prevStatement.isIfStatement() &&\n prevStatement.get('consequent').isReturnStatement()\n ) {\n // It's `if (…) return …`, we can remove it.\n return findActionForNode(prevStatement);\n }\n } else if (\n body.slice(1).every((statement) => deletingNodes.has(statement))\n ) {\n // If it is the first statement and all other statements\n // are marked for deletion, we can remove the whole block.\n return findActionForNode(parent);\n }\n }\n }\n\n if (parent.isVariableDeclarator()) {\n if (path.key === 'init' && path.isAssignmentExpression()) {\n // We are removing `bar` in `var foo = bar = 42`. Path should be replaced with `var foo = 42`\n return ['replace', path, path.node.right];\n }\n\n const init = parent.get('init');\n if (path.key === 'id' && init.isAssignmentExpression()) {\n // We are removing `foo` in `var foo = bar = 42`. Ignore it.\n return null;\n }\n\n return findActionForNode(parent);\n }\n\n if (\n parent.isExportNamedDeclaration() &&\n ((path.key === 'specifiers' && isEmptyList(parent.get('specifiers'))) ||\n (path.key === 'declaration' && parent.node.declaration === path.node))\n ) {\n return findActionForNode(parent);\n }\n\n for (const key of ['body', 'declarations', 'specifiers']) {\n if (path.listKey === key && typeof path.key === 'number') {\n const list = parent.get(key) as NodePath[];\n if (isEmptyList(list)) {\n return findActionForNode(parent);\n }\n }\n }\n\n if (parent.isTryStatement()) {\n return findActionForNode(parent);\n }\n\n if (!path.listKey && path.key) {\n const field = NODE_FIELDS[parent.type][path.key];\n if (!validateField(parent.node, path.key as string, null, field)) {\n // The parent node isn't valid without this field, so we should remove it also.\n return findActionForNode(parent);\n }\n }\n\n for (const key of [\n 'argument',\n 'block',\n 'body',\n 'callee',\n 'discriminant',\n 'expression',\n 'id',\n 'left',\n 'object',\n 'property',\n 'right',\n 'test',\n ]) {\n if (path.key === key && parent.get(key) === path) {\n return findActionForNode(parent);\n }\n }\n\n return ['remove', path];\n}\n\n// @babel/preset-typescript transpiles enums, but doesn't reference used identifiers.\nfunction referenceEnums(program: NodePath<Program>) {\n /*\n * We are looking for transpiled enums.\n * (function (Colors) {\n * Colors[\"BLUE\"] = \"#27509A\";\n * })(Colors || (Colors = {}));\n */\n program.traverse({\n ExpressionStatement(expressionStatement) {\n const expression = expressionStatement.get('expression');\n if (!expression.isCallExpression()) return;\n\n const callee = expression.get('callee');\n const args = expression.get('arguments');\n if (!callee.isFunctionExpression() || args.length !== 1) return;\n const [arg] = args;\n if (arg.isLogicalExpression({ operator: '||' })) {\n referenceAll(arg);\n }\n },\n });\n}\n\nconst fixed = new WeakSet<NodePath<Program>>();\n\nfunction removeUnreferenced(items: NodePath<Identifier | JSXIdentifier>[]) {\n const referenced = new Set<NodePath<Identifier | JSXIdentifier>>();\n items.forEach((item) => {\n if (!item.node || isRemoved(item)) return;\n const binding = getScope(item).getBinding(item.node.name);\n if (!binding) return;\n const hasReferences =\n binding.referencePaths.filter((i) => !isRemoved(i)).length > 0;\n if (hasReferences) {\n referenced.add(item);\n return;\n }\n\n const forDeleting = [binding.path, ...binding.constantViolations]\n .map(findActionForNode)\n .filter(isNotNull)\n .map(getPathFromAction);\n\n if (forDeleting.length === 0) return;\n\n findIdentifiers(forDeleting).forEach((identifier) => {\n referenced.add(identifier);\n });\n\n removeWithRelated(forDeleting);\n });\n\n const result = [...referenced];\n result.sort((a, b) => a.node?.name.localeCompare(b.node?.name));\n\n return result;\n}\n\nfunction getNodeForValue(value: unknown): Node | undefined {\n if (typeof value === 'string') {\n return {\n type: 'StringLiteral',\n value,\n };\n }\n\n if (typeof value === 'number') {\n return {\n type: 'NumericLiteral',\n value,\n };\n }\n\n if (typeof value === 'boolean') {\n return {\n type: 'BooleanLiteral',\n value,\n };\n }\n\n if (value === null) {\n return {\n type: 'NullLiteral',\n };\n }\n\n if (value === undefined) {\n return {\n type: 'Identifier',\n name: 'undefined',\n };\n }\n\n return undefined;\n}\n\nfunction staticEvaluate(path: NodePath | null | undefined): void {\n if (!path) return;\n const evaluated = path.evaluate();\n if (evaluated.confident) {\n const node = getNodeForValue(evaluated.value);\n if (node) {\n applyAction(['replace', path, node]);\n return;\n }\n }\n\n if (path.isIfStatement()) {\n const test = path.get('test');\n if (!test.isBooleanLiteral()) {\n return;\n }\n\n const { consequent, alternate } = path.node;\n if (test.node.value) {\n applyAction(['replace', path, consequent]);\n } else if (alternate) {\n applyAction(['replace', path, alternate]);\n } else {\n applyAction(['remove', path]);\n }\n }\n}\n\nfunction applyAction(action: ReplaceAction | RemoveAction) {\n mutate(action[1], (p) => {\n if (isRemoved(p)) return;\n\n const parent = p.parentPath;\n\n if (action[0] === 'remove') {\n p.remove();\n }\n\n if (action[0] === 'replace') {\n p.replaceWith(action[2]);\n }\n\n staticEvaluate(parent);\n });\n}\n\nfunction removeWithRelated(paths: NodePath[]) {\n if (paths.length === 0) return;\n\n const rootPath = getScope(paths[0]).getProgramParent()\n .path as NodePath<Program>;\n\n if (!fixed.has(rootPath)) {\n // Some libraries don't care about bindings, references, and other staff\n // So we have to fix the scope before we can detect unused code\n referenceEnums(rootPath);\n fixed.add(rootPath);\n }\n\n const actions: (ReplaceAction | RemoveAction)[] = paths\n .map(findActionForNode)\n .filter(isNotNull);\n\n const affectedPaths = actions.map(getPathFromAction);\n\n let referencedIdentifiers = findIdentifiers(affectedPaths, 'reference');\n referencedIdentifiers.sort(\n (a, b) => a.node?.name.localeCompare(b.node?.name)\n );\n\n const referencesOfBinding = findIdentifiers(affectedPaths, 'declaration')\n .map((i) => (i.node && getScope(i).getBinding(i.node.name)) ?? null)\n .filter(isNotNull)\n .reduce(\n (acc, i) => [...acc, ...i.referencePaths.filter(nonType)],\n [] as NodePath[]\n )\n .filter(\n (ref) =>\n // Do not remove `export default function`\n !ref.isExportDefaultDeclaration() ||\n !ref.get('declaration').isFunctionDeclaration()\n );\n\n actions.forEach(applyAction);\n\n removeWithRelated(referencesOfBinding);\n\n let clean = false;\n while (!clean && referencedIdentifiers.length > 0) {\n const referenced = removeUnreferenced(referencedIdentifiers);\n clean =\n referenced.map((i) => i.node?.name).join('|') ===\n referencedIdentifiers.map((i) => i.node?.name).join('|');\n referencedIdentifiers = referenced;\n }\n}\n\nfunction mutate<T extends NodePath>(path: T, fn: (p: T) => NodePath[] | void) {\n const dereferenced = dereferenceAll(path);\n\n const mutated = fn(path);\n\n referenceAll(path);\n mutated?.forEach((p) => referenceAll(p));\n\n const dead = dereferenced.filter((p) => !isReferenced(p));\n\n const forDeleting: NodePath[] = [];\n dead.forEach((binding) => {\n const assignments = [binding.path, ...binding.constantViolations];\n assignments.forEach((assignment) => {\n const { scope } = assignment;\n const declared = Object.values(\n assignment.getOuterBindingIdentifiers(false)\n );\n if (\n declared.length === 1 &&\n 'name' in declared[0] &&\n declared[0].name === binding.identifier.name\n ) {\n const init = assignment.get('init');\n if (!Array.isArray(init) && init?.isAssignmentExpression()) {\n // `const a = b = 1` → `b = 1`\n assignment.parentPath?.replaceWith({\n type: 'ExpressionStatement',\n expression: init.node,\n });\n\n const left = init.get('left');\n if (left.isIdentifier()) {\n // If it was forcefully referenced in the shaker\n dereference(left);\n }\n\n return;\n }\n // Only one identifier is declared, so we can remove the whole declaration\n forDeleting.push(assignment);\n return;\n }\n\n if (\n declared.every(\n (identifier) =>\n identifier.type === 'Identifier' &&\n !scope.getBinding(identifier.name)?.referenced\n )\n ) {\n // No other identifier is referenced, so we can remove the whole declaration\n forDeleting.push(assignment);\n return;\n }\n\n // We can't remove the binding, but we can remove the part of it\n assignment.traverse({\n Identifier(identifier) {\n if (identifier.node.name === binding.identifier.name) {\n const parent = identifier.parentPath;\n if (\n parent.isArrayPattern() &&\n identifier.listKey === 'elements' &&\n typeof identifier.key === 'number'\n ) {\n parent.node.elements[identifier.key] = null;\n } else if (parent.isObjectProperty()) {\n forDeleting.push(parent);\n }\n }\n },\n });\n });\n });\n\n removeWithRelated(forDeleting);\n}\n\nexport { applyAction, mutate, removeWithRelated };\n"],"mappings":"AAAA;AACA;;AAWA,SAASA,WAAW,QAAQ,cAAc;AAE1C,SAASC,eAAe,EAAEC,OAAO,QAAQ,mBAAmB;AAC5D,SAASC,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,SAAS,QAAQ,aAAa;AAEvC,SAASC,aAAaA,CACpBC,IAAU,EACVC,GAAW,EACXC,GAAY,EACZC,KAAmB,EACnB;EACA,IAAI,EAAEA,KAAK,IAAI,IAAI,IAAIA,KAAK,CAACC,QAAQ,CAAC,EAAE,OAAO,IAAI;EACnD,IAAID,KAAK,CAACE,QAAQ,IAAIH,GAAG,IAAI,IAAI,EAAE,OAAO,IAAI;EAC9C,IAAI;IACFC,KAAK,CAACC,QAAQ,CAACJ,IAAI,EAAEC,GAAG,EAAEC,GAAG,CAAC;IAC9B,OAAO,IAAI;EACb,CAAC,CAAC,MAAM;IACN,OAAO,KAAK;EACd;AACF;AAEA,SAASI,UAAUA,CAACC,IAA0C,EAAE;EAC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CAACsD,MAAM,CAAC;YAC1B;UACF;QACF;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFuD,iBAAiB,CAACF,WAAW,CAAC;AAChC;AAEA,SAASa,WAAW,EAAEI,MAAM,EAAEf,iBAAiB","ignoreList":[]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const caches = new WeakMap();
|
|
2
|
-
export const getTraversalCache = (path, name) => {
|
|
3
|
-
const programPath = path.find(p => p.isProgram());
|
|
4
|
-
if (!programPath) {
|
|
5
|
-
throw new Error(`Could not find program for ${path.node.type}`);
|
|
6
|
-
}
|
|
7
|
-
if (!caches.has(programPath)) {
|
|
8
|
-
caches.set(programPath, new Map());
|
|
9
|
-
}
|
|
10
|
-
const cache = caches.get(programPath);
|
|
11
|
-
if (!cache.has(name)) {
|
|
12
|
-
cache.set(name, new WeakMap());
|
|
13
|
-
}
|
|
14
|
-
return cache.get(name);
|
|
15
|
-
};
|
|
16
|
-
export const invalidateTraversalCache = path => {
|
|
17
|
-
const programPath = path.find(p => p.isProgram());
|
|
18
|
-
if (!programPath) {
|
|
19
|
-
throw new Error(`Could not find program for ${path.node.type}`);
|
|
20
|
-
}
|
|
21
|
-
caches.delete(programPath);
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=traversalCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"traversalCache.js","names":["caches","WeakMap","getTraversalCache","path","name","programPath","find","p","isProgram","Error","node","type","has","set","Map","cache","get","invalidateTraversalCache","delete"],"sources":["../../src/utils/traversalCache.ts"],"sourcesContent":["import type { NodePath } from '@babel/traverse';\nimport type { Node } from '@babel/types';\n\nconst caches = new WeakMap<\n NodePath,\n Map<string, WeakMap<NodePath | Node, unknown>>\n>();\n\nexport const getTraversalCache = <\n TValue,\n TKey extends NodePath | Node = NodePath,\n>(\n path: NodePath,\n name: string\n) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n if (!caches.has(programPath)) {\n caches.set(programPath, new Map());\n }\n\n const cache = caches.get(programPath)!;\n if (!cache.has(name)) {\n cache.set(name, new WeakMap());\n }\n\n return cache.get(name) as WeakMap<TKey, TValue>;\n};\n\nexport const invalidateTraversalCache = (path: NodePath) => {\n const programPath = path.find((p) => p.isProgram());\n if (!programPath) {\n throw new Error(`Could not find program for ${path.node.type}`);\n }\n\n caches.delete(programPath);\n};\n"],"mappings":"AAGA,MAAMA,MAAM,GAAG,IAAIC,OAAO,CAGxB,CAAC;AAEH,OAAO,MAAMC,iBAAiB,GAAGA,CAI/BC,IAAc,EACdC,IAAY,KACT;EACH,MAAMC,WAAW,GAAGF,IAAI,CAACG,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,SAAS,CAAC,CAAC,CAAC;EACnD,IAAI,CAACH,WAAW,EAAE;IAChB,MAAM,IAAII,KAAK,CAAC,8BAA8BN,IAAI,CAACO,IAAI,CAACC,IAAI,EAAE,CAAC;EACjE;EAEA,IAAI,CAACX,MAAM,CAACY,GAAG,CAACP,WAAW,CAAC,EAAE;IAC5BL,MAAM,CAACa,GAAG,CAACR,WAAW,EAAE,IAAIS,GAAG,CAAC,CAAC,CAAC;EACpC;EAEA,MAAMC,KAAK,GAAGf,MAAM,CAACgB,GAAG,CAACX,WAAW,CAAE;EACtC,IAAI,CAACU,KAAK,CAACH,GAAG,CAACR,IAAI,CAAC,EAAE;IACpBW,KAAK,CAACF,GAAG,CAACT,IAAI,EAAE,IAAIH,OAAO,CAAC,CAAC,CAAC;EAChC;EAEA,OAAOc,KAAK,CAACC,GAAG,CAACZ,IAAI,CAAC;AACxB,CAAC;AAED,OAAO,MAAMa,wBAAwB,GAAId,IAAc,IAAK;EAC1D,MAAME,WAAW,GAAGF,IAAI,CAACG,IAAI,CAAEC,CAAC,IAAKA,CAAC,CAACC,SAAS,CAAC,CAAC,CAAC;EACnD,IAAI,CAACH,WAAW,EAAE;IAChB,MAAM,IAAII,KAAK,CAAC,8BAA8BN,IAAI,CAACO,IAAI,CAACC,IAAI,EAAE,CAAC;EACjE;EAEAX,MAAM,CAACkB,MAAM,CAACb,WAAW,CAAC;AAC5B,CAAC","ignoreList":[]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
const unwrapOnce = node => {
|
|
3
|
-
if (t.isTSAsExpression(node)) return node.expression;
|
|
4
|
-
if (t.isTSTypeAssertion(node)) return node.expression;
|
|
5
|
-
if (t.isTSNonNullExpression(node)) return node.expression;
|
|
6
|
-
if (t.isParenthesizedExpression(node)) return node.expression;
|
|
7
|
-
return node;
|
|
8
|
-
};
|
|
9
|
-
export function unwrapExpression(node) {
|
|
10
|
-
let current = node;
|
|
11
|
-
let next = unwrapOnce(current);
|
|
12
|
-
while (next !== current) {
|
|
13
|
-
current = next;
|
|
14
|
-
next = unwrapOnce(current);
|
|
15
|
-
}
|
|
16
|
-
return current;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=unwrapExpression.js.map
|