From 3b6878818746c4dead5d1bb77f09d3158e9c0227 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Thu, 14 Jan 2021 16:37:31 -0500 Subject: [PATCH] [JavaScript] [TypeScript] Use keyword.declaration for class, interface, and namespace. (#2645) --- JavaScript/JavaScript.sublime-syntax | 2 +- JavaScript/TypeScript.sublime-syntax | 4 +- JavaScript/tests/.DS_Store | Bin 0 -> 6148 bytes JavaScript/tests/syntax_test_js.js | 556 ++++++++++++++++++++- JavaScript/tests/syntax_test_js_class.js | 12 +- JavaScript/tests/syntax_test_typescript.ts | 10 +- 6 files changed, 568 insertions(+), 16 deletions(-) create mode 100644 JavaScript/tests/.DS_Store diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 0067101b493..e996fad8cec 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1295,7 +1295,7 @@ contexts: class: - match: class{{identifier_break}} - scope: storage.type.class.js + scope: keyword.declaration.class.js set: - class-meta - class-body diff --git a/JavaScript/TypeScript.sublime-syntax b/JavaScript/TypeScript.sublime-syntax index d0ac4e92657..9542ce420e8 100644 --- a/JavaScript/TypeScript.sublime-syntax +++ b/JavaScript/TypeScript.sublime-syntax @@ -186,7 +186,7 @@ contexts: ts-interface-declaration: - match: interface{{identifier_break}} - scope: storage.type.js + scope: keyword.declaration.js set: - ts-interface-meta - ts-type-body @@ -330,7 +330,7 @@ contexts: ts-namespace-declaration: - match: namespace{{identifier_break}} - scope: storage.type.js + scope: keyword.declaration.js set: - ts-namespace-meta - block diff --git a/JavaScript/tests/.DS_Store b/JavaScript/tests/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 qux) { +// <- meta.conditional.js keyword.control.conditional.if +// ^^^^^^^^^^^^^^^ meta.conditional +// ^^^^^^^^ constant.language.infinity + a; +// ^ meta.conditional meta.block +} +// <- meta.conditional meta.block + +if (foo bar) + baz = "test" + +if(false){}/**/ +// ^ - meta.conditional + +do { +// <- meta.do-while keyword.control.loop.do-while +// ^ meta.block + qux += 1 +// ^^^^^^^^ meta.do-while meta.block +} while(qux < 20); +// <- meta.block +// ^^^^^^^^^^^^^^ meta.do-while - meta.block +// ^^^^ keyword.control.loop.while +// ^^^^^^^^ meta.group + +do // Incomplete statement + 42; +// ^^ constant.numeric - meta.do-while + +do {} while (false)/**/ +// <- meta.do-while keyword.control.loop.do-while +//^^^^^^^^^^^^^^^^^ meta.do-while.js +// ^^ - meta.do-while +// ^^^^^ keyword.control.loop.while.js + +for (var i = 0; i < 10; i++) { +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.for +// ^^^^^^^^^^^^^^^^^^^^^^ meta.group +// ^^^ storage.type.js +// ^ meta.block + i += 1; +// ^^^^^^^ meta.for meta.block +} +// <- meta.block + + for (; x in list;) {} +// ^^^^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^^^^ meta.group +// ^ punctuation.separator.expression +// ^^ keyword.operator +// ^ punctuation.separator.expression + + for (a[x in list];;) {} +// ^^^^^^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^^^^^^ meta.group +// ^^^^^^^^^^^ meta.brackets +// ^^ keyword.operator +// ^ punctuation.separator.expression +// ^ punctuation.separator.expression + + for (;function () {}/a/g;) {} +// ^ keyword.operator + + for (const x in list) {} +// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^^^^^^^ meta.group +// ^^^^^ storage.type +// ^^ keyword.operator.word + + for (const x of list) {} +// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^^^^^^^ meta.group +// ^^^^^ storage.type +// ^^ keyword.operator.word + + for (x in list) {} +// ^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^ meta.group +// ^^ keyword.operator.word + + for (x of list) {} +// ^^^^^^^^^^^^^^^^^^ meta.for +// ^^^ keyword.control.loop.for +// ^^^^^^^^^^^ meta.group +// ^^ keyword.operator.word + + for await (const x of list) {} +// ^^^ keyword.control.loop.for +// ^^^^^ keyword.control.flow.await + +for + 42; +// ^^ constant.numeric - meta.for + +for(;;){}/**/ +// ^ - meta.for + +while (true) +// ^^^^^^^^^ meta.while +// ^^^^ meta.group +{ +// <- meta.block + x = yield; +// ^^^^^ keyword.control.flow.yield + + x = yield * 42; +// ^^^^^ keyword.control.flow.yield +// ^ keyword.generator.asterisk + + x = yield + function f() {} + []; +// ^^ meta.sequence - meta.brackets + + + x = yield* + function f() {} + []; +// ^^ meta.brackets - meta.sequence + + y = await 42; +// ^^^^^ keyword.control.flow.await + + y = yield await 42; +// ^^^^^ keyword.control.flow.yield +// ^^^^^ keyword.control.flow.await + + yield (parenthesized_expression); +// ^^^^^ keyword.control.flow.yield + + yield `template`; +// ^^^^^ keyword.control.flow.yield + + break; +// ^^^^^ keyword.control.flow.break + + break foo; +// ^^^^^ keyword.control.flow.break +// ^^^ variable.label + + break + foo; +// ^^^ variable.other.readwrite - variable.label + + break/**/foo; +// ^^^ variable.label - variable.other.readwrite + + break/* + */foo; +// ^^^ variable.other.readwrite - variable.label + + break function; +// ^^^^^^^^ invalid.illegal.identifier variable.label + + continue; +// ^^^^^^^^ keyword.control.flow.continue + + continue foo; +// ^^^^^^^^ keyword.control.flow.continue +// ^^^ variable.label + + continue + foo; +// ^^^ variable.other.readwrite - variable.label + + continue/**/foo; +// ^^^ variable.label - variable.other.readwrite + + continue/* + */ foo; +// ^^^ variable.other.readwrite - variable.label + + goto; +// ^^^^ variable.other.readwrite - keyword +} +// <- meta.block + +while // Incomplete statement + 42; +// ^^ constant.numeric - meta.while + +while(false){}/**/ +// ^ - meta.while + +with (undefined) { +// <- keyword.control.import.with +//^^^^^^^^^^ meta.with +// ^^^^^^^^^ constant.language.undefined + return; +// ^^^^^^ meta.with.js meta.block.js keyword.control.flow.return +} + +with // Incomplete statement + 42; +// ^^ constant.numeric - meta.while + +with(false){}/**/ +// ^ - meta.with + +switch ($foo) { +// <- meta.switch.js keyword.control.conditional.switch +// ^^^^^^^^^^^^ meta.switch +//^^^^ keyword.control.conditional.switch +// ^^^^ meta.group +// ^ meta.block punctuation.section.block.begin + case foo: + // ^ meta.switch meta.block keyword.control.conditional.case + // ^ - punctuation.separator.key-value + qux = 1; + break; + // ^ keyword.control.flow.break + case "baz": + // ^ keyword.control.conditional.case + // ^ - punctuation.separator.key-value string + qux = 2; + break; + // ^ keyword.control.flow.break + default: + // ^ meta.switch meta.block keyword.control.conditional.default + // ^ - punctuation.separator.key-value + qux = 3; + + case$ +// ^^^^^ - keyword + ; + + default$ +// ^^^^^^^^ - keyword + ; + + case 0: {} + case 1: +// ^^^^ keyword.control.conditional.case +} +// <- meta.block punctuation.section.block.end + +try { +// <- meta.try keyword.control.exception.try +// ^^ meta.try +// ^ meta.block + foobar = qux.bar(); +// ^^^^^^^^^^^^^^^^^^^ meta.try meta.block +} catch (e) { +// <- meta.block +//^^^^^^^^^^^^ meta.catch +//^^^^^ keyword.control.exception.catch +// ^ meta.group +// ^ meta.block + foobar = 0 +// ^^^^^^^^^^ meta.catch meta.block +} finally { +// <- meta.block +//^^^^^^^^^^ meta.finally +//^^^^^^^ keyword.control.exception.finally +// ^ meta.block + foobar += 1 +// ^^^^^^^^^^^ meta.finally meta.block +} +// <- meta.block + +switch // Incomplete statement + 42; +// ^^ constant.numeric - meta.switch + +switch(x){}/**/ +// ^^ - meta.switch + +try{}/**/ +// ^ - meta.try +catch{}/**/ +// ^ - meta.catch +finally{}/**/ +// ^ - meta.finally + +class MyClass extends TheirClass { +// <- keyword.declaration.class +// ^^^^^^^ entity.name.class +// ^^^^^^^ storage.modifier.extends +// ^^^^^^^^^^ entity.other.inherited-class +// ^ meta.block punctuation.section.block.begin + + x = 42; +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + 'y' = 42; +// ^^^ meta.string string.quoted.single +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + "z" = 42; +// ^^^ meta.string string.quoted.double +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + [w] = 42; +// ^ punctuation.section.brackets.begin +// ^ variable.other.readwrite +// ^ punctuation.section.brackets.end +// ^ keyword.operator.assignment +// ^^ constant.numeric + + #v = 42; +// ^ punctuation.definition.variable +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + f = a => b; +// ^ entity.name.function variable.other.readwrite +// ^^^^^^ meta.function +// ^ variable.parameter.function + + g = function() {}; +// ^ entity.name.function variable.other.readwrite +// ^^^^^^^^^^^^^ meta.function + + #h = function() {}; +// ^ punctuation.definition.variable +// ^ entity.name.function variable.other.readwrite +// ^^^^^^^^^^^^^ meta.function + + static x = 42; +// ^^^^^^ storage.modifier.js +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + static 'y' = 42; +// ^^^^^^ storage.modifier.js +// ^^^ meta.string string.quoted.single +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + static "z" = 42; +// ^^^^^^ storage.modifier.js +// ^^^ meta.string string.quoted.double +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + static [w] = 42; +// ^^^^^^ storage.modifier.js +// ^ punctuation.section.brackets.begin +// ^ variable.other.readwrite +// ^ punctuation.section.brackets.end +// ^ keyword.operator.assignment +// ^^ constant.numeric + + static #v = 42; +// ^ punctuation.definition.variable +// ^ variable.other.readwrite +// ^ keyword.operator.assignment +// ^^ constant.numeric + + static f = a => b; +// ^ entity.name.function variable.other.readwrite +// ^^^^^^ meta.function +// ^ variable.parameter.function + + static g = function() {}; +// ^ entity.name.function variable.other.readwrite +// ^^^^^^^^^^^^^ meta.function + + foo // You thought I was a field... + () { return '...but was a method all along!'; } +// ^^ meta.class meta.block meta.function + + someMethod() { + return #e * 2; +// ^ punctuation.definition.variable +// ^ variable.other.readwrite +// ^ keyword.operator.arithmetic + + for (const param of this.#data.get('value')) {} +// ^ punctuation.definition.variable +// ^^^^ meta.property.object + } + + #privateMethod() {} +// ^^^^^^^^^^^^^^^^^^^ meta.function +// ^^^^^^^^^^^^^^ entity.name.function.js +// ^ punctuation.definition.js + + constructor(el) +// ^^^^^^^^^^^^^^^ meta.function + // ^ entity.name.function.constructor + { +// ^ meta.class meta.block meta.function meta.block punctuation.section.block + $.foo = ""; + super(el); + } +// ^ meta.class meta.block meta.function meta.block punctuation.section.block + + get foo() +// ^^^^^^^^^ meta.function + // <- storage.type.accessor + // ^ entity.name.function + { + return this._foo; + } + + static foo(baz) { +// ^^^^^^ storage.modifier +// ^^^^^^^^^^ meta.function + // ^^^ entity.name.function + + } + + qux() +// ^^^^^ meta.function + { } +// ^ meta.class meta.block meta.block punctuation.section.block.begin + + get bar () { +// ^^^^^^^^^^^^ meta.function +// ^ meta.class meta.block meta.block punctuation.section.block.begin + // <- storage.type.accessor + // ^ entity.name.function + return false; + } + + baz() { return null } +// ^^^^^^^^^^^^^^^^^^^^^ meta.function + // <- entity.name.function + + get() { return "foobar"; } +// ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +// ^^^ entity.name.function.js - storage.type.accessor + + set (value) { return value; } +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +// ^^^^^ variable.parameter.function.js +// ^^^ entity.name.function.js - storage.type.accessor + + set abc(value1, value2) { return value1 + value2; } +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +// ^^^ storage.type.accessor - entity.name.function.js +// ^^^ entity.name.function.js +// ^^^^^^ variable.parameter.function.js +// ^ punctuation.separator.parameter.function.js +// ^^^^^^ variable.parameter.function.js + + static$ +// ^^^^^^^ - storage + () {}; + + constructor$() {} +// ^^^^^^^^^^^^ entity.name.function - entity.name.function.constructor + + @foo bar() {} +// ^^^^ meta.annotation +// ^ punctuation.definition.annotation +// ^^^ variable.annotation +// ^^^ entity.name.function + + @foo.bar bar() {} +// ^^^^^^^^ meta.annotation +// ^ punctuation.definition.annotation +// ^^^ variable.other.readwrite - variable.annotation +// ^^^ variable.annotation +// ^^^ entity.name.function + + @(whatever) bar() {} +// ^^^^^^^^^^^ meta.annotation +// ^ punctuation.definition.annotation +// ^^^^^^^^^^ meta.group +// ^^^ entity.name.function + + ['foo']() {} +// ^^^^^^^^^^^^ meta.function + + static ['foo']() {} +// ^^^^^^^^^^^^ meta.function + + async foo() {} +// ^^^^^ keyword.declaration.async + + *foo() {} +// ^ keyword.generator.asterisk + + async *foo() {} +// ^^^^^ keyword.declaration.async +// ^ keyword.generator.asterisk + + static async foo() {} +// ^^^^^ keyword.declaration.async +} +// <- meta.block punctuation.section.block.end + +class Foo extends React.Component { +// ^^^^^ - entity.other.inherited-class +// ^^^^^^^^^ entity.other.inherited-class + constructor() + {} + + [foo.bar](arg) { +// ^^^ variable.other +// ^^^ meta.property +// ^^^ variable.parameter + return this.a; + } +} + +class Foo extends (Foo).Bar {} +// ^^^ entity.other.inherited-class + +class Foo extends Bar +// ^^^ entity.other.inherited-class + .baz {} +// ^^^^^^^ meta.class +// ^ punctuation.accessor +// ^^^ entity.other.inherited-class + +class Foo extends +// ^^^^^^^ storage.modifier.extends +Bar {} + +class Foo extends getSomeClass() {} +// ^^^^^^^^^^^^ meta.function-call variable.function - entity.other.inherited-class + + (class extends Bar {}); +// ^^^^^^^ storage.modifier.extends - entity.name.class + + (class extends class {} {}); +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class +// ^^^^^^^ storage.modifier.extends +// ^^^^^^^^ meta.class meta.class +// ^^^^^ keyword.declaration.class + +// Better highlighting while typing. +class +class +// <- keyword.declaration.class - entity.name.class + +class{}/**/ +// ^ - meta.class + () => {}; // ^^^^^^^^ meta.function - meta.function meta.function // ^^ meta.function.parameters @@ -667,7 +1219,7 @@ var obj = new function() {}(); // ^^^^^^^^ keyword.declaration.function var obj2 = new class Foo{}(); -// ^^^^^ storage.type.class +// ^^^^^ keyword.declaration.class this.func() // <- variable.language.this diff --git a/JavaScript/tests/syntax_test_js_class.js b/JavaScript/tests/syntax_test_js_class.js index 70e0be9255d..e27739742e3 100644 --- a/JavaScript/tests/syntax_test_js_class.js +++ b/JavaScript/tests/syntax_test_js_class.js @@ -1,7 +1,7 @@ // SYNTAX TEST "Packages/JavaScript/JavaScript.sublime-syntax" class MyClass extends TheirClass { -// <- storage.type.class +// <- keyword.declaration.class // ^^^^^^^ entity.name.class // ^^^^^^^ storage.modifier.extends // ^^^^^^^^^^ entity.other.inherited-class @@ -261,12 +261,12 @@ class Foo extends getSomeClass() {} // ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class // ^^^^^^^ storage.modifier.extends // ^^^^^^^^ meta.class meta.class -// ^^^^^ storage.type.class +// ^^^^^ keyword.declaration.class // Better highlighting while typing. class class -// <- storage.type.class - entity.name.class +// <- keyword.declaration.class - entity.name.class class{}/**/ // ^ - meta.class @@ -275,17 +275,17 @@ class{}/**/ // ^^^^ meta.annotation // ^ punctuation.definition.annotation // ^^^ variable.annotation -// ^^^^^ storage.type.class +// ^^^^^ keyword.declaration.class @foo.bar class Foo {} // ^^^^^^^^ meta.annotation // ^ punctuation.definition.annotation // ^^^ variable.other.readwrite - variable.annotation // ^^^ variable.annotation -// ^^^^^ storage.type.class +// ^^^^^ keyword.declaration.class @(whatever) class Foo {} // ^^^^^^^^^^^ meta.annotation // ^ punctuation.definition.annotation // ^^^^^^^^^^ meta.group -// ^^^^^ storage.type.class +// ^^^^^ keyword.declaration.class diff --git a/JavaScript/tests/syntax_test_typescript.ts b/JavaScript/tests/syntax_test_typescript.ts index 8de68c6f106..0060240f9ac 100644 --- a/JavaScript/tests/syntax_test_typescript.ts +++ b/JavaScript/tests/syntax_test_typescript.ts @@ -31,7 +31,7 @@ // ^^^^^^^^^^^^^^^^^^^^^^^ meta.export // ^^^^^^ keyword.control.import-export // ^^^^^^^^^^^^^^^^ meta.interface -// ^^^^^^^^^ storage.type +// ^^^^^^^^^ keyword.declaration // ^^^ entity.name.interface // ^^ meta.block @@ -39,7 +39,7 @@ // ^^^^^^^^^^^^^^^^^^^^^^^ meta.export // ^^^^^^ keyword.control.import-export // ^^^^^^^^^^^^^^^^ meta.namespace -// ^^^^^^^^^ storage.type +// ^^^^^^^^^ keyword.declaration // ^^^ entity.name.namespace // ^^ meta.block @@ -47,7 +47,7 @@ interface Foo { // ^^^^^^^^^^^^^^^^ meta.interface -// ^^^^^^^^^ storage.type +// ^^^^^^^^^ keyword.declaration // ^^^ entity.name.interface // ^ meta.block punctuation.section.block.begin foo: any; @@ -68,7 +68,7 @@ interface Foo < T > extends Bar < T > {} // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interface -// ^^^^^^^^^ storage.type +// ^^^^^^^^^ keyword.declaration // ^^^ entity.name.interface // ^^^^^ meta.generic // ^ punctuation.definition.generic.begin @@ -237,7 +237,7 @@ namespace Foo { // ^^^^^^^^^^^^^^^^ meta.namespace -// ^^^^^^^^^ storage.type +// ^^^^^^^^^ keyword.declaration // ^^^ entity.name.namespace // ^ meta.block punctuation.section.block.begin }