8000 handle es2015 template strings in expressions (fix #2364) · lrenc/vue@142046f · GitHub
[go: up one dir, main page]

Skip to content

Commit 142046f

Browse files
committed
handle es2015 template strings in expressions (fix vuejs#2364)
1 parent 521e8d2 commit 142046f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/parsers/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const improperKeywordsRE =
2323

2424
const wsRE = /\s/g
2525
const newlineRE = /\n/g
26-
const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")|new |typeof |void /g
26+
const saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`)|new |< 8000 span class="pl-s">typeof |void /g
2727
const restoreRE = /"(\d+)"/g
2828
const pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/
2929
const identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g

test/unit/specs/parsers/expression_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ describe('Expression Parser', function () {
286286
expect(res1).toBe(res2)
287287
})
288288

289+
it('ES2015 template string handling', function () {
290+
var res = expParser.parseExpression('a + `hi ${ b }` + c')
291+
expect(res.get.toString().indexOf('scope.a+`hi ${scope.b}`+scope.c') > -1).toBe(true)
292+
res = expParser.parseExpression('`hi ${ b + `${ d }` }`')
293+
expect(res.get.toString().indexOf('`hi ${scope.b+`${scope.d}`}`') > -1).toBe(true)
294+
res = expParser.parseExpression('{transform:`rotate(${x}deg)`}')
295+
expect(res.get.toString().indexOf('{transform:`rotate(${scope.x}deg)`}') > -1).toBe(true)
296+
})
297+
289298
describe('invalid expression', function () {
290299
beforeEach(function () {
291300
spyWarns()

0 commit comments

Comments
 (0)
0