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

Use function rather than var to compile private methods #12990

Merged
merged 3 commits into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,7 @@
console.log(class A {
#foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,16 @@
var _foo;

console.log((_foo = babelHelpers.classPrivateFieldLooseKey("foo"), class A {
constructor() {
Object.defineProperty(this, _foo, {
value: _foo2
});
}

method() {
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]();
}

}));

function _foo2() {}
@@ -0,0 +1,7 @@
console.log(class A {
#foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,16 @@
var _foo;

console.log((_foo = babelHelpers.classPrivateFieldLooseKey("foo"), class A {
constructor() {
Object.defineProperty(this, _foo, {
value: _foo2
});
}

method() {
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]();
}

}));

function _foo2() {}
@@ -0,0 +1,7 @@
console.log(class A {
#foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,14 @@
var _foo;

console.log((_foo = new WeakSet(), class A {
constructor() {
_foo.add(this);
}

method() {
babelHelpers.classPrivateMethodGet(this, _foo, _foo2).call(this);
}

}));

function _foo2() {}
Copy link
Member Author

Choose a reason for hiding this comment

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

The output on main is

var _foo, _temp, _foo2;

console.log((_temp = (_foo = new WeakSet(), class A {
  constructor() {
    _foo.add(this);
  }

  method() {
    babelHelpers.classPrivateMethodGet(this, _foo, _foo2).call(this);
  }

}), _foo2 = function _foo2() {}, _temp));

@@ -0,0 +1,7 @@
console.log(class A {
static #foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,12 @@
var _class, _foo, _temp;

console.log((_temp = (_foo = babelHelpers.classPrivateFieldLooseKey("foo"), _class = class A {
method() {
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]();
}

}), Object.defineProperty(_class, _foo, {
value: _foo2
}), _temp));

function _foo2() {}
@@ -0,0 +1,7 @@
console.log(class A {
static #foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,12 @@
var _class, _foo, _temp;

console.log((_temp = (_foo = babelHelpers.classPrivateFieldLooseKey("foo"), _class = class A {
method() {
babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]();
}

}), Object.defineProperty(_class, _foo, {
value: _foo2
}), _temp));

function _foo2() {}
@@ -0,0 +1,7 @@
console.log(class A {
static #foo() {}

method() {
this.#foo();
}
});
@@ -0,0 +1,10 @@
var _class;

console.log(_class = class A {
method() {
babelHelpers.classStaticPrivateMethodGet(this, _class, _foo).call(this);
}

});

function _foo() {}