New issue

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

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

Already on GitHub? Sign in to your account

default to spec mode for template literal transform #6098

Merged
merged 5 commits into from Aug 28, 2017

Conversation

Projects
None yet
6 participants
@kedromelon
Contributor

kedromelon commented Aug 13, 2017

Q                       A
Fixed Issues
Patch: Bug Fix?
Major: Breaking Change? 👌 (change to transform option)
Minor: New Feature?
Tests Added/Pass?
Spec Compliancy?
License MIT
Doc PR
Any Dependency Changes?

Similar to #6076, change transform-es2015-template-literals to default to spec mode, with loose optional

When this was being discussed in slack, there was also talk of this transform not throwing errors properly in some cases, but I didn't totally follow. If this could be further clarified, I'd be happy to try to implement that fix in this PR as well.

@kedromelon

This comment has been minimized.

Contributor

kedromelon commented Aug 13, 2017

transform-es2015-arrow-functions and babel-preset-es2015 still default to non-spec mode -- should these be updated?

if (!t.isStringLiteral(nodes[0]) && considerSecondNode) {
nodes.unshift(t.stringLiteral(""));
}
let root = nodes[0];
if (state.opts.spec) {
if (!state.opts.loose) {

This comment has been minimized.

@jridgewell

jridgewell Aug 23, 2017

Member

Flip the if statements, please.

@babel-bot

This comment has been minimized.

Collaborator

babel-bot commented Aug 23, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4695/

@babel-bot

This comment has been minimized.

Collaborator

babel-bot commented Aug 23, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4690/

Noah Lemen
root = buildConcatCallExressions(nodes);
}
} else {
if (state.opts.loose) {

This comment has been minimized.

@kedromelon

kedromelon Aug 23, 2017

Contributor

@jridgewell let me know if i misunderstood what you meant by "flip" here!

This comment has been minimized.

@jridgewell

jridgewell Aug 23, 2017

Member

That was it.

@kedromelon

This comment has been minimized.

Contributor

kedromelon commented Aug 23, 2017

^^^ oh man these integrated REPL builds are sliiiiiiick

for (let i = 1; i < nodes.length; i++) {
root = t.binaryExpression("+", root, nodes[i]);
}
} else {
if (nodes.length > 1) {

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Aug 23, 2017

Member

Can you also merge else { if ( -> else if (?

This comment has been minimized.

@kedromelon

kedromelon Aug 23, 2017

Contributor

👍 great idea!

Noah Lemen
`boolean`, defaults to `false`.
This option combines all template literal expressions and quasis with `String.prototype.concat`. It will handle cases with `Symbol.toPrimitive` correctly and throw correctly if template literal expression is a `Symbol()`. See [babel/babel#5791](https://github.com/babel/babel/pull/5791).
When `false` or not set, combines all template literal expressions and quasis with `String.prototype.concat`. It will handle cases with `Symbol.toPrimitive` correctly and throw correctly if template literal expression is a `Symbol()`. See [babel/babel#5791](https://github.com/babel/babel/pull/5791).

This comment has been minimized.

@existentialism

existentialism Aug 23, 2017

Member

When false or not set, combines all template...

Maybe:

When false or not set, all template literal expressions and quasis are combined with String.prototype.concat.

**In**
```javascript
`foo${bar}baz${quux}${1}`;
```
**Out**
**Out (without `{"loose": true}`)**

This comment has been minimized.

@existentialism

existentialism Aug 23, 2017

Member

I think it might be better if we update the example above with the default behavior, and keep this In/Out for loose: true

This option combines all template literal expressions and quasis with `String.prototype.concat`. It will handle cases with `Symbol.toPrimitive` correctly and throw correctly if template literal expression is a `Symbol()`. See [babel/babel#5791](https://github.com/babel/babel/pull/5791).
When `false` or not set, all template literal expressions and quasis are combined with `String.prototype.concat`. It will handle cases with `Symbol.toPrimitive` correctly and throw correctly if template literal expression is a `Symbol()`. See [babel/babel#5791](https://github.com/babel/babel/pull/5791).

This comment has been minimized.

@kedromelon

kedromelon Aug 23, 2017

Contributor

should "See babel/babel#5791" stay or be removed?

@hzoo hzoo merged commit 4080589 into babel:7.0 Aug 28, 2017

4 checks passed

babel/repl REPL preview is available
Details
ci/circleci Your tests passed on CircleCI!
Details
codecov/project 86.09% (target 80%)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@@ -1,3 +0,0 @@
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;

This comment has been minimized.

@hzoo

hzoo Aug 28, 2017

Member

did we mean to delete this tests or are the covered already?

This comment has been minimized.

@kedromelon

kedromelon Aug 28, 2017

Contributor

er, maybe that isn't the same? i might have been mistaken. thought there was some test duplication, but it can be hard to wrap your head around that while working with so many rennamed files 🙃

This comment has been minimized.

@kedromelon

kedromelon Aug 28, 2017

Contributor

i'll have a chance to inspect this a bit more later. will check and submit a PR re-adding these tests if they were mistakenly removed

This comment has been minimized.

@kedromelon

kedromelon Aug 30, 2017

Contributor

submitted #6169

@kedromelon kedromelon deleted the kedromelon:spec-template-literals branch Aug 30, 2017

@hzoo hzoo referenced this pull request Sep 16, 2017

Merged

Babel 7 #23966

2 of 2 tasks complete
@hzoo

This comment has been minimized.

Member

hzoo commented Sep 20, 2017

For documentation, this causes an issue with webpack if you are using dynamic imports with template strings because we turn import(`${a}`) into .concat which webpack doesn't handle.

Issue: webpack/webpack#5674
PR: webpack/webpack#5679

We made it default so the workaround is to just you a normal string concat (don't use template literals) or use loose mode until webpack updates.

{
    presets: [
      require('babel-preset-env'),
    ],
    plugins: [
      [
        require('babel-plugin-transform-es2015-template-literals'), { loose: true },
      ],
    ],
  };

or if you are using loose mode for everything:

{
    presets: [
      [require('babel-preset-env'), { loose: true }],
    ],
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment