Skip to content

Commit dbb32c9

Browse files
committed
feat: strictMode show or not throw an exception, close #102
1 parent 2149183 commit dbb32c9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ module.exports = function postHTMLExpressions (options) {
112112
switchTags: ['switch', 'case', 'default'],
113113
loopTags: ['each'],
114114
scopeTags: ['scope'],
115-
ignoredTag: 'raw'
115+
ignoredTag: 'raw',
116+
strictMode: true
116117
}, options)
117-
118+
118119
// set tags
119120
loops = options.loopTags
120121
scopes = options.scopeTags
@@ -155,7 +156,7 @@ module.exports = function postHTMLExpressions (options) {
155156

156157
// kick off the parsing
157158
return function (tree) {
158-
return normalizeTree(clearRawTag(walk({ locals: options.locals }, tree)), tree.options)
159+
return normalizeTree(clearRawTag(walk({ locals: options.locals, strictMode: options.strictMode }, tree)), tree.options)
159160
}
160161
}
161162

@@ -267,7 +268,15 @@ function walk (opts, nodes) {
267268
}
268269

269270
// evaluate the expression, get the winning condition branch
270-
const branch = branches[vm.runInContext(expression, ctx)]
271+
let branch;
272+
try {
273+
branch = branches[vm.runInContext(expression, ctx)]
274+
} catch (error) {
275+
if (opts.strictMode) {
276+
throw new SyntaxError(error)
277+
}
278+
}
279+
271280

272281
// remove all of the conditional tags from the tree
273282
// we subtract 1 from i as it's incremented from the initial if statement

0 commit comments

Comments
 (0)