babel-plugin-inline-react-svg
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -28,2 +28,10 @@ "use strict"; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var ignoreRegex; | ||
@@ -44,3 +52,3 @@ | ||
SVG_DEFAULT_PROPS_CODE = _ref2.SVG_DEFAULT_PROPS_CODE; | ||
var namedTemplate = "\n var SVG_NAME = function SVG_NAME(props) { return SVG_CODE; };\n ".concat(SVG_DEFAULT_PROPS_CODE ? 'SVG_NAME.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '', " \n ").concat(IS_EXPORT ? 'export { SVG_NAME };' : '', "\n "); | ||
var namedTemplate = "\n var SVG_NAME = function SVG_NAME(props) { return SVG_CODE; };\n ".concat(SVG_DEFAULT_PROPS_CODE ? 'SVG_NAME.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '', "\n ").concat(IS_EXPORT ? 'export { SVG_NAME };' : '', "\n "); | ||
var anonymousTemplate = "\n var Component = function (props) { return SVG_CODE; };\n ".concat(SVG_DEFAULT_PROPS_CODE ? 'Component.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '', "\n Component.displayName = 'EXPORT_FILENAME';\n export default Component;\n "); | ||
@@ -147,8 +155,6 @@ | ||
Program: { | ||
enter: function enter(_ref3, _ref4) { | ||
var scope = _ref3.scope, | ||
node = _ref3.node; | ||
var file = _ref4.file, | ||
opts = _ref4.opts, | ||
filename = _ref4.filename; | ||
enter: function enter(path, _ref3) { | ||
var file = _ref3.file, | ||
opts = _ref3.opts, | ||
filename = _ref3.filename; | ||
@@ -163,6 +169,12 @@ if (typeof filename === 'string' && typeof opts.filename !== 'undefined') { | ||
if (!scope.hasBinding('React')) { | ||
if (!path.scope.hasBinding('React')) { | ||
var reactImportDeclaration = t.importDeclaration([t.importDefaultSpecifier(t.identifier('React'))], t.stringLiteral('react')); | ||
file.set('ensureReact', function () { | ||
node.body.unshift(reactImportDeclaration); | ||
var _path$unshiftContaine = path.unshiftContainer('body', reactImportDeclaration), | ||
_path$unshiftContaine2 = _slicedToArray(_path$unshiftContaine, 1), | ||
newPath = _path$unshiftContaine2[0]; | ||
newPath.get('specifiers').forEach(function (specifier) { | ||
path.scope.registerBinding('module', specifier); | ||
}); | ||
}); | ||
@@ -169,0 +181,0 @@ } else { |
{ | ||
"name": "babel-plugin-inline-react-svg", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A babel plugin that optimizes and inlines SVGs for your react components.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -61,2 +61,26 @@ import { transformFile, transform } from '@babel/core'; | ||
transformFile('test/fixtures/test-no-duplicate-react.jsx', { | ||
babelrc: false, | ||
presets: ['@babel/preset-react'], | ||
plugins: [ | ||
inlineReactSvgPlugin, | ||
({ | ||
visitor: { | ||
Program: { | ||
exit({ scope }) { | ||
if (!scope.hasBinding('React')) { | ||
throw new Error('React binding was expected.'); | ||
} | ||
}, | ||
}, | ||
}, | ||
}), | ||
], | ||
}, (err, result) => { | ||
if (err) throw err; | ||
console.log('test/fixtures/test-no-duplicate-react.jsx', result.code); | ||
assertReactImport(result); | ||
validateDefaultProps(result); | ||
}); | ||
if (fs.existsSync(path.resolve('./PACKAGE.JSON'))) { | ||
@@ -75,3 +99,3 @@ transformFile('test/fixtures/test-case-sensitive.jsx', { | ||
} else { | ||
throw new Error('Test failed: Expected case sensitive error wasn‘t thrown, got: ' + err.message); | ||
throw new Error(`Test failed: Expected case sensitive error wasn‘t thrown, got: ${err.message}`); | ||
} | ||
@@ -78,0 +102,0 @@ }); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
37164
30
778
1