Skip to content

Commit 1471307

Browse files
committed
[typescript] update grammar
1 parent 1aaf1a8 commit 1471307

9 files changed

Lines changed: 1023 additions & 465 deletions

File tree

extensions/javascript/syntaxes/JavaScript.tmLanguage.json

Lines changed: 250 additions & 139 deletions
Large diffs are not rendered by default.

extensions/javascript/test/colorize-results/test_jsx.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@
17721772
},
17731773
{
17741774
"c": " ",
1775-
"t": "attribute-name.block.children.expr.function.js.jsx.member.meta.object.objectliteral.tag.tsx.var.without-attributes",
1775+
"t": "block.children.expr.function.js.jsx.member.meta.object.objectliteral.tag.tsx.var.without-attributes",
17761776
"r": {
17771777
"dark_plus": ".vs-dark .token rgb(212, 212, 212)",
17781778
"light_plus": ".vs .token rgb(0, 0, 0)",
@@ -1805,7 +1805,7 @@
18051805
},
18061806
{
18071807
"c": "\"",
1808-
"t": "begin.block.children.definition.double.expr.function.js.jsx.jsxAttributeValue.member.meta.object.objectliteral.punctuation.quoted.string.tag.tsx.var.without-attributes",
1808+
"t": "begin.block.children.definition.double.expr.function.js.jsx.member.meta.object.objectliteral.punctuation.quoted.string.tag.tsx.var.without-attributes",
18091809
"r": {
18101810
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
18111811
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",
@@ -1816,7 +1816,7 @@
18161816
},
18171817
{
18181818
"c": "\"",
1819-
"t": "block.children.definition.double.end.expr.function.js.jsx.jsxAttributeValue.member.meta.object.objectliteral.punctuation.quoted.string.tag.tsx.var.without-attributes",
1819+
"t": "block.children.definition.double.end.expr.function.js.jsx.member.meta.object.objectliteral.punctuation.quoted.string.tag.tsx.var.without-attributes",
18201820
"r": {
18211821
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
18221822
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",
@@ -1827,7 +1827,7 @@
18271827
},
18281828
{
18291829
"c": " ",
1830-
"t": "attribute-name.block.children.expr.function.js.jsx.member.meta.object.objectliteral.tag.tsx.var.without-attributes",
1830+
"t": "block.children.expr.function.js.jsx.member.meta.object.objectliteral.tag.tsx.var.without-attributes",
18311831
"r": {
18321832
"dark_plus": ".vs-dark .token rgb(212, 212, 212)",
18331833
"light_plus": ".vs .token rgb(0, 0, 0)",
@@ -2168,7 +2168,7 @@
21682168
},
21692169
{
21702170
"c": " ",
2171-
"t": "attribute-name.js.meta.tag",
2171+
"t": "js.meta.tag",
21722172
"r": {
21732173
"dark_plus": ".vs-dark .token rgb(212, 212, 212)",
21742174
"light_plus": ".vs .token rgb(0, 0, 0)",
@@ -2201,7 +2201,7 @@
22012201
},
22022202
{
22032203
"c": "\"",
2204-
"t": "begin.definition.double.js.jsxAttributeValue.meta.punctuation.quoted.string.tag",
2204+
"t": "begin.definition.double.js.meta.punctuation.quoted.string.tag",
22052205
"r": {
22062206
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
22072207
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",
@@ -2212,7 +2212,7 @@
22122212
},
22132213
{
22142214
"c": "World",
2215-
"t": "double.js.jsxAttributeValue.meta.quoted.string.tag",
2215+
"t": "double.js.meta.quoted.string.tag",
22162216
"r": {
22172217
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.string.tag rgb(206, 145, 120)",
22182218
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.string rgb(163, 21, 21)",
@@ -2223,7 +2223,7 @@
22232223
},
22242224
{
22252225
"c": "\"",
2226-
"t": "definition.double.end.js.jsxAttributeValue.meta.punctuation.quoted.string.tag",
2226+
"t": "definition.double.end.js.meta.punctuation.quoted.string.tag",
22272227
"r": {
22282228
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
22292229
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",
@@ -2234,7 +2234,7 @@
22342234
},
22352235
{
22362236
"c": " ",
2237-
"t": "attribute-name.js.meta.tag",
2237+
"t": "js.meta.tag",
22382238
"r": {
22392239
"dark_plus": ".vs-dark .token rgb(212, 212, 212)",
22402240
"light_plus": ".vs .token rgb(0, 0, 0)",
@@ -2267,7 +2267,7 @@
22672267
},
22682268
{
22692269
"c": "\"",
2270-
"t": "begin.definition.double.js.jsxAttributeValue.meta.punctuation.quoted.string.tag",
2270+
"t": "begin.definition.double.js.meta.punctuation.quoted.string.tag",
22712271
"r": {
22722272
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
22732273
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",
@@ -2278,7 +2278,7 @@
22782278
},
22792279
{
22802280
"c": "Mars",
2281-
"t": "double.js.jsxAttributeValue.meta.quoted.string.tag",
2281+
"t": "double.js.meta.quoted.string.tag",
22822282
"r": {
22832283
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.string.tag rgb(206, 145, 120)",
22842284
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.string rgb(163, 21, 21)",
@@ -2289,7 +2289,7 @@
22892289
},
22902290
{
22912291
"c": "\"",
2292-
"t": "definition.double.end.js.jsxAttributeValue.meta.punctuation.quoted.string.tag",
2292+
"t": "definition.double.end.js.meta.punctuation.quoted.string.tag",
22932293
"r": {
22942294
"dark_plus": ".vs-dark.vscode-theme-defaults-themes-dark_plus-json .token.punctuation.definition.tag rgb(128, 128, 128)",
22952295
"light_plus": ".vs.vscode-theme-defaults-themes-light_plus-json .token.punctuation.definition.tag rgb(128, 0, 0)",

extensions/typescript/build/update-grammars.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function adaptToJavaScript(grammar) {
1414
var fixScopeNames = function(rule) {
1515
if (typeof rule.name === 'string') {
1616
rule.name = rule.name.replace(/\.tsx/g, '.js');
17+
rule.name = rule.name.replace(/^\S+ (\S+)$/g, '$1');
1718
}
1819
for (var property in rule) {
1920
var value = rule[property];
@@ -27,14 +28,30 @@ function adaptToJavaScript(grammar) {
2728
for (var key in repository) {
2829
fixScopeNames(repository[key]);
2930
}
30-
// disable type parameters
31-
if (repository['type-parameters']) {
32-
repository['type-parameters']['begin'] = 'DO_NOT_MATCH';
31+
}
32+
33+
function fixSpacesInNames(grammar) {
34+
var fixScopeNames = function(rule) {
35+
if (typeof rule.name === 'string') {
36+
rule.name = rule.name.replace(/^\S+ (\S+)$/g, '$1');
37+
}
38+
for (var property in rule) {
39+
var value = rule[property];
40+
if (typeof value === 'object') {
41+
fixScopeNames(value);
42+
}
43+
}
44+
};
45+
46+
var repository = grammar.repository;
47+
for (var key in repository) {
48+
fixScopeNames(repository[key]);
3349
}
3450
}
51+
3552
var tsGrammarRepo = 'Microsoft/TypeScript-TmLanguage';
36-
updateGrammar.update(tsGrammarRepo, 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage.json');
37-
updateGrammar.update(tsGrammarRepo, 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage.json');
53+
updateGrammar.update(tsGrammarRepo, 'TypeScript.tmLanguage', './syntaxes/TypeScript.tmLanguage.json', fixSpacesInNames);
54+
updateGrammar.update(tsGrammarRepo, 'TypeScriptReact.tmLanguage', './syntaxes/TypeScriptReact.tmLanguage.json', fixSpacesInNames);
3855
updateGrammar.update(tsGrammarRepo, 'TypeScriptReact.tmLanguage', '../javascript/syntaxes/JavaScript.tmLanguage.json', adaptToJavaScript);
3956

4057

0 commit comments

Comments
 (0)