@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.20.12 to 7.21.0
@@ -45,3 +45,3 @@ "use strict"; | ||
} | ||
function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, state) { | ||
function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) { | ||
const initNodes = []; | ||
@@ -60,2 +60,4 @@ for (const [name, value] of privateNamesMap) { | ||
init = _core.types.callExpression(state.addHelper("classPrivateFieldLooseKey"), [_core.types.stringLiteral(name)]); | ||
} else if (privateFieldsAsSymbols) { | ||
init = _core.types.callExpression(_core.types.identifier("Symbol"), [_core.types.stringLiteral(name)]); | ||
} else if (!isStatic) { | ||
@@ -375,10 +377,10 @@ init = _core.types.newExpression(_core.types.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []); | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return _core.template.statement.ast` | ||
Object.defineProperty(${ref}, ${_core.types.cloneNode(id)}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
writable: true, | ||
value: ${value} | ||
}); | ||
`; | ||
return inheritPropComments(_core.template.statement.ast` | ||
Object.defineProperty(${ref}, ${_core.types.cloneNode(id)}, { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
writable: true, | ||
value: ${value} | ||
}); | ||
`, prop); | ||
} | ||
@@ -392,19 +394,19 @@ function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { | ||
if (!state.availableHelper("classPrivateFieldInitSpec")) { | ||
return _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}, | ||
})`; | ||
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 _core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
{ | ||
writable: true, | ||
value: ${value} | ||
}, | ||
)`; | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
{ | ||
writable: true, | ||
value: ${value} | ||
}, | ||
)`, prop); | ||
} | ||
@@ -425,21 +427,21 @@ function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { | ||
})); | ||
return _core.template.statement.ast` | ||
return inheritPropComments(_core.template.statement.ast` | ||
var ${_core.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(_core.template.statement.ast` | ||
var ${_core.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()} | ||
} | ||
`; | ||
} | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return _core.template.statement.ast` | ||
var ${_core.types.cloneNode(id)} = { | ||
// configurable is false by default | ||
// enumerable is false by default | ||
writable: true, | ||
value: ${value} | ||
}; | ||
`; | ||
writable: true, | ||
value: ${value} | ||
}; | ||
`, prop); | ||
} | ||
@@ -457,3 +459,3 @@ function buildPrivateMethodInitLoose(ref, prop, privateNamesMap) { | ||
if (methodId) { | ||
return _core.template.statement.ast` | ||
return inheritPropComments(_core.template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -465,3 +467,3 @@ // configurable is false by default | ||
}); | ||
`; | ||
`, prop); | ||
} | ||
@@ -473,11 +475,11 @@ const isAccessor = getId || setId; | ||
})); | ||
return _core.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()} | ||
}); | ||
`; | ||
return inheritPropComments(_core.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); | ||
} | ||
@@ -497,3 +499,3 @@ } | ||
} | ||
return buildPrivateInstanceMethodInitalization(ref, prop, privateNamesMap, state); | ||
return buildPrivateInstanceMethodInitialization(ref, prop, privateNamesMap, state); | ||
} | ||
@@ -512,21 +514,21 @@ function buildPrivateAccessorInitialization(ref, prop, privateNamesMap, state) { | ||
if (!state.availableHelper("classPrivateFieldInitSpec")) { | ||
return _core.template.statement.ast` | ||
${id}.set(${ref}, { | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}); | ||
`; | ||
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 _core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
{ | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}, | ||
)`; | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)}, | ||
{ | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}, | ||
)`, prop); | ||
} | ||
function buildPrivateInstanceMethodInitalization(ref, prop, privateNamesMap, state) { | ||
function buildPrivateInstanceMethodInitialization(ref, prop, privateNamesMap, state) { | ||
const privateName = privateNamesMap.get(prop.node.key.id.name); | ||
@@ -538,10 +540,10 @@ const { | ||
if (!state.availableHelper("classPrivateMethodInitSpec")) { | ||
return _core.template.statement.ast`${id}.add(${ref})`; | ||
return inheritPropComments(_core.template.statement.ast`${id}.add(${ref})`, prop); | ||
} | ||
} | ||
const helper = state.addHelper("classPrivateMethodInitSpec"); | ||
return _core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)} | ||
)`; | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
${_core.types.cloneNode(id)} | ||
)`, prop); | ||
} | ||
@@ -554,3 +556,3 @@ function buildPublicFieldInitLoose(ref, prop) { | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return _core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(ref, key, computed || _core.types.isLiteral(key)), value)); | ||
return inheritPropComments(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(ref, key, computed || _core.types.isLiteral(key)), value)), prop); | ||
} | ||
@@ -563,3 +565,3 @@ function buildPublicFieldInitSpec(ref, prop, state) { | ||
const value = prop.node.value || prop.scope.buildUndefinedNode(); | ||
return _core.types.expressionStatement(_core.types.callExpression(state.addHelper("defineProperty"), [ref, computed || _core.types.isLiteral(key) ? key : _core.types.stringLiteral(key.name), value])); | ||
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); | ||
} | ||
@@ -581,3 +583,13 @@ function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) { | ||
})); | ||
return _core.template.statement.ast` | ||
return inheritPropComments(_core.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(_core.template.statement.ast` | ||
Object.defineProperty(${ref}, ${id}, { | ||
@@ -587,15 +599,5 @@ // configurable is false by default | ||
// writable is false by default | ||
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, | ||
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} | ||
}) | ||
`; | ||
} | ||
return _core.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} | ||
}); | ||
`; | ||
value: ${methodId.name} | ||
}); | ||
`, prop); | ||
} | ||
@@ -635,3 +637,3 @@ function buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties = false) { | ||
} | ||
return _core.types.functionDeclaration(_core.types.cloneNode(declId), params, body, generator, async); | ||
return inheritPropComments(_core.types.functionDeclaration(_core.types.cloneNode(declId), params, body, generator, async), prop); | ||
} | ||
@@ -712,2 +714,7 @@ const thisContextVisitor = _core.traverse.visitors.merge([{ | ||
} | ||
function inheritPropComments(node, prop) { | ||
_core.types.inheritLeadingComments(node, prop.node); | ||
_core.types.inheritInnerComments(node, prop.node); | ||
return node; | ||
} | ||
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, state, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) { | ||
@@ -742,5 +749,5 @@ let needsClassRef = false; | ||
if (blockBody.length === 1 && _core.types.isExpressionStatement(blockBody[0])) { | ||
staticNodes.push(blockBody[0]); | ||
staticNodes.push(inheritPropComments(blockBody[0], prop)); | ||
} else { | ||
staticNodes.push(_core.template.statement.ast`(() => { ${blockBody} })()`); | ||
staticNodes.push(_core.types.inheritsComments(_core.template.statement.ast`(() => { ${blockBody} })()`, prop.node)); | ||
} | ||
@@ -747,0 +754,0 @@ break; |
@@ -39,3 +39,3 @@ "use strict"; | ||
var _typescript = require("./typescript"); | ||
const version = "7.20.12".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const version = "7.21.0".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const versionKey = "@babel/plugin-class-features/version"; | ||
@@ -53,5 +53,10 @@ function createClassFeaturePlugin({ | ||
const setPublicClassFields = api.assumption("setPublicClassFields"); | ||
const privateFieldsAsSymbols = api.assumption("privateFieldsAsSymbols"); | ||
const privateFieldsAsProperties = api.assumption("privateFieldsAsProperties"); | ||
const constantSuper = api.assumption("constantSuper"); | ||
const noDocumentAll = api.assumption("noDocumentAll"); | ||
if (privateFieldsAsProperties && privateFieldsAsSymbols) { | ||
throw new Error(`Cannot enable both the "privateFieldsAsProperties" and ` + `"privateFieldsAsSymbols" assumptions as the same time.`); | ||
} | ||
const privateFieldsAsSymbolsOrProperties = privateFieldsAsProperties || privateFieldsAsSymbols; | ||
if (loose === true) { | ||
@@ -65,4 +70,7 @@ const explicit = []; | ||
} | ||
if (privateFieldsAsSymbols !== undefined) { | ||
explicit.push(`"privateFieldsAsSymbols"`); | ||
} | ||
if (explicit.length !== 0) { | ||
console.warn(`[${name}]: You are using the "loose: true" option and you are` + ` explicitly setting a value for the ${explicit.join(" and ")}` + ` assumption${explicit.length > 1 ? "s" : ""}. The "loose" option` + ` can cause incompatibilities with the other class features` + ` plugins, so it's recommended that you replace it with the` + ` following top-level option:\n` + `\t"assumptions": {\n` + `\t\t"setPublicClassFields": true,\n` + `\t\t"privateFieldsAsProperties": true\n` + `\t}`); | ||
console.warn(`[${name}]: You are using the "loose: true" option and you are` + ` explicitly setting a value for the ${explicit.join(" and ")}` + ` assumption${explicit.length > 1 ? "s" : ""}. The "loose" option` + ` can cause incompatibilities with the other class features` + ` plugins, so it's recommended that you replace it with the` + ` following top-level option:\n` + `\t"assumptions": {\n` + `\t\t"setPublicClassFields": true,\n` + `\t\t"privateFieldsAsSymbols": true\n` + `\t}`); | ||
} | ||
@@ -147,5 +155,5 @@ } | ||
const privateNamesMap = (0, _fields.buildPrivateNamesMap)(props); | ||
const privateNamesNodes = (0, _fields.buildPrivateNamesNodes)(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, file); | ||
const privateNamesNodes = (0, _fields.buildPrivateNamesNodes)(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, privateFieldsAsSymbols != null ? privateFieldsAsSymbols : false, file); | ||
(0, _fields.transformPrivateNamesUsage)(ref, path, privateNamesMap, { | ||
privateFieldsAsProperties: privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, | ||
privateFieldsAsProperties: privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, | ||
noDocumentAll, | ||
@@ -169,3 +177,3 @@ innerBinding | ||
wrapClass | ||
} = (0, _fields.buildFieldsInitNodes)(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding)); | ||
} = (0, _fields.buildFieldsInitNodes)(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding)); | ||
} | ||
@@ -172,0 +180,0 @@ } |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.20.12", | ||
"version": "7.21.0", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -23,4 +23,4 @@ "license": "MIT", | ||
"@babel/helper-environment-visitor": "^7.18.9", | ||
"@babel/helper-function-name": "^7.19.0", | ||
"@babel/helper-member-expression-to-functions": "^7.20.7", | ||
"@babel/helper-function-name": "^7.21.0", | ||
"@babel/helper-member-expression-to-functions": "^7.21.0", | ||
"@babel/helper-optimise-call-expression": "^7.18.6", | ||
@@ -35,3 +35,3 @@ "@babel/helper-replace-supers": "^7.20.7", | ||
"devDependencies": { | ||
"@babel/core": "^7.20.12", | ||
"@babel/core": "^7.21.0", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
@@ -38,0 +38,0 @@ "@babel/plugin-syntax-class-static-block": "^7.14.5", |
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
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
185599
1405
+ Added@babel/code-frame@7.25.7(transitive)
+ Added@babel/compat-data@7.25.8(transitive)
+ Added@babel/core@7.25.8(transitive)
+ Added@babel/generator@7.25.7(transitive)
+ Added@babel/helper-annotate-as-pure@7.25.7(transitive)
+ Added@babel/helper-compilation-targets@7.25.7(transitive)
+ Added@babel/helper-member-expression-to-functions@7.25.7(transitive)
+ Added@babel/helper-module-imports@7.25.7(transitive)
+ Added@babel/helper-module-transforms@7.25.7(transitive)
+ Added@babel/helper-optimise-call-expression@7.25.7(transitive)
+ Added@babel/helper-replace-supers@7.25.7(transitive)
+ Added@babel/helper-simple-access@7.25.7(transitive)
+ Added@babel/helper-skip-transparent-expression-wrappers@7.25.7(transitive)
+ Added@babel/helper-string-parser@7.25.7(transitive)
+ Added@babel/helper-validator-identifier@7.25.7(transitive)
+ Added@babel/helper-validator-option@7.25.7(transitive)
+ Added@babel/helpers@7.25.7(transitive)
+ Added@babel/highlight@7.25.7(transitive)
+ Added@babel/parser@7.25.8(transitive)
+ Added@babel/template@7.25.7(transitive)
+ Added@babel/traverse@7.25.7(transitive)
+ Added@babel/types@7.25.8(transitive)
+ Addedbrowserslist@4.24.0(transitive)
+ Addedelectron-to-chromium@1.5.41(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
- Removed@babel/code-frame@7.25.9(transitive)
- Removed@babel/compat-data@7.25.9(transitive)
- Removed@babel/core@7.25.9(transitive)
- Removed@babel/generator@7.25.9(transitive)
- Removed@babel/helper-annotate-as-pure@7.25.9(transitive)
- Removed@babel/helper-compilation-targets@7.25.9(transitive)
- Removed@babel/helper-member-expression-to-functions@7.25.9(transitive)
- Removed@babel/helper-module-imports@7.25.9(transitive)
- Removed@babel/helper-module-transforms@7.25.9(transitive)
- Removed@babel/helper-optimise-call-expression@7.25.9(transitive)
- Removed@babel/helper-replace-supers@7.25.9(transitive)
- Removed@babel/helper-simple-access@7.25.9(transitive)
- Removed@babel/helper-skip-transparent-expression-wrappers@7.25.9(transitive)
- Removed@babel/helper-string-parser@7.25.9(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@babel/helper-validator-option@7.25.9(transitive)
- Removed@babel/helpers@7.25.9(transitive)
- Removed@babel/highlight@7.25.9(transitive)
- Removed@babel/parser@7.25.9(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.25.9(transitive)
- Removed@babel/types@7.25.9(transitive)
- Removedbrowserslist@4.24.2(transitive)
- Removedelectron-to-chromium@1.5.45(transitive)