( source, ast, variable, moduleIdentifier, readableIdentifier, allUsedNames )
| 360 | * @returns {void} |
| 361 | */ |
| 362 | const renameInlinedModuleVariable = ( |
| 363 | source, |
| 364 | ast, |
| 365 | variable, |
| 366 | moduleIdentifier, |
| 367 | readableIdentifier, |
| 368 | allUsedNames |
| 369 | ) => { |
| 370 | /** @type {UsedNamesInScopeInfo} */ |
| 371 | const usedNamesInScopeInfo = new Map(); |
| 372 | /** @type {ScopeSet} */ |
| 373 | const ignoredScopes = new Set(); |
| 374 | |
| 375 | const name = variable.name; |
| 376 | const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo( |
| 377 | usedNamesInScopeInfo, |
| 378 | moduleIdentifier, |
| 379 | name |
| 380 | ); |
| 381 | |
| 382 | if (allUsedNames.has(name) || usedNames.has(name)) { |
| 383 | const references = getAllReferences(variable); |
| 384 | const allIdentifiers = new Set([ |
| 385 | ...references.map((r) => r.identifier), |
| 386 | ...variable.identifiers |
| 387 | ]); |
| 388 | for (const ref of references) { |
| 389 | addScopeSymbols(ref.from, usedNames, alreadyCheckedScopes, ignoredScopes); |
| 390 | } |
| 391 | |
| 392 | const newName = findNewName( |
| 393 | name, |
| 394 | allUsedNames, |
| 395 | usedNames, |
| 396 | readableIdentifier |
| 397 | ); |
| 398 | allUsedNames.add(newName); |
| 399 | for (const identifier of allIdentifiers) { |
| 400 | const r = /** @type {Range} */ (identifier.range); |
| 401 | const path = getPathInAst(ast, identifier); |
| 402 | if (path && path.length > 1) { |
| 403 | const maybeProperty = |
| 404 | path[1].type === "AssignmentPattern" && path[1].left === path[0] |
| 405 | ? path[2] |
| 406 | : path[1]; |
| 407 | if (maybeProperty.type === "Property" && maybeProperty.shorthand) { |
| 408 | source.insert(r[1], `: ${newName}`); |
| 409 | continue; |
| 410 | } |
| 411 | } |
| 412 | source.replace(r[0], r[1] - 1, newName); |
| 413 | } |
| 414 | } |
| 415 | allUsedNames.add(name); |
| 416 | }; |
| 417 | |
| 418 | const PLUGIN_NAME = "JavascriptModulesPlugin"; |
| 419 |
no test coverage detected