From 48007533ced455bf3cff79fb0f2553b7e6e1fef8 Mon Sep 17 00:00:00 2001 From: Emily Marigold Klassen Date: Thu, 2 Jan 2020 14:00:45 -0800 Subject: [PATCH] Improve scopes of type cast declarations --- TypeScript.YAML-tmLanguage | 7 ++++--- TypeScript.tmLanguage | 8 +++++--- TypeScriptReact.tmLanguage | 6 ++++-- tests/baselines/Issue314.baseline.txt | 4 ++-- tests/baselines/Issue500.baseline.txt | 6 +++--- tests/baselines/Issue59.baseline.txt | 4 ++-- tests/baselines/Issue647.baseline.txt | 2 +- tests/baselines/Issue695.baseline.txt | 2 +- tests/baselines/Issue762.baseline.txt | 4 ++-- tests/baselines/constType.baseline.txt | 10 +++++----- tests/baselines/constTypeAssert.baseline.txt | 2 +- 11 files changed, 30 insertions(+), 25 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index bf2000ae..5ccef9bb 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -1375,7 +1375,7 @@ repository: match: '{{startOfIdentifier}}(as)\s+(const)(?=\s*([,}]|$))' captures: '1': { name: keyword.control.as.ts } - '2': { name: storage.modifier.ts } + '2': { name: storage.modifier.const.type.ts } - name: meta.object.member.ts begin: '{{startOfIdentifier}}(as)\s+' beginCaptures: @@ -1561,7 +1561,7 @@ repository: match: \s*(<)\s*(const)\s*(>) captures: '1': { name: meta.brace.angle.ts } - '2': { name: storage.modifier.ts } + '2': { name: storage.modifier.const.type.ts } '3': { name: meta.brace.angle.ts } - name: cast.expr.ts # We need to differentiate between the relational '<' operator and the beginning of a type assertion/cast using the surrounding context. @@ -1624,11 +1624,12 @@ repository: - match: '{{startOfIdentifier}}(as)\s+(const)(?=\s*($|[;,:})\]]))' captures: '1': { name: keyword.control.as.ts } - '2': { name: storage.modifier.ts } + '2': { name: storage.modifier.const.type.ts } - begin: '{{startOfIdentifier}}(as)\s+' beginCaptures: '1': { name: keyword.control.as.ts } end: (?=$|^|[;,:})\]]|\|\||\&\&|({{startOfIdentifier}}(as)\s+)|(\s+\<)) + contentName: meta.type.cast.ts patterns: - include: '#type' - name: keyword.operator.spread.ts diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index 8a063d78..5031940e 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -4440,7 +4440,7 @@ 2 name - storage.modifier.ts + storage.modifier.const.type.ts @@ -5099,7 +5099,7 @@ 2 name - storage.modifier.ts + storage.modifier.const.type.ts 3 @@ -5281,7 +5281,7 @@ 2 name - storage.modifier.ts + storage.modifier.const.type.ts @@ -5298,6 +5298,8 @@ end (?=$|^|[;,:})\]]|\|\||\&\&|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+)|(\s+\<)) + contentName + meta.type.cast.ts patterns diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 33132db5..97412a22 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -4464,7 +4464,7 @@ 2 name - storage.modifier.tsx + storage.modifier.const.type.tsx @@ -5227,7 +5227,7 @@ 2 name - storage.modifier.tsx + storage.modifier.const.type.tsx @@ -5244,6 +5244,8 @@ end (?=$|^|[;,:})\]]|\|\||\&\&|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+)|(\s+\<)) + contentName + meta.type.cast.tsx patterns diff --git a/tests/baselines/Issue314.baseline.txt b/tests/baselines/Issue314.baseline.txt index ba5db05c..8c5b881b 100644 --- a/tests/baselines/Issue314.baseline.txt +++ b/tests/baselines/Issue314.baseline.txt @@ -36,9 +36,9 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts ^ - source.ts meta.var.expr.ts entity.name.type.ts + source.ts meta.var.expr.ts meta.type.cast.ts entity.name.type.ts ^ - source.ts meta.var.expr.ts + source.ts meta.var.expr.ts meta.type.cast.ts ^ source.ts meta.var.expr.ts keyword.operator.ternary.ts ^ diff --git a/tests/baselines/Issue500.baseline.txt b/tests/baselines/Issue500.baseline.txt index 030b1293..025883de 100644 --- a/tests/baselines/Issue500.baseline.txt +++ b/tests/baselines/Issue500.baseline.txt @@ -15,14 +15,14 @@ Grammar: TypeScript.tmLanguage ^ source.ts ^^^ - source.ts support.type.primitive.ts + source.ts meta.type.cast.ts support.type.primitive.ts ^ - source.ts + source.ts meta.type.cast.ts ^^ source.ts keyword.control.as.ts ^ source.ts ^^^^^^ - source.ts support.type.primitive.ts + source.ts meta.type.cast.ts support.type.primitive.ts ^ source.ts punctuation.terminator.statement.ts \ No newline at end of file diff --git a/tests/baselines/Issue59.baseline.txt b/tests/baselines/Issue59.baseline.txt index 4ee048e2..68b98da5 100644 --- a/tests/baselines/Issue59.baseline.txt +++ b/tests/baselines/Issue59.baseline.txt @@ -45,9 +45,9 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.class.ts meta.field.declaration.ts ^ - source.ts meta.class.ts meta.field.declaration.ts meta.object.type.ts punctuation.definition.block.ts + source.ts meta.class.ts meta.field.declaration.ts meta.type.cast.ts meta.object.type.ts punctuation.definition.block.ts ^ - source.ts meta.class.ts meta.field.declaration.ts meta.object.type.ts punctuation.definition.block.ts + source.ts meta.class.ts meta.field.declaration.ts meta.type.cast.ts meta.object.type.ts punctuation.definition.block.ts ^ source.ts meta.class.ts punctuation.terminator.statement.ts > public a: string; diff --git a/tests/baselines/Issue647.baseline.txt b/tests/baselines/Issue647.baseline.txt index 72677fef..de59cd95 100644 --- a/tests/baselines/Issue647.baseline.txt +++ b/tests/baselines/Issue647.baseline.txt @@ -52,7 +52,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.function.ts meta.block.ts ^^^^^^ - source.ts meta.function.ts meta.block.ts support.type.primitive.ts + source.ts meta.function.ts meta.block.ts meta.type.cast.ts support.type.primitive.ts ^ source.ts meta.function.ts meta.block.ts ^ diff --git a/tests/baselines/Issue695.baseline.txt b/tests/baselines/Issue695.baseline.txt index c447c807..346f85d0 100644 --- a/tests/baselines/Issue695.baseline.txt +++ b/tests/baselines/Issue695.baseline.txt @@ -127,6 +127,6 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.ts meta.var.expr.ts entity.name.type.ts + source.ts meta.var.expr.ts meta.type.cast.ts entity.name.type.ts ^ source.ts punctuation.terminator.statement.ts \ No newline at end of file diff --git a/tests/baselines/Issue762.baseline.txt b/tests/baselines/Issue762.baseline.txt index 2c0caf36..e54bff9e 100644 --- a/tests/baselines/Issue762.baseline.txt +++ b/tests/baselines/Issue762.baseline.txt @@ -15,9 +15,9 @@ Grammar: TypeScript.tmLanguage ^ source.ts ^^^ - source.ts support.type.primitive.ts + source.ts meta.type.cast.ts support.type.primitive.ts ^ - source.ts + source.ts meta.type.cast.ts ^^ source.ts keyword.operator.logical.ts ^ diff --git a/tests/baselines/constType.baseline.txt b/tests/baselines/constType.baseline.txt index 644cbca9..da6f2810 100644 --- a/tests/baselines/constType.baseline.txt +++ b/tests/baselines/constType.baseline.txt @@ -56,7 +56,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts ^^^^^ - source.ts meta.var.expr.ts storage.modifier.ts + source.ts meta.var.expr.ts storage.modifier.const.type.ts ^ source.ts punctuation.terminator.statement.ts >let r2 = {...p} as const; @@ -87,7 +87,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts ^^^^^ - source.ts meta.var.expr.ts storage.modifier.ts + source.ts meta.var.expr.ts storage.modifier.const.type.ts ^ source.ts punctuation.terminator.statement.ts >let p1 = { x: 10, y: 20 as const }; @@ -134,7 +134,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts ^^^^^ - source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts + source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts ^ source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts ^ @@ -167,7 +167,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts ^^^^^ - source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts + source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts ^ source.ts meta.var.expr.ts meta.objectliteral.ts punctuation.separator.comma.ts ^ @@ -185,7 +185,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts ^^^^^ - source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.ts + source.ts meta.var.expr.ts meta.objectliteral.ts meta.object.member.ts storage.modifier.const.type.ts ^ source.ts meta.var.expr.ts meta.objectliteral.ts ^ diff --git a/tests/baselines/constTypeAssert.baseline.txt b/tests/baselines/constTypeAssert.baseline.txt index 7a1a18cc..8dc5dfd7 100644 --- a/tests/baselines/constTypeAssert.baseline.txt +++ b/tests/baselines/constTypeAssert.baseline.txt @@ -27,7 +27,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts ^^^^^ - source.ts meta.var.expr.ts cast.expr.ts storage.modifier.ts + source.ts meta.var.expr.ts cast.expr.ts storage.modifier.const.type.ts ^ source.ts meta.var.expr.ts cast.expr.ts meta.brace.angle.ts ^