| 698 | } |
| 699 | |
| 700 | private _consumeLet(startToken: LetStartToken) { |
| 701 | const name = startToken.parts[0]; |
| 702 | let valueToken: LetValueToken; |
| 703 | let endToken: LetEndToken; |
| 704 | |
| 705 | if (this._peek.type !== TokenType.LET_VALUE) { |
| 706 | this.errors.push( |
| 707 | TreeError.create( |
| 708 | startToken.parts[0], |
| 709 | startToken.sourceSpan, |
| 710 | `Invalid @let declaration "${name}". Declaration must have a value.`, |
| 711 | ), |
| 712 | ); |
| 713 | return; |
| 714 | } else { |
| 715 | valueToken = this._advance(); |
| 716 | } |
| 717 | |
| 718 | // Type cast is necessary here since TS narrowed the type of `peek` above. |
| 719 | if ((this._peek as Token).type !== TokenType.LET_END) { |
| 720 | this.errors.push( |
| 721 | TreeError.create( |
| 722 | startToken.parts[0], |
| 723 | startToken.sourceSpan, |
| 724 | `Unterminated @let declaration "${name}". Declaration must be terminated with a semicolon.`, |
| 725 | ), |
| 726 | ); |
| 727 | return; |
| 728 | } else { |
| 729 | endToken = this._advance(); |
| 730 | } |
| 731 | |
| 732 | const end = endToken.sourceSpan.end; |
| 733 | const span = new ParseSourceSpan( |
| 734 | startToken.sourceSpan.start, |
| 735 | end, |
| 736 | startToken.sourceSpan.fullStart, |
| 737 | ); |
| 738 | |
| 739 | // The start token usually captures the `@let`. Construct a name span by |
| 740 | // offsetting the start by the length of any text before the name. |
| 741 | const startOffset = startToken.sourceSpan.toString().lastIndexOf(name); |
| 742 | const nameStart = startToken.sourceSpan.start.moveBy(startOffset); |
| 743 | const nameSpan = new ParseSourceSpan(nameStart, startToken.sourceSpan.end); |
| 744 | const node = new html.LetDeclaration( |
| 745 | name, |
| 746 | valueToken.parts[0], |
| 747 | span, |
| 748 | nameSpan, |
| 749 | valueToken.sourceSpan, |
| 750 | ); |
| 751 | |
| 752 | this._addToParent(node); |
| 753 | } |
| 754 | |
| 755 | private _consumeIncompleteLet(token: IncompleteLetToken) { |
| 756 | // Incomplete `@let` declaration may end up with an empty name. |