* Applies the plugin by registering its hooks on the compiler. * @param {JavascriptParser} parser the parser * @returns {void}
(parser)
| 190 | * @returns {void} |
| 191 | */ |
| 192 | apply(parser) { |
| 193 | parser.hooks.collectDestructuringAssignmentProperties.tap( |
| 194 | PLUGIN_NAME, |
| 195 | (expr) => { |
| 196 | if (expr.type === "ImportExpression") return true; |
| 197 | const nameInfo = parser.getNameForExpression(expr); |
| 198 | if ( |
| 199 | nameInfo && |
| 200 | nameInfo.rootInfo instanceof VariableInfo && |
| 201 | nameInfo.rootInfo.name && |
| 202 | parser.getTagData(nameInfo.rootInfo.name, dynamicImportTag) |
| 203 | ) { |
| 204 | return true; |
| 205 | } |
| 206 | } |
| 207 | ); |
| 208 | parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl) => { |
| 209 | if ( |
| 210 | decl.init && |
| 211 | decl.init.type === "AwaitExpression" && |
| 212 | decl.init.argument.type === "ImportExpression" && |
| 213 | decl.id.type === "Identifier" |
| 214 | ) { |
| 215 | parser.defineVariable(decl.id.name); |
| 216 | tagDynamicImportReferenced(parser, decl.init.argument, decl.id.name); |
| 217 | } |
| 218 | }); |
| 219 | parser.hooks.expression.for(dynamicImportTag).tap(PLUGIN_NAME, (expr) => { |
| 220 | const settings = /** @type {ImportSettings} */ (parser.currentTagData); |
| 221 | const referencedPropertiesInDestructuring = |
| 222 | parser.destructuringAssignmentPropertiesFor(expr); |
| 223 | if (referencedPropertiesInDestructuring) { |
| 224 | /** @type {RawReferencedExports} */ |
| 225 | const refsInDestructuring = []; |
| 226 | traverseDestructuringAssignmentProperties( |
| 227 | referencedPropertiesInDestructuring, |
| 228 | (stack) => refsInDestructuring.push(stack.map((p) => p.id)) |
| 229 | ); |
| 230 | for (const ids of refsInDestructuring) { |
| 231 | settings.references.push(ids); |
| 232 | } |
| 233 | } else { |
| 234 | settings.references.push([]); |
| 235 | } |
| 236 | return true; |
| 237 | }); |
| 238 | parser.hooks.expressionMemberChain |
| 239 | .for(dynamicImportTag) |
| 240 | .tap(PLUGIN_NAME, (_expression, members, membersOptionals) => { |
| 241 | const settings = /** @type {ImportSettings} */ (parser.currentTagData); |
| 242 | const ids = getNonOptionalPart(members, membersOptionals); |
| 243 | settings.references.push(ids); |
| 244 | return true; |
| 245 | }); |
| 246 | parser.hooks.callMemberChain |
| 247 | .for(dynamicImportTag) |
| 248 | .tap(PLUGIN_NAME, (expression, members, membersOptionals) => { |
| 249 | const { arguments: args } = expression; |
nothing calls this directly
no test coverage detected