Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

constant-folding template strings #612

Closed
mariusGundersen opened this issue Jul 2, 2017 · 3 comments
Closed

constant-folding template strings #612

mariusGundersen opened this issue Jul 2, 2017 · 3 comments
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue

Comments

@mariusGundersen
Copy link

There is a bug in the babel-plugin-minify-constant-folding package where it incorrectly inlines template strings. Here is a simple example:

const a = ["a", "b"].join(' ');
// -> const a="a b";


const b = [`a${a}`, `b${a}`].join(' ');
// -> const b=" ";

In the second example it should keep the interpolation and produce a template string, but it does not, instead returning just an empty string. The result is broken code.

@vigneshshanmugam vigneshshanmugam added bug Confirmed bug has PR Has an open PR that fixes this issue labels Jul 2, 2017
@vigneshshanmugam
Copy link
Member

@mariusGundersen Thanks for creating the issue, #613 should fix this

@mgol
Copy link

mgol commented Jul 18, 2017

This has just hit me in production. A very simple complete test case:

const a = 'a';
console.log([`${ a }b`, 'c',].join(''));

transpiles to:

const a='a';console.log('c');

instead of the expected:

const a='a';console.log(`${ a }bc`);

or:

console.log('abc');

Perhaps the PR should include a test like that.

@lydell
Copy link

lydell commented Oct 19, 2017

Could this please be released to npm? @boopathi?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Confirmed bug has PR Has an open PR that fixes this issue
Projects
None yet
Development

No branches or pull requests

4 participants