Skip to content

Commit

Permalink
feat: strictMode show or not throw an exception, close #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrum committed Oct 30, 2020
1 parent 2149183 commit dbb32c9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ module.exports = function postHTMLExpressions (options) {
switchTags: ['switch', 'case', 'default'],
loopTags: ['each'],
scopeTags: ['scope'],
ignoredTag: 'raw'
ignoredTag: 'raw',
strictMode: true
}, options)

// set tags
loops = options.loopTags
scopes = options.scopeTags
Expand Down Expand Up @@ -155,7 +156,7 @@ module.exports = function postHTMLExpressions (options) {

// kick off the parsing
return function (tree) {
return normalizeTree(clearRawTag(walk({ locals: options.locals }, tree)), tree.options)
return normalizeTree(clearRawTag(walk({ locals: options.locals, strictMode: options.strictMode }, tree)), tree.options)
}
}

Expand Down Expand Up @@ -267,7 +268,15 @@ function walk (opts, nodes) {
}

// evaluate the expression, get the winning condition branch
const branch = branches[vm.runInContext(expression, ctx)]
let branch;
try {
branch = branches[vm.runInContext(expression, ctx)]
} catch (error) {
if (opts.strictMode) {
throw new SyntaxError(error)
}
}


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

0 comments on commit dbb32c9

Please sign in to comment.