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

Function ArrayExpression

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

Source from the content-addressed store, hash-verified

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

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