()
| 3488 | } |
| 3489 | |
| 3490 | parseExportDeclaration(): Node.ExportDeclaration { |
| 3491 | if (this.context.inFunctionBody) { |
| 3492 | this.throwError(Messages.IllegalExportDeclaration); |
| 3493 | } |
| 3494 | |
| 3495 | const node = this.createNode(); |
| 3496 | this.expectKeyword('export'); |
| 3497 | |
| 3498 | let exportDeclaration; |
| 3499 | if (this.matchKeyword('default')) { |
| 3500 | // export default ... |
| 3501 | this.nextToken(); |
| 3502 | if (this.matchKeyword('function')) { |
| 3503 | // export default function foo () {} |
| 3504 | // export default function () {} |
| 3505 | const declaration = this.parseFunctionDeclaration(true); |
| 3506 | exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration)); |
| 3507 | } else if (this.matchKeyword('class')) { |
| 3508 | // export default class foo {} |
| 3509 | const declaration = this.parseClassDeclaration(true); |
| 3510 | exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration)); |
| 3511 | } else if (this.matchContextualKeyword('async')) { |
| 3512 | // export default async function f () {} |
| 3513 | // export default async function () {} |
| 3514 | // export default async x => x |
| 3515 | const declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression(); |
| 3516 | exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration)); |
| 3517 | } else { |
| 3518 | if (this.matchContextualKeyword('from')) { |
| 3519 | this.throwError(Messages.UnexpectedToken, this.lookahead.value); |
| 3520 | } |
| 3521 | // export default {}; |
| 3522 | // export default []; |
| 3523 | // export default (1 + 2); |
| 3524 | const declaration = this.match('{') ? this.parseObjectInitializer() : |
| 3525 | this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression(); |
| 3526 | this.consumeSemicolon(); |
| 3527 | exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration)); |
| 3528 | } |
| 3529 | |
| 3530 | } else if (this.match('*')) { |
| 3531 | // export * from 'foo'; |
| 3532 | this.nextToken(); |
| 3533 | if (!this.matchContextualKeyword('from')) { |
| 3534 | const message = this.lookahead.value ? Messages.UnexpectedToken : Messages.MissingFromClause; |
| 3535 | this.throwError(message, this.lookahead.value); |
| 3536 | } |
| 3537 | this.nextToken(); |
| 3538 | const src = this.parseModuleSpecifier(); |
| 3539 | this.consumeSemicolon(); |
| 3540 | exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src)); |
| 3541 | |
| 3542 | } else if (this.lookahead.type === Token.Keyword) { |
| 3543 | // export var f = 1; |
| 3544 | let declaration; |
| 3545 | switch (this.lookahead.value) { |
| 3546 | case 'let': |
| 3547 | case 'const': |
no test coverage detected