@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.22.9 to 8.0.0-alpha.0
@@ -1,16 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.buildDecoratedClass = buildDecoratedClass; | ||
exports.hasDecorators = hasDecorators; | ||
exports.hasOwnDecorators = hasOwnDecorators; | ||
var _core = require("@babel/core"); | ||
var _helperReplaceSupers = require("@babel/helper-replace-supers"); | ||
var _helperFunctionName = require("@babel/helper-function-name"); | ||
function hasOwnDecorators(node) { | ||
return !!(node.decorators && node.decorators.length); | ||
import { types as t, template } from "@babel/core"; | ||
import ReplaceSupers from "@babel/helper-replace-supers"; | ||
import nameFunction from "@babel/helper-function-name"; | ||
export function hasOwnDecorators(node) { | ||
return !!node.decorators?.length; | ||
} | ||
function hasDecorators(node) { | ||
export function hasDecorators(node) { | ||
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators); | ||
@@ -20,6 +12,6 @@ } | ||
if (!value) return null; | ||
return _core.types.objectProperty(_core.types.identifier(key), value); | ||
return t.objectProperty(t.identifier(key), value); | ||
} | ||
function method(key, body) { | ||
return _core.types.objectMethod("method", _core.types.identifier(key), [], _core.types.blockStatement(body)); | ||
return t.objectMethod("method", t.identifier(key), [], t.blockStatement(body)); | ||
} | ||
@@ -29,3 +21,3 @@ function takeDecorators(node) { | ||
if (node.decorators && node.decorators.length > 0) { | ||
result = _core.types.arrayExpression(node.decorators.map(decorator => decorator.expression)); | ||
result = t.arrayExpression(node.decorators.map(decorator => decorator.expression)); | ||
} | ||
@@ -38,6 +30,6 @@ node.decorators = undefined; | ||
return node.key; | ||
} else if (_core.types.isIdentifier(node.key)) { | ||
return _core.types.stringLiteral(node.key.name); | ||
} else if (t.isIdentifier(node.key)) { | ||
return t.stringLiteral(node.key.name); | ||
} else { | ||
return _core.types.stringLiteral(String(node.key.value)); | ||
return t.stringLiteral(String(node.key.value)); | ||
} | ||
@@ -61,3 +53,3 @@ } | ||
if (!path.isTSDeclareMethod()) { | ||
new _helperReplaceSupers.default({ | ||
new ReplaceSupers({ | ||
methodPath: path, | ||
@@ -70,7 +62,7 @@ objectRef: classRef, | ||
} | ||
const properties = [prop("kind", _core.types.stringLiteral(_core.types.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean); | ||
if (_core.types.isClassMethod(node)) { | ||
const properties = [prop("kind", t.stringLiteral(t.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && t.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean); | ||
if (t.isClassMethod(node)) { | ||
const id = node.computed ? null : node.key; | ||
const transformed = _core.types.toExpression(node); | ||
properties.push(prop("value", (0, _helperFunctionName.default)({ | ||
const transformed = t.toExpression(node); | ||
properties.push(prop("value", nameFunction({ | ||
node: transformed, | ||
@@ -80,4 +72,4 @@ id, | ||
}) || transformed)); | ||
} else if (_core.types.isClassProperty(node) && node.value) { | ||
properties.push(method("value", _core.template.statements.ast`return ${node.value}`)); | ||
} else if (t.isClassProperty(node) && node.value) { | ||
properties.push(method("value", template.statements.ast`return ${node.value}`)); | ||
} else { | ||
@@ -87,3 +79,3 @@ properties.push(prop("value", scope.buildUndefinedNode())); | ||
path.remove(); | ||
return _core.types.objectExpression(properties); | ||
return t.objectExpression(properties); | ||
} | ||
@@ -93,3 +85,3 @@ function addDecorateHelper(file) { | ||
} | ||
function buildDecoratedClass(ref, path, elements, file) { | ||
export function buildDecoratedClass(ref, path, elements, file) { | ||
const { | ||
@@ -106,3 +98,3 @@ node, | ||
node.type = "ClassDeclaration"; | ||
if (!node.id) node.id = _core.types.cloneNode(ref); | ||
if (!node.id) node.id = t.cloneNode(ref); | ||
let superId; | ||
@@ -114,9 +106,9 @@ if (superClass) { | ||
const classDecorators = takeDecorators(node); | ||
const definitions = _core.types.arrayExpression(elements.filter(element => !element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, path))); | ||
const wrapperCall = _core.template.expression.ast` | ||
const definitions = t.arrayExpression(elements.filter(element => !element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, path))); | ||
const wrapperCall = template.expression.ast` | ||
${addDecorateHelper(file)}( | ||
${classDecorators || _core.types.nullLiteral()}, | ||
function (${initializeId}, ${superClass ? _core.types.cloneNode(superId) : null}) { | ||
${classDecorators || t.nullLiteral()}, | ||
function (${initializeId}, ${superClass ? t.cloneNode(superId) : null}) { | ||
${node} | ||
return { F: ${_core.types.cloneNode(node.id)}, d: ${definitions} }; | ||
return { F: ${t.cloneNode(node.id)}, d: ${definitions} }; | ||
}, | ||
@@ -127,3 +119,3 @@ ${superClass} | ||
if (!isStrict) { | ||
wrapperCall.arguments[1].body.directives.push(_core.types.directive(_core.types.directiveLiteral("use strict"))); | ||
wrapperCall.arguments[1].body.directives.push(t.directive(t.directiveLiteral("use strict"))); | ||
} | ||
@@ -133,7 +125,7 @@ let replacement = wrapperCall; | ||
if (isDeclaration) { | ||
replacement = _core.template.statement.ast`let ${ref} = ${wrapperCall}`; | ||
replacement = template.statement.ast`let ${ref} = ${wrapperCall}`; | ||
classPathDesc = "declarations.0.init." + classPathDesc; | ||
} | ||
return { | ||
instanceNodes: [_core.template.statement.ast`${_core.types.cloneNode(initializeId)}(this)`], | ||
instanceNodes: [template.statement.ast`${t.cloneNode(initializeId)}(this)`], | ||
wrapClass(path) { | ||
@@ -140,0 +132,0 @@ path.replaceWith(replacement); |
@@ -1,19 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.FEATURES = void 0; | ||
exports.enableFeature = enableFeature; | ||
exports.isLoose = isLoose; | ||
exports.shouldTransform = shouldTransform; | ||
var _decorators = require("./decorators"); | ||
const FEATURES = Object.freeze({ | ||
import { hasOwnDecorators } from "./decorators.js"; | ||
export const FEATURES = Object.freeze({ | ||
fields: 1 << 1, | ||
privateMethods: 1 << 2, | ||
decorators: 1 << 3, | ||
privateIn: 1 << 4, | ||
staticBlocks: 1 << 5 | ||
privateIn: 1 << 3, | ||
staticBlocks: 1 << 4 | ||
}); | ||
exports.FEATURES = FEATURES; | ||
const featuresSameLoose = new Map([[FEATURES.fields, "@babel/plugin-transform-class-properties"], [FEATURES.privateMethods, "@babel/plugin-transform-private-methods"], [FEATURES.privateIn, "@babel/plugin-transform-private-property-in-object"]]); | ||
@@ -23,3 +12,3 @@ const featuresKey = "@babel/plugin-class-features/featuresKey"; | ||
const looseLowPriorityKey = "@babel/plugin-class-features/looseLowPriorityKey/#__internal__@babel/preset-env__please-overwrite-loose-instead-of-throwing"; | ||
function enableFeature(file, feature, loose) { | ||
export function enableFeature(file, feature, loose) { | ||
if (!hasFeature(file, feature) || canIgnoreLoose(file, feature)) { | ||
@@ -63,3 +52,3 @@ file.set(featuresKey, file.get(featuresKey) | feature); | ||
} | ||
function isLoose(file, feature) { | ||
export function isLoose(file, feature) { | ||
return !!(file.get(looseKey) & feature); | ||
@@ -74,3 +63,3 @@ } | ||
} | ||
function shouldTransform(path, file) { | ||
export function shouldTransform(path, file) { | ||
let decoratorPath = null; | ||
@@ -81,7 +70,7 @@ let publicFieldPath = null; | ||
let staticBlockPath = null; | ||
if ((0, _decorators.hasOwnDecorators)(path.node)) { | ||
if (hasOwnDecorators(path.node)) { | ||
decoratorPath = path.get("decorators.0"); | ||
} | ||
for (const el of path.get("body.body")) { | ||
if (!decoratorPath && (0, _decorators.hasOwnDecorators)(el.node)) { | ||
if (!decoratorPath && hasOwnDecorators(el.node)) { | ||
decoratorPath = el.get("decorators.0"); | ||
@@ -95,6 +84,6 @@ } | ||
} | ||
if (!privateMethodPath && el.isClassPrivateMethod != null && el.isClassPrivateMethod()) { | ||
if (!privateMethodPath && el.isClassPrivateMethod?.()) { | ||
privateMethodPath = el; | ||
} | ||
if (!staticBlockPath && el.isStaticBlock != null && el.isStaticBlock()) { | ||
if (!staticBlockPath && el.isStaticBlock?.()) { | ||
staticBlockPath = el; | ||
@@ -101,0 +90,0 @@ } |
@@ -1,20 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.buildCheckInRHS = buildCheckInRHS; | ||
exports.buildFieldsInitNodes = buildFieldsInitNodes; | ||
exports.buildPrivateNamesMap = buildPrivateNamesMap; | ||
exports.buildPrivateNamesNodes = buildPrivateNamesNodes; | ||
exports.transformPrivateNamesUsage = transformPrivateNamesUsage; | ||
var _core = require("@babel/core"); | ||
var _helperReplaceSupers = require("@babel/helper-replace-supers"); | ||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor"); | ||
var _helperMemberExpressionToFunctions = require("@babel/helper-member-expression-to-functions"); | ||
var _helperOptimiseCallExpression = require("@babel/helper-optimise-call-expression"); | ||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); | ||
var _helperSkipTransparentExpressionWrappers = require("@babel/helper-skip-transparent-expression-wrappers"); | ||
var ts = require("./typescript"); | ||
function buildPrivateNamesMap(props) { | ||
import { template, traverse, types as t } from "@babel/core"; | ||
import ReplaceSupers from "@babel/helper-replace-supers"; | ||
import environmentVisitor from "@babel/helper-environment-visitor"; | ||
import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions"; | ||
import optimiseCall from "@babel/helper-optimise-call-expression"; | ||
import annotateAsPure from "@babel/helper-annotate-as-pure"; | ||
import { skipTransparentExprWrapperNodes } from "@babel/helper-skip-transparent-expression-wrappers"; | ||
import * as ts from "./typescript.js"; | ||
export function buildPrivateNamesMap(props) { | ||
const privateNamesMap = new Map(); | ||
@@ -45,3 +35,3 @@ for (const prop of props) { | ||
} | ||
function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) { | ||
export function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) { | ||
const initNodes = []; | ||
@@ -56,14 +46,14 @@ for (const [name, value] of privateNamesMap) { | ||
const isAccessor = getId || setId; | ||
const id = _core.types.cloneNode(value.id); | ||
const id = t.cloneNode(value.id); | ||
let init; | ||
if (privateFieldsAsProperties) { | ||
init = _core.types.callExpression(state.addHelper("classPrivateFieldLooseKey"), [_core.types.stringLiteral(name)]); | ||
init = t.callExpression(state.addHelper("classPrivateFieldLooseKey"), [t.stringLiteral(name)]); | ||
} else if (privateFieldsAsSymbols) { | ||
init = _core.types.callExpression(_core.types.identifier("Symbol"), [_core.types.stringLiteral(name)]); | ||
init = t.callExpression(t.identifier("Symbol"), [t.stringLiteral(name)]); | ||
} else if (!isStatic) { | ||
init = _core.types.newExpression(_core.types.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []); | ||
init = t.newExpression(t.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []); | ||
} | ||
if (init) { | ||
(0, _helperAnnotateAsPure.default)(init); | ||
initNodes.push(_core.template.statement.ast`var ${id} = ${init}`); | ||
annotateAsPure(init); | ||
initNodes.push(template.statement.ast`var ${id} = ${init}`); | ||
} | ||
@@ -74,3 +64,3 @@ } | ||
function privateNameVisitorFactory(visitor) { | ||
const nestedVisitor = _core.traverse.visitors.merge([Object.assign({}, visitor), _helperEnvironmentVisitor.default]); | ||
const nestedVisitor = traverse.visitors.merge([Object.assign({}, visitor), environmentVisitor]); | ||
const privateNameVisitor = Object.assign({}, visitor, { | ||
@@ -134,4 +124,3 @@ Class(path) { | ||
function unshadow(name, scope, innerBinding) { | ||
while ((_scope = scope) != null && _scope.hasBinding(name) && !scope.bindingIdentifierEquals(name, innerBinding)) { | ||
var _scope; | ||
while (scope?.hasBinding(name) && !scope.bindingIdentifierEquals(name, innerBinding)) { | ||
scope.rename(name); | ||
@@ -141,5 +130,5 @@ scope = scope.parent; | ||
} | ||
function buildCheckInRHS(rhs, file, inRHSIsObject) { | ||
if (inRHSIsObject || !(file.availableHelper != null && file.availableHelper("checkInRHS"))) return rhs; | ||
return _core.types.callExpression(file.addHelper("checkInRHS"), [rhs]); | ||
export function buildCheckInRHS(rhs, file, inRHSIsObject) { | ||
if (inRHSIsObject || !file.availableHelper?.("checkInRHS")) return rhs; | ||
return t.callExpression(file.addHelper("checkInRHS"), [rhs]); | ||
} | ||
@@ -156,3 +145,3 @@ const privateInVisitor = privateNameVisitorFactory({ | ||
if (operator !== "in") return; | ||
if (!_core.types.isPrivateName(left)) return; | ||
if (!t.isPrivateName(left)) return; | ||
const { | ||
@@ -173,4 +162,4 @@ privateFieldsAsProperties, | ||
} = privateNamesMap.get(name); | ||
path.replaceWith(_core.template.expression.ast` | ||
Object.prototype.hasOwnProperty.call(${buildCheckInRHS(right, file)}, ${_core.types.cloneNode(id)}) | ||
path.replaceWith(template.expression.ast` | ||
Object.prototype.hasOwnProperty.call(${buildCheckInRHS(right, file)}, ${t.cloneNode(id)}) | ||
`); | ||
@@ -184,6 +173,6 @@ return; | ||
if (isStatic) { | ||
path.replaceWith(_core.template.expression.ast`${buildCheckInRHS(right, file)} === ${_core.types.cloneNode(this.classRef)}`); | ||
path.replaceWith(template.expression.ast`${buildCheckInRHS(right, file)} === ${t.cloneNode(this.classRef)}`); | ||
return; | ||
} | ||
path.replaceWith(_core.template.expression.ast`${_core.types.cloneNode(id)}.has(${buildCheckInRHS(right, file)})`); | ||
path.replaceWith(template.expression.ast`${t.cloneNode(id)}.has(${buildCheckInRHS(right, file)})`); | ||
} | ||
@@ -210,5 +199,5 @@ }); | ||
if (this.memoiser.has(object)) { | ||
return _core.types.cloneNode(this.memoiser.get(object)); | ||
return t.cloneNode(this.memoiser.get(object)); | ||
} | ||
return _core.types.cloneNode(object); | ||
return t.cloneNode(object); | ||
}, | ||
@@ -237,3 +226,3 @@ get(member) { | ||
unshadow(classRef.name, member.scope, innerBinding); | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]); | ||
return t.callExpression(file.addHelper(helperName), [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)]); | ||
} | ||
@@ -244,15 +233,15 @@ if (isMethod) { | ||
if (file.availableHelper("writeOnlyError")) { | ||
return _core.types.sequenceExpression([this.receiver(member), _core.types.callExpression(file.addHelper("writeOnlyError"), [_core.types.stringLiteral(`#${name}`)])]); | ||
return t.sequenceExpression([this.receiver(member), t.callExpression(file.addHelper("writeOnlyError"), [t.stringLiteral(`#${name}`)])]); | ||
} | ||
console.warn(`@babel/helpers is outdated, update it to silence this warning.`); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]); | ||
return t.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), t.cloneNode(id)]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), _core.types.cloneNode(id), _core.types.cloneNode(methodId)]); | ||
return t.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), t.cloneNode(id), t.cloneNode(methodId)]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]); | ||
return t.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), t.cloneNode(id)]); | ||
}, | ||
boundGet(member) { | ||
this.memoise(member, 1); | ||
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), [this.receiver(member)]); | ||
return t.callExpression(t.memberExpression(this.get(member), t.identifier("bind")), [this.receiver(member)]); | ||
}, | ||
@@ -278,11 +267,11 @@ set(member, value) { | ||
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodSet" : "classStaticPrivateFieldSpecSet"; | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id), value]); | ||
return t.callExpression(file.addHelper(helperName), [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id), value]); | ||
} | ||
if (isMethod) { | ||
if (setId) { | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]); | ||
return t.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), t.cloneNode(id), value]); | ||
} | ||
return _core.types.sequenceExpression([this.receiver(member), value, _core.types.callExpression(file.addHelper("readOnlyError"), [_core.types.stringLiteral(`#${name}`)])]); | ||
return t.sequenceExpression([this.receiver(member), value, t.callExpression(file.addHelper("readOnlyError"), [t.stringLiteral(`#${name}`)])]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]); | ||
return t.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), t.cloneNode(id), value]); | ||
}, | ||
@@ -305,16 +294,16 @@ destructureSet(member) { | ||
var helper = file.addHelper("classStaticPrivateFieldDestructureSet"); | ||
} catch (_unused) { | ||
} catch { | ||
throw new Error("Babel can not transpile `[C.#p] = [0]` with @babel/helpers < 7.13.10, \n" + "please update @babel/helpers to the latest version."); | ||
} | ||
return _core.types.memberExpression(_core.types.callExpression(helper, [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]), _core.types.identifier("value")); | ||
return t.memberExpression(t.callExpression(helper, [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)]), t.identifier("value")); | ||
} | ||
return _core.types.memberExpression(_core.types.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), _core.types.cloneNode(id)]), _core.types.identifier("value")); | ||
return t.memberExpression(t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), t.cloneNode(id)]), t.identifier("value")); | ||
}, | ||
call(member, args) { | ||
this.memoise(member, 1); | ||
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args, false); | ||
return optimiseCall(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); | ||
return optimiseCall(this.get(member), this.receiver(member), args, true); | ||
}, | ||
@@ -337,6 +326,6 @@ delete() { | ||
} = member.node.property.id; | ||
return _core.template.expression`BASE(REF, PROP)[PROP]`({ | ||
return template.expression`BASE(REF, PROP)[PROP]`({ | ||
BASE: file.addHelper("classPrivateFieldLooseBase"), | ||
REF: _core.types.cloneNode(object), | ||
PROP: _core.types.cloneNode(privateNamesMap.get(name).id) | ||
REF: t.cloneNode(object), | ||
PROP: t.cloneNode(privateNamesMap.get(name).id) | ||
}); | ||
@@ -348,3 +337,3 @@ }, | ||
boundGet(member) { | ||
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), [_core.types.cloneNode(member.node.object)]); | ||
return t.callExpression(t.memberExpression(this.get(member), t.identifier("bind")), [t.cloneNode(member.node.object)]); | ||
}, | ||
@@ -358,6 +347,6 @@ simpleSet(member) { | ||
call(member, args) { | ||
return _core.types.callExpression(this.get(member), args); | ||
return t.callExpression(this.get(member), args); | ||
}, | ||
optionalCall(member, args) { | ||
return _core.types.optionalCallExpression(this.get(member), args, true); | ||
return t.optionalCallExpression(this.get(member), args, true); | ||
}, | ||
@@ -368,3 +357,3 @@ delete() { | ||
}; | ||
function transformPrivateNamesUsage(ref, path, privateNamesMap, { | ||
export function transformPrivateNamesUsage(ref, path, privateNamesMap, { | ||
privateFieldsAsProperties, | ||
@@ -377,3 +366,3 @@ noDocumentAll, | ||
const handler = privateFieldsAsProperties ? privateNameHandlerLoose : privateNameHandlerSpec; | ||
(0, _helperMemberExpressionToFunctions.default)(body, privateNameVisitor, Object.assign({ | ||
memberExpressionToFunctions(body, privateNameVisitor, Object.assign({ | ||
privateNamesMap, | ||
@@ -399,4 +388,4 @@ classRef: ref, | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(_core.template.statement.ast` | ||
Object.defineProperty(${ref}, ${_core.types.cloneNode(id)}, { | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${t.cloneNode(id)}, { | ||
// configurable is false by default | ||
@@ -414,16 +403,7 @@ // enumerable is false by default | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
{ | ||
if (!state.availableHelper("classPrivateFieldInitSpec")) { | ||
return inheritPropComments(_core.template.statement.ast`${_core.types.cloneNode(id)}.set(${ref}, { | ||
// configurable is always false for private elements | ||
// enumerable is always false for private elements | ||
writable: true, | ||
value: ${value}, | ||
})`, prop); | ||
} | ||
} | ||
; | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${t.thisExpression()}, | ||
${t.cloneNode(id)}, | ||
{ | ||
@@ -449,4 +429,4 @@ writable: true, | ||
})); | ||
return inheritPropComments(_core.template.statement.ast` | ||
var ${_core.types.cloneNode(id)} = { | ||
return inheritPropComments(template.statement.ast` | ||
var ${t.cloneNode(id)} = { | ||
// configurable is false by default | ||
@@ -461,4 +441,4 @@ // enumerable is false by default | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(_core.template.statement.ast` | ||
var ${_core.types.cloneNode(id)} = { | ||
return inheritPropComments(template.statement.ast` | ||
var ${t.cloneNode(id)} = { | ||
// configurable is false by default | ||
@@ -482,3 +462,3 @@ // enumerable is false by default | ||
if (methodId) { | ||
return inheritPropComments(_core.template.statement.ast` | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -497,3 +477,3 @@ // configurable is false by default | ||
})); | ||
return inheritPropComments(_core.template.statement.ast` | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -533,16 +513,7 @@ // configurable is false by default | ||
})); | ||
{ | ||
if (!state.availableHelper("classPrivateFieldInitSpec")) { | ||
return inheritPropComments(_core.template.statement.ast` | ||
${id}.set(${ref}, { | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}); | ||
`, prop); | ||
} | ||
} | ||
; | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${t.thisExpression()}, | ||
${t.cloneNode(id)}, | ||
{ | ||
@@ -559,11 +530,7 @@ get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
} = privateName; | ||
{ | ||
if (!state.availableHelper("classPrivateMethodInitSpec")) { | ||
return inheritPropComments(_core.template.statement.ast`${id}.add(${ref})`, prop); | ||
} | ||
} | ||
; | ||
const helper = state.addHelper("classPrivateMethodInitSpec"); | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)} | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${t.thisExpression()}, | ||
${t.cloneNode(id)} | ||
)`, prop); | ||
@@ -577,3 +544,3 @@ } | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(ref, key, computed || _core.types.isLiteral(key)), value)), prop); | ||
return inheritPropComments(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value)), prop); | ||
} | ||
@@ -586,3 +553,3 @@ function buildPublicFieldInitSpec(ref, prop, state) { | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(_core.types.expressionStatement(_core.types.callExpression(state.addHelper("defineProperty"), [ref, computed || _core.types.isLiteral(key) ? key : _core.types.stringLiteral(key.name), value])), prop); | ||
return inheritPropComments(t.expressionStatement(t.callExpression(state.addHelper("defineProperty"), [ref, computed || t.isLiteral(key) ? key : t.stringLiteral(key.name), value])), prop); | ||
} | ||
@@ -604,3 +571,3 @@ function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) { | ||
})); | ||
return inheritPropComments(_core.template.statement.ast` | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -615,3 +582,3 @@ // configurable is false by default | ||
} | ||
return inheritPropComments(_core.template.statement.ast` | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -658,5 +625,5 @@ // configurable is false by default | ||
} | ||
return inheritPropComments(_core.types.functionDeclaration(_core.types.cloneNode(declId), params, body, generator, async), prop); | ||
return inheritPropComments(t.functionDeclaration(t.cloneNode(declId), params, body, generator, async), prop); | ||
} | ||
const thisContextVisitor = _core.traverse.visitors.merge([{ | ||
const thisContextVisitor = traverse.visitors.merge([{ | ||
UnaryExpression(path) { | ||
@@ -667,5 +634,5 @@ const { | ||
if (node.operator === "delete") { | ||
const argument = (0, _helperSkipTransparentExpressionWrappers.skipTransparentExprWrapperNodes)(node.argument); | ||
if (_core.types.isThisExpression(argument)) { | ||
path.replaceWith(_core.types.booleanLiteral(true)); | ||
const argument = skipTransparentExprWrapperNodes(node.argument); | ||
if (t.isThisExpression(argument)) { | ||
path.replaceWith(t.booleanLiteral(true)); | ||
} | ||
@@ -676,3 +643,3 @@ } | ||
state.needsClassRef = true; | ||
path.replaceWith(_core.types.cloneNode(state.classRef)); | ||
path.replaceWith(t.cloneNode(state.classRef)); | ||
}, | ||
@@ -688,3 +655,3 @@ MetaProperty(path) { | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
}, environmentVisitor]); | ||
const innerReferencesVisitor = { | ||
@@ -698,4 +665,3 @@ ReferencedIdentifier(path, state) { | ||
}; | ||
function replaceThisContext(path, ref, getSuperRef, file, isStaticBlock, constantSuper, innerBindingRef) { | ||
var _state$classRef; | ||
function replaceThisContext(path, ref, innerBindingRef) { | ||
const state = { | ||
@@ -706,18 +672,6 @@ classRef: ref, | ||
}; | ||
const replacer = new _helperReplaceSupers.default({ | ||
methodPath: path, | ||
constantSuper, | ||
file, | ||
refToPreserve: ref, | ||
getSuperRef, | ||
getObjectRef() { | ||
state.needsClassRef = true; | ||
return _core.types.isStaticBlock != null && _core.types.isStaticBlock(path.node) || path.node.static ? ref : _core.types.memberExpression(ref, _core.types.identifier("prototype")); | ||
} | ||
}); | ||
replacer.replace(); | ||
if (isStaticBlock || path.isProperty()) { | ||
if (!path.isMethod()) { | ||
path.traverse(thisContextVisitor, state); | ||
} | ||
if (innerBindingRef != null && (_state$classRef = state.classRef) != null && _state$classRef.name && state.classRef.name !== (innerBindingRef == null ? void 0 : innerBindingRef.name)) { | ||
if (innerBindingRef != null && state.classRef?.name && state.classRef.name !== innerBindingRef.name) { | ||
path.traverse(innerReferencesVisitor, state); | ||
@@ -740,8 +694,8 @@ } | ||
function inheritPropComments(node, prop) { | ||
_core.types.inheritLeadingComments(node, prop.node); | ||
_core.types.inheritInnerComments(node, prop.node); | ||
t.inheritLeadingComments(node, prop.node); | ||
t.inheritInnerComments(node, prop.node); | ||
return node; | ||
} | ||
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, state, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) { | ||
let needsClassRef = false; | ||
export function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, file, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) { | ||
let classRefFlags = 0; | ||
let injectSuperRef; | ||
@@ -751,10 +705,12 @@ const staticNodes = []; | ||
const pureStaticNodes = []; | ||
const getSuperRef = _core.types.isIdentifier(superRef) ? () => superRef : () => { | ||
var _injectSuperRef; | ||
(_injectSuperRef = injectSuperRef) != null ? _injectSuperRef : injectSuperRef = props[0].scope.generateUidIdentifierBasedOnNode(superRef); | ||
let classBindingNode = null; | ||
const getSuperRef = t.isIdentifier(superRef) ? () => superRef : () => { | ||
injectSuperRef ??= props[0].scope.generateUidIdentifierBasedOnNode(superRef); | ||
return injectSuperRef; | ||
}; | ||
const classRefForInnerBinding = ref ?? props[0].scope.generateUidIdentifier("class"); | ||
ref ??= t.cloneNode(innerBindingRef); | ||
for (const prop of props) { | ||
prop.isClassProperty() && ts.assertFieldTransformed(prop); | ||
const isStatic = !(_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node)) && prop.node.static; | ||
const isStatic = !t.isStaticBlock?.(prop.node) && prop.node.static; | ||
const isInstance = !isStatic; | ||
@@ -765,6 +721,24 @@ const isPrivate = prop.isPrivate(); | ||
const isMethod = !isField; | ||
const isStaticBlock = prop.isStaticBlock == null ? void 0 : prop.isStaticBlock(); | ||
const isStaticBlock = prop.isStaticBlock?.(); | ||
if (isStatic) classRefFlags |= 1; | ||
if (isStatic || isMethod && isPrivate || isStaticBlock) { | ||
const replaced = replaceThisContext(prop, ref, getSuperRef, state, isStaticBlock, constantSuper, innerBindingRef); | ||
needsClassRef = needsClassRef || replaced; | ||
new ReplaceSupers({ | ||
methodPath: prop, | ||
constantSuper, | ||
file: file, | ||
refToPreserve: innerBindingRef, | ||
getSuperRef, | ||
getObjectRef() { | ||
classRefFlags |= 2; | ||
if (isStatic || isStaticBlock) { | ||
return classRefForInnerBinding; | ||
} else { | ||
return t.memberExpression(classRefForInnerBinding, t.identifier("prototype")); | ||
} | ||
} | ||
}).replace(); | ||
const replaced = replaceThisContext(prop, classRefForInnerBinding, innerBindingRef); | ||
if (replaced) { | ||
classRefFlags |= 2; | ||
} | ||
} | ||
@@ -775,6 +749,6 @@ switch (true) { | ||
const blockBody = prop.node.body; | ||
if (blockBody.length === 1 && _core.types.isExpressionStatement(blockBody[0])) { | ||
if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) { | ||
staticNodes.push(inheritPropComments(blockBody[0], prop)); | ||
} else { | ||
staticNodes.push(_core.types.inheritsComments(_core.template.statement.ast`(() => { ${blockBody} })()`, prop.node)); | ||
staticNodes.push(t.inheritsComments(template.statement.ast`(() => { ${blockBody} })()`, prop.node)); | ||
} | ||
@@ -784,7 +758,5 @@ break; | ||
case isStatic && isPrivate && isField && privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.push(buildPrivateFieldInitLoose(_core.types.cloneNode(ref), prop, privateNamesMap)); | ||
staticNodes.push(buildPrivateFieldInitLoose(t.cloneNode(ref), prop, privateNamesMap)); | ||
break; | ||
case isStatic && isPrivate && isField && !privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.push(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
@@ -794,26 +766,23 @@ break; | ||
if (!isNameOrLength(prop.node)) { | ||
needsClassRef = true; | ||
staticNodes.push(buildPublicFieldInitLoose(_core.types.cloneNode(ref), prop)); | ||
staticNodes.push(buildPublicFieldInitLoose(t.cloneNode(ref), prop)); | ||
break; | ||
} | ||
case isStatic && isPublic && isField && !setPublicClassFields: | ||
needsClassRef = true; | ||
staticNodes.push(buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, state)); | ||
staticNodes.push(buildPublicFieldInitSpec(t.cloneNode(ref), prop, file)); | ||
break; | ||
case isInstance && isPrivate && isField && privateFieldsAsProperties: | ||
instanceNodes.push(buildPrivateFieldInitLoose(_core.types.thisExpression(), prop, privateNamesMap)); | ||
instanceNodes.push(buildPrivateFieldInitLoose(t.thisExpression(), prop, privateNamesMap)); | ||
break; | ||
case isInstance && isPrivate && isField && !privateFieldsAsProperties: | ||
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state)); | ||
instanceNodes.push(buildPrivateInstanceFieldInitSpec(t.thisExpression(), prop, privateNamesMap, file)); | ||
break; | ||
case isInstance && isPrivate && isMethod && privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateMethodInitLoose(_core.types.thisExpression(), prop, privateNamesMap)); | ||
instanceNodes.unshift(buildPrivateMethodInitLoose(t.thisExpression(), prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isInstance && isPrivate && isMethod && !privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state)); | ||
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(t.thisExpression(), prop, privateNamesMap, file)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isStatic && isPrivate && isMethod && !privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.unshift(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
@@ -823,11 +792,10 @@ pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
case isStatic && isPrivate && isMethod && privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), prop, state, privateNamesMap)); | ||
staticNodes.unshift(buildPrivateStaticMethodInitLoose(t.cloneNode(ref), prop, file, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isInstance && isPublic && isField && setPublicClassFields: | ||
instanceNodes.push(buildPublicFieldInitLoose(_core.types.thisExpression(), prop)); | ||
instanceNodes.push(buildPublicFieldInitLoose(t.thisExpression(), prop)); | ||
break; | ||
case isInstance && isPublic && isField && !setPublicClassFields: | ||
instanceNodes.push(buildPublicFieldInitSpec(_core.types.thisExpression(), prop, state)); | ||
instanceNodes.push(buildPublicFieldInitSpec(t.thisExpression(), prop, file)); | ||
break; | ||
@@ -838,2 +806,5 @@ default: | ||
} | ||
if (classRefFlags & 2 && innerBindingRef != null) { | ||
classBindingNode = t.expressionStatement(t.assignmentExpression("=", t.cloneNode(classRefForInnerBinding), t.cloneNode(innerBindingRef))); | ||
} | ||
return { | ||
@@ -843,2 +814,3 @@ staticNodes: staticNodes.filter(Boolean), | ||
pureStaticNodes: pureStaticNodes.filter(Boolean), | ||
classBindingNode, | ||
wrapClass(path) { | ||
@@ -851,14 +823,22 @@ for (const prop of props) { | ||
path.scope.push({ | ||
id: _core.types.cloneNode(injectSuperRef) | ||
id: t.cloneNode(injectSuperRef) | ||
}); | ||
path.set("superClass", _core.types.assignmentExpression("=", injectSuperRef, path.node.superClass)); | ||
path.set("superClass", t.assignmentExpression("=", injectSuperRef, path.node.superClass)); | ||
} | ||
if (!needsClassRef) return path; | ||
if (path.isClassExpression()) { | ||
path.scope.push({ | ||
id: ref | ||
}); | ||
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(ref), path.node)); | ||
} else if (!path.node.id) { | ||
path.node.id = ref; | ||
if (classRefFlags !== 0) { | ||
if (path.isClassExpression()) { | ||
path.scope.push({ | ||
id: ref | ||
}); | ||
path.replaceWith(t.assignmentExpression("=", t.cloneNode(ref), path.node)); | ||
} else { | ||
if (innerBindingRef == null) { | ||
path.node.id = ref; | ||
} | ||
if (classBindingNode != null) { | ||
path.scope.push({ | ||
id: classRefForInnerBinding | ||
}); | ||
} | ||
} | ||
} | ||
@@ -865,0 +845,0 @@ return path; |
1146
lib/index.js
@@ -1,40 +0,1027 @@ | ||
"use strict"; | ||
import { traverse, types, template } from '@babel/core'; | ||
import nameFunction from '@babel/helper-function-name'; | ||
import '@babel/helper-split-export-declaration'; | ||
import semver from 'semver'; | ||
import ReplaceSupers from '@babel/helper-replace-supers'; | ||
import environmentVisitor from '@babel/helper-environment-visitor'; | ||
import memberExpressionToFunctions from '@babel/helper-member-expression-to-functions'; | ||
import optimiseCall from '@babel/helper-optimise-call-expression'; | ||
import annotateAsPure from '@babel/helper-annotate-as-pure'; | ||
import { skipTransparentExprWrapperNodes } from '@babel/helper-skip-transparent-expression-wrappers'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "FEATURES", { | ||
enumerable: true, | ||
get: function () { | ||
return _features.FEATURES; | ||
function assertFieldTransformed(path) { | ||
if (path.node.declare || path.isClassProperty({ | ||
definite: true | ||
})) { | ||
throw path.buildCodeFrameError(`TypeScript 'declare' fields must first be transformed by ` + `@babel/plugin-transform-typescript.\n` + `If you have already enabled that plugin (or '@babel/preset-typescript'), make sure ` + `that it runs before any plugin related to additional class features:\n` + ` - @babel/plugin-transform-class-properties\n` + ` - @babel/plugin-transform-private-methods\n` + ` - @babel/plugin-proposal-decorators`); | ||
} | ||
} | ||
function buildPrivateNamesMap(props) { | ||
const privateNamesMap = new Map(); | ||
for (const prop of props) { | ||
if (prop.isPrivate()) { | ||
const { | ||
name | ||
} = prop.node.key.id; | ||
const update = privateNamesMap.has(name) ? privateNamesMap.get(name) : { | ||
id: prop.scope.generateUidIdentifier(name), | ||
static: prop.node.static, | ||
method: !prop.isProperty() | ||
}; | ||
if (prop.isClassPrivateMethod()) { | ||
if (prop.node.kind === "get") { | ||
update.getId = prop.scope.generateUidIdentifier(`get_${name}`); | ||
} else if (prop.node.kind === "set") { | ||
update.setId = prop.scope.generateUidIdentifier(`set_${name}`); | ||
} else if (prop.node.kind === "method") { | ||
update.methodId = prop.scope.generateUidIdentifier(name); | ||
} | ||
} | ||
privateNamesMap.set(name, update); | ||
} | ||
} | ||
return privateNamesMap; | ||
} | ||
function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) { | ||
const initNodes = []; | ||
for (const [name, value] of privateNamesMap) { | ||
const { | ||
static: isStatic, | ||
method: isMethod, | ||
getId, | ||
setId | ||
} = value; | ||
const isAccessor = getId || setId; | ||
const id = types.cloneNode(value.id); | ||
let init; | ||
if (privateFieldsAsProperties) { | ||
init = types.callExpression(state.addHelper("classPrivateFieldLooseKey"), [types.stringLiteral(name)]); | ||
} else if (privateFieldsAsSymbols) { | ||
init = types.callExpression(types.identifier("Symbol"), [types.stringLiteral(name)]); | ||
} else if (!isStatic) { | ||
init = types.newExpression(types.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []); | ||
} | ||
if (init) { | ||
annotateAsPure(init); | ||
initNodes.push(template.statement.ast`var ${id} = ${init}`); | ||
} | ||
} | ||
return initNodes; | ||
} | ||
function privateNameVisitorFactory(visitor) { | ||
const nestedVisitor = traverse.visitors.merge([Object.assign({}, visitor), environmentVisitor]); | ||
const privateNameVisitor = 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({}, this, { | ||
redeclared | ||
})); | ||
path.traverse(privateNameVisitor, Object.assign({}, this, { | ||
privateNamesMap: visiblePrivateNames | ||
})); | ||
path.skipKey("body"); | ||
} | ||
}); | ||
return privateNameVisitor; | ||
} | ||
const privateNameVisitor = privateNameVisitorFactory({ | ||
PrivateName(path, { | ||
noDocumentAll | ||
}) { | ||
const { | ||
privateNamesMap, | ||
redeclared | ||
} = this; | ||
const { | ||
node, | ||
parentPath | ||
} = path; | ||
if (!parentPath.isMemberExpression({ | ||
property: node | ||
}) && !parentPath.isOptionalMemberExpression({ | ||
property: node | ||
})) { | ||
return; | ||
} | ||
const { | ||
name | ||
} = node.id; | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
this.handle(parentPath, noDocumentAll); | ||
} | ||
}); | ||
Object.defineProperty(exports, "buildCheckInRHS", { | ||
enumerable: true, | ||
get: function () { | ||
return _fields.buildCheckInRHS; | ||
function unshadow(name, scope, innerBinding) { | ||
while (scope?.hasBinding(name) && !scope.bindingIdentifierEquals(name, innerBinding)) { | ||
scope.rename(name); | ||
scope = scope.parent; | ||
} | ||
} | ||
function buildCheckInRHS(rhs, file, inRHSIsObject) { | ||
if (inRHSIsObject || !file.availableHelper?.("checkInRHS")) return rhs; | ||
return types.callExpression(file.addHelper("checkInRHS"), [rhs]); | ||
} | ||
const privateInVisitor = privateNameVisitorFactory({ | ||
BinaryExpression(path, { | ||
file | ||
}) { | ||
const { | ||
operator, | ||
left, | ||
right | ||
} = path.node; | ||
if (operator !== "in") return; | ||
if (!types.isPrivateName(left)) return; | ||
const { | ||
privateFieldsAsProperties, | ||
privateNamesMap, | ||
redeclared | ||
} = this; | ||
const { | ||
name | ||
} = left.id; | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
unshadow(this.classRef.name, path.scope, this.innerBinding); | ||
if (privateFieldsAsProperties) { | ||
const { | ||
id | ||
} = privateNamesMap.get(name); | ||
path.replaceWith(template.expression.ast` | ||
Object.prototype.hasOwnProperty.call(${buildCheckInRHS(right, file)}, ${types.cloneNode(id)}) | ||
`); | ||
return; | ||
} | ||
const { | ||
id, | ||
static: isStatic | ||
} = privateNamesMap.get(name); | ||
if (isStatic) { | ||
path.replaceWith(template.expression.ast`${buildCheckInRHS(right, file)} === ${types.cloneNode(this.classRef)}`); | ||
return; | ||
} | ||
path.replaceWith(template.expression.ast`${types.cloneNode(id)}.has(${buildCheckInRHS(right, file)})`); | ||
} | ||
}); | ||
exports.createClassFeaturePlugin = createClassFeaturePlugin; | ||
Object.defineProperty(exports, "enableFeature", { | ||
enumerable: true, | ||
get: function () { | ||
return _features.enableFeature; | ||
const privateNameHandlerSpec = { | ||
memoise(member, count) { | ||
const { | ||
scope | ||
} = member; | ||
const { | ||
object | ||
} = member.node; | ||
const memo = scope.maybeGenerateMemoised(object); | ||
if (!memo) { | ||
return; | ||
} | ||
this.memoiser.set(object, memo, count); | ||
}, | ||
receiver(member) { | ||
const { | ||
object | ||
} = member.node; | ||
if (this.memoiser.has(object)) { | ||
return types.cloneNode(this.memoiser.get(object)); | ||
} | ||
return types.cloneNode(object); | ||
}, | ||
get(member) { | ||
const { | ||
classRef, | ||
privateNamesMap, | ||
file, | ||
innerBinding | ||
} = this; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
const { | ||
id, | ||
static: isStatic, | ||
method: isMethod, | ||
methodId, | ||
getId, | ||
setId | ||
} = privateNamesMap.get(name); | ||
const isAccessor = getId || setId; | ||
if (isStatic) { | ||
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet"; | ||
unshadow(classRef.name, member.scope, innerBinding); | ||
return types.callExpression(file.addHelper(helperName), [this.receiver(member), types.cloneNode(classRef), types.cloneNode(id)]); | ||
} | ||
if (isMethod) { | ||
if (isAccessor) { | ||
if (!getId && setId) { | ||
if (file.availableHelper("writeOnlyError")) { | ||
return types.sequenceExpression([this.receiver(member), types.callExpression(file.addHelper("writeOnlyError"), [types.stringLiteral(`#${name}`)])]); | ||
} | ||
console.warn(`@babel/helpers is outdated, update it to silence this warning.`); | ||
} | ||
return types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), types.cloneNode(id)]); | ||
} | ||
return types.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), types.cloneNode(id), types.cloneNode(methodId)]); | ||
} | ||
return types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), types.cloneNode(id)]); | ||
}, | ||
boundGet(member) { | ||
this.memoise(member, 1); | ||
return types.callExpression(types.memberExpression(this.get(member), types.identifier("bind")), [this.receiver(member)]); | ||
}, | ||
set(member, value) { | ||
const { | ||
classRef, | ||
privateNamesMap, | ||
file | ||
} = this; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
const { | ||
id, | ||
static: isStatic, | ||
method: isMethod, | ||
setId, | ||
getId | ||
} = privateNamesMap.get(name); | ||
const isAccessor = getId || setId; | ||
if (isStatic) { | ||
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodSet" : "classStaticPrivateFieldSpecSet"; | ||
return types.callExpression(file.addHelper(helperName), [this.receiver(member), types.cloneNode(classRef), types.cloneNode(id), value]); | ||
} | ||
if (isMethod) { | ||
if (setId) { | ||
return types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), types.cloneNode(id), value]); | ||
} | ||
return types.sequenceExpression([this.receiver(member), value, types.callExpression(file.addHelper("readOnlyError"), [types.stringLiteral(`#${name}`)])]); | ||
} | ||
return types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), types.cloneNode(id), value]); | ||
}, | ||
destructureSet(member) { | ||
const { | ||
classRef, | ||
privateNamesMap, | ||
file | ||
} = this; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
const { | ||
id, | ||
static: isStatic | ||
} = privateNamesMap.get(name); | ||
if (isStatic) { | ||
try { | ||
var helper = file.addHelper("classStaticPrivateFieldDestructureSet"); | ||
} catch { | ||
throw new Error("Babel can not transpile `[C.#p] = [0]` with @babel/helpers < 7.13.10, \n" + "please update @babel/helpers to the latest version."); | ||
} | ||
return types.memberExpression(types.callExpression(helper, [this.receiver(member), types.cloneNode(classRef), types.cloneNode(id)]), types.identifier("value")); | ||
} | ||
return types.memberExpression(types.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), types.cloneNode(id)]), types.identifier("value")); | ||
}, | ||
call(member, args) { | ||
this.memoise(member, 1); | ||
return optimiseCall(this.get(member), this.receiver(member), args, false); | ||
}, | ||
optionalCall(member, args) { | ||
this.memoise(member, 1); | ||
return optimiseCall(this.get(member), this.receiver(member), args, true); | ||
}, | ||
delete() { | ||
throw new Error("Internal Babel error: deleting private elements is a parsing error."); | ||
} | ||
}; | ||
const privateNameHandlerLoose = { | ||
get(member) { | ||
const { | ||
privateNamesMap, | ||
file | ||
} = this; | ||
const { | ||
object | ||
} = member.node; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
return template.expression`BASE(REF, PROP)[PROP]`({ | ||
BASE: file.addHelper("classPrivateFieldLooseBase"), | ||
REF: types.cloneNode(object), | ||
PROP: types.cloneNode(privateNamesMap.get(name).id) | ||
}); | ||
}, | ||
set() { | ||
throw new Error("private name handler with loose = true don't need set()"); | ||
}, | ||
boundGet(member) { | ||
return types.callExpression(types.memberExpression(this.get(member), types.identifier("bind")), [types.cloneNode(member.node.object)]); | ||
}, | ||
simpleSet(member) { | ||
return this.get(member); | ||
}, | ||
destructureSet(member) { | ||
return this.get(member); | ||
}, | ||
call(member, args) { | ||
return types.callExpression(this.get(member), args); | ||
}, | ||
optionalCall(member, args) { | ||
return types.optionalCallExpression(this.get(member), args, true); | ||
}, | ||
delete() { | ||
throw new Error("Internal Babel error: deleting private elements is a parsing error."); | ||
} | ||
}; | ||
function transformPrivateNamesUsage(ref, path, privateNamesMap, { | ||
privateFieldsAsProperties, | ||
noDocumentAll, | ||
innerBinding | ||
}, state) { | ||
if (!privateNamesMap.size) return; | ||
const body = path.get("body"); | ||
const handler = privateFieldsAsProperties ? privateNameHandlerLoose : privateNameHandlerSpec; | ||
memberExpressionToFunctions(body, privateNameVisitor, Object.assign({ | ||
privateNamesMap, | ||
classRef: ref, | ||
file: state | ||
}, handler, { | ||
noDocumentAll, | ||
innerBinding | ||
})); | ||
body.traverse(privateInVisitor, { | ||
privateNamesMap, | ||
classRef: ref, | ||
file: state, | ||
privateFieldsAsProperties, | ||
innerBinding | ||
}); | ||
} | ||
function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { | ||
const { | ||
id | ||
} = privateNamesMap.get(prop.node.key.id.name); | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${types.cloneNode(id)}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
writable: true, | ||
value: ${value} | ||
}); | ||
`, prop); | ||
} | ||
function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { | ||
const { | ||
id | ||
} = privateNamesMap.get(prop.node.key.id.name); | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${types.thisExpression()}, | ||
${types.cloneNode(id)}, | ||
{ | ||
writable: true, | ||
value: ${value} | ||
}, | ||
)`, prop); | ||
} | ||
function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
id, | ||
getId, | ||
setId, | ||
initAdded | ||
} = privateName; | ||
const isAccessor = getId || setId; | ||
if (!prop.isProperty() && (initAdded || !isAccessor)) return; | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
initAdded: true | ||
})); | ||
return inheritPropComments(template.statement.ast` | ||
var ${types.cloneNode(id)} = { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
// writable is false by default | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
} | ||
`, prop); | ||
} | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(template.statement.ast` | ||
var ${types.cloneNode(id)} = { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
writable: true, | ||
value: ${value} | ||
}; | ||
`, prop); | ||
} | ||
function buildPrivateMethodInitLoose(ref, prop, privateNamesMap) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
methodId, | ||
id, | ||
getId, | ||
setId, | ||
initAdded | ||
} = privateName; | ||
if (initAdded) return; | ||
if (methodId) { | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
// writable is false by default | ||
value: ${methodId.name} | ||
}); | ||
`, prop); | ||
} | ||
const isAccessor = getId || setId; | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
initAdded: true | ||
})); | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
// writable is false by default | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}); | ||
`, prop); | ||
} | ||
} | ||
function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap, state) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
getId, | ||
setId, | ||
initAdded | ||
} = privateName; | ||
if (initAdded) return; | ||
const isAccessor = getId || setId; | ||
if (isAccessor) { | ||
return buildPrivateAccessorInitialization(ref, prop, privateNamesMap, state); | ||
} | ||
return buildPrivateInstanceMethodInitialization(ref, prop, privateNamesMap, state); | ||
} | ||
function buildPrivateAccessorInitialization(ref, prop, privateNamesMap, state) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
id, | ||
getId, | ||
setId | ||
} = privateName; | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
initAdded: true | ||
})); | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${types.thisExpression()}, | ||
${types.cloneNode(id)}, | ||
{ | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}, | ||
)`, prop); | ||
} | ||
function buildPrivateInstanceMethodInitialization(ref, prop, privateNamesMap, state) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
id | ||
} = privateName; | ||
const helper = state.addHelper("classPrivateMethodInitSpec"); | ||
return inheritPropComments(template.statement.ast`${helper}( | ||
${types.thisExpression()}, | ||
${types.cloneNode(id)} | ||
)`, prop); | ||
} | ||
function buildPublicFieldInitLoose(ref, prop) { | ||
const { | ||
key, | ||
computed | ||
} = prop.node; | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(types.expressionStatement(types.assignmentExpression("=", types.memberExpression(ref, key, computed || types.isLiteral(key)), value)), prop); | ||
} | ||
function buildPublicFieldInitSpec(ref, prop, state) { | ||
const { | ||
key, | ||
computed | ||
} = prop.node; | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return inheritPropComments(types.expressionStatement(types.callExpression(state.addHelper("defineProperty"), [ref, computed || types.isLiteral(key) ? key : types.stringLiteral(key.name), value])), prop); | ||
} | ||
function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
id, | ||
methodId, | ||
getId, | ||
setId, | ||
initAdded | ||
} = privateName; | ||
if (initAdded) return; | ||
const isAccessor = getId || setId; | ||
if (isAccessor) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
initAdded: true | ||
})); | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
// writable is false by default | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}) | ||
`, prop); | ||
} | ||
return inheritPropComments(template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
// writable is false by default | ||
value: ${methodId.name} | ||
}); | ||
`, prop); | ||
} | ||
function buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties = false) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
const { | ||
id, | ||
methodId, | ||
getId, | ||
setId, | ||
getterDeclared, | ||
setterDeclared, | ||
static: isStatic | ||
} = privateName; | ||
const { | ||
params, | ||
body, | ||
generator, | ||
async | ||
} = prop.node; | ||
const isGetter = getId && !getterDeclared && params.length === 0; | ||
const isSetter = setId && !setterDeclared && params.length > 0; | ||
let declId = methodId; | ||
if (isGetter) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
getterDeclared: true | ||
})); | ||
declId = getId; | ||
} else if (isSetter) { | ||
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, { | ||
setterDeclared: true | ||
})); | ||
declId = setId; | ||
} else if (isStatic && !privateFieldsAsProperties) { | ||
declId = id; | ||
} | ||
return inheritPropComments(types.functionDeclaration(types.cloneNode(declId), params, body, generator, async), prop); | ||
} | ||
const thisContextVisitor = traverse.visitors.merge([{ | ||
UnaryExpression(path) { | ||
const { | ||
node | ||
} = path; | ||
if (node.operator === "delete") { | ||
const argument = skipTransparentExprWrapperNodes(node.argument); | ||
if (types.isThisExpression(argument)) { | ||
path.replaceWith(types.booleanLiteral(true)); | ||
} | ||
} | ||
}, | ||
ThisExpression(path, state) { | ||
state.needsClassRef = true; | ||
path.replaceWith(types.cloneNode(state.classRef)); | ||
}, | ||
MetaProperty(path) { | ||
const { | ||
node, | ||
scope | ||
} = path; | ||
if (node.meta.name === "new" && node.property.name === "target") { | ||
path.replaceWith(scope.buildUndefinedNode()); | ||
} | ||
} | ||
}, environmentVisitor]); | ||
const innerReferencesVisitor = { | ||
ReferencedIdentifier(path, state) { | ||
if (path.scope.bindingIdentifierEquals(path.node.name, state.innerBinding)) { | ||
state.needsClassRef = true; | ||
path.node.name = state.classRef.name; | ||
} | ||
} | ||
}; | ||
function replaceThisContext(path, ref, innerBindingRef) { | ||
const state = { | ||
classRef: ref, | ||
needsClassRef: false, | ||
innerBinding: innerBindingRef | ||
}; | ||
if (!path.isMethod()) { | ||
path.traverse(thisContextVisitor, state); | ||
} | ||
if (innerBindingRef != null && state.classRef?.name && state.classRef.name !== innerBindingRef.name) { | ||
path.traverse(innerReferencesVisitor, state); | ||
} | ||
return state.needsClassRef; | ||
} | ||
function isNameOrLength({ | ||
key, | ||
computed | ||
}) { | ||
if (key.type === "Identifier") { | ||
return !computed && (key.name === "name" || key.name === "length"); | ||
} | ||
if (key.type === "StringLiteral") { | ||
return key.value === "name" || key.value === "length"; | ||
} | ||
return false; | ||
} | ||
function inheritPropComments(node, prop) { | ||
types.inheritLeadingComments(node, prop.node); | ||
types.inheritInnerComments(node, prop.node); | ||
return node; | ||
} | ||
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, file, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) { | ||
let classRefFlags = 0; | ||
let injectSuperRef; | ||
const staticNodes = []; | ||
const instanceNodes = []; | ||
const pureStaticNodes = []; | ||
let classBindingNode = null; | ||
const getSuperRef = types.isIdentifier(superRef) ? () => superRef : () => { | ||
injectSuperRef ??= props[0].scope.generateUidIdentifierBasedOnNode(superRef); | ||
return injectSuperRef; | ||
}; | ||
const classRefForInnerBinding = ref ?? props[0].scope.generateUidIdentifier("class"); | ||
ref ??= types.cloneNode(innerBindingRef); | ||
for (const prop of props) { | ||
prop.isClassProperty() && assertFieldTransformed(prop); | ||
const isStatic = !types.isStaticBlock?.(prop.node) && prop.node.static; | ||
const isInstance = !isStatic; | ||
const isPrivate = prop.isPrivate(); | ||
const isPublic = !isPrivate; | ||
const isField = prop.isProperty(); | ||
const isMethod = !isField; | ||
const isStaticBlock = prop.isStaticBlock?.(); | ||
if (isStatic) classRefFlags |= 1; | ||
if (isStatic || isMethod && isPrivate || isStaticBlock) { | ||
new ReplaceSupers({ | ||
methodPath: prop, | ||
constantSuper, | ||
file: file, | ||
refToPreserve: innerBindingRef, | ||
getSuperRef, | ||
getObjectRef() { | ||
classRefFlags |= 2; | ||
if (isStatic || isStaticBlock) { | ||
return classRefForInnerBinding; | ||
} else { | ||
return types.memberExpression(classRefForInnerBinding, types.identifier("prototype")); | ||
} | ||
} | ||
}).replace(); | ||
const replaced = replaceThisContext(prop, classRefForInnerBinding, innerBindingRef); | ||
if (replaced) { | ||
classRefFlags |= 2; | ||
} | ||
} | ||
switch (true) { | ||
case isStaticBlock: | ||
{ | ||
const blockBody = prop.node.body; | ||
if (blockBody.length === 1 && types.isExpressionStatement(blockBody[0])) { | ||
staticNodes.push(inheritPropComments(blockBody[0], prop)); | ||
} else { | ||
staticNodes.push(types.inheritsComments(template.statement.ast`(() => { ${blockBody} })()`, prop.node)); | ||
} | ||
break; | ||
} | ||
case isStatic && isPrivate && isField && privateFieldsAsProperties: | ||
staticNodes.push(buildPrivateFieldInitLoose(types.cloneNode(ref), prop, privateNamesMap)); | ||
break; | ||
case isStatic && isPrivate && isField && !privateFieldsAsProperties: | ||
staticNodes.push(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
break; | ||
case isStatic && isPublic && isField && setPublicClassFields: | ||
if (!isNameOrLength(prop.node)) { | ||
staticNodes.push(buildPublicFieldInitLoose(types.cloneNode(ref), prop)); | ||
break; | ||
} | ||
case isStatic && isPublic && isField && !setPublicClassFields: | ||
staticNodes.push(buildPublicFieldInitSpec(types.cloneNode(ref), prop, file)); | ||
break; | ||
case isInstance && isPrivate && isField && privateFieldsAsProperties: | ||
instanceNodes.push(buildPrivateFieldInitLoose(types.thisExpression(), prop, privateNamesMap)); | ||
break; | ||
case isInstance && isPrivate && isField && !privateFieldsAsProperties: | ||
instanceNodes.push(buildPrivateInstanceFieldInitSpec(types.thisExpression(), prop, privateNamesMap, file)); | ||
break; | ||
case isInstance && isPrivate && isMethod && privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateMethodInitLoose(types.thisExpression(), prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isInstance && isPrivate && isMethod && !privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(types.thisExpression(), prop, privateNamesMap, file)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isStatic && isPrivate && isMethod && !privateFieldsAsProperties: | ||
staticNodes.unshift(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isStatic && isPrivate && isMethod && privateFieldsAsProperties: | ||
staticNodes.unshift(buildPrivateStaticMethodInitLoose(types.cloneNode(ref), prop, file, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isInstance && isPublic && isField && setPublicClassFields: | ||
instanceNodes.push(buildPublicFieldInitLoose(types.thisExpression(), prop)); | ||
break; | ||
case isInstance && isPublic && isField && !setPublicClassFields: | ||
instanceNodes.push(buildPublicFieldInitSpec(types.thisExpression(), prop, file)); | ||
break; | ||
default: | ||
throw new Error("Unreachable."); | ||
} | ||
} | ||
if (classRefFlags & 2 && innerBindingRef != null) { | ||
classBindingNode = types.expressionStatement(types.assignmentExpression("=", types.cloneNode(classRefForInnerBinding), types.cloneNode(innerBindingRef))); | ||
} | ||
return { | ||
staticNodes: staticNodes.filter(Boolean), | ||
instanceNodes: instanceNodes.filter(Boolean), | ||
pureStaticNodes: pureStaticNodes.filter(Boolean), | ||
classBindingNode, | ||
wrapClass(path) { | ||
for (const prop of props) { | ||
prop.node.leadingComments = null; | ||
prop.remove(); | ||
} | ||
if (injectSuperRef) { | ||
path.scope.push({ | ||
id: types.cloneNode(injectSuperRef) | ||
}); | ||
path.set("superClass", types.assignmentExpression("=", injectSuperRef, path.node.superClass)); | ||
} | ||
if (classRefFlags !== 0) { | ||
if (path.isClassExpression()) { | ||
path.scope.push({ | ||
id: ref | ||
}); | ||
path.replaceWith(types.assignmentExpression("=", types.cloneNode(ref), path.node)); | ||
} else { | ||
if (innerBindingRef == null) { | ||
path.node.id = ref; | ||
} | ||
if (classBindingNode != null) { | ||
path.scope.push({ | ||
id: classRefForInnerBinding | ||
}); | ||
} | ||
} | ||
} | ||
return path; | ||
} | ||
}; | ||
} | ||
function hasOwnDecorators(node) { | ||
return !!node.decorators?.length; | ||
} | ||
function hasDecorators(node) { | ||
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators); | ||
} | ||
const findBareSupers = traverse.visitors.merge([{ | ||
Super(path) { | ||
const { | ||
node, | ||
parentPath | ||
} = path; | ||
if (parentPath.isCallExpression({ | ||
callee: node | ||
})) { | ||
this.push(parentPath); | ||
} | ||
} | ||
}, environmentVisitor]); | ||
const referenceVisitor = { | ||
"TSTypeAnnotation|TypeAnnotation"(path) { | ||
path.skip(); | ||
}, | ||
ReferencedIdentifier(path, { | ||
scope | ||
}) { | ||
if (scope.hasOwnBinding(path.node.name)) { | ||
scope.rename(path.node.name); | ||
path.skip(); | ||
} | ||
} | ||
}; | ||
function handleClassTDZ(path, state) { | ||
if (state.classBinding && state.classBinding === path.scope.getBinding(path.node.name)) { | ||
const classNameTDZError = state.file.addHelper("classNameTDZError"); | ||
const throwNode = types.callExpression(classNameTDZError, [types.stringLiteral(path.node.name)]); | ||
path.replaceWith(types.sequenceExpression([throwNode, path.node])); | ||
path.skip(); | ||
} | ||
} | ||
const classFieldDefinitionEvaluationTDZVisitor = { | ||
ReferencedIdentifier: handleClassTDZ | ||
}; | ||
function injectInitialization(path, constructor, nodes, renamer) { | ||
if (!nodes.length) return; | ||
const isDerived = !!path.node.superClass; | ||
if (!constructor) { | ||
const newConstructor = types.classMethod("constructor", types.identifier("constructor"), [], types.blockStatement([])); | ||
if (isDerived) { | ||
newConstructor.params = [types.restElement(types.identifier("args"))]; | ||
newConstructor.body.body.push(template.statement.ast`super(...args)`); | ||
} | ||
[constructor] = path.get("body").unshiftContainer("body", newConstructor); | ||
} | ||
if (renamer) { | ||
renamer(referenceVisitor, { | ||
scope: constructor.scope | ||
}); | ||
} | ||
if (isDerived) { | ||
const bareSupers = []; | ||
constructor.traverse(findBareSupers, bareSupers); | ||
let isFirst = true; | ||
for (const bareSuper of bareSupers) { | ||
if (isFirst) { | ||
bareSuper.insertAfter(nodes); | ||
isFirst = false; | ||
} else { | ||
bareSuper.insertAfter(nodes.map(n => types.cloneNode(n))); | ||
} | ||
} | ||
} else { | ||
constructor.get("body").unshiftContainer("body", nodes); | ||
} | ||
} | ||
function extractComputedKeys(path, computedPaths, file) { | ||
const declarations = []; | ||
const state = { | ||
classBinding: path.node.id && path.scope.getBinding(path.node.id.name), | ||
file | ||
}; | ||
for (const computedPath of computedPaths) { | ||
const computedKey = computedPath.get("key"); | ||
if (computedKey.isReferencedIdentifier()) { | ||
handleClassTDZ(computedKey, state); | ||
} else { | ||
computedKey.traverse(classFieldDefinitionEvaluationTDZVisitor, state); | ||
} | ||
const computedNode = computedPath.node; | ||
if (!computedKey.isConstantExpression()) { | ||
const ident = path.scope.generateUidIdentifierBasedOnNode(computedNode.key); | ||
path.scope.push({ | ||
id: ident, | ||
kind: "let" | ||
}); | ||
declarations.push(types.expressionStatement(types.assignmentExpression("=", types.cloneNode(ident), computedNode.key))); | ||
computedNode.key = types.cloneNode(ident); | ||
} | ||
} | ||
return declarations; | ||
} | ||
const FEATURES = Object.freeze({ | ||
fields: 1 << 1, | ||
privateMethods: 1 << 2, | ||
privateIn: 1 << 3, | ||
staticBlocks: 1 << 4 | ||
}); | ||
Object.defineProperty(exports, "injectInitialization", { | ||
enumerable: true, | ||
get: function () { | ||
return _misc.injectInitialization; | ||
const featuresSameLoose = new Map([[FEATURES.fields, "@babel/plugin-transform-class-properties"], [FEATURES.privateMethods, "@babel/plugin-transform-private-methods"], [FEATURES.privateIn, "@babel/plugin-transform-private-property-in-object"]]); | ||
const featuresKey = "@babel/plugin-class-features/featuresKey"; | ||
const looseKey = "@babel/plugin-class-features/looseKey"; | ||
const looseLowPriorityKey = "@babel/plugin-class-features/looseLowPriorityKey/#__internal__@babel/preset-env__please-overwrite-loose-instead-of-throwing"; | ||
function enableFeature(file, feature, loose) { | ||
if (!hasFeature(file, feature) || canIgnoreLoose(file, feature)) { | ||
file.set(featuresKey, file.get(featuresKey) | feature); | ||
if (loose === "#__internal__@babel/preset-env__prefer-true-but-false-is-ok-if-it-prevents-an-error") { | ||
setLoose(file, feature, true); | ||
file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature); | ||
} else if (loose === "#__internal__@babel/preset-env__prefer-false-but-true-is-ok-if-it-prevents-an-error") { | ||
setLoose(file, feature, false); | ||
file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature); | ||
} else { | ||
setLoose(file, feature, loose); | ||
} | ||
} | ||
}); | ||
var _core = require("@babel/core"); | ||
var _helperFunctionName = require("@babel/helper-function-name"); | ||
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration"); | ||
var _semver = require("semver"); | ||
var _fields = require("./fields"); | ||
var _decorators = require("./decorators"); | ||
var _misc = require("./misc"); | ||
var _features = require("./features"); | ||
var _typescript = require("./typescript"); | ||
let resolvedLoose; | ||
let higherPriorityPluginName; | ||
for (const [mask, name] of featuresSameLoose) { | ||
if (!hasFeature(file, mask)) continue; | ||
const loose = isLoose(file, mask); | ||
if (canIgnoreLoose(file, mask)) { | ||
continue; | ||
} else if (resolvedLoose === !loose) { | ||
throw new Error("'loose' mode configuration must be the same for @babel/plugin-transform-class-properties, " + "@babel/plugin-transform-private-methods and " + "@babel/plugin-transform-private-property-in-object (when they are enabled)."); | ||
} else { | ||
resolvedLoose = loose; | ||
higherPriorityPluginName = name; | ||
} | ||
} | ||
if (resolvedLoose !== undefined) { | ||
for (const [mask, name] of featuresSameLoose) { | ||
if (hasFeature(file, mask) && isLoose(file, mask) !== resolvedLoose) { | ||
setLoose(file, mask, resolvedLoose); | ||
console.warn(`Though the "loose" option was set to "${!resolvedLoose}" in your @babel/preset-env ` + `config, it will not be used for ${name} since the "loose" mode option was set to ` + `"${resolvedLoose}" for ${higherPriorityPluginName}.\nThe "loose" option must be the ` + `same for @babel/plugin-transform-class-properties, @babel/plugin-transform-private-methods ` + `and @babel/plugin-transform-private-property-in-object (when they are enabled): you can ` + `silence this warning by explicitly adding\n` + `\t["${name}", { "loose": ${resolvedLoose} }]\n` + `to the "plugins" section of your Babel config.`); | ||
} | ||
} | ||
} | ||
} | ||
function hasFeature(file, feature) { | ||
return !!(file.get(featuresKey) & feature); | ||
} | ||
function isLoose(file, feature) { | ||
return !!(file.get(looseKey) & feature); | ||
} | ||
function setLoose(file, feature, loose) { | ||
if (loose) file.set(looseKey, file.get(looseKey) | feature);else file.set(looseKey, file.get(looseKey) & ~feature); | ||
file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) & ~feature); | ||
} | ||
function canIgnoreLoose(file, feature) { | ||
return !!(file.get(looseLowPriorityKey) & feature); | ||
} | ||
function shouldTransform(path, file) { | ||
let decoratorPath = null; | ||
let publicFieldPath = null; | ||
let privateFieldPath = null; | ||
let privateMethodPath = null; | ||
let staticBlockPath = null; | ||
if (hasOwnDecorators(path.node)) { | ||
decoratorPath = path.get("decorators.0"); | ||
} | ||
for (const el of path.get("body.body")) { | ||
if (!decoratorPath && hasOwnDecorators(el.node)) { | ||
decoratorPath = el.get("decorators.0"); | ||
} | ||
if (!publicFieldPath && el.isClassProperty()) { | ||
publicFieldPath = el; | ||
} | ||
if (!privateFieldPath && el.isClassPrivateProperty()) { | ||
privateFieldPath = el; | ||
} | ||
if (!privateMethodPath && el.isClassPrivateMethod?.()) { | ||
privateMethodPath = el; | ||
} | ||
if (!staticBlockPath && el.isStaticBlock?.()) { | ||
staticBlockPath = el; | ||
} | ||
} | ||
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", { "version": "legacy" }], ' + 'make sure it comes *before* "@babel/plugin-transform-class-properties" ' + "and enable loose mode, like so:\n" + '\t["@babel/plugin-proposal-decorators", { "version": "legacy" }]\n' + '\t["@babel/plugin-transform-class-properties", { "loose": true }]'); | ||
} | ||
if (privateMethodPath && !hasFeature(file, FEATURES.privateMethods)) { | ||
throw privateMethodPath.buildCodeFrameError("Class private methods are not enabled. " + "Please add `@babel/plugin-transform-private-methods` 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-transform-class-properties` to your configuration."); | ||
} | ||
if (staticBlockPath && !hasFeature(file, FEATURES.staticBlocks)) { | ||
throw path.buildCodeFrameError("Static class blocks are not enabled. " + "Please add `@babel/plugin-transform-class-static-block` to your configuration."); | ||
} | ||
if (decoratorPath || privateMethodPath || staticBlockPath) { | ||
return true; | ||
} | ||
if ((publicFieldPath || privateFieldPath) && hasFeature(file, FEATURES.fields)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
const versionKey = "@babel/plugin-class-features/version"; | ||
@@ -49,8 +1036,2 @@ function createClassFeaturePlugin({ | ||
}) { | ||
{ | ||
var _api; | ||
(_api = api) != null ? _api : api = { | ||
assumption: () => void 0 | ||
}; | ||
} | ||
const setPublicClassFields = api.assumption("setPublicClassFields"); | ||
@@ -85,12 +1066,6 @@ const privateFieldsAsSymbols = api.assumption("privateFieldsAsSymbols"); | ||
pre(file) { | ||
(0, _features.enableFeature)(file, feature, loose); | ||
{ | ||
if (typeof file.get(versionKey) === "number") { | ||
file.set(versionKey, "7.22.9"); | ||
return; | ||
} | ||
enableFeature(file, feature, loose); | ||
if (!file.get(versionKey) || semver.lt(file.get(versionKey), "8.0.0-alpha.0")) { | ||
file.set(versionKey, "8.0.0-alpha.0"); | ||
} | ||
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.22.9")) { | ||
file.set(versionKey, "7.22.9"); | ||
} | ||
}, | ||
@@ -101,10 +1076,10 @@ visitor: { | ||
}) { | ||
if (file.get(versionKey) !== "7.22.9") return; | ||
if (!(0, _features.shouldTransform)(path, file)) return; | ||
if (path.isClassDeclaration()) (0, _typescript.assertFieldTransformed)(path); | ||
const loose = (0, _features.isLoose)(file, feature); | ||
if (file.get(versionKey) !== "8.0.0-alpha.0") return; | ||
if (!shouldTransform(path, file)) return; | ||
const pathIsClassDeclaration = path.isClassDeclaration(); | ||
if (pathIsClassDeclaration) assertFieldTransformed(path); | ||
const loose = isLoose(file, feature); | ||
let constructor; | ||
const isDecorated = (0, _decorators.hasDecorators)(path.node); | ||
hasDecorators(path.node); | ||
const props = []; | ||
const elements = []; | ||
const computedPaths = []; | ||
@@ -147,4 +1122,3 @@ const privateNames = new Set(); | ||
} else { | ||
elements.push(path); | ||
if (path.isProperty() || path.isPrivate() || path.isStaticBlock != null && path.isStaticBlock()) { | ||
if (path.isProperty() || path.isPrivate() || path.isStaticBlock?.()) { | ||
props.push(path); | ||
@@ -155,44 +1129,33 @@ } | ||
{ | ||
if (!props.length && !isDecorated) return; | ||
if (!props.length) return; | ||
} | ||
const innerBinding = path.node.id; | ||
let ref; | ||
if (!innerBinding || path.isClassExpression()) { | ||
(0, _helperFunctionName.default)(path); | ||
if (!innerBinding || !pathIsClassDeclaration) { | ||
nameFunction(path); | ||
ref = path.scope.generateUidIdentifier("class"); | ||
} else { | ||
ref = _core.types.cloneNode(path.node.id); | ||
} | ||
const privateNamesMap = (0, _fields.buildPrivateNamesMap)(props); | ||
const privateNamesNodes = (0, _fields.buildPrivateNamesNodes)(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, privateFieldsAsSymbols != null ? privateFieldsAsSymbols : false, file); | ||
(0, _fields.transformPrivateNamesUsage)(ref, path, privateNamesMap, { | ||
privateFieldsAsProperties: privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, | ||
const classRefForDefine = ref ?? types.cloneNode(innerBinding); | ||
const privateNamesMap = buildPrivateNamesMap(props); | ||
const privateNamesNodes = buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties ?? loose, privateFieldsAsSymbols ?? false, file); | ||
transformPrivateNamesUsage(classRefForDefine, path, privateNamesMap, { | ||
privateFieldsAsProperties: privateFieldsAsSymbolsOrProperties ?? loose, | ||
noDocumentAll, | ||
innerBinding | ||
}, file); | ||
let keysNodes, staticNodes, instanceNodes, pureStaticNodes, wrapClass; | ||
let keysNodes, staticNodes, instanceNodes, pureStaticNodes, classBindingNode, wrapClass; | ||
{ | ||
if (isDecorated) { | ||
staticNodes = pureStaticNodes = keysNodes = []; | ||
({ | ||
instanceNodes, | ||
wrapClass | ||
} = (0, _decorators.buildDecoratedClass)(ref, path, elements, file)); | ||
} else { | ||
keysNodes = (0, _misc.extractComputedKeys)(path, computedPaths, file); | ||
({ | ||
staticNodes, | ||
pureStaticNodes, | ||
instanceNodes, | ||
wrapClass | ||
} = (0, _fields.buildFieldsInitNodes)(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding)); | ||
} | ||
keysNodes = extractComputedKeys(path, computedPaths, file); | ||
({ | ||
staticNodes, | ||
pureStaticNodes, | ||
instanceNodes, | ||
classBindingNode, | ||
wrapClass | ||
} = buildFieldsInitNodes(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields ?? loose, privateFieldsAsSymbolsOrProperties ?? loose, constantSuper ?? loose, innerBinding)); | ||
} | ||
if (instanceNodes.length > 0) { | ||
(0, _misc.injectInitialization)(path, constructor, instanceNodes, (referenceVisitor, state) => { | ||
{ | ||
if (isDecorated) return; | ||
} | ||
injectInitialization(path, constructor, instanceNodes, (referenceVisitor, state) => { | ||
for (const prop of props) { | ||
if (_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node) || prop.node.static) continue; | ||
if (types.isStaticBlock?.(prop.node) || prop.node.static) continue; | ||
prop.traverse(referenceVisitor, state); | ||
@@ -210,2 +1173,5 @@ } | ||
} | ||
if (classBindingNode != null && pathIsClassDeclaration) { | ||
wrappedPath.insertAfter(classBindingNode); | ||
} | ||
}, | ||
@@ -215,13 +1181,2 @@ ExportDefaultDeclaration(path, { | ||
}) { | ||
{ | ||
if (file.get(versionKey) !== "7.22.9") return; | ||
const decl = path.get("declaration"); | ||
if (decl.isClassDeclaration() && (0, _decorators.hasDecorators)(decl.node)) { | ||
if (decl.node.id) { | ||
(0, _helperSplitExportDeclaration.default)(path); | ||
} else { | ||
decl.node.type = "ClassExpression"; | ||
} | ||
} | ||
} | ||
} | ||
@@ -232,2 +1187,3 @@ } | ||
export { FEATURES, buildCheckInRHS, createClassFeaturePlugin, enableFeature, injectInitialization }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,11 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.extractComputedKeys = extractComputedKeys; | ||
exports.injectInitialization = injectInitialization; | ||
var _core = require("@babel/core"); | ||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor"); | ||
const findBareSupers = _core.traverse.visitors.merge([{ | ||
import { template, traverse, types as t } from "@babel/core"; | ||
import environmentVisitor from "@babel/helper-environment-visitor"; | ||
const findBareSupers = traverse.visitors.merge([{ | ||
Super(path) { | ||
@@ -22,3 +15,3 @@ const { | ||
} | ||
}, _helperEnvironmentVisitor.default]); | ||
}, environmentVisitor]); | ||
const referenceVisitor = { | ||
@@ -40,4 +33,4 @@ "TSTypeAnnotation|TypeAnnotation"(path) { | ||
const classNameTDZError = state.file.addHelper("classNameTDZError"); | ||
const throwNode = _core.types.callExpression(classNameTDZError, [_core.types.stringLiteral(path.node.name)]); | ||
path.replaceWith(_core.types.sequenceExpression([throwNode, path.node])); | ||
const throwNode = t.callExpression(classNameTDZError, [t.stringLiteral(path.node.name)]); | ||
path.replaceWith(t.sequenceExpression([throwNode, path.node])); | ||
path.skip(); | ||
@@ -49,10 +42,10 @@ } | ||
}; | ||
function injectInitialization(path, constructor, nodes, renamer) { | ||
export function injectInitialization(path, constructor, nodes, renamer) { | ||
if (!nodes.length) return; | ||
const isDerived = !!path.node.superClass; | ||
if (!constructor) { | ||
const newConstructor = _core.types.classMethod("constructor", _core.types.identifier("constructor"), [], _core.types.blockStatement([])); | ||
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([])); | ||
if (isDerived) { | ||
newConstructor.params = [_core.types.restElement(_core.types.identifier("args"))]; | ||
newConstructor.body.body.push(_core.template.statement.ast`super(...args)`); | ||
newConstructor.params = [t.restElement(t.identifier("args"))]; | ||
newConstructor.body.body.push(template.statement.ast`super(...args)`); | ||
} | ||
@@ -75,3 +68,3 @@ [constructor] = path.get("body").unshiftContainer("body", newConstructor); | ||
} else { | ||
bareSuper.insertAfter(nodes.map(n => _core.types.cloneNode(n))); | ||
bareSuper.insertAfter(nodes.map(n => t.cloneNode(n))); | ||
} | ||
@@ -83,3 +76,3 @@ } | ||
} | ||
function extractComputedKeys(path, computedPaths, file) { | ||
export function extractComputedKeys(path, computedPaths, file) { | ||
const declarations = []; | ||
@@ -104,4 +97,4 @@ const state = { | ||
}); | ||
declarations.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(ident), computedNode.key))); | ||
computedNode.key = _core.types.cloneNode(ident); | ||
declarations.push(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(ident), computedNode.key))); | ||
computedNode.key = t.cloneNode(ident); | ||
} | ||
@@ -108,0 +101,0 @@ } |
@@ -1,9 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.assertFieldTransformed = assertFieldTransformed; | ||
function assertFieldTransformed(path) { | ||
if (path.node.declare || false) { | ||
export function assertFieldTransformed(path) { | ||
if (path.node.declare || path.isClassProperty({ | ||
definite: true | ||
})) { | ||
throw path.buildCodeFrameError(`TypeScript 'declare' fields must first be transformed by ` + `@babel/plugin-transform-typescript.\n` + `If you have already enabled that plugin (or '@babel/preset-typescript'), make sure ` + `that it runs before any plugin related to additional class features:\n` + ` - @babel/plugin-transform-class-properties\n` + ` - @babel/plugin-transform-private-methods\n` + ` - @babel/plugin-proposal-decorators`); | ||
@@ -10,0 +6,0 @@ } |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.22.9", | ||
"version": "8.0.0-alpha.0", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -21,25 +21,29 @@ "license": "MIT", | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^7.22.5", | ||
"@babel/helper-environment-visitor": "^7.22.5", | ||
"@babel/helper-function-name": "^7.22.5", | ||
"@babel/helper-member-expression-to-functions": "^7.22.5", | ||
"@babel/helper-optimise-call-expression": "^7.22.5", | ||
"@babel/helper-replace-supers": "^7.22.9", | ||
"@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", | ||
"@babel/helper-split-export-declaration": "^7.22.6", | ||
"semver": "^6.3.1" | ||
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.0", | ||
"@babel/helper-environment-visitor": "^8.0.0-alpha.0", | ||
"@babel/helper-function-name": "^8.0.0-alpha.0", | ||
"@babel/helper-member-expression-to-functions": "^8.0.0-alpha.0", | ||
"@babel/helper-optimise-call-expression": "^8.0.0-alpha.0", | ||
"@babel/helper-replace-supers": "^8.0.0-alpha.0", | ||
"@babel/helper-skip-transparent-expression-wrappers": "^8.0.0-alpha.0", | ||
"@babel/helper-split-export-declaration": "^8.0.0-alpha.0", | ||
"semver": "^7.3.4" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0" | ||
"@babel/core": "^8.0.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.9", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/core": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0", | ||
"@babel/plugin-syntax-class-static-block": "^7.14.5", | ||
"@babel/preset-env": "^7.22.9" | ||
"@babel/preset-env": "^8.0.0-alpha.0" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"type": "commonjs" | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
330477
2330
Yes
2
+ Added@babel/code-frame@8.0.0-alpha.12(transitive)
+ Added@babel/compat-data@8.0.0-alpha.12(transitive)
+ Added@babel/core@8.0.0-alpha.12(transitive)
+ Added@babel/generator@8.0.0-alpha.12(transitive)
+ Added@babel/helper-annotate-as-pure@8.0.0-alpha.12(transitive)
+ Added@babel/helper-compilation-targets@8.0.0-alpha.12(transitive)
+ Added@babel/helper-environment-visitor@8.0.0-alpha.11(transitive)
+ Added@babel/helper-function-name@8.0.0-alpha.11(transitive)
+ Added@babel/helper-member-expression-to-functions@8.0.0-alpha.12(transitive)
+ Added@babel/helper-optimise-call-expression@8.0.0-alpha.12(transitive)
+ Added@babel/helper-replace-supers@8.0.0-alpha.12(transitive)
+ Added@babel/helper-skip-transparent-expression-wrappers@8.0.0-alpha.12(transitive)
+ Added@babel/helper-split-export-declaration@8.0.0-alpha.11(transitive)
+ Added@babel/helper-string-parser@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-identifier@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-option@8.0.0-alpha.12(transitive)
+ Added@babel/helpers@8.0.0-alpha.12(transitive)
+ Added@babel/highlight@8.0.0-alpha.12(transitive)
+ Added@babel/parser@8.0.0-alpha.12(transitive)
+ Added@babel/template@8.0.0-alpha.12(transitive)
+ Added@babel/traverse@8.0.0-alpha.12(transitive)
+ Added@babel/types@8.0.0-alpha.12(transitive)
+ Addedcaniuse-lite@1.0.30001655(transitive)
+ Addeddebug@4.3.6(transitive)
+ Addedelectron-to-chromium@1.5.13(transitive)
+ Addedglobals@15.9.0(transitive)
+ Addedjs-tokens@8.0.3(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedlru-cache@7.18.3(transitive)
+ Addedms@2.1.2(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedto-fast-properties@3.0.1(transitive)
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/compat-data@7.25.4(transitive)
- Removed@babel/core@7.25.2(transitive)
- Removed@babel/generator@7.25.6(transitive)
- Removed@babel/helper-annotate-as-pure@7.24.7(transitive)
- Removed@babel/helper-compilation-targets@7.25.2(transitive)
- Removed@babel/helper-environment-visitor@7.24.7(transitive)
- Removed@babel/helper-function-name@7.24.7(transitive)
- Removed@babel/helper-member-expression-to-functions@7.24.8(transitive)
- Removed@babel/helper-module-imports@7.24.7(transitive)
- Removed@babel/helper-module-transforms@7.25.2(transitive)
- Removed@babel/helper-optimise-call-expression@7.24.7(transitive)
- Removed@babel/helper-replace-supers@7.25.0(transitive)
- Removed@babel/helper-simple-access@7.24.7(transitive)
- Removed@babel/helper-skip-transparent-expression-wrappers@7.24.7(transitive)
- Removed@babel/helper-split-export-declaration@7.24.7(transitive)
- Removed@babel/helper-string-parser@7.24.8(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/helper-validator-option@7.24.8(transitive)
- Removed@babel/helpers@7.25.6(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@babel/parser@7.25.6(transitive)
- Removed@babel/template@7.25.0(transitive)
- Removed@babel/traverse@7.25.6(transitive)
- Removed@babel/types@7.25.6(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcaniuse-lite@1.0.30001660(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddebug@4.3.7(transitive)
- Removedelectron-to-chromium@1.5.18(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedglobals@11.12.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjsesc@2.5.2(transitive)
- Removedlru-cache@5.1.1(transitive)
- Removedms@2.1.3(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedto-fast-properties@2.0.0(transitive)
- Removedyallist@3.1.1(transitive)
Updated@babel/helper-member-expression-to-functions@^8.0.0-alpha.0
Updated@babel/helper-optimise-call-expression@^8.0.0-alpha.0
Updated@babel/helper-skip-transparent-expression-wrappers@^8.0.0-alpha.0
Updated@babel/helper-split-export-declaration@^8.0.0-alpha.0
Updatedsemver@^7.3.4