From fdcbf91f27133613759ab0a2121f1f77e472d728 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Tue, 2 Aug 2016 17:20:04 +0200 Subject: [PATCH] [typescript] evolve update script, emit grammar as JSON --- extensions/typescript/OSSREADME.json | 3 +- .../typescript/build/update-grammars.js | 62 +- extensions/typescript/package.json | 6 +- extensions/typescript/syntaxes/Readme.md | 5 + .../typescript/syntaxes/TypeScript.tmLanguage | 1996 -------------- .../syntaxes/TypeScript.tmLanguage.json | 1292 +++++++++ .../syntaxes/TypeScriptReact.tmLanguage | 2362 ----------------- .../syntaxes/TypeScriptReact.tmLanguage.json | 1525 +++++++++++ .../typescript/syntaxes/grammar-version.txt | 1 - package.json | 1 + 10 files changed, 2879 insertions(+), 4374 deletions(-) create mode 100644 extensions/typescript/syntaxes/Readme.md delete mode 100644 extensions/typescript/syntaxes/TypeScript.tmLanguage create mode 100644 extensions/typescript/syntaxes/TypeScript.tmLanguage.json delete mode 100644 extensions/typescript/syntaxes/TypeScriptReact.tmLanguage create mode 100644 extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json delete mode 100644 extensions/typescript/syntaxes/grammar-version.txt diff --git a/extensions/typescript/OSSREADME.json b/extensions/typescript/OSSREADME.json index 6680f0eac84..91e2030ce8e 100644 --- a/extensions/typescript/OSSREADME.json +++ b/extensions/typescript/OSSREADME.json @@ -4,10 +4,11 @@ // DO NOT USE OR SHARE THIS CODE WITHOUT APPROVAL PURSUANT TO THE MICROSOFT OPEN SOURCE SOFTWARE APPROVAL POLICY. [{ - "name": "typescript-sublime-plugin", + "name": "TypeScript-TmLanguage", "version": "0.1.8", "license": "Apache2", "repositoryURL": "https://github.com/Microsoft/TypeScript-TmLanguage", + "description": "The files syntaxes/TypeScript.tmLanguage.json and syntaxes/TypeScriptReact.tmLanguage.json were derived from TypeScript.tmLanguage and TypeScriptReact.tmLanguage in https://github.com/Microsoft/TypeScript-TmLanguage.", "licenseDetail": [ // Reason: LICENSE file does not include Copyright statement "Copyright (c) Microsoft Corporation. All rights reserved.", diff --git a/extensions/typescript/build/update-grammars.js b/extensions/typescript/build/update-grammars.js index e93c3d708b1..8a87bfc277b 100644 --- a/extensions/typescript/build/update-grammars.js +++ b/extensions/typescript/build/update-grammars.js @@ -6,20 +6,60 @@ var download = require('../../../build/lib/download'); var fs = require('fs'); +var plist = require('plist'); var contentBaseLocation = 'https://raw.githubusercontent.com/Microsoft/TypeScript-TmLanguage/master/'; + var lastCommit = 'https://api.github.com/repos/Microsoft/TypeScript-TmLanguage/git/refs/heads/master'; -Promise.all([ - download.toFile(contentBaseLocation + 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage'), - download.toFile(contentBaseLocation + 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage'), - download.toString(lastCommit).then(function (content) { - var commitInfo = JSON.parse(content); - fs.writeFileSync('./syntaxes/grammar-version.txt', commitInfo.object.url); - console.log('Update completed.'); - console.log('New commit comment:'); - console.log('[typescript] update grammar (Microsoft/TypeScript-TmLanguage@' + commitInfo.object.sha.substr(0, 7) + ')'); - }, console.error) -]); +download.toString(lastCommit).then(function (content) { + var commitSha = JSON.parse(content).object.sha; + function writeJSON(fileName, modifyGrammar) { + return function(content) { + var grammar = plist.parse(content); + grammar.version = 'https://github.com/Microsoft/TypeScript-TmLanguage/commit/' + commitSha; + if (modifyGrammar) { + modifyGrammar(grammar); + } + fs.writeFileSync(fileName, JSON.stringify(grammar, null, '\t')); + } + } + + return Promise.all([ + download.toString(contentBaseLocation + 'TypeScript.tmLanguage').then(writeJSON('./syntaxes/TypeScript.tmLanguage.json'), console.error), + download.toString(contentBaseLocation + 'TypeScriptReact.tmLanguage').then(writeJSON('./syntaxes/TypeScriptReact.tmLanguage.json'), console.error), + download.toString(contentBaseLocation + 'TypeScriptReact.tmLanguage').then(writeJSON('../javascript/syntaxes/JavaScript.tmLanguage.json', adaptToJavaScript), console.error) + ]).then(function() { + console.log('Update complete.'); + console.log('[typescript] update grammar (Microsoft/TypeScript-TmLanguage@' + commitSha.substr(0, 7) + ')'); + }); +}, console.error); + +function adaptToJavaScript(grammar) { + grammar.name = 'JavaScript (with React support)'; + grammar.fileTypes = ['.js', '.jsx' ]; + grammar.scopeName = 'source.js'; + + var fixScopeNames = function(rule) { + if (typeof rule.name === 'string') { + rule.name = rule.name.replace(/\.tsx/g, '.js'); + } + for (var property in rule) { + var value = rule[property]; + if (typeof value === 'object') { + fixScopeNames(value); + } + } + }; + + var repository = grammar.repository; + for (var key in repository) { + fixScopeNames(repository[key]); + } + // disable type parameters + if (repository['type-parameters']) { + repository['type-parameters']['begin'] = 'DO_NOT_MATCH'; + } +} diff --git a/extensions/typescript/package.json b/extensions/typescript/package.json index ee5e64c1567..d1ba19d4dbb 100644 --- a/extensions/typescript/package.json +++ b/extensions/typescript/package.json @@ -16,7 +16,7 @@ }, "scripts": { "vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:typescript ./tsconfig.json", - "update-grammar": "node ./build/update-grammars.js" + "update-grammars": "node ./build/update-grammars.js" }, "activationEvents": [ "onLanguage:javascript", @@ -57,12 +57,12 @@ { "language": "typescript", "scopeName": "source.ts", - "path": "./syntaxes/TypeScript.tmLanguage" + "path": "./syntaxes/TypeScript.tmLanguage.json" }, { "language": "typescriptreact", "scopeName": "source.tsx", - "path": "./syntaxes/TypeScriptReact.tmLanguage" + "path": "./syntaxes/TypeScriptReact.tmLanguage.json" } ], "configuration": { diff --git a/extensions/typescript/syntaxes/Readme.md b/extensions/typescript/syntaxes/Readme.md new file mode 100644 index 00000000000..c60adbcf4a5 --- /dev/null +++ b/extensions/typescript/syntaxes/Readme.md @@ -0,0 +1,5 @@ +The file `TypeScript.tmLanguage.json` and `TypeScriptReact.tmLanguage.json` are derived from [TypeScript.tmLanguage](https://github.com/Microsoft/TypeScript-TmLanguage/blob/master/TypeScript.tmLanguage) and [TypeScriptReact.tmLanguage](https://github.com/Microsoft/TypeScript-TmLanguage/blob/master/TypeScriptReact.tmLanguage). + +To update to the latest version: +- `cd extensions/typescript` and run `npm run update-grammars` +- don't forget to run the integration tests at `./scripts/test-integration.sh` diff --git a/extensions/typescript/syntaxes/TypeScript.tmLanguage b/extensions/typescript/syntaxes/TypeScript.tmLanguage deleted file mode 100644 index 88cda0449ee..00000000000 --- a/extensions/typescript/syntaxes/TypeScript.tmLanguage +++ /dev/null @@ -1,1996 +0,0 @@ - - - - - fileTypes - - ts - - name - TypeScript - patterns - - - include - #expression - - - repository - - access-modifier - - match - \b(public|protected|private)\b - name - storage.modifier.ts - - arithmetic-operator - - match - \*|/|\-\-|\-|\+\+|\+|% - name - keyword.operator.arithmetic.ts - - array-literal - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.ts - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.ts - - - name - meta.array.literal.ts - patterns - - - include - #expression - - - - assignment-operator - - match - <<=|>>>=|>>=|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^= - name - keyword.operator.assignment.ts - - await-modifier - - match - \bawait\b - name - storage.modifier.ts - - block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.ts - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.ts - - - name - meta.block.ts - patterns - - - include - #object-member - - - include - #expression - - - - boolean-literal - - match - \b(false|true)\b - name - constant.language.boolean.ts - - case-clause - - begin - (?<!\.)\b(case|default(?=:))\b - beginCaptures - - 1 - - name - keyword.control.ts - - - end - : - name - case-clause.expr.ts - patterns - - - include - #expression-type - - - - cast - - begin - (?:(?<=return|throw|yield|await|[=(,:>]))\s*(<)(?!<?\=) - beginCaptures - - 1 - - name - meta.brace.angle.ts - - - end - > - endCaptures - - 0 - - name - meta.brace.angle.ts - - - name - cast.expr.ts - patterns - - - include - #type - - - - comment - - name - comment.ts - patterns - - - include - #comment-block-doc - - - include - #comment-block - - - include - #comment-line - - - - comment-block - - begin - /\* - end - \*/ - name - comment.block.ts - - comment-block-doc - - begin - /\*\*(?!/) - end - \*/ - name - comment.block.documentation.ts - - comment-line - - match - (//).*$\n? - name - comment.line.ts - - control-statement - - match - (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default|yield)\b - name - keyword.control.ts - - decl-block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.ts - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.ts - - - name - meta.decl.block.ts - patterns - - - include - #expression - - - - declaration - - name - meta.declaration.ts - patterns - - - include - #function-declaration - - - include - #object-declaration - - - include - #type-declaration - - - include - #enum-declaration - - - - enum-declaration - - captures - - 1 - - name - storage.modifier.ts - - 2 - - name - storage.type.ts - - 3 - - name - entity.name.class.ts - - - match - (?:\b(const)\s+)?\b(enum)\s+([a-zA-Z_$][\w$]*) - name - meta.enum.declaration.ts - - expression - - name - meta.expression.ts - patterns - - - include - #for-in-simple - - - include - #string - - - include - #regex - - - include - #template - - - include - #comment - - - include - #literal - - - include - #paren-expression - - - include - #var-expr - - - include - #declaration - - - include - #cast - - - include - #new-expr - - - include - #switch-statement - - - include - #block - - - include - #import-operator - - - include - #expression-operator - - - include - #imply-operator - - - include - #relational-operator - - - include - #arithmetic-operator - - - include - #logic-operator - - - include - #assignment-operator - - - include - #storage-keyword - - - include - #type-primitive - - - include - #function-call - - - include - #case-clause - - - include - #control-statement - - - - expression-operator - - match - \b(delete|in|instanceof|new|typeof|as|is|of)\b - name - keyword.others.ts - - expression-type - - name - meta.expression.ts - patterns - - - include - #string - - - include - #regex - - - include - #template - - - include - #comment - - - include - #literal - - - include - #paren-expression - - - include - #ternary-expression - - - include - #import-operator - - - include - #expression-operator - - - include - #imply-operator - - - include - #relational-operator - - - include - #arithmetic-operator - - - include - #logic-operator - - - include - #assignment-operator - - - include - #type-primitive - - - include - #function-call - - - - field-declaration - - begin - (?<!\()\s*((?:\b[a-zA-Z_$][\w$]*)|(?:\'[^']*\')|(?:\"[^"]*\"))\s*(\?\s*)?(?=(=|:)) - beginCaptures - - 1 - - name - variable.ts - - 2 - - name - keyword.others.ts - - - end - (?=\}|;|,|$)|(?<=\}) - name - meta.field.declaration.ts - patterns - - - include - #expression - - - - for-in-simple - - captures - - 1 - - name - storage.type.ts - - 3 - - name - keyword.others.ts - - - match - (?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b - name - forin.expr.ts - - function-call - - name - functioncall.expr.ts - patterns - - - include - #await-modifier - - - include - #type-parameters - - - include - #paren-expression - - - - function-declaration - - begin - \b(?:(export)\s+)?(?:(async)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - beginCaptures - - 1 - - name - storage.type.ts - - 2 - - name - storage.modifier.ts - - 3 - - name - storage.type.function.ts - - 4 - - name - entity.name.function.ts - - - end - (?=;|\})|(?<=\}) - name - meta.function.ts - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #return-type - - - include - #function-overload-declaration - - - include - #decl-block - - - - function-overload-declaration - - captures - - 1 - - name - storage.type.ts - - 2 - - name - storage.type.function.ts - - 3 - - name - entity.name.function.ts - - - match - \b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - name - meta.function.overload.ts - - function-type-parameters - - begin - \( - beginCaptures - - 0 - - name - meta.brace.round.ts - - - end - \) - endCaptures - - 0 - - name - meta.brace.round.ts - - - name - meta.function.type.parameter.ts - patterns - - - include - #comment - - - include - #parameter-name - - - include - #type-annotation - - - include - #variable-initializer - - - - imply-operator - - match - => - name - keyword.operator.ts - - import-operator - - match - \b(import|from)\b - name - keyword.control.import.include.ts - - indexer-declaration - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.ts - - - end - (\])\s*(\?\s*)?|$ - endCaptures - - 1 - - name - meta.brace.square.ts - - 2 - - name - keyword.others.ts - - - name - meta.indexer.declaration.ts - patterns - - - include - #type-annotation - - - include - #indexer-parameter - - - include - #expression - - - - indexer-parameter - - captures - - 1 - - name - variable.parameter.ts - - - match - ([a-zA-Z_$][\w$]*)(?=\:) - name - meta.indexer.parameter.ts - - literal - - name - literal.ts - patterns - - - include - #numeric-literal - - - include - #boolean-literal - - - include - #null-literal - - - include - #undefined-literal - - - include - #array-literal - - - include - #this-literal - - - - logic-operator - - match - \!|&&|&|~|\^|\|\||\| - name - keyword.operator.arithmetic.ts - - method-declaration - - begin - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - beginCaptures - - 1 - - name - storage.modifier.ts - - 2 - - name - storage.modifier.ts - - 3 - - name - storage.modifier.ts - - 4 - - name - storage.type.property.ts - - 5 - - name - keyword.operator.ts - - 6 - - name - storage.type.ts - - 7 - - name - entity.name.function.ts - - 8 - - name - keyword.operator.ts - - - end - (?=\}|;|,)|(?<=\}) - name - meta.method.declaration.ts - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #type-annotation - - - include - #method-overload-declaration - - - include - #decl-block - - - - method-overload-declaration - - captures - - 1 - - name - storage.modifier.ts - - 2 - - name - storage.modifier.ts - - 3 - - name - storage.modifier.ts - - 4 - - name - storage.type.property.ts - - 5 - - name - keyword.operator.ts - - 6 - - name - storage.type.ts - - 7 - - name - entity.name.function.ts - - 8 - - name - keyword.operator.ts - - - match - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - name - meta.method.overload.declaration.ts - - new-expr - - begin - \b(new)\b - beginCaptures - - 1 - - name - keyword.others.ts - - - end - (?=[(;]|$) - name - new.expr.ts - patterns - - - include - #type - - - include - #comment - - - - null-literal - - match - \b(null)\b - name - constant.language.null.ts - - numeric-literal - - match - \b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|(0(o|O)[0-7]+)|(0(b|B)(0|1)+)|(([0-9]+(\.[0-9]+)?))([eE]([+-]?)[0-9]+(\.[0-9]+)?)?)\b - name - constant.numeric.ts - - object-body - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.ts - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.ts - - - name - meta.object.body.ts - patterns - - - include - #string - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - include - #variable-initializer - - - include - #access-modifier - - - include - #static-modifier - - - include - #property-accessor - - - - object-declaration - - begin - \b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(class|interface)\b - beginCaptures - - 1 - - name - storage.type.ts - - 2 - - name - storage.modifier.ts - - 3 - - name - storage.type.ts - - - end - (?<=\}) - endCaptures - - 1 - - name - brace.curly.ts - - - name - meta.declaration.object.ts - patterns - - - include - #comment - - - include - #object-heritage - - - include - #object-name - - - include - #type-parameters - - - include - #object-body - - - - object-heritage - - begin - (?:\b(extends|implements)\b) - beginCaptures - - 1 - - name - keyword.other.ts - - - end - (?=\{) - endCaptures - - 1 - - name - brace.curly.ts - - - name - meta.object.heritage.ts - patterns - - - include - #comment - - - include - #object-heritage - - - include - #type-parameters - - - include - #object-heritage-type - - - - object-heritage-type - - captures - - 1 - - name - support.type.ts - - - match - (?:\b([a-zA-Z_$][\w$]*)\b) - name - meta.object.heritage.parent.ts - - object-member - - begin - [a-zA-Z_$][\w$]*\s*: - end - (?=,|\}) - name - meta.object.member.ts - patterns - - - include - #expression - - - - object-name - - captures - - 0 - - name - entity.name.class.ts - - - match - [a-zA-Z_$][\w$]* - name - meta.object.name.ts - - parameter-name - - captures - - 1 - - name - storage.modifier.ts - - 2 - - name - keyword.others.ts - - 3 - - name - variable.parameter.ts - - 4 - - name - keyword.others.ts - - - match - (?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??) - name - parameter.name.ts - - paren-expression - - begin - \( - beginCaptures - - 0 - - name - meta.brace.paren.ts - - - end - \) - endCaptures - - 0 - - name - meta.brace.paren.ts - - - patterns - - - include - #expression - - - - property-accessor - - match - \b(get|set)\b - name - storage.type.property.ts - - qstring-double - - begin - " - end - "|(?:[^\\\n]$) - name - string.double.ts - patterns - - - include - #string-character-escape - - - - qstring-single - - begin - ' - end - \'|(?:[^\\\n]$) - name - string.single.ts - patterns - - - include - #string-character-escape - - - - regex - - begin - (?<=[=(:,\[]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?]) - end - $|(/)[igm]* - name - string.regex.ts - patterns - - - match - \\. - name - constant.character.escape.ts - - - match - \[(\\\]|[^\]])*\] - name - constant.character.class.ts - - - - relational-operator - - match - ===|!==|==|!=|<=|>=|<>|=|<|> - name - keyword.operator.comparison.ts - - return-type - - begin - (?<=\))\s*: - end - (?=$)|(?=\{|;|//) - name - meta.return.type.ts - patterns - - - include - #type - - - - static-modifier - - match - \b(static)\b - name - keyword.other.ts - - storage-keyword - - match - \b(var|let|function|const|module|namespace|void|export)\b - name - storage.type.ts - - string - - name - string.ts - patterns - - - include - #qstring-single - - - include - #qstring-double - - - - string-character-escape - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$) - name - constant.character.escape - - switch-block - - begin - { - end - (?=\}) - name - switch-block.expr.ts - patterns - - - include - #expression - - - - switch-expression - - begin - \b(switch)\b\s*\( - beginCaptures - - 1 - - name - keyword.control.ts - - - end - \) - name - switch-expression.expr.ts - patterns - - - include - #expression - - - - switch-statement - - begin - (?=\bswitch\b\s*\() - end - } - name - switch-statement.expr.ts - patterns - - - include - #switch-expression - - - include - #switch-block - - - - template - - begin - ` - beginCaptures - - 0 - - name - string.template.ts - - - end - ` - endCaptures - - 0 - - name - string.template.ts - - - name - meta.template.ts - patterns - - - include - #template-substitution-element - - - include - #template-string-contents - - - - template-string-contents - - begin - .*? - end - (?=(\$\{|`)) - name - string.template.ts - patterns - - - include - #string-character-escape - - - - template-substitution-element - - begin - \$\{ - beginCaptures - - 0 - - name - keyword.others.ts - - - end - \} - endCaptures - - 0 - - name - keyword.others.ts - - - name - template.element.ts - patterns - - - include - #expression - - - - ternary-expression - - begin - (?=\?) - end - (?=$|[;,]) - patterns - - - include - #ternary-operator - - - include - #expression-type - - - - ternary-operator - - begin - (\?) - end - (:) - patterns - - - include - #expression-type - - - - this-literal - - match - \b(this)\b - name - constant.language.this.ts - - type - - name - meta.type.ts - patterns - - - include - #type-primitive - - - include - #type-parameters - - - include - #type-tuple - - - include - #type-object - - - include - #type-operator - - - include - #type-paren-or-function-type-parameters - - - include - #type-function-return-type - - - include - #type-name - - - - type-annotation - - begin - : - end - (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{) - name - meta.type.annotation.ts - patterns - - - include - #expression-operator - - - include - #type - - - include - #string - - - include - #comment - - - - type-declaration - - begin - \b(type)\b\s+([a-zA-Z_$][\w$]*)\s* - beginCaptures - - 1 - - name - keyword.other.ts - - 2 - - name - entity.name.class.ts - - - end - (?=$|[,);>]|var|type|function|class|interface) - name - meta.type.declaration.ts - patterns - - - include - #type-parameters - - - include - #type - - - match - =\s* - name - keyword.operator.comparison.ts - - - - type-function-return-type - - begin - => - beginCaptures - - 0 - - name - keyword.operator.ts - - - end - (?=\s*[,\)\{=;>]|//|$) - name - meta.type.function.return.ts - patterns - - - include - #type - - - - type-name - - captures - - 1 - - name - entity.name.type.ts - - - match - [a-zA-Z_$][.\w$]* - name - meta.type.name.ts - - type-object - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.ts - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.ts - - - name - meta.object.type.ts - patterns - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - - type-operator - - match - [.|] - name - keyword.operator.type.ts - - type-parameters - - begin - ([a-zA-Z_$][\w$]*)?(<) - beginCaptures - - 1 - - name - entity.name.type.ts - - 2 - - name - meta.brace.angle.ts - - - end - (?=$)|(>) - endCaptures - - 2 - - name - meta.brace.angle.ts - - - name - meta.type.parameters.ts - patterns - - - match - \b(extends)\b - name - keyword.other.ts - - - include - #comment - - - include - #type - - - - type-paren-or-function-type-parameters - - begin - (?:\b(new)\b)?\s*\( - beginCaptures - - 1 - - name - keyword.control.ts - - - end - \) - name - meta.type.paren.cover.ts - patterns - - - include - #comment - - - include - #type - - - include - #function-type-parameters - - - - type-primitive - - captures - - 1 - - name - support.type.ts - - - match - \b(string|number|boolean|symbol|any|void)\b - name - meta.type.primitive.ts - - type-tuple - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.ts - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.ts - - - name - meta.type.tuple.ts - patterns - - - include - #type - - - include - #comment - - - - undefined-literal - - match - \b(undefined)\b - name - constant.language.ts - - var-expr - - begin - (?<!\()\s*\b(var|let|const(?!\s+enum))\b - beginCaptures - - 1 - - name - storage.type.ts - - - end - (?=$|;) - name - meta.var.expr.ts - patterns - - - include - #var-single-variable - - - include - #comment - - - - var-single-variable - - begin - \b([a-zA-Z_$][\w$]*)\s*(=?) - beginCaptures - - 1 - - name - variable.ts - - - end - (?=$|[;,]) - name - meta.var-single-variable.expr.ts - patterns - - - include - #ternary-expression - - - include - #type-annotation - - - include - #string - - - include - #comment - - - include - #expression - - - - variable-initializer - - begin - (=) - beginCaptures - - 1 - - name - keyword.operator.comparison.ts - - - end - (?=$|[,);=]) - patterns - - - include - #expression - - - - - scopeName - source.ts - uuid - ef98eb90-bf9b-11e4-bb52-0800200c9a66 - - diff --git a/extensions/typescript/syntaxes/TypeScript.tmLanguage.json b/extensions/typescript/syntaxes/TypeScript.tmLanguage.json new file mode 100644 index 00000000000..0935b2e2666 --- /dev/null +++ b/extensions/typescript/syntaxes/TypeScript.tmLanguage.json @@ -0,0 +1,1292 @@ +{ + "fileTypes": [ + "ts" + ], + "name": "TypeScript", + "patterns": [ + { + "include": "#expression" + } + ], + "repository": { + "access-modifier": { + "match": "\\b(public|protected|private)\\b", + "name": "storage.modifier.ts" + }, + "arithmetic-operator": { + "match": "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%", + "name": "keyword.operator.arithmetic.ts" + }, + "array-literal": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.ts" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.ts" + } + }, + "name": "meta.array.literal.ts", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "assignment-operator": { + "match": "<<=|>>>=|>>=|\\*=|(?]))\\s*(<)(?!", + "endCaptures": { + "0": { + "name": "meta.brace.angle.ts" + } + }, + "name": "cast.expr.ts", + "patterns": [ + { + "include": "#type" + } + ] + }, + "comment": { + "name": "comment.ts", + "patterns": [ + { + "include": "#comment-block-doc" + }, + { + "include": "#comment-block" + }, + { + "include": "#comment-line" + } + ] + }, + "comment-block": { + "begin": "/\\*", + "end": "\\*/", + "name": "comment.block.ts" + }, + "comment-block-doc": { + "begin": "/\\*\\*(?!/)", + "end": "\\*/", + "name": "comment.block.documentation.ts" + }, + "comment-line": { + "match": "(//).*$\\n?", + "name": "comment.line.ts" + }, + "control-statement": { + "match": "(?", + "name": "keyword.operator.ts" + }, + "import-operator": { + "match": "\\b(import|from)\\b", + "name": "keyword.control.import.include.ts" + }, + "indexer-declaration": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.ts" + } + }, + "end": "(\\])\\s*(\\?\\s*)?|$", + "endCaptures": { + "1": { + "name": "meta.brace.square.ts" + }, + "2": { + "name": "keyword.others.ts" + } + }, + "name": "meta.indexer.declaration.ts", + "patterns": [ + { + "include": "#type-annotation" + }, + { + "include": "#indexer-parameter" + }, + { + "include": "#expression" + } + ] + }, + "indexer-parameter": { + "captures": { + "1": { + "name": "variable.parameter.ts" + } + }, + "match": "([a-zA-Z_$][\\w$]*)(?=\\:)", + "name": "meta.indexer.parameter.ts" + }, + "literal": { + "name": "literal.ts", + "patterns": [ + { + "include": "#numeric-literal" + }, + { + "include": "#boolean-literal" + }, + { + "include": "#null-literal" + }, + { + "include": "#undefined-literal" + }, + { + "include": "#array-literal" + }, + { + "include": "#this-literal" + } + ] + }, + "logic-operator": { + "match": "\\!|&&|&|~|\\^|\\|\\||\\|", + "name": "keyword.operator.arithmetic.ts" + }, + "method-declaration": { + "begin": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:\\b(constructor)\\b)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "beginCaptures": { + "1": { + "name": "storage.modifier.ts" + }, + "2": { + "name": "storage.modifier.ts" + }, + "3": { + "name": "storage.modifier.ts" + }, + "4": { + "name": "storage.type.property.ts" + }, + "5": { + "name": "keyword.operator.ts" + }, + "6": { + "name": "storage.type.ts" + }, + "7": { + "name": "entity.name.function.ts" + }, + "8": { + "name": "keyword.operator.ts" + } + }, + "end": "(?=\\}|;|,)|(?<=\\})", + "name": "meta.method.declaration.ts", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-parameters" + }, + { + "include": "#function-type-parameters" + }, + { + "include": "#type-annotation" + }, + { + "include": "#method-overload-declaration" + }, + { + "include": "#decl-block" + } + ] + }, + "method-overload-declaration": { + "captures": { + "1": { + "name": "storage.modifier.ts" + }, + "2": { + "name": "storage.modifier.ts" + }, + "3": { + "name": "storage.modifier.ts" + }, + "4": { + "name": "storage.type.property.ts" + }, + "5": { + "name": "keyword.operator.ts" + }, + "6": { + "name": "storage.type.ts" + }, + "7": { + "name": "entity.name.function.ts" + }, + "8": { + "name": "keyword.operator.ts" + } + }, + "match": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:\\b(constructor)\\b)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "name": "meta.method.overload.declaration.ts" + }, + "new-expr": { + "begin": "\\b(new)\\b", + "beginCaptures": { + "1": { + "name": "keyword.others.ts" + } + }, + "end": "(?=[(;]|$)", + "name": "new.expr.ts", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "null-literal": { + "match": "\\b(null)\\b", + "name": "constant.language.null.ts" + }, + "numeric-literal": { + "match": "\\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|(0(o|O)[0-7]+)|(0(b|B)(0|1)+)|(([0-9]+(\\.[0-9]+)?))([eE]([+-]?)[0-9]+(\\.[0-9]+)?)?)\\b", + "name": "constant.numeric.ts" + }, + "object-body": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.ts" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.ts" + } + }, + "name": "meta.object.body.ts", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + }, + { + "include": "#variable-initializer" + }, + { + "include": "#access-modifier" + }, + { + "include": "#static-modifier" + }, + { + "include": "#property-accessor" + } + ] + }, + "object-declaration": { + "begin": "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?=|<>|=|<|>", + "name": "keyword.operator.comparison.ts" + }, + "return-type": { + "begin": "(?<=\\))\\s*:", + "end": "(?=$)|(?=\\{|;|//)", + "name": "meta.return.type.ts", + "patterns": [ + { + "include": "#type" + } + ] + }, + "static-modifier": { + "match": "\\b(static)\\b", + "name": "keyword.other.ts" + }, + "storage-keyword": { + "match": "\\b(var|let|function|const|module|namespace|void|export)\\b", + "name": "storage.type.ts" + }, + "string": { + "name": "string.ts", + "patterns": [ + { + "include": "#qstring-single" + }, + { + "include": "#qstring-double" + } + ] + }, + "string-character-escape": { + "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)", + "name": "constant.character.escape" + }, + "switch-block": { + "begin": "{", + "end": "(?=\\})", + "name": "switch-block.expr.ts", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-expression": { + "begin": "\\b(switch)\\b\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.control.ts" + } + }, + "end": "\\)", + "name": "switch-expression.expr.ts", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-statement": { + "begin": "(?=\\bswitch\\b\\s*\\()", + "end": "}", + "name": "switch-statement.expr.ts", + "patterns": [ + { + "include": "#switch-expression" + }, + { + "include": "#switch-block" + } + ] + }, + "template": { + "begin": "`", + "beginCaptures": { + "0": { + "name": "string.template.ts" + } + }, + "end": "`", + "endCaptures": { + "0": { + "name": "string.template.ts" + } + }, + "name": "meta.template.ts", + "patterns": [ + { + "include": "#template-substitution-element" + }, + { + "include": "#template-string-contents" + } + ] + }, + "template-string-contents": { + "begin": ".*?", + "end": "(?=(\\$\\{|`))", + "name": "string.template.ts", + "patterns": [ + { + "include": "#string-character-escape" + } + ] + }, + "template-substitution-element": { + "begin": "\\$\\{", + "beginCaptures": { + "0": { + "name": "keyword.others.ts" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "keyword.others.ts" + } + }, + "name": "template.element.ts", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "ternary-expression": { + "begin": "(?=\\?)", + "end": "(?=$|[;,])", + "patterns": [ + { + "include": "#ternary-operator" + }, + { + "include": "#expression-type" + } + ] + }, + "ternary-operator": { + "begin": "(\\?)", + "end": "(:)", + "patterns": [ + { + "include": "#expression-type" + } + ] + }, + "this-literal": { + "match": "\\b(this)\\b", + "name": "constant.language.this.ts" + }, + "type": { + "name": "meta.type.ts", + "patterns": [ + { + "include": "#type-primitive" + }, + { + "include": "#type-parameters" + }, + { + "include": "#type-tuple" + }, + { + "include": "#type-object" + }, + { + "include": "#type-operator" + }, + { + "include": "#type-paren-or-function-type-parameters" + }, + { + "include": "#type-function-return-type" + }, + { + "include": "#type-name" + } + ] + }, + "type-annotation": { + "begin": ":", + "end": "(?=$|[,);\\}\\]]|//)|(?==[^>])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)", + "name": "meta.type.annotation.ts", + "patterns": [ + { + "include": "#expression-operator" + }, + { + "include": "#type" + }, + { + "include": "#string" + }, + { + "include": "#comment" + } + ] + }, + "type-declaration": { + "begin": "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*", + "beginCaptures": { + "1": { + "name": "keyword.other.ts" + }, + "2": { + "name": "entity.name.class.ts" + } + }, + "end": "(?=$|[,);>]|var|type|function|class|interface)", + "name": "meta.type.declaration.ts", + "patterns": [ + { + "include": "#type-parameters" + }, + { + "include": "#type" + }, + { + "match": "=\\s*", + "name": "keyword.operator.comparison.ts" + } + ] + }, + "type-function-return-type": { + "begin": "=>", + "beginCaptures": { + "0": { + "name": "keyword.operator.ts" + } + }, + "end": "(?=\\s*[,\\)\\{=;>]|//|$)", + "name": "meta.type.function.return.ts", + "patterns": [ + { + "include": "#type" + } + ] + }, + "type-name": { + "captures": { + "1": { + "name": "entity.name.type.ts" + } + }, + "match": "[a-zA-Z_$][.\\w$]*", + "name": "meta.type.name.ts" + }, + "type-object": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.ts" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.ts" + } + }, + "name": "meta.object.type.ts", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + } + ] + }, + "type-operator": { + "match": "[.|]", + "name": "keyword.operator.type.ts" + }, + "type-parameters": { + "begin": "([a-zA-Z_$][\\w$]*)?(<)", + "beginCaptures": { + "1": { + "name": "entity.name.type.ts" + }, + "2": { + "name": "meta.brace.angle.ts" + } + }, + "end": "(?=$)|(>)", + "endCaptures": { + "2": { + "name": "meta.brace.angle.ts" + } + }, + "name": "meta.type.parameters.ts", + "patterns": [ + { + "match": "\\b(extends)\\b", + "name": "keyword.other.ts" + }, + { + "include": "#comment" + }, + { + "include": "#type" + } + ] + }, + "type-paren-or-function-type-parameters": { + "begin": "(?:\\b(new)\\b)?\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.control.ts" + } + }, + "end": "\\)", + "name": "meta.type.paren.cover.ts", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type" + }, + { + "include": "#function-type-parameters" + } + ] + }, + "type-primitive": { + "captures": { + "1": { + "name": "support.type.ts" + } + }, + "match": "\\b(string|number|boolean|symbol|any|void)\\b", + "name": "meta.type.primitive.ts" + }, + "type-tuple": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.ts" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.ts" + } + }, + "name": "meta.type.tuple.ts", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "undefined-literal": { + "match": "\\b(undefined)\\b", + "name": "constant.language.ts" + }, + "var-expr": { + "begin": "(? - - - - fileTypes - - tsx - - name - TypeScriptReact - patterns - - - include - #expression - - - repository - - access-modifier - - match - \b(public|protected|private)\b - name - storage.modifier.tsx - - arithmetic-operator - - match - \*|/|\-\-|\-|\+\+|\+|% - name - keyword.operator.arithmetic.tsx - - array-literal - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.tsx - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.tsx - - - name - meta.array.literal.tsx - patterns - - - include - #expression - - - - assignment-operator - - match - <<=|>>>=|>>=|\*=|(?<!\()/=|%=|\+=|\-=|&=|\^= - name - keyword.operator.assignment.tsx - - await-modifier - - match - \bawait\b - name - storage.modifier.tsx - - block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.tsx - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.tsx - - - name - meta.block.tsx - patterns - - - include - #object-member - - - include - #expression - - - - boolean-literal - - match - \b(false|true)\b - name - constant.language.boolean.tsx - - case-clause - - begin - (?<!\.)\b(case|default(?=:))\b - beginCaptures - - 1 - - name - keyword.control.tsx - - - end - : - name - case-clause.expr.tsx - patterns - - - include - #expression-type - - - - comment - - name - comment.tsx - patterns - - - include - #comment-block-doc - - - include - #comment-block - - - include - #comment-line - - - - comment-block - - begin - /\* - end - \*/ - name - comment.block.tsx - - comment-block-doc - - begin - /\*\*(?!/) - end - \*/ - name - comment.block.documentation.tsx - - comment-line - - match - (//).*$\n? - name - comment.line.tsx - - control-statement - - match - (?<!\.)\b(break|catch|continue|debugger|declare|do|else|finally|for|if|return|switch|throw|try|while|with|super|case|default|yield)\b - name - keyword.control.tsx - - decl-block - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.tsx - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.tsx - - - name - meta.decl.block.tsx - patterns - - - include - #expression - - - - declaration - - name - meta.declaration.tsx - patterns - - - include - #function-declaration - - - include - #object-declaration - - - include - #type-declaration - - - include - #enum-declaration - - - - enum-declaration - - captures - - 1 - - name - storage.modifier.tsx - - 2 - - name - storage.type.tsx - - 3 - - name - entity.name.class.tsx - - - match - (?:\b(const)\s+)?\b(enum)\s+([a-zA-Z_$][\w$]*) - name - meta.enum.declaration.tsx - - expression - - name - meta.expression.tsx - patterns - - - include - #jsx - - - include - #for-in-simple - - - include - #string - - - include - #regex - - - include - #template - - - include - #comment - - - include - #literal - - - include - #paren-expression - - - include - #var-expr - - - include - #declaration - - - include - #new-expr - - - include - #switch-statement - - - include - #block - - - include - #import-operator - - - include - #expression-operator - - - include - #imply-operator - - - include - #relational-operator - - - include - #arithmetic-operator - - - include - #logic-operator - - - include - #assignment-operator - - - include - #storage-keyword - - - include - #type-primitive - - - include - #function-call - - - include - #case-clause - - - include - #control-statement - - - - expression-operator - - match - \b(delete|in|instanceof|new|typeof|as|is|of)\b - name - keyword.others.tsx - - expression-type - - name - meta.expression.tsx - patterns - - - include - #string - - - include - #regex - - - include - #template - - - include - #comment - - - include - #literal - - - include - #paren-expression - - - include - #ternary-expression - - - include - #import-operator - - - include - #expression-operator - - - include - #imply-operator - - - include - #relational-operator - - - include - #arithmetic-operator - - - include - #logic-operator - - - include - #assignment-operator - - - include - #type-primitive - - - include - #function-call - - - - field-declaration - - begin - (?<!\()\s*((?:\b[a-zA-Z_$][\w$]*)|(?:\'[^']*\')|(?:\"[^"]*\"))\s*(\?\s*)?(?=(=|:)) - beginCaptures - - 1 - - name - variable.tsx - - 2 - - name - keyword.others.tsx - - - end - (?=\}|;|,|$)|(?<=\}) - name - meta.field.declaration.tsx - patterns - - - include - #expression - - - - for-in-simple - - captures - - 1 - - name - storage.type.tsx - - 3 - - name - keyword.others.tsx - - - match - (?<=\()\s*\b(var|let|const)\s+([a-zA-Z_$][\w$]*)\s+(in|of)\b - name - forin.expr.tsx - - function-call - - name - functioncall.expr.tsx - patterns - - - include - #await-modifier - - - include - #type-parameters - - - include - #paren-expression - - - - function-declaration - - begin - \b(?:(export)\s+)?(?:(async)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - beginCaptures - - 1 - - name - storage.type.tsx - - 2 - - name - storage.modifier.tsx - - 3 - - name - storage.type.function.tsx - - 4 - - name - entity.name.function.tsx - - - end - (?=;|\})|(?<=\}) - name - meta.function.tsx - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #return-type - - - include - #function-overload-declaration - - - include - #decl-block - - - - function-overload-declaration - - captures - - 1 - - name - storage.type.tsx - - 2 - - name - storage.type.function.tsx - - 3 - - name - entity.name.function.tsx - - - match - \b(?:(export)\s+)?(function\b)(?:\s+([a-zA-Z_$][\w$]*))?\s* - name - meta.function.overload.tsx - - function-type-parameters - - begin - \( - beginCaptures - - 0 - - name - meta.brace.round.tsx - - - end - \) - endCaptures - - 0 - - name - meta.brace.round.tsx - - - name - meta.function.type.parameter.tsx - patterns - - - include - #comment - - - include - #parameter-name - - - include - #type-annotation - - - include - #variable-initializer - - - - imply-operator - - match - => - name - keyword.operator.tsx - - import-operator - - match - \b(import|from)\b - name - keyword.control.import.include.tsx - - indexer-declaration - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.tsx - - - end - (\])\s*(\?\s*)?|$ - endCaptures - - 1 - - name - meta.brace.square.tsx - - 2 - - name - keyword.others.tsx - - - name - meta.indexer.declaration.tsx - patterns - - - include - #type-annotation - - - include - #indexer-parameter - - - include - #expression - - - - indexer-parameter - - captures - - 1 - - name - variable.parameter.tsx - - - match - ([a-zA-Z_$][\w$]*)(?=\:) - name - meta.indexer.parameter.tsx - - jsx - - name - meta.jsx.tsx - patterns - - - include - #jsx-tag-without-attributes - - - include - #jsx-tag-open - - - include - #jsx-tag-close - - - include - #jsx-tag-invalid - - - begin - (?<=(?:'|"|})>) - end - (?=</) - name - meta.jsx.children.tsx - patterns - - - include - #jsx-children - - - - - - jsx-children - - patterns - - - include - #jsx-tag-without-attributes - - - include - #jsx-tag-open - - - include - #jsx-tag-close - - - include - #jsx-tag-invalid - - - include - #jsx-evaluated-code - - - include - #jsx-entities - - - - jsx-entities - - patterns - - - captures - - 1 - - name - punctuation.definition.entity.tsx - - 3 - - name - punctuation.definition.entity.tsx - - - match - (&)([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+)(;) - name - constant.character.entity.tsx - - - match - & - name - invalid.illegal.bad-ampersand.tsx - - - - jsx-evaluated-code - - begin - { - beginCaptures - - 0 - - name - punctuation.definition.brace.curly.start.tsx - - - end - } - endCaptures - - 0 - - name - punctuation.definition.brace.curly.end.tsx - - - name - meta.brace.curly.tsx - patterns - - - include - #expression - - - - jsx-string-double-quoted - - begin - " - beginCaptures - - 0 - - name - punctuation.definition.string.begin.tsx - - - end - " - endCaptures - - 0 - - name - punctuation.definition.string.end.tsx - - - name - string.quoted.double.tsx - patterns - - - include - #jsx-entities - - - - jsx-string-single-quoted - - begin - ' - beginCaptures - - 0 - - name - punctuation.definition.string.begin.tsx - - - end - ' - endCaptures - - 0 - - name - punctuation.definition.string.end.tsx - - - name - string.quoted.single.tsx - patterns - - - include - #jsx-entities - - - - jsx-tag-attribute-assignment - - match - =(?=\s*(?:'|"|{|/\*|//|\n)) - name - keyword.operator.assignment.tsx - - jsx-tag-attribute-name - - captures - - 1 - - name - entity.other.attribute-name.tsx - - - match - (?x) - \s* - ([_$a-zA-Z][-$\w]*) - (?=\s|=|/?>|/\*|//) - name - meta.tag.attribute-name.tsx - - jsx-tag-attributes - - patterns - - - include - #jsx-tag-attribute-name - - - include - #jsx-tag-attribute-assignment - - - include - #jsx-string-double-quoted - - - include - #jsx-string-single-quoted - - - include - #jsx-evaluated-code - - - - jsx-tag-attributes-illegal - - match - \S+ - name - invalid.illegal.attribute.tsx - - jsx-tag-close - - begin - (</)([_$a-zA-Z][-$\w.]*(?<!\.|-)) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.tsx - - 2 - - name - entity.name.tag.tsx - - - end - (>) - endCaptures - - 1 - - name - punctuation.definition.tag.end.tsx - - - name - tag.close.tsx - patterns - - - include - #comment - - - - jsx-tag-invalid - - match - <\s*> - name - invalid.illegal.tag.incomplete.tsx - - jsx-tag-open - - begin - (?x) - (<) - ([_$a-zA-Z][-$\w.]*(?<!\.|-)) - (?=\s+(?!\?)|/?>) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.tsx - - 2 - - name - entity.name.tag.tsx - - - end - (/?>) - endCaptures - - 1 - - name - punctuation.definition.tag.end.tsx - - - name - tag.open.tsx - patterns - - - include - #comment - - - include - #jsx-tag-attributes - - - include - #jsx-tag-attributes-illegal - - - - jsx-tag-without-attributes - - begin - (<)([_$a-zA-Z][-$\w.]*(?<!\.|-))(>) - beginCaptures - - 1 - - name - punctuation.definition.tag.begin.tsx - - 2 - - name - entity.name.tag.tsx - - 3 - - name - punctuation.definition.tag.end.tsx - - - end - (</)([_$a-zA-Z][-$\w.]*(?<!\.|-))(>) - endCaptures - - 1 - - name - punctuation.definition.tag.begin.tsx - - 2 - - name - entity.name.tag.tsx - - 3 - - name - punctuation.definition.tag.end.tsx - - - name - tag.without-attributes.tsx - patterns - - - include - #jsx-children - - - - literal - - name - literal.tsx - patterns - - - include - #numeric-literal - - - include - #boolean-literal - - - include - #null-literal - - - include - #undefined-literal - - - include - #array-literal - - - include - #this-literal - - - - logic-operator - - match - \!|&&|&|~|\^|\|\||\| - name - keyword.operator.arithmetic.tsx - - method-declaration - - begin - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - beginCaptures - - 1 - - name - storage.modifier.tsx - - 2 - - name - storage.modifier.tsx - - 3 - - name - storage.modifier.tsx - - 4 - - name - storage.type.property.tsx - - 5 - - name - keyword.operator.tsx - - 6 - - name - storage.type.tsx - - 7 - - name - entity.name.function.tsx - - 8 - - name - keyword.operator.tsx - - - end - (?=\}|;|,)|(?<=\}) - name - meta.method.declaration.tsx - patterns - - - include - #comment - - - include - #type-parameters - - - include - #function-type-parameters - - - include - #type-annotation - - - include - #method-overload-declaration - - - include - #decl-block - - - - method-overload-declaration - - captures - - 1 - - name - storage.modifier.tsx - - 2 - - name - storage.modifier.tsx - - 3 - - name - storage.modifier.tsx - - 4 - - name - storage.type.property.tsx - - 5 - - name - keyword.operator.tsx - - 6 - - name - storage.type.tsx - - 7 - - name - entity.name.function.tsx - - 8 - - name - keyword.operator.tsx - - - match - \b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<) - name - meta.method.overload.declaration.tsx - - new-expr - - begin - \b(new)\b - beginCaptures - - 1 - - name - keyword.others.tsx - - - end - (?=[(;]|$) - name - new.expr.tsx - patterns - - - include - #type - - - include - #comment - - - - null-literal - - match - \b(null)\b - name - constant.language.null.tsx - - numeric-literal - - match - \b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|(0(o|O)[0-7]+)|(0(b|B)(0|1)+)|(([0-9]+(\.[0-9]+)?))([eE]([+-]?)[0-9]+(\.[0-9]+)?)?)\b - name - constant.numeric.tsx - - object-body - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.tsx - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.tsx - - - name - meta.object.body.tsx - patterns - - - include - #string - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - include - #variable-initializer - - - include - #access-modifier - - - include - #static-modifier - - - include - #property-accessor - - - - object-declaration - - begin - \b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(class|interface)\b - beginCaptures - - 1 - - name - storage.type.tsx - - 2 - - name - storage.modifier.tsx - - 3 - - name - storage.type.tsx - - - end - (?<=\}) - endCaptures - - 1 - - name - brace.curly.tsx - - - name - meta.declaration.object.tsx - patterns - - - include - #comment - - - include - #object-heritage - - - include - #object-name - - - include - #type-parameters - - - include - #object-body - - - - object-heritage - - begin - (?:\b(extends|implements)\b) - beginCaptures - - 1 - - name - keyword.other.tsx - - - end - (?=\{) - endCaptures - - 1 - - name - brace.curly.tsx - - - name - meta.object.heritage.tsx - patterns - - - include - #comment - - - include - #object-heritage - - - include - #type-parameters - - - include - #object-heritage-type - - - - object-heritage-type - - captures - - 1 - - name - support.type.tsx - - - match - (?:\b([a-zA-Z_$][\w$]*)\b) - name - meta.object.heritage.parent.tsx - - object-member - - begin - [a-zA-Z_$][\w$]*\s*: - end - (?=,|\}) - name - meta.object.member.tsx - patterns - - - include - #expression - - - - object-name - - captures - - 0 - - name - entity.name.class.tsx - - - match - [a-zA-Z_$][\w$]* - name - meta.object.name.tsx - - parameter-name - - captures - - 1 - - name - storage.modifier.tsx - - 2 - - name - keyword.others.tsx - - 3 - - name - variable.parameter.tsx - - 4 - - name - keyword.others.tsx - - - match - (?:\s*\b(public|private|protected)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??) - name - parameter.name.tsx - - paren-expression - - begin - \( - beginCaptures - - 0 - - name - meta.brace.paren.tsx - - - end - \) - endCaptures - - 0 - - name - meta.brace.paren.tsx - - - patterns - - - include - #expression - - - - property-accessor - - match - \b(get|set)\b - name - storage.type.property.tsx - - qstring-double - - begin - " - end - "|(?:[^\\\n]$) - name - string.double.tsx - patterns - - - include - #string-character-escape - - - - qstring-single - - begin - ' - end - \'|(?:[^\\\n]$) - name - string.single.tsx - patterns - - - include - #string-character-escape - - - - regex - - begin - (?<=[=(:,\[]|^|return|&&|\|\||!)\s*(/)(?![/*+{}?]) - end - $|(/)[igm]* - name - string.regex.tsx - patterns - - - match - \\. - name - constant.character.escape.tsx - - - match - \[(\\\]|[^\]])*\] - name - constant.character.class.tsx - - - - relational-operator - - match - ===|!==|==|!=|<=|>=|<>|=|<|> - name - keyword.operator.comparison.tsx - - return-type - - begin - (?<=\))\s*: - end - (?=$)|(?=\{|;|//) - name - meta.return.type.tsx - patterns - - - include - #type - - - - static-modifier - - match - \b(static)\b - name - keyword.other.tsx - - storage-keyword - - match - \b(var|let|function|const|module|namespace|void|export)\b - name - storage.type.tsx - - string - - name - string.tsx - patterns - - - include - #qstring-single - - - include - #qstring-double - - - - string-character-escape - - match - \\(x\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$) - name - constant.character.escape - - switch-block - - begin - { - end - (?=\}) - name - switch-block.expr.tsx - patterns - - - include - #expression - - - - switch-expression - - begin - \b(switch)\b\s*\( - beginCaptures - - 1 - - name - keyword.control.tsx - - - end - \) - name - switch-expression.expr.tsx - patterns - - - include - #expression - - - - switch-statement - - begin - (?=\bswitch\b\s*\() - end - } - name - switch-statement.expr.tsx - patterns - - - include - #switch-expression - - - include - #switch-block - - - - template - - begin - ` - beginCaptures - - 0 - - name - string.template.tsx - - - end - ` - endCaptures - - 0 - - name - string.template.tsx - - - name - meta.template.tsx - patterns - - - include - #template-substitution-element - - - include - #template-string-contents - - - - template-string-contents - - begin - .*? - end - (?=(\$\{|`)) - name - string.template.tsx - patterns - - - include - #string-character-escape - - - - template-substitution-element - - begin - \$\{ - beginCaptures - - 0 - - name - keyword.others.tsx - - - end - \} - endCaptures - - 0 - - name - keyword.others.tsx - - - name - template.element.tsx - patterns - - - include - #expression - - - - ternary-expression - - begin - (?=\?) - end - (?=$|[;,]) - patterns - - - include - #ternary-operator - - - include - #expression-type - - - - ternary-operator - - begin - (\?) - end - (:) - patterns - - - include - #expression-type - - - - this-literal - - match - \b(this)\b - name - constant.language.this.tsx - - type - - name - meta.type.tsx - patterns - - - include - #type-primitive - - - include - #type-parameters - - - include - #type-tuple - - - include - #type-object - - - include - #type-operator - - - include - #type-paren-or-function-type-parameters - - - include - #type-function-return-type - - - include - #type-name - - - - type-annotation - - begin - : - end - (?=$|[,);\}\]]|//)|(?==[^>])|(?<=[\}>\]\)]|[a-zA-Z_$])\s*(?=\{) - name - meta.type.annotation.tsx - patterns - - - include - #expression-operator - - - include - #type - - - include - #string - - - include - #comment - - - - type-declaration - - begin - \b(type)\b\s+([a-zA-Z_$][\w$]*)\s* - beginCaptures - - 1 - - name - keyword.other.tsx - - 2 - - name - entity.name.class.tsx - - - end - (?=$|[,);>]|var|type|function|class|interface) - name - meta.type.declaration.tsx - patterns - - - include - #type-parameters - - - include - #type - - - match - =\s* - name - keyword.operator.comparison.tsx - - - - type-function-return-type - - begin - => - beginCaptures - - 0 - - name - keyword.operator.tsx - - - end - (?=\s*[,\)\{=;>]|//|$) - name - meta.type.function.return.tsx - patterns - - - include - #type - - - - type-name - - captures - - 1 - - name - entity.name.type.tsx - - - match - [a-zA-Z_$][.\w$]* - name - meta.type.name.tsx - - type-object - - begin - \{ - beginCaptures - - 0 - - name - meta.brace.curly.tsx - - - end - \} - endCaptures - - 0 - - name - meta.brace.curly.tsx - - - name - meta.object.type.tsx - patterns - - - include - #comment - - - include - #field-declaration - - - include - #method-declaration - - - include - #indexer-declaration - - - include - #type-annotation - - - - type-operator - - match - [.|] - name - keyword.operator.type.tsx - - type-parameters - - begin - ([a-zA-Z_$][\w$]*)?(<) - beginCaptures - - 1 - - name - entity.name.type.tsx - - 2 - - name - meta.brace.angle.tsx - - - end - (?=$)|(>) - endCaptures - - 2 - - name - meta.brace.angle.tsx - - - name - meta.type.parameters.tsx - patterns - - - match - \b(extends)\b - name - keyword.other.tsx - - - include - #comment - - - include - #type - - - - type-paren-or-function-type-parameters - - begin - (?:\b(new)\b)?\s*\( - beginCaptures - - 1 - - name - keyword.control.tsx - - - end - \) - name - meta.type.paren.cover.tsx - patterns - - - include - #comment - - - include - #type - - - include - #function-type-parameters - - - - type-primitive - - captures - - 1 - - name - support.type.tsx - - - match - \b(string|number|boolean|symbol|any|void)\b - name - meta.type.primitive.tsx - - type-tuple - - begin - \[ - beginCaptures - - 0 - - name - meta.brace.square.tsx - - - end - \] - endCaptures - - 0 - - name - meta.brace.square.tsx - - - name - meta.type.tuple.tsx - patterns - - - include - #type - - - include - #comment - - - - undefined-literal - - match - \b(undefined)\b - name - constant.language.tsx - - var-expr - - begin - (?<!\()\s*\b(var|let|const(?!\s+enum))\b - beginCaptures - - 1 - - name - storage.type.tsx - - - end - (?=$|;) - name - meta.var.expr.tsx - patterns - - - include - #var-single-variable - - - include - #comment - - - - var-single-variable - - begin - \b([a-zA-Z_$][\w$]*)\s*(=?) - beginCaptures - - 1 - - name - variable.tsx - - - end - (?=$|[;,]) - name - meta.var-single-variable.expr.tsx - patterns - - - include - #ternary-expression - - - include - #type-annotation - - - include - #string - - - include - #comment - - - include - #expression - - - - variable-initializer - - begin - (=) - beginCaptures - - 1 - - name - keyword.operator.comparison.tsx - - - end - (?=$|[,);=]) - patterns - - - include - #expression - - - - - scopeName - source.tsx - uuid - 805375ec-d614-41f5-8993-5843fe63ea82 - - diff --git a/extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json b/extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json new file mode 100644 index 00000000000..8fa443f81a0 --- /dev/null +++ b/extensions/typescript/syntaxes/TypeScriptReact.tmLanguage.json @@ -0,0 +1,1525 @@ +{ + "fileTypes": [ + "tsx" + ], + "name": "TypeScriptReact", + "patterns": [ + { + "include": "#expression" + } + ], + "repository": { + "access-modifier": { + "match": "\\b(public|protected|private)\\b", + "name": "storage.modifier.tsx" + }, + "arithmetic-operator": { + "match": "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%", + "name": "keyword.operator.arithmetic.tsx" + }, + "array-literal": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.tsx" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.tsx" + } + }, + "name": "meta.array.literal.tsx", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "assignment-operator": { + "match": "<<=|>>>=|>>=|\\*=|(?", + "name": "keyword.operator.tsx" + }, + "import-operator": { + "match": "\\b(import|from)\\b", + "name": "keyword.control.import.include.tsx" + }, + "indexer-declaration": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.tsx" + } + }, + "end": "(\\])\\s*(\\?\\s*)?|$", + "endCaptures": { + "1": { + "name": "meta.brace.square.tsx" + }, + "2": { + "name": "keyword.others.tsx" + } + }, + "name": "meta.indexer.declaration.tsx", + "patterns": [ + { + "include": "#type-annotation" + }, + { + "include": "#indexer-parameter" + }, + { + "include": "#expression" + } + ] + }, + "indexer-parameter": { + "captures": { + "1": { + "name": "variable.parameter.tsx" + } + }, + "match": "([a-zA-Z_$][\\w$]*)(?=\\:)", + "name": "meta.indexer.parameter.tsx" + }, + "jsx": { + "name": "meta.jsx.tsx", + "patterns": [ + { + "include": "#jsx-tag-without-attributes" + }, + { + "include": "#jsx-tag-open" + }, + { + "include": "#jsx-tag-close" + }, + { + "include": "#jsx-tag-invalid" + }, + { + "begin": "(?<=(?:'|\"|})>)", + "end": "(?=|/\\*|//)", + "name": "meta.tag.attribute-name.tsx" + }, + "jsx-tag-attributes": { + "patterns": [ + { + "include": "#jsx-tag-attribute-name" + }, + { + "include": "#jsx-tag-attribute-assignment" + }, + { + "include": "#jsx-string-double-quoted" + }, + { + "include": "#jsx-string-single-quoted" + }, + { + "include": "#jsx-evaluated-code" + } + ] + }, + "jsx-tag-attributes-illegal": { + "match": "\\S+", + "name": "invalid.illegal.attribute.tsx" + }, + "jsx-tag-close": { + "begin": "()", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.end.tsx" + } + }, + "name": "tag.close.tsx", + "patterns": [ + { + "include": "#comment" + } + ] + }, + "jsx-tag-invalid": { + "match": "<\\s*>", + "name": "invalid.illegal.tag.incomplete.tsx" + }, + "jsx-tag-open": { + "begin": "(?x)\n (<)\n ([_$a-zA-Z][-$\\w.]*(?)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.tsx" + }, + "2": { + "name": "entity.name.tag.tsx" + } + }, + "end": "(/?>)", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.end.tsx" + } + }, + "name": "tag.open.tsx", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#jsx-tag-attributes" + }, + { + "include": "#jsx-tag-attributes-illegal" + } + ] + }, + "jsx-tag-without-attributes": { + "begin": "(<)([_$a-zA-Z][-$\\w.]*(?)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.tsx" + }, + "2": { + "name": "entity.name.tag.tsx" + }, + "3": { + "name": "punctuation.definition.tag.end.tsx" + } + }, + "end": "()", + "endCaptures": { + "1": { + "name": "punctuation.definition.tag.begin.tsx" + }, + "2": { + "name": "entity.name.tag.tsx" + }, + "3": { + "name": "punctuation.definition.tag.end.tsx" + } + }, + "name": "tag.without-attributes.tsx", + "patterns": [ + { + "include": "#jsx-children" + } + ] + }, + "literal": { + "name": "literal.tsx", + "patterns": [ + { + "include": "#numeric-literal" + }, + { + "include": "#boolean-literal" + }, + { + "include": "#null-literal" + }, + { + "include": "#undefined-literal" + }, + { + "include": "#array-literal" + }, + { + "include": "#this-literal" + } + ] + }, + "logic-operator": { + "match": "\\!|&&|&|~|\\^|\\|\\||\\|", + "name": "keyword.operator.arithmetic.tsx" + }, + "method-declaration": { + "begin": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:\\b(constructor)\\b)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "beginCaptures": { + "1": { + "name": "storage.modifier.tsx" + }, + "2": { + "name": "storage.modifier.tsx" + }, + "3": { + "name": "storage.modifier.tsx" + }, + "4": { + "name": "storage.type.property.tsx" + }, + "5": { + "name": "keyword.operator.tsx" + }, + "6": { + "name": "storage.type.tsx" + }, + "7": { + "name": "entity.name.function.tsx" + }, + "8": { + "name": "keyword.operator.tsx" + } + }, + "end": "(?=\\}|;|,)|(?<=\\})", + "name": "meta.method.declaration.tsx", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type-parameters" + }, + { + "include": "#function-type-parameters" + }, + { + "include": "#type-annotation" + }, + { + "include": "#method-overload-declaration" + }, + { + "include": "#decl-block" + } + ] + }, + "method-overload-declaration": { + "captures": { + "1": { + "name": "storage.modifier.tsx" + }, + "2": { + "name": "storage.modifier.tsx" + }, + "3": { + "name": "storage.modifier.tsx" + }, + "4": { + "name": "storage.type.property.tsx" + }, + "5": { + "name": "keyword.operator.tsx" + }, + "6": { + "name": "storage.type.tsx" + }, + "7": { + "name": "entity.name.function.tsx" + }, + "8": { + "name": "keyword.operator.tsx" + } + }, + "match": "\\b(?:(abstract)\\s+)?\\b(?:(public|private|protected)\\s+)?\\b(?:(async)\\s+)?(?:(get|set)\\s+)?(?:(new)|(?:\\b(constructor)\\b)|(?:([a-zA-Z_$][\\.\\w$]*)\\s*(\\??)))?\\s*(?=\\(|\\<)", + "name": "meta.method.overload.declaration.tsx" + }, + "new-expr": { + "begin": "\\b(new)\\b", + "beginCaptures": { + "1": { + "name": "keyword.others.tsx" + } + }, + "end": "(?=[(;]|$)", + "name": "new.expr.tsx", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "null-literal": { + "match": "\\b(null)\\b", + "name": "constant.language.null.tsx" + }, + "numeric-literal": { + "match": "\\b(?<=[^$])((0(x|X)[0-9a-fA-F]+)|(0(o|O)[0-7]+)|(0(b|B)(0|1)+)|(([0-9]+(\\.[0-9]+)?))([eE]([+-]?)[0-9]+(\\.[0-9]+)?)?)\\b", + "name": "constant.numeric.tsx" + }, + "object-body": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.tsx" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.tsx" + } + }, + "name": "meta.object.body.tsx", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + }, + { + "include": "#variable-initializer" + }, + { + "include": "#access-modifier" + }, + { + "include": "#static-modifier" + }, + { + "include": "#property-accessor" + } + ] + }, + "object-declaration": { + "begin": "\\b(?:(export)\\s+)?\\b(?:(abstract)\\s+)?\\b(?=|<>|=|<|>", + "name": "keyword.operator.comparison.tsx" + }, + "return-type": { + "begin": "(?<=\\))\\s*:", + "end": "(?=$)|(?=\\{|;|//)", + "name": "meta.return.type.tsx", + "patterns": [ + { + "include": "#type" + } + ] + }, + "static-modifier": { + "match": "\\b(static)\\b", + "name": "keyword.other.tsx" + }, + "storage-keyword": { + "match": "\\b(var|let|function|const|module|namespace|void|export)\\b", + "name": "storage.type.tsx" + }, + "string": { + "name": "string.tsx", + "patterns": [ + { + "include": "#qstring-single" + }, + { + "include": "#qstring-double" + } + ] + }, + "string-character-escape": { + "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)", + "name": "constant.character.escape" + }, + "switch-block": { + "begin": "{", + "end": "(?=\\})", + "name": "switch-block.expr.tsx", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-expression": { + "begin": "\\b(switch)\\b\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.control.tsx" + } + }, + "end": "\\)", + "name": "switch-expression.expr.tsx", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "switch-statement": { + "begin": "(?=\\bswitch\\b\\s*\\()", + "end": "}", + "name": "switch-statement.expr.tsx", + "patterns": [ + { + "include": "#switch-expression" + }, + { + "include": "#switch-block" + } + ] + }, + "template": { + "begin": "`", + "beginCaptures": { + "0": { + "name": "string.template.tsx" + } + }, + "end": "`", + "endCaptures": { + "0": { + "name": "string.template.tsx" + } + }, + "name": "meta.template.tsx", + "patterns": [ + { + "include": "#template-substitution-element" + }, + { + "include": "#template-string-contents" + } + ] + }, + "template-string-contents": { + "begin": ".*?", + "end": "(?=(\\$\\{|`))", + "name": "string.template.tsx", + "patterns": [ + { + "include": "#string-character-escape" + } + ] + }, + "template-substitution-element": { + "begin": "\\$\\{", + "beginCaptures": { + "0": { + "name": "keyword.others.tsx" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "keyword.others.tsx" + } + }, + "name": "template.element.tsx", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "ternary-expression": { + "begin": "(?=\\?)", + "end": "(?=$|[;,])", + "patterns": [ + { + "include": "#ternary-operator" + }, + { + "include": "#expression-type" + } + ] + }, + "ternary-operator": { + "begin": "(\\?)", + "end": "(:)", + "patterns": [ + { + "include": "#expression-type" + } + ] + }, + "this-literal": { + "match": "\\b(this)\\b", + "name": "constant.language.this.tsx" + }, + "type": { + "name": "meta.type.tsx", + "patterns": [ + { + "include": "#type-primitive" + }, + { + "include": "#type-parameters" + }, + { + "include": "#type-tuple" + }, + { + "include": "#type-object" + }, + { + "include": "#type-operator" + }, + { + "include": "#type-paren-or-function-type-parameters" + }, + { + "include": "#type-function-return-type" + }, + { + "include": "#type-name" + } + ] + }, + "type-annotation": { + "begin": ":", + "end": "(?=$|[,);\\}\\]]|//)|(?==[^>])|(?<=[\\}>\\]\\)]|[a-zA-Z_$])\\s*(?=\\{)", + "name": "meta.type.annotation.tsx", + "patterns": [ + { + "include": "#expression-operator" + }, + { + "include": "#type" + }, + { + "include": "#string" + }, + { + "include": "#comment" + } + ] + }, + "type-declaration": { + "begin": "\\b(type)\\b\\s+([a-zA-Z_$][\\w$]*)\\s*", + "beginCaptures": { + "1": { + "name": "keyword.other.tsx" + }, + "2": { + "name": "entity.name.class.tsx" + } + }, + "end": "(?=$|[,);>]|var|type|function|class|interface)", + "name": "meta.type.declaration.tsx", + "patterns": [ + { + "include": "#type-parameters" + }, + { + "include": "#type" + }, + { + "match": "=\\s*", + "name": "keyword.operator.comparison.tsx" + } + ] + }, + "type-function-return-type": { + "begin": "=>", + "beginCaptures": { + "0": { + "name": "keyword.operator.tsx" + } + }, + "end": "(?=\\s*[,\\)\\{=;>]|//|$)", + "name": "meta.type.function.return.tsx", + "patterns": [ + { + "include": "#type" + } + ] + }, + "type-name": { + "captures": { + "1": { + "name": "entity.name.type.tsx" + } + }, + "match": "[a-zA-Z_$][.\\w$]*", + "name": "meta.type.name.tsx" + }, + "type-object": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.tsx" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "meta.brace.curly.tsx" + } + }, + "name": "meta.object.type.tsx", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#field-declaration" + }, + { + "include": "#method-declaration" + }, + { + "include": "#indexer-declaration" + }, + { + "include": "#type-annotation" + } + ] + }, + "type-operator": { + "match": "[.|]", + "name": "keyword.operator.type.tsx" + }, + "type-parameters": { + "begin": "([a-zA-Z_$][\\w$]*)?(<)", + "beginCaptures": { + "1": { + "name": "entity.name.type.tsx" + }, + "2": { + "name": "meta.brace.angle.tsx" + } + }, + "end": "(?=$)|(>)", + "endCaptures": { + "2": { + "name": "meta.brace.angle.tsx" + } + }, + "name": "meta.type.parameters.tsx", + "patterns": [ + { + "match": "\\b(extends)\\b", + "name": "keyword.other.tsx" + }, + { + "include": "#comment" + }, + { + "include": "#type" + } + ] + }, + "type-paren-or-function-type-parameters": { + "begin": "(?:\\b(new)\\b)?\\s*\\(", + "beginCaptures": { + "1": { + "name": "keyword.control.tsx" + } + }, + "end": "\\)", + "name": "meta.type.paren.cover.tsx", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type" + }, + { + "include": "#function-type-parameters" + } + ] + }, + "type-primitive": { + "captures": { + "1": { + "name": "support.type.tsx" + } + }, + "match": "\\b(string|number|boolean|symbol|any|void)\\b", + "name": "meta.type.primitive.tsx" + }, + "type-tuple": { + "begin": "\\[", + "beginCaptures": { + "0": { + "name": "meta.brace.square.tsx" + } + }, + "end": "\\]", + "endCaptures": { + "0": { + "name": "meta.brace.square.tsx" + } + }, + "name": "meta.type.tuple.tsx", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, + "undefined-literal": { + "match": "\\b(undefined)\\b", + "name": "constant.language.tsx" + }, + "var-expr": { + "begin": "(?