소스 검색

解构支持类型定义解析

kj863257 3 년 전
부모
커밋
0e81587704
1개의 변경된 파일35개의 추가작업 그리고 1개의 파일을 삭제
  1. 35 1
      src/scripts/parsing/parser.js

+ 35 - 1
src/scripts/parsing/parser.js

@@ -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() {