|
493 | 493 | SCOPE_SUPER = 64, |
494 | 494 | SCOPE_DIRECT_SUPER = 128, |
495 | 495 | SCOPE_CLASS_STATIC_BLOCK = 256, |
| 496 | + SCOPE_CLASS_FIELD_INIT = 512, |
496 | 497 | SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK; |
497 | 498 |
|
498 | 499 | function functionFlags(async, generator) { |
|
603 | 604 |
|
604 | 605 | prototypeAccessors.inFunction.get = function () { return (this.currentVarScope().flags & SCOPE_FUNCTION) > 0 }; |
605 | 606 |
|
606 | | - prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 && !this.currentVarScope().inClassFieldInit }; |
| 607 | + prototypeAccessors.inGenerator.get = function () { return (this.currentVarScope().flags & SCOPE_GENERATOR) > 0 }; |
607 | 608 |
|
608 | | - prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 && !this.currentVarScope().inClassFieldInit }; |
| 609 | + prototypeAccessors.inAsync.get = function () { return (this.currentVarScope().flags & SCOPE_ASYNC) > 0 }; |
609 | 610 |
|
610 | 611 | prototypeAccessors.canAwait.get = function () { |
611 | 612 | for (var i = this.scopeStack.length - 1; i >= 0; i--) { |
612 | | - var scope = this.scopeStack[i]; |
613 | | - if (scope.inClassFieldInit || scope.flags & SCOPE_CLASS_STATIC_BLOCK) { return false } |
614 | | - if (scope.flags & SCOPE_FUNCTION) { return (scope.flags & SCOPE_ASYNC) > 0 } |
| 613 | + var ref = this.scopeStack[i]; |
| 614 | + var flags = ref.flags; |
| 615 | + if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT)) { return false } |
| 616 | + if (flags & SCOPE_FUNCTION) { return (flags & SCOPE_ASYNC) > 0 } |
615 | 617 | } |
616 | 618 | return (this.inModule && this.options.ecmaVersion >= 13) || this.options.allowAwaitOutsideFunction |
617 | 619 | }; |
618 | 620 |
|
619 | 621 | prototypeAccessors.allowSuper.get = function () { |
620 | 622 | var ref = this.currentThisScope(); |
621 | 623 | var flags = ref.flags; |
622 | | - var inClassFieldInit = ref.inClassFieldInit; |
623 | | - return (flags & SCOPE_SUPER) > 0 || inClassFieldInit || this.options.allowSuperOutsideMethod |
| 624 | + return (flags & SCOPE_SUPER) > 0 || this.options.allowSuperOutsideMethod |
624 | 625 | }; |
625 | 626 |
|
626 | 627 | prototypeAccessors.allowDirectSuper.get = function () { return (this.currentThisScope().flags & SCOPE_DIRECT_SUPER) > 0 }; |
627 | 628 |
|
628 | 629 | prototypeAccessors.treatFunctionsAsVar.get = function () { return this.treatFunctionsAsVarInScope(this.currentScope()) }; |
629 | 630 |
|
630 | 631 | prototypeAccessors.allowNewDotTarget.get = function () { |
631 | | - var ref = this.currentThisScope(); |
632 | | - var flags = ref.flags; |
633 | | - var inClassFieldInit = ref.inClassFieldInit; |
634 | | - return (flags & (SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK)) > 0 || inClassFieldInit |
| 632 | + for (var i = this.scopeStack.length - 1; i >= 0; i--) { |
| 633 | + var ref = this.scopeStack[i]; |
| 634 | + var flags = ref.flags; |
| 635 | + if (flags & (SCOPE_CLASS_STATIC_BLOCK | SCOPE_CLASS_FIELD_INIT) || |
| 636 | + ((flags & SCOPE_FUNCTION) && !(flags & SCOPE_ARROW))) { return true } |
| 637 | + } |
| 638 | + return false |
635 | 639 | }; |
636 | 640 |
|
637 | 641 | prototypeAccessors.inClassStaticBlock.get = function () { |
|
1558 | 1562 |
|
1559 | 1563 | if (this.eat(types$1.eq)) { |
1560 | 1564 | // To raise SyntaxError if 'arguments' exists in the initializer. |
1561 | | - var scope = this.currentThisScope(); |
1562 | | - var inClassFieldInit = scope.inClassFieldInit; |
1563 | | - scope.inClassFieldInit = true; |
| 1565 | + this.enterScope(SCOPE_CLASS_FIELD_INIT | SCOPE_SUPER); |
1564 | 1566 | field.value = this.parseMaybeAssign(); |
1565 | | - scope.inClassFieldInit = inClassFieldInit; |
| 1567 | + this.exitScope(); |
1566 | 1568 | } else { |
1567 | 1569 | field.value = null; |
1568 | 1570 | } |
|
1704 | 1706 | { this.checkExport(exports, node.declaration.id, node.declaration.id.start); } |
1705 | 1707 | node.specifiers = []; |
1706 | 1708 | node.source = null; |
| 1709 | + if (this.options.ecmaVersion >= 16) |
| 1710 | + { node.attributes = []; } |
1707 | 1711 | } else { // export { x, y as z } [from '...'] |
1708 | 1712 | node.declaration = null; |
1709 | 1713 | node.specifiers = this.parseExportSpecifiers(exports); |
|
1727 | 1731 | } |
1728 | 1732 |
|
1729 | 1733 | node.source = null; |
| 1734 | + if (this.options.ecmaVersion >= 16) |
| 1735 | + { node.attributes = []; } |
1730 | 1736 | } |
1731 | 1737 | this.semicolon(); |
1732 | 1738 | } |
|
3306 | 3312 | }; |
3307 | 3313 |
|
3308 | 3314 | pp$5.parseGetterSetter = function(prop) { |
3309 | | - prop.kind = prop.key.name; |
| 3315 | + var kind = prop.key.name; |
3310 | 3316 | this.parsePropertyName(prop); |
3311 | 3317 | prop.value = this.parseMethod(false); |
| 3318 | + prop.kind = kind; |
3312 | 3319 | var paramCount = prop.kind === "get" ? 0 : 1; |
3313 | 3320 | if (prop.value.params.length !== paramCount) { |
3314 | 3321 | var start = prop.value.start; |
|
3331 | 3338 | prop.kind = "init"; |
3332 | 3339 | } else if (this.options.ecmaVersion >= 6 && this.type === types$1.parenL) { |
3333 | 3340 | if (isPattern) { this.unexpected(); } |
3334 | | - prop.kind = "init"; |
3335 | 3341 | prop.method = true; |
3336 | 3342 | prop.value = this.parseMethod(isGenerator, isAsync); |
| 3343 | + prop.kind = "init"; |
3337 | 3344 | } else if (!isPattern && !containsEsc && |
3338 | 3345 | this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && |
3339 | 3346 | (prop.key.name === "get" || prop.key.name === "set") && |
|
3345 | 3352 | this.checkUnreserved(prop.key); |
3346 | 3353 | if (prop.key.name === "await" && !this.awaitIdentPos) |
3347 | 3354 | { this.awaitIdentPos = startPos; } |
3348 | | - prop.kind = "init"; |
3349 | 3355 | if (isPattern) { |
3350 | 3356 | prop.value = this.parseMaybeDefault(startPos, startLoc, this.copyNode(prop.key)); |
3351 | 3357 | } else if (this.type === types$1.eq && refDestructuringErrors) { |
|
3355 | 3361 | } else { |
3356 | 3362 | prop.value = this.copyNode(prop.key); |
3357 | 3363 | } |
| 3364 | + prop.kind = "init"; |
3358 | 3365 | prop.shorthand = true; |
3359 | 3366 | } else { this.unexpected(); } |
3360 | 3367 | }; |
|
3530 | 3537 | { this.raiseRecoverable(start, "Cannot use 'yield' as identifier inside a generator"); } |
3531 | 3538 | if (this.inAsync && name === "await") |
3532 | 3539 | { this.raiseRecoverable(start, "Cannot use 'await' as identifier inside an async function"); } |
3533 | | - if (this.currentThisScope().inClassFieldInit && name === "arguments") |
| 3540 | + if (!(this.currentThisScope().flags & SCOPE_VAR) && name === "arguments") |
3534 | 3541 | { this.raiseRecoverable(start, "Cannot use 'arguments' in class field initializer"); } |
3535 | 3542 | if (this.inClassStaticBlock && (name === "arguments" || name === "await")) |
3536 | 3543 | { this.raise(start, ("Cannot use " + name + " in class static initialization block")); } |
|
3643 | 3650 | pp$4.raise = function(pos, message) { |
3644 | 3651 | var loc = getLineInfo(this.input, pos); |
3645 | 3652 | message += " (" + loc.line + ":" + loc.column + ")"; |
| 3653 | + if (this.sourceFile) { |
| 3654 | + message += " in " + this.sourceFile; |
| 3655 | + } |
3646 | 3656 | var err = new SyntaxError(message); |
3647 | 3657 | err.pos = pos; err.loc = loc; err.raisedAt = this.pos; |
3648 | 3658 | throw err |
|
3666 | 3676 | this.lexical = []; |
3667 | 3677 | // A list of lexically-declared FunctionDeclaration names in the current lexical scope |
3668 | 3678 | this.functions = []; |
3669 | | - // A switch to disallow the identifier reference 'arguments' |
3670 | | - this.inClassFieldInit = false; |
3671 | 3679 | }; |
3672 | 3680 |
|
3673 | 3681 | // The functions in this module keep track of declared variables in the current scope in order to detect duplicate variable names. |
|
3737 | 3745 | pp$3.currentVarScope = function() { |
3738 | 3746 | for (var i = this.scopeStack.length - 1;; i--) { |
3739 | 3747 | var scope = this.scopeStack[i]; |
3740 | | - if (scope.flags & SCOPE_VAR) { return scope } |
| 3748 | + if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK)) { return scope } |
3741 | 3749 | } |
3742 | 3750 | }; |
3743 | 3751 |
|
3744 | 3752 | // Could be useful for `this`, `new.target`, `super()`, `super.property`, and `super[property]`. |
3745 | 3753 | pp$3.currentThisScope = function() { |
3746 | 3754 | for (var i = this.scopeStack.length - 1;; i--) { |
3747 | 3755 | var scope = this.scopeStack[i]; |
3748 | | - if (scope.flags & SCOPE_VAR && !(scope.flags & SCOPE_ARROW)) { return scope } |
| 3756 | + if (scope.flags & (SCOPE_VAR | SCOPE_CLASS_FIELD_INIT | SCOPE_CLASS_STATIC_BLOCK) && |
| 3757 | + !(scope.flags & SCOPE_ARROW)) { return scope } |
3749 | 3758 | } |
3750 | 3759 | }; |
3751 | 3760 |
|
|
6099 | 6108 | // [walk]: util/walk.js |
6100 | 6109 |
|
6101 | 6110 |
|
6102 | | - var version = "8.14.0"; |
| 6111 | + var version = "8.14.1"; |
6103 | 6112 |
|
6104 | 6113 | Parser.acorn = { |
6105 | 6114 | Parser: Parser, |
|
0 commit comments