New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-react-jsx-props

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-react-jsx-props - npm Package Compare versions

Comparing version 1.2.2 to 2.0.0

63

lib/index.js

@@ -8,10 +8,6 @@ 'use strict';

var _typeof2 = require('babel-runtime/helpers/typeof');
var _keys = require('babel-runtime/core-js/object/keys');
var _typeof3 = _interopRequireDefault(_typeof2);
var _keys2 = _interopRequireDefault(_keys);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
exports.default = function (_ref) {

@@ -55,15 +51,32 @@ var

var _unquote = require('unquote');
var _unquote2 = _interopRequireDefault(_unquote);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function parseExpression(code) {
var result = (0, _babylon.parse)('x = ' + (0, _stringify2.default)(code), { sourceType: "script", plugins: ['jsx'] });
/* eslint-disable no-param-reassign */
return (0, _babelTypes.cloneDeep)(result.program.body[0].expression.right);
function parseExpression(code, t) {
var result = (0, _babylon.parse)('x = ' + code, { sourceType: 'script', plugins: ['jsx'] });
var node = (0, _babelTypes.cloneDeep)(result.program.body[0].expression.right);
// Everything besides strings gets wrapped in an expression container
if (!t.isStringLiteral(node)) {
node = t.jSXExpressionContainer(node);
}
return node;
}
function pushPropsToJSXElement(props, path, t) {
var _loop = function _loop(prop) {
var value = void 0;
(0, _keys2.default)(props).forEach(function (prop) {
var propValue = props[prop];
if (typeof propValue !== 'string') {
throw new Error('The value for prop "' + prop + '" is not a string. (e.g "3" => 3, "\'3\'" => \'3\', ...)');
}
if (prop === 'children') {

@@ -75,4 +88,4 @@ // we need to handle children in a special way

if (isText && typeof propValue === 'string') {
path.parentPath.node.children = [t.jSXText(propValue)];
if (isText) {
path.parentPath.node.children = [t.jSXText((0, _unquote2.default)(propValue))];

@@ -86,19 +99,7 @@ // If it was a self-closing tag make it a non-self-closing one

return 'continue';
return;
}
var id = t.jSXIdentifier(prop);
switch (typeof propValue === 'undefined' ? 'undefined' : (0, _typeof3.default)(propValue)) {
case 'string':
value = t.stringLiteral(propValue);
break;
case 'number':
value = t.jSXExpressionContainer(t.numericLiteral(propValue));
break;
case 'boolean':
value = t.jSXExpressionContainer(t.booleanLiteral(propValue));
break;
default:
value = t.jSXExpressionContainer(parseExpression(propValue, path.node.loc.line));
}
var value = parseExpression(propValue, t);

@@ -115,11 +116,5 @@ var attribute = t.jSXAttribute(id, value);

}
};
for (var prop in props) {
var _ret = _loop(prop);
if (_ret === 'continue') continue;
}
});
}
exports.getJSXTagName = _getJSXTagName2.default;

@@ -6,2 +6,3 @@ 'use strict';

});
function getTagName(path) {

@@ -8,0 +9,0 @@ if (path.isJSXIdentifier()) {

{
"name": "babel-plugin-transform-react-jsx-props",
"version": "1.2.2",
"version": "2.0.0",
"description": "Add additional props to a jsx snippet",

@@ -15,6 +15,9 @@ "repository": {

"scripts": {
"test": "npm run build && ava test/",
"build": "babel src --out-dir lib",
"check": "npm run lint && npm run flow && npm test",
"flow": "flow",
"lint": "eslint src",
"prepublish": "npm run build",
"preversion": "npm test",
"preversion": "npm run check",
"test": "npm run build && ava test/",
"watch": "babel src --out-dir lib --watch"

@@ -30,5 +33,6 @@ },

"babel-plugin-syntax-jsx": "^6.3.13",
"babel-runtime": "^6.0.0",
"babel-types": "^6.0.0",
"babylon": "^6.0.0",
"babel-types": "^6.0.0",
"babel-runtime": "^6.0.0"
"unquote": "^1.1.0"
},

@@ -39,7 +43,14 @@ "devDependencies": {

"babel-core": "^6.6.0",
"babel-eslint": "^6.0.4",
"babel-helper-fixtures": "^6.6.0",
"babel-plugin-syntax-flow": "^6.8.0",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-1": "^6.5.0",
"babel-traverse": "^6.7.6"
"babel-traverse": "^6.7.6",
"eslint": "^2.11.1",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.8.1",
"flow-bin": "^0.26.0"
},

@@ -46,0 +57,0 @@ "ava": {

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