|
@@ -345,6 +345,21 @@ export class Parser {
|
|
|
|
|
|
parseVarDefine() {
|
|
|
let opening = this.stream.consume().getSpan();
|
|
|
+ // destructuring
|
|
|
+ let isMapAccess;
|
|
|
+ if ( (isMapAccess = this.stream.match(TokenType.LeftCurly, false)) || this.stream.match(TokenType.LeftBracket, false) ) {
|
|
|
+ this.stream.expect(TokenType.LeftCurly, TokenType.LeftBracket);
|
|
|
+ do {
|
|
|
+ this.stream.expect(TokenType.Identifier);
|
|
|
+ } while (this.stream.match(TokenType.Comma, true));
|
|
|
+ if (isMapAccess) {
|
|
|
+ this.stream.match(TokenType.RightCurly);
|
|
|
+ } else {
|
|
|
+ this.stream.match(TokenType.RightBracket);
|
|
|
+ }
|
|
|
+ this.stream.match(TokenType.Assignment, true);
|
|
|
+ return new VarDefine(new Span(opening, this.stream.getPrev().getSpan()), 'destructuring', this.parseExpression(), opening.getText())
|
|
|
+ }
|
|
|
let token = this.stream.expect(TokenType.Identifier);
|
|
|
this.checkKeyword(token.getSpan());
|
|
|
let varDefine;
|