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:
committed by
Nicolò Ribaudo
parent
8d4f95de45
commit
66062c2a8c
@@ -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}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user