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

this before super() is a runtime error, not a static one. #6467

Merged

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues? #6370
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?

This errors were all thrown at compile-time, but they should be runtime errors:

class A extends B {
  constructor() {
    // Missing super
  }
}
class A extends B {
  constructor() {
    super.foo; // super.* before super()
    super();
  }
}
class A extends B {
  constructor() {
    this.foo; // this before super
    super();
  }
}

I have mixed feelings about 14f35c8: it makes the output faster and smaller, but it generates an inconsistent error message (this.foo; super() throws something like "Can't read property foo of undefined" instead of "this is not initialized")

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 12, 2017

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

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Spec Compliance 👓 A type of pull request used for our changelog categories labels Oct 12, 2017
@nicolo-ribaudo
Copy link
Member Author

Rebased

);
if (this.isDerived) {
if (path.parentPath.isMemberExpression({ object: path.node })) {
// In cases like this.foo or this[foo], there is no need to ass
Copy link
Member

Choose a reason for hiding this comment

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

Super small nit: extraneous ass :)

Copy link
Member Author

@nicolo-ribaudo nicolo-ribaudo Dec 5, 2017

Choose a reason for hiding this comment

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

Lol I meant "add" 🤣
I will correct it later and then merge the pr.

Copy link
Member

Choose a reason for hiding this comment

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

@nicolo-ribaudo lol sounds good

@@ -500,11 +500,23 @@ helpers.objectWithoutProperties = defineHelper(`
}
`);

helpers.assertThisInitialized = defineHelper(`
export default function _assertThisInitialized(self) {
if (!self) {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to be more explicit in the test here, like: typeof self === 'undefined'. It's faster.

Copy link
Member Author

@nicolo-ribaudo nicolo-ribaudo Dec 5, 2017

Choose a reason for hiding this comment

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

Which is faster? typeof self === "undefined" or self === void 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

I set up a not too much significative jsperf (https://jsperf.com/x-vs-typeof-vs-void-0/1) and they are almost the same. I'll stick with the second one since it is shorter.

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks!

@@ -36,7 +36,7 @@ const verifyConstructorVisitor = visitors.merge([
ThisExpression(path) {
if (this.isDerived) {
if (path.parentPath.isMemberExpression({ object: path.node })) {
// In cases like this.foo or this[foo], there is no need to ass
Copy link
Member

Choose a reason for hiding this comment

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

👍

@nicolo-ribaudo nicolo-ribaudo merged commit 509dbb7 into babel:master Dec 6, 2017
@nicolo-ribaudo nicolo-ribaudo deleted the class-this-checks-runtime branch December 6, 2017 05:47
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Spec Compliance 👓 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants