From d0eb1272d531f047b6fc9a05a01b5a572cec01c2 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Mon, 29 Jul 2019 21:33:22 -0400 Subject: [PATCH 1/3] [JavaScript] Use meta.mapping instead of meta.object-literal --- JavaScript/JavaScript.sublime-syntax | 20 +++-- JavaScript/tests/syntax_test_js.js | 91 +++++++++++---------- JavaScript/tests/syntax_test_js_bindings.js | 30 +++---- 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 9fdd2ed3da..d1da9c6133 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1469,7 +1469,7 @@ contexts: set: object-literal-contents object-literal-contents: - - meta_scope: meta.object-literal.js + - meta_scope: meta.mapping.js - match: '\}' scope: punctuation.section.block.end.js @@ -1497,7 +1497,9 @@ contexts: - match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))' scope: variable.other.readwrite.js - match: (?=\[) - push: computed-property-name + push: + - object-literal-meta-key + - computed-property-name - match: (?=\"|') push: - object-literal-meta-key @@ -1505,7 +1507,7 @@ contexts: - include: bare-property-name - match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d)) push: - - meta_scope: meta.object-literal.key.js + - meta_scope: meta.mapping.key.js - include: literal-number - include: comma-separator @@ -1521,13 +1523,13 @@ contexts: bare-property-name: - match: '{{dollar_only_identifier}}' - scope: meta.object-literal.key.dollar.only.js punctuation.dollar.js + scope: meta.mapping.key.dollar.only.js punctuation.dollar.js - match: '{{dollar_identifier}}' - scope: meta.object-literal.key.dollar.js + scope: meta.mapping.key.dollar.js captures: 1: punctuation.dollar.js - match: '{{identifier}}' - scope: meta.object-literal.key.js + scope: meta.mapping.key.js computed-property-name: - match: \[ @@ -1540,7 +1542,7 @@ contexts: push: expression object-literal-meta-key: - - meta_scope: meta.object-literal.key.js + - meta_scope: meta.mapping.key.js - include: else-pop object-literal-expect-colon: @@ -1550,7 +1552,7 @@ contexts: method-name: - match: '{{dollar_identifier}}' - scope: meta.object-literal.key.dollar.js entity.name.function.js + scope: meta.mapping.key.dollar.js entity.name.function.js captures: 1: punctuation.dollar.js pop: true @@ -1591,7 +1593,7 @@ contexts: field-name: - match: '{{dollar_identifier}}' - scope: meta.object-literal.key.dollar.js variable.other.readwrite.js + scope: meta.mapping.key.dollar.js variable.other.readwrite.js captures: 1: punctuation.dollar.js pop: true diff --git a/JavaScript/tests/syntax_test_js.js b/JavaScript/tests/syntax_test_js.js index 4b95a1b298..a9913fcf27 100644 --- a/JavaScript/tests/syntax_test_js.js +++ b/JavaScript/tests/syntax_test_js.js @@ -218,10 +218,10 @@ let x = import.meta; // method body, but we include it here to ensure that highlighting is not // broken as the user is typing let a = { otherIdentifier, foo(), baz: 1 } -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.object-literal +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping // ^^^^^^^^^^^^^^^ variable.other.readwrite // ^^^ entity.name.function -// ^^^ meta.object-literal.key +// ^^^ meta.mapping.key someFunction({ prop1, prop2, prop3 @@ -427,27 +427,28 @@ a = test ? a + b : c; // ^ meta.block meta.block variable.other.readwrite var obj = { -// ^ meta.object-literal punctuation.section.block.begin - meta.block +// ^ meta.mapping punctuation.section.block.begin - meta.block key: bar, - // <- meta.object-literal.key + // <- meta.mapping.key $key2: "string value", - // ^ meta.object-literal.key + // ^ meta.mapping.key // ^ - constant.other // ^^^^^^^^^^^^^^ meta.string string.quoted.double $key3: 0, - // <- meta.object-literal.key.dollar punctuation.dollar - // <- meta.object-literal.key.dollar - punctuation.dollar + // <- meta.mapping.key.dollar punctuation.dollar + // <- meta.mapping.key.dollar - punctuation.dollar $: 0, -// ^ meta.object-literal.key.dollar.only punctuation.dollar +// ^ meta.mapping.key.dollar.only punctuation.dollar $keyFunc: function() { // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration - // <- meta.object-literal.key.dollar entity.name.function punctuation.dollar - // <- meta.object-literal.key.dollar entity.name.function - punctuation.dollar + // <- meta.mapping.key.dollar entity.name.function punctuation.dollar + // <- meta.mapping.key.dollar entity.name.function - punctuation.dollar }, [true==false ? 'one' : 'two']: false, +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.key // ^ punctuation.section.brackets.begin // ^^^^ constant.language // ^^^^ constant.language @@ -457,13 +458,13 @@ var obj = { // ^ punctuation.separator.key-value "": true, - // <- meta.object-literal.key + // <- meta.mapping.key "key4": true, -// ^^^^^^ meta.object-literal.key meta.string string.quoted.double +// ^^^^^^ meta.mapping.key meta.string string.quoted.double // ^ punctuation.separator.key-value - string 'key5': false, -// ^^^^^^meta.object-literal.key meta.string string.quoted.single +// ^^^^^^meta.mapping.key meta.string string.quoted.single // ^ punctuation.separator.key-value - string // ^^^^^ constant.language.boolean.false @@ -484,40 +485,40 @@ var obj = { funcKey: function() { // ^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^ meta.object-literal.key entity.name.function +// ^^^^^^^ meta.mapping.key entity.name.function }, func2Key: function func2Key() { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^ meta.object-literal.key entity.name.function +// ^^^^^^^^ meta.mapping.key entity.name.function }, funcKeyArrow: () => { // ^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^^^^^ meta.object-literal.key entity.name.function +// ^^^^^^^^^^^^ meta.mapping.key entity.name.function }, "funcStringKey": function funcStringKey() // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^^^^^^^^ meta.object-literal.key meta.string string.quoted.double +// ^^^^^^^^^^^^^^^ meta.mapping.key meta.string string.quoted.double // ^^^^^^^^^^^^^ entity.name.function { }, 'funcStringKey': function() { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^^^^^^^^ meta.object-literal.key meta.string string.quoted.single +// ^^^^^^^^^^^^^^^ meta.mapping.key meta.string string.quoted.single // ^^^^^^^^^^^^^ entity.name.function }, 'funcStringKeyArrow': () => { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^^^^^^^^^^^^^ meta.object-literal.key meta.string string.quoted.single +// ^^^^^^^^^^^^^^^^^^^^ meta.mapping.key meta.string string.quoted.single // ^^^^^^^^^^^^^^^^^^ entity.name.function }, "func\\String2KeyArrow": (foo) => { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration -// ^^^^^^^^^^^^^^^^^^^^^^^ meta.object-literal.key meta.string string.quoted.double +// ^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping.key meta.string string.quoted.double // ^^^^^^^^^^^^^^^^^^^^^ entity.name.function // ^^ constant.character.escape }, @@ -540,13 +541,13 @@ var obj = { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.function "key (": true, -// ^^^^^^^ meta.object-literal.key +// ^^^^^^^ meta.mapping.key "key \"(": true, -// ^^^^^^^^^ meta.object-literal.key +// ^^^^^^^^^ meta.mapping.key "key '(": true, -// ^^^^^^^^ meta.object-literal.key +// ^^^^^^^^ meta.mapping.key static, // ^^^^^^ variable.other.readwrite @@ -568,7 +569,7 @@ var obj = { // ^^^ variable.function // ^ punctuation.separator.comma } -// <- meta.object-literal - meta.block +// <- meta.mapping - meta.block +{ // <- keyword.operator @@ -580,14 +581,14 @@ var obj = { // ^ keyword.operator // ^ constant.language }; -// <- meta.object-literal punctuation.section.block.end +// <- meta.mapping punctuation.section.block.end ({ - // <- meta.object-literal + // <- meta.mapping 0.: {0.e+0: 0} -//^^ meta.object-literal.key constant.numeric +//^^ meta.mapping.key constant.numeric // ^ punctuation.separator.key-value -// ^^^^^ meta.object-literal.key constant.numeric +// ^^^^^ meta.mapping.key constant.numeric // ^ constant.numeric }); @@ -1208,7 +1209,7 @@ const test = ({a, b, c=()=>({active:false}) }) => {}; () => { return; } // ^^ storage.type.function.arrow -// ^^^^^^^^^^^ meta.block - meta.object-literal +// ^^^^^^^^^^^ meta.block - meta.mapping // ^^^^^^ keyword.control.flow ); @@ -1307,7 +1308,7 @@ var foo = ~{a:function(){}.a()} // ^ keyword.operator.assignment // ^ keyword.operator.bitwise // ^ punctuation.section.block.begin -// ^^^^^^^^^^^^^^^^^^^^ meta.object-literal +// ^^^^^^^^^^^^^^^^^^^^ meta.mapping // ^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function // ^ punctuation.separator.key-value @@ -1316,7 +1317,7 @@ var foo = ~{a:function(){}.a()} // ^ punctuation.section.group.end // ^ meta.block punctuation.section.block.begin // ^ meta.block punctuation.section.block.end -// ^ meta.object-literal +// ^ meta.mapping // ^^^ meta.function.declaration // ^ entity.name.function // ^ punctuation.section.group.begin @@ -1421,17 +1422,17 @@ void { // ^ meta.brackets 'test3': "asdf" } -// <- meta.object-literal punctuation.section.block.end +// <- meta.mapping punctuation.section.block.end // This tests parsing semi-broken object literals, which should help while a // user is in the middle of typing code void { key1: true -// ^^^^ meta.object-literal.key.js +// ^^^^ meta.mapping.key.js key2: 0 -// ^^^^ meta.object-literal.key.js +// ^^^^ meta.mapping.key.js key3: function() -// ^^^^ meta.object-literal.key.js entity.name.function +// ^^^^ meta.mapping.key.js entity.name.function { } @@ -1615,7 +1616,7 @@ new FooBar(function(){ var test = {a: 1} -// <- meta.object-literal punctuation.section.block.begin +// <- meta.mapping punctuation.section.block.begin var arrowFuncBraceNextLine = () => /* comments! */ // ^ entity.name.function @@ -1646,14 +1647,14 @@ var o = { a: i => i * 2, b: i => i * 3 } function test() { return {a: 1}; -// ^^^^^^ meta.object-literal -// ^ meta.object-literal.key +// ^^^^^^ meta.mapping +// ^ meta.mapping.key // ^ constant.numeric } $.each({}) // <- variable.other.dollar.only punctuation.dollar -// ^ meta.object-literal +// ^ meta.mapping $varname.method() // <- variable.other.dollar punctuation.dollar - variable.object.dollar.only @@ -1709,18 +1710,18 @@ var CONST; return; {a: 1}; -// ^ meta.block - meta.object-literal +// ^ meta.block - meta.mapping return/**/{a: 1} -// ^^^^^^ meta.object-literal - meta.block +// ^^^^^^ meta.mapping - meta.block return {a: 1}; -// ^ meta.block - meta.object-literal +// ^ meta.block - meta.mapping return/* */{a: 1} -//^^^^^^ meta.block - meta.object-literal +//^^^^^^ meta.block - meta.mapping const abc = new Set if (true) {}; @@ -1736,13 +1737,13 @@ var o = { var query = { type: type==undefined ? null : {$in: type.split(',')} -//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.object-literal +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.mapping // ^^^^^^^^^ constant.language.undefined // ^ keyword.operator.ternary // ^^^^ constant.language.null // ^ keyword.operator.ternary // ^ punctuation.section.block.begin -// ^^ meta.object-literal.key.dollar.js +// ^^ meta.mapping.key.dollar.js // ^ punctuation.separator.key-value.js // ^ punctuation.section.block.end }; diff --git a/JavaScript/tests/syntax_test_js_bindings.js b/JavaScript/tests/syntax_test_js_bindings.js index 65f5be14b1..a03700b7b2 100644 --- a/JavaScript/tests/syntax_test_js_bindings.js +++ b/JavaScript/tests/syntax_test_js_bindings.js @@ -33,22 +33,22 @@ const [ x = 42, y = [a, b, c] ] = value; const { a, b: c, ...d } = value; // ^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^ meta.object-literal.key meta.binding.name variable.other.readwrite +// ^ meta.mapping.key meta.binding.name variable.other.readwrite // ^ punctuation.separator.comma -// ^ meta.object-literal.key - variable +// ^ meta.mapping.key - variable // ^ punctuation.separator.key-value // ^^^ keyword.operator.spread // ^ meta.binding.name variable.other.readwrite const { 'a': x, "b": y, [c]: z } = value; // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^^^ meta.object-literal.key string.quoted.single +// ^^^ meta.mapping.key string.quoted.single // ^ punctuation.separator.key-value // ^ meta.binding.name variable.other.readwrite -// ^^^ meta.object-literal.key string.quoted.double +// ^^^ meta.mapping.key string.quoted.double // ^ punctuation.separator.key-value // ^ meta.binding.name variable.other.readwrite -// ^^^ meta.object-literal.key +// ^^^ meta.mapping.key // ^ variable.other.readwrite // ^ punctuation.separator.key-value // ^ meta.binding.name variable.other.readwrite @@ -112,22 +112,22 @@ function f ([ x = 42, y = [a, b, c] ]) {} function f ({ a, b: c, ...d }) {} // ^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^ meta.object-literal.key meta.binding.name variable.parameter.function +// ^ meta.mapping.key meta.binding.name variable.parameter.function // ^ punctuation.separator.parameter -// ^ meta.object-literal.key - variable +// ^ meta.mapping.key - variable // ^ punctuation.separator.key-value // ^^^ keyword.operator.spread // ^ meta.binding.name variable.parameter.function function f ({ 'a': x, "b": y, [c]: z }) = value; // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^^^ meta.object-literal.key string.quoted.single +// ^^^ meta.mapping.key string.quoted.single // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function -// ^^^ meta.object-literal.key string.quoted.double +// ^^^ meta.mapping.key string.quoted.double // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function -// ^^^ meta.object-literal.key +// ^^^ meta.mapping.key // ^ variable.other.readwrite // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function @@ -174,22 +174,22 @@ let f = ({ a, b: c, ...d }) => {}; // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.declaration // ^ entity.name.function variable.other.readwrite // ^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^ meta.object-literal.key meta.binding.name variable.parameter.function +// ^ meta.mapping.key meta.binding.name variable.parameter.function // ^ punctuation.separator.parameter -// ^ meta.object-literal.key - variable +// ^ meta.mapping.key - variable // ^ punctuation.separator.key-value // ^^^ keyword.operator.spread // ^ meta.binding.name variable.parameter.function let f = ({ 'a': x, "b": y, [c]: z }) => {}; // ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.binding.destructuring.mapping -// ^^^ meta.object-literal.key string.quoted.single +// ^^^ meta.mapping.key string.quoted.single // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function -// ^^^ meta.object-literal.key string.quoted.double +// ^^^ meta.mapping.key string.quoted.double // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function -// ^^^ meta.object-literal.key +// ^^^ meta.mapping.key // ^ variable.other.readwrite // ^ punctuation.separator.key-value // ^ meta.binding.name variable.parameter.function From 3260a32e49285dca93a8f3d5458adeed286100bf Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Tue, 30 Jul 2019 18:36:20 -0400 Subject: [PATCH 2/3] Remove dollar scopes from meta.mapping. --- JavaScript/JavaScript.sublime-syntax | 22 ++++++++++++---------- JavaScript/tests/syntax_test_js.js | 8 +------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index d1da9c6133..d392556103 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -1496,19 +1496,27 @@ contexts: - match: '{{identifier}}(?=\s*(?:[},]|$|//|/\*))' scope: variable.other.readwrite.js + - match: (?=\[) push: - object-literal-meta-key - computed-property-name + - match: (?=\"|') push: - object-literal-meta-key - literal-string - - include: bare-property-name + - match: (?=[-+]?(?:\.[0-9]|0[bxo]|\d)) push: - - meta_scope: meta.mapping.key.js - - include: literal-number + - object-literal-meta-key + - literal-number + + # - include: bare-property-name + - match: (?={{identifier}}) + push: + - object-literal-meta-key + - bare-property-name - include: comma-separator - match: ':' @@ -1522,14 +1530,8 @@ contexts: push: expression-no-comma bare-property-name: - - match: '{{dollar_only_identifier}}' - scope: meta.mapping.key.dollar.only.js punctuation.dollar.js - - match: '{{dollar_identifier}}' - scope: meta.mapping.key.dollar.js - captures: - 1: punctuation.dollar.js - match: '{{identifier}}' - scope: meta.mapping.key.js + pop: true computed-property-name: - match: \[ diff --git a/JavaScript/tests/syntax_test_js.js b/JavaScript/tests/syntax_test_js.js index a9913fcf27..e4e8585ca3 100644 --- a/JavaScript/tests/syntax_test_js.js +++ b/JavaScript/tests/syntax_test_js.js @@ -434,12 +434,6 @@ var obj = { // ^ meta.mapping.key // ^ - constant.other // ^^^^^^^^^^^^^^ meta.string string.quoted.double - $key3: 0, - // <- meta.mapping.key.dollar punctuation.dollar - // <- meta.mapping.key.dollar - punctuation.dollar - - $: 0, -// ^ meta.mapping.key.dollar.only punctuation.dollar $keyFunc: function() { // ^^^^^^^^^^^^^^^^^^^^ meta.function.declaration @@ -1743,7 +1737,7 @@ var query = { // ^^^^ constant.language.null // ^ keyword.operator.ternary // ^ punctuation.section.block.begin -// ^^ meta.mapping.key.dollar.js +// ^^ meta.mapping.key.js // ^ punctuation.separator.key-value.js // ^ punctuation.section.block.end }; From d479388bd9c49aeb0966811d524a3af9b1caae82 Mon Sep 17 00:00:00 2001 From: Thomas Smith Date: Thu, 17 Oct 2019 21:20:38 -0400 Subject: [PATCH 3/3] Fix merge issue. --- JavaScript/tests/syntax_test_js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JavaScript/tests/syntax_test_js.js b/JavaScript/tests/syntax_test_js.js index 8f85d5829b..35a86d1f38 100644 --- a/JavaScript/tests/syntax_test_js.js +++ b/JavaScript/tests/syntax_test_js.js @@ -591,7 +591,7 @@ var obj = { // ^^^ entity.name.function get: 42, -// ^^^ meta.object-literal.key +// ^^^ meta.mapping.key } // <- meta.mapping - meta.block