Skip to content
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

IE11 breaks when a static method named `length` is used. #9950

Open
anilanar opened this issue May 6, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@anilanar
Copy link

commented May 6, 2019

Bug Report

Current Behaviour
IE11 breaks when a static method named length is used.

For example, the following class:

class Foo {
  static length() { return 10; }
}

fails to work in IE11 (using preset-env) because apparently length is a non-configurable property of function.

Input Code
https://babeljs.io/repl/#?babili=false&browsers=ie%2011&build=&builtIns=false&spec=false&loose=false&code_lz=MYGwhgzhAEBiD29oG8BQ1oQC5iwS2GhAFMA7AcywAsAKAShXWgF9Vmg&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=script&lineWrap=false&presets=env&prettier=false&targets=&version=7.4.4&externalPlugins=

Expected behaviour/code
I expect Babel to throw an error during transformation if someone uses a static property/method named length. This can be further extended to cases in which babel uses defineProperty and the target object has known non-configurable properties.

Screenshots

image

image

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented May 6, 2019

Hey @anilanar! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented May 6, 2019

class Foo {
  static length() { return 10; }
}

is valid JavaScript code, so Babel should accept it. I think that it's a linter's duty to disallow it.

@anilanar

This comment has been minimized.

Copy link
Author

commented May 7, 2019

I disagree. Babel is supposed to take valid Javascript and output valid Javascript that has the same semantics as the original. If it cannot do so, due to technical limitations, it should fail. The output of static method length is invalid in ES5 because length is a non-configurable property of functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.