Skip to content

Commit

Permalink
Fix private dupe name check
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-mc committed Dec 27, 2018
1 parent 26369de commit b6427cc
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/babel-helper-create-class-features-plugin/src/index.js
Expand Up @@ -75,32 +75,37 @@ export function createClassFeaturePlugin({

if (path.isPrivate()) {
const { name } = path.node.key.id;
const getName = `get_${name}`;
const setName = `set_${name}`;
const getName = `get ${name}`;
const setName = `set ${name}`;

if (path.node.kind === "get") {
if (privateNames.has(getName)) {
if (
privateNames.has(getName) ||
(privateNames.has(name) && !privateNames.has(setName))
) {
throw path.buildCodeFrameError("Duplicate private field");
}

privateNames.add(getName);
privateNames.add(getName).add(name);
} else if (path.node.kind === "set") {
if (privateNames.has(setName)) {
if (
privateNames.has(setName) ||
(privateNames.has(name) && !privateNames.has(getName))
) {
throw path.buildCodeFrameError("Duplicate private field");
}

privateNames.add(setName);
}
privateNames.add(setName).add(name);
} else {
if (
privateNames.has(name) &&
(privateNames.has(getName) || privateNames.has(setName))
) {
throw path.buildCodeFrameError("Duplicate private field");
}

if (
privateNames.has(name) &&
!privateNames.has(getName) &&
!privateNames.has(setName)
) {
throw path.buildCodeFrameError("Duplicate private field");
privateNames.add(name);
}

privateNames.add(name);
}

if (path.isClassMethod({ kind: "constructor" })) {
Expand Down

0 comments on commit b6427cc

Please sign in to comment.