MCPcopy Create free account
hub / github.com/babel/babel / ArrayExpression

Function ArrayExpression

packages/babel-generator/src/generators/types.ts:116–145  ·  view source on GitHub ↗
(this: Printer, node: t.ArrayExpression)

Source from the content-addressed store, hash-verified

114}
115
116export function ArrayExpression(this: Printer, node: t.ArrayExpression) {
117 const elems = node.elements;
118 const len = elems.length;
119
120 this.token("[");
121
122 const oldNoLineTerminatorAfterNode = this.enterDelimited();
123
124 for (let i = 0; i < elems.length; i++) {
125 const elem = elems[i];
126 if (elem) {
127 if (i > 0) this.space();
128 this.print(elem, undefined, true);
129 if (i < len - 1 || this.shouldPrintTrailingComma("]")) {
130 this.tokenChar(charCodes.comma, i);
131 }
132 } else {
133 // If the array expression ends with a hole, that hole
134 // will be ignored by the interpreter, but if it ends with
135 // two (or more) holes, we need to write out two (or more)
136 // commas so that the resulting code is interpreted with
137 // both (all) of the holes.
138 this.tokenChar(charCodes.comma, i);
139 }
140 }
141
142 this._noLineTerminatorAfterNode = oldNoLineTerminatorAfterNode;
143
144 this.token("]");
145}
146
147export { ArrayExpression as ArrayPattern };
148

Callers

nothing calls this directly

Calls 6

enterDelimitedMethod · 0.80
tokenMethod · 0.45
spaceMethod · 0.45
printMethod · 0.45
tokenCharMethod · 0.45

Tested by

no test coverage detected