Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-class-properties

Package Overview
Dependencies
Maintainers
6
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-class-properties - npm Package Compare versions

Comparing version 6.18.0 to 6.19.0

76

lib/index.js

@@ -29,2 +29,22 @@ "use strict";

var buildObjectDefineProperty = (0, _babelTemplate2.default)("\n Object.defineProperty(REF, KEY, {\n // configurable is false by default\n enumerable: true,\n writable: true,\n value: VALUE\n });\n ");
var buildClassPropertySpec = function buildClassPropertySpec(ref, _ref2) {
var key = _ref2.key,
value = _ref2.value,
computed = _ref2.computed;
return buildObjectDefineProperty({
REF: ref,
KEY: t.isIdentifier(key) && !computed ? t.stringLiteral(key.name) : key,
VALUE: value ? value : t.identifier("undefined")
});
};
var buildClassPropertyNonSpec = function buildClassPropertyNonSpec(ref, _ref3) {
var key = _ref3.key,
value = _ref3.value,
computed = _ref3.computed;
return t.expressionStatement(t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value));
};
return {

@@ -34,3 +54,4 @@ inherits: require("babel-plugin-syntax-class-properties"),

visitor: {
Class: function Class(path) {
Class: function Class(path, state) {
var buildClassProperty = state.opts.spec ? buildClassPropertySpec : buildClassPropertyNonSpec;
var isDerived = !!path.node.superClass;

@@ -42,14 +63,14 @@ var constructor = void 0;

for (var _iterator = body.get("body"), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref2;
var _ref4;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref2 = _iterator[_i++];
_ref4 = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref2 = _i.value;
_ref4 = _i.value;
}
var _path = _ref2;
var _path = _ref4;

@@ -78,26 +99,27 @@ if (_path.isClassProperty()) {

for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref3;
var _ref5;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref3 = _iterator2[_i2++];
_ref5 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref3 = _i2.value;
_ref5 = _i2.value;
}
var _prop = _ref3;
var _prop = _ref5;
var propNode = _prop.node;
if (propNode.decorators && propNode.decorators.length > 0) continue;
if (!propNode.value) continue;
if (!state.opts.spec && !propNode.value) continue;
var isStatic = propNode.static;
var isComputed = propNode.computed || t.isLiteral(_prop.key);
if (isStatic) {
nodes.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(ref, propNode.key, isComputed), propNode.value)));
nodes.push(buildClassProperty(ref, propNode));
} else {
instanceBody.push(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.thisExpression(), propNode.key, isComputed), propNode.value)));
if (!propNode.value) continue;
instanceBody.push(buildClassProperty(t.thisExpression(), propNode));
}

@@ -125,14 +147,14 @@ }

for (var _iterator3 = props, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref4;
var _ref6;
if (_isArray3) {
if (_i3 >= _iterator3.length) break;
_ref4 = _iterator3[_i3++];
_ref6 = _iterator3[_i3++];
} else {
_i3 = _iterator3.next();
if (_i3.done) break;
_ref4 = _i3.value;
_ref6 = _i3.value;
}
var prop = _ref4;
var prop = _ref6;

@@ -155,14 +177,14 @@ prop.traverse(referenceVisitor, collisionState);

for (var _iterator4 = bareSupers, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
var _ref5;
var _ref7;
if (_isArray4) {
if (_i4 >= _iterator4.length) break;
_ref5 = _iterator4[_i4++];
_ref7 = _iterator4[_i4++];
} else {
_i4 = _iterator4.next();
if (_i4.done) break;
_ref5 = _i4.value;
_ref7 = _i4.value;
}
var bareSuper = _ref5;
var bareSuper = _ref7;

@@ -177,14 +199,14 @@ bareSuper.insertAfter(instanceBody);

for (var _iterator5 = props, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : (0, _getIterator3.default)(_iterator5);;) {
var _ref6;
var _ref8;
if (_isArray5) {
if (_i5 >= _iterator5.length) break;
_ref6 = _iterator5[_i5++];
_ref8 = _iterator5[_i5++];
} else {
_i5 = _iterator5.next();
if (_i5.done) break;
_ref6 = _i5.value;
_ref8 = _i5.value;
}
var _prop2 = _ref6;
var _prop2 = _ref8;

@@ -231,4 +253,8 @@ _prop2.remove();

var _babelTemplate = require("babel-template");
var _babelTemplate2 = _interopRequireDefault(_babelTemplate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports["default"];
{
"name": "babel-plugin-transform-class-properties",
"version": "6.18.0",
"version": "6.19.0",
"description": "This plugin transforms static class properties as well as properties declared with the property initializer syntax",

@@ -14,3 +14,4 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-class-properties",

"babel-plugin-syntax-class-properties": "^6.8.0",
"babel-runtime": "^6.9.1"
"babel-runtime": "^6.9.1",
"babel-template": "^6.15.0"
},

@@ -17,0 +18,0 @@ "devDependencies": {

@@ -9,2 +9,7 @@ # babel-plugin-transform-class-properties

### Options: `spec`
- Class properties are compiled to use `Object.defineProperty`
- Static fields are now defined even if they are not initialized
## Usage

@@ -17,5 +22,13 @@

```json
// without options
{
"plugins": ["transform-class-properties"]
}
// with options
{
"plugins": [
["transform-class-properties", { "spec": true }]
]
}
```

@@ -22,0 +35,0 @@

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