babel-plugin-transform-react-jsx-source
Advanced tools
Comparing version 6.3.13 to 6.5.0-1
@@ -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" | ||
} | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
2909
46
2