@babel/plugin-proposal-private-property-in-object
Advanced tools
Comparing version 7.20.5 to 7.21.0-placeholder-for-preset-env
157
lib/index.js
@@ -1,131 +0,34 @@ | ||
"use strict"; | ||
maybeWarn: try { | ||
var stackTraceLimit = Error.stackTraceLimit; | ||
Error.stackTraceLimit = Infinity; | ||
var stack = new Error().stack; | ||
Error.stackTraceLimit = stackTraceLimit; | ||
if (!stack.includes("babel-preset-react-app")) break maybeWarn; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
var _pluginSyntaxPrivatePropertyInObject = require("@babel/plugin-syntax-private-property-in-object"); | ||
var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin"); | ||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); | ||
var _default = (0, _helperPluginUtils.declare)((api, opt) => { | ||
api.assertVersion(7); | ||
const { | ||
types: t, | ||
template | ||
} = api; | ||
const { | ||
loose | ||
} = opt; | ||
// Try this as a fallback, in case it's available in node_modules | ||
module.exports = require("@babel/plugin-transform-private-property-in-object"); | ||
const classWeakSets = new WeakMap(); | ||
const fieldsWeakSets = new WeakMap(); | ||
function unshadow(name, targetScope, scope) { | ||
while (scope !== targetScope) { | ||
if (scope.hasOwnBinding(name)) scope.rename(name); | ||
scope = scope.parent; | ||
} | ||
} | ||
function injectToFieldInit(fieldPath, expr, before = false) { | ||
if (fieldPath.node.value) { | ||
const value = fieldPath.get("value"); | ||
if (before) { | ||
value.insertBefore(expr); | ||
} else { | ||
value.insertAfter(expr); | ||
} | ||
} else { | ||
fieldPath.set("value", t.unaryExpression("void", expr)); | ||
} | ||
} | ||
function injectInitialization(classPath, init) { | ||
let firstFieldPath; | ||
let consturctorPath; | ||
for (const el of classPath.get("body.body")) { | ||
if ((el.isClassProperty() || el.isClassPrivateProperty()) && !el.node.static) { | ||
firstFieldPath = el; | ||
break; | ||
} | ||
if (!consturctorPath && el.isClassMethod({ | ||
kind: "constructor" | ||
})) { | ||
consturctorPath = el; | ||
} | ||
} | ||
if (firstFieldPath) { | ||
injectToFieldInit(firstFieldPath, init, true); | ||
} else { | ||
(0, _helperCreateClassFeaturesPlugin.injectInitialization)(classPath, consturctorPath, [t.expressionStatement(init)]); | ||
} | ||
} | ||
function getWeakSetId(weakSets, outerClass, reference, name = "", inject) { | ||
let id = weakSets.get(reference.node); | ||
if (!id) { | ||
id = outerClass.scope.generateUidIdentifier(`${name || ""} brandCheck`); | ||
weakSets.set(reference.node, id); | ||
inject(reference, template.expression.ast`${t.cloneNode(id)}.add(this)`); | ||
const newExpr = t.newExpression(t.identifier("WeakSet"), []); | ||
(0, _helperAnnotateAsPure.default)(newExpr); | ||
outerClass.insertBefore(template.ast`var ${id} = ${newExpr}`); | ||
} | ||
return t.cloneNode(id); | ||
} | ||
return { | ||
name: "proposal-private-property-in-object", | ||
inherits: _pluginSyntaxPrivatePropertyInObject.default, | ||
pre() { | ||
(0, _helperCreateClassFeaturesPlugin.enableFeature)(this.file, _helperCreateClassFeaturesPlugin.FEATURES.privateIn, loose); | ||
}, | ||
visitor: { | ||
BinaryExpression(path, state) { | ||
const { | ||
node | ||
} = path; | ||
const { | ||
file | ||
} = state; | ||
if (node.operator !== "in") return; | ||
if (!t.isPrivateName(node.left)) return; | ||
const { | ||
name | ||
} = node.left.id; | ||
let privateElement; | ||
const outerClass = path.findParent(path => { | ||
if (!path.isClass()) return false; | ||
privateElement = path.get("body.body").find(({ | ||
node | ||
}) => | ||
t.isPrivate(node) && node.key.id.name === name); | ||
return !!privateElement; | ||
}); | ||
if (outerClass.parentPath.scope.path.isPattern()) { | ||
outerClass.replaceWith(template.ast`(() => ${outerClass.node})()`); | ||
return; | ||
} | ||
if (privateElement.node.type === "ClassPrivateMethod") { | ||
if (privateElement.node.static) { | ||
if (outerClass.node.id) { | ||
unshadow(outerClass.node.id.name, outerClass.scope, path.scope); | ||
} else { | ||
outerClass.set("id", path.scope.generateUidIdentifier("class")); | ||
} | ||
path.replaceWith(template.expression.ast` | ||
${t.cloneNode(outerClass.node.id)} === ${(0, _helperCreateClassFeaturesPlugin.buildCheckInRHS)(node.right, file)} | ||
`); | ||
} else { | ||
var _outerClass$node$id; | ||
const id = getWeakSetId(classWeakSets, outerClass, outerClass, (_outerClass$node$id = outerClass.node.id) == null ? void 0 : _outerClass$node$id.name, injectInitialization); | ||
path.replaceWith(template.expression.ast`${id}.has(${(0, _helperCreateClassFeaturesPlugin.buildCheckInRHS)(node.right, file)})`); | ||
} | ||
} else { | ||
setTimeout(console.warn, 2500, `\ | ||
\x1B[0;33mOne of your dependencies, babel-preset-react-app, is importing the | ||
"@babel/plugin-proposal-private-property-in-object" package without | ||
declaring it in its dependencies. This is currently working because | ||
"@babel/plugin-proposal-private-property-in-object" is already in your | ||
node_modules folder for unrelated reasons, but it \x1B[1mmay break at any time\x1B[0;33m. | ||
const id = getWeakSetId(fieldsWeakSets, outerClass, privateElement, privateElement.node.key.id.name, injectToFieldInit); | ||
path.replaceWith(template.expression.ast`${id}.has(${(0, _helperCreateClassFeaturesPlugin.buildCheckInRHS)(node.right, file)})`); | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
exports.default = _default; | ||
babel-preset-react-app is part of the create-react-app project, \x1B[1mwhich | ||
is not maintianed anymore\x1B[0;33m. It is thus unlikely that this bug will | ||
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to | ||
your devDependencies to work around this error. This will make this message | ||
go away.\x1B[0m | ||
`); | ||
} catch (e) {} | ||
//# sourceMappingURL=index.js.map | ||
throw new Error(`\ | ||
--- PLACEHOLDER PACKAGE --- | ||
This @babel/plugi-proposal-private-property-in-object version is not meant to | ||
be imported. Something is importing | ||
@babel/plugi-proposal-private-property-in-object without declaring it in its | ||
dependencies (or devDependencies) in the package.json file. | ||
Add "@babel/plugin-proposal-private-property-in-object" to your devDependencies | ||
to work around this error. This will make this message go away. | ||
`); |
{ | ||
"name": "@babel/plugin-proposal-private-property-in-object", | ||
"version": "7.20.5", | ||
"version": "7.21.0-placeholder-for-preset-env", | ||
"description": "This plugin transforms checks for a private property in an object", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/babel/babel.git", | ||
"directory": "packages/babel-plugin-proposal-private-property-in-object" | ||
"url": "https://github.com/babel/babel-plugin-proposal-private-property-in-object.git" | ||
}, | ||
@@ -19,15 +18,6 @@ "homepage": "https://babel.dev/docs/en/next/babel-plugin-proposal-private-property-in-object", | ||
], | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^7.18.6", | ||
"@babel/helper-create-class-features-plugin": "^7.20.5", | ||
"@babel/helper-plugin-utils": "^7.20.2", | ||
"@babel/plugin-syntax-private-property-in-object": "^7.14.5" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.20.5", | ||
"@babel/helper-plugin-test-runner": "^7.18.6" | ||
}, | ||
"devDependencies": {}, | ||
"engines": { | ||
@@ -38,2 +28,2 @@ "node": ">=6.9.0" | ||
"type": "commonjs" | ||
} | ||
} |
# @babel/plugin-proposal-private-property-in-object | ||
> ⚠️ This version of the package (`v7.21.0-placeholder-for-preset-env`) is not meant to | ||
> be imported. Use any other version of this plugin or, even better, the | ||
> [@babel/plugin-transform-private-property-in-object](https://babeljs.io/docs/en/babel-plugin-transform-private-property-in-object) package. | ||
> This plugin transforms checks for a private property in an object | ||
@@ -4,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
0
24
16322
30
2
+ Added@babel/core@7.24.4(transitive)
+ Added@babel/generator@7.24.4(transitive)
+ Added@babel/helper-module-transforms@7.23.3(transitive)
+ Added@babel/helper-simple-access@7.22.5(transitive)
+ Added@babel/helper-split-export-declaration@7.22.6(transitive)
+ Added@babel/helper-validator-identifier@7.22.20(transitive)
+ Added@babel/helpers@7.24.4(transitive)
+ Added@babel/highlight@7.24.2(transitive)
+ Added@babel/parser@7.24.4(transitive)
+ Added@babel/traverse@7.24.1(transitive)
+ Added@babel/types@7.24.0(transitive)
+ Addedcaniuse-lite@1.0.30001612(transitive)
+ Addedelectron-to-chromium@1.4.750(transitive)
+ Addedescalade@3.1.2(transitive)
+ Addedupdate-browserslist-db@1.0.13(transitive)
- Removed@babel/helper-plugin-utils@^7.20.2
- Removed@babel/plugin-syntax-private-property-in-object@^7.14.5
- Removed@babel/core@7.24.5(transitive)
- Removed@babel/generator@7.24.5(transitive)
- Removed@babel/helper-annotate-as-pure@7.22.5(transitive)
- Removed@babel/helper-create-class-features-plugin@7.24.5(transitive)
- Removed@babel/helper-member-expression-to-functions@7.24.5(transitive)
- Removed@babel/helper-module-transforms@7.24.5(transitive)
- Removed@babel/helper-optimise-call-expression@7.22.5(transitive)
- Removed@babel/helper-plugin-utils@7.24.5(transitive)
- Removed@babel/helper-replace-supers@7.24.1(transitive)
- Removed@babel/helper-simple-access@7.24.5(transitive)
- Removed@babel/helper-skip-transparent-expression-wrappers@7.22.5(transitive)
- Removed@babel/helper-split-export-declaration@7.24.5(transitive)
- Removed@babel/helper-validator-identifier@7.24.5(transitive)
- Removed@babel/helpers@7.24.5(transitive)
- Removed@babel/highlight@7.24.5(transitive)
- Removed@babel/parser@7.24.5(transitive)
- Removed@babel/plugin-syntax-private-property-in-object@7.14.5(transitive)
- Removed@babel/traverse@7.24.5(transitive)
- Removed@babel/types@7.24.5(transitive)
- Removedcaniuse-lite@1.0.30001615(transitive)