0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

View file

@ -0,0 +1,50 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.4.0](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/compare/v5.3.1...v5.4.0) (2020-04-27)
### Features
* add `ForeignObject` support for react native ([#430](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/issues/430)) ([1b56b85](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/commit/1b56b851478803d40105ce63c70e457bd3183da6))
## [5.0.1](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/compare/v5.0.0...v5.0.1) (2019-12-29)
### Bug Fixes
* fix engines in package.json ([a45d6fc](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/commit/a45d6fc8b43402bec60ed4e9273f90fdc65a23a7))
# [4.2.0](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/compare/v4.1.0...v4.2.0) (2019-04-11)
### Features
* add expo option ([#289](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/issues/289)) ([978db3e](https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg/commit/978db3e))
# [4.0.0](https://github.com/gregberge/svgr/compare/v3.1.0...v4.0.0) (2018-11-04)
### Features
* **v4:** new architecture ([ac8b8ca](https://github.com/gregberge/svgr/commit/ac8b8ca))
### BREAKING CHANGES
* **v4:** - `template` option must now returns a Babel AST
- `@svgr/core` does not include svgo & prettier by default

View file

@ -0,0 +1,7 @@
Copyright 2017 Smooth Code
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,21 @@
# @svgr/babel-plugin-transform-react-native-svg
## Install
```
npm install --save-dev @svgr/babel-plugin-transform-react-native-svg
```
## Usage
**.babelrc**
```json
{
"plugins": ["@svgr/babel-plugin-transform-react-native-svg"]
}
```
## License
MIT

View file

@ -0,0 +1,133 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
const elementToComponent = {
svg: 'Svg',
circle: 'Circle',
clipPath: 'ClipPath',
ellipse: 'Ellipse',
g: 'G',
linearGradient: 'LinearGradient',
radialGradient: 'RadialGradient',
line: 'Line',
path: 'Path',
pattern: 'Pattern',
polygon: 'Polygon',
polyline: 'Polyline',
rect: 'Rect',
symbol: 'Symbol',
text: 'Text',
textPath: 'TextPath',
tspan: 'TSpan',
use: 'Use',
defs: 'Defs',
stop: 'Stop',
mask: 'Mask',
image: 'Image',
foreignObject: 'ForeignObject'
};
const expoPrefix = (component, expo) => {
// Prefix with 'Svg.' in the case we're transforming for Expo
if (!expo) {
return component;
}
return (component !== 'Svg' ? 'Svg.' : '') + component;
};
const plugin = ({
types: t
}, {
expo
}) => {
function replaceElement(path, state) {
const {
name
} = path.node.openingElement.name; // Replace element by react-native-svg components
const component = elementToComponent[name];
if (component) {
const prefixedComponent = expoPrefix(component, expo);
const openingElementName = path.get('openingElement.name');
openingElementName.replaceWith(t.jsxIdentifier(prefixedComponent));
if (path.has('closingElement')) {
const closingElementName = path.get('closingElement.name');
closingElementName.replaceWith(t.jsxIdentifier(prefixedComponent));
}
state.replacedComponents.add(prefixedComponent);
return;
} // Remove element if not supported
state.unsupportedComponents.add(name);
path.remove();
}
const svgElementVisitor = {
JSXElement(path, state) {
if (!path.get('openingElement.name').isJSXIdentifier({
name: 'svg'
})) {
return;
}
replaceElement(path, state);
path.traverse(jsxElementVisitor, state);
}
};
const jsxElementVisitor = {
JSXElement(path, state) {
replaceElement(path, state);
}
};
const importDeclarationVisitor = {
ImportDeclaration(path, state) {
if (path.get('source').isStringLiteral({
value: 'react-native-svg'
})) {
state.replacedComponents.forEach(component => {
if (path.get('specifiers').some(specifier => specifier.get('local').isIdentifier({
name: component
}))) {
return;
}
path.pushContainer('specifiers', t.importSpecifier(t.identifier(component), t.identifier(component)));
});
} else if (path.get('source').isStringLiteral({
value: 'expo'
})) {
path.pushContainer('specifiers', t.importSpecifier(t.identifier('Svg'), t.identifier('Svg')));
} else {
return;
}
if (state.unsupportedComponents.size && !path.has('trailingComments')) {
const componentList = [...state.unsupportedComponents].join(', ');
path.addComment('trailing', ` SVGR has dropped some elements not supported by react-native-svg: ${componentList} `);
}
}
};
return {
visitor: {
Program(path, state) {
state.replacedComponents = new Set();
state.unsupportedComponents = new Set();
path.traverse(svgElementVisitor, state);
path.traverse(importDeclarationVisitor, state);
}
}
};
};
var _default = plugin;
exports.default = _default;

View file

@ -0,0 +1,29 @@
{
"name": "@svgr/babel-plugin-transform-react-native-svg",
"description": "Transform DOM elements into react-native-svg components",
"version": "5.4.0",
"main": "lib/index.js",
"repository": "https://github.com/gregberge/svgr/tree/master/packages/babel-plugin-transform-react-native-svg",
"author": "Greg Bergé <berge.greg@gmail.com>",
"publishConfig": {
"access": "public"
},
"keywords": [
"babel-plugin"
],
"engines": {
"node": ">=10"
},
"homepage": "https://react-svgr.com",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/gregberge"
},
"license": "MIT",
"scripts": {
"prebuild": "rm -rf lib/",
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src",
"prepublishOnly": "yarn run build"
},
"gitHead": "e9c9d2fbfbce7a6879c90cd8522101caf2406d42"
}