UNPKG

3.21 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/resolveStringLiteral.js"],"names":["path","styleModuleImportMap","sourceAttribute","destinationName","options","resolvedStyleName","value","destinationAttribute","node","openingElement","attributes","find","attribute","name","expression","Error","splice","indexOf"],"mappings":";;;;;;;AAEA;;AAMA;;AACA;;;;AAUA;;;eAGe,CACbA,IADa,EAEbC,oBAFa,EAGbC,eAHa,EAIbC,eAJa,EAKbC,OALa,KAMJ;AACT,QAAMC,iBAAiB,GAAG,2BAAaH,eAAe,CAACI,KAAhB,CAAsBA,KAAnC,EAA0CL,oBAA1C,EAAgEG,OAAhE,CAA1B;AAEA,QAAMG,oBAAoB,GAAGP,IAAI,CAACQ,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAC1BC,IAD0B,CACpBC,SAAD,IAAe;AACnB,WAAO,OAAOA,SAAS,CAACC,IAAjB,KAA0B,WAA1B,IAAyCD,SAAS,CAACC,IAAV,CAAeA,IAAf,KAAwBV,eAAxE;AACD,GAH0B,CAA7B;;AAKA,MAAII,oBAAJ,EAA0B;AACxB,QAAI,4BAAgBA,oBAAoB,CAACD,KAArC,CAAJ,EAAiD;AAC/CC,MAAAA,oBAAoB,CAACD,KAArB,CAA2BA,KAA3B,IAAoC,MAAMD,iBAA1C;AACD,KAFD,MAEO,IAAI,qCAAyBE,oBAAoB,CAACD,KAA9C,CAAJ,EAA0D;AAC/DC,MAAAA,oBAAoB,CAACD,KAArB,CAA2BQ,UAA3B,GAAwC,oCACtCP,oBAAoB,CAACD,KAArB,CAA2BQ,UADW,EAEtC,0BAAcT,iBAAd,CAFsC,CAAxC;AAID,KALM,MAKA;AACL,YAAM,IAAIU,KAAJ,CAAU,gCAAgCR,oBAAoB,CAACD,KAA/D,CAAN;AACD;;AAEDN,IAAAA,IAAI,CAACQ,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCM,MAApC,CAA2ChB,IAAI,CAACQ,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCO,OAApC,CAA4Cf,eAA5C,CAA3C,EAAyG,CAAzG;AACD,GAbD,MAaO;AACLA,IAAAA,eAAe,CAACW,IAAhB,CAAqBA,IAArB,GAA4BV,eAA5B;AACAD,IAAAA,eAAe,CAACI,KAAhB,CAAsBA,KAAtB,GAA8BD,iBAA9B;AACD;AACF,C","sourcesContent":["// @flow\n\nimport {\n isJSXExpressionContainer,\n isStringLiteral,\n JSXAttribute,\n stringLiteral\n} from '@babel/types';\nimport conditionalClassMerge from './conditionalClassMerge';\nimport getClassName from './getClassName';\nimport type {\n StyleModuleImportMapType,\n HandleMissingStyleNameOptionType\n} from './types';\n\ntype OptionsType = {|\n handleMissingStyleName: HandleMissingStyleNameOptionType\n|};\n\n/**\n * Updates the className value of a JSX element using a provided styleName attribute.\n */\nexport default (\n path: *,\n styleModuleImportMap: StyleModuleImportMapType,\n sourceAttribute: JSXAttribute,\n destinationName: string,\n options: OptionsType\n): void => {\n const resolvedStyleName = getClassName(sourceAttribute.value.value, styleModuleImportMap, options);\n\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 if (isStringLiteral(destinationAttribute.value)) {\n destinationAttribute.value.value += ' ' + resolvedStyleName;\n } else if (isJSXExpressionContainer(destinationAttribute.value)) {\n destinationAttribute.value.expression = conditionalClassMerge(\n destinationAttribute.value.expression,\n stringLiteral(resolvedStyleName)\n );\n } else {\n throw new Error('Unexpected attribute value:' + destinationAttribute.value);\n }\n\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(sourceAttribute), 1);\n } else {\n sourceAttribute.name.name = destinationName;\n sourceAttribute.value.value = resolvedStyleName;\n }\n};\n"],"file":"resolveStringLiteral.js"}
\No newline at end of file