-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
|
04e56c6
to
8ec7656
Compare
if (!t.isStringLiteral(nodes[0]) && considerSecondNode) { | ||
nodes.unshift(t.stringLiteral("")); | ||
} | ||
let root = nodes[0]; | ||
|
||
if (state.opts.spec) { | ||
if (!state.opts.loose) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flip the if statements, please.
8ec7656
to
58391de
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4695/ |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4690/ |
root = buildConcatCallExressions(nodes); | ||
} | ||
} else { | ||
if (state.opts.loose) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jridgewell let me know if i misunderstood what you meant by "flip" here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was it.
^^^ 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also merge else { if (
-> else if (
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 great idea!
`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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
false
or not set, combines all template...
Maybe:
When
false
or not set, all template literal expressions and quasis are combined withString.prototype.concat
.
|
||
**In** | ||
|
||
```javascript | ||
`foo${bar}baz${quux}${1}`; | ||
``` | ||
|
||
**Out** | ||
**Out (without `{"loose": true}`)** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better if we update the example above with the default behavior, and keep this In/Out for loose: true
ecd04bc
to
0781ee3
Compare
|
||
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should "See babel/babel#5791" stay or be removed?
@@ -1,3 +0,0 @@ | |||
var foo = bar`wow\na${ 42 }b ${_.foobar()}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did we mean to delete this tests or are the covered already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
submitted #6169
For documentation, this causes an issue with webpack if you are using dynamic imports with template strings because we turn Issue: webpack/webpack#5674 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 }],
],
}; |
Similar to #6076, change
transform-es2015-template-literals
to default tospec
mode, withloose
optionalWhen 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.