MCPcopy
hub / github.com/webpack/webpack / _preWalkObjectPattern

Method _preWalkObjectPattern

lib/javascript/JavascriptParser.js:3218–3276  ·  view source on GitHub ↗

* Pre walk object pattern. * @param {ObjectPattern} objectPattern object pattern * @returns {DestructuringAssignmentProperties | undefined} set of names or undefined if not all keys are identifiers

(objectPattern)

Source from the content-addressed store, hash-verified

3216 * @returns {DestructuringAssignmentProperties | undefined} set of names or undefined if not all keys are identifiers
3217 */
3218 _preWalkObjectPattern(objectPattern) {
3219 /** @type {DestructuringAssignmentProperties} */
3220 const props = new Set();
3221 const properties = objectPattern.properties;
3222 for (let i = 0; i < properties.length; i++) {
3223 const property = properties[i];
3224 if (property.type !== "Property") return;
3225 if (property.shorthand) {
3226 if (property.value.type === "Identifier") {
3227 this.scope.inShorthand = property.value.name;
3228 } else if (
3229 property.value.type === "AssignmentPattern" &&
3230 property.value.left.type === "Identifier"
3231 ) {
3232 this.scope.inShorthand = property.value.left.name;
3233 }
3234 }
3235 const key = property.key;
3236 if (key.type === "Identifier" && !property.computed) {
3237 const pattern =
3238 property.value.type === "ObjectPattern"
3239 ? this._preWalkObjectPattern(property.value)
3240 : property.value.type === "ArrayPattern"
3241 ? this._preWalkArrayPattern(property.value)
3242 : undefined;
3243 props.add({
3244 id: key.name,
3245 range: /** @type {Range} */ (key.range),
3246 loc: /** @type {SourceLocation} */ (key.loc),
3247 pattern,
3248 shorthand: this.scope.inShorthand
3249 });
3250 } else {
3251 const id = this.evaluateExpression(key);
3252 const str = id.asString();
3253 if (str) {
3254 const pattern =
3255 property.value.type === "ObjectPattern"
3256 ? this._preWalkObjectPattern(property.value)
3257 : property.value.type === "ArrayPattern"
3258 ? this._preWalkArrayPattern(property.value)
3259 : undefined;
3260 props.add({
3261 id: str,
3262 range: /** @type {Range} */ (key.range),
3263 loc: /** @type {SourceLocation} */ (key.loc),
3264 pattern,
3265 shorthand: this.scope.inShorthand
3266 });
3267 } else {
3268 // could not evaluate key
3269 return;
3270 }
3271 }
3272 this.scope.inShorthand = false;
3273 }
3274
3275 return props;

Callers 2

_preWalkArrayPatternMethod · 0.95

Calls 4

_preWalkArrayPatternMethod · 0.95
evaluateExpressionMethod · 0.95
addMethod · 0.45
asStringMethod · 0.45

Tested by

no test coverage detected