Template literal validation (#10492)

* add template literal validation

* avoid null/undefined error when validating

* simplify validation logic and fix tests

Co-authored-by: Michael J. Currie <michaeljcurrie136@gmail.com>
This commit is contained in:
Michael J. Currie
2019-09-26 12:58:36 -05:00
committed by Nicolò Ribaudo
parent 8d4f95de45
commit 66062c2a8c
3 changed files with 97 additions and 0 deletions

View File

@@ -574,6 +574,16 @@ defineType("TemplateLiteral", {
validate: chain(
assertValueType("array"),
assertEach(assertNodeType("Expression")),
function(node, key, val) {
if (node.quasis.length !== val.length + 1) {
throw new TypeError(
`Number of ${
node.type
} quasis should be exactly one more than the number of expressions.\nExpected ${val.length +
1} quasis but got ${node.quasis.length}`,
);
}
},
),
},
},