UNPKG

5.33 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/replaceJsxExpressionContainer.js"],"names":["t","path","sourceAttribute","destinationName","importedHelperIndentifier","styleModuleImportMapIdentifier","options","expressionContainerValue","value","destinationAttribute","node","openingElement","attributes","find","attribute","name","splice","indexOf","args","expression","handleMissingStyleName","optionsDefaults","push","styleNameExpression","callExpression","clone","stringLiteral","Error"],"mappings":";;;;;;;AAEA;;AAaA;;AACA;;AACA;;;;;;eAMe,CACbA,CADa,EAGbC,IAHa,EAIbC,eAJa,EAKbC,eALa,EAMbC,yBANa,EAObC,8BAPa,EAQbC,OARa,KASJ;AACT,QAAMC,wBAAwB,GAAGL,eAAe,CAACM,KAAjD;AACA,QAAMC,oBAAoB,GAAGR,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAC1BC,IAD0B,CACpBC,SAAD,IAAe;AACnB,WAAO,OAAOA,SAAS,CAACC,IAAjB,KAA0B,WAA1B,IAAyCD,SAAS,CAACC,IAAV,CAAeA,IAAf,KAAwBZ,eAAxE;AACD,GAH0B,CAA7B;;AAKA,MAAIM,oBAAJ,EAA0B;AACxBR,IAAAA,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCI,MAApC,CAA2Cf,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCK,OAApC,CAA4CR,oBAA5C,CAA3C,EAA8G,CAA9G;AACD;;AAEDR,EAAAA,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCI,MAApC,CAA2Cf,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCK,OAApC,CAA4Cf,eAA5C,CAA3C,EAAyG,CAAzG;AAEA,QAAMgB,IAAI,GAAG,CACXX,wBAAwB,CAACY,UADd,EAEXd,8BAFW,CAAb,CAbS,CAkBT;AACA;;AACA,MAAIC,OAAO,CAACc,sBAAR,KAAmCC,yBAAgBD,sBAAvD,EAA+E;AAC7EF,IAAAA,IAAI,CAACI,IAAL,CAAU,qCAAuBtB,CAAvB,EAA0BM,OAA1B,CAAV;AACD;;AAED,QAAMiB,mBAAmB,GAAGvB,CAAC,CAACwB,cAAF,CAC1BxB,CAAC,CAACyB,KAAF,CAAQrB,yBAAR,CAD0B,EAE1Bc,IAF0B,CAA5B;;AAKA,MAAIT,oBAAJ,EAA0B;AACxB,QAAI,4BAAgBA,oBAAoB,CAACD,KAArC,CAAJ,EAAiD;AAC/CP,MAAAA,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCU,IAApC,CAAyC,yBACvC,0BAAcnB,eAAd,CADuC,EAEvC,mCACE,6BACE,GADF,EAEEH,CAAC,CAAC0B,aAAF,CAAgBjB,oBAAoB,CAACD,KAArB,CAA2BA,KAA3B,GAAmC,GAAnD,CAFF,EAGEe,mBAHF,CADF,CAFuC,CAAzC;AAUD,KAXD,MAWO,IAAI,qCAAyBd,oBAAoB,CAACD,KAA9C,CAAJ,EAA0D;AAC/DP,MAAAA,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCU,IAApC,CAAyC,yBACvC,0BAAcnB,eAAd,CADuC,EAEvC,mCACE,oCACEM,oBAAoB,CAACD,KAArB,CAA2BW,UAD7B,EAEEI,mBAFF,CADF,CAFuC,CAAzC;AASD,KAVM,MAUA;AACL,YAAM,IAAII,KAAJ,CAAU,iCAAiClB,oBAAoB,CAACD,KAAhE,CAAN;AACD;AACF,GAzBD,MAyBO;AACLP,IAAAA,IAAI,CAACS,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCU,IAApC,CAAyC,yBACvC,0BAAcnB,eAAd,CADuC,EAEvC,mCACEoB,mBADF,CAFuC,CAAzC;AAMD;AACF,C","sourcesContent":["// @flow\n\nimport BabelTypes, {\n binaryExpression,\n Identifier,\n isJSXExpressionContainer,\n isStringLiteral,\n jSXAttribute,\n JSXAttribute,\n jSXExpressionContainer,\n jSXIdentifier\n} from '@babel/types';\nimport type {\n HandleMissingStyleNameOptionType\n} from './types';\nimport conditionalClassMerge from './conditionalClassMerge';\nimport createObjectExpression from './createObjectExpression';\nimport optionsDefaults from './schemas/optionsDefaults';\n\ntype OptionsType = {|\n handleMissingStyleName: HandleMissingStyleNameOptionType\n|};\n\nexport default (\n t: BabelTypes,\n // eslint-disable-next-line flowtype/no-weak-types\n path: Object,\n sourceAttribute: JSXAttribute,\n destinationName: string,\n importedHelperIndentifier: Identifier,\n styleModuleImportMapIdentifier: Identifier,\n options: OptionsType\n): void => {\n const expressionContainerValue = sourceAttribute.value;\n const destinationAttribute = path.node.openingElement.attributes\n .find((attribute) => {\n return typeof attribute.name !== 'undefined' && attribute.name.name === destinationName;\n });\n\n if (destinationAttribute) {\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(destinationAttribute), 1);\n }\n\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);\n\n const args = [\n expressionContainerValue.expression,\n styleModuleImportMapIdentifier\n ];\n\n // Only provide options argument if the options are something other than default\n // This helps save a few bits in the generated user code\n if (options.handleMissingStyleName !== optionsDefaults.handleMissingStyleName) {\n args.push(createObjectExpression(t, options));\n }\n\n const styleNameExpression = t.callExpression(\n t.clone(importedHelperIndentifier),\n args\n );\n\n if (destinationAttribute) {\n if (isStringLiteral(destinationAttribute.value)) {\n path.node.openingElement.attributes.push(jSXAttribute(\n jSXIdentifier(destinationName),\n jSXExpressionContainer(\n binaryExpression(\n '+',\n t.stringLiteral(destinationAttribute.value.value + ' '),\n styleNameExpression\n )\n )\n ));\n } else if (isJSXExpressionContainer(destinationAttribute.value)) {\n path.node.openingElement.attributes.push(jSXAttribute(\n jSXIdentifier(destinationName),\n jSXExpressionContainer(\n conditionalClassMerge(\n destinationAttribute.value.expression,\n styleNameExpression\n )\n )\n ));\n } else {\n throw new Error('Unexpected attribute value: ' + destinationAttribute.value);\n }\n } else {\n path.node.openingElement.attributes.push(jSXAttribute(\n jSXIdentifier(destinationName),\n jSXExpressionContainer(\n styleNameExpression\n )\n ));\n }\n};\n"],"file":"replaceJsxExpressionContainer.js"}
\No newline at end of file