|
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 |
|
|---|
| 3 | exports.__esModule = true;
|
|---|
| 4 | exports.default = void 0;
|
|---|
| 5 |
|
|---|
| 6 | const 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 |
|
|---|
| 51 | var _default = addJSXAttribute;
|
|---|
| 52 | exports.default = _default; |
|---|
Note:
See
TracBrowser
for help on using the repository browser.