@wyw-in-js/transform 0.8.0 → 1.0.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/babel.js.map +1 -1
- package/esm/cache.js +15 -4
- package/esm/cache.js.map +1 -1
- package/esm/debug/fileReporter.js.map +1 -1
- package/esm/evaluators/index.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/module.js +174 -15
- package/esm/module.js.map +1 -1
- package/esm/options/buildOptions.js +123 -4
- package/esm/options/buildOptions.js.map +1 -1
- package/esm/options/buildOptions.test.js +41 -0
- package/esm/options/buildOptions.test.js.map +1 -0
- package/esm/options/loadBabelOptions.js.map +1 -1
- package/esm/plugins/babel-transform.js.map +1 -1
- package/esm/plugins/collector.js.map +1 -1
- package/esm/plugins/dynamic-import.js +35 -12
- package/esm/plugins/dynamic-import.js.map +1 -1
- package/esm/plugins/preeval.js +4 -0
- package/esm/plugins/preeval.js.map +1 -1
- package/esm/plugins/shaker.js +170 -23
- package/esm/plugins/shaker.js.map +1 -1
- package/esm/shaker.js +6 -3
- package/esm/shaker.js.map +1 -1
- package/esm/transform/BaseEntrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.helpers.js +105 -15
- package/esm/transform/Entrypoint.helpers.js.map +1 -1
- package/esm/transform/Entrypoint.js +13 -2
- package/esm/transform/Entrypoint.js.map +1 -1
- package/esm/transform/Entrypoint.types.js.map +1 -1
- package/esm/transform/EvaluatedEntrypoint.js.map +1 -1
- package/esm/transform/actions/AbortError.js.map +1 -1
- package/esm/transform/actions/BaseAction.js +5 -0
- package/esm/transform/actions/BaseAction.js.map +1 -1
- package/esm/transform/actions/UnprocessedEntrypointError.js.map +1 -1
- package/esm/transform/actions/actionRunner.js.map +1 -1
- package/esm/transform/actions/types.js.map +1 -1
- package/esm/transform/generators/baseProcessingHandlers.js.map +1 -1
- package/esm/transform/generators/collect.js.map +1 -1
- package/esm/transform/generators/createStylisPreprocessor.js +118 -2
- package/esm/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/esm/transform/generators/evalFile.js.map +1 -1
- package/esm/transform/generators/explodeReexports.js +10 -10
- package/esm/transform/generators/explodeReexports.js.map +1 -1
- package/esm/transform/generators/extract.js.map +1 -1
- package/esm/transform/generators/getExports.js.map +1 -1
- package/esm/transform/generators/index.js.map +1 -1
- package/esm/transform/generators/processEntrypoint.js +5 -8
- package/esm/transform/generators/processEntrypoint.js.map +1 -1
- package/esm/transform/generators/processImports.js.map +1 -1
- package/esm/transform/generators/resolveImports.js +41 -2
- package/esm/transform/generators/resolveImports.js.map +1 -1
- package/esm/transform/generators/transform.js +7 -3
- package/esm/transform/generators/transform.js.map +1 -1
- package/esm/transform/generators/workflow.js.map +1 -1
- package/esm/transform/helpers/loadWywOptions.js +15 -2
- package/esm/transform/helpers/loadWywOptions.js.map +1 -1
- package/esm/transform/helpers/withDefaultServices.js +2 -0
- package/esm/transform/helpers/withDefaultServices.js.map +1 -1
- package/esm/transform/isStaticallyEvaluatableModule.js +153 -0
- package/esm/transform/isStaticallyEvaluatableModule.js.map +1 -0
- package/esm/transform/rootLog.js.map +1 -1
- package/esm/transform/types.js.map +1 -1
- package/esm/transform.js +15 -6
- package/esm/transform.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/EventEmitter.js.map +1 -1
- package/esm/utils/ShakerMetadata.js.map +1 -1
- package/esm/utils/TransformMetadata.js.map +1 -1
- package/esm/utils/addIdentifierToWywPreval.js.map +1 -1
- package/esm/utils/collectExportsAndImports.js +97 -6
- package/esm/utils/collectExportsAndImports.js.map +1 -1
- package/esm/utils/collectTemplateDependencies.js +1 -1
- package/esm/utils/collectTemplateDependencies.js.map +1 -1
- package/esm/utils/createId.js.map +1 -1
- package/esm/utils/dispose-polyfill.js.map +1 -1
- package/esm/utils/findIdentifiers.js.map +1 -1
- package/esm/utils/getConstantStringValue.js +58 -0
- package/esm/utils/getConstantStringValue.js.map +1 -0
- package/esm/utils/getFileIdx.js.map +1 -1
- package/esm/utils/getMemberExpressionPropertyName.js +11 -0
- package/esm/utils/getMemberExpressionPropertyName.js.map +1 -0
- package/esm/utils/getPluginKey.js.map +1 -1
- package/esm/utils/getScope.js.map +1 -1
- package/esm/utils/getSource.js.map +1 -1
- package/esm/utils/getTagProcessor.js +34 -6
- package/esm/utils/getTagProcessor.js.map +1 -1
- package/esm/utils/getVisitorKeys.js.map +1 -1
- package/esm/utils/hasWywPreval.js.map +1 -1
- package/esm/utils/importOverrides.js +47 -0
- package/esm/utils/importOverrides.js.map +1 -0
- package/esm/utils/isExports.js.map +1 -1
- package/esm/utils/isGlobal.js.map +1 -1
- package/esm/utils/isNode.js.map +1 -1
- package/esm/utils/isNodePath.js.map +1 -1
- package/esm/utils/isNotNull.js.map +1 -1
- package/esm/utils/isRemoved.js.map +1 -1
- package/esm/utils/isRequire.js.map +1 -1
- package/esm/utils/isSerializable.js.map +1 -1
- package/esm/utils/isTypedNode.js.map +1 -1
- package/esm/utils/isUnnecessaryReactCall.js.map +1 -1
- package/esm/utils/parseRequest.js +29 -0
- package/esm/utils/parseRequest.js.map +1 -0
- package/esm/utils/peek.js.map +1 -1
- package/esm/utils/removeDangerousCode.js +32 -2
- package/esm/utils/removeDangerousCode.js.map +1 -1
- package/esm/utils/replaceImportMetaEnv.js +44 -0
- package/esm/utils/replaceImportMetaEnv.js.map +1 -0
- package/esm/utils/scopeHelpers.js.map +1 -1
- package/esm/utils/traversalCache.js.map +1 -1
- package/esm/utils/unwrapExpression.js +18 -0
- package/esm/utils/unwrapExpression.js.map +1 -0
- package/esm/utils/unwrapSequence.js.map +1 -1
- package/esm/utils/valueToLiteral.js.map +1 -1
- package/esm/utils/visitors/JSXElementsRemover.js.map +1 -1
- package/esm/vm/createVmContext.js +44 -0
- package/esm/vm/createVmContext.js.map +1 -1
- package/esm/vm/process.js.map +1 -1
- package/lib/babel.js.map +1 -1
- package/lib/cache.js +16 -5
- package/lib/cache.js.map +1 -1
- package/lib/debug/fileReporter.js +1 -1
- package/lib/debug/fileReporter.js.map +1 -1
- package/lib/evaluators/index.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/module.js +177 -16
- package/lib/module.js.map +1 -1
- package/lib/options/buildOptions.js +127 -6
- package/lib/options/buildOptions.js.map +1 -1
- package/lib/options/buildOptions.test.js +44 -0
- package/lib/options/buildOptions.test.js.map +1 -0
- package/lib/options/loadBabelOptions.js.map +1 -1
- package/lib/plugins/babel-transform.js.map +1 -1
- package/lib/plugins/collector.js.map +1 -1
- package/lib/plugins/dynamic-import.js +34 -12
- package/lib/plugins/dynamic-import.js.map +1 -1
- package/lib/plugins/preeval.js +4 -0
- package/lib/plugins/preeval.js.map +1 -1
- package/lib/plugins/shaker.js +172 -22
- package/lib/plugins/shaker.js.map +1 -1
- package/lib/shaker.js +8 -4
- package/lib/shaker.js.map +1 -1
- package/lib/transform/BaseEntrypoint.js.map +1 -1
- package/lib/transform/Entrypoint.helpers.js +106 -15
- package/lib/transform/Entrypoint.helpers.js.map +1 -1
- package/lib/transform/Entrypoint.js +13 -2
- package/lib/transform/Entrypoint.js.map +1 -1
- package/lib/transform/Entrypoint.types.js.map +1 -1
- package/lib/transform/EvaluatedEntrypoint.js.map +1 -1
- package/lib/transform/actions/AbortError.js.map +1 -1
- package/lib/transform/actions/BaseAction.js +5 -0
- package/lib/transform/actions/BaseAction.js.map +1 -1
- package/lib/transform/actions/UnprocessedEntrypointError.js.map +1 -1
- package/lib/transform/actions/actionRunner.js.map +1 -1
- package/lib/transform/actions/types.js.map +1 -1
- package/lib/transform/generators/baseProcessingHandlers.js.map +1 -1
- package/lib/transform/generators/collect.js.map +1 -1
- package/lib/transform/generators/createStylisPreprocessor.js +119 -3
- package/lib/transform/generators/createStylisPreprocessor.js.map +1 -1
- package/lib/transform/generators/evalFile.js +1 -1
- package/lib/transform/generators/evalFile.js.map +1 -1
- package/lib/transform/generators/explodeReexports.js +11 -11
- package/lib/transform/generators/explodeReexports.js.map +1 -1
- package/lib/transform/generators/extract.js.map +1 -1
- package/lib/transform/generators/getExports.js.map +1 -1
- package/lib/transform/generators/index.js.map +1 -1
- package/lib/transform/generators/processEntrypoint.js +5 -8
- package/lib/transform/generators/processEntrypoint.js.map +1 -1
- package/lib/transform/generators/processImports.js.map +1 -1
- package/lib/transform/generators/resolveImports.js +41 -2
- package/lib/transform/generators/resolveImports.js.map +1 -1
- package/lib/transform/generators/transform.js +8 -3
- package/lib/transform/generators/transform.js.map +1 -1
- package/lib/transform/generators/workflow.js.map +1 -1
- package/lib/transform/helpers/loadWywOptions.js +16 -2
- package/lib/transform/helpers/loadWywOptions.js.map +1 -1
- package/lib/transform/helpers/withDefaultServices.js +3 -2
- package/lib/transform/helpers/withDefaultServices.js.map +1 -1
- package/lib/transform/isStaticallyEvaluatableModule.js +159 -0
- package/lib/transform/isStaticallyEvaluatableModule.js.map +1 -0
- package/lib/transform/rootLog.js.map +1 -1
- package/lib/transform/types.js.map +1 -1
- package/lib/transform.js +15 -6
- package/lib/transform.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/EventEmitter.js.map +1 -1
- package/lib/utils/ShakerMetadata.js.map +1 -1
- package/lib/utils/TransformMetadata.js.map +1 -1
- package/lib/utils/addIdentifierToWywPreval.js.map +1 -1
- package/lib/utils/collectExportsAndImports.js +97 -6
- package/lib/utils/collectExportsAndImports.js.map +1 -1
- package/lib/utils/collectTemplateDependencies.js +1 -1
- package/lib/utils/collectTemplateDependencies.js.map +1 -1
- package/lib/utils/createId.js.map +1 -1
- package/lib/utils/dispose-polyfill.js.map +1 -1
- package/lib/utils/findIdentifiers.js.map +1 -1
- package/lib/utils/getConstantStringValue.js +66 -0
- package/lib/utils/getConstantStringValue.js.map +1 -0
- package/lib/utils/getFileIdx.js.map +1 -1
- package/lib/utils/getMemberExpressionPropertyName.js +18 -0
- package/lib/utils/getMemberExpressionPropertyName.js.map +1 -0
- package/lib/utils/getPluginKey.js.map +1 -1
- package/lib/utils/getScope.js.map +1 -1
- package/lib/utils/getSource.js +1 -1
- package/lib/utils/getSource.js.map +1 -1
- package/lib/utils/getTagProcessor.js +33 -6
- package/lib/utils/getTagProcessor.js.map +1 -1
- package/lib/utils/getVisitorKeys.js.map +1 -1
- package/lib/utils/hasWywPreval.js.map +1 -1
- package/lib/utils/importOverrides.js +57 -0
- package/lib/utils/importOverrides.js.map +1 -0
- package/lib/utils/isExports.js.map +1 -1
- package/lib/utils/isGlobal.js.map +1 -1
- package/lib/utils/isNode.js.map +1 -1
- package/lib/utils/isNodePath.js.map +1 -1
- package/lib/utils/isNotNull.js.map +1 -1
- package/lib/utils/isRemoved.js.map +1 -1
- package/lib/utils/isRequire.js.map +1 -1
- package/lib/utils/isSerializable.js.map +1 -1
- package/lib/utils/isTypedNode.js.map +1 -1
- package/lib/utils/isUnnecessaryReactCall.js.map +1 -1
- package/lib/utils/parseRequest.js +37 -0
- package/lib/utils/parseRequest.js.map +1 -0
- package/lib/utils/peek.js.map +1 -1
- package/lib/utils/removeDangerousCode.js +32 -2
- package/lib/utils/removeDangerousCode.js.map +1 -1
- package/lib/utils/replaceImportMetaEnv.js +50 -0
- package/lib/utils/replaceImportMetaEnv.js.map +1 -0
- package/lib/utils/scopeHelpers.js.map +1 -1
- package/lib/utils/traversalCache.js.map +1 -1
- package/lib/utils/unwrapExpression.js +25 -0
- package/lib/utils/unwrapExpression.js.map +1 -0
- package/lib/utils/unwrapSequence.js.map +1 -1
- package/lib/utils/valueToLiteral.js.map +1 -1
- package/lib/utils/visitors/JSXElementsRemover.js.map +1 -1
- package/lib/vm/createVmContext.js +45 -2
- package/lib/vm/createVmContext.js.map +1 -1
- package/lib/vm/process.js.map +1 -1
- package/package.json +13 -15
- package/types/cache.d.ts +1 -1
- package/types/cache.js +15 -4
- package/types/evaluators/index.js +1 -1
- package/types/module.d.ts +1 -2
- package/types/module.js +189 -11
- package/types/options/buildOptions.d.ts +0 -1
- package/types/options/buildOptions.js +125 -9
- package/types/options/loadBabelOptions.js +1 -2
- package/types/plugins/babel-transform.js +1 -1
- package/types/plugins/collector.js +3 -3
- package/types/plugins/dynamic-import.js +38 -18
- package/types/plugins/preeval.js +5 -2
- package/types/plugins/shaker.d.ts +4 -1
- package/types/plugins/shaker.js +189 -24
- package/types/shaker.js +9 -3
- package/types/transform/BaseEntrypoint.d.ts +0 -1
- package/types/transform/Entrypoint.helpers.d.ts +0 -1
- package/types/transform/Entrypoint.helpers.js +122 -25
- package/types/transform/Entrypoint.js +14 -2
- package/types/transform/Entrypoint.types.d.ts +0 -1
- package/types/transform/EvaluatedEntrypoint.d.ts +0 -1
- package/types/transform/actions/BaseAction.d.ts +1 -1
- package/types/transform/actions/BaseAction.js +5 -0
- package/types/transform/actions/actionRunner.js +2 -3
- package/types/transform/generators/collect.js +1 -2
- package/types/transform/generators/createStylisPreprocessor.d.ts +0 -1
- package/types/transform/generators/createStylisPreprocessor.js +168 -13
- package/types/transform/generators/evalFile.js +1 -2
- package/types/transform/generators/explodeReexports.js +12 -15
- package/types/transform/generators/extract.js +1 -2
- package/types/transform/generators/getExports.js +2 -3
- package/types/transform/generators/processEntrypoint.js +13 -7
- package/types/transform/generators/processImports.js +1 -2
- package/types/transform/generators/resolveImports.js +41 -5
- package/types/transform/generators/transform.d.ts +1 -1
- package/types/transform/generators/transform.js +16 -6
- package/types/transform/generators/workflow.js +1 -2
- package/types/transform/helpers/loadWywOptions.js +16 -5
- package/types/transform/helpers/withDefaultServices.d.ts +1 -1
- package/types/transform/helpers/withDefaultServices.js +19 -8
- package/types/transform/isStaticallyEvaluatableModule.d.ts +2 -0
- package/types/transform/isStaticallyEvaluatableModule.js +177 -0
- package/types/transform/rootLog.d.ts +0 -1
- package/types/transform/types.d.ts +1 -1
- package/types/transform.js +17 -9
- package/types/types.d.ts +1 -1
- package/types/utils/addIdentifierToWywPreval.js +2 -3
- package/types/utils/collectExportsAndImports.js +102 -20
- package/types/utils/collectTemplateDependencies.js +3 -4
- package/types/utils/findIdentifiers.js +2 -3
- package/types/utils/getConstantStringValue.d.ts +2 -0
- package/types/utils/getConstantStringValue.js +94 -0
- package/types/utils/getFileIdx.js +1 -2
- package/types/utils/getMemberExpressionPropertyName.d.ts +2 -0
- package/types/utils/getMemberExpressionPropertyName.js +46 -0
- package/types/utils/getScope.js +1 -2
- package/types/utils/getTagProcessor.js +35 -9
- package/types/utils/getVisitorKeys.js +1 -2
- package/types/utils/hasWywPreval.js +1 -1
- package/types/utils/importOverrides.d.ts +19 -0
- package/types/utils/importOverrides.js +40 -0
- package/types/utils/isExports.js +1 -2
- package/types/utils/isNodePath.js +1 -2
- package/types/utils/isNotNull.js +1 -2
- package/types/utils/isRemoved.js +1 -2
- package/types/utils/isRequire.js +1 -2
- package/types/utils/isSerializable.js +1 -2
- package/types/utils/isUnnecessaryReactCall.js +1 -2
- package/types/utils/parseRequest.d.ts +7 -0
- package/types/utils/parseRequest.js +29 -0
- package/types/utils/removeDangerousCode.js +37 -2
- package/types/utils/replaceImportMetaEnv.d.ts +3 -0
- package/types/utils/replaceImportMetaEnv.js +39 -0
- package/types/utils/scopeHelpers.js +7 -8
- package/types/utils/traversalCache.d.ts +1 -1
- package/types/utils/unwrapExpression.d.ts +2 -0
- package/types/utils/unwrapExpression.js +57 -0
- package/types/utils/unwrapSequence.js +1 -2
- package/types/utils/valueToLiteral.js +1 -2
- package/types/utils/visitors/JSXElementsRemover.js +1 -2
- package/types/vm/createVmContext.d.ts +0 -1
- package/types/vm/createVmContext.js +68 -9
- package/types/vm/process.d.ts +0 -2
- package/LICENSE +0 -21
- package/esm/options/babel-merge.d.js +0 -2
- package/esm/options/babel-merge.d.js.map +0 -1
- package/lib/options/babel-merge.d.js +0 -2
- package/lib/options/babel-merge.d.js.map +0 -1
package/esm/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["isFeatureEnabled","loadWywOptions","TransformCacheCollection","Entrypoint","asyncActionRunner","syncActionRunner","baseHandlers","asyncResolveImports","syncResolveImports","withDefaultServices","transformSync","partialServices","originalCode","syncResolve","customHandlers","options","pluginOptions","services","features","filename","cache","entrypoint","createRoot","ignored","code","sourceMap","inputSourceMap","workflowAction","createAction","undefined","result","resolveImports","call","log","name","err","console","error","transform","asyncResolve"],"sources":["../src/transform.ts"],"sourcesContent":["/**\n * This file exposes sync and async transform functions that:\n * - parse the passed code to AST\n * - builds a dependency graph for the file\n * - shakes each dependency and removes unused code\n * - runs generated code in a sandbox\n * - collects artifacts\n * - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.\n */\n\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport type { PartialOptions } from './transform/helpers/loadWywOptions';\nimport { loadWywOptions } from './transform/helpers/loadWywOptions';\nimport { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport {\n asyncActionRunner,\n syncActionRunner,\n} from './transform/actions/actionRunner';\nimport { baseHandlers } from './transform/generators';\nimport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nimport { withDefaultServices } from './transform/helpers/withDefaultServices';\nimport type {\n Handlers,\n IResolveImportsAction,\n Services,\n} from './transform/types';\nimport type { Result } from './types';\n\ntype PartialServices = Partial<Omit<Services, 'options'>> & {\n options: Omit<Services['options'], 'pluginOptions'> & {\n pluginOptions?: PartialOptions;\n };\n};\n\ntype AllHandlers<TMode extends 'async' | 'sync'> = Handlers<TMode>;\n\nexport function transformSync(\n partialServices: PartialServices,\n originalCode: string,\n syncResolve: (what: string, importer: string, stack: string[]) => string,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Result {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = syncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports() {\n return syncResolveImports.call(this, syncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n\nexport async function transform(\n partialServices: PartialServices,\n originalCode: string,\n asyncResolve: (\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Promise<Result> {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n /*\n * This method can be run simultaneously for multiple files.\n * A shared cache is accessible for all runs, but each run has its own queue\n * to maintain the correct processing order. The cache stores the outcome\n * of tree-shaking, and if the result is already stored in the cache\n * but the \"only\" option has changed, the file will be re-processed using\n * the combined \"only\" option.\n */\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n try {\n const result = await asyncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports(this: IResolveImportsAction) {\n return asyncResolveImports.call(this, asyncResolve);\n },\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAQ,mBAAmB;AAGpD,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,wBAAwB,QAAQ,SAAS;AAClD,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SACEC,iBAAiB,EACjBC,gBAAgB,QACX,kCAAkC;AACzC,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SACEC,mBAAmB,EACnBC,kBAAkB,QACb,uCAAuC;AAC9C,SAASC,mBAAmB,QAAQ,yCAAyC;AAgB7E,OAAO,SAASC,aAAaA,CAC3BC,eAAgC,EAChCC,YAAoB,EACpBC,WAAwE,EACxEC,cAA4C,GAAG,CAAC,CAAC,EACzC;EACR,MAAM;IAAEC;EAAQ,CAAC,GAAGJ,eAAe;EACnC,MAAMK,aAAa,GAAGf,cAAc,CAACc,OAAO,CAACC,aAAa,CAAC;EAC3D,MAAMC,QAAQ,GAAGR,mBAAmB,CAAC;IACnC,GAAGE,eAAe;IAClBI,OAAO,EAAE;MACP,GAAGA,OAAO;MACVC;IACF;EACF,CAAC,CAAC;EAEF,IACE,CAAChB,gBAAgB,CAACgB,aAAa,CAACE,QAAQ,EAAE,aAAa,EAAEH,OAAO,CAACI,QAAQ,CAAC,EAC1E;IACA;IACAF,QAAQ,CAACG,KAAK,GAAG,IAAIlB,wBAAwB,CAAC,CAAC;EACjD;EAEA,MAAMmB,UAAU,GAAGlB,UAAU,CAACmB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B,UAAU,CAACa,IAAK,GAAE,EAAEC,GAAG,CAAC;MAEnE,OAAO;QACLX,IAAI,EAAEZ,YAAY;QAClBa,SAAS,EAAEV,OAAO,CAACW;MACrB,CAAC;IACH;IAEA,MAAMS,GAAG;EACX;AACF"}
|
|
1
|
+
{"version":3,"file":"transform.js","names":["isFeatureEnabled","loadWywOptions","TransformCacheCollection","Entrypoint","asyncActionRunner","syncActionRunner","baseHandlers","asyncResolveImports","syncResolveImports","withDefaultServices","memoizedSyncResolve","WeakMap","memoizedAsyncResolve","transformSync","partialServices","originalCode","syncResolve","customHandlers","options","pluginOptions","services","features","filename","cache","entrypoint","createRoot","ignored","code","sourceMap","inputSourceMap","workflowAction","createAction","undefined","has","set","resolveImports","call","result","get","log","name","err","console","error","transform","asyncResolve"],"sources":["../src/transform.ts"],"sourcesContent":["/**\n * This file exposes sync and async transform functions that:\n * - parse the passed code to AST\n * - builds a dependency graph for the file\n * - shakes each dependency and removes unused code\n * - runs generated code in a sandbox\n * - collects artifacts\n * - returns transformed code (without WYW template literals), generated CSS, source maps and babel metadata from transform step.\n */\n\nimport { isFeatureEnabled } from '@wyw-in-js/shared';\n\nimport type { PartialOptions } from './transform/helpers/loadWywOptions';\nimport { loadWywOptions } from './transform/helpers/loadWywOptions';\nimport { TransformCacheCollection } from './cache';\nimport { Entrypoint } from './transform/Entrypoint';\nimport {\n asyncActionRunner,\n syncActionRunner,\n} from './transform/actions/actionRunner';\nimport { baseHandlers } from './transform/generators';\nimport {\n asyncResolveImports,\n syncResolveImports,\n} from './transform/generators/resolveImports';\nimport { withDefaultServices } from './transform/helpers/withDefaultServices';\nimport type {\n Handler,\n Handlers,\n IResolveImportsAction,\n Services,\n} from './transform/types';\nimport type { Result } from './types';\n\ntype PartialServices = Partial<Omit<Services, 'options'>> & {\n options: Omit<Services['options'], 'pluginOptions'> & {\n pluginOptions?: PartialOptions;\n };\n};\n\ntype AllHandlers<TMode extends 'async' | 'sync'> = Handlers<TMode>;\n\nconst memoizedSyncResolve = new WeakMap<\n (what: string, importer: string, stack: string[]) => string | null,\n Handler<'sync', IResolveImportsAction>\n>();\n\nconst memoizedAsyncResolve = new WeakMap<\n (what: string, importer: string, stack: string[]) => Promise<string | null>,\n Handler<'async' | 'sync', IResolveImportsAction>\n>();\n\nexport function transformSync(\n partialServices: PartialServices,\n originalCode: string,\n syncResolve: (what: string, importer: string, stack: string[]) => string,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Result {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n if (!memoizedSyncResolve.has(syncResolve)) {\n memoizedSyncResolve.set(\n syncResolve,\n function resolveImports(this: IResolveImportsAction) {\n return syncResolveImports.call(this, syncResolve);\n }\n );\n }\n\n try {\n const result = syncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports: memoizedSyncResolve.get(syncResolve)!,\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n\nexport async function transform(\n partialServices: PartialServices,\n originalCode: string,\n asyncResolve: (\n what: string,\n importer: string,\n stack: string[]\n ) => Promise<string | null>,\n customHandlers: Partial<AllHandlers<'sync'>> = {}\n): Promise<Result> {\n const { options } = partialServices;\n const pluginOptions = loadWywOptions(options.pluginOptions);\n const services = withDefaultServices({\n ...partialServices,\n options: {\n ...options,\n pluginOptions,\n },\n });\n\n if (\n !isFeatureEnabled(pluginOptions.features, 'globalCache', options.filename)\n ) {\n // If global cache is disabled, we need to create a new cache for each file\n services.cache = new TransformCacheCollection();\n }\n\n /*\n * This method can be run simultaneously for multiple files.\n * A shared cache is accessible for all runs, but each run has its own queue\n * to maintain the correct processing order. The cache stores the outcome\n * of tree-shaking, and if the result is already stored in the cache\n * but the \"only\" option has changed, the file will be re-processed using\n * the combined \"only\" option.\n */\n const entrypoint = Entrypoint.createRoot(\n services,\n options.filename,\n ['__wywPreval'],\n originalCode\n );\n\n if (entrypoint.ignored) {\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n const workflowAction = entrypoint.createAction('workflow', undefined);\n\n if (!memoizedAsyncResolve.has(asyncResolve)) {\n const resolveImports = function resolveImports(\n this: IResolveImportsAction\n ) {\n return asyncResolveImports.call(this, asyncResolve);\n };\n\n memoizedAsyncResolve.set(asyncResolve, resolveImports);\n }\n\n try {\n const result = await asyncActionRunner(workflowAction, {\n ...baseHandlers,\n ...customHandlers,\n resolveImports: memoizedAsyncResolve.get(asyncResolve)!,\n });\n\n entrypoint.log('%s is ready', entrypoint.name);\n\n return result;\n } catch (err) {\n entrypoint.log('Unhandled error %O', err);\n\n if (\n isFeatureEnabled(pluginOptions.features, 'softErrors', options.filename)\n ) {\n // eslint-disable-next-line no-console\n console.error(`Error during transform of ${entrypoint.name}:`, err);\n\n return {\n code: originalCode,\n sourceMap: options.inputSourceMap,\n };\n }\n\n throw err;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAQ,mBAAmB;AAGpD,SAASC,cAAc,QAAQ,oCAAoC;AACnE,SAASC,wBAAwB,QAAQ,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QAAQ,CAAC,EACxE;MACA;MACAoB,OAAO,CAACC,KAAK,CAAC,6BAA6BnB,UAAU,CAACgB,IAAI,GAAG,EAAEC,GAAG,CAAC;MAEnE,OAAO;QACLd,IAAI,EAAEZ,YAAY;QAClBa,SAAS,EAAEV,OAAO,CAACW;MACrB,CAAC;IACH;IAEA,MAAMY,GAAG;EACX;AACF","ignoreList":[]}
|
package/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n wywInJS?: WYWTransformMetadata;\n };\n };\n processors: BaseProcessor[];\n}\n\nexport interface ITransformFileResult {\n code: string;\n metadata: WYWTransformMetadata | null;\n}\n\nexport type Stage = 'preeval' | 'collect';\n\nexport type Result = {\n code: string;\n cssSourceMapText?: string;\n cssText?: string;\n dependencies?: string[];\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n root?: string;\n};\n\nexport type PreprocessorFn = (selector: string, cssText: string) => string;\nexport type Preprocessor = 'none' | 'stylis' | PreprocessorFn | void;\n\nexport type MissedBabelCoreTypes = {\n File: new (\n options: { filename: string },\n file: { ast: File; code: string }\n ) => { path: NodePath<Program> };\n};\n\nexport type JSONValue =\n | null\n | string\n | number\n | boolean\n | JSONObject\n | JSONArray;\n\nexport interface JSONObject {\n [x: string]: JSONValue;\n}\n\nexport type JSONArray = Array<JSONValue>;\n\nexport type Serializable = JSONValue;\n\n/**\n * CSS-related types\n */\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { BabelFile, PluginPass } from '@babel/core';\nimport type { NodePath } from '@babel/traverse';\nimport type { File, Program } from '@babel/types';\nimport type { RawSourceMap } from 'source-map';\n\nimport type { BaseProcessor } from '@wyw-in-js/processor-utils';\nimport type {\n Debugger,\n Replacement,\n Rules,\n StrictOptions,\n} from '@wyw-in-js/shared';\n\nimport type { WYWTransformMetadata } from './utils/TransformMetadata';\n\nexport type PluginOptions = StrictOptions & {\n configFile?: string | false;\n stage?: Stage;\n};\n\nexport type ParentEntrypoint = {\n evaluated: boolean;\n log: Debugger;\n name: string;\n parents: ParentEntrypoint[];\n seqId: number;\n};\n\nexport type Dependencies = string[];\n\nexport interface IPluginState extends PluginPass {\n dependencies: Dependencies;\n file: BabelFile & {\n metadata: {\n wywInJS?: WYWTransformMetadata;\n };\n };\n processors: BaseProcessor[];\n}\n\nexport interface ITransformFileResult {\n code: string;\n metadata: WYWTransformMetadata | null;\n}\n\nexport type Stage = 'preeval' | 'collect';\n\nexport type Result = {\n code: string;\n cssSourceMapText?: string;\n cssText?: string;\n dependencies?: string[];\n replacements?: Replacement[];\n rules?: Rules;\n sourceMap?: RawSourceMap | null;\n};\n\nexport type Options = {\n filename: string;\n inputSourceMap?: RawSourceMap;\n keepComments?: boolean | RegExp;\n outputFilename?: string;\n pluginOptions?: Partial<PluginOptions>;\n prefixer?: boolean;\n preprocessor?: Preprocessor;\n root?: string;\n};\n\nexport type PreprocessorFn = (selector: string, cssText: string) => string;\nexport type Preprocessor = 'none' | 'stylis' | PreprocessorFn | void;\n\nexport type MissedBabelCoreTypes = {\n File: new (\n options: { filename: string },\n file: { ast: File; code: string }\n ) => { path: NodePath<Program> };\n};\n\nexport type JSONValue =\n | null\n | string\n | number\n | boolean\n | JSONObject\n | JSONArray;\n\nexport interface JSONObject {\n [x: string]: JSONValue;\n}\n\nexport type JSONArray = Array<JSONValue>;\n\nexport type Serializable = JSONValue;\n\n/**\n * CSS-related types\n */\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitter.js","names":["isOnActionStartArgs","args","isOnActionFinishArgs","EventEmitter","dummy","constructor","onEvent","onAction","onEntrypointEvent","action","actonType","idx","entrypointRef","fn","id","performance","now","result","Promise","then","e","entrypointEvent","sequenceId","event","perf","method","labels","single","datetime","Date"],"sources":["../../src/utils/EventEmitter.ts"],"sourcesContent":["export type OnEvent = (\n labels: Record<string, unknown>,\n type: 'start' | 'finish' | 'single',\n event?: unknown\n) => void;\n\nexport interface IActionCreated {\n actionIdx: string;\n actionType: string;\n type: 'actionCreated';\n}\n\nexport interface ICreatedEvent {\n class: string;\n evaluatedOnly: string[];\n filename: string;\n generation: number;\n idx: string;\n isExportsInherited: boolean;\n only: string[];\n parentId: number | null;\n type: 'created';\n}\n\nexport interface ISupersededEvent {\n type: 'superseded';\n with: number;\n}\n\nexport interface ISetTransformResultEvent {\n isNull: boolean;\n type: 'setTransformResult';\n}\n\nexport type EntrypointEvent =\n | IActionCreated\n | ICreatedEvent\n | ISupersededEvent\n | ISetTransformResultEvent;\n\nexport type OnEntrypointEvent = (\n idx: number,\n timestamp: number,\n event: EntrypointEvent\n) => void;\n\nexport type OnActionStartArgs = [\n phase: 'start',\n timestamp: number,\n type: string,\n idx: string,\n entrypointRef: string,\n];\n\nexport type OnActionFinishArgs = [\n phase: 'finish' | 'fail',\n timestamp: number,\n id: number,\n isAsync: boolean,\n error?: unknown,\n];\n\nexport const isOnActionStartArgs = (\n args: OnActionStartArgs | OnActionFinishArgs\n): args is OnActionStartArgs => {\n return args[0] === 'start';\n};\n\nexport const isOnActionFinishArgs = (\n args: OnActionStartArgs | OnActionFinishArgs\n): args is OnActionFinishArgs => {\n return args[0] === 'finish' || args[0] === 'fail';\n};\n\nexport interface OnAction {\n (...args: OnActionStartArgs): number;\n (...args: OnActionFinishArgs): void;\n}\n\nexport class EventEmitter {\n static dummy = new EventEmitter(\n () => {},\n () => 0,\n () => {}\n );\n\n constructor(\n protected onEvent: OnEvent,\n protected onAction: OnAction,\n protected onEntrypointEvent: OnEntrypointEvent\n ) {}\n\n public action<TRes>(\n actonType: string,\n idx: string,\n entrypointRef: string,\n fn: () => TRes\n ) {\n const id = this.onAction(\n 'start',\n performance.now(),\n actonType,\n idx,\n entrypointRef\n );\n\n try {\n const result = fn();\n if (result instanceof Promise) {\n result.then(\n () => this.onAction('finish', performance.now(), id, true),\n (e) => this.onAction('fail', performance.now(), id, true, e)\n );\n } else {\n this.onAction('finish', performance.now(), id, false);\n }\n\n return result;\n } catch (e) {\n this.onAction('fail', performance.now(), id, false, e);\n throw e;\n }\n }\n\n public entrypointEvent(sequenceId: number, event: EntrypointEvent) {\n this.onEntrypointEvent(sequenceId, performance.now(), event);\n }\n\n public perf<TRes>(method: string, fn: () => TRes): TRes {\n const labels = { method };\n\n this.onEvent(labels, 'start');\n\n const result = fn();\n if (result instanceof Promise) {\n result.then(\n () => this.onEvent(labels, 'finish'),\n () => this.onEvent(labels, 'finish')\n );\n } else {\n this.onEvent(labels, 'finish');\n }\n\n return result;\n }\n\n public single(labels: Record<string, unknown>) {\n this.onEvent(\n {\n ...labels,\n datetime: new Date(),\n },\n 'single'\n );\n }\n}\n"],"mappings":"AA8DA,OAAO,MAAMA,mBAAmB,GAC9BC,IAA4C,IACd;EAC9B,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO;AAC5B,CAAC;AAED,OAAO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V,IAAI,CAACb,QAAQ,CAAC,MAAM,EAAEQ,WAAW,CAACC,GAAG,CAAC,CAAC,EAAEF,EAAE,EAAE,KAAK,EAAEM,CAAC,CAAC;MACtD,MAAMA,CAAC;IACT;EACF;EAEOC,eAAeA,CAACC,UAAkB,EAAEC,KAAsB,EAAE;IACjE,IAAI,CAACf,iBAAiB,CAACc,UAAU,EAAEP,WAAW,CAACC,GAAG,CAAC,CAAC,EAAEO,KAAK,CAAC;EAC9D;EAEOC,IAAIA,CAAOC,MAAc,EAAEZ,EAAc,EAAQ;IACtD,MAAMa,MAAM,GAAG;MAAED;IAAO,CAAC;IAEzB,IAAI,CAACnB,OAAO,CAACoB,MAAM,EAAE,OAAO,CAAC;IAE7B,MAAMT,MAAM,GAAGJ,EAAE,CAAC,CAAC;IACnB,IAAII,MAAM,YAAYC,OAAO,EAAE;MAC7BD,MAAM,CAACE,IAAI,CACT,MAAM,IAAI,CAACb,OAAO,CAACoB,MAAM,EAAE,QAAQ,CAAC,EACpC,MAAM,IAAI,CAACpB,OAAO,CAACoB,MAAM,EAAE,QAAQ,CACrC,CAAC;IACH,CAAC,MAAM;MACL,IAAI,CAACpB,OAAO,CAACoB,MAAM,EAAE,QAAQ,CAAC;IAChC;IAEA,OAAOT,MAAM;EACf;EAEOU,MAAMA,CAACD,MAA+B,EAAE;IAC7C,IAAI,CAACpB,OAAO,CACV;MACE,GAAGoB,MAAM;MACTE,QAAQ,EAAE,IAAIC,IAAI,CAAC;IACrB,CAAC,EACD,QACF,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"EventEmitter.js","names":["isOnActionStartArgs","args","isOnActionFinishArgs","EventEmitter","dummy","constructor","onEvent","onAction","onEntrypointEvent","action","actonType","idx","entrypointRef","fn","id","performance","now","result","Promise","then","e","entrypointEvent","sequenceId","event","perf","method","labels","single","datetime","Date"],"sources":["../../src/utils/EventEmitter.ts"],"sourcesContent":["export type OnEvent = (\n labels: Record<string, unknown>,\n type: 'start' | 'finish' | 'single',\n event?: unknown\n) => void;\n\nexport interface IActionCreated {\n actionIdx: string;\n actionType: string;\n type: 'actionCreated';\n}\n\nexport interface ICreatedEvent {\n class: string;\n evaluatedOnly: string[];\n filename: string;\n generation: number;\n idx: string;\n isExportsInherited: boolean;\n only: string[];\n parentId: number | null;\n type: 'created';\n}\n\nexport interface ISupersededEvent {\n type: 'superseded';\n with: number;\n}\n\nexport interface ISetTransformResultEvent {\n isNull: boolean;\n type: 'setTransformResult';\n}\n\nexport type EntrypointEvent =\n | IActionCreated\n | ICreatedEvent\n | ISupersededEvent\n | ISetTransformResultEvent;\n\nexport type OnEntrypointEvent = (\n idx: number,\n timestamp: number,\n event: EntrypointEvent\n) => void;\n\nexport type OnActionStartArgs = [\n phase: 'start',\n timestamp: number,\n type: string,\n idx: string,\n entrypointRef: string,\n];\n\nexport type OnActionFinishArgs = [\n phase: 'finish' | 'fail',\n timestamp: number,\n id: number,\n isAsync: boolean,\n error?: unknown,\n];\n\nexport const isOnActionStartArgs = (\n args: OnActionStartArgs | OnActionFinishArgs\n): args is OnActionStartArgs => {\n return args[0] === 'start';\n};\n\nexport const isOnActionFinishArgs = (\n args: OnActionStartArgs | OnActionFinishArgs\n): args is OnActionFinishArgs => {\n return args[0] === 'finish' || args[0] === 'fail';\n};\n\nexport interface OnAction {\n (...args: OnActionStartArgs): number;\n (...args: OnActionFinishArgs): void;\n}\n\nexport class EventEmitter {\n static dummy = new EventEmitter(\n () => {},\n () => 0,\n () => {}\n );\n\n constructor(\n protected onEvent: OnEvent,\n protected onAction: OnAction,\n protected onEntrypointEvent: OnEntrypointEvent\n ) {}\n\n public action<TRes>(\n actonType: string,\n idx: string,\n entrypointRef: string,\n fn: () => TRes\n ) {\n const id = this.onAction(\n 'start',\n performance.now(),\n actonType,\n idx,\n entrypointRef\n );\n\n try {\n const result = fn();\n if (result instanceof Promise) {\n result.then(\n () => this.onAction('finish', performance.now(), id, true),\n (e) => this.onAction('fail', performance.now(), id, true, e)\n );\n } else {\n this.onAction('finish', performance.now(), id, false);\n }\n\n return result;\n } catch (e) {\n this.onAction('fail', performance.now(), id, false, e);\n throw e;\n }\n }\n\n public entrypointEvent(sequenceId: number, event: EntrypointEvent) {\n this.onEntrypointEvent(sequenceId, performance.now(), event);\n }\n\n public perf<TRes>(method: string, fn: () => TRes): TRes {\n const labels = { method };\n\n this.onEvent(labels, 'start');\n\n const result = fn();\n if (result instanceof Promise) {\n result.then(\n () => this.onEvent(labels, 'finish'),\n () => this.onEvent(labels, 'finish')\n );\n } else {\n this.onEvent(labels, 'finish');\n }\n\n return result;\n }\n\n public single(labels: Record<string, unknown>) {\n this.onEvent(\n {\n ...labels,\n datetime: new Date(),\n },\n 'single'\n );\n }\n}\n"],"mappings":"AA8DA,OAAO,MAAMA,mBAAmB,GAC9BC,IAA4C,IACd;EAC9B,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO;AAC5B,CAAC;AAED,OAAO,MAAMC,oBAAoB,GAC/BD,IAA4C,IACb;EAC/B,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAIA,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM;AACnD,CAAC;AAOD,OAAO,MAAME,YAAY,CAAC;EACxB,OAAOC,KAAK,GAAG,IAAID,YAAY,CAC7B,MAAM,CAAC,CAAC,EACR,MAAM,CAAC,EACP,MAAM,CAAC,CACT,CAAC;EAEDE,WAAWA,CACCC,OAAgB,EAChBC,QAAkB,EAClBC,iBAAoC,EAC9C;IAAA,KAHUF,OAAgB,GAAhBA,OAAgB;IAAA,KAChBC,QAAkB,GAAlBA,QAAkB;IAAA,KAClBC,iBAAoC,GAApCA,iBAAoC;EAC7C;EAEIC,MAAMA,CACXC,SAAiB,EACjBC,GAAW,EACXC,aAAqB,EACrBC,EAAc,EACd;IACA,MAAMC,EAAE,GAAG,IAAI,CAACP,QAAQ,CACtB,OAAO,EACPQ,WAAW,CAACC,GAAG,CAAC,CAAC,EACjBN,SAAS,EACTC,GA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CAACoB,MAAM,EAAE,QAAQ,CACrC,CAAC;IACH,CAAC,MAAM;MACL,IAAI,CAACpB,OAAO,CAACoB,MAAM,EAAE,QAAQ,CAAC;IAChC;IAEA,OAAOT,MAAM;EACf;EAEOU,MAAMA,CAACD,MAA+B,EAAE;IAC7C,IAAI,CAACpB,OAAO,CACV;MACE,GAAGoB,MAAM;MACTE,QAAQ,EAAE,IAAIC,IAAI,CAAC;IACrB,CAAC,EACD,QACF,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n wywEvaluator: IShakerMetadata;\n}\n\nexport const hasShakerMetadata = (\n metadata: object | undefined\n): metadata is IMetadata =>\n metadata !== undefined && 'wywEvaluator' in metadata;\n"],"mappings":"AAQA,OAAO,MAAMA,iBAAiB,GAC5BC,QAA4B,IAE5BA,QAAQ,KAAKC,SAAS,IAAI,cAAc,IAAID,QAAQ"}
|
|
1
|
+
{"version":3,"file":"ShakerMetadata.js","names":["hasShakerMetadata","metadata","undefined"],"sources":["../../src/utils/ShakerMetadata.ts"],"sourcesContent":["export interface IShakerMetadata {\n imports: Map<string, string[]>;\n}\n\nexport interface IMetadata {\n wywEvaluator: IShakerMetadata;\n}\n\nexport const hasShakerMetadata = (\n metadata: object | undefined\n): metadata is IMetadata =>\n metadata !== undefined && 'wywEvaluator' in metadata;\n"],"mappings":"AAQA,OAAO,MAAMA,iBAAiB,GAC5BC,QAA4B,IAE5BA,QAAQ,KAAKC,SAAS,IAAI,cAAc,IAAID,QAAQ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransformMetadata.js","names":["withTransformMetadata","value","wywInJS","getTransformMetadata","metadata","undefined"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { Artifact, Replacement, Rules } from '@wyw-in-js/shared';\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: { artifacts: Artifact[] }[];\n replacements: Replacement[];\n rules: Rules;\n};\n\nexport const withTransformMetadata = (\n value: unknown\n): value is { wywInJS: WYWTransformMetadata } =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { wywInJS: unknown }).wywInJS === 'object';\n\nexport const getTransformMetadata = (\n value: unknown\n): WYWTransformMetadata | undefined => {\n if (withTransformMetadata(value) && value.wywInJS !== null) {\n const metadata = value.wywInJS;\n // eslint-disable-next-line no-param-reassign\n delete (value as { wywInJS: unknown }).wywInJS;\n return metadata;\n }\n\n return undefined;\n};\n"],"mappings":"AASA,OAAO,MAAMA,qBAAqB,GAChCC,KAAc,IAEd,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAA0BC,OAAO,KAAK,QAAQ;AAE7D,OAAO,MAAMC,oBAAoB,GAC/BF,KAAc,IACuB;EACrC,IAAID,qBAAqB,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACC,OAAO,KAAK,IAAI,EAAE;IAC1D,MAAME,QAAQ,GAAGH,KAAK,CAACC,OAAO;IAC9B;IACA,OAAQD,KAAK,CAA0BC,OAAO;IAC9C,OAAOE,QAAQ;EACjB;EAEA,OAAOC,SAAS;AAClB,CAAC"}
|
|
1
|
+
{"version":3,"file":"TransformMetadata.js","names":["withTransformMetadata","value","wywInJS","getTransformMetadata","metadata","undefined"],"sources":["../../src/utils/TransformMetadata.ts"],"sourcesContent":["import type { Artifact, Replacement, Rules } from '@wyw-in-js/shared';\n\nexport type WYWTransformMetadata = {\n dependencies: string[];\n processors: { artifacts: Artifact[] }[];\n replacements: Replacement[];\n rules: Rules;\n};\n\nexport const withTransformMetadata = (\n value: unknown\n): value is { wywInJS: WYWTransformMetadata } =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { wywInJS: unknown }).wywInJS === 'object';\n\nexport const getTransformMetadata = (\n value: unknown\n): WYWTransformMetadata | undefined => {\n if (withTransformMetadata(value) && value.wywInJS !== null) {\n const metadata = value.wywInJS;\n // eslint-disable-next-line no-param-reassign\n delete (value as { wywInJS: unknown }).wywInJS;\n return metadata;\n }\n\n return undefined;\n};\n"],"mappings":"AASA,OAAO,MAAMA,qBAAqB,GAChCC,KAAc,IAEd,OAAOA,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,OAAQA,KAAK,CAA0BC,OAAO,KAAK,QAAQ;AAE7D,OAAO,MAAMC,oBAAoB,GAC/BF,KAAc,IACuB;EACrC,IAAID,qBAAqB,CAACC,KAAK,CAAC,IAAIA,KAAK,CAACC,OAAO,KAAK,IAAI,EAAE;IAC1D,MAAME,QAAQ,GAAGH,KAAK,CAACC,OAAO;IAC9B;IACA,OAAQD,KAAK,CAA0BC,OAAO;IAC9C,OAAOE,QAAQ;EACjB;EAEA,OAAOC,SAAS;AAClB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addIdentifierToWywPreval.js","names":["createId","reference","getOrAddWywPreval","scope","rootScope","getProgramParent","programPath","path","object","getData","node","sourceType","prevalExport","expression","type","operator","left","computed","property","right","properties","inserted","pushContainer","get","declaration","declarations","id","init","kind","specifiers","setData","addIdentifierToWywPreval","name","newProperty","key","value","shorthand"],"sources":["../../src/utils/addIdentifierToWywPreval.ts"],"sourcesContent":["import type { NodePath, Scope } from '@babel/traverse';\nimport type {\n ExportNamedDeclaration,\n ExpressionStatement,\n Identifier,\n ObjectExpression,\n ObjectProperty,\n Program,\n} from '@babel/types';\n\nimport { createId } from './createId';\nimport { reference } from './scopeHelpers';\n\nexport function getOrAddWywPreval(scope: Scope): NodePath<ObjectExpression> {\n const rootScope = scope.getProgramParent();\n const programPath = rootScope.path as NodePath<Program>;\n\n let object = programPath.getData('__wywPreval');\n if (object) {\n return object;\n }\n\n if (programPath.node.sourceType === 'script') {\n // CJS exports.__wywPreval = {};\n const prevalExport: ExpressionStatement = {\n expression: {\n type: 'AssignmentExpression',\n operator: '=',\n left: {\n computed: false,\n object: createId('exports'),\n property: createId('__wywPreval'),\n type: 'MemberExpression',\n },\n right: {\n properties: [],\n type: 'ObjectExpression',\n },\n },\n type: 'ExpressionStatement',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get('expression.right') as NodePath<ObjectExpression>;\n } else {\n // ESM export const __wywPreval = {};\n const prevalExport: ExportNamedDeclaration = {\n declaration: {\n declarations: [\n {\n id: createId('__wywPreval'),\n init: {\n properties: [],\n type: 'ObjectExpression',\n },\n type: 'VariableDeclarator',\n },\n ],\n kind: 'const',\n type: 'VariableDeclaration',\n },\n specifiers: [],\n type: 'ExportNamedDeclaration',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get(\n 'declaration.declarations.0.init'\n ) as NodePath<ObjectExpression>;\n }\n\n programPath.setData('__wywPreval', object);\n return object;\n}\n\nexport function addIdentifierToWywPreval(scope: Scope, name: string) {\n const rootScope = scope.getProgramParent();\n const object = getOrAddWywPreval(rootScope);\n const newProperty: ObjectProperty = {\n type: 'ObjectProperty',\n key: createId(name),\n value: createId(name),\n computed: false,\n shorthand: false,\n };\n\n const [inserted] = object.pushContainer('properties', [newProperty]);\n reference(inserted.get('value') as NodePath<Identifier>);\n}\n"],"mappings":"AAUA,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,OAAO,SAASC,iBAAiBA,CAACC,KAAY,EAA8B;EAC1E,MAAMC,SAAS,GAAGD,KAAK,CAACE,gBAAgB,CAAC,CAAC;EAC1C,MAAMC,WAAW,GAAGF,SAAS,CAACG,IAAyB;EAEvD,IAAIC,MAAM,GAAGF,WAAW,CAACG,OAAO,CAAC,aAAa,CAAC;EAC/C,IAAID,MAAM,EAAE;IACV,OAAOA,MAAM;EACf;EAEA,IAAIF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Y,EAAE6B,IAAY,EAAE;EACnE,MAAM5B,SAAS,GAAGD,KAAK,CAACE,gBAAgB,CAAC,CAAC;EAC1C,MAAMG,MAAM,GAAGN,iBAAiB,CAACE,SAAS,CAAC;EAC3C,MAAM6B,WAA2B,GAAG;IAClCnB,IAAI,EAAE,gBAAgB;IACtBoB,GAAG,EAAElC,QAAQ,CAACgC,IAAI,CAAC;IACnBG,KAAK,EAAEnC,QAAQ,CAACgC,IAAI,CAAC;IACrBf,QAAQ,EAAE,KAAK;IACfmB,SAAS,EAAE;EACb,CAAC;EAED,MAAM,CAACf,QAAQ,CAAC,GAAGb,MAAM,CAACc,aAAa,CAAC,YAAY,EAAE,CAACW,WAAW,CAAC,CAAC;EACpEhC,SAAS,CAACoB,QAAQ,CAACE,GAAG,CAAC,OAAO,CAAyB,CAAC;AAC1D"}
|
|
1
|
+
{"version":3,"file":"addIdentifierToWywPreval.js","names":["createId","reference","getOrAddWywPreval","scope","rootScope","getProgramParent","programPath","path","object","getData","node","sourceType","prevalExport","expression","type","operator","left","computed","property","right","properties","inserted","pushContainer","get","declaration","declarations","id","init","kind","specifiers","setData","addIdentifierToWywPreval","name","newProperty","key","value","shorthand"],"sources":["../../src/utils/addIdentifierToWywPreval.ts"],"sourcesContent":["import type { NodePath, Scope } from '@babel/traverse';\nimport type {\n ExportNamedDeclaration,\n ExpressionStatement,\n Identifier,\n ObjectExpression,\n ObjectProperty,\n Program,\n} from '@babel/types';\n\nimport { createId } from './createId';\nimport { reference } from './scopeHelpers';\n\nexport function getOrAddWywPreval(scope: Scope): NodePath<ObjectExpression> {\n const rootScope = scope.getProgramParent();\n const programPath = rootScope.path as NodePath<Program>;\n\n let object = programPath.getData('__wywPreval');\n if (object) {\n return object;\n }\n\n if (programPath.node.sourceType === 'script') {\n // CJS exports.__wywPreval = {};\n const prevalExport: ExpressionStatement = {\n expression: {\n type: 'AssignmentExpression',\n operator: '=',\n left: {\n computed: false,\n object: createId('exports'),\n property: createId('__wywPreval'),\n type: 'MemberExpression',\n },\n right: {\n properties: [],\n type: 'ObjectExpression',\n },\n },\n type: 'ExpressionStatement',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get('expression.right') as NodePath<ObjectExpression>;\n } else {\n // ESM export const __wywPreval = {};\n const prevalExport: ExportNamedDeclaration = {\n declaration: {\n declarations: [\n {\n id: createId('__wywPreval'),\n init: {\n properties: [],\n type: 'ObjectExpression',\n },\n type: 'VariableDeclarator',\n },\n ],\n kind: 'const',\n type: 'VariableDeclaration',\n },\n specifiers: [],\n type: 'ExportNamedDeclaration',\n };\n\n const [inserted] = programPath.pushContainer('body', [prevalExport]);\n object = inserted.get(\n 'declaration.declarations.0.init'\n ) as NodePath<ObjectExpression>;\n }\n\n programPath.setData('__wywPreval', object);\n return object;\n}\n\nexport function addIdentifierToWywPreval(scope: Scope, name: string) {\n const rootScope = scope.getProgramParent();\n const object = getOrAddWywPreval(rootScope);\n const newProperty: ObjectProperty = {\n type: 'ObjectProperty',\n key: createId(name),\n value: createId(name),\n computed: false,\n shorthand: false,\n };\n\n const [inserted] = object.pushContainer('properties', [newProperty]);\n reference(inserted.get('value') as NodePath<Identifier>);\n}\n"],"mappings":"AAUA,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,OAAO,SAASC,iBAAiBA,CAACC,KAAY,EAA8B;EAC1E,MAAMC,SAAS,GAAGD,KAAK,CAACE,gBAAgB,CAAC,CAAC;EAC1C,MAAMC,WAAW,GAAGF,SAAS,CAACG,IAAyB;EAEvD,IAAIC,MAAM,GAAGF,WAAW,CAACG,OAAO,CAAC,aAAa,CAAC;EAC/C,IAAID,MAAM,EAAE;IACV,OAAOA,MAAM;EACf;EAEA,IAAIF,WAAW,CAACI,IAAI,CAACC,UAAU,KAAK,QAAQ,EAAE;IAC5C;IACA,MAAMC,YAAiC,GAAG;MACxCC,UAAU,EAAE;QACVC,IAAI,EAAE,sBAAsB;QAC5BC,QA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C3C,MAAM6B,WAA2B,GAAG;IAClCnB,IAAI,EAAE,gBAAgB;IACtBoB,GAAG,EAAElC,QAAQ,CAACgC,IAAI,CAAC;IACnBG,KAAK,EAAEnC,QAAQ,CAACgC,IAAI,CAAC;IACrBf,QAAQ,EAAE,KAAK;IACfmB,SAAS,EAAE;EACb,CAAC;EAED,MAAM,CAACf,QAAQ,CAAC,GAAGb,MAAM,CAACc,aAAa,CAAC,YAAY,EAAE,CAACW,WAAW,CAAC,CAAC;EACpEhC,SAAS,CAACoB,QAAQ,CAACE,GAAG,CAAC,OAAO,CAAyB,CAAC;AAC1D","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ import { isExports } from './isExports';
|
|
|
7
7
|
import { isNotNull } from './isNotNull';
|
|
8
8
|
import { isRequire } from './isRequire';
|
|
9
9
|
import { isTypedNode } from './isTypedNode';
|
|
10
|
+
import { getConstantStringValue } from './getConstantStringValue';
|
|
10
11
|
import { getTraversalCache } from './traversalCache';
|
|
11
12
|
|
|
12
13
|
// '*' means re-export all
|
|
@@ -188,6 +189,25 @@ function exportFromVariableDeclarator(path) {
|
|
|
188
189
|
[destructed.as.node.name]: init
|
|
189
190
|
}), {});
|
|
190
191
|
}
|
|
192
|
+
if (id.isArrayPattern()) {
|
|
193
|
+
// It is `export const [a, , b, ...rest] = arr;`
|
|
194
|
+
const exported = new Set();
|
|
195
|
+
id.traverse({
|
|
196
|
+
Identifier(identifier) {
|
|
197
|
+
if (identifier.isBindingIdentifier()) {
|
|
198
|
+
exported.add(identifier.node.name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
if (exported.size === 0) {
|
|
203
|
+
return {};
|
|
204
|
+
}
|
|
205
|
+
const result = {};
|
|
206
|
+
exported.forEach(name => {
|
|
207
|
+
result[name] = init;
|
|
208
|
+
});
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
191
211
|
|
|
192
212
|
// What else it can be?
|
|
193
213
|
debug('exportFromVariableDeclarator: unknown type of id %o', id.node.type);
|
|
@@ -202,11 +222,14 @@ function collectFromDynamicImport(path, state) {
|
|
|
202
222
|
return;
|
|
203
223
|
}
|
|
204
224
|
const [sourcePath] = callExpression.get('arguments');
|
|
205
|
-
if (!sourcePath || !sourcePath.
|
|
206
|
-
// Import should have at least one argument
|
|
225
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
226
|
+
// Import should have at least one argument
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const source = getConstantStringValue(sourcePath.node);
|
|
230
|
+
if (source === null) {
|
|
207
231
|
return;
|
|
208
232
|
}
|
|
209
|
-
const source = sourcePath.node.value;
|
|
210
233
|
let {
|
|
211
234
|
parentPath: container,
|
|
212
235
|
key
|
|
@@ -349,11 +372,14 @@ function collectFromRequire(path, state) {
|
|
|
349
372
|
return;
|
|
350
373
|
}
|
|
351
374
|
const [sourcePath] = callExpression.get('arguments');
|
|
352
|
-
if (!sourcePath || !sourcePath.
|
|
353
|
-
// Import should have at least one argument
|
|
375
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
376
|
+
// Import should have at least one argument
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const source = getConstantStringValue(sourcePath.node);
|
|
380
|
+
if (source === null) {
|
|
354
381
|
return;
|
|
355
382
|
}
|
|
356
|
-
const source = sourcePath.node.value;
|
|
357
383
|
const {
|
|
358
384
|
parentPath: container,
|
|
359
385
|
key
|
|
@@ -480,6 +506,67 @@ function collectFromRequire(path, state) {
|
|
|
480
506
|
});
|
|
481
507
|
}
|
|
482
508
|
}
|
|
509
|
+
function collectFromWywDynamicImport(path, state) {
|
|
510
|
+
if (!path.isIdentifier({
|
|
511
|
+
name: '__wyw_dynamic_import'
|
|
512
|
+
})) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const {
|
|
516
|
+
parentPath: callExpression
|
|
517
|
+
} = path;
|
|
518
|
+
if (!callExpression.isCallExpression()) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const [sourcePath] = callExpression.get('arguments');
|
|
522
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const source = getConstantStringValue(sourcePath.node);
|
|
526
|
+
if (source === null) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
let {
|
|
530
|
+
parentPath: container,
|
|
531
|
+
key
|
|
532
|
+
} = callExpression;
|
|
533
|
+
let isAwaited = false;
|
|
534
|
+
if (container.isAwaitExpression()) {
|
|
535
|
+
// If it's not awaited import, it imports the full namespace
|
|
536
|
+
isAwaited = true;
|
|
537
|
+
key = container.key;
|
|
538
|
+
container = container.parentPath;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Is it `const something = await __wyw_dynamic_import("something")`?
|
|
542
|
+
if (key === 'init' && container.isVariableDeclarator()) {
|
|
543
|
+
importFromVariableDeclarator(container, isAwaited).forEach(prop => {
|
|
544
|
+
if (prop.what === '*') {
|
|
545
|
+
const unfolded = unfoldNamespaceImport({
|
|
546
|
+
imported: '*',
|
|
547
|
+
local: prop.as,
|
|
548
|
+
source,
|
|
549
|
+
type: 'dynamic'
|
|
550
|
+
});
|
|
551
|
+
state.imports.push(...unfolded);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
state.imports.push({
|
|
555
|
+
imported: prop.what,
|
|
556
|
+
local: prop.as,
|
|
557
|
+
source,
|
|
558
|
+
type: 'dynamic'
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
state.imports.push({
|
|
564
|
+
imported: '*',
|
|
565
|
+
local: path,
|
|
566
|
+
source,
|
|
567
|
+
type: 'dynamic'
|
|
568
|
+
});
|
|
569
|
+
}
|
|
483
570
|
function collectFromVariableDeclarator(path, state) {
|
|
484
571
|
let found = false;
|
|
485
572
|
path.traverse({
|
|
@@ -667,6 +754,10 @@ function collectFromExports(path, state) {
|
|
|
667
754
|
function collectFromRequireOrExports(path, state) {
|
|
668
755
|
if (isRequire(path)) {
|
|
669
756
|
collectFromRequire(path, state);
|
|
757
|
+
} else if (path.isIdentifier({
|
|
758
|
+
name: '__wyw_dynamic_import'
|
|
759
|
+
})) {
|
|
760
|
+
collectFromWywDynamicImport(path, state);
|
|
670
761
|
} else if (isExports(path)) {
|
|
671
762
|
collectFromExports(path, state);
|
|
672
763
|
}
|