Skip to content
This repository was archived by the owner on May 11, 2018. It is now read-only.

If babel doesn't implement it either, don't count against it#30

Closed
hzoo wants to merge 1 commit intomasterfrom
fix-versions
Closed

If babel doesn't implement it either, don't count against it#30
hzoo wants to merge 1 commit intomasterfrom
fix-versions

Conversation

@hzoo
Copy link
Copy Markdown
Member

@hzoo hzoo commented Nov 2, 2016

Didn't get to this at the time and the fix is actually pretty simple I think?

@jdalton mentioned in b80dfaa#commitcomment-19652847 that node 4 supports arrow-functions. It's a similar thing for other transforms which I noticed before but didn't look into. This seems to change a bunch to node 4.

the entries babel is failing at (or w/ non-spec option) arrow functions/correct precedence

arrow functions/no "prototype" property
arrow functions/lexical "super" binding in constructors
arrow functions/lexical "new.target" binding
class/computed names, temporal dead zone
class/extends null
class/new.target
super/statement in constructors
super/expression in constructors
super/constructor calls use correct "new.target" binding
super/super() invokes the correct constructor
destructuring, parameters/new Function() support
destructuring, parameters/defaults, separate scope
destructuring, parameters/defaults, new Function() support
function "name" property/new Function
function "name" property/bound functions
function "name" property/accessor properties
function "name" property/symbol-keyed methods
function "name" property/object methods (class)
function "name" property/isn't writable, is configurable
Unicode code point escapes/in identifiers
default function parameters/temporal dead zone
default function parameters/separate scope
default function parameters/new Function() support
rest parameters/can't be used in setters
rest parameters/new Function() support
spread (...) operator/with sparse arrays, in array literals
spread (...) operator/spreading non-iterables is a runtime error
RegExp "y" and "u" flags / "y" flag
RegExp "y" and "u" flags / "y" flag, lastIndex
template literals/toString conversion
generators/can't use "this" with new
generators/%GeneratorPrototype%.constructor
generators/yield * on non-iterables is a runtime error

Details

"firefox": 3,
"safari": 10,
"node": 6
"chrome": -1,
Copy link
Copy Markdown
Member Author

@hzoo hzoo Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is interesting since it seems as if the transform doesn't actually work or the compat-table is wrong for babel's data?

@hzoo hzoo changed the title If babel doesn't implement it correctly, don't count against it If babel doesn't implement it, don't count against it Nov 2, 2016
@hzoo hzoo changed the title If babel doesn't implement it, don't count against it If babel doesn't implement it either, don't count against it Nov 2, 2016
"firefox": 45,
"safari": 10,
"node": 6
"node": 4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Function.name will be incorrect, and the function-name transform can only fix it for transformed arrow functions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I think that is the case with Node 6 too (but should be fixed in Node 7).

Copy link
Copy Markdown
Member

@jdalton jdalton Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var a = ()=>1
a.name // is '' in v4, 'a' in v6 & v7.
Object.defineProperty(a, 'name', { 'value': 'a', 'configurable': true });
a.name // is 'a' in v4

In my arrow function use at least, name wasn't a stopper. @sindresorhus

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's definitely not a stopper, though it might make things more confusing when debugging, especially for functional React components.

Copy link
Copy Markdown
Member

@jdalton jdalton Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly out of Chrome, Edge, Firefox, and Safari, it's Firefox 49 (current stable) that still displays "" for a.name while the others display "a".

"firefox": 45,
"safari": 10,
"node": 5
"node": 4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 4 doesn't support spread, so non-transformed classes that have super(...args) will not run.

class X extends Y {
  constructor (...args) {
    super(...args)
  }
}

is invalid in node 4 regardless of the other transforms. That example constructor is useless as that is the default implementation, but when transform-class-properties runs, it has to generate a constructor with that content to attach the public property initializers:

class X extends Y {
  z = null
}

transforms to:

class X extends Y {
  constructor (...args) {
    super(...args)
    this.z = null
  }
}

Copy link
Copy Markdown
Member Author

@hzoo hzoo Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to change spread to account for this? Or do we need to check if a user is using spread.. or make another option

Copy link
Copy Markdown
Member Author

@hzoo hzoo Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I guess we'll need to figure out a good way to override this or just not do this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote, a long time ago in phabricator (no idea on the bug number), that transform-rest-spread should, at least, detect if super with spread is being used, and bail if transform-es2015-classes is not also being used.

@hzoo
Copy link
Copy Markdown
Member Author

hzoo commented Mar 29, 2017

Closing for now, doing this may cause more issues

@hzoo hzoo closed this Mar 29, 2017
@jdalton
Copy link
Copy Markdown
Member

jdalton commented Mar 29, 2017

Is there a way to opt-out of transforms? For example, say I don't want to transform arrow functions in Node 4 (I don't care about whatever edge case issue there is) but I still want the general Node 4 bar.

@hzoo
Copy link
Copy Markdown
Member Author

hzoo commented Mar 29, 2017

there's the exclude option

@jdalton
Copy link
Copy Markdown
Member

jdalton commented Mar 29, 2017

Something like

  "presets": [
    ["env", {
      "exclude": ["transform-es2015-arrow-functions"],
      "targets": { "node": 4 }
    }]
  ]

@danez danez deleted the fix-versions branch March 29, 2017 10:01
josephfrazier added a commit to josephfrazier/xregexp that referenced this pull request Apr 17, 2017
Following up on slevithan#108 (comment),
this change adds [Babel] to the build process, with [babel-preset-env] to
ensure browser compatibility. It defaults to supporting all ES5
browsers, but can be tweaked in the future.

To reduce potential merge conflicts, this commit intentionally omits the
resulting changes to `xregexp-all.js`, but they are only formatting
changes anyway (you can use a tool like [prettier-diff] to see this). In
particular, `'use strict';` is prepended to every module in the bundle.
Of course, this shouldn't affect the API or browser compatibility.

The [transform-es2015-literals] plugin is [excluded] to avoid changing
unicode strings. See slevithan#174 (comment)

After this commit, a separate "build" commit should be made that updates
`xregexp-all.js`.

[Babel]: https://babeljs.io/
[babel-preset-env]: https://github.com/babel/babel-preset-env
[prettier-diff]: https://github.com/josephfrazier/prettier-diff
[transform-es2015-literals]: https://www.npmjs.com/package/babel-plugin-transform-es2015-literals
[excluded]: babel/babel-preset-env#30 (comment)
slevithan pushed a commit to slevithan/xregexp that referenced this pull request Apr 19, 2017
Following up on #108 (comment),
this change adds [Babel] to the build process, with [babel-preset-env] to
ensure browser compatibility. It defaults to supporting all ES5
browsers, but can be tweaked in the future.

To reduce potential merge conflicts, this commit intentionally omits the
resulting changes to `xregexp-all.js`, but they are only formatting
changes anyway (you can use a tool like [prettier-diff] to see this). In
particular, `'use strict';` is prepended to every module in the bundle.
Of course, this shouldn't affect the API or browser compatibility.

The [transform-es2015-literals] plugin is [excluded] to avoid changing
unicode strings. See #174 (comment)

After this commit, a separate "build" commit should be made that updates
`xregexp-all.js`.

[Babel]: https://babeljs.io/
[babel-preset-env]: https://github.com/babel/babel-preset-env
[prettier-diff]: https://github.com/josephfrazier/prettier-diff
[transform-es2015-literals]: https://www.npmjs.com/package/babel-plugin-transform-es2015-literals
[excluded]: babel/babel-preset-env#30 (comment)
@hzoo hzoo added i: stale and removed orphaned labels Oct 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants