@babel/plugin-transform-react-jsx
Advanced tools
Comparing version 7.14.5 to 7.14.9
@@ -80,7 +80,10 @@ "use strict"; | ||
const self = _core.types.jsxAttribute(_core.types.jsxIdentifier("__self"), _core.types.jsxExpressionContainer(_core.types.thisExpression())); | ||
const attributes = []; | ||
const source = _core.types.jsxAttribute(_core.types.jsxIdentifier("__source"), _core.types.jsxExpressionContainer(makeSource(path, state))); | ||
if (isThisAllowed(path)) { | ||
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__self"), _core.types.jsxExpressionContainer(_core.types.thisExpression()))); | ||
} | ||
path.pushContainer("attributes", [self, source]); | ||
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__source"), _core.types.jsxExpressionContainer(makeSource(path, state)))); | ||
path.pushContainer("attributes", attributes); | ||
} | ||
@@ -220,2 +223,36 @@ | ||
function getThisFunctionParent(path) { | ||
let scope = path.scope; | ||
do { | ||
if (scope.path.isFunctionParent() && !scope.path.isArrowFunctionExpression()) { | ||
return scope.path; | ||
} | ||
} while (scope = scope.parent); | ||
return null; | ||
} | ||
function isDerivedClass(classPath) { | ||
return classPath.node.superClass !== null; | ||
} | ||
function isThisAllowed(path) { | ||
const parentMethodOrFunction = getThisFunctionParent(path); | ||
if (parentMethodOrFunction === null) { | ||
return true; | ||
} | ||
if (!parentMethodOrFunction.isMethod()) { | ||
return true; | ||
} | ||
if (parentMethodOrFunction.node.kind !== "constructor") { | ||
return true; | ||
} | ||
return !isDerivedClass(parentMethodOrFunction.parentPath.parentPath); | ||
} | ||
function call(pass, name, args) { | ||
@@ -376,3 +413,3 @@ const node = _core.types.callExpression(get(pass, `id/${name}`)(), args); | ||
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1), (_extracted$__source = extracted.__source) != null ? _extracted$__source : path.scope.buildUndefinedNode(), (_extracted$__self = extracted.__self) != null ? _extracted$__self : _core.types.thisExpression()); | ||
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1), (_extracted$__source = extracted.__source) != null ? _extracted$__source : path.scope.buildUndefinedNode(), (_extracted$__self = extracted.__self) != null ? _extracted$__self : path.scope.buildUndefinedNode()); | ||
} else if (extracted.key !== undefined) { | ||
@@ -379,0 +416,0 @@ args.push(extracted.key); |
{ | ||
"name": "@babel/plugin-transform-react-jsx", | ||
"version": "7.14.5", | ||
"version": "7.14.9", | ||
"description": "Turn JSX into React function calls", | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"@babel/plugin-syntax-jsx": "^7.14.5", | ||
"@babel/types": "^7.14.5" | ||
"@babel/types": "^7.14.9" | ||
}, | ||
@@ -31,5 +31,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.14.5", | ||
"@babel/core": "7.14.8", | ||
"@babel/helper-plugin-test-runner": "7.14.5", | ||
"@babel/traverse": "7.14.5" | ||
"@babel/traverse": "7.14.9" | ||
}, | ||
@@ -36,0 +36,0 @@ "engines": { |
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
24650
514
Updated@babel/types@^7.14.9