1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _babelTypes = require('babel-types');
|
8 |
|
9 | var _babelTypes2 = _interopRequireDefault(_babelTypes);
|
10 |
|
11 | var _conditionalClassMerge = require('./conditionalClassMerge');
|
12 |
|
13 | var _conditionalClassMerge2 = _interopRequireDefault(_conditionalClassMerge);
|
14 |
|
15 | var _createObjectExpression = require('./createObjectExpression');
|
16 |
|
17 | var _createObjectExpression2 = _interopRequireDefault(_createObjectExpression);
|
18 |
|
19 | var _optionsDefaults = require('./schemas/optionsDefaults');
|
20 |
|
21 | var _optionsDefaults2 = _interopRequireDefault(_optionsDefaults);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 | exports.default = (t, path, sourceAttribute, destinationName, importedHelperIndentifier, styleModuleImportMapIdentifier, options) => {
|
26 | const expressionContainerValue = sourceAttribute.value;
|
27 | const destinationAttribute = path.node.openingElement.attributes.find(attribute => {
|
28 | return typeof attribute.name !== 'undefined' && attribute.name.name === destinationName;
|
29 | });
|
30 |
|
31 | if (destinationAttribute) {
|
32 | path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(destinationAttribute), 1);
|
33 | }
|
34 |
|
35 | path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);
|
36 |
|
37 | const args = [expressionContainerValue.expression, styleModuleImportMapIdentifier];
|
38 |
|
39 |
|
40 |
|
41 | if (options.handleMissingStyleName !== _optionsDefaults2.default.handleMissingStyleName) {
|
42 | args.push((0, _createObjectExpression2.default)(t, options));
|
43 | }
|
44 |
|
45 | const styleNameExpression = t.callExpression(t.clone(importedHelperIndentifier), args);
|
46 |
|
47 | if (destinationAttribute) {
|
48 | if ((0, _babelTypes.isStringLiteral)(destinationAttribute.value)) {
|
49 | path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)(destinationName), (0, _babelTypes.jSXExpressionContainer)((0, _babelTypes.binaryExpression)('+', t.stringLiteral(destinationAttribute.value.value + ' '), styleNameExpression))));
|
50 | } else if ((0, _babelTypes.isJSXExpressionContainer)(destinationAttribute.value)) {
|
51 | path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)(destinationName), (0, _babelTypes.jSXExpressionContainer)((0, _conditionalClassMerge2.default)(destinationAttribute.value.expression, styleNameExpression))));
|
52 | } else {
|
53 | throw new Error('Unexpected attribute value: ' + destinationAttribute.value);
|
54 | }
|
55 | } else {
|
56 | path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)(destinationName), (0, _babelTypes.jSXExpressionContainer)(styleNameExpression)));
|
57 | }
|
58 | };
|
59 |
|
\ | No newline at end of file |