|
@@ -171,7 +171,41 @@ export class Parser {
|
|
|
}
|
|
|
|
|
|
matchTypeDefine() {
|
|
|
- return this.stream.match(TokenType.Identifier, true) && this.stream.match(TokenType.Identifier, false);
|
|
|
+ let typeDefine = this.stream.match(TokenType.Identifier, true);
|
|
|
+ if (!typeDefine) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ let index = this.stream.makeIndex();
|
|
|
+ try {
|
|
|
+ if ('new' === this.stream.prev().getText()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (this.stream.match(TokenType.Identifier, false)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ let end = this.stream.prev().getSpan().getEnd();
|
|
|
+ this.stream.next();
|
|
|
+ if (this.stream.hasMore() && this.stream.consume().getSpan().getSpan().getStart() === end) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ this.stream.resetIndex(index)
|
|
|
+ }
|
|
|
+ // destructuring support
|
|
|
+ let isMapAccess;
|
|
|
+ if ((isMapAccess = this.stream.match(TokenType.LeftCurly, true)) || this.stream.match(TokenType.LeftBracket, true)) {
|
|
|
+ do {
|
|
|
+ if (!this.stream.match(TokenType.Identifier, true)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } while (this.stream.match(TokenType.Comma, true));
|
|
|
+ if (isMapAccess) {
|
|
|
+ return this.stream.match(TokenType.RightCurly)
|
|
|
+ } else {
|
|
|
+ return this.stream.match(TokenType.RightBracket)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
matchVarDefine() {
|