@babel/plugin-proposal-decorators
Advanced tools
Comparing version 7.20.0 to 7.22.10
@@ -7,13 +7,7 @@ "use strict"; | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
var _pluginSyntaxDecorators = require("@babel/plugin-syntax-decorators"); | ||
var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin"); | ||
var _transformerLegacy = require("./transformer-legacy"); | ||
var _transformer = require("./transformer-2022-03"); | ||
var _transformer = require("./transformer-2023-05"); | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
@@ -29,3 +23,2 @@ api.assertVersion(7); | ||
} = options; | ||
if (legacy || version === "legacy") { | ||
@@ -37,5 +30,6 @@ return { | ||
}; | ||
} else if (version === "2021-12" || version === "2022-03") { | ||
} else if (version === "2021-12" || version === "2022-03" || version === "2023-01" || version === "2023-05") { | ||
return (0, _transformer.default)(api, options, version); | ||
} else { | ||
api.assertVersion("^7.0.2"); | ||
return (0, _helperCreateClassFeaturesPlugin.createClassFeaturePlugin)({ | ||
@@ -49,5 +43,4 @@ name: "proposal-decorators", | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
@@ -7,9 +7,6 @@ "use strict"; | ||
exports.default = void 0; | ||
var _core = require("@babel/core"); | ||
const buildClassDecorator = _core.template.statement(` | ||
DECORATOR(CLASS_REF = INNER) || CLASS_REF; | ||
`); | ||
const buildClassPrototype = (0, _core.template)(` | ||
@@ -32,3 +29,2 @@ CLASS_REF.prototype; | ||
const WARNING_CALLS = new WeakSet(); | ||
function applyEnsureOrdering(path) { | ||
@@ -44,3 +40,2 @@ const decorators = (path.isClass() ? [path, ...path.get("body.body")] : path.get("properties")).reduce((acc, prop) => acc.concat(prop.node.decorators || []), []); | ||
} | ||
function applyClassDecorators(classPath) { | ||
@@ -59,7 +54,6 @@ if (!hasClassDecorators(classPath.node)) return; | ||
} | ||
function hasClassDecorators(classNode) { | ||
return !!(classNode.decorators && classNode.decorators.length); | ||
var _classNode$decorators; | ||
return !!((_classNode$decorators = classNode.decorators) != null && _classNode$decorators.length); | ||
} | ||
function applyMethodDecorators(path, state) { | ||
@@ -69,11 +63,8 @@ if (!hasMethodDecorators(path.node.body.body)) return; | ||
} | ||
function hasMethodDecorators(body) { | ||
return body.some(node => { | ||
var _node$decorators; | ||
return (_node$decorators = node.decorators) == null ? void 0 : _node$decorators.length; | ||
}); | ||
} | ||
function applyObjectDecorators(path, state) { | ||
@@ -83,3 +74,2 @@ if (!hasMethodDecorators(path.node.properties)) return; | ||
} | ||
function applyTargetDecorators(path, state, decoratedProps) { | ||
@@ -89,3 +79,2 @@ const name = path.scope.generateDeclaredUidIdentifier(path.isClass() ? "class" : "obj"); | ||
let decorators = []; | ||
if (node.decorators != null) { | ||
@@ -95,9 +84,6 @@ decorators = node.decorators; | ||
} | ||
if (decorators.length === 0) return acc; | ||
if (node.computed) { | ||
throw path.buildCodeFrameError("Computed method/property decorators are not yet supported."); | ||
} | ||
const property = _core.types.isLiteral(node.key) ? node.key : _core.types.stringLiteral(node.key.name); | ||
@@ -107,3 +93,2 @@ const target = path.isClass() && !node.static ? buildClassPrototype({ | ||
}).expression : name; | ||
if (_core.types.isClassProperty(node, { | ||
@@ -129,3 +114,2 @@ static: false | ||
} | ||
return acc; | ||
@@ -135,3 +119,2 @@ }, []); | ||
} | ||
function decoratedClassToExpression({ | ||
@@ -144,7 +127,5 @@ node, | ||
} | ||
const ref = node.id ? _core.types.cloneNode(node.id) : scope.generateUidIdentifier("class"); | ||
return _core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]); | ||
} | ||
const visitor = { | ||
@@ -155,6 +136,4 @@ ExportDefaultDeclaration(path) { | ||
const replacement = decoratedClassToExpression(decl); | ||
if (replacement) { | ||
const [varDeclPath] = path.replaceWithMultiple([replacement, _core.types.exportNamedDeclaration(null, [_core.types.exportSpecifier(_core.types.cloneNode(replacement.declarations[0].id), _core.types.identifier("default"))])]); | ||
if (!decl.node.id) { | ||
@@ -165,6 +144,4 @@ path.scope.registerDeclaration(varDeclPath); | ||
}, | ||
ClassDeclaration(path) { | ||
const replacement = decoratedClassToExpression(path); | ||
if (replacement) { | ||
@@ -179,3 +156,2 @@ const [newPath] = path.replaceWith(replacement); | ||
}, | ||
ClassExpression(path, state) { | ||
@@ -185,3 +161,2 @@ const decoratedClass = applyEnsureOrdering(path) || applyClassDecorators(path) || applyMethodDecorators(path, state); | ||
}, | ||
ObjectExpression(path, state) { | ||
@@ -191,3 +166,2 @@ const decoratedObject = applyEnsureOrdering(path) || applyObjectDecorators(path, state); | ||
}, | ||
AssignmentExpression(path, state) { | ||
@@ -197,14 +171,10 @@ if (!WARNING_CALLS.has(path.node.right)) return; | ||
}, | ||
CallExpression(path, state) { | ||
if (path.node.arguments.length !== 3) return; | ||
if (!WARNING_CALLS.has(path.node.arguments[2])) return; | ||
if (path.node.callee.name !== state.addHelper("defineProperty").name) { | ||
return; | ||
} | ||
path.replaceWith(_core.types.callExpression(state.addHelper("initializerDefineProperty"), [_core.types.cloneNode(path.get("arguments")[0].node), _core.types.cloneNode(path.get("arguments")[1].node), _core.types.cloneNode(path.get("arguments.2.arguments")[0].node), _core.types.cloneNode(path.get("arguments.2.arguments")[1].node)])); | ||
} | ||
}; | ||
@@ -211,0 +181,0 @@ var _default = visitor; |
{ | ||
"name": "@babel/plugin-proposal-decorators", | ||
"version": "7.20.0", | ||
"version": "7.22.10", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -23,7 +23,7 @@ "license": "MIT", | ||
"dependencies": { | ||
"@babel/helper-create-class-features-plugin": "^7.19.0", | ||
"@babel/helper-plugin-utils": "^7.19.0", | ||
"@babel/helper-replace-supers": "^7.19.1", | ||
"@babel/helper-split-export-declaration": "^7.18.6", | ||
"@babel/plugin-syntax-decorators": "^7.19.0" | ||
"@babel/helper-create-class-features-plugin": "^7.22.10", | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/helper-replace-supers": "^7.22.9", | ||
"@babel/helper-split-export-declaration": "^7.22.6", | ||
"@babel/plugin-syntax-decorators": "^7.22.10" | ||
}, | ||
@@ -34,8 +34,8 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.19.6", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
"@babel/traverse": "^7.20.0", | ||
"@babel/core": "^7.22.10", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/traverse": "^7.22.10", | ||
"@types/charcodes": "^0.2.0", | ||
"array.prototype.concat": "^1.0.2", | ||
"babel-plugin-polyfill-es-shims": "^0.7.1", | ||
"babel-plugin-polyfill-es-shims": "^0.9.2", | ||
"charcodes": "^0.2.0", | ||
@@ -42,0 +42,0 @@ "object.getownpropertydescriptors": "^2.1.1" |
@@ -5,3 +5,3 @@ # @babel/plugin-proposal-decorators | ||
See our website [@babel/plugin-proposal-decorators](https://babeljs.io/docs/en/babel-plugin-proposal-decorators) for more information. | ||
See our website [@babel/plugin-proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators) for more information. | ||
@@ -8,0 +8,0 @@ ## Install |
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
137148
862