diff --git a/TypeScriptReact.YAML-tmLanguage b/TypeScriptReact.YAML-tmLanguage index f2d203de..50dfc255 100644 --- a/TypeScriptReact.YAML-tmLanguage +++ b/TypeScriptReact.YAML-tmLanguage @@ -12,7 +12,7 @@ variables: # because tsx cannot have cast expression, we can say ] # < typeparam extends + [<]\s*(const\s+)?{{identifier}}\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | #possiblyMultilineArrowExpressionBeforeEndOfLine: ({{typeParameters}})?\( possiblyMultilineArrow: ((<\s*$)|({{possiblyMultilineArrowWithoutTypeParameters}})) # during lookup treat ( followed by line end as arrow @@ -80,7 +80,7 @@ repository: begin: |- (?x) {{jsxLookBehindInExpression}} - (?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow + (?!<\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow (optional const modifier from TS 5.0) {{jsxTagStartLookahead}} end: (?!{{jsxTagStart}}) patterns: diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index a7aec5da..0c23f2ed 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -761,7 +761,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -804,7 +804,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -924,7 +924,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -967,7 +967,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -1590,7 +1590,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -1633,7 +1633,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -2057,7 +2057,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -2100,7 +2100,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -2678,7 +2678,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -4672,7 +4672,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -5350,7 +5350,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -5393,7 +5393,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -6686,7 +6686,7 @@ ) ) | ( - [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends + [<]\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>] # < typeparam extends (optional const modifier from TS 5.0) ) | # arrow function possible to detect only with => on same line ( @@ -9918,7 +9918,7 @@ begin (?x) (?<!\+\+|--)(?<=[({\[,?=>:*]|&&|\|\||\?|\*\/|^await|[^\._$[:alnum:]]await|^return|[^\._$[:alnum:]]return|^default|[^\._$[:alnum:]]default|^yield|[^\._$[:alnum:]]yield|^)\s* - (?!<\s*[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow + (?!<\s*(const\s+)?[_$[:alpha:]][_$[:alnum:]]*((\s+extends\s+[^=>])|,)) # look ahead is not type parameter of arrow (optional const modifier from TS 5.0) (?=(<)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?<!\.|-))(?=((<\s*)|(\s+))(?!\?)|\/?>)) end (?!(<)\s*(?:([_$[:alpha:]][-_$[:alnum:].]*)(?<!\.|-)(:))?((?:[a-z][a-z0-9]*|([_$[:alpha:]][-_$[:alnum:].]*))(?<!\.|-))(?=((<\s*)|(\s+))(?!\?)|\/?>)) diff --git a/tests/baselines/constTypeParameter.baseline.txt b/tests/baselines/constTypeParameter.baseline.txt index 48386d73..d4ac7661 100644 --- a/tests/baselines/constTypeParameter.baseline.txt +++ b/tests/baselines/constTypeParameter.baseline.txt @@ -1,6 +1,5 @@ original file ----------------------------------- -// @onlyOwnGrammar - this has type parameters that would be jsx in tsx files declare function f1(x: T): T; declare function f2(x: T | undefined): T; declare function f3(x: T): T[]; @@ -12,7 +11,6 @@ class C1 { foo(x: U) { return x; } } const C2 = class {} -const fx1 = (x: T) => x; const fx2 = (x: T) => x; interface I1 { x: T } // Error interface I2 { @@ -28,11 +26,6 @@ function set(obj: T, path: P, value: GetPa Grammar: TypeScript.tmLanguage ----------------------------------- ->// @onlyOwnGrammar - this has type parameters that would be jsx in tsx files - ^^ - source.ts comment.line.double-slash.ts punctuation.definition.comment.ts - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.ts comment.line.double-slash.ts >declare function f1(x: T): T; ^^^^^^^ source.ts meta.function.ts storage.modifier.ts @@ -476,51 +469,6 @@ Grammar: TypeScript.tmLanguage source.ts meta.var.expr.ts meta.class.ts punctuation.definition.block.ts ^ source.ts meta.var.expr.ts meta.class.ts punctuation.definition.block.ts ->const fx1 = (x: T) => x; - ^^^^^ - 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.constant.ts entity.name.function.ts - ^ - source.ts meta.var.expr.ts meta.var-single-variable.expr.ts - ^ - source.ts meta.var.expr.ts keyword.operator.assignment.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts - ^^^^^ - source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts storage.modifier.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts entity.name.type.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts - ^^ - source.ts meta.var.expr.ts meta.arrow.ts storage.type.function.arrow.ts - ^ - source.ts meta.var.expr.ts meta.arrow.ts - ^ - source.ts meta.var.expr.ts variable.other.readwrite.ts - ^ - source.ts punctuation.terminator.statement.ts >const fx2 = (x: T) => x; ^^^^^ source.ts meta.var.expr.ts storage.type.ts diff --git a/tests/baselines/constTypeParameterJsxOnly.baseline.txt b/tests/baselines/constTypeParameterJsxOnly.baseline.txt new file mode 100644 index 00000000..01c2b730 --- /dev/null +++ b/tests/baselines/constTypeParameterJsxOnly.baseline.txt @@ -0,0 +1,62 @@ +original file +----------------------------------- +// @onlyOwnGrammar - bare `(x: T) => x` in expression position is unresolvably jsx-ambiguous in tsx +const fx1 = (x: T) => x; + +----------------------------------- + +Grammar: TypeScript.tmLanguage +----------------------------------- +>// @onlyOwnGrammar - bare `(x: T) => x` in expression position is unresolvably jsx-ambiguous in tsx + ^^ + source.ts comment.line.double-slash.ts punctuation.definition.comment.ts + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + source.ts comment.line.double-slash.ts +>const fx1 = (x: T) => x; + ^^^^^ + 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.constant.ts entity.name.function.ts + ^ + source.ts meta.var.expr.ts meta.var-single-variable.expr.ts + ^ + source.ts meta.var.expr.ts keyword.operator.assignment.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts + ^^^^^ + source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts storage.modifier.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts entity.name.type.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts variable.parameter.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts + ^^ + source.ts meta.var.expr.ts meta.arrow.ts storage.type.function.arrow.ts + ^ + source.ts meta.var.expr.ts meta.arrow.ts + ^ + source.ts meta.var.expr.ts variable.other.readwrite.ts + ^ + source.ts punctuation.terminator.statement.ts +> + ^ + source.ts \ No newline at end of file diff --git a/tests/cases/constTypeParameter.ts b/tests/cases/constTypeParameter.ts index cc9290a5..fe8363e6 100644 --- a/tests/cases/constTypeParameter.ts +++ b/tests/cases/constTypeParameter.ts @@ -1,4 +1,3 @@ -// @onlyOwnGrammar - this has type parameters that would be jsx in tsx files declare function f1(x: T): T; declare function f2(x: T | undefined): T; declare function f3(x: T): T[]; @@ -10,7 +9,6 @@ class C1 { foo(x: U) { return x; } } const C2 = class {} -const fx1 = (x: T) => x; const fx2 = (x: T) => x; interface I1 { x: T } // Error interface I2 { diff --git a/tests/cases/constTypeParameterJsxOnly.ts b/tests/cases/constTypeParameterJsxOnly.ts new file mode 100644 index 00000000..4c09afcc --- /dev/null +++ b/tests/cases/constTypeParameterJsxOnly.ts @@ -0,0 +1,2 @@ +// @onlyOwnGrammar - bare `(x: T) => x` in expression position is unresolvably jsx-ambiguous in tsx +const fx1 = (x: T) => x;