Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Add support for optional chaining within template literals #586

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@
]
}
{
'begin': '\\?'
'begin': '\\?(?!\\.)'
'beginCaptures':
'0':
'name': 'keyword.operator.ternary.js'
Expand Down Expand Up @@ -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'
}
]
Expand Down
11 changes: 11 additions & 0 deletions spec/javascript-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down