* Walk import then fulfilled callback. * @param {JavascriptParser} parser javascript parser * @param {ImportExpression} importCall import expression * @param {ArrowFunctionExpression | FunctionExpression} fulfilledCallback the fulfilled callback * @param {Identifier | ObjectPattern} namespaceObj
( parser, importCall, fulfilledCallback, namespaceObjArg )
| 109 | * @param {Identifier | ObjectPattern} namespaceObjArg the argument of namespace object= |
| 110 | */ |
| 111 | function walkImportThenFulfilledCallback( |
| 112 | parser, |
| 113 | importCall, |
| 114 | fulfilledCallback, |
| 115 | namespaceObjArg |
| 116 | ) { |
| 117 | const arrow = fulfilledCallback.type === "ArrowFunctionExpression"; |
| 118 | const wasTopLevel = parser.scope.topLevelScope; |
| 119 | parser.scope.topLevelScope = arrow ? (wasTopLevel ? "arrow" : false) : false; |
| 120 | const scopeParams = [...fulfilledCallback.params]; |
| 121 | |
| 122 | // Add function name in scope for recursive calls |
| 123 | if (!arrow && fulfilledCallback.id) { |
| 124 | scopeParams.push(fulfilledCallback.id); |
| 125 | } |
| 126 | |
| 127 | parser.inFunctionScope(!arrow, scopeParams, () => { |
| 128 | if (namespaceObjArg.type === "Identifier") { |
| 129 | tagDynamicImportReferenced(parser, importCall, namespaceObjArg.name); |
| 130 | } else { |
| 131 | parser.enterDestructuringAssignment(namespaceObjArg, importCall); |
| 132 | const referencedPropertiesInDestructuring = |
| 133 | parser.destructuringAssignmentPropertiesFor(importCall); |
| 134 | if (referencedPropertiesInDestructuring) { |
| 135 | const state = getState(parser); |
| 136 | const references = /** @type {RawReferencedExports} */ ( |
| 137 | state.get(importCall) |
| 138 | ); |
| 139 | /** @type {RawReferencedExports} */ |
| 140 | const refsInDestructuring = []; |
| 141 | traverseDestructuringAssignmentProperties( |
| 142 | referencedPropertiesInDestructuring, |
| 143 | (stack) => refsInDestructuring.push(stack.map((p) => p.id)) |
| 144 | ); |
| 145 | for (const ids of refsInDestructuring) { |
| 146 | references.push(ids); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | for (const param of fulfilledCallback.params) { |
| 151 | parser.walkPattern(param); |
| 152 | } |
| 153 | if (fulfilledCallback.body.type === "BlockStatement") { |
| 154 | parser.detectMode(fulfilledCallback.body.body); |
| 155 | const prev = parser.prevStatement; |
| 156 | parser.preWalkStatement(fulfilledCallback.body); |
| 157 | parser.prevStatement = prev; |
| 158 | parser.walkStatement(fulfilledCallback.body); |
| 159 | } else { |
| 160 | parser.walkExpression(fulfilledCallback.body); |
| 161 | } |
| 162 | }); |
| 163 | parser.scope.topLevelScope = wasTopLevel; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Exports from enumerable. |
no test coverage detected