source: frontend/node_modules/@svgr/babel-plugin-replace-jsx-attribute-value/lib/index.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.default = void 0;
5
6const addJSXAttribute = ({
7 types: t,
8 template
9}, opts) => {
10 function getAttributeValue(value, literal) {
11 if (typeof value === 'string' && literal) {
12 return t.jsxExpressionContainer(template.ast(value).expression);
13 }
14
15 if (typeof value === 'string') {
16 return t.stringLiteral(value);
17 }
18
19 if (typeof value === 'boolean') {
20 return t.jsxExpressionContainer(t.booleanLiteral(value));
21 }
22
23 if (typeof value === 'number') {
24 return t.jsxExpressionContainer(t.numericLiteral(value));
25 }
26
27 return null;
28 }
29
30 return {
31 visitor: {
32 JSXAttribute(path) {
33 const valuePath = path.get('value');
34 if (!valuePath.isStringLiteral()) return;
35 opts.values.forEach(({
36 value,
37 newValue,
38 literal
39 }) => {
40 if (!valuePath.isStringLiteral({
41 value
42 })) return;
43 valuePath.replaceWith(getAttributeValue(newValue, literal));
44 });
45 }
46
47 }
48 };
49};
50
51var _default = addJSXAttribute;
52exports.default = _default;
Note: See TracBrowser for help on using the repository browser.