Permalink
Browse files

fix(parser): throw on unterminated template literal

  • Loading branch information...
fkleuver committed Nov 22, 2018
1 parent ef11389 commit 5c5b5e367e65494735d1739e2ec175c494f8a582
Showing with 31 additions and 0 deletions.
  1. +2 −0 src/parser.js
  2. +29 −0 test/parser.spec.js
@@ -509,6 +509,8 @@ export class ParserImplementation {
}
} else if (this.ch === /*\*/0x5C) {
result += fromCharCode(unescape(this.next()));
} else if (this.ch === /*EOF*/0 || this.idx >= this.len) {
this.err('Unterminated template literal');
} else {
result += fromCharCode(this.ch);
}
@@ -678,6 +678,35 @@ describe('Parser', () => {
}
});
describe('Unterminated template literal', () => {
const unterminatedBacktick = [
'`a',
'`',
'a`',
'`a ${b} ${`',
'`a ${`',
'`${`'
];
for (const expr of unterminatedBacktick) {
it(expr, () => {
_verifyError(expr, 'Unterminated template literal');
});
}
const unterminatedExpr = [
'`a ${b} ${',
'`a ${',
'`${'
];
for (const expr of unterminatedExpr) {
it(expr, () => {
_verifyError(expr, 'Unexpected end of expression');
});
}
});
describe('LiteralObject with computed property', () => {
const expressions = [
'{ []: "foo" }',

0 comments on commit 5c5b5e3

Please sign in to comment.