@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.9.6 to 7.10.0
@@ -16,3 +16,4 @@ "use strict"; | ||
privateMethods: 1 << 2, | ||
decorators: 1 << 3 | ||
decorators: 1 << 3, | ||
privateIn: 1 << 4 | ||
}); | ||
@@ -28,2 +29,14 @@ exports.FEATURES = FEATURES; | ||
} | ||
if (hasFeature(file, FEATURES.fields) && hasFeature(file, FEATURES.privateMethods) && isLoose(file, FEATURES.fields) !== isLoose(file, FEATURES.privateMethods)) { | ||
throw new Error("'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " + "and @babel/plugin-proposal-private-methods"); | ||
} | ||
if (hasFeature(file, FEATURES.fields) && hasFeature(file, FEATURES.privateIn) && isLoose(file, FEATURES.fields) !== isLoose(file, FEATURES.privateIn)) { | ||
throw new Error("'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " + "and @babel/plugin-proposal-private-property-in-object"); | ||
} | ||
if (hasFeature(file, FEATURES.privateMethods) && hasFeature(file, FEATURES.privateIn) && isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.privateIn)) { | ||
throw new Error("'loose' mode configuration must be the same for both @babel/plugin-proposal-private-methods " + "and @babel/plugin-proposal-private-property-in-object"); | ||
} | ||
} | ||
@@ -56,4 +69,9 @@ | ||
if (hasFeature(file, FEATURES.privateMethods) && hasFeature(file, FEATURES.fields) && isLoose(file, FEATURES.privateMethods) !== isLoose(file, FEATURES.fields)) { | ||
throw path.buildCodeFrameError("'loose' mode configuration must be the same for both @babel/plugin-proposal-class-properties " + "and @babel/plugin-proposal-private-methods"); | ||
if (path.isPrivateName() && path.parentPath.isBinaryExpression({ | ||
operator: "in", | ||
left: path.node | ||
})) { | ||
if (!hasFeature(file, FEATURES.privateIn)) { | ||
throw path.buildCodeFrameError("Private property in checks are not enabled."); | ||
} | ||
} | ||
@@ -60,0 +78,0 @@ |
@@ -91,6 +91,46 @@ "use strict"; | ||
const privateNameVisitor = { | ||
function privateNameVisitorFactory(visitor) { | ||
const privateNameVisitor = Object.assign(Object.assign({}, visitor), {}, { | ||
Class(path) { | ||
const { | ||
privateNamesMap | ||
} = this; | ||
const body = path.get("body.body"); | ||
const visiblePrivateNames = new Map(privateNamesMap); | ||
const redeclared = []; | ||
for (const prop of body) { | ||
if (!prop.isPrivate()) continue; | ||
const { | ||
name | ||
} = prop.node.key.id; | ||
visiblePrivateNames.delete(name); | ||
redeclared.push(name); | ||
} | ||
if (!redeclared.length) { | ||
return; | ||
} | ||
path.get("body").traverse(nestedVisitor, Object.assign(Object.assign({}, this), {}, { | ||
redeclared | ||
})); | ||
path.traverse(privateNameVisitor, Object.assign(Object.assign({}, this), {}, { | ||
privateNamesMap: visiblePrivateNames | ||
})); | ||
path.skipKey("body"); | ||
} | ||
}); | ||
const nestedVisitor = _core.traverse.visitors.merge([Object.assign({}, visitor), _helperReplaceSupers.environmentVisitor]); | ||
return privateNameVisitor; | ||
} | ||
const privateNameVisitor = privateNameVisitorFactory({ | ||
PrivateName(path) { | ||
const { | ||
privateNamesMap | ||
privateNamesMap, | ||
redeclared | ||
} = this; | ||
@@ -101,56 +141,64 @@ const { | ||
} = path; | ||
if (!parentPath.isMemberExpression({ | ||
property: node | ||
})) return; | ||
if (!privateNamesMap.has(node.id.name)) return; | ||
}) && !parentPath.isOptionalMemberExpression({ | ||
property: node | ||
})) { | ||
return; | ||
} | ||
const { | ||
name | ||
} = node.id; | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
this.handle(parentPath); | ||
}, | ||
} | ||
Class(path) { | ||
}); | ||
const privateInVisitor = privateNameVisitorFactory({ | ||
BinaryExpression(path) { | ||
const { | ||
privateNamesMap | ||
operator, | ||
left, | ||
right | ||
} = path.node; | ||
if (operator !== "in") return; | ||
if (!path.get("left").isPrivateName()) return; | ||
const { | ||
loose, | ||
privateNamesMap, | ||
redeclared | ||
} = this; | ||
const body = path.get("body.body"); | ||
const visiblePrivateNames = new Map(privateNamesMap); | ||
const redeclared = []; | ||
const { | ||
name | ||
} = left.id; | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
for (const prop of body) { | ||
if (!prop.isPrivate()) continue; | ||
if (loose) { | ||
const { | ||
name | ||
} = prop.node.key.id; | ||
visiblePrivateNames.delete(name); | ||
redeclared.push(name); | ||
id | ||
} = privateNamesMap.get(name); | ||
path.replaceWith(_core.template.expression.ast` | ||
Object.prototype.hasOwnProperty.call(${right}, ${id}) | ||
`); | ||
return; | ||
} | ||
if (!redeclared.length) { | ||
const { | ||
id, | ||
static: isStatic | ||
} = privateNamesMap.get(name); | ||
if (isStatic) { | ||
path.replaceWith(_core.template.expression.ast`${right} === ${this.classRef}`); | ||
return; | ||
} | ||
path.get("body").traverse(privateNameNestedVisitor, Object.assign({}, this, { | ||
redeclared | ||
})); | ||
path.traverse(privateNameVisitor, Object.assign({}, this, { | ||
privateNamesMap: visiblePrivateNames | ||
})); | ||
path.skipKey("body"); | ||
path.replaceWith(_core.template.expression.ast`${id}.has(${right})`); | ||
} | ||
}; | ||
const privateNameNestedVisitor = _core.traverse.visitors.merge([{ | ||
PrivateName(path) { | ||
const { | ||
redeclared | ||
} = this; | ||
const { | ||
name | ||
} = path.node.id; | ||
if (redeclared.includes(name)) path.skip(); | ||
} | ||
}, { | ||
PrivateName: privateNameVisitor.PrivateName | ||
}, _helperReplaceSupers.environmentVisitor]); | ||
}); | ||
const privateNameHandlerSpec = { | ||
@@ -270,3 +318,8 @@ memoise(member, count) { | ||
this.memoise(member, 1); | ||
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args); | ||
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args, false); | ||
}, | ||
optionalCall(member, args) { | ||
this.memoise(member, 1); | ||
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args, true); | ||
} | ||
@@ -276,3 +329,3 @@ | ||
const privateNameHandlerLoose = { | ||
handle(member) { | ||
get(member) { | ||
const { | ||
@@ -288,7 +341,23 @@ privateNamesMap, | ||
} = member.node.property.id; | ||
member.replaceWith(_core.template.expression`BASE(REF, PROP)[PROP]`({ | ||
return _core.template.expression`BASE(REF, PROP)[PROP]`({ | ||
BASE: file.addHelper("classPrivateFieldLooseBase"), | ||
REF: object, | ||
PROP: privateNamesMap.get(name).id | ||
})); | ||
}); | ||
}, | ||
simpleSet(member) { | ||
return this.get(member); | ||
}, | ||
destructureSet(member) { | ||
return this.get(member); | ||
}, | ||
call(member, args) { | ||
return _core.types.callExpression(this.get(member), args); | ||
}, | ||
optionalCall(member, args) { | ||
return _core.types.optionalCallExpression(this.get(member), args, true); | ||
} | ||
@@ -301,15 +370,14 @@ | ||
const body = path.get("body"); | ||
if (loose) { | ||
body.traverse(privateNameVisitor, Object.assign({ | ||
privateNamesMap, | ||
file: state | ||
}, privateNameHandlerLoose)); | ||
} else { | ||
(0, _helperMemberExpressionToFunctions.default)(body, privateNameVisitor, Object.assign({ | ||
privateNamesMap, | ||
classRef: ref, | ||
file: state | ||
}, privateNameHandlerSpec)); | ||
} | ||
const handler = loose ? privateNameHandlerLoose : privateNameHandlerSpec; | ||
(0, _helperMemberExpressionToFunctions.default)(body, privateNameVisitor, Object.assign({ | ||
privateNamesMap, | ||
classRef: ref, | ||
file: state | ||
}, handler)); | ||
body.traverse(privateInVisitor, { | ||
privateNamesMap, | ||
classRef: ref, | ||
file: state, | ||
loose | ||
}); | ||
} | ||
@@ -357,3 +425,3 @@ | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
initAdded: true | ||
@@ -408,3 +476,3 @@ })); | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
initAdded: true | ||
@@ -436,3 +504,3 @@ })); | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
initAdded: true | ||
@@ -482,3 +550,3 @@ })); | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
initAdded: true | ||
@@ -531,3 +599,3 @@ })); | ||
if (isGetter) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
getterDeclared: true | ||
@@ -539,3 +607,3 @@ })); | ||
if (isSetter) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign(Object.assign({}, privateName), {}, { | ||
setterDeclared: true | ||
@@ -542,0 +610,0 @@ })); |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.9.6", | ||
"version": "7.10.0", | ||
"author": "The Babel Team (https://babeljs.io/team)", | ||
@@ -18,6 +18,6 @@ "license": "MIT", | ||
"@babel/helper-function-name": "^7.9.5", | ||
"@babel/helper-member-expression-to-functions": "^7.8.3", | ||
"@babel/helper-optimise-call-expression": "^7.8.3", | ||
"@babel/helper-member-expression-to-functions": "^7.10.0", | ||
"@babel/helper-optimise-call-expression": "^7.10.0", | ||
"@babel/helper-plugin-utils": "^7.8.3", | ||
"@babel/helper-replace-supers": "^7.9.6", | ||
"@babel/helper-replace-supers": "^7.10.0", | ||
"@babel/helper-split-export-declaration": "^7.8.3" | ||
@@ -29,6 +29,6 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.9.6", | ||
"@babel/core": "^7.10.0", | ||
"@babel/helper-plugin-test-runner": "^7.8.3" | ||
}, | ||
"gitHead": "9c2846bcacc75aa931ea9d556950c2113765d43d" | ||
"gitHead": "5da2440adff6f25579fb6e9a018062291c89416f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42908
1090