Skip to content

Commit

Permalink
Fix template string transpile bug. (#361)
Browse files Browse the repository at this point in the history
Fixes #355
  • Loading branch information
TwitchBronBron authored Mar 16, 2021
1 parent 471884d commit 08e016e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,10 @@ export class TemplateStringExpression extends Expression {
...items
);
}
plus = items.length > 0 ? ' + ' : '';
//set the plus after the first occurance of a nonzero length set of items
if (plus === '' && items.length > 0) {
plus = ' + ';
}
}

for (let i = 0; i < this.quasis.length; i++) {
Expand Down
7 changes: 7 additions & 0 deletions src/parser/tests/expression/TemplateStringExpression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ describe('TemplateStringExpression', () => {
`);
});

it('properly transpiles two template strings side-by-side', () => {
testTranspile(
'a = `${"hello"}${"world"}`',
'a = "hello" + "world"'
);
});

it('skips calling toString on strings', () => {
testTranspile(`
text = \`Hello \${"world"}\`
Expand Down

0 comments on commit 08e016e

Please sign in to comment.