Skip to content

Commit a888024

Browse files
authored
added whitespace trim to handle oddly formatted vue templates (#32)
1 parent 80f2552 commit a888024

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function evaluateValue (expression) {
4848
if (!expression.match(stringRE)) { return ret }
4949

5050
try {
51-
const val = (new Function(`return ${expression}`))()
51+
const val = (new Function(`return ${expression.trim()}`))()
5252
ret.status = 'ok'
5353
ret.value = val
5454
} catch (e) { }

test/utils.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ it('string literal containing period delimited ecmascript keywords should evalua
2828
const { status, value } = evaluateValue(`'new.alert.import'`)
2929
expect(status).toEqual('ok')
3030
expect(value).toEqual('new.alert.import')
31+
})
32+
33+
it('string literal containing whitespace and newline keywords should evaluate', () => {
34+
const { status, value } = evaluateValue(`
35+
'hello'
36+
`)
37+
expect(status).toEqual('ok')
38+
expect(value).toEqual('hello')
3139
})

0 commit comments

Comments
 (0)