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

babel-plugin-transform-react-jsx-source

Package Overview
Dependencies
Maintainers
6
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 6.3.13 to 6.5.0-1

35

lib/index.js

@@ -13,3 +13,4 @@

*
* <sometag __source={{fileName: 'this/file.js', lineNumber: 10}}/>
* var __jsxFileName = 'this/file.js';
* <sometag __source={{fileName: __jsxFileName, lineNumber: 10}}/>
*/

@@ -19,11 +20,5 @@

var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"];
exports.__esModule = true;
var _path = require("path");
var _path2 = _interopRequireDefault(_path);
var TRACE_ID = "__source";
var FILE_NAME_VAR = "_jsxFileName";

@@ -33,6 +28,5 @@ exports["default"] = function (_ref) {

function makeTrace(fileName, lineNumber) {
var fileNameLiteral = fileName != null ? t.stringLiteral(fileName) : t.nullLiteral();
function makeTrace(fileNameIdentifier, lineNumber) {
var fileLineLiteral = lineNumber != null ? t.numericLiteral(lineNumber) : t.nullLiteral();
var fileNameProperty = t.objectProperty(t.identifier("fileName"), fileNameLiteral);
var fileNameProperty = t.objectProperty(t.identifier("fileName"), fileNameIdentifier);
var lineNumberProperty = t.objectProperty(t.identifier("lineNumber"), fileLineLiteral);

@@ -43,8 +37,17 @@ return t.objectExpression([fileNameProperty, lineNumberProperty]);

var visitor = {
JSXOpeningElement: function JSXOpeningElement(node, state) {
JSXOpeningElement: function JSXOpeningElement(path, state) {
if (!state.fileNameIdentifier) {
var fileName = state.file.log.filename !== "unknown" ? state.file.log.filename : null;
var fileNameIdentifier = path.scope.generateUidIdentifier(FILE_NAME_VAR);
path.hub.file.scope.push({ id: fileNameIdentifier, init: t.stringLiteral(fileName) });
state.fileNameIdentifier = fileNameIdentifier;
}
var id = t.jSXIdentifier(TRACE_ID);
var fileName = state.file.log.filename !== "unknown" ? _path2["default"].relative(__dirname, state.file.log.filename) : null;
var trace = makeTrace(fileName, node.container.openingElement.loc.start.line);
node.container.openingElement.attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace)));
var location = path.container.openingElement.loc; // undefined for generated elements
if (location) {
var trace = makeTrace(state.fileNameIdentifier, location.start.line);
path.container.openingElement.attributes.push(t.jSXAttribute(id, t.jSXExpressionContainer(trace)));
}
}

@@ -51,0 +54,0 @@ };

{
"name": "babel-plugin-transform-react-jsx-source",
"version": "6.3.13",
"version": "6.5.0-1",
"description": "Add a __source prop to all JSX Elements",

@@ -13,7 +13,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source",

"babel-runtime": "^5.0.0",
"babel-plugin-syntax-jsx": "^6.3.13"
"babel-plugin-syntax-jsx": "^6.5.0-1"
},
"devDependencies": {
"babel-helper-plugin-test-runner": "^6.3.13"
"babel-helper-plugin-test-runner": "^6.5.0-1"
}
}
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