This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

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,31 @@
# @svgr/babel-plugin-replace-jsx-attribute-value
## Install
```
npm install --save-dev @svgr/babel-plugin-replace-jsx-attribute-value
```
## Usage
**.babelrc**
```json
{
"plugins": [
[
"@svgr/babel-plugin-replace-jsx-attribute-value",
{
"values": [
{ "value": "#000", "newValue": "#fff" },
{ "value": "blue", "newValue": "props.color", "literal": true }
]
}
]
]
}
```
## License
MIT

View File

@@ -0,0 +1,17 @@
import { ConfigAPI, NodePath, types } from '@babel/core';
interface Value {
value: string;
newValue: string | boolean | number;
literal?: boolean;
}
interface Options {
values: Value[];
}
declare const addJSXAttribute: (api: ConfigAPI, opts: Options) => {
visitor: {
JSXAttribute(path: NodePath<types.JSXAttribute>): void;
};
};
export { Options, Value, addJSXAttribute as default };

View File

@@ -0,0 +1,43 @@
'use strict';
var core = require('@babel/core');
const addJSXAttribute = (api, opts) => {
const getAttributeValue = (value, literal) => {
if (typeof value === "string" && literal) {
return core.types.jsxExpressionContainer(
core.template.ast(value).expression
);
}
if (typeof value === "string") {
return core.types.stringLiteral(value);
}
if (typeof value === "boolean") {
return core.types.jsxExpressionContainer(core.types.booleanLiteral(value));
}
if (typeof value === "number") {
return core.types.jsxExpressionContainer(core.types.numericLiteral(value));
}
return null;
};
return {
visitor: {
JSXAttribute(path) {
const valuePath = path.get("value");
if (!valuePath.isStringLiteral())
return;
opts.values.forEach(({ value, newValue, literal }) => {
if (!valuePath.isStringLiteral({ value }))
return;
const attributeValue = getAttributeValue(newValue, literal);
if (attributeValue) {
valuePath.replaceWith(attributeValue);
}
});
}
}
};
};
module.exports = addJSXAttribute;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { ConfigAPI, types as t, NodePath, template } from '@babel/core'\n\nexport interface Value {\n value: string\n newValue: string | boolean | number\n literal?: boolean\n}\n\nexport interface Options {\n values: Value[]\n}\n\nconst addJSXAttribute = (api: ConfigAPI, opts: Options) => {\n const getAttributeValue = (\n value: string | boolean | number,\n literal?: boolean,\n ) => {\n if (typeof value === 'string' && literal) {\n return t.jsxExpressionContainer(\n (template.ast(value) as t.ExpressionStatement).expression,\n )\n }\n\n if (typeof value === 'string') {\n return t.stringLiteral(value)\n }\n\n if (typeof value === 'boolean') {\n return t.jsxExpressionContainer(t.booleanLiteral(value))\n }\n\n if (typeof value === 'number') {\n return t.jsxExpressionContainer(t.numericLiteral(value))\n }\n\n return null\n }\n\n return {\n visitor: {\n JSXAttribute(path: NodePath<t.JSXAttribute>) {\n const valuePath = path.get('value')\n if (!valuePath.isStringLiteral()) return\n\n opts.values.forEach(({ value, newValue, literal }) => {\n if (!valuePath.isStringLiteral({ value })) return\n const attributeValue = getAttributeValue(newValue, literal)\n if (attributeValue) {\n valuePath.replaceW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AAM,MAAA,cAAA,GAAiB,iBAAkB,CAAA,QAAA,EAAU,OAAO,CAAA,CAAA;AAC1D,UAAA,IAAI,cAAgB,EAAA;AAClB,YAAA,SAAA,CAAU,YAAY,cAAc,CAAA,CAAA;AAAA,WACtC;AAAA,SACD,CAAA,CAAA;AAAA,OACH;AAAA,KACF;AAAA,GACF,CAAA;AACF;;;;"}

View File

@@ -0,0 +1,40 @@
{
"name": "@svgr/babel-plugin-replace-jsx-attribute-value",
"description": "Replace JSX attribute value",
"version": "6.5.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"repository": "https://github.com/gregberge/svgr/tree/main/packages/babel-plugin-replace-jsx-attribute-value",
"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",
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"scripts": {
"reset": "rm -rf dist",
"build": "rollup -c ../../build/rollup.config.js",
"prepublishOnly": "npm run reset && npm run build"
},
"gitHead": "d5efedd372999692f84d30072e502b5a6b8fe734"
}