MCPcopy
hub / github.com/webpack/webpack / findNewName

Function findNewName

lib/util/concatenate.js:124–163  ·  view source on GitHub ↗

* Returns found new name. * @param {string} oldName old name * @param {UsedNames} usedNamed1 used named 1 * @param {UsedNames} usedNamed2 used named 2 * @param {string} extraInfo extra info * @returns {string} found new name

(oldName, usedNamed1, usedNamed2, extraInfo)

Source from the content-addressed store, hash-verified

122 * @returns {string} found new name
123 */
124function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
125 let name = oldName;
126
127 if (name === DEFAULT_EXPORT) {
128 name = "";
129 }
130 if (name === NAMESPACE_OBJECT_EXPORT) {
131 name = "namespaceObject";
132 }
133
134 // Remove uncool stuff
135 extraInfo = extraInfo.replace(
136 /\.+\/|(?:\/index)?\.[a-zA-Z0-9]{1,4}(?:$|\s|\?)|\s*\+\s*\d+\s*modules/g,
137 ""
138 );
139
140 const splittedInfo = extraInfo.split("/");
141 while (splittedInfo.length) {
142 name = splittedInfo.pop() + (name ? `_${name}` : "");
143 const nameIdent = Template.toIdentifier(name);
144 if (
145 !usedNamed1.has(nameIdent) &&
146 (!usedNamed2 || !usedNamed2.has(nameIdent))
147 ) {
148 return nameIdent;
149 }
150 }
151
152 let i = 0;
153 let nameWithNumber = Template.toIdentifier(`${name}_${i}`);
154 while (
155 usedNamed1.has(nameWithNumber) ||
156 // eslint-disable-next-line no-unmodified-loop-condition
157 (usedNamed2 && usedNamed2.has(nameWithNumber))
158 ) {
159 i++;
160 nameWithNumber = Template.toIdentifier(`${name}_${i}`);
161 }
162 return nameWithNumber;
163}
164
165/** @typedef {Set<Scope>} ScopeSet */
166

Callers 5

_findNewNameMethod · 0.85
codeGenerationMethod · 0.85

Calls 5

splitMethod · 0.80
popMethod · 0.80
toIdentifierMethod · 0.80
replaceMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected