Skip to content

Commit 6dd73bb

Browse files
committed
failing tests and partial fix for #31
1 parent ffe3259 commit 6dd73bb

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export function x(strings: TemplateStringsArray, ...values: any[]): Expression {
206206

207207
try {
208208
const expression = acorn.parseExpressionAt(str, 0, acorn_opts(comments, str)) as Expression;
209+
const match = /\S+/.exec(str.slice((expression as any).end));
210+
if (match) {
211+
throw new Error(`Unexpected token '${match[0]}'`);
212+
}
209213

210214
inject(str, expression, values, comments);
211215

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo || (bar => bar);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = ({ b, x }) => b`foo || ${x`bar => bar`}`;

test/test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ describe('codered', () => {
398398
mappings: 'YASK,EAAE'
399399
});
400400
});
401+
402+
it('errors on invalid expressions', () => {
403+
assert.throws(() => {
404+
x`this is broken`;
405+
}, /Unexpected token 'is'/);
406+
});
401407
});
402408

403409
describe('p', () => {

0 commit comments

Comments
 (0)