@svgr/babel-plugin-svg-dynamic-title
Advanced tools
Comparing version 6.5.0 to 6.5.1
@@ -8,11 +8,22 @@ 'use strict'; | ||
const eleName = core.types.jsxIdentifier(tag); | ||
return core.types.jsxElement(core.types.jsxOpeningElement(eleName, attributes), core.types.jsxClosingElement(eleName), children); | ||
return core.types.jsxElement( | ||
core.types.jsxOpeningElement(eleName, attributes), | ||
core.types.jsxClosingElement(eleName), | ||
children | ||
); | ||
}; | ||
const createTagIdAttribute = (tag) => core.types.jsxAttribute(core.types.jsxIdentifier("id"), core.types.jsxExpressionContainer(core.types.identifier(`${tag}Id`))); | ||
const createTagIdAttribute = (tag) => core.types.jsxAttribute( | ||
core.types.jsxIdentifier("id"), | ||
core.types.jsxExpressionContainer(core.types.identifier(`${tag}Id`)) | ||
); | ||
const addTagIdAttribute = (tag, attributes) => { | ||
const existingId = attributes.find((attribute) => core.types.isJSXAttribute(attribute) && attribute.name.name === "id"); | ||
const existingId = attributes.find( | ||
(attribute) => core.types.isJSXAttribute(attribute) && attribute.name.name === "id" | ||
); | ||
if (!existingId) { | ||
return [...attributes, createTagIdAttribute(tag)]; | ||
} | ||
existingId.value = core.types.jsxExpressionContainer(core.types.isStringLiteral(existingId.value) ? core.types.logicalExpression("||", core.types.identifier(`${tag}Id`), existingId.value) : core.types.identifier(`${tag}Id`)); | ||
existingId.value = core.types.jsxExpressionContainer( | ||
core.types.isStringLiteral(existingId.value) ? core.types.logicalExpression("||", core.types.identifier(`${tag}Id`), existingId.value) : core.types.identifier(`${tag}Id`) | ||
); | ||
return attributes; | ||
@@ -28,3 +39,5 @@ }; | ||
const openingElementName = openingElement.get("name"); | ||
if (!elements.some((element) => openingElementName.isJSXIdentifier({ name: element }))) { | ||
if (!elements.some( | ||
(element) => openingElementName.isJSXIdentifier({ name: element }) | ||
)) { | ||
return; | ||
@@ -36,7 +49,28 @@ } | ||
if (existingTitle) { | ||
existingTitle.openingElement.attributes = addTagIdAttribute(tag, existingTitle.openingElement.attributes); | ||
existingTitle.openingElement.attributes = addTagIdAttribute( | ||
tag, | ||
existingTitle.openingElement.attributes | ||
); | ||
} | ||
const conditionalTitle = core.types.conditionalExpression(tagExpression, createTagElement(tag, [core.types.jsxExpressionContainer(tagExpression)], existingTitle ? existingTitle.openingElement.attributes : [createTagIdAttribute(tag)]), core.types.nullLiteral()); | ||
const conditionalTitle = core.types.conditionalExpression( | ||
tagExpression, | ||
createTagElement( | ||
tag, | ||
[core.types.jsxExpressionContainer(tagExpression)], | ||
existingTitle ? existingTitle.openingElement.attributes : [createTagIdAttribute(tag)] | ||
), | ||
core.types.nullLiteral() | ||
); | ||
if ((_a = existingTitle == null ? void 0 : existingTitle.children) == null ? void 0 : _a.length) { | ||
return core.types.jsxExpressionContainer(core.types.conditionalExpression(core.types.binaryExpression("===", tagExpression, core.types.identifier("undefined")), existingTitle, conditionalTitle)); | ||
return core.types.jsxExpressionContainer( | ||
core.types.conditionalExpression( | ||
core.types.binaryExpression( | ||
"===", | ||
tagExpression, | ||
core.types.identifier("undefined") | ||
), | ||
existingTitle, | ||
conditionalTitle | ||
) | ||
); | ||
} | ||
@@ -43,0 +77,0 @@ return core.types.jsxExpressionContainer(conditionalTitle); |
{ | ||
"name": "@svgr/babel-plugin-svg-dynamic-title", | ||
"description": "Transform SVG by adding a dynamic title element", | ||
"version": "6.5.0", | ||
"version": "6.5.1", | ||
"main": "./dist/index.js", | ||
@@ -39,3 +39,3 @@ "types": "./dist/index.d.ts", | ||
}, | ||
"gitHead": "b385279d27e51d34e4684dda326aa4216a485572" | ||
"gitHead": "d5efedd372999692f84d30072e502b5a6b8fe734" | ||
} |
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
13840
112