From 381571074bca1f707b09758aa968f54602d0e89b Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 11 Mar 2022 12:41:06 +0800 Subject: [PATCH] fix(ts): fix undefined issue --- .../src/main/antlr/TypeScriptLexer.g4 | 2 + .../src/main/antlr/TypeScriptLexer.tokens | 52 ++++++++++--------- .../src/main/antlr/TypeScriptParser.g4 | 12 ++--- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.g4 index 68fc548b..50c6f257 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.g4 @@ -168,6 +168,8 @@ Require: 'require'; Module: 'module'; Declare: 'declare'; +Undefined: 'undefined'; + Abstract: 'abstract'; Is: 'is'; diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.tokens b/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.tokens index 11753728..9633306e 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.tokens +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptLexer.tokens @@ -123,26 +123,27 @@ Namespace=122 Require=123 Module=124 Declare=125 -Abstract=126 -Is=127 -At=128 -Identifier=129 -StringLiteral=130 -BackTick=131 -WhiteSpaces=132 -LineTerminator=133 -HtmlComment=134 -CDataComment=135 -UnexpectedCharacter=136 -TemplateStringStartExpression=137 -TemplateStringAtom=138 -TagOpen=139 -TagClose=140 -TagSlashClose=141 -TagSlash=142 -TagName=143 -AttributeValue=144 -Attribute=145 +Undefined=126 +Abstract=127 +Is=128 +At=129 +Identifier=130 +StringLiteral=131 +BackTick=132 +WhiteSpaces=133 +LineTerminator=134 +HtmlComment=135 +CDataComment=136 +UnexpectedCharacter=137 +TemplateStringStartExpression=138 +TemplateStringAtom=139 +TagOpen=140 +TagClose=141 +TagSlashClose=142 +TagSlash=143 +TagName=144 +AttributeValue=145 +Attribute=146 '['=4 ']'=5 '('=6 @@ -258,8 +259,9 @@ Attribute=145 'require'=123 'module'=124 'declare'=125 -'abstract'=126 -'is'=127 -'@'=128 -'${'=137 -'/>'=141 +'undefined'=126 +'abstract'=127 +'is'=128 +'@'=129 +'${'=138 +'/>'=142 diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index 81ad8aac..f505917d 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -101,6 +101,7 @@ primaryType | typeQuery #QueryPrimType | This #ThisPrimType | typeReference Is primaryType #RedefinitionOfType + | 'undefined' #UndefinedType ; predefinedType @@ -523,6 +524,7 @@ htmlTagName htmlAttribute : htmlAttributeName '=' htmlAttributeValue | htmlAttributeName + | objectLiteral ; htmlAttributeName @@ -754,17 +756,15 @@ expressionSequence functionExpressionDeclaration : Function_ Identifier? '(' formalParameterList? ')' typeAnnotation? '{' functionBody '}' ; -// -//anoymousFunction -// : functionDeclaration # FunctionDecl -// | Async? Function_ '*'? '(' formalParameterList? ')' '{' functionBody '}' # AnoymousFunctionDecl -// | Async? arrowFunctionParameters '=>' arrowFunctionBody # ArrowFunction -// ; +jsxArrowFunction + : '(' formalParameterList (',' formalParameterList)* ')' '=>' arrowFunctionBody # JsxArrowFunctionDecl + ; singleExpression : functionExpressionDeclaration # FunctionExpression | arrowFunctionDeclaration # ArrowFunctionExpression // ECMAScript 6 + | jsxArrowFunction # JsxArrowFunctionExpression | Class Identifier? classTail # ClassExpression | singleExpression '[' expressionSequence ']' # MemberIndexExpression | singleExpression '?'? '!'? '.' '#'? identifierName nestedTypeGeneric? # MemberDotExpression