Skip to content

Commit

Permalink
fix(ts): merge type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 17, 2022
1 parent ded0de5 commit 38ed025
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
8 changes: 4 additions & 4 deletions chapi-ast-typescript/src/main/antlr/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1006,10 +1006,10 @@ identifierOrKeyWord
;

identifierName
: reservedWord ('?' | '!')?
: reservedWord
| Lodash
| Dollar
| Identifier ('?' | '!')?
| Identifier
;

reservedWord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ function hello2() {
}

@Test
internal fun optionCheckAfterData() {
fun optionCheckAfterData() {
val code = """
const QualityGateProfile = () => {
updateQualityGateProfile(profile.id!, profile).then(() => {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 38ed025

Please sign in to comment.