@babel/plugin-transform-react-jsx
Advanced tools
Comparing version 7.21.4-esm.3 to 7.21.4-esm.4
@@ -1,12 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = createPlugin; | ||
var _pluginSyntaxJsx = require("@babel/plugin-syntax-jsx"); | ||
var _helperPluginUtils = require("@babel/helper-plugin-utils"); | ||
var _core = require("@babel/core"); | ||
var _helperModuleImports = require("@babel/helper-module-imports"); | ||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); | ||
import jsx from "@babel/plugin-syntax-jsx"; | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
import { template, types as t } from "@babel/core"; | ||
import { addNamed, addNamespace, isModule } from "@babel/helper-module-imports"; | ||
import annotateAsPure from "@babel/helper-annotate-as-pure"; | ||
const DEFAULT = { | ||
@@ -25,16 +19,16 @@ importSource: "react", | ||
function hasProto(node) { | ||
return node.properties.some(value => _core.types.isObjectProperty(value, { | ||
return node.properties.some(value => t.isObjectProperty(value, { | ||
computed: false, | ||
shorthand: false | ||
}) && (_core.types.isIdentifier(value.key, { | ||
}) && (t.isIdentifier(value.key, { | ||
name: "__proto__" | ||
}) || _core.types.isStringLiteral(value.key, { | ||
}) || t.isStringLiteral(value.key, { | ||
value: "__proto__" | ||
}))); | ||
} | ||
function createPlugin({ | ||
export default function createPlugin({ | ||
name, | ||
development | ||
}) { | ||
return (0, _helperPluginUtils.declare)((_, options) => { | ||
return declare((_, options) => { | ||
const { | ||
@@ -70,5 +64,5 @@ pure: PURE_ANNOTATION, | ||
if (isThisAllowed(path.scope)) { | ||
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__self"), _core.types.jsxExpressionContainer(_core.types.thisExpression()))); | ||
attributes.push(t.jsxAttribute(t.jsxIdentifier("__self"), t.jsxExpressionContainer(t.thisExpression()))); | ||
} | ||
attributes.push(_core.types.jsxAttribute(_core.types.jsxIdentifier("__source"), _core.types.jsxExpressionContainer(makeSource(path, state)))); | ||
attributes.push(t.jsxAttribute(t.jsxIdentifier("__source"), t.jsxExpressionContainer(makeSource(path, state)))); | ||
path.pushContainer("attributes", attributes); | ||
@@ -79,3 +73,3 @@ } | ||
name, | ||
inherits: _pluginSyntaxJsx.default, | ||
inherits: jsx, | ||
visitor: { | ||
@@ -133,4 +127,4 @@ JSXNamespacedName(path) { | ||
const fragment = toMemberExpression(pragmaFrag); | ||
set(state, "id/createElement", () => _core.types.cloneNode(createElement)); | ||
set(state, "id/fragment", () => _core.types.cloneNode(fragment)); | ||
set(state, "id/createElement", () => t.cloneNode(createElement)); | ||
set(state, "id/fragment", () => t.cloneNode(fragment)); | ||
set(state, "defaultPure", pragma === DEFAULT.pragma); | ||
@@ -163,3 +157,3 @@ } else if (runtime === "automatic") { | ||
} | ||
path.replaceWith(_core.types.inherits(callExpr, path.node)); | ||
path.replaceWith(t.inherits(callExpr, path.node)); | ||
} | ||
@@ -175,8 +169,8 @@ }, | ||
} | ||
path.replaceWith(_core.types.inherits(callExpr, path.node)); | ||
path.replaceWith(t.inherits(callExpr, path.node)); | ||
} | ||
}, | ||
JSXAttribute(path) { | ||
if (_core.types.isJSXElement(path.node.value)) { | ||
path.node.value = _core.types.jsxExpressionContainer(path.node.value); | ||
if (t.isJSXElement(path.node.value)) { | ||
path.node.value = t.jsxExpressionContainer(path.node.value); | ||
} | ||
@@ -210,4 +204,4 @@ } | ||
function call(pass, name, args) { | ||
const node = _core.types.callExpression(get(pass, `id/${name}`)(), args); | ||
if (PURE_ANNOTATION != null ? PURE_ANNOTATION : get(pass, "defaultPure")) (0, _helperAnnotateAsPure.default)(node); | ||
const node = t.callExpression(get(pass, `id/${name}`)(), args); | ||
if (PURE_ANNOTATION != null ? PURE_ANNOTATION : get(pass, "defaultPure")) annotateAsPure(node); | ||
return node; | ||
@@ -221,5 +215,5 @@ } | ||
const attr = attributes[i]; | ||
if (seenPropsSpread && _core.types.isJSXAttribute(attr) && attr.name.name === "key") { | ||
if (seenPropsSpread && t.isJSXAttribute(attr) && attr.name.name === "key") { | ||
return true; | ||
} else if (_core.types.isJSXSpreadAttribute(attr)) { | ||
} else if (t.isJSXSpreadAttribute(attr)) { | ||
seenPropsSpread = true; | ||
@@ -231,15 +225,15 @@ } | ||
function convertJSXIdentifier(node, parent) { | ||
if (_core.types.isJSXIdentifier(node)) { | ||
if (node.name === "this" && _core.types.isReferenced(node, parent)) { | ||
return _core.types.thisExpression(); | ||
} else if (_core.types.isValidIdentifier(node.name, false)) { | ||
if (t.isJSXIdentifier(node)) { | ||
if (node.name === "this" && t.isReferenced(node, parent)) { | ||
return t.thisExpression(); | ||
} else if (t.isValidIdentifier(node.name, false)) { | ||
node.type = "Identifier"; | ||
return node; | ||
} else { | ||
return _core.types.stringLiteral(node.name); | ||
return t.stringLiteral(node.name); | ||
} | ||
} else if (_core.types.isJSXMemberExpression(node)) { | ||
return _core.types.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node)); | ||
} else if (_core.types.isJSXNamespacedName(node)) { | ||
return _core.types.stringLiteral(`${node.namespace.name}:${node.name.name}`); | ||
} else if (t.isJSXMemberExpression(node)) { | ||
return t.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node)); | ||
} else if (t.isJSXNamespacedName(node)) { | ||
return t.stringLiteral(`${node.namespace.name}:${node.name.name}`); | ||
} | ||
@@ -249,3 +243,3 @@ return node; | ||
function convertAttributeValue(node) { | ||
if (_core.types.isJSXExpressionContainer(node)) { | ||
if (t.isJSXExpressionContainer(node)) { | ||
return node.expression; | ||
@@ -257,16 +251,16 @@ } else { | ||
function accumulateAttribute(array, attribute) { | ||
if (_core.types.isJSXSpreadAttribute(attribute.node)) { | ||
if (t.isJSXSpreadAttribute(attribute.node)) { | ||
const arg = attribute.node.argument; | ||
if (_core.types.isObjectExpression(arg) && !hasProto(arg)) { | ||
if (t.isObjectExpression(arg) && !hasProto(arg)) { | ||
array.push(...arg.properties); | ||
} else { | ||
array.push(_core.types.spreadElement(arg)); | ||
array.push(t.spreadElement(arg)); | ||
} | ||
return array; | ||
} | ||
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || _core.types.booleanLiteral(true) : attribute.node.value); | ||
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || t.booleanLiteral(true) : attribute.node.value); | ||
if (attribute.node.name.name === "key" && value === null) { | ||
throw attribute.buildCodeFrameError('Please provide an explicit key value. Using "key" as a shorthand for "key={true}" is not allowed.'); | ||
} | ||
if (_core.types.isStringLiteral(value) && !_core.types.isJSXExpressionContainer(attribute.node.value)) { | ||
if (t.isStringLiteral(value) && !t.isJSXExpressionContainer(attribute.node.value)) { | ||
var _value$extra; | ||
@@ -276,10 +270,10 @@ value.value = value.value.replace(/\n\s+/g, " "); | ||
} | ||
if (_core.types.isJSXNamespacedName(attribute.node.name)) { | ||
attribute.node.name = _core.types.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name); | ||
} else if (_core.types.isValidIdentifier(attribute.node.name.name, false)) { | ||
if (t.isJSXNamespacedName(attribute.node.name)) { | ||
attribute.node.name = t.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name); | ||
} else if (t.isValidIdentifier(attribute.node.name.name, false)) { | ||
attribute.node.name.type = "Identifier"; | ||
} else { | ||
attribute.node.name = _core.types.stringLiteral(attribute.node.name.name); | ||
attribute.node.name = t.stringLiteral(attribute.node.name.name); | ||
} | ||
array.push(_core.types.inherits(_core.types.objectProperty(attribute.node.name, value), attribute.node)); | ||
array.push(t.inherits(t.objectProperty(attribute.node.name, value), attribute.node)); | ||
return array; | ||
@@ -292,7 +286,7 @@ } | ||
} else if (children.length > 1) { | ||
childrenNode = _core.types.arrayExpression(children); | ||
childrenNode = t.arrayExpression(children); | ||
} else { | ||
return undefined; | ||
} | ||
return _core.types.objectProperty(_core.types.identifier("children"), childrenNode); | ||
return t.objectProperty(t.identifier("children"), childrenNode); | ||
} | ||
@@ -305,3 +299,3 @@ function buildJSXElementCall(path, file) { | ||
for (const attr of openingPath.get("attributes")) { | ||
if (attr.isJSXAttribute() && _core.types.isJSXIdentifier(attr.node.name)) { | ||
if (attr.isJSXAttribute() && t.isJSXIdentifier(attr.node.name)) { | ||
const { | ||
@@ -330,3 +324,3 @@ name | ||
} | ||
const children = _core.types.react.buildChildren(path.node); | ||
const children = t.react.buildChildren(path.node); | ||
let attribs; | ||
@@ -336,3 +330,3 @@ if (attribsArray.length || children.length) { | ||
} else { | ||
attribs = _core.types.objectExpression([]); | ||
attribs = t.objectExpression([]); | ||
} | ||
@@ -342,3 +336,3 @@ args.push(attribs); | ||
var _extracted$key; | ||
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1)); | ||
args.push((_extracted$key = extracted.key) != null ? _extracted$key : path.scope.buildUndefinedNode(), t.booleanLiteral(children.length > 1)); | ||
if (extracted.__source) { | ||
@@ -360,10 +354,10 @@ args.push(extracted.__source); | ||
} | ||
return _core.types.objectExpression(props); | ||
return t.objectExpression(props); | ||
} | ||
function buildJSXFragmentCall(path, file) { | ||
const args = [get(file, "id/fragment")()]; | ||
const children = _core.types.react.buildChildren(path.node); | ||
args.push(_core.types.objectExpression(children.length > 0 ? [buildChildrenProperty(children)] : [])); | ||
const children = t.react.buildChildren(path.node); | ||
args.push(t.objectExpression(children.length > 0 ? [buildChildrenProperty(children)] : [])); | ||
if (development) { | ||
args.push(path.scope.buildUndefinedNode(), _core.types.booleanLiteral(children.length > 1)); | ||
args.push(path.scope.buildUndefinedNode(), t.booleanLiteral(children.length > 1)); | ||
} | ||
@@ -374,7 +368,7 @@ return call(file, children.length > 1 ? "jsxs" : "jsx", args); | ||
if (filter && !filter(path.node, file)) return; | ||
return call(file, "createElement", [get(file, "id/fragment")(), _core.types.nullLiteral(), ..._core.types.react.buildChildren(path.node)]); | ||
return call(file, "createElement", [get(file, "id/fragment")(), t.nullLiteral(), ...t.react.buildChildren(path.node)]); | ||
} | ||
function buildCreateElementCall(path, file) { | ||
const openingPath = path.get("openingElement"); | ||
return call(file, "createElement", [getTag(openingPath), buildCreateElementOpeningElementAttributes(file, path, openingPath.get("attributes")), ..._core.types.react.buildChildren(path.node)]); | ||
return call(file, "createElement", [getTag(openingPath), buildCreateElementOpeningElementAttributes(file, path, openingPath.get("attributes")), ...t.react.buildChildren(path.node)]); | ||
} | ||
@@ -384,9 +378,9 @@ function getTag(openingPath) { | ||
let tagName; | ||
if (_core.types.isIdentifier(tagExpr)) { | ||
if (t.isIdentifier(tagExpr)) { | ||
tagName = tagExpr.name; | ||
} else if (_core.types.isStringLiteral(tagExpr)) { | ||
} else if (t.isStringLiteral(tagExpr)) { | ||
tagName = tagExpr.value; | ||
} | ||
if (_core.types.react.isCompatTag(tagName)) { | ||
return _core.types.stringLiteral(tagName); | ||
if (t.react.isCompatTag(tagName)) { | ||
return t.stringLiteral(tagName); | ||
} else { | ||
@@ -405,5 +399,5 @@ return tagExpr; | ||
props.forEach((prop, i) => { | ||
if (_core.types.isSpreadElement(prop)) { | ||
if (t.isSpreadElement(prop)) { | ||
if (i > start) { | ||
objs.push(_core.types.objectExpression(props.slice(start, i))); | ||
objs.push(t.objectExpression(props.slice(start, i))); | ||
} | ||
@@ -415,20 +409,20 @@ objs.push(prop.argument); | ||
if (props.length > start) { | ||
objs.push(_core.types.objectExpression(props.slice(start))); | ||
objs.push(t.objectExpression(props.slice(start))); | ||
} | ||
} else if (props.length) { | ||
objs.push(_core.types.objectExpression(props)); | ||
objs.push(t.objectExpression(props)); | ||
} | ||
if (!objs.length) { | ||
return _core.types.nullLiteral(); | ||
return t.nullLiteral(); | ||
} | ||
if (objs.length === 1) { | ||
if (!(_core.types.isSpreadElement(props[0]) && _core.types.isObjectExpression(props[0].argument))) { | ||
if (!(t.isSpreadElement(props[0]) && t.isObjectExpression(props[0].argument))) { | ||
return objs[0]; | ||
} | ||
} | ||
if (!_core.types.isObjectExpression(objs[0])) { | ||
objs.unshift(_core.types.objectExpression([])); | ||
if (!t.isObjectExpression(objs[0])) { | ||
objs.unshift(t.objectExpression([])); | ||
} | ||
const helper = useBuiltIns ? _core.types.memberExpression(_core.types.identifier("Object"), _core.types.identifier("assign")) : file.addHelper("extends"); | ||
return _core.types.callExpression(helper, objs); | ||
const helper = useBuiltIns ? t.memberExpression(t.identifier("Object"), t.identifier("assign")) : file.addHelper("extends"); | ||
return t.callExpression(helper, objs); | ||
} | ||
@@ -439,3 +433,3 @@ } | ||
for (const attr of attribs) { | ||
const name = _core.types.isJSXAttribute(attr) && _core.types.isJSXIdentifier(attr.name) && attr.name.name; | ||
const name = t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name) && attr.name.name; | ||
if (runtime === "automatic" && (name === "__source" || name === "__self")) { | ||
@@ -447,3 +441,3 @@ if (found[name]) throw sourceSelfError(path, name); | ||
} | ||
return props.length === 1 && _core.types.isSpreadElement(props[0]) && !_core.types.isObjectExpression(props[0].argument) ? props[0].argument : props.length > 0 ? _core.types.objectExpression(props) : _core.types.nullLiteral(); | ||
return props.length === 1 && t.isSpreadElement(props[0]) && !t.isObjectExpression(props[0].argument) ? props[0].argument : props.length > 0 ? t.objectExpression(props) : t.nullLiteral(); | ||
} | ||
@@ -467,6 +461,6 @@ }); | ||
const actualSource = getSource(source, importName); | ||
if ((0, _helperModuleImports.isModule)(path)) { | ||
if (isModule(path)) { | ||
let reference = get(pass, `imports/${importName}`); | ||
if (reference) return _core.types.cloneNode(reference); | ||
reference = (0, _helperModuleImports.addNamed)(path, importName, actualSource, { | ||
if (reference) return t.cloneNode(reference); | ||
reference = addNamed(path, importName, actualSource, { | ||
importedInterop: "uncompiled", | ||
@@ -480,5 +474,5 @@ importPosition: "after" | ||
if (reference) { | ||
reference = _core.types.cloneNode(reference); | ||
reference = t.cloneNode(reference); | ||
} else { | ||
reference = (0, _helperModuleImports.addNamespace)(path, actualSource, { | ||
reference = addNamespace(path, actualSource, { | ||
importedInterop: "uncompiled" | ||
@@ -488,3 +482,3 @@ }); | ||
} | ||
return _core.types.memberExpression(reference, _core.types.identifier(importName)); | ||
return t.memberExpression(reference, t.identifier(importName)); | ||
} | ||
@@ -495,3 +489,3 @@ }; | ||
function toMemberExpression(id) { | ||
return id.split(".").map(name => _core.types.identifier(name)).reduce((object, property) => _core.types.memberExpression(object, property)); | ||
return id.split(".").map(name => t.identifier(name)).reduce((object, property) => t.memberExpression(object, property)); | ||
} | ||
@@ -510,12 +504,12 @@ function makeSource(path, state) { | ||
id: fileNameIdentifier, | ||
init: _core.types.stringLiteral(filename) | ||
init: t.stringLiteral(filename) | ||
}); | ||
state.fileNameIdentifier = fileNameIdentifier; | ||
} | ||
return makeTrace(_core.types.cloneNode(state.fileNameIdentifier), location.start.line, location.start.column); | ||
return makeTrace(t.cloneNode(state.fileNameIdentifier), location.start.line, location.start.column); | ||
} | ||
function makeTrace(fileNameIdentifier, lineNumber, column0Based) { | ||
const fileLineLiteral = lineNumber != null ? _core.types.numericLiteral(lineNumber) : _core.types.nullLiteral(); | ||
const fileColumnLiteral = column0Based != null ? _core.types.numericLiteral(column0Based + 1) : _core.types.nullLiteral(); | ||
return _core.template.expression.ast`{ | ||
const fileLineLiteral = lineNumber != null ? t.numericLiteral(lineNumber) : t.nullLiteral(); | ||
const fileColumnLiteral = column0Based != null ? t.numericLiteral(column0Based + 1) : t.nullLiteral(); | ||
return template.expression.ast`{ | ||
fileName: ${fileNameIdentifier}, | ||
@@ -522,0 +516,0 @@ lineNumber: ${fileLineLiteral}, |
@@ -1,14 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _createPlugin = require("./create-plugin"); | ||
var _default = (0, _createPlugin.default)({ | ||
import createPlugin from "./create-plugin.js"; | ||
export default createPlugin({ | ||
name: "transform-react-jsx/development", | ||
development: true | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=development.js.map |
@@ -1,14 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _createPlugin = require("./create-plugin"); | ||
var _default = (0, _createPlugin.default)({ | ||
import createPlugin from "./create-plugin.js"; | ||
export default createPlugin({ | ||
name: "transform-react-jsx", | ||
development: false | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-transform-react-jsx", | ||
"version": "7.21.4-esm.3", | ||
"version": "7.21.4-esm.4", | ||
"description": "Turn JSX into React function calls", | ||
@@ -20,7 +20,7 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "7.21.4-esm.3", | ||
"@babel/helper-module-imports": "7.21.4-esm.3", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.3", | ||
"@babel/plugin-syntax-jsx": "7.21.4-esm.3", | ||
"@babel/types": "7.21.4-esm.3" | ||
"@babel/helper-annotate-as-pure": "7.21.4-esm.4", | ||
"@babel/helper-module-imports": "7.21.4-esm.4", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.4", | ||
"@babel/plugin-syntax-jsx": "7.21.4-esm.4", | ||
"@babel/types": "7.21.4-esm.4" | ||
}, | ||
@@ -31,5 +31,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.21.4-esm.3", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.3", | ||
"@babel/traverse": "7.21.4-esm.3" | ||
"@babel/core": "7.21.4-esm.4", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.4", | ||
"@babel/traverse": "7.21.4-esm.4" | ||
}, | ||
@@ -36,0 +36,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
10
77986
508
+ Added@babel/helper-annotate-as-pure@7.21.4-esm.4(transitive)
+ Added@babel/helper-module-imports@7.21.4-esm.4(transitive)
+ Added@babel/helper-plugin-utils@7.21.4-esm.4(transitive)
+ Added@babel/helper-string-parser@7.21.4-esm.4(transitive)
+ Added@babel/helper-validator-identifier@7.21.4-esm.4(transitive)
+ Added@babel/plugin-syntax-jsx@7.21.4-esm.4(transitive)
+ Added@babel/types@7.21.4-esm.4(transitive)
- Removed@babel/helper-annotate-as-pure@7.21.4-esm.3(transitive)
- Removed@babel/helper-module-imports@7.21.4-esm.3(transitive)
- Removed@babel/helper-plugin-utils@7.21.4-esm.3(transitive)
- Removed@babel/helper-string-parser@7.21.4-esm.3(transitive)
- Removed@babel/helper-validator-identifier@7.21.4-esm.3(transitive)
- Removed@babel/plugin-syntax-jsx@7.21.4-esm.3(transitive)
- Removed@babel/types@7.21.4-esm.3(transitive)
Updated@babel/types@7.21.4-esm.4