@babel/plugin-transform-react-display-name
Advanced tools
Comparing version 7.0.0-beta.42 to 7.0.0-beta.43
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
function _helperPluginUtils() { | ||
const data = require("@babel/helper-plugin-utils"); | ||
var _path = _interopRequireDefault(require("path")); | ||
_helperPluginUtils = function () { | ||
return data; | ||
}; | ||
var _core = require("@babel/core"); | ||
return data; | ||
} | ||
function _path() { | ||
const data = _interopRequireDefault(require("path")); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _core() { | ||
const data = require("@babel/core"); | ||
_core = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _default = (0, _helperPluginUtils.declare)(function (api) { | ||
var _default = (0, _helperPluginUtils().declare)(api => { | ||
api.assertVersion(7); | ||
function addDisplayName(id, call) { | ||
var props = call.arguments[0].properties; | ||
var safe = true; | ||
const props = call.arguments[0].properties; | ||
let safe = true; | ||
for (var i = 0; i < props.length; i++) { | ||
var prop = props[i]; | ||
for (let i = 0; i < props.length; i++) { | ||
const prop = props[i]; | ||
var key = _core.types.toComputedKey(prop); | ||
const key = _core().types.toComputedKey(prop); | ||
if (_core.types.isLiteral(key, { | ||
if (_core().types.isLiteral(key, { | ||
value: "displayName" | ||
@@ -35,14 +61,12 @@ })) { | ||
if (safe) { | ||
props.unshift(_core.types.objectProperty(_core.types.identifier("displayName"), _core.types.stringLiteral(id))); | ||
props.unshift(_core().types.objectProperty(_core().types.identifier("displayName"), _core().types.stringLiteral(id))); | ||
} | ||
} | ||
var isCreateClassCallExpression = _core.types.buildMatchMemberExpression("React.createClass"); | ||
const isCreateClassCallExpression = _core().types.buildMatchMemberExpression("React.createClass"); | ||
var isCreateClassAddon = function isCreateClassAddon(callee) { | ||
return callee.name === "createReactClass"; | ||
}; | ||
const isCreateClassAddon = callee => callee.name === "createReactClass"; | ||
function isCreateClass(node) { | ||
if (!node || !_core.types.isCallExpression(node)) return false; | ||
if (!node || !_core().types.isCallExpression(node)) return false; | ||
@@ -53,6 +77,6 @@ if (!isCreateClassCallExpression(node.callee) && !isCreateClassAddon(node.callee)) { | ||
var args = node.arguments; | ||
const args = node.arguments; | ||
if (args.length !== 1) return false; | ||
var first = args[0]; | ||
if (!_core.types.isObjectExpression(first)) return false; | ||
const first = args[0]; | ||
if (!_core().types.isObjectExpression(first)) return false; | ||
return true; | ||
@@ -63,12 +87,12 @@ } | ||
visitor: { | ||
ExportDefaultDeclaration: function ExportDefaultDeclaration(_ref, state) { | ||
var node = _ref.node; | ||
ExportDefaultDeclaration({ | ||
node | ||
}, state) { | ||
if (isCreateClass(node.declaration)) { | ||
var filename = state.filename || "unknown"; | ||
const filename = state.filename || "unknown"; | ||
var displayName = _path.default.basename(filename, _path.default.extname(filename)); | ||
let displayName = _path().default.basename(filename, _path().default.extname(filename)); | ||
if (displayName === "index") { | ||
displayName = _path.default.basename(_path.default.dirname(filename)); | ||
displayName = _path().default.basename(_path().default.dirname(filename)); | ||
} | ||
@@ -79,6 +103,9 @@ | ||
}, | ||
CallExpression: function CallExpression(path) { | ||
var node = path.node; | ||
CallExpression(path) { | ||
const { | ||
node | ||
} = path; | ||
if (!isCreateClass(node)) return; | ||
var id; | ||
let id; | ||
path.find(function (path) { | ||
@@ -99,10 +126,11 @@ if (path.isAssignmentExpression()) { | ||
if (_core.types.isMemberExpression(id)) { | ||
if (_core().types.isMemberExpression(id)) { | ||
id = id.property; | ||
} | ||
if (_core.types.isIdentifier(id)) { | ||
if (_core().types.isIdentifier(id)) { | ||
addDisplayName(id.name, node); | ||
} | ||
} | ||
} | ||
@@ -109,0 +137,0 @@ }; |
{ | ||
"name": "@babel/plugin-transform-react-display-name", | ||
"version": "7.0.0-beta.42", | ||
"version": "7.0.0-beta.43", | ||
"description": "Add displayName to React.createClass calls", | ||
@@ -12,11 +12,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-display-name", | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.0.0-beta.42" | ||
"@babel/helper-plugin-utils": "7.0.0-beta.43" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.42", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.42" | ||
"@babel/core": "7.0.0-beta.43", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.43" | ||
} | ||
} |
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
4616
102
+ Added@babel/code-frame@7.0.0-beta.43(transitive)
+ Added@babel/core@7.0.0-beta.43(transitive)
+ Added@babel/generator@7.0.0-beta.43(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.43(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.43(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.43(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.43(transitive)
+ Added@babel/helpers@7.0.0-beta.43(transitive)
+ Added@babel/highlight@7.0.0-beta.43(transitive)
+ Added@babel/template@7.0.0-beta.43(transitive)
+ Added@babel/traverse@7.0.0-beta.43(transitive)
+ Added@babel/types@7.0.0-beta.43(transitive)
+ Addedbabylon@7.0.0-beta.43(transitive)
- Removed@babel/code-frame@7.0.0-beta.42(transitive)
- Removed@babel/core@7.0.0-beta.42(transitive)
- Removed@babel/generator@7.0.0-beta.42(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.42(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.42(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.42(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.42(transitive)
- Removed@babel/helpers@7.0.0-beta.42(transitive)
- Removed@babel/highlight@7.0.0-beta.42(transitive)
- Removed@babel/template@7.0.0-beta.42(transitive)
- Removed@babel/traverse@7.0.0-beta.42(transitive)
- Removed@babel/types@7.0.0-beta.42(transitive)
- Removedbabylon@7.0.0-beta.42(transitive)