From 3d5af35c330d3cd9c7199087011f69b1b0b92675 Mon Sep 17 00:00:00 2001 From: Brennen Berkley Date: Tue, 17 Jul 2018 14:15:20 -0600 Subject: [PATCH 1/2] Added specs to test support for optional chaining within template literals --- spec/javascript-spec.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/javascript-spec.coffee b/spec/javascript-spec.coffee index b23d5bc0..964a6dc2 100644 --- a/spec/javascript-spec.coffee +++ b/spec/javascript-spec.coffee @@ -696,6 +696,17 @@ describe "JavaScript grammar", -> expect(tokens[13]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.js', 'source.js.embedded.source', 'punctuation.section.embedded.js'] expect(tokens[14]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.js', 'punctuation.definition.string.end.js'] + describe "ES6 string templates with optional chaining", -> + it "tokenizes them as strings", -> + {tokens} = grammar.tokenizeLine('`hey ${person?.name}`') + expect(tokens[0]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.js', 'punctuation.definition.string.begin.js'] + expect(tokens[1]).toEqual value: 'hey ', scopes: ['source.js', 'string.quoted.template.js'] + expect(tokens[2]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.js', 'source.js.embedded.source', 'punctuation.section.embedded.js'] + expect(tokens[3]).toEqual value: 'person', scopes: ['source.js', 'string.quoted.template.js', 'source.js.embedded.source', 'variable.other.object.js'] + expect(tokens[6]).toEqual value: 'name', scopes: ['source.js', 'string.quoted.template.js', 'source.js.embedded.source', 'support.variable.property.dom.js'] + expect(tokens[7]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.js', 'source.js.embedded.source', 'punctuation.section.embedded.js'] + expect(tokens[8]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.js', 'punctuation.definition.string.end.js'] + describe "HTML template strings", -> # TODO: Remove after Atom 1.21 is released [tagScope, entityScope] = [] From 51a5ccd3a70dd1bf3c7ef290954a26f2e3742b15 Mon Sep 17 00:00:00 2001 From: Brennen Berkley Date: Tue, 17 Jul 2018 14:16:55 -0600 Subject: [PATCH 2/2] Added support for optional chaining within template literals --- grammars/javascript.cson | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grammars/javascript.cson b/grammars/javascript.cson index 147a7b80..284fa5ad 100644 --- a/grammars/javascript.cson +++ b/grammars/javascript.cson @@ -1137,7 +1137,7 @@ ] } { - 'begin': '\\?' + 'begin': '\\?(?!\\.)' 'beginCaptures': '0': 'name': 'keyword.operator.ternary.js' @@ -1795,8 +1795,8 @@ 'name': 'constant.other.object.js' } { - # obj in obj.prop, obj.methodCall() - 'match': '[a-zA-Z_$][\\w$]*(?=\\s*\\.\\s*[a-zA-Z_$]\\w*)' + # obj in obj.prop, obj.methodCall(), obj?.prop + 'match': '[a-zA-Z_$][\\w$]*(?=\\s*\\??\\.\\s*[a-zA-Z_$]\\w*)' 'name': 'variable.other.object.js' } ]