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