From 8c967fe7553297bfad672b7417d78e357c8fe724 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 24 May 2017 11:35:33 -0700 Subject: [PATCH] Handle accessors separately so as to correctly tokenize method with name 'get/set' Fixes #458 --- TypeScript.YAML-tmLanguage | 54 ++++--- TypeScript.tmLanguage | 195 +++++++++++++++++--------- TypeScriptReact.tmLanguage | 195 +++++++++++++++++--------- tests/baselines/Issue458.baseline.txt | 92 ++++++++++++ tests/cases/Issue458.ts | 6 + 5 files changed, 391 insertions(+), 151 deletions(-) create mode 100644 tests/baselines/Issue458.baseline.txt create mode 100644 tests/cases/Issue458.ts diff --git a/TypeScript.YAML-tmLanguage b/TypeScript.YAML-tmLanguage index dbe76894..2e8eb091 100644 --- a/TypeScript.YAML-tmLanguage +++ b/TypeScript.YAML-tmLanguage @@ -586,24 +586,40 @@ repository: match: \? method-declaration: - name: meta.method.declaration.ts - begin: (? method-declaration - name - meta.method.declaration.ts - begin - (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|\.|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<])) - beginCaptures - - 1 - - name - storage.modifier.ts - - 2 - - name - storage.modifier.ts - - 3 - - name - storage.modifier.async.ts - - 4 - - name - storage.type.property.ts - - 5 - - name - keyword.operator.new.ts - - 6 - - name - storage.type.ts - - 7 - - name - keyword.generator.asterisk.ts - - - end - (?=\}|;|,|$)|(?<=\}) patterns - include - #method-declaration-name - - - include - #comment - - - include - #type-parameters - - - include - #function-parameters - - - include - #return-type + name + meta.method.declaration.ts + begin + (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) + beginCaptures + + 1 + + name + storage.modifier.ts + + 2 + + name + storage.modifier.ts + + 3 + + name + storage.modifier.async.ts + + 4 + + name + storage.type.property.ts + + 5 + + name + keyword.generator.asterisk.ts + + + end + (?=\}|;|,|$)|(?<=\}) + patterns + + + include + #method-declaration-name + + + include + #comment + + + include + #type-parameters + + + include + #function-parameters + + + include + #return-type + + + include + #decl-block + + - include - #decl-block + name + meta.method.declaration.ts + begin + (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|\.|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<])) + beginCaptures + + 1 + + name + storage.modifier.ts + + 2 + + name + storage.modifier.ts + + 3 + + name + storage.modifier.async.ts + + 4 + + name + keyword.operator.new.ts + + 5 + + name + storage.type.ts + + 6 + + name + keyword.generator.asterisk.ts + + + end + (?=\}|;|,|$)|(?<=\}) + patterns + + + include + #method-declaration-name + + + include + #comment + + + include + #type-parameters + + + include + #function-parameters + + + include + #return-type + + + include + #decl-block + + @@ -1910,7 +1973,7 @@ name meta.method.declaration.ts begin - (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<]) + (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) beginCaptures 1 @@ -1966,7 +2029,7 @@ object-literal-method-overload-declaration begin - (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<]) + (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) beginCaptures 1 diff --git a/TypeScriptReact.tmLanguage b/TypeScriptReact.tmLanguage index 0fb9d57f..53f228e8 100644 --- a/TypeScriptReact.tmLanguage +++ b/TypeScriptReact.tmLanguage @@ -1807,75 +1807,138 @@ method-declaration - name - meta.method.declaration.tsx - begin - (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|\.|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<])) - beginCaptures - - 1 - - name - storage.modifier.tsx - - 2 - - name - storage.modifier.tsx - - 3 - - name - storage.modifier.async.tsx - - 4 - - name - storage.type.property.tsx - - 5 - - name - keyword.operator.new.tsx - - 6 - - name - storage.type.tsx - - 7 - - name - keyword.generator.asterisk.tsx - - - end - (?=\}|;|,|$)|(?<=\}) patterns - include - #method-declaration-name - - - include - #comment - - - include - #type-parameters - - - include - #function-parameters - - - include - #return-type + name + meta.method.declaration.tsx + begin + (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) + beginCaptures + + 1 + + name + storage.modifier.tsx + + 2 + + name + storage.modifier.tsx + + 3 + + name + storage.modifier.async.tsx + + 4 + + name + storage.type.property.tsx + + 5 + + name + keyword.generator.asterisk.tsx + + + end + (?=\}|;|,|$)|(?<=\}) + patterns + + + include + #method-declaration-name + + + include + #comment + + + include + #type-parameters + + + include + #function-parameters + + + include + #return-type + + + include + #decl-block + + - include - #decl-block + name + meta.method.declaration.tsx + begin + (?<!\.|\$)(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\b(?:(new)|(constructor))\b(?!\$|\.|:))|(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<])) + beginCaptures + + 1 + + name + storage.modifier.tsx + + 2 + + name + storage.modifier.tsx + + 3 + + name + storage.modifier.async.tsx + + 4 + + name + keyword.operator.new.tsx + + 5 + + name + storage.type.tsx + + 6 + + name + keyword.generator.asterisk.tsx + + + end + (?=\}|;|,|$)|(?<=\}) + patterns + + + include + #method-declaration-name + + + include + #comment + + + include + #type-parameters + + + include + #function-parameters + + + include + #return-type + + + include + #decl-block + + @@ -1914,7 +1977,7 @@ name meta.method.declaration.tsx begin - (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<]) + (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) beginCaptures 1 @@ -1970,7 +2033,7 @@ object-literal-method-overload-declaration begin - (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))?\s*[\(\<]) + (?<!\.|\$)(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=((([_$[:alpha:]][_$[:alnum:]]*)|(\'[^']*\')|(\"[^"]*\")|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*[\(\<]) beginCaptures 1 diff --git a/tests/baselines/Issue458.baseline.txt b/tests/baselines/Issue458.baseline.txt new file mode 100644 index 00000000..ec6f3548 --- /dev/null +++ b/tests/baselines/Issue458.baseline.txt @@ -0,0 +1,92 @@ +original file +----------------------------------- +export class Blah { + get () {} +} +const x = { + get () {} +} +----------------------------------- + +Grammar: TypeScript.tmLanguage +----------------------------------- +>export class Blah { + ^^^^^^ + source.ts meta.class.ts keyword.control.export.ts + ^ + source.ts meta.class.ts + ^^^^^ + source.ts meta.class.ts storage.type.class.ts + ^ + source.ts meta.class.ts + ^^^^ + source.ts meta.class.ts entity.name.type.class.ts + ^ + source.ts meta.class.ts + ^ + source.ts meta.class.ts punctuation.definition.block.ts + ^^ + source.ts meta.class.ts +> get () {} + ^^ + source.ts meta.class.ts + ^^^ + source.ts meta.class.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts + ^ + source.ts meta.class.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts + ^^ + source.ts meta.class.ts +>} + ^ + source.ts meta.class.ts punctuation.definition.block.ts + ^^ + source.ts +>const 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.readwrite.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 + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts punctuation.definition.block.ts + ^^ + source.ts meta.var.expr.ts meta.objectliteral.ts +> get () {} + ^^ + source.ts meta.var.expr.ts meta.objectliteral.ts + ^^^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts meta.method.declaration.ts meta.block.ts punctuation.definition.block.ts + ^^ + source.ts meta.var.expr.ts meta.objectliteral.ts +>} + ^ + source.ts meta.var.expr.ts meta.objectliteral.ts punctuation.definition.block.ts \ No newline at end of file diff --git a/tests/cases/Issue458.ts b/tests/cases/Issue458.ts new file mode 100644 index 00000000..b754eec6 --- /dev/null +++ b/tests/cases/Issue458.ts @@ -0,0 +1,6 @@ +export class Blah { + get () {} +} +const x = { + get () {} +} \ No newline at end of file