@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,326 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeDangerousCode = void 0;
|
|
4
|
-
const core_1 = require("@babel/core");
|
|
5
|
-
const findIdentifiers_1 = require("./findIdentifiers");
|
|
6
|
-
const isUnnecessaryReactCall_1 = require("./isUnnecessaryReactCall");
|
|
7
|
-
const scopeHelpers_1 = require("./scopeHelpers");
|
|
8
|
-
const JSXElementsRemover_1 = require("./visitors/JSXElementsRemover");
|
|
9
|
-
const collectExportsAndImports_1 = require("./collectExportsAndImports");
|
|
10
|
-
const isGlobal = (id) => {
|
|
11
|
-
if (!(0, findIdentifiers_1.nonType)(id)) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const { scope } = id;
|
|
15
|
-
const { name } = id.node;
|
|
16
|
-
return !scope.hasBinding(name) && scope.hasGlobal(name);
|
|
17
|
-
};
|
|
18
|
-
const ssrCheckFields = new Set([
|
|
19
|
-
'document',
|
|
20
|
-
'location',
|
|
21
|
-
'navigator',
|
|
22
|
-
'sessionStorage',
|
|
23
|
-
'localStorage',
|
|
24
|
-
'window',
|
|
25
|
-
]);
|
|
26
|
-
const forbiddenGlobals = new Set([
|
|
27
|
-
...ssrCheckFields,
|
|
28
|
-
'$RefreshReg$',
|
|
29
|
-
'$RefreshSig$',
|
|
30
|
-
'XMLHttpRequest',
|
|
31
|
-
'clearImmediate',
|
|
32
|
-
'clearInterval',
|
|
33
|
-
'clearTimeout',
|
|
34
|
-
'fetch',
|
|
35
|
-
'navigator',
|
|
36
|
-
'setImmediate',
|
|
37
|
-
'setInterval',
|
|
38
|
-
'setTimeout',
|
|
39
|
-
]);
|
|
40
|
-
const alwaysForbiddenIdentifiers = new Set(['$RefreshReg$', '$RefreshSig$']);
|
|
41
|
-
const isBrowserGlobal = (id) => {
|
|
42
|
-
const { name } = id.node;
|
|
43
|
-
if (alwaysForbiddenIdentifiers.has(name)) {
|
|
44
|
-
return (0, findIdentifiers_1.nonType)(id);
|
|
45
|
-
}
|
|
46
|
-
return forbiddenGlobals.has(name) && isGlobal(id);
|
|
47
|
-
};
|
|
48
|
-
const isSSRCheckField = (id) => {
|
|
49
|
-
return ssrCheckFields.has(id.node.name) && isGlobal(id);
|
|
50
|
-
};
|
|
51
|
-
const promiseCallbackMethods = new Set(['then', 'catch', 'finally']);
|
|
52
|
-
const getPropertyName = (path) => {
|
|
53
|
-
if (path.isIdentifier()) {
|
|
54
|
-
return path.node.name;
|
|
55
|
-
}
|
|
56
|
-
if (path.isStringLiteral()) {
|
|
57
|
-
return path.node.value;
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
};
|
|
61
|
-
const isPromiseCallbackArgument = (path, ref) => {
|
|
62
|
-
return path
|
|
63
|
-
.get('arguments')
|
|
64
|
-
.some((arg) => arg === ref || arg.isAncestor(ref));
|
|
65
|
-
};
|
|
66
|
-
const findPromiseCallbackOwner = (path) => {
|
|
67
|
-
const owner = path.findParent((parent) => {
|
|
68
|
-
if (parent.isNewExpression()) {
|
|
69
|
-
const callee = parent.get('callee');
|
|
70
|
-
return (callee.isIdentifier({ name: 'Promise' }) &&
|
|
71
|
-
isPromiseCallbackArgument(parent, path));
|
|
72
|
-
}
|
|
73
|
-
if (parent.isCallExpression()) {
|
|
74
|
-
const callee = parent.get('callee');
|
|
75
|
-
if (!callee.isMemberExpression())
|
|
76
|
-
return false;
|
|
77
|
-
const propName = getPropertyName(callee.get('property'));
|
|
78
|
-
return (propName !== null &&
|
|
79
|
-
promiseCallbackMethods.has(propName) &&
|
|
80
|
-
isPromiseCallbackArgument(parent, path));
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
});
|
|
84
|
-
return owner;
|
|
85
|
-
};
|
|
86
|
-
const removeForbiddenGlobal = (path) => {
|
|
87
|
-
const promiseOwner = findPromiseCallbackOwner(path);
|
|
88
|
-
if (promiseOwner) {
|
|
89
|
-
(0, scopeHelpers_1.removeWithRelated)([promiseOwner]);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
(0, scopeHelpers_1.removeWithRelated)([path]);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const getImport = (path) => {
|
|
96
|
-
const programPath = path.findParent((p) => p.isProgram());
|
|
97
|
-
if (!programPath) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
const { imports } = (0, collectExportsAndImports_1.collectExportsAndImports)(programPath);
|
|
101
|
-
if (path.isIdentifier()) {
|
|
102
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
103
|
-
const matched = binding &&
|
|
104
|
-
imports.find((imp) => imp.imported !== 'side-effect' && binding.path.isAncestor(imp.local));
|
|
105
|
-
if (matched) {
|
|
106
|
-
return [matched.source, matched.imported];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (path.isMemberExpression()) {
|
|
110
|
-
const leftPath = path.get('object');
|
|
111
|
-
if (!leftPath.isIdentifier()) {
|
|
112
|
-
// Nested member expression. Not supported yet.
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
const rightPath = path.get('property');
|
|
116
|
-
if (!rightPath.isIdentifier()) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
const binding = path.scope.getBinding(leftPath.node.name);
|
|
120
|
-
const matched = binding &&
|
|
121
|
-
imports.find((imp) => imp.imported !== 'side-effect' && binding.path.isAncestor(imp.local));
|
|
122
|
-
if (matched) {
|
|
123
|
-
return [matched.source, rightPath.node.name];
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return undefined;
|
|
127
|
-
};
|
|
128
|
-
const getTypeImport = (path) => {
|
|
129
|
-
// We are looking for either Identifier or TSQualifiedName in path
|
|
130
|
-
if (path.isIdentifier()) {
|
|
131
|
-
const binding = path.scope.getBinding(path.node.name);
|
|
132
|
-
if (!binding) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
if (!binding.path.isImportSpecifier() ||
|
|
136
|
-
!binding.path.parentPath.isImportDeclaration()) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
const importDeclaration = binding.path.parentPath;
|
|
140
|
-
const imported = binding.path.get('imported');
|
|
141
|
-
const source = importDeclaration.node.source.value;
|
|
142
|
-
const importedNode = imported.node;
|
|
143
|
-
return [
|
|
144
|
-
source,
|
|
145
|
-
core_1.types.isIdentifier(importedNode) ? importedNode.name : importedNode.value,
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
if (path.isTSQualifiedName()) {
|
|
149
|
-
const leftPath = path.get('left');
|
|
150
|
-
if (!leftPath.isIdentifier()) {
|
|
151
|
-
// Nested type. Not supported yet.
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
const rightPath = path.get('right');
|
|
155
|
-
const binding = path.scope.getBinding(leftPath.node.name);
|
|
156
|
-
if (!binding) {
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
if ((!binding.path.isImportDefaultSpecifier() &&
|
|
160
|
-
!binding.path.isImportNamespaceSpecifier()) ||
|
|
161
|
-
!binding.path.parentPath.isImportDeclaration()) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
return [binding.path.parentPath.node.source.value, rightPath.node.name];
|
|
165
|
-
}
|
|
166
|
-
return undefined;
|
|
167
|
-
};
|
|
168
|
-
const isTypeMatch = (id, types) => {
|
|
169
|
-
const typeAnnotation = id.get('typeAnnotation');
|
|
170
|
-
if (!typeAnnotation.isTSTypeAnnotation()) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
const typeReference = typeAnnotation.get('typeAnnotation');
|
|
174
|
-
if (!typeReference.isTSTypeReference()) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
const typeName = typeReference.get('typeName');
|
|
178
|
-
const matchedImport = getTypeImport(typeName);
|
|
179
|
-
return (matchedImport !== undefined &&
|
|
180
|
-
matchedImport[0] in types &&
|
|
181
|
-
types[matchedImport[0]].includes(matchedImport[1]));
|
|
182
|
-
};
|
|
183
|
-
const isHOC = (path, hocs) => {
|
|
184
|
-
let calleePath = path;
|
|
185
|
-
while (calleePath.isCallExpression()) {
|
|
186
|
-
calleePath = calleePath.get('callee');
|
|
187
|
-
}
|
|
188
|
-
const matchedImport = getImport(calleePath);
|
|
189
|
-
return (matchedImport !== undefined &&
|
|
190
|
-
matchedImport[0] in hocs &&
|
|
191
|
-
hocs[matchedImport[0]].includes(matchedImport[1]));
|
|
192
|
-
};
|
|
193
|
-
const defaultPlaceholder = '...';
|
|
194
|
-
const defaultReactComponentTypes = [
|
|
195
|
-
'ExoticComponent',
|
|
196
|
-
'FC',
|
|
197
|
-
'ForwardRefExoticComponent',
|
|
198
|
-
'FunctionComponent',
|
|
199
|
-
'LazyExoticComponent',
|
|
200
|
-
'MemoExoticComponent',
|
|
201
|
-
'NamedExoticComponent',
|
|
202
|
-
];
|
|
203
|
-
const removeDangerousCode = (programPath, options) => {
|
|
204
|
-
const hocs = options?.hocs ?? {};
|
|
205
|
-
const componentTypes = options?.componentTypes ?? {
|
|
206
|
-
react: [defaultPlaceholder],
|
|
207
|
-
};
|
|
208
|
-
if (Array.isArray(componentTypes.react) &&
|
|
209
|
-
componentTypes.react.includes(defaultPlaceholder)) {
|
|
210
|
-
const idx = componentTypes.react.indexOf(defaultPlaceholder);
|
|
211
|
-
componentTypes.react = [...componentTypes.react];
|
|
212
|
-
componentTypes.react.splice(idx, 1, ...defaultReactComponentTypes);
|
|
213
|
-
}
|
|
214
|
-
programPath.traverse({
|
|
215
|
-
// JSX can be replaced with a dummy value,
|
|
216
|
-
// but we have to do it after we processed template tags.
|
|
217
|
-
CallExpression: {
|
|
218
|
-
enter(p) {
|
|
219
|
-
if ((0, isUnnecessaryReactCall_1.isUnnecessaryReactCall)(p)) {
|
|
220
|
-
(0, JSXElementsRemover_1.JSXElementsRemover)(p);
|
|
221
|
-
}
|
|
222
|
-
if (isHOC(p, hocs)) {
|
|
223
|
-
(0, scopeHelpers_1.applyAction)([
|
|
224
|
-
'replace',
|
|
225
|
-
p,
|
|
226
|
-
core_1.types.arrowFunctionExpression([], core_1.types.nullLiteral()),
|
|
227
|
-
]);
|
|
228
|
-
}
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
JSXElement: {
|
|
232
|
-
enter: JSXElementsRemover_1.JSXElementsRemover,
|
|
233
|
-
},
|
|
234
|
-
JSXFragment: {
|
|
235
|
-
enter: JSXElementsRemover_1.JSXElementsRemover,
|
|
236
|
-
},
|
|
237
|
-
MemberExpression(p, state) {
|
|
238
|
-
const obj = p.get('object');
|
|
239
|
-
const prop = p.get('property');
|
|
240
|
-
if (!obj.isIdentifier({ name: 'window' })) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
const name = getPropertyName(prop);
|
|
244
|
-
if (!name) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
state.windowScoped.add(name);
|
|
248
|
-
// eslint-disable-next-line no-param-reassign
|
|
249
|
-
state.globals = state.globals.filter((id) => {
|
|
250
|
-
if (id.node.name === name) {
|
|
251
|
-
(0, scopeHelpers_1.removeWithRelated)([id]);
|
|
252
|
-
return false;
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
255
|
-
});
|
|
256
|
-
},
|
|
257
|
-
MetaProperty(p) {
|
|
258
|
-
// Remove all references to `import.meta`
|
|
259
|
-
(0, scopeHelpers_1.removeWithRelated)([p]);
|
|
260
|
-
},
|
|
261
|
-
Identifier(p, state) {
|
|
262
|
-
if (p.find((parent) => parent.isTSTypeReference())) {
|
|
263
|
-
// don't mess with TS type references
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (isBrowserGlobal(p)) {
|
|
267
|
-
if (p.find((parentPath) => parentPath.isUnaryExpression({ operator: 'typeof' }) ||
|
|
268
|
-
parentPath.isTSTypeQuery())) {
|
|
269
|
-
// Ignore `typeof window` expressions
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (p.parentPath.isClassProperty()) {
|
|
273
|
-
// ignore class property decls
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if (p.parentPath.isMemberExpression() && p.key === 'property') {
|
|
277
|
-
// ignore e.g this.fetch()
|
|
278
|
-
// window.fetch will be handled by the windowScoped block below
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
removeForbiddenGlobal(p);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
if (state.windowScoped.has(p.node.name)) {
|
|
285
|
-
removeForbiddenGlobal(p);
|
|
286
|
-
}
|
|
287
|
-
else if (isGlobal(p)) {
|
|
288
|
-
state.globals.push(p);
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
// Since we can use happy-dom, typical SSR checks may not work as expected.
|
|
292
|
-
// We need to detect them and replace with an "undefined" literal.
|
|
293
|
-
UnaryExpression(p) {
|
|
294
|
-
if (p.node.operator !== 'typeof') {
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const arg = p.get('argument');
|
|
298
|
-
if (!arg.isIdentifier() || !isSSRCheckField(arg)) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
(0, scopeHelpers_1.applyAction)([
|
|
302
|
-
'replace',
|
|
303
|
-
p,
|
|
304
|
-
{ type: 'StringLiteral', value: 'undefined' },
|
|
305
|
-
]);
|
|
306
|
-
},
|
|
307
|
-
VariableDeclarator(p) {
|
|
308
|
-
const id = p.get('id');
|
|
309
|
-
const init = p.get('init');
|
|
310
|
-
if (id.isIdentifier() &&
|
|
311
|
-
isTypeMatch(id, componentTypes) &&
|
|
312
|
-
init.isExpression()) {
|
|
313
|
-
// Variable is typed as a React component. We can replace its value with a null-function.
|
|
314
|
-
(0, scopeHelpers_1.applyAction)([
|
|
315
|
-
'replace',
|
|
316
|
-
init,
|
|
317
|
-
core_1.types.arrowFunctionExpression([], core_1.types.nullLiteral()),
|
|
318
|
-
]);
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
}, {
|
|
322
|
-
globals: [],
|
|
323
|
-
windowScoped: new Set(),
|
|
324
|
-
});
|
|
325
|
-
};
|
|
326
|
-
exports.removeDangerousCode = removeDangerousCode;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceImportMetaEnv = replaceImportMetaEnv;
|
|
4
|
-
const IMPORT_META_ENV = '__wyw_import_meta_env';
|
|
5
|
-
const isRecord = (obj) => typeof obj === 'object' && obj !== null;
|
|
6
|
-
function isImportMeta(obj) {
|
|
7
|
-
if (!isRecord(obj)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const { meta, property } = obj;
|
|
11
|
-
if (!isRecord(meta) || !isRecord(property)) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return meta.name === 'import' && property.name === 'meta';
|
|
15
|
-
}
|
|
16
|
-
function isImportMetaEnv(node) {
|
|
17
|
-
const { computed, object, property } = node;
|
|
18
|
-
if (computed) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (!isImportMeta(object)) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
return property.type === 'Identifier' && property.name === 'env';
|
|
25
|
-
}
|
|
26
|
-
function replaceImportMetaEnv(programPath, t) {
|
|
27
|
-
programPath.traverse({
|
|
28
|
-
MemberExpression(path) {
|
|
29
|
-
if (isImportMetaEnv(path.node)) {
|
|
30
|
-
path.replaceWith(t.identifier(IMPORT_META_ENV));
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
OptionalMemberExpression(path) {
|
|
34
|
-
if (isImportMetaEnv(path.node)) {
|
|
35
|
-
path.replaceWith(t.identifier(IMPORT_META_ENV));
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Binding, NodePath } from '@babel/traverse';
|
|
2
|
-
import type { Identifier, JSXIdentifier, Node } from '@babel/types';
|
|
3
|
-
export declare function reference(path: NodePath<Identifier | JSXIdentifier>, referencePath?: NodePath, force?: boolean): void;
|
|
4
|
-
export declare function dereference(path: NodePath<Identifier | JSXIdentifier>): Binding | null;
|
|
5
|
-
export declare function referenceAll(path: NodePath): void;
|
|
6
|
-
type ReplaceAction = [action: 'replace', what: NodePath, by: Node];
|
|
7
|
-
type RemoveAction = [action: 'remove', what: NodePath];
|
|
8
|
-
export declare function findActionForNode(path: NodePath): RemoveAction | ReplaceAction | null;
|
|
9
|
-
declare function applyAction(action: ReplaceAction | RemoveAction): void;
|
|
10
|
-
declare function removeWithRelated(paths: NodePath[]): void;
|
|
11
|
-
declare function mutate<T extends NodePath>(path: T, fn: (p: T) => NodePath[] | void): void;
|
|
12
|
-
export { applyAction, mutate, removeWithRelated };
|