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