1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _types = require("@babel/types");
|
9 |
|
10 | var _conditionalClassMerge = _interopRequireDefault(require("./conditionalClassMerge"));
|
11 |
|
12 | var _getClassName = _interopRequireDefault(require("./getClassName"));
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var _default = (path, styleModuleImportMap, sourceAttribute, destinationName, options) => {
|
20 | const resolvedStyleName = (0, _getClassName.default)(sourceAttribute.value.value, styleModuleImportMap, options);
|
21 | const destinationAttribute = path.node.openingElement.attributes.find(attribute => {
|
22 | return typeof attribute.name !== 'undefined' && attribute.name.name === destinationName;
|
23 | });
|
24 |
|
25 | if (destinationAttribute) {
|
26 | if ((0, _types.isStringLiteral)(destinationAttribute.value)) {
|
27 | destinationAttribute.value.value += ' ' + resolvedStyleName;
|
28 | } else if ((0, _types.isJSXExpressionContainer)(destinationAttribute.value)) {
|
29 | destinationAttribute.value.expression = (0, _conditionalClassMerge.default)(destinationAttribute.value.expression, (0, _types.stringLiteral)(resolvedStyleName));
|
30 | } else {
|
31 | throw new Error('Unexpected attribute value:' + destinationAttribute.value);
|
32 | }
|
33 |
|
34 | path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);
|
35 | } else {
|
36 | sourceAttribute.name.name = destinationName;
|
37 | sourceAttribute.value.value = resolvedStyleName;
|
38 | }
|
39 | };
|
40 |
|
41 | exports.default = _default;
|
42 |
|
\ | No newline at end of file |