diff --git a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 index e5aff217..ddad5aec 100644 --- a/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 +++ b/chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4 @@ -876,9 +876,9 @@ singleExpression | singleExpression '?'? '!'? '.'? '[' expressionSequence ']' # MemberIndexExpression // for: `onHotUpdateSuccess?.();` // onChange?.(userName || password || null) - | singleExpression ('?' | '!')* '.' '#'? identifierName? typeArguments? # MemberDotExpression + | singleExpression ('?' | '!')* '.' '#'? identifierName? typeArguments? ('?' | '!')* # MemberDotExpression // for: `onHotUpdateSuccess?.();` - | singleExpression ('?' | '!')* '.' '#'? '(' identifierName? ')' # MemberDotExpression + | singleExpression ('?' | '!')* '.' '#'? '(' identifierName? ')' ('?' | '!')* # MemberDotExpression // request('/api/system-info', { method: 'GET' }); // | singleExpression arguments # MemberDotExpression @@ -1006,10 +1006,10 @@ identifierOrKeyWord ; identifierName - : reservedWord ('?' | '!')? + : reservedWord | Lodash | Dollar - | Identifier ('?' | '!')? + | Identifier ; reservedWord diff --git a/chapi-ast-typescript/src/main/java/chapi/ast/antlr/TypeScriptLexerBase.java b/chapi-ast-typescript/src/main/java/chapi/ast/antlr/TypeScriptLexerBase.java index 97370923..fd748a4e 100644 --- a/chapi-ast-typescript/src/main/java/chapi/ast/antlr/TypeScriptLexerBase.java +++ b/chapi-ast-typescript/src/main/java/chapi/ast/antlr/TypeScriptLexerBase.java @@ -58,8 +58,8 @@ public boolean IsStrictMode() { } /** - * @return {@code true} iff the cursor is inside a template string - * @implNote method name starts with upper case latter: see {@link #TypeScriptLexerBase} + * {@code true} iff the cursor is inside a template string + * method name starts with upper case latter: see {@link #TypeScriptLexerBase} */ public boolean IsInTemplateString() { return this.templateDepth > 0; diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt index a609c0cd..93905f0b 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt @@ -902,7 +902,7 @@ function hello2() { } @Test - internal fun optionCheckAfterData() { + fun optionCheckAfterData() { val code = """ const QualityGateProfile = () => { updateQualityGateProfile(profile.id!, profile).then(() => { @@ -914,7 +914,12 @@ const QualityGateProfile = () => { """ val codeFile = TypeScriptAnalyser().analysis(code, "index.tsx") - assertEquals(1, codeFile.DataStructures.size) + val defaultStruct = codeFile.DataStructures[0] + assertEquals(1, defaultStruct.Functions.size) + assertEquals(3, defaultStruct.Functions[0].FunctionCalls.size) + assertEquals("updateQualityGateProfile", defaultStruct.Functions[0].FunctionCalls[0].FunctionName) + assertEquals("", defaultStruct.Functions[0].FunctionCalls[1].FunctionName) + assertEquals("success", defaultStruct.Functions[0].FunctionCalls[2].FunctionName) } @Test diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt index 19bdff6f..f55e2d27 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptRegressionTest.kt @@ -162,4 +162,19 @@ export class PopupDirective { assertEquals(codeFile.DataStructures[0].Functions.size, 1) assertEquals(codeFile.DataStructures[0].Functions[0].Name, "openPopup") } + + @Test + fun private_issue2() { + val code = """ +export class PopupDirective { + get taskTitle(): string { + return this.isSubTask ? this.subTask?.name : this.commonTaskWorkOrder?.title; + } +}""" + + val codeFile = TypeScriptAnalyser().analysis(code, "index.tsx") + assertEquals(codeFile.DataStructures.size, 1) + assertEquals(codeFile.DataStructures[0].Functions.size, 1) + assertEquals(codeFile.DataStructures[0].Functions[0].Name, "get") + } }