Socket
Socket
Sign inDemoInstall

babel-plugin-transform-decorators

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-decorators - npm Package Compare versions

Comparing version 7.0.0-alpha.15 to 7.0.0-alpha.16

44

lib/index.js

@@ -48,3 +48,2 @@ "use strict";

}, []);
var identDecorators = decorators.filter(function (decorator) {

@@ -54,3 +53,2 @@ return !t.isIdentifier(decorator.expression);

if (identDecorators.length === 0) return;
return t.sequenceExpression(identDecorators.map(function (decorator) {

@@ -66,7 +64,4 @@ var expression = decorator.expression;

classPath.node.decorators = null;
if (decorators.length === 0) return;
var name = classPath.scope.generateDeclaredUidIdentifier("class");
return decorators.map(function (dec) {

@@ -87,5 +82,3 @@ return dec.expression;

});
if (!hasMethodDecorators) return;
return applyTargetDecorators(path, state, path.node.body.body);

@@ -98,5 +91,3 @@ }

});
if (!hasMethodDecorators) return;
return applyTargetDecorators(path, state, path.node.properties);

@@ -107,7 +98,5 @@ }

var name = path.scope.generateDeclaredUidIdentifier(path.isClass() ? "class" : "obj");
var exprs = decoratedProps.reduce(function (acc, node) {
var decorators = node.decorators || [];
node.decorators = null;
if (decorators.length === 0) return acc;

@@ -120,3 +109,2 @@

var property = t.isLiteral(node.key) ? node.key : t.stringLiteral(node.key.name);
var target = path.isClass() && !node.static ? buildClassPrototype({

@@ -126,8 +114,8 @@ CLASS_REF: name

if (t.isClassProperty(node, { static: false })) {
if (t.isClassProperty(node, {
static: false
})) {
var descriptor = path.scope.generateDeclaredUidIdentifier("descriptor");
var initializer = node.value ? t.functionExpression(null, [], t.blockStatement([t.returnStatement(node.value)])) : t.nullLiteral();
node.value = t.callExpression(ensureInitializerWarning(path, state), [descriptor, t.thisExpression()]);
acc = acc.concat([t.assignmentExpression("=", descriptor, t.callExpression(ensureApplyDecoratedDescriptorHelper(path, state), [target, property, t.arrayExpression(decorators.map(function (dec) {

@@ -139,3 +127,5 @@ return dec.expression;

return dec.expression;
})), t.isObjectProperty(node) || t.isClassProperty(node, { static: true }) ? buildGetObjectInitializer({
})), t.isObjectProperty(node) || t.isClassProperty(node, {
static: true
}) ? buildGetObjectInitializer({
TEMP: path.scope.generateDeclaredUidIdentifier("init"),

@@ -152,3 +142,2 @@ TARGET: target,

}, []);
return t.sequenceExpression([t.assignmentExpression("=", name, path.node), t.sequenceExpression(exprs), name]);

@@ -159,12 +148,8 @@ }

inherits: _babelPluginSyntaxDecorators2.default,
visitor: {
ExportDefaultDeclaration: function ExportDefaultDeclaration(path) {
if (!path.get("declaration").isClassDeclaration()) return;
var node = path.node;
var ref = node.declaration.id || path.scope.generateUidIdentifier("default");
node.declaration.id = ref;
path.replaceWith(node.declaration);

@@ -175,6 +160,3 @@ path.insertAfter(t.exportNamedDeclaration(null, [t.exportSpecifier(ref, t.identifier("default"))]));

var node = path.node;
var ref = node.id || path.scope.generateUidIdentifier("class");
path.replaceWith(t.variableDeclaration("let", [t.variableDeclarator(ref, t.toExpression(node))]));

@@ -184,3 +166,2 @@ },

var decoratedClass = applyEnsureOrdering(path) || applyClassDecorators(path, state) || applyMethodDecorators(path, state);
if (decoratedClass) path.replaceWith(decoratedClass);

@@ -190,3 +171,2 @@ },

var decoratedObject = applyEnsureOrdering(path) || applyObjectDecorators(path, state);
if (decoratedObject) path.replaceWith(decoratedObject);

@@ -196,7 +176,9 @@ },

if (!state.initializerWarningHelper) return;
if (!path.get("left").isMemberExpression()) return;
if (!path.get("left.property").isIdentifier()) return;
if (!path.get("right").isCallExpression()) return;
if (!path.get("right.callee").isIdentifier({ name: state.initializerWarningHelper.name })) {
if (!path.get("right.callee").isIdentifier({
name: state.initializerWarningHelper.name
})) {
return;

@@ -222,13 +204,7 @@ }

var buildClassDecorator = (0, _babelTemplate2.default)("\n DECORATOR(CLASS_REF = INNER) || CLASS_REF;\n");
var buildClassPrototype = (0, _babelTemplate2.default)("\n CLASS_REF.prototype;\n");
var buildGetDescriptor = (0, _babelTemplate2.default)("\n Object.getOwnPropertyDescriptor(TARGET, PROPERTY);\n");
var buildGetObjectInitializer = (0, _babelTemplate2.default)("\n (TEMP = Object.getOwnPropertyDescriptor(TARGET, PROPERTY), (TEMP = TEMP ? TEMP.value : undefined), {\n enumerable: true,\n configurable: true,\n writable: true,\n initializer: function(){\n return TEMP;\n }\n })\n");
var buildInitializerWarningHelper = (0, _babelTemplate2.default)("\n function NAME(descriptor, context){\n throw new Error(\n 'Decorating class property failed. Please ensure that ' +\n 'transform-class-properties is enabled.'\n );\n }\n");
var buildInitializerDefineProperty = (0, _babelTemplate2.default)("\n function NAME(target, property, descriptor, context){\n if (!descriptor) return;\n\n Object.defineProperty(target, property, {\n enumerable: descriptor.enumerable,\n configurable: descriptor.configurable,\n writable: descriptor.writable,\n value: descriptor.initializer ? descriptor.initializer.call(context) : void 0,\n });\n }\n");
var buildApplyDecoratedDescriptor = (0, _babelTemplate2.default)("\n function NAME(target, property, decorators, descriptor, context){\n var desc = {};\n Object['ke' + 'ys'](descriptor).forEach(function(key){\n desc[key] = descriptor[key];\n });\n desc.enumerable = !!desc.enumerable;\n desc.configurable = !!desc.configurable;\n if ('value' in desc || desc.initializer){\n desc.writable = true;\n }\n\n desc = decorators.slice().reverse().reduce(function(desc, decorator){\n return decorator(target, property, desc) || desc;\n }, desc);\n\n if (context && desc.initializer !== void 0){\n desc.value = desc.initializer ? desc.initializer.call(context) : void 0;\n desc.initializer = undefined;\n }\n\n if (desc.initializer === void 0){\n // This is a hack to avoid this being processed by 'transform-runtime'.\n // See issue #9.\n Object['define' + 'Property'](target, property, desc);\n desc = null;\n }\n\n return desc;\n }\n");
{
"name": "babel-plugin-transform-decorators",
"version": "7.0.0-alpha.15",
"version": "7.0.0-alpha.16",
"author": "Logan Smyth <loganfsmyth@gmail.com>",

@@ -15,8 +15,8 @@ "license": "MIT",

"dependencies": {
"babel-plugin-syntax-decorators": "7.0.0-alpha.15",
"babel-template": "7.0.0-alpha.15"
"babel-plugin-syntax-decorators": "7.0.0-alpha.16",
"babel-template": "7.0.0-alpha.16"
},
"devDependencies": {
"babel-helper-plugin-test-runner": "7.0.0-alpha.15"
"babel-helper-plugin-test-runner": "7.0.0-alpha.16"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc