@shopify/async
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -22,3 +22,2 @@ 'use strict'; | ||
}, | ||
ImportDeclaration(path, state) { | ||
@@ -28,14 +27,10 @@ const { | ||
} = state; | ||
if (!(processPackages instanceof Map)) { | ||
return; | ||
} | ||
const source = path.node.source.value; | ||
const processImports = processPackages.get(source) || []; | ||
if (processImports.length === 0) { | ||
return; | ||
} | ||
const importSpecifiersToProcess = path.get('specifiers').filter(specifier => { | ||
@@ -46,11 +41,8 @@ return specifier.isImportSpecifier() && processImports.some(name => specifier.get('imported').isIdentifier({ | ||
}); | ||
if (importSpecifiersToProcess.length === 0) { | ||
return; | ||
} | ||
for (const importSpecifier of importSpecifiersToProcess) { | ||
const bindingName = importSpecifier.node.local.name; | ||
const binding = path.scope.getBinding(bindingName); | ||
if (binding != null) { | ||
@@ -61,7 +53,5 @@ addIdOption(binding, t, state.opts); | ||
} | ||
} | ||
}; | ||
} | ||
function addIdOption(binding, t, { | ||
@@ -72,19 +62,13 @@ webpack = true | ||
const callExpression = refPath.parentPath; | ||
if (!callExpression.isCallExpression()) { | ||
return; | ||
} | ||
const args = callExpression.get('arguments'); | ||
if (args.length === 0) { | ||
return; | ||
} | ||
const options = args[0]; | ||
if (!options.isObjectExpression()) { | ||
return; | ||
} | ||
const properties = options.get('properties'); | ||
@@ -96,9 +80,6 @@ const propertiesMap = {}; | ||
} | ||
const key = property.get('key'); | ||
if (!key.isIdentifier()) { | ||
return; | ||
} | ||
propertiesMap[key.node.name] = property; | ||
@@ -110,10 +91,7 @@ }); | ||
} = propertiesMap; | ||
if (id != null || loadProperty == null) { | ||
return; | ||
} | ||
const loaderMethod = loadProperty.isObjectProperty() ? loadProperty.get('value') : loadProperty.get('body'); | ||
const dynamicImports = []; | ||
if (!Array.isArray(loaderMethod)) { | ||
@@ -128,10 +106,7 @@ loaderMethod.traverse({ | ||
} | ||
}); | ||
} | ||
if (!dynamicImports.length) { | ||
return; | ||
} | ||
if (webpack) { | ||
@@ -138,0 +113,0 @@ loadProperty.insertAfter(t.objectProperty(t.identifier('id'), t.arrowFunctionExpression([], t.callExpression(t.memberExpression(t.identifier('require'), t.identifier('resolveWeak')), [dynamicImports[0].get('arguments')[0].node])))); |
@@ -17,3 +17,2 @@ 'use strict'; | ||
}, | ||
get resolved() { | ||
@@ -24,6 +23,4 @@ if (resolved == null && !hasTriedSyncResolve) { | ||
} | ||
return resolved; | ||
}, | ||
resolve: async () => { | ||
@@ -36,3 +33,2 @@ resolvePromise = resolvePromise || resolve(load); | ||
} | ||
async function resolve(load) { | ||
@@ -42,3 +38,2 @@ const resolved = await load(); | ||
} | ||
function normalize(module) { | ||
@@ -48,7 +43,5 @@ if (module == null) { | ||
} | ||
const value = typeof module === 'object' && 'default' in module ? module.default : module; | ||
return value == null ? null : value; | ||
} | ||
// Webpack does not like seeing an explicit require(someVariable) in code | ||
@@ -67,7 +60,8 @@ // because that is a dynamic require that it can’t resolve. This code | ||
const requireKey = 'require'; | ||
const nodeRequire = typeof global === 'object' && typeof global[requireKey] === 'function' && global[requireKey] || typeof module === 'object' && typeof module[requireKey] === 'function' && module[requireKey] || undefined; // If we have an ID, we try to first use Webpack’s internal stuff | ||
const nodeRequire = typeof global === 'object' && typeof global[requireKey] === 'function' && global[requireKey] || typeof module === 'object' && typeof module[requireKey] === 'function' && module[requireKey] || undefined; | ||
// If we have an ID, we try to first use Webpack’s internal stuff | ||
// to resolve the module. If those don’t exist, we know we aren’t | ||
// inside of a Webpack bundle, so we try to use Node’s native resolution | ||
// (which will work in environments like Jest’s test runner). | ||
function tryRequire(id) { | ||
@@ -77,3 +71,4 @@ if (typeof __webpack_require__ === 'function' && typeof __webpack_modules__ === 'object' && __webpack_modules__[id]) { | ||
return normalize(__webpack_require__(id)); | ||
} catch {// Just ignore failures | ||
} catch { | ||
// Just ignore failures | ||
} | ||
@@ -83,9 +78,8 @@ } else if (typeof nodeRequire === 'function') { | ||
return normalize(nodeRequire(id)); | ||
} catch {// Just ignore failures | ||
} catch { | ||
// Just ignore failures | ||
} | ||
} | ||
return undefined; | ||
} | ||
function trySynchronousResolve(id) { | ||
@@ -92,0 +86,0 @@ return tryRequire(id) || null; |
@@ -6,3 +6,2 @@ 'use strict'; | ||
exports.DeferTiming = void 0; | ||
(function (DeferTiming) { | ||
@@ -9,0 +8,0 @@ DeferTiming[DeferTiming["Mount"] = 0] = "Mount"; |
{ | ||
"name": "@shopify/async", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"license": "MIT", | ||
@@ -36,3 +36,3 @@ "description": "Primitives for loading parts of an application asynchronously", | ||
"@babel/plugin-syntax-dynamic-import": ">=7.0.0", | ||
"@babel/traverse": ">=7.0.0", | ||
"@babel/traverse": ">=7.23.2", | ||
"@babel/types": ">=7.0.0", | ||
@@ -39,0 +39,0 @@ "@types/babel__core": ">=7.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
452
30421