@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
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
|
|
3
3
|
/* eslint-disable no-restricted-syntax,no-continue */
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.
|
|
5
|
+
exports.explicitImport = exports.sideEffectImport = void 0;
|
|
6
|
+
exports.collectExportsAndImports = collectExportsAndImports;
|
|
6
7
|
const shared_1 = require("@wyw-in-js/shared");
|
|
7
8
|
const getScope_1 = require("./getScope");
|
|
8
9
|
const isExports_1 = require("./isExports");
|
|
9
10
|
const isNotNull_1 = require("./isNotNull");
|
|
10
11
|
const isRequire_1 = require("./isRequire");
|
|
11
12
|
const isTypedNode_1 = require("./isTypedNode");
|
|
13
|
+
const getConstantStringValue_1 = require("./getConstantStringValue");
|
|
12
14
|
const traversalCache_1 = require("./traversalCache");
|
|
13
15
|
const sideEffectImport = (item) => item.imported === 'side-effect';
|
|
14
16
|
exports.sideEffectImport = sideEffectImport;
|
|
@@ -173,6 +175,25 @@ function exportFromVariableDeclarator(path) {
|
|
|
173
175
|
[destructed.as.node.name]: init,
|
|
174
176
|
}), {});
|
|
175
177
|
}
|
|
178
|
+
if (id.isArrayPattern()) {
|
|
179
|
+
// It is `export const [a, , b, ...rest] = arr;`
|
|
180
|
+
const exported = new Set();
|
|
181
|
+
id.traverse({
|
|
182
|
+
Identifier(identifier) {
|
|
183
|
+
if (identifier.isBindingIdentifier()) {
|
|
184
|
+
exported.add(identifier.node.name);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
if (exported.size === 0) {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
191
|
+
const result = {};
|
|
192
|
+
exported.forEach((name) => {
|
|
193
|
+
result[name] = init;
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
176
197
|
// What else it can be?
|
|
177
198
|
debug('exportFromVariableDeclarator: unknown type of id %o', id.node.type);
|
|
178
199
|
return {};
|
|
@@ -184,11 +205,14 @@ function collectFromDynamicImport(path, state) {
|
|
|
184
205
|
return;
|
|
185
206
|
}
|
|
186
207
|
const [sourcePath] = callExpression.get('arguments');
|
|
187
|
-
if (!sourcePath || !sourcePath.
|
|
188
|
-
// Import should have at least one argument
|
|
208
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
209
|
+
// Import should have at least one argument
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const source = (0, getConstantStringValue_1.getConstantStringValue)(sourcePath.node);
|
|
213
|
+
if (source === null) {
|
|
189
214
|
return;
|
|
190
215
|
}
|
|
191
|
-
const source = sourcePath.node.value;
|
|
192
216
|
let { parentPath: container, key } = callExpression;
|
|
193
217
|
let isAwaited = false;
|
|
194
218
|
if (container.isAwaitExpression()) {
|
|
@@ -245,28 +269,28 @@ function getImportExportTypeByInteropFunction(path, argPath) {
|
|
|
245
269
|
return 're-export:*';
|
|
246
270
|
}
|
|
247
271
|
if (matchCall(path, [
|
|
248
|
-
['_interopRequireDefault', argPath],
|
|
249
|
-
['_interop_require_default', argPath],
|
|
272
|
+
['_interopRequireDefault', argPath], // babel and swc <1.3.50
|
|
273
|
+
['_interop_require_default', argPath], // swc >=1.3.50
|
|
250
274
|
['__importDefault', argPath], // ?
|
|
251
275
|
])) {
|
|
252
276
|
return 'default';
|
|
253
277
|
}
|
|
254
278
|
if (matchCall(path, [
|
|
255
|
-
['_interopRequireWildcard', argPath],
|
|
256
|
-
['_interop_require_wildcard', argPath],
|
|
257
|
-
['__importStar', argPath],
|
|
258
|
-
['__toESM', argPath],
|
|
279
|
+
['_interopRequireWildcard', argPath], // babel and swc <1.3.50
|
|
280
|
+
['_interop_require_wildcard', argPath], // swc >=1.3.50
|
|
281
|
+
['__importStar', argPath], // ?
|
|
282
|
+
['__toESM', argPath], // esbuild >=0.14.7
|
|
259
283
|
['__toModule', argPath], // esbuild <0.14.7
|
|
260
284
|
])) {
|
|
261
285
|
return 'import:*';
|
|
262
286
|
}
|
|
263
287
|
if (matchCall(path, [
|
|
264
|
-
['_extends', isEmptyObject, argPath],
|
|
265
|
-
['__rest', argPath, isArrayExpression],
|
|
266
|
-
['__objRest', argPath, isArrayExpression],
|
|
267
|
-
['_objectWithoutProperties', argPath, isArrayExpression],
|
|
268
|
-
['_object_without_properties', argPath, isArrayExpression],
|
|
269
|
-
['_objectDestructuringEmpty', argPath],
|
|
288
|
+
['_extends', isEmptyObject, argPath], // babel and swc
|
|
289
|
+
['__rest', argPath, isArrayExpression], // tsc and esbuild <=0.11.3
|
|
290
|
+
['__objRest', argPath, isArrayExpression], // esbuild >0.11.3
|
|
291
|
+
['_objectWithoutProperties', argPath, isArrayExpression], // babel and swc <1.3.50
|
|
292
|
+
['_object_without_properties', argPath, isArrayExpression], // swc >=1.3.50
|
|
293
|
+
['_objectDestructuringEmpty', argPath], // swc <1.3.50
|
|
270
294
|
['_object_destructuring_empty', argPath], // swc >=1.3.50
|
|
271
295
|
])) {
|
|
272
296
|
return 'import:*';
|
|
@@ -317,11 +341,14 @@ function collectFromRequire(path, state) {
|
|
|
317
341
|
return;
|
|
318
342
|
}
|
|
319
343
|
const [sourcePath] = callExpression.get('arguments');
|
|
320
|
-
if (!sourcePath || !sourcePath.
|
|
321
|
-
// Import should have at least one argument
|
|
344
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
345
|
+
// Import should have at least one argument
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const source = (0, getConstantStringValue_1.getConstantStringValue)(sourcePath.node);
|
|
349
|
+
if (source === null) {
|
|
322
350
|
return;
|
|
323
351
|
}
|
|
324
|
-
const source = sourcePath.node.value;
|
|
325
352
|
const { parentPath: container, key } = callExpression;
|
|
326
353
|
if (container.isCallExpression()) {
|
|
327
354
|
// It may be transpiled import such as
|
|
@@ -442,6 +469,59 @@ function collectFromRequire(path, state) {
|
|
|
442
469
|
});
|
|
443
470
|
}
|
|
444
471
|
}
|
|
472
|
+
function collectFromWywDynamicImport(path, state) {
|
|
473
|
+
if (!path.isIdentifier({ name: '__wyw_dynamic_import' })) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const { parentPath: callExpression } = path;
|
|
477
|
+
if (!callExpression.isCallExpression()) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const [sourcePath] = callExpression.get('arguments');
|
|
481
|
+
if (!sourcePath || !sourcePath.isExpression()) {
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const source = (0, getConstantStringValue_1.getConstantStringValue)(sourcePath.node);
|
|
485
|
+
if (source === null) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
let { parentPath: container, key } = callExpression;
|
|
489
|
+
let isAwaited = false;
|
|
490
|
+
if (container.isAwaitExpression()) {
|
|
491
|
+
// If it's not awaited import, it imports the full namespace
|
|
492
|
+
isAwaited = true;
|
|
493
|
+
key = container.key;
|
|
494
|
+
container = container.parentPath;
|
|
495
|
+
}
|
|
496
|
+
// Is it `const something = await __wyw_dynamic_import("something")`?
|
|
497
|
+
if (key === 'init' && container.isVariableDeclarator()) {
|
|
498
|
+
importFromVariableDeclarator(container, isAwaited).forEach((prop) => {
|
|
499
|
+
if (prop.what === '*') {
|
|
500
|
+
const unfolded = unfoldNamespaceImport({
|
|
501
|
+
imported: '*',
|
|
502
|
+
local: prop.as,
|
|
503
|
+
source,
|
|
504
|
+
type: 'dynamic',
|
|
505
|
+
});
|
|
506
|
+
state.imports.push(...unfolded);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
state.imports.push({
|
|
510
|
+
imported: prop.what,
|
|
511
|
+
local: prop.as,
|
|
512
|
+
source,
|
|
513
|
+
type: 'dynamic',
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
state.imports.push({
|
|
519
|
+
imported: '*',
|
|
520
|
+
local: path,
|
|
521
|
+
source,
|
|
522
|
+
type: 'dynamic',
|
|
523
|
+
});
|
|
524
|
+
}
|
|
445
525
|
function collectFromVariableDeclarator(path, state) {
|
|
446
526
|
let found = false;
|
|
447
527
|
path.traverse({
|
|
@@ -635,6 +715,9 @@ function collectFromRequireOrExports(path, state) {
|
|
|
635
715
|
if ((0, isRequire_1.isRequire)(path)) {
|
|
636
716
|
collectFromRequire(path, state);
|
|
637
717
|
}
|
|
718
|
+
else if (path.isIdentifier({ name: '__wyw_dynamic_import' })) {
|
|
719
|
+
collectFromWywDynamicImport(path, state);
|
|
720
|
+
}
|
|
638
721
|
else if ((0, isExports_1.isExports)(path)) {
|
|
639
722
|
collectFromExports(path, state);
|
|
640
723
|
}
|
|
@@ -1062,4 +1145,3 @@ function collectExportsAndImports(path, cacheMode = 'enabled') {
|
|
|
1062
1145
|
cache?.set(path, state);
|
|
1063
1146
|
return state;
|
|
1064
1147
|
}
|
|
1065
|
-
exports.collectExportsAndImports = collectExportsAndImports;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.extractExpression = extractExpression;
|
|
5
|
+
exports.collectTemplateDependencies = collectTemplateDependencies;
|
|
5
6
|
/**
|
|
6
7
|
* This file is a visitor that checks TaggedTemplateExpressions and look for WYW template literals.
|
|
7
8
|
* For each template it makes a list of dependencies, try to evaluate expressions, and if it is not possible, mark them as lazy dependencies.
|
|
@@ -23,7 +24,7 @@ function staticEval(ex, evaluate = false) {
|
|
|
23
24
|
}
|
|
24
25
|
return undefined;
|
|
25
26
|
}
|
|
26
|
-
const expressionDeclarationTpl = (0, template_1.statement)('const %%expId%% =
|
|
27
|
+
const expressionDeclarationTpl = (0, template_1.statement)('const %%expId%% = () => %%expression%%', {
|
|
27
28
|
preserveComments: true,
|
|
28
29
|
});
|
|
29
30
|
const unsupported = (ex, reason) => ex.buildCodeFrameError(`This ${ex.isIdentifier() ? 'identifier' : 'expression'} cannot be used in the template${reason ? `, because it ${reason}` : ''}.`);
|
|
@@ -183,7 +184,6 @@ function extractExpression(ex, evaluate = false, imports = []) {
|
|
|
183
184
|
};
|
|
184
185
|
return result;
|
|
185
186
|
}
|
|
186
|
-
exports.extractExpression = extractExpression;
|
|
187
187
|
const debug = shared_1.logger.extend('template-parse:identify-expressions');
|
|
188
188
|
/**
|
|
189
189
|
* Collects, hoists, and makes lazy all expressions in the given template
|
|
@@ -209,4 +209,3 @@ function collectTemplateDependencies(path, evaluate = false) {
|
|
|
209
209
|
});
|
|
210
210
|
return [quasis.map((p) => p.node), expressionValues];
|
|
211
211
|
}
|
|
212
|
-
exports.collectTemplateDependencies = collectTemplateDependencies;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.nonType = nonType;
|
|
4
|
+
exports.findIdentifiers = findIdentifiers;
|
|
4
5
|
const getScope_1 = require("./getScope");
|
|
5
6
|
function isInUnary(path) {
|
|
6
7
|
return path.parentPath?.isUnaryExpression() ?? false;
|
|
@@ -30,7 +31,6 @@ function nonType(path) {
|
|
|
30
31
|
p.isFlowDeclaration() ||
|
|
31
32
|
p.isTSInterfaceDeclaration());
|
|
32
33
|
}
|
|
33
|
-
exports.nonType = nonType;
|
|
34
34
|
function findIdentifiers(expressions, type = 'reference') {
|
|
35
35
|
const identifiers = [];
|
|
36
36
|
expressions.forEach((ex) => {
|
|
@@ -65,4 +65,3 @@ function findIdentifiers(expressions, type = 'reference') {
|
|
|
65
65
|
});
|
|
66
66
|
return identifiers;
|
|
67
67
|
}
|
|
68
|
-
exports.findIdentifiers = findIdentifiers;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getConstantStringValue = getConstantStringValue;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
const getMemberExpressionPropertyName_1 = require("./getMemberExpressionPropertyName");
|
|
39
|
+
const unwrapExpression_1 = require("./unwrapExpression");
|
|
40
|
+
function getConstantStringValue(node) {
|
|
41
|
+
const fromExpression = (value) => {
|
|
42
|
+
const expression = (0, unwrapExpression_1.unwrapExpression)(value);
|
|
43
|
+
if (t.isStringLiteral(expression)) {
|
|
44
|
+
return expression.value;
|
|
45
|
+
}
|
|
46
|
+
if (t.isTemplateLiteral(expression)) {
|
|
47
|
+
if (expression.expressions.length !== 0) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const [quasi] = expression.quasis;
|
|
51
|
+
return quasi?.value.cooked ?? null;
|
|
52
|
+
}
|
|
53
|
+
if (t.isBinaryExpression(expression) && expression.operator === '+') {
|
|
54
|
+
if (!t.isExpression(expression.left) || !t.isExpression(expression.right))
|
|
55
|
+
return null;
|
|
56
|
+
const left = fromExpression(expression.left);
|
|
57
|
+
const right = fromExpression(expression.right);
|
|
58
|
+
if (left === null || right === null) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return left + right;
|
|
62
|
+
}
|
|
63
|
+
if (t.isCallExpression(expression)) {
|
|
64
|
+
const concatProperty = t.isMemberExpression(expression.callee)
|
|
65
|
+
? (0, getMemberExpressionPropertyName_1.getMemberExpressionPropertyName)(expression.callee)
|
|
66
|
+
: null;
|
|
67
|
+
if (concatProperty !== 'concat') {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const { callee } = expression;
|
|
71
|
+
if (!t.isMemberExpression(callee) || !t.isExpression(callee.object)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const base = fromExpression(callee.object);
|
|
75
|
+
if (base === null) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const parts = [base];
|
|
79
|
+
for (const arg of expression.arguments) {
|
|
80
|
+
if (!t.isExpression(arg)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const part = fromExpression(arg);
|
|
84
|
+
if (part === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
parts.push(part);
|
|
88
|
+
}
|
|
89
|
+
return parts.join('');
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
};
|
|
93
|
+
return fromExpression(node);
|
|
94
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFileIdx =
|
|
3
|
+
exports.getFileIdx = getFileIdx;
|
|
4
4
|
let nextIdx = 1;
|
|
5
5
|
const processed = new Map();
|
|
6
6
|
function getFileIdx(name) {
|
|
@@ -10,4 +10,3 @@ function getFileIdx(name) {
|
|
|
10
10
|
}
|
|
11
11
|
return processed.get(name).toString().padStart(5, '0');
|
|
12
12
|
}
|
|
13
|
-
exports.getFileIdx = getFileIdx;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getMemberExpressionPropertyName = getMemberExpressionPropertyName;
|
|
37
|
+
const t = __importStar(require("@babel/types"));
|
|
38
|
+
function getMemberExpressionPropertyName(node) {
|
|
39
|
+
if (!node.computed && t.isIdentifier(node.property)) {
|
|
40
|
+
return node.property.name;
|
|
41
|
+
}
|
|
42
|
+
if (node.computed && t.isStringLiteral(node.property)) {
|
|
43
|
+
return node.property.value;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
package/types/utils/getScope.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getScope =
|
|
3
|
+
exports.getScope = getScope;
|
|
4
4
|
function getScope(path) {
|
|
5
5
|
// In some nodes (like FunctionDeclaration) `scope` for `id` returns
|
|
6
6
|
// local function scope instead of a scope where function is declared.
|
|
@@ -8,4 +8,3 @@ function getScope(path) {
|
|
|
8
8
|
? path.scope.parent
|
|
9
9
|
: path.scope;
|
|
10
10
|
}
|
|
11
|
-
exports.getScope = getScope;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getProcessorForImport = getProcessorForImport;
|
|
4
|
+
exports.getDefinedProcessors = getDefinedProcessors;
|
|
5
|
+
exports.applyProcessors = applyProcessors;
|
|
4
6
|
const fs_1 = require("fs");
|
|
5
7
|
const path_1 = require("path");
|
|
6
8
|
const core_1 = require("@babel/core");
|
|
@@ -32,6 +34,25 @@ function buildCodeFrameError(path, message) {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
const definedTagsCache = new Map();
|
|
37
|
+
const resolvedTagResolverSourceCache = new Map();
|
|
38
|
+
const getResolvedTagResolverSource = (source, sourceFile) => {
|
|
39
|
+
if (!sourceFile) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const key = `${sourceFile}\0${source}`;
|
|
43
|
+
if (resolvedTagResolverSourceCache.has(key)) {
|
|
44
|
+
return resolvedTagResolverSourceCache.get(key);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const resolved = (0, shared_1.syncResolve)(source, sourceFile, []);
|
|
48
|
+
resolvedTagResolverSourceCache.set(key, resolved);
|
|
49
|
+
return resolved;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
resolvedTagResolverSourceCache.set(key, undefined);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
35
56
|
const getDefinedTagsFromPackage = (pkgName, filename) => {
|
|
36
57
|
if (definedTagsCache.has(pkgName)) {
|
|
37
58
|
return definedTagsCache.get(pkgName);
|
|
@@ -77,14 +98,20 @@ function getProcessorFromFile(processorPath) {
|
|
|
77
98
|
return Processor;
|
|
78
99
|
}
|
|
79
100
|
function getProcessorForImport({ imported, source }, filename, options) {
|
|
80
|
-
const tagResolver = options
|
|
81
|
-
|
|
101
|
+
const { tagResolver } = options;
|
|
102
|
+
let customFile = null;
|
|
103
|
+
if (tagResolver) {
|
|
104
|
+
const tagResolverMeta = {
|
|
105
|
+
sourceFile: filename,
|
|
106
|
+
resolvedSource: getResolvedTagResolverSource(source, filename),
|
|
107
|
+
};
|
|
108
|
+
customFile = tagResolver(source, imported, tagResolverMeta);
|
|
109
|
+
}
|
|
82
110
|
const processor = customFile
|
|
83
111
|
? getProcessorFromFile(customFile)
|
|
84
112
|
: getProcessorFromPackage(source, imported, filename);
|
|
85
113
|
return [processor, { imported, source }];
|
|
86
114
|
}
|
|
87
|
-
exports.getProcessorForImport = getProcessorForImport;
|
|
88
115
|
function getBuilderForIdentifier(definedProcessor, path, imports, options) {
|
|
89
116
|
const [Processor, tagSource] = definedProcessor;
|
|
90
117
|
let tagPath = path;
|
|
@@ -156,8 +183,9 @@ function getBuilderForIdentifier(definedProcessor, path, imports, options) {
|
|
|
156
183
|
}
|
|
157
184
|
const replacer = (replacement, isPure) => {
|
|
158
185
|
(0, scopeHelpers_1.mutate)(prev, (p) => {
|
|
159
|
-
|
|
160
|
-
|
|
186
|
+
const next = typeof replacement === 'function' ? replacement(p) : replacement;
|
|
187
|
+
p.replaceWith(next);
|
|
188
|
+
if (isPure && (p.isCallExpression() || p.isNewExpression())) {
|
|
161
189
|
p.addComment('leading', '#__PURE__');
|
|
162
190
|
}
|
|
163
191
|
});
|
|
@@ -240,7 +268,7 @@ function isTagReferenced(path) {
|
|
|
240
268
|
const id = parent.get('id');
|
|
241
269
|
// FIXME: replace with id.isReferencedIdentifier()
|
|
242
270
|
if (id.isIdentifier()) {
|
|
243
|
-
const { referencePaths } =
|
|
271
|
+
const { referencePaths } = id.scope.getBinding(id.node.name) || {
|
|
244
272
|
referencePaths: [],
|
|
245
273
|
};
|
|
246
274
|
isReferenced = referencePaths.length !== 0;
|
|
@@ -285,7 +313,6 @@ function getDefinedProcessors(imports, path, filename, options) {
|
|
|
285
313
|
}
|
|
286
314
|
return cache.get(path);
|
|
287
315
|
}
|
|
288
|
-
exports.getDefinedProcessors = getDefinedProcessors;
|
|
289
316
|
function createProcessorInstance(definedProcessor, imports, path, fileContext, options) {
|
|
290
317
|
const cache = (0, traversalCache_1.getTraversalCache)(path, 'createProcessorInstance');
|
|
291
318
|
if (!cache.has(path.node)) {
|
|
@@ -367,4 +394,3 @@ function applyProcessors(path, fileContext, options, callback) {
|
|
|
367
394
|
callback(instance);
|
|
368
395
|
});
|
|
369
396
|
}
|
|
370
|
-
exports.applyProcessors = applyProcessors;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVisitorKeys =
|
|
3
|
+
exports.getVisitorKeys = getVisitorKeys;
|
|
4
4
|
const core_1 = require("@babel/core");
|
|
5
5
|
function getVisitorKeys(node) {
|
|
6
6
|
return core_1.types.VISITOR_KEYS[node.type];
|
|
7
7
|
}
|
|
8
|
-
exports.getVisitorKeys = getVisitorKeys;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = hasWywPreval;
|
|
3
4
|
function hasWywPreval(exports) {
|
|
4
5
|
if (!exports || typeof exports !== 'object') {
|
|
5
6
|
return false;
|
|
6
7
|
}
|
|
7
8
|
return '__wywPreval' in exports;
|
|
8
9
|
}
|
|
9
|
-
exports.default = hasWywPreval;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ImportOverride } from '@wyw-in-js/shared';
|
|
2
|
+
export type ImportKeyKind = 'file' | 'package';
|
|
3
|
+
export type ImportKey = {
|
|
4
|
+
key: string;
|
|
5
|
+
kind: ImportKeyKind;
|
|
6
|
+
};
|
|
7
|
+
export declare function toCanonicalFileKey(resolved: string, root: string | undefined): string;
|
|
8
|
+
export declare function toImportKey({ source, resolved, root, }: {
|
|
9
|
+
resolved: string | null;
|
|
10
|
+
root: string | undefined;
|
|
11
|
+
source: string;
|
|
12
|
+
}): ImportKey;
|
|
13
|
+
export declare function resolveMockSpecifier({ importer, mock, root, stack, }: {
|
|
14
|
+
importer: string;
|
|
15
|
+
mock: string;
|
|
16
|
+
root: string | undefined;
|
|
17
|
+
stack: string[];
|
|
18
|
+
}): string;
|
|
19
|
+
export declare function applyImportOverrideToOnly(only: string[], override: ImportOverride | undefined): string[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toCanonicalFileKey = toCanonicalFileKey;
|
|
7
|
+
exports.toImportKey = toImportKey;
|
|
8
|
+
exports.resolveMockSpecifier = resolveMockSpecifier;
|
|
9
|
+
exports.applyImportOverrideToOnly = applyImportOverrideToOnly;
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const shared_1 = require("@wyw-in-js/shared");
|
|
12
|
+
function toCanonicalFileKey(resolved, root) {
|
|
13
|
+
const rootDir = root ? path_1.default.resolve(root) : process.cwd();
|
|
14
|
+
const normalizedResolved = path_1.default.resolve(resolved);
|
|
15
|
+
let relative = path_1.default.relative(rootDir, normalizedResolved);
|
|
16
|
+
if (path_1.default.sep !== path_1.default.posix.sep) {
|
|
17
|
+
relative = relative.split(path_1.default.sep).join(path_1.default.posix.sep);
|
|
18
|
+
}
|
|
19
|
+
if (!relative.startsWith('.')) {
|
|
20
|
+
relative = `./${relative}`;
|
|
21
|
+
}
|
|
22
|
+
return relative;
|
|
23
|
+
}
|
|
24
|
+
function toImportKey({ source, resolved, root, }) {
|
|
25
|
+
const isFileImport = source.startsWith('.') || path_1.default.isAbsolute(source);
|
|
26
|
+
if (isFileImport && resolved) {
|
|
27
|
+
return { key: toCanonicalFileKey(resolved, root), kind: 'file' };
|
|
28
|
+
}
|
|
29
|
+
return { key: source, kind: 'package' };
|
|
30
|
+
}
|
|
31
|
+
function resolveMockSpecifier({ importer, mock, root, stack, }) {
|
|
32
|
+
const specifier = mock.startsWith('.') && root ? path_1.default.resolve(root, mock) : mock;
|
|
33
|
+
return (0, shared_1.syncResolve)(specifier, importer, stack);
|
|
34
|
+
}
|
|
35
|
+
function applyImportOverrideToOnly(only, override) {
|
|
36
|
+
if (override?.noShake) {
|
|
37
|
+
return ['*'];
|
|
38
|
+
}
|
|
39
|
+
return only;
|
|
40
|
+
}
|
package/types/utils/isExports.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isExports =
|
|
3
|
+
exports.isExports = isExports;
|
|
4
4
|
const isGlobal_1 = require("./isGlobal");
|
|
5
5
|
/**
|
|
6
6
|
* Checks that specified Identifier is a global `exports` or `module.exports`
|
|
@@ -17,4 +17,3 @@ function isExports(node) {
|
|
|
17
17
|
}
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
exports.isExports = isExports;
|
package/types/utils/isNotNull.js
CHANGED
package/types/utils/isRemoved.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRemoved =
|
|
3
|
+
exports.isRemoved = isRemoved;
|
|
4
4
|
/**
|
|
5
5
|
* Checks if a given path has been removed from the AST.
|
|
6
6
|
*/
|
|
@@ -39,4 +39,3 @@ function isRemoved(path) {
|
|
|
39
39
|
// If the function has not returned true by this point, return false
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
|
-
exports.isRemoved = isRemoved;
|
package/types/utils/isRequire.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRequire =
|
|
3
|
+
exports.isRequire = isRequire;
|
|
4
4
|
const isGlobal_1 = require("./isGlobal");
|
|
5
5
|
/**
|
|
6
6
|
* Checks that specified Identifier is a global `require`
|
|
@@ -12,4 +12,3 @@ function isRequire(id) {
|
|
|
12
12
|
}
|
|
13
13
|
return (0, isGlobal_1.isGlobal)(id, 'require');
|
|
14
14
|
}
|
|
15
|
-
exports.isRequire = isRequire;
|