(deterministic, exportsInfo, isNamespace)
| 54 | * @returns {void} |
| 55 | */ |
| 56 | const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => { |
| 57 | if (!canMangle(exportsInfo)) return; |
| 58 | /** @type {UsedNames} */ |
| 59 | const usedNames = new Set(); |
| 60 | /** @type {ExportInfo[]} */ |
| 61 | const mangleableExports = []; |
| 62 | |
| 63 | // Avoid to renamed exports that are not provided when |
| 64 | // 1. it's not a namespace export: non-provided exports can be found in prototype chain |
| 65 | // 2. there are other provided exports and deterministic mode is chosen: |
| 66 | // non-provided exports would break the determinism |
| 67 | let avoidMangleNonProvided = !isNamespace; |
| 68 | if (!avoidMangleNonProvided && deterministic) { |
| 69 | for (const exportInfo of exportsInfo.ownedExports) { |
| 70 | if (exportInfo.provided !== false) { |
| 71 | avoidMangleNonProvided = true; |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | for (const exportInfo of exportsInfo.ownedExports) { |
| 77 | const name = exportInfo.name; |
| 78 | if (!exportInfo.hasUsedName()) { |
| 79 | if ( |
| 80 | // Can the export be mangled? |
| 81 | exportInfo.canMangle !== true || |
| 82 | // Never rename 1 char exports |
| 83 | (name.length === 1 && /^[a-z0-9_$]/i.test(name)) || |
| 84 | // Don't rename 2 char exports in deterministic mode |
| 85 | (deterministic && |
| 86 | name.length === 2 && |
| 87 | /^[a-z_$][a-z0-9_$]|^[1-9][0-9]/i.test(name)) || |
| 88 | // Don't rename exports that are not provided |
| 89 | (avoidMangleNonProvided && exportInfo.provided !== true) |
| 90 | ) { |
| 91 | exportInfo.setUsedName(name); |
| 92 | usedNames.add(name); |
| 93 | } else { |
| 94 | mangleableExports.push(exportInfo); |
| 95 | } |
| 96 | } |
| 97 | if (exportInfo.exportsInfoOwned) { |
| 98 | const used = exportInfo.getUsed(undefined); |
| 99 | if ( |
| 100 | used === UsageState.OnlyPropertiesUsed || |
| 101 | used === UsageState.Unused |
| 102 | ) { |
| 103 | mangleExportsInfo( |
| 104 | deterministic, |
| 105 | /** @type {ExportsInfo} */ (exportInfo.exportsInfo), |
| 106 | false |
| 107 | ); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | if (deterministic) { |
| 112 | assignDeterministicIds( |
| 113 | mangleableExports, |
no test coverage detected