()
| 5313 | // 11.1.4 Array Initialiser |
| 5314 | |
| 5315 | function parseArrayInitialiser() { |
| 5316 | var elements = [], blocks = [], filter = null, tmp, possiblecomprehension = true, |
| 5317 | marker = markerCreate(); |
| 5318 | |
| 5319 | expect('['); |
| 5320 | while (!match(']')) { |
| 5321 | if (lookahead.value === 'for' && |
| 5322 | lookahead.type === Token.Keyword) { |
| 5323 | if (!possiblecomprehension) { |
| 5324 | throwError({}, Messages.ComprehensionError); |
| 5325 | } |
| 5326 | matchKeyword('for'); |
| 5327 | tmp = parseForStatement({ignoreBody: true}); |
| 5328 | tmp.of = tmp.type === Syntax.ForOfStatement; |
| 5329 | tmp.type = Syntax.ComprehensionBlock; |
| 5330 | if (tmp.left.kind) { // can't be let or const |
| 5331 | throwError({}, Messages.ComprehensionError); |
| 5332 | } |
| 5333 | blocks.push(tmp); |
| 5334 | } else if (lookahead.value === 'if' && |
| 5335 | lookahead.type === Token.Keyword) { |
| 5336 | if (!possiblecomprehension) { |
| 5337 | throwError({}, Messages.ComprehensionError); |
| 5338 | } |
| 5339 | expectKeyword('if'); |
| 5340 | expect('('); |
| 5341 | filter = parseExpression(); |
| 5342 | expect(')'); |
| 5343 | } else if (lookahead.value === ',' && |
| 5344 | lookahead.type === Token.Punctuator) { |
| 5345 | possiblecomprehension = false; // no longer allowed. |
| 5346 | lex(); |
| 5347 | elements.push(null); |
| 5348 | } else { |
| 5349 | tmp = parseSpreadOrAssignmentExpression(); |
| 5350 | elements.push(tmp); |
| 5351 | if (tmp && tmp.type === Syntax.SpreadElement) { |
| 5352 | if (!match(']')) { |
| 5353 | throwError({}, Messages.ElementAfterSpreadElement); |
| 5354 | } |
| 5355 | } else if (!(match(']') || matchKeyword('for') || matchKeyword('if'))) { |
| 5356 | expect(','); // this lexes. |
| 5357 | possiblecomprehension = false; |
| 5358 | } |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | expect(']'); |
| 5363 | |
| 5364 | if (filter && !blocks.length) { |
| 5365 | throwError({}, Messages.ComprehensionRequiresBlock); |
| 5366 | } |
| 5367 | |
| 5368 | if (blocks.length) { |
| 5369 | if (elements.length !== 1) { |
| 5370 | throwError({}, Messages.ComprehensionError); |
| 5371 | } |
| 5372 | return markerApply(marker, delegate.createComprehensionExpression(filter, blocks, elements[0])); |
no test coverage detected