Skip to content

Commit

Permalink
fix(parser): throw on unterminated template literal
Browse files Browse the repository at this point in the history
  • Loading branch information
fkleuver committed Nov 22, 2018
1 parent ef11389 commit 5c5b5e3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
29 changes: 29 additions & 0 deletions test/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" }',
Expand Down

0 comments on commit 5c5b5e3

Please sign in to comment.