From 3afa3ac9a26703f7b6fb37c752375f46490a73b3 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 30 Oct 2023 12:51:31 -0400 Subject: [PATCH] [TypeScript] Fix generic parameters in namespaced types --- JavaScript/TypeScript.sublime-syntax | 14 +++++++--- JavaScript/tests/syntax_test_tsx.tsx | 9 ++++++ JavaScript/tests/syntax_test_typescript.ts | 32 ++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/JavaScript/TypeScript.sublime-syntax b/JavaScript/TypeScript.sublime-syntax index 1ead7057e4..cd98496541 100644 --- a/JavaScript/TypeScript.sublime-syntax +++ b/JavaScript/TypeScript.sublime-syntax @@ -834,7 +834,9 @@ contexts: push: - match: '{{identifier_name}}' scope: support.class.js - set: ts-type-expression-end-no-line-terminator + set: + - ts-type-expression-end-no-line-terminator + - ts-optional-generic-type-arguments - match: extends{{identifier_break}} scope: keyword.operator.type.extends.js @@ -1063,9 +1065,13 @@ contexts: ts-type-basic: - match: '{{identifier_name}}' scope: support.class.js - set: - - include: ts-generic-type-arguments - - include: else-pop + set: ts-optional-generic-type-arguments + + ts-optional-generic-type-arguments: + - match: $ + pop: 1 + - include: ts-generic-type-arguments + - include: else-pop ts-type-template-string: - match: '`' diff --git a/JavaScript/tests/syntax_test_tsx.tsx b/JavaScript/tests/syntax_test_tsx.tsx index 9f275bec12..60ca310b3e 100644 --- a/JavaScript/tests/syntax_test_tsx.tsx +++ b/JavaScript/tests/syntax_test_tsx.tsx @@ -125,6 +125,15 @@ let x : T.U; // ^^^ meta.generic // ^ support.class +let x : T.U +// ^^^ meta.type +// ^ support.class +// ^ punctuation.accessor +// ^ support.class + +; +// <- meta.jsx - meta.type + // This is invalid TSX as the TypeScript type assertion is parsed as a JSX tag let strLength: number = (someValue).length; // ); // ^^^^^^^^ meta.tag - meta.assertion diff --git a/JavaScript/tests/syntax_test_typescript.ts b/JavaScript/tests/syntax_test_typescript.ts index eb4ab49aec..f3083e8121 100644 --- a/JavaScript/tests/syntax_test_typescript.ts +++ b/JavaScript/tests/syntax_test_typescript.ts @@ -1327,6 +1327,38 @@ let x: import ( "foo" ) . Bar ; // ^ punctuation.accessor // ^^^ support.class +let x: T.U; +// ^^^^ meta.type +// ^ support.class +// ^ punctuation.accessor +// ^ support.class +// ^ punctuation.terminator.statement + +let x: T.U[]; +// ^^^^ meta.type +// ^ support.class +// ^ punctuation.accessor +// ^ support.class +// ^^ storage.modifier.array +// ^ punctuation.terminator.statement + +let x: T.U[]; +// ^^^^ meta.type +// ^ support.class +// ^ punctuation.accessor +// ^ support.class +// ^^^ meta.generic +// ^^ storage.modifier.array +// ^ punctuation.terminator.statement + +let x: T.U +// ^^^^ meta.type +// ^ support.class +// ^ punctuation.accessor +// ^ support.class +[]; +//<- meta.sequence - meta.type + foo < bar > (); // ^^^ variable.function // ^^^^^^^ meta.generic