babel-plugin-transform-decorators
Advanced tools
Comparing version 7.0.0-alpha.15 to 7.0.0-alpha.16
@@ -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" | ||
} | ||
} |
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
12634
168
+ Addedansi-styles@3.2.1(transitive)
+ Addedbabel-code-frame@7.0.0-alpha.16(transitive)
+ Addedbabel-helper-function-name@7.0.0-alpha.16(transitive)
+ Addedbabel-helper-get-function-arity@7.0.0-alpha.16(transitive)
+ Addedbabel-messages@7.0.0-alpha.16(transitive)
+ Addedbabel-plugin-syntax-decorators@7.0.0-alpha.16(transitive)
+ Addedbabel-template@7.0.0-alpha.16(transitive)
+ Addedbabel-traverse@7.0.0-alpha.16(transitive)
+ Addedbabel-types@7.0.0-alpha.16(transitive)
+ Addedbabylon@7.0.0-beta.17(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedglobals@10.4.0(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedbabel-code-frame@7.0.0-alpha.15(transitive)
- Removedbabel-helper-function-name@7.0.0-alpha.15(transitive)
- Removedbabel-helper-get-function-arity@7.0.0-alpha.15(transitive)
- Removedbabel-messages@7.0.0-alpha.15(transitive)
- Removedbabel-plugin-syntax-decorators@7.0.0-alpha.15(transitive)
- Removedbabel-template@7.0.0-alpha.15(transitive)
- Removedbabel-traverse@7.0.0-alpha.15(transitive)
- Removedbabel-types@7.0.0-alpha.15(transitive)
- Removedbabylon@7.0.0-beta.13(transitive)
- Removedchalk@1.1.3(transitive)
- Removedglobals@9.18.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedto-fast-properties@1.0.3(transitive)