Skip to content

Commit

Permalink
fixes template strings introducing errant plus when there are no items (
Browse files Browse the repository at this point in the history
#327)

* fixes template strings introducing errant plus when there are no items

* simplify spec

Co-authored-by: Bronley <[email protected]>
  • Loading branch information
georgejecook and TwitchBronBron authored Feb 20, 2021
1 parent 7db62ed commit 345ee59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ export class TemplateStringExpression extends Expression {
...items
);
}
plus = ' + ';
plus = items.length > 0 ? ' + ' : '';
}

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 @@ -74,6 +74,13 @@ describe('TemplateStringExpression', () => {
program.dispose();
});

it('properly transpiles simple template string with no leading text', () => {
testTranspile(
'a = `${one},${two}`',
`a = bslib_toString(one) + "," + bslib_toString(two)`
);
});

it('properly transpiles simple template string', () => {
testTranspile(
'a = `hello world`',
Expand Down

0 comments on commit 345ee59

Please sign in to comment.