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

support embedded hbs #710

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
24 changes: 24 additions & 0 deletions grammars/javascript.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,30 @@
}
]
}
{
'begin': '(hbs|handlebars)\\s*(`)'
'beginCaptures':
'1':
'name': 'entity.name.function.js'
'2':
'name': 'punctuation.definition.string.begin.js'
'end': '`'
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.js'
'name': 'string.quoted.template.hbs.js'
'patterns': [
{
'include': '#string_escapes'
}
{
'include': '#interpolated_js'
}
{
'include': 'source.handlebars'
}
]
}
{
'begin': '`'
'beginCaptures':
Expand Down
19 changes: 19 additions & 0 deletions spec/javascript-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,25 @@ describe "JavaScript grammar", ->
expect(tokens[5]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.sql.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[6]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.sql.js', 'punctuation.definition.string.end.js']

describe "ES6 tagged HBS string templates", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('hbs`{{#if isAdmin`')
expect(tokens[0]).toEqual value: 'hbs', scopes: ['source.js', 'string.quoted.template.hbs.js', 'entity.name.function.js']
expect(tokens[1]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.hbs.js', 'punctuation.definition.string.begin.js']
expect(tokens[2]).toEqual value: '{{#if isAdmin', scopes: ['source.js', 'string.quoted.template.hbs.js']
expect(tokens[3]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.hbs.js', 'punctuation.definition.string.end.js']

describe "ES6 tagged HBS string templates with interpolation", ->
it "tokenizes them as strings", ->
{tokens} = grammar.tokenizeLine('hbs`{{#if ${isAdmin}`')
expect(tokens[0]).toEqual value: 'hbs', scopes: ['source.js', 'string.quoted.template.hbs.js', 'entity.name.function.js']
expect(tokens[1]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.hbs.js', 'punctuation.definition.string.begin.js']
expect(tokens[2]).toEqual value: '{{#if ', scopes: ['source.js', 'string.quoted.template.hbs.js']
expect(tokens[3]).toEqual value: '${', scopes: ['source.js', 'string.quoted.template.hbs.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[4]).toEqual value: 'isAdmin', scopes: ['source.js', 'string.quoted.template.hbs.js', 'source.js.embedded.source']
expect(tokens[5]).toEqual value: '}', scopes: ['source.js', 'string.quoted.template.hbs.js', 'source.js.embedded.source', 'punctuation.section.embedded.js']
expect(tokens[6]).toEqual value: '`', scopes: ['source.js', 'string.quoted.template.hbs.js', 'punctuation.definition.string.end.js']

describe "ES6 class", ->
it "tokenizes class", ->
{tokens} = grammar.tokenizeLine('class MyClass')
Expand Down