@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.16.7 to 7.16.10
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.isLoose = isLoose; | ||
exports.verifyUsedFeatures = verifyUsedFeatures; | ||
exports.shouldTransform = shouldTransform; | ||
@@ -86,39 +86,68 @@ var _decorators = require("./decorators"); | ||
function verifyUsedFeatures(path, file) { | ||
function shouldTransform(path, file) { | ||
let decoratorPath = null; | ||
let publicFieldPath = null; | ||
let privateFieldPath = null; | ||
let privateMethodPath = null; | ||
let staticBlockPath = null; | ||
if ((0, _decorators.hasOwnDecorators)(path.node)) { | ||
if (!hasFeature(file, FEATURES.decorators)) { | ||
throw path.buildCodeFrameError("Decorators are not enabled." + "\nIf you are using " + '["@babel/plugin-proposal-decorators", { "legacy": true }], ' + 'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' + "and enable loose mode, like so:\n" + '\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' + '\t["@babel/plugin-proposal-class-properties", { "loose": true }]'); | ||
decoratorPath = path.get("decorators.0"); | ||
} | ||
for (const el of path.get("body.body")) { | ||
if (!decoratorPath && (0, _decorators.hasOwnDecorators)(el.node)) { | ||
decoratorPath = el.get("decorators.0"); | ||
} | ||
if (path.isPrivate()) { | ||
throw path.buildCodeFrameError(`Private ${path.isClassMethod() ? "methods" : "fields"} in decorated classes are not supported yet.`); | ||
if (!publicFieldPath && el.isClassProperty()) { | ||
publicFieldPath = el; | ||
} | ||
} | ||
if (path.isClassPrivateMethod != null && path.isClassPrivateMethod()) { | ||
if (!hasFeature(file, FEATURES.privateMethods)) { | ||
throw path.buildCodeFrameError("Class private methods are not enabled."); | ||
if (!privateFieldPath && el.isClassPrivateProperty()) { | ||
privateFieldPath = el; | ||
} | ||
} | ||
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."); | ||
if (!privateMethodPath && el.isClassPrivateMethod != null && el.isClassPrivateMethod()) { | ||
privateMethodPath = el; | ||
} | ||
} | ||
if (path.isProperty()) { | ||
if (!hasFeature(file, FEATURES.fields)) { | ||
throw path.buildCodeFrameError("Class fields are not enabled."); | ||
if (!staticBlockPath && el.isStaticBlock != null && el.isStaticBlock()) { | ||
staticBlockPath = el; | ||
} | ||
} | ||
if (path.isStaticBlock != null && path.isStaticBlock()) { | ||
if (!hasFeature(file, FEATURES.staticBlocks)) { | ||
throw path.buildCodeFrameError("Static class blocks are not enabled. " + "Please add `@babel/plugin-proposal-class-static-block` to your configuration."); | ||
} | ||
if (decoratorPath && privateFieldPath) { | ||
throw privateFieldPath.buildCodeFrameError("Private fields in decorated classes are not supported yet."); | ||
} | ||
if (decoratorPath && privateMethodPath) { | ||
throw privateMethodPath.buildCodeFrameError("Private methods in decorated classes are not supported yet."); | ||
} | ||
if (decoratorPath && !hasFeature(file, FEATURES.decorators)) { | ||
throw path.buildCodeFrameError("Decorators are not enabled." + "\nIf you are using " + '["@babel/plugin-proposal-decorators", { "legacy": true }], ' + 'make sure it comes *before* "@babel/plugin-proposal-class-properties" ' + "and enable loose mode, like so:\n" + '\t["@babel/plugin-proposal-decorators", { "legacy": true }]\n' + '\t["@babel/plugin-proposal-class-properties", { "loose": true }]'); | ||
} | ||
if (privateMethodPath && !hasFeature(file, FEATURES.privateMethods)) { | ||
throw privateMethodPath.buildCodeFrameError("Class private methods are not enabled. " + "Please add `@babel/plugin-proposal-private-method` to your configuration."); | ||
} | ||
if ((publicFieldPath || privateFieldPath) && !hasFeature(file, FEATURES.fields) && !hasFeature(file, FEATURES.privateMethods)) { | ||
throw path.buildCodeFrameError("Class fields are not enabled. " + "Please add `@babel/plugin-proposal-class-properties` to your configuration."); | ||
} | ||
if (staticBlockPath && !hasFeature(file, FEATURES.staticBlocks)) { | ||
throw path.buildCodeFrameError("Static class blocks are not enabled. " + "Please add `@babel/plugin-proposal-class-static-block` to your configuration."); | ||
} | ||
if (decoratorPath || privateMethodPath || staticBlockPath) { | ||
return true; | ||
} | ||
if ((publicFieldPath || privateFieldPath) && hasFeature(file, FEATURES.fields)) { | ||
return true; | ||
} | ||
return false; | ||
} |
@@ -42,3 +42,3 @@ "use strict"; | ||
const version = "7.16.7".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const version = "7.16.10".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const versionKey = "@babel/plugin-class-features/version"; | ||
@@ -91,3 +91,3 @@ | ||
if (this.file.get(versionKey) !== version) return; | ||
(0, _features.verifyUsedFeatures)(path, this.file); | ||
if (!(0, _features.shouldTransform)(path, this.file)) return; | ||
if (path.isClassDeclaration()) (0, _typescript.assertFieldTransformed)(path); | ||
@@ -104,4 +104,2 @@ const loose = (0, _features.isLoose)(this.file, feature); | ||
for (const path of body.get("body")) { | ||
(0, _features.verifyUsedFeatures)(path, this.file); | ||
if ((path.isClassProperty() || path.isClassMethod()) && path.node.computed) { | ||
@@ -213,12 +211,2 @@ computedPaths.push(path); | ||
PrivateName(path) { | ||
if (this.file.get(versionKey) !== version || path.parentPath.isPrivate({ | ||
key: path.node | ||
})) { | ||
return; | ||
} | ||
throw path.buildCodeFrameError(`Unknown PrivateName "${path}"`); | ||
}, | ||
ExportDefaultDeclaration(path) { | ||
@@ -225,0 +213,0 @@ if (this.file.get(versionKey) !== version) return; |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.16.7", | ||
"version": "7.16.10", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -33,6 +33,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@babel/core": "^7.16.7", | ||
"@babel/core": "^7.16.10", | ||
"@babel/helper-plugin-test-runner": "^7.16.7", | ||
"@babel/plugin-syntax-class-static-block": "^7.14.5", | ||
"@babel/preset-env": "^7.16.7" | ||
"@babel/preset-env": "^7.16.10" | ||
}, | ||
@@ -39,0 +39,0 @@ "engines": { |
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
52762
1319