@svgr/babel-plugin-svg-dynamic-title
Advanced tools
Comparing version 4.3.1 to 4.3.3
@@ -6,2 +6,13 @@ # Change Log | ||
## [4.3.3](https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title/compare/v4.3.2...v4.3.3) (2019-09-24) | ||
### Bug Fixes | ||
* **babel-plugin-svg-dynamic-title:** dont render empty title ([#341](https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title/issues/341)) ([88b24c5](https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title/commit/88b24c5)), closes [#333](https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title/issues/333) | ||
## [4.3.1](https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title/compare/v4.3.0...v4.3.1) (2019-07-01) | ||
@@ -8,0 +19,0 @@ |
@@ -18,17 +18,19 @@ "use strict"; | ||
function createTitle(children = []) { | ||
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('title'), []), t.jsxClosingElement(t.jsxIdentifier('title')), children); | ||
function createTitle(children = [], attributes = []) { | ||
return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('title'), attributes), t.jsxClosingElement(t.jsxIdentifier('title')), children); | ||
} | ||
function getTitleElement(existingTitleChildren = []) { | ||
function getTitleElement(existingTitle) { | ||
const titleExpression = t.identifier('title'); | ||
let titleElement = createTitle([t.jsxExpressionContainer(titleExpression)]); | ||
let titleElement = t.conditionalExpression(titleExpression, createTitle([t.jsxExpressionContainer(titleExpression)], existingTitle ? existingTitle.openingElement.attributes : []), t.nullLiteral()); | ||
if (existingTitleChildren && existingTitleChildren.length) { | ||
if (existingTitle && existingTitle.children && existingTitle.children.length) { | ||
// if title already exists | ||
// render as follows | ||
const fallbackTitleElement = createTitle(existingTitleChildren); // {title === undefined ? fallbackTitleElement : titleElement} | ||
const fallbackTitleElement = existingTitle; // {title === undefined ? fallbackTitleElement : titleElement} | ||
const conditionalExpressionForTitle = t.conditionalExpression(t.binaryExpression('===', titleExpression, t.identifier('undefined')), fallbackTitleElement, titleElement); | ||
titleElement = t.jsxExpressionContainer(conditionalExpressionForTitle); | ||
} else { | ||
titleElement = t.jsxExpressionContainer(titleElement); | ||
} | ||
@@ -45,3 +47,3 @@ | ||
if (childPath.node.openingElement.name.name !== 'title') return false; | ||
titleElement = getTitleElement(childPath.node.children); | ||
titleElement = getTitleElement(childPath.node); | ||
childPath.replaceWith(titleElement); | ||
@@ -48,0 +50,0 @@ return true; |
{ | ||
"name": "@svgr/babel-plugin-svg-dynamic-title", | ||
"description": "Transform SVG by adding a dynamic title element", | ||
"version": "4.3.1", | ||
"version": "4.3.3", | ||
"main": "lib/index.js", | ||
@@ -23,3 +23,3 @@ "repository": "https://github.com/smooth-code/svgr/tree/master/packages/babel-plugin-svg-dynamic-title", | ||
}, | ||
"gitHead": "06e1e996a92289183fca0aabe4ba286e3a227f1b" | ||
"gitHead": "14a26644e7bda24c2ff97524f3d8841801a6442f" | ||
} |
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
6534
51