Skip to content

Commit

Permalink
Fix name collision issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-mc committed Oct 25, 2018
1 parent 9b14bbf commit ca44ffd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions packages/babel-plugin-proposal-class-properties/src/index.js
Expand Up @@ -192,12 +192,12 @@ export default declare((api, options) => {
const privateMethodHandlerSpec = {
...privateNameHandlerSpec,
get(member) {
const { map, file } = this;
const { map, file, identifier } = this;

return t.callExpression(file.addHelper("classPrivateMethodGet"), [
this.receiver(member),
t.cloneNode(map),
t.identifier(this.name),
t.cloneNode(identifier),
]);
},
set() {
Expand Down Expand Up @@ -354,10 +354,12 @@ export default declare((api, options) => {
} = path.node;

const methodSet = scope.generateUidIdentifier(name);
const methodNameNode = scope.generateUidIdentifier(name);
memberExpressionToFunctions(parentPath, privateNameVisitor, {
name,
map: methodSet,
file: state,
identifier: methodNameNode,
...privateMethodHandlerSpec,
});

Expand All @@ -367,7 +369,6 @@ export default declare((api, options) => {
}),
);

const methodNameNode = t.identifier(name);
const methodValueNode = path.node
? t.functionExpression(methodNameNode, params, body)
: scope.buildUndefinedNode();
Expand Down
@@ -1,4 +1,4 @@
var privateMethod = function privateMethod() {
var _privateMethod2 = function _privateMethod2() {
return 42;
};

Expand All @@ -15,7 +15,7 @@ function () {
value: 0
});

babelHelpers.defineProperty(this, "publicField", babelHelpers.classPrivateMethodGet(this, _privateMethod, privateMethod).call(this));
babelHelpers.defineProperty(this, "publicField", babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this));

_privateMethod.add(this);
}
Expand Down
@@ -1,6 +1,6 @@
var exfiltrated;

var privateMethod = function privateMethod() {};
var _privateMethod2 = function _privateMethod2() {};

var Foo = function Foo() {
"use strict";
Expand All @@ -10,7 +10,7 @@ var Foo = function Foo() {
_privateMethod.add(this);

if (exfiltrated === undefined) {
exfiltrated = babelHelpers.classPrivateMethodGet(this, _privateMethod, privateMethod);
exfiltrated = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2);
}
};

Expand Down
Expand Up @@ -17,9 +17,9 @@ class Foo {
}

getFakeStatus(fakeStatus) {
const fakeGetStatus = this.#getStatus;
const getStatus = this.#getStatus;
return function () {
return fakeGetStatus.call({ status: fakeStatus });
return getStatus.call({ status: fakeStatus });
};
}

Expand Down
@@ -1,4 +1,4 @@
var getStatus = function getStatus() {
var _getStatus2 = function _getStatus2() {
return this.status;
};

Expand All @@ -18,7 +18,7 @@ function () {
babelHelpers.createClass(Foo, [{
key: "getCurrentStatus",
value: function getCurrentStatus() {
return babelHelpers.classPrivateMethodGet(this, _getStatus, getStatus).call(this);
return babelHelpers.classPrivateMethodGet(this, _getStatus, _getStatus2).call(this);
}
}, {
key: "setCurrentStatus",
Expand All @@ -28,7 +28,7 @@ function () {
}, {
key: "getFakeStatus",
value: function getFakeStatus(fakeStatus) {
var fakeGetStatus = babelHelpers.classPrivateMethodGet(this, _getStatus, getStatus);
var fakeGetStatus = babelHelpers.classPrivateMethodGet(this, _getStatus, _getStatus2);
return function () {
return fakeGetStatus.call({
status: fakeStatus
Expand All @@ -40,7 +40,7 @@ function () {
value: function getFakeStatusFunc() {
return {
status: 'fake-status',
getFakeStatus: babelHelpers.classPrivateMethodGet(this, _getStatus, getStatus)
getFakeStatus: babelHelpers.classPrivateMethodGet(this, _getStatus, _getStatus2)
};
}
}]);
Expand Down

0 comments on commit ca44ffd

Please sign in to comment.