From 642dea665e6a0aac5c00e4ddc679ade8a5464c64 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 24 Oct 2016 14:40:44 -0700 Subject: [PATCH 1/5] Enable the variable declarations to be scoped as function if they have possibly function type or assignment looks like arrow function --- TypeScript.YAML-tmLanguage | 45 +++++++++-- TypeScript.tmLanguage | 80 ++++++++++++++----- TypeScriptReact.tmLanguage | 80 ++++++++++++++----- tests/baselines/Issue115.baseline.txt | 4 +- tests/baselines/Issue172.baseline.txt | 4 +- tests/baselines/Issue186.baseline.txt | 2 +- tests/baselines/Issue226.baseline.txt | 2 +- tests/baselines/Issue249.baseline.txt | 2 +- tests/baselines/arrow.baseline.txt | 2 +- .../multipleVariableDeclaration.baseline.txt | 4 +- .../baselines/multipleVariableDeclaration.txt | 4 +- 11 files changed, 165 insertions(+), 64 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 0933fa2..71d2f18 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -41,15 +41,44 @@ repository: - include: '#punctuation-comma' var-single-variable: - name: meta.var-single-variable.expr.ts - begin: ([_$[:alpha:]][_$[:alnum:]]*) - beginCaptures: - '1': { name: meta.definition.variable.ts variable.other.readwrite.ts } - end: (?=$|[;,=}]|(\s+(of|in)\s+)) patterns: - - include: '#type-annotation' - - include: '#string' - - include: '#comment' + - name: meta.var-single-variable.expr.ts + # function assignment | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + begin: (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* + (=\s*( + (async\s+) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | + ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) + ) | + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + ))) + )) + beginCaptures: + '1': { name: meta.definition.variable.ts entity.name.function.ts } + end: (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns: + - include: '#type-annotation' + - include: '#string' + - include: '#comment' + - name: meta.var-single-variable.expr.ts + begin: ([_$[:alpha:]][_$[:alnum:]]*) + beginCaptures: + '1': { name: meta.definition.variable.ts variable.other.readwrite.ts } + end: (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns: + - include: '#type-annotation' + - include: '#string' + - include: '#comment' destructuring-variable: patterns: diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index 2451bc7..605f2b3 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -126,33 +126,69 @@ var-single-variable - name - meta.var-single-variable.expr.ts - begin - ([_$[:alpha:]][_$[:alnum:]]*) - beginCaptures - - 1 - - name - meta.definition.variable.ts variable.other.readwrite.ts - - - end - (?=$|[;,=}]|(\s+(of|in)\s+)) patterns - include - #type-annotation + name + meta.var-single-variable.expr.ts + begin + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + beginCaptures + + 1 + + name + meta.definition.variable.ts entity.name.function.ts + + + end + (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns + + + include + #type-annotation + + + include + #string + + + include + #comment + + - include - #string - - - include - #comment + name + meta.var-single-variable.expr.ts + begin + ([_$[:alpha:]][_$[:alnum:]]*) + beginCaptures + + 1 + + name + meta.definition.variable.ts variable.other.readwrite.ts + + + end + (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns + + + include + #type-annotation + + + include + #string + + + include + #comment + + diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 62f5dfe..e80f67b 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -126,33 +126,69 @@ var-single-variable - name - meta.var-single-variable.expr.tsx - begin - ([_$[:alpha:]][_$[:alnum:]]*) - beginCaptures - - 1 - - name - meta.definition.variable.tsx variable.other.readwrite.tsx - - - end - (?=$|[;,=}]|(\s+(of|in)\s+)) patterns - include - #type-annotation + name + meta.var-single-variable.expr.tsx + begin + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + beginCaptures + + 1 + + name + meta.definition.variable.tsx entity.name.function.tsx + + + end + (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns + + + include + #type-annotation + + + include + #string + + + include + #comment + + - include - #string - - - include - #comment + name + meta.var-single-variable.expr.tsx + begin + ([_$[:alpha:]][_$[:alnum:]]*) + beginCaptures + + 1 + + name + meta.definition.variable.tsx variable.other.readwrite.tsx + + + end + (?=$|[;,=}]|(\s+(of|in)\s+)) + patterns + + + include + #type-annotation + + + include + #string + + + include + #comment + + diff --git a/tests/baselines/Issue115.baseline.txt b/tests/baselines/Issue115.baseline.txt index 44c268f..f0c8c70 100644 --- a/tests/baselines/Issue115.baseline.txt +++ b/tests/baselines/Issue115.baseline.txt @@ -128,7 +128,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ @@ -182,7 +182,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/Issue172.baseline.txt b/tests/baselines/Issue172.baseline.txt index 2af78eb..23ca008 100644 --- a/tests/baselines/Issue172.baseline.txt +++ b/tests/baselines/Issue172.baseline.txt @@ -12,7 +12,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ @@ -49,7 +49,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/Issue186.baseline.txt b/tests/baselines/Issue186.baseline.txt index ceff573..5cac57b 100644 --- a/tests/baselines/Issue186.baseline.txt +++ b/tests/baselines/Issue186.baseline.txt @@ -63,7 +63,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.function.ts meta.block.ts meta.var.expr.ts ^ - source.ts meta.function.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts + source.ts meta.function.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.function.ts meta.block.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/Issue226.baseline.txt b/tests/baselines/Issue226.baseline.txt index 00b3f3f..81fea1e 100644 --- a/tests/baselines/Issue226.baseline.txt +++ b/tests/baselines/Issue226.baseline.txt @@ -43,7 +43,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/Issue249.baseline.txt b/tests/baselines/Issue249.baseline.txt index 67f7e64..17fb760 100644 --- a/tests/baselines/Issue249.baseline.txt +++ b/tests/baselines/Issue249.baseline.txt @@ -17,7 +17,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/arrow.baseline.txt b/tests/baselines/arrow.baseline.txt index c8e8ed5..f842990 100644 --- a/tests/baselines/arrow.baseline.txt +++ b/tests/baselines/arrow.baseline.txt @@ -19,7 +19,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ diff --git a/tests/baselines/multipleVariableDeclaration.baseline.txt b/tests/baselines/multipleVariableDeclaration.baseline.txt index 2c9cd81..0a53a81 100644 --- a/tests/baselines/multipleVariableDeclaration.baseline.txt +++ b/tests/baselines/multipleVariableDeclaration.baseline.txt @@ -49,7 +49,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ @@ -132,7 +132,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ diff --git a/tests/baselines/multipleVariableDeclaration.txt b/tests/baselines/multipleVariableDeclaration.txt index d8108f1..be9442c 100644 --- a/tests/baselines/multipleVariableDeclaration.txt +++ b/tests/baselines/multipleVariableDeclaration.txt @@ -21,14 +21,14 @@ Grammar: TypeScript.tmLanguage ^^ [2, 5]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts ^^ - [2, 13]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts + [2, 13]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^^ [2, 46]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts >var a2: string = "test", b2: () => void = () => { console.log("hello"); }, c2: string | number; ^^ [3, 5]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts ^^ - [3, 26]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts + [3, 26]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^^ [3, 76]: source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts >var obj = { From f1d347c3266ca54c143f7d16cfae653337853716 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 24 Oct 2016 14:47:54 -0700 Subject: [PATCH 2/5] Property declarations are scoped as methods if they are assigned function expression or are annotated with function type --- TypeScript.YAML-tmLanguage | 21 +++++++++++++++++++++ TypeScript.tmLanguage | 6 ++++++ TypeScriptReact.tmLanguage | 6 ++++++ tests/baselines/Issue119.baseline.txt | 2 +- tests/baselines/Issue133.baseline.txt | 2 +- tests/baselines/Issue142.baseline.txt | 2 +- tests/baselines/Issue183.baseline.txt | 2 +- tests/baselines/Issue216.baseline.txt | 2 +- tests/baselines/Issue250.baseline.txt | 2 +- 9 files changed, 39 insertions(+), 6 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 71d2f18..387fd28 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -518,6 +518,27 @@ repository: - include: '#string' - include: '#array-literal' - include: '#comment' + - name: meta.definition.property.ts entity.name.function.ts + # function assignment | + # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) => + match: (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* + (=\s*( + (async\s+) | + (function\s+) | + ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | + ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) + ) | + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + ))) + )) - name: meta.definition.property.ts variable.object.property.ts match: '[_$[:alpha:]][_$[:alnum:]]*' - name: keyword.operator.optional.ts diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index 605f2b3..f6a1c97 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -1644,6 +1644,12 @@ include #comment + + name + meta.definition.property.ts entity.name.function.ts + match + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + name meta.definition.property.ts variable.object.property.ts diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index e80f67b..4ee18d4 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -1648,6 +1648,12 @@ include #comment + + name + meta.definition.property.tsx entity.name.function.tsx + match + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + name meta.definition.property.tsx variable.object.property.tsx diff --git a/tests/baselines/Issue119.baseline.txt b/tests/baselines/Issue119.baseline.txt index 4a3b715..3badf88 100644 --- a/tests/baselines/Issue119.baseline.txt +++ b/tests/baselines/Issue119.baseline.txt @@ -84,7 +84,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.class.ts ^^^^^^^^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts ^ diff --git a/tests/baselines/Issue133.baseline.txt b/tests/baselines/Issue133.baseline.txt index 2c1bf72..35c6687 100644 --- a/tests/baselines/Issue133.baseline.txt +++ b/tests/baselines/Issue133.baseline.txt @@ -40,7 +40,7 @@ Grammar: TypeScript.tmLanguage ^^ source.ts meta.class.ts ^^^^^^^^^^^^^^^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ diff --git a/tests/baselines/Issue142.baseline.txt b/tests/baselines/Issue142.baseline.txt index c2df3da..7b1b5d6 100644 --- a/tests/baselines/Issue142.baseline.txt +++ b/tests/baselines/Issue142.baseline.txt @@ -26,7 +26,7 @@ Grammar: TypeScript.tmLanguage ^^ source.ts meta.class.ts ^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts ^ diff --git a/tests/baselines/Issue183.baseline.txt b/tests/baselines/Issue183.baseline.txt index 48f3383..5f34f4f 100644 --- a/tests/baselines/Issue183.baseline.txt +++ b/tests/baselines/Issue183.baseline.txt @@ -72,7 +72,7 @@ Grammar: TypeScript.tmLanguage ^^^^ source.ts meta.class.ts ^^^^^^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts ^ diff --git a/tests/baselines/Issue216.baseline.txt b/tests/baselines/Issue216.baseline.txt index b64f000..c89fd39 100644 --- a/tests/baselines/Issue216.baseline.txt +++ b/tests/baselines/Issue216.baseline.txt @@ -35,7 +35,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.class.ts ^^^^^^^^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts ^ diff --git a/tests/baselines/Issue250.baseline.txt b/tests/baselines/Issue250.baseline.txt index 3785ea2..bfa3703 100644 --- a/tests/baselines/Issue250.baseline.txt +++ b/tests/baselines/Issue250.baseline.txt @@ -82,7 +82,7 @@ Grammar: TypeScript.tmLanguage ^ source.ts meta.class.ts ^^^^^^^^ - source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts + source.ts meta.class.ts meta.field.declaration.ts meta.definition.property.ts entity.name.function.ts ^ source.ts meta.class.ts meta.field.declaration.ts ^ From a14e341be481203cc8f80be424f2978561150f54 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 24 Oct 2016 14:58:21 -0700 Subject: [PATCH 3/5] Parameters are scoped as function if assigned from function or have function type annotation --- TypeScript.YAML-tmLanguage | 41 +++++++-- TypeScript.tmLanguage | 89 +++++++++++++------ TypeScriptReact.tmLanguage | 89 +++++++++++++------ .../FunctionMethodParameters.baseline.txt | 8 +- tests/baselines/FunctionMethodParameters.txt | 8 +- tests/baselines/Issue82.baseline.txt | 2 +- tests/baselines/Issue82.txt | 2 +- 7 files changed, 170 insertions(+), 69 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 387fd28..225ce94 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -666,13 +666,40 @@ repository: - include: '#object-member' parameter-name: - match: '(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(? + - match: (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?) | + ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) + ) | + (:\s*( + (<) | + ([(]\s*( + ([)]) | + (\.\.\.) | + ([_$[:alnum:]]+\s*( + ([:,?=])| + ([)]\s*=>) + )) + ))) + )) + captures: + '1': { name: storage.modifier.ts } + '2': { name: storage.modifier.ts } + '3': { name: keyword.operator.rest.ts } + '4': { name: entity.name.function.ts } + '5': { name: keyword.operator.optional.ts } + - match: (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(? parameter-name - match - (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??) - captures - - 1 + patterns + - name - storage.modifier.ts + match + (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + captures + + 1 + + name + storage.modifier.ts + + 2 + + name + storage.modifier.ts + + 3 + + name + keyword.operator.rest.ts + + 4 + + name + entity.name.function.ts + + 5 + + name + keyword.operator.optional.ts + + - 2 - name - storage.modifier.ts + match + (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??) + captures + + 1 + + name + storage.modifier.ts + + 2 + + name + storage.modifier.ts + + 3 + + name + keyword.operator.rest.ts + + 4 + + name + variable.parameter.ts + + 5 + + name + keyword.operator.optional.ts + + - 3 - - name - keyword.operator.rest.ts - - 4 - - name - variable.parameter.ts - - 5 - - name - keyword.operator.optional.ts - - + destructuring-parameter diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 4ee18d4..3fdb723 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -2074,36 +2074,73 @@ parameter-name - match - (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??) - captures - - 1 + patterns + - name - storage.modifier.tsx + match + (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + captures + + 1 + + name + storage.modifier.tsx + + 2 + + name + storage.modifier.tsx + + 3 + + name + keyword.operator.rest.tsx + + 4 + + name + entity.name.function.tsx + + 5 + + name + keyword.operator.optional.tsx + + - 2 - name - storage.modifier.tsx + match + (?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??) + captures + + 1 + + name + storage.modifier.tsx + + 2 + + name + storage.modifier.tsx + + 3 + + name + keyword.operator.rest.tsx + + 4 + + name + variable.parameter.tsx + + 5 + + name + keyword.operator.optional.tsx + + - 3 - - name - keyword.operator.rest.tsx - - 4 - - name - variable.parameter.tsx - - 5 - - name - keyword.operator.optional.tsx - - + destructuring-parameter diff --git a/tests/baselines/FunctionMethodParameters.baseline.txt b/tests/baselines/FunctionMethodParameters.baseline.txt index d301f18..72a949d 100644 --- a/tests/baselines/FunctionMethodParameters.baseline.txt +++ b/tests/baselines/FunctionMethodParameters.baseline.txt @@ -139,7 +139,7 @@ Grammar: TypeScript.tmLanguage ^^^^ source.ts meta.function.ts meta.parameters.ts ^^ - source.ts meta.function.ts meta.parameters.ts variable.parameter.ts + source.ts meta.function.ts meta.parameters.ts entity.name.function.ts ^ source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ @@ -162,7 +162,7 @@ Grammar: TypeScript.tmLanguage ^^^^ source.ts meta.function.ts meta.parameters.ts ^^ - source.ts meta.function.ts meta.parameters.ts variable.parameter.ts + source.ts meta.function.ts meta.parameters.ts entity.name.function.ts ^ source.ts meta.function.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ @@ -497,7 +497,7 @@ Grammar: TypeScript.tmLanguage ^^^^^^^^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts ^^ - source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts ^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ @@ -520,7 +520,7 @@ Grammar: TypeScript.tmLanguage ^^^^^^^^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts ^^ - source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts ^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ diff --git a/tests/baselines/FunctionMethodParameters.txt b/tests/baselines/FunctionMethodParameters.txt index dce321b..fd0faa1 100644 --- a/tests/baselines/FunctionMethodParameters.txt +++ b/tests/baselines/FunctionMethodParameters.txt @@ -51,10 +51,10 @@ Grammar: TypeScript.tmLanguage [6, 5]: source.ts meta.function.ts meta.parameters.ts variable.parameter.ts > m5: () => void, ^^ - [7, 5]: source.ts meta.function.ts meta.parameters.ts variable.parameter.ts + [7, 5]: source.ts meta.function.ts meta.parameters.ts entity.name.function.ts > m6: (x:(string), y:[number, string]) => number, ^^ - [8, 5]: source.ts meta.function.ts meta.parameters.ts variable.parameter.ts + [8, 5]: source.ts meta.function.ts meta.parameters.ts entity.name.function.ts > m7: Array, ^^ [9, 5]: source.ts meta.function.ts meta.parameters.ts variable.parameter.ts @@ -89,10 +89,10 @@ Grammar: TypeScript.tmLanguage [22, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts > m5: () => void, ^^ - [23, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + [23, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts > m6: (x:(string), y:[number, string]) => number, ^^ - [24, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + [24, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts > m7: Array, ^^ [25, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts diff --git a/tests/baselines/Issue82.baseline.txt b/tests/baselines/Issue82.baseline.txt index 143621e..1a28202 100644 --- a/tests/baselines/Issue82.baseline.txt +++ b/tests/baselines/Issue82.baseline.txt @@ -53,7 +53,7 @@ Grammar: TypeScript.tmLanguage ^^^^^^^^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts ^^^^^^^^^^^^^^^^^^^^ - source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts ^ source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts ^ diff --git a/tests/baselines/Issue82.txt b/tests/baselines/Issue82.txt index c946388..4c597af 100644 --- a/tests/baselines/Issue82.txt +++ b/tests/baselines/Issue82.txt @@ -23,7 +23,7 @@ Grammar: TypeScript.tmLanguage [3, 25]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts comment.line.double-slash.ts > exitEditModeCallback: () => void // Used to re-enable View updates. ^^^^^^^^^^^^^^^^^^^^ - [4, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts + [4, 9]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts entity.name.function.ts ^ [4, 31]: source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts meta.type.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 5f17434b8f052eaf7ca46394e7418e4559cc951a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 26 Oct 2016 11:00:15 -0700 Subject: [PATCH 4/5] Handle function() case in look ahead --- TypeScript.YAML-tmLanguage | 3 +++ TypeScript.tmLanguage | 6 +++--- TypeScriptReact.tmLanguage | 6 +++--- tests/baselines/Issue288.baseline.txt | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index 225ce94..9414297 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -48,6 +48,7 @@ repository: begin: (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | + (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) @@ -524,6 +525,7 @@ repository: match: (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | + (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) @@ -672,6 +674,7 @@ repository: - match: (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index f676903..0046407 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -132,7 +132,7 @@ name meta.var-single-variable.expr.ts begin - (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) beginCaptures 1 @@ -1648,7 +1648,7 @@ name meta.definition.property.ts entity.name.function.ts match - (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) name @@ -2074,7 +2074,7 @@ match - (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) captures 1 diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 3fdb723..e099d2a 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -132,7 +132,7 @@ name meta.var-single-variable.expr.tsx begin - (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) beginCaptures 1 @@ -1652,7 +1652,7 @@ name meta.definition.property.tsx entity.name.function.tsx match - (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=(\?\s*)?\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) name @@ -2078,7 +2078,7 @@ match - (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) + (?x)(?:\s*\b(readonly)\s+)?(?:\s*\b(public|private|protected)\s+)?(\.\.\.)?\s*(?<!=|:)([_$[:alpha:]][_$[:alnum:]]*)\s*(\??)(?=\s* (=\s*( (async\s+) | (function\s*[(<]) | (function\s+) | ([_$[:alpha:]][_$[:alnum:]]*\s*=>) | ((<([^<>]|\<[^<>]+\>)+>\s*)?\(([^()]|\([^()]*\))*\)(\s*:\s*(.)*)?\s*=>)) ) | (:\s*( (<) | ([(]\s*( ([)]) | (\.\.\.) | ([_$[:alnum:]]+\s*( ([:,?=])| ([)]\s*=>) )) ))) )) captures 1 diff --git a/tests/baselines/Issue288.baseline.txt b/tests/baselines/Issue288.baseline.txt index 4a5b5eb..5096091 100644 --- a/tests/baselines/Issue288.baseline.txt +++ b/tests/baselines/Issue288.baseline.txt @@ -63,7 +63,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ @@ -114,7 +114,7 @@ Grammar: TypeScript.tmLanguage ^ 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 meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts entity.name.function.ts ^ source.ts meta.var.expr.ts meta.var-single-variable.expr.ts ^ From 9dc74a5bf0d91a2a48a8dc482dd1765e098ad2ed Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 1 Nov 2016 15:23:34 -0700 Subject: [PATCH 5/5] Added support for property names that are not identifier in object binding element --- TypeScript.YAML-tmLanguage | 53 +++--- TypeScript.tmLanguage | 126 +++++++------- TypeScriptReact.tmLanguage | 126 +++++++------- ...rtyNameInObjectBindingElement.baseline.txt | 160 ++++++++++++++++++ .../propertyNameInObjectBindingElement.ts | 3 + 5 files changed, 310 insertions(+), 158 deletions(-) create mode 100644 tests/baselines/propertyNameInObjectBindingElement.baseline.txt create mode 100644 tests/cases/propertyNameInObjectBindingElement.ts diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index f8b1b45..9a2c061 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -105,30 +105,34 @@ repository: object-binding-element: patterns: - include: '#comment' - - begin: ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures: - '1': { name: variable.object.property.ts } - '2': { name: punctuation.destructuring.ts } + - begin: (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end: (?=,|\}) patterns: - - include: '#object-binding-pattern' - - include: '#array-binding-pattern' - - name: meta.definition.variable.ts variable.other.readwrite.ts - match: ([_$[:alpha:]][_$[:alnum:]]*) - - include: '#variable-initializer' + - include: '#object-binding-element-propertyName' + - include: '#binding-element' - include: '#object-binding-pattern' - include: '#destructuring-variable-rest' - include: '#variable-initializer' - include: '#punctuation-comma' - array-binding-element: + object-binding-element-propertyName: + begin: (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) + end: (:) + endCaptures: + '0': { name: punctuation.destructuring.ts } + patterns: + - include: '#string' + - include: '#array-literal' + - name: variable.object.property.ts + match: ([_$[:alpha:]][_$[:alnum:]]*) + + binding-element: patterns: - include: '#comment' - include: '#object-binding-pattern' - include: '#array-binding-pattern' - include: '#destructuring-variable-rest' - include: '#variable-initializer' - - include: '#punctuation-comma' destructuring-variable-rest: match: (?:(\.\.\.)\s*)?([_$[:alpha:]][_$[:alnum:]]*) @@ -156,7 +160,8 @@ repository: endCaptures: '0': { name: punctuation.definition.binding-pattern.array.ts } patterns: - - include: '#array-binding-element' + - include: '#binding-element' + - include: '#punctuation-comma' ternary-expression: begin: (?=\?) @@ -287,10 +292,11 @@ repository: patterns: - include: '#comment' - include: '#variable-initializer' - - begin: (?=(?:(?:\'[^']*\')|(?:\"[^"]*\"))) + - begin: (?=((\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))) end: (?=,|\}|$) patterns: - include: '#string' + - include: '#array-literal' - include: '#comment' - include: '#variable-initializer' - include: '#punctuation-comma' @@ -727,35 +733,29 @@ repository: endCaptures: '0': { name: punctuation.definition.binding-pattern.array.ts } patterns: - - include: '#parameter-array-binding-element' + - include: '#parameter-binding-element' + - include: '#punctuation-comma' parameter-object-binding-element: patterns: - include: '#comment' - - begin: ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures: - '1': { name: variable.object.property.ts } - '2': { name: punctuation.destructuring.ts } + - begin: (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end: (?=,|\}) patterns: - - include: '#parameter-object-binding-pattern' - - include: '#parameter-array-binding-pattern' - - name: variable.parameter.ts - match: ([_$[:alpha:]][_$[:alnum:]]*) - - include: '#variable-initializer' + - include: '#object-binding-element-propertyName' + - include: '#parameter-binding-element' - include: '#parameter-object-binding-pattern' - include: '#destructuring-parameter-rest' - include: '#variable-initializer' - include: '#punctuation-comma' - parameter-array-binding-element: + parameter-binding-element: patterns: - include: '#comment' - include: '#parameter-object-binding-pattern' - include: '#parameter-array-binding-pattern' - include: '#destructuring-parameter-rest' - include: '#variable-initializer' - - include: '#punctuation-comma' destructuring-parameter-rest: match: (?:(\.\.\.)\s*)?([_$[:alpha:]][_$[:alnum:]]*) @@ -783,7 +783,8 @@ repository: endCaptures: '0': { name: punctuation.definition.binding-pattern.array.ts } patterns: - - include: '#parameter-array-binding-element' + - include: '#parameter-binding-element' + - include: '#punctuation-comma' return-type: name: meta.return.type.ts diff --git a/TypeScript.tmLanguage b/TypeScript.tmLanguage index efb51dc..32d8995 100644 --- a/TypeScript.tmLanguage +++ b/TypeScript.tmLanguage @@ -268,41 +268,18 @@ begin - ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures - - 1 - - name - variable.object.property.ts - - 2 - - name - punctuation.destructuring.ts - - + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end (?=,|\}) patterns include - #object-binding-pattern + #object-binding-element-propertyName include - #array-binding-pattern - - - name - meta.definition.variable.ts variable.other.readwrite.ts - match - ([_$[:alpha:]][_$[:alnum:]]*) - - - include - #variable-initializer + #binding-element @@ -324,7 +301,39 @@ - array-binding-element + object-binding-element-propertyName + + begin + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) + end + (:) + endCaptures + + 0 + + name + punctuation.destructuring.ts + + + patterns + + + include + #string + + + include + #array-literal + + + name + variable.object.property.ts + match + ([_$[:alpha:]][_$[:alnum:]]*) + + + + binding-element patterns @@ -348,10 +357,6 @@ include #variable-initializer - - include - #punctuation-comma - destructuring-variable-rest @@ -438,7 +443,11 @@ include - #array-binding-element + #binding-element + + + include + #punctuation-comma @@ -862,7 +871,7 @@ begin - (?=(?:(?:\'[^']*\')|(?:\"[^"]*\"))) + (?=((\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))) end (?=,|\}|$) patterns @@ -871,6 +880,10 @@ include #string + + include + #array-literal + include #comment @@ -2214,7 +2227,11 @@ include - #parameter-array-binding-element + #parameter-binding-element + + + include + #punctuation-comma @@ -2230,41 +2247,18 @@ begin - ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures - - 1 - - name - variable.object.property.ts - - 2 - - name - punctuation.destructuring.ts - - + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end (?=,|\}) patterns include - #parameter-object-binding-pattern + #object-binding-element-propertyName include - #parameter-array-binding-pattern - - - name - variable.parameter.ts - match - ([_$[:alpha:]][_$[:alnum:]]*) - - - include - #variable-initializer + #parameter-binding-element @@ -2286,7 +2280,7 @@ - parameter-array-binding-element + parameter-binding-element patterns @@ -2310,10 +2304,6 @@ include #variable-initializer - - include - #punctuation-comma - destructuring-parameter-rest @@ -2400,7 +2390,11 @@ include - #parameter-array-binding-element + #parameter-binding-element + + + include + #punctuation-comma diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index e7be6d5..eca345d 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -268,41 +268,18 @@ begin - ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures - - 1 - - name - variable.object.property.tsx - - 2 - - name - punctuation.destructuring.tsx - - + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end (?=,|\}) patterns include - #object-binding-pattern + #object-binding-element-propertyName include - #array-binding-pattern - - - name - meta.definition.variable.tsx variable.other.readwrite.tsx - match - ([_$[:alpha:]][_$[:alnum:]]*) - - - include - #variable-initializer + #binding-element @@ -324,7 +301,39 @@ - array-binding-element + object-binding-element-propertyName + + begin + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) + end + (:) + endCaptures + + 0 + + name + punctuation.destructuring.tsx + + + patterns + + + include + #string + + + include + #array-literal + + + name + variable.object.property.tsx + match + ([_$[:alpha:]][_$[:alnum:]]*) + + + + binding-element patterns @@ -348,10 +357,6 @@ include #variable-initializer - - include - #punctuation-comma - destructuring-variable-rest @@ -438,7 +443,11 @@ include - #array-binding-element + #binding-element + + + include + #punctuation-comma @@ -866,7 +875,7 @@ begin - (?=(?:(?:\'[^']*\')|(?:\"[^"]*\"))) + (?=((\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))) end (?=,|\}|$) patterns @@ -875,6 +884,10 @@ include #string + + include + #array-literal + include #comment @@ -2218,7 +2231,11 @@ include - #parameter-array-binding-element + #parameter-binding-element + + + include + #punctuation-comma @@ -2234,41 +2251,18 @@ begin - ([_$[:alpha:]][_$[:alnum:]]*)\s*(:) - beginCaptures - - 1 - - name - variable.object.property.tsx - - 2 - - name - punctuation.destructuring.tsx - - + (?=(([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]+\])+\]))\s*(:)) end (?=,|\}) patterns include - #parameter-object-binding-pattern + #object-binding-element-propertyName include - #parameter-array-binding-pattern - - - name - variable.parameter.tsx - match - ([_$[:alpha:]][_$[:alnum:]]*) - - - include - #variable-initializer + #parameter-binding-element @@ -2290,7 +2284,7 @@ - parameter-array-binding-element + parameter-binding-element patterns @@ -2314,10 +2308,6 @@ include #variable-initializer - - include - #punctuation-comma - destructuring-parameter-rest @@ -2404,7 +2394,11 @@ include - #parameter-array-binding-element + #parameter-binding-element + + + include + #punctuation-comma diff --git a/tests/baselines/propertyNameInObjectBindingElement.baseline.txt b/tests/baselines/propertyNameInObjectBindingElement.baseline.txt new file mode 100644 index 0000000..c2220d1 --- /dev/null +++ b/tests/baselines/propertyNameInObjectBindingElement.baseline.txt @@ -0,0 +1,160 @@ +original file +----------------------------------- +var { "propName": prop, 'propName2': prop2, ["string"]: str } = foo(); +function bar({ "propName": prop, 'propName2': prop2, ["string"]: str }){ +} +----------------------------------- + +Grammar: TypeScript.tmLanguage +----------------------------------- +>var { "propName": prop, 'propName2': prop2, ["string"]: str } = foo(); + ^^^ + source.ts meta.var.expr.ts storage.type.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.double.ts punctuation.definition.string.begin.ts + ^^^^^^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.double.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.double.ts punctuation.definition.string.end.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.destructuring.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.definition.variable.ts variable.other.readwrite.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.separator.comma.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.single.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.destructuring.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^^^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.definition.variable.ts variable.other.readwrite.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.separator.comma.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.array.literal.ts meta.brace.square.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.array.literal.ts string.quoted.double.ts punctuation.definition.string.begin.ts + ^^^^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.array.literal.ts string.quoted.double.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.array.literal.ts string.quoted.double.ts punctuation.definition.string.end.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.array.literal.ts meta.brace.square.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.destructuring.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^^^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts meta.definition.variable.ts variable.other.readwrite.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts punctuation.definition.binding-pattern.object.ts + ^ + source.ts meta.var.expr.ts meta.object-binding-pattern-variable.ts + ^ + source.ts meta.var.expr.ts keyword.operator.assignment.ts + ^ + source.ts meta.var.expr.ts + ^^^ + source.ts meta.var.expr.ts entity.name.function.ts + ^ + source.ts meta.var.expr.ts meta.brace.round.ts + ^ + source.ts meta.var.expr.ts meta.brace.round.ts + ^ + source.ts punctuation.terminator.statement.ts + ^^ + source.ts +>function bar({ "propName": prop, 'propName2': prop2, ["string"]: str }){ + ^^^^^^^^ + source.ts meta.function.ts storage.type.function.ts + ^ + source.ts meta.function.ts + ^^^ + source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts + ^ + source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.definition.binding-pattern.object.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.double.ts punctuation.definition.string.begin.ts + ^^^^^^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.double.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.double.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.destructuring.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.separator.comma.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.single.ts punctuation.definition.string.begin.ts + ^^^^^^^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.single.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts string.quoted.single.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.destructuring.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^^^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.separator.comma.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts meta.array.literal.ts meta.brace.square.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts meta.array.literal.ts string.quoted.double.ts punctuation.definition.string.begin.ts + ^^^^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts meta.array.literal.ts string.quoted.double.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts meta.array.literal.ts string.quoted.double.ts punctuation.definition.string.end.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts meta.array.literal.ts meta.brace.square.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.destructuring.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^^^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts variable.parameter.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts + ^ + source.ts meta.function.ts meta.parameters.ts meta.parameter.object-binding-pattern.ts punctuation.definition.binding-pattern.object.ts + ^ + source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts + ^ + source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts + ^^ + source.ts meta.function.ts meta.block.ts +>} + ^ + source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts \ No newline at end of file diff --git a/tests/cases/propertyNameInObjectBindingElement.ts b/tests/cases/propertyNameInObjectBindingElement.ts new file mode 100644 index 0000000..968442e --- /dev/null +++ b/tests/cases/propertyNameInObjectBindingElement.ts @@ -0,0 +1,3 @@ +var { "propName": prop, 'propName2': prop2, ["string"]: str } = foo(); +function bar({ "propName": prop, 'propName2': prop2, ["string"]: str }){ +} \ No newline at end of file