Skip to content

Commit

Permalink
Fix string/number literals in interface method generic parameter defa…
Browse files Browse the repository at this point in the history
…ult/extends

Fixes #1035
  • Loading branch information
frank-weindel committed Jun 25, 2024
1 parent 4724f0e commit d84f2b1
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 89 deletions.
4 changes: 3 additions & 1 deletion TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ variables:
lookBehindOfPossiblyMultilineArrow: (?<=[(=,]|=>|{{lookBehindReturn}})
lookBehindOfObjectMemberPossiblyMultilineArrow: (?<=:)
# Identifier start | matching braces | matching parenthesis | matching square brackets
typeParamersStart: (((const\s+)?[_$[:alpha:]])|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}})
typeParamersStart: (((const\s+)?[_$\'"[:alnum:]])|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}})
typeParameters: (<\s*{{typeParamersStart}}([^=<>]|=[^<]|\<\s*{{typeParamersStart}}([^=<>]|=[^<]|\<\s*{{typeParamersStart}}([^=<>]|=[^<])*\>)*\>)*>\s*)
# typeParamersStart2: (((const\s+)?[_$\'[:alpha:]])|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}})
# typeParameters2: (<\s*{{typeParamersStart2}}([^=<>]|=[^<]|\<\s*{{typeParamersStart2}}([^=<>]|=[^<]|\<\s*{{typeParamersStart2}}([^=<>]|=[^<])*\>)*\>)*>\s*)
# Identifier start | matching braces | matching parenthesis | matching square brackets | matching strings
typeArgumentsStart: (((keyof|infer|typeof|readonly)\s+)|(({{identifier}}|{{matchingBraces}}|{{matchingParenthesis}}|{{matchingBrackets}}|{{quotedStrings}})(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))
typeArgumentsInnerExpressionPart: '[^<>\(]|{{matchingParenthesis}}|(?<==)\>'
Expand Down
106 changes: 53 additions & 53 deletions TypeScript.tmLanguage

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions TypeScriptReact.tmLanguage

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions tests/baselines/Issue1035.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
original file
-----------------------------------
let var1;

interface MyInterface {
func1<T = Lowercase<'StringLiteral'>>(): T;
func2<T = Lowercase<"StringLiteral">>(): T;
func3<T = Lowercase<123>>(): T;
}

let var2;

-----------------------------------

Grammar: TypeScript.tmLanguage
-----------------------------------
>let var1;
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts punctuation.terminator.statement.ts
>
^
source.ts
>interface MyInterface {
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^^^^^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
> func1<T = Lowercase<'StringLiteral'>>(): T;
^^
source.ts meta.interface.ts meta.method.declaration.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts keyword.operator.assignment.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.single.ts punctuation.definition.string.begin.ts
^^^^^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.single.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.single.ts punctuation.definition.string.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts entity.name.type.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
> func2<T = Lowercase<"StringLiteral">>(): T;
^^
source.ts meta.interface.ts meta.method.declaration.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts keyword.operator.assignment.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.double.ts punctuation.definition.string.begin.ts
^^^^^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.double.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts string.quoted.double.ts punctuation.definition.string.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts entity.name.type.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
> func3<T = Lowercase<123>>(): T;
^^
source.ts meta.interface.ts meta.method.declaration.ts
^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts keyword.operator.assignment.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts
^^^^^^^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
^^^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts constant.numeric.decimal.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.interface.ts meta.method.declaration.ts meta.return.type.ts entity.name.type.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
>
^
source.ts
>let var2;
^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts punctuation.terminator.statement.ts
>
^
source.ts
Loading

0 comments on commit d84f2b1

Please sign in to comment.