diff --git a/.gitignore b/.gitignore index e944420..552588d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ coverage -dist node_modules *.log .* diff --git a/README.md b/README.md index 6dbe7ec..a827672 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # babel-plugin-react-css-modules -[![Travis build status](http://img.shields.io/travis/gajus/babel-plugin-react-css-modules/master.svg?style=flat-square)](https://travis-ci.org/gajus/babel-plugin-react-css-modules) +[![Travis build status](http://img.shields.io/travis/domehead100/babel-plugin-react-css-modules/master.svg?style=flat-square)](https://travis-ci.org/domehead100/babel-plugin-react-css-modules) [![NPM version](http://img.shields.io/npm/v/babel-plugin-react-css-modules.svg?style=flat-square)](https://www.npmjs.org/package/babel-plugin-react-css-modules) [![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical) [![Gitter](https://img.shields.io/gitter/room/babel-plugin-react-css-modules/Lobby.svg?style=flat-square)](https://gitter.im/babel-plugin-react-css-modules/Lobby) diff --git a/dist/browser/getClassName.js b/dist/browser/getClassName.js new file mode 100644 index 0000000..33c2f40 --- /dev/null +++ b/dist/browser/getClassName.js @@ -0,0 +1,98 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + + +var DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw'; + +var isNamespacedStyleName = function isNamespacedStyleName(styleName) { + return styleName.indexOf('.') !== -1; +}; + +var getClassNameForNamespacedStyleName = function getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleNameOption) { + // Note: + // Do not use the desctructing syntax with Babel. + // Desctructing adds _slicedToArray helper. + var styleNameParts = styleName.split('.'); + var importName = styleNameParts[0]; + var moduleName = styleNameParts[1]; + var handleMissingStyleName = handleMissingStyleNameOption || DEFAULT_HANDLE_MISSING_STYLENAME_OPTION; + + if (!moduleName) { + if (handleMissingStyleName === 'throw') { + throw new Error('Invalid style name.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('Invalid style name.'); + } else { + return null; + } + } + + if (!styleModuleImportMap[importName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('CSS module import does not exist.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('CSS module import does not exist.'); + } else { + return null; + } + } + + if (!styleModuleImportMap[importName][moduleName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('CSS module does not exist.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('CSS module does not exist.'); + } else { + return null; + } + } + + return styleModuleImportMap[importName][moduleName]; +}; + +exports.default = function (styleNameValue, styleModuleImportMap, options) { + var styleModuleImportMapKeys = Object.keys(styleModuleImportMap); + + var handleMissingStyleName = options && options.handleMissingStyleName || DEFAULT_HANDLE_MISSING_STYLENAME_OPTION; + + return styleNameValue.split(' ').filter(function (styleName) { + return styleName; + }).map(function (styleName) { + if (isNamespacedStyleName(styleName)) { + return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName); + } + + if (styleModuleImportMapKeys.length === 0) { + throw new Error('Cannot use styleName attribute without importing at least one stylesheet.'); + } + + if (styleModuleImportMapKeys.length > 1) { + throw new Error('Cannot use anonymous style name with more than one stylesheet import.'); + } + + var styleModuleMap = styleModuleImportMap[styleModuleImportMapKeys[0]]; + + if (!styleModuleMap[styleName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('Could not resolve the styleName \'' + styleName + '\'.'); + } + if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('Could not resolve the styleName \'' + styleName + '\'.'); + } + } + + return styleModuleMap[styleName]; + }).filter(function (className) { + // Remove any styles which could not be found (if handleMissingStyleName === 'ignore') + return className; + }).join(' '); +}; + +//# sourceMappingURL=getClassName.js.map \ No newline at end of file diff --git a/dist/browser/getClassName.js.map b/dist/browser/getClassName.js.map new file mode 100644 index 0000000..e201980 --- /dev/null +++ b/dist/browser/getClassName.js.map @@ -0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n HandleMissingStyleNameOptionType\r\n} from './types';\r\n\r\nconst DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw';\r\n\r\nconst isNamespacedStyleName = (styleName: string): boolean => {\r\n return styleName.indexOf('.') !== -1;\r\n};\r\n\r\nconst getClassNameForNamespacedStyleName = (\r\n styleName: string,\r\n styleModuleImportMap: StyleModuleImportMapType,\r\n handleMissingStyleNameOption?: HandleMissingStyleNameOptionType\r\n): ?string => {\r\n // Note:\r\n // Do not use the desctructing syntax with Babel.\r\n // Desctructing adds _slicedToArray helper.\r\n const styleNameParts = styleName.split('.');\r\n const importName = styleNameParts[0];\r\n const moduleName = styleNameParts[1];\r\n const handleMissingStyleName = handleMissingStyleNameOption ||\r\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\r\n\r\n if (!moduleName) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('Invalid style name.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('Invalid style name.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n if (!styleModuleImportMap[importName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('CSS module import does not exist.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('CSS module import does not exist.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n if (!styleModuleImportMap[importName][moduleName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('CSS module does not exist.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('CSS module does not exist.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n return styleModuleImportMap[importName][moduleName];\r\n};\r\n\r\ntype OptionsType = {|\r\n handleMissingStyleName: HandleMissingStyleNameOptionType\r\n|};\r\n\r\nexport default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options?: OptionsType): string => {\r\n const styleModuleImportMapKeys = Object.keys(styleModuleImportMap);\r\n\r\n const handleMissingStyleName = options && options.handleMissingStyleName ||\r\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\r\n\r\n return styleNameValue\r\n .split(' ')\r\n .filter((styleName) => {\r\n return styleName;\r\n })\r\n .map((styleName) => {\r\n if (isNamespacedStyleName(styleName)) {\r\n return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName);\r\n }\r\n\r\n if (styleModuleImportMapKeys.length === 0) {\r\n throw new Error('Cannot use styleName attribute without importing at least one stylesheet.');\r\n }\r\n\r\n if (styleModuleImportMapKeys.length > 1) {\r\n throw new Error('Cannot use anonymous style name with more than one stylesheet import.');\r\n }\r\n\r\n const styleModuleMap: StyleModuleMapType = styleModuleImportMap[styleModuleImportMapKeys[0]];\r\n\r\n if (!styleModuleMap[styleName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('Could not resolve the styleName \\'' + styleName + '\\'.');\r\n }\r\n if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('Could not resolve the styleName \\'' + styleName + '\\'.');\r\n }\r\n }\r\n\r\n return styleModuleMap[styleName];\r\n })\r\n .filter((className) => {\r\n // Remove any styles which could not be found (if handleMissingStyleName === 'ignore')\r\n return className;\r\n })\r\n .join(' ');\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/conditionalClassMerge.js b/dist/conditionalClassMerge.js new file mode 100644 index 0000000..0d629d4 --- /dev/null +++ b/dist/conditionalClassMerge.js @@ -0,0 +1,14 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _babelTypes = require('babel-types'); + +/* eslint-disable flowtype/no-weak-types */ + +exports.default = (classNameExpression, styleNameExpression) => { + return (0, _babelTypes.binaryExpression)('+', (0, _babelTypes.conditionalExpression)(classNameExpression, (0, _babelTypes.binaryExpression)('+', classNameExpression, (0, _babelTypes.stringLiteral)(' ')), (0, _babelTypes.stringLiteral)('')), styleNameExpression); +}; +//# sourceMappingURL=conditionalClassMerge.js.map \ No newline at end of file diff --git a/dist/conditionalClassMerge.js.map b/dist/conditionalClassMerge.js.map new file mode 100644 index 0000000..100dfc5 --- /dev/null +++ b/dist/conditionalClassMerge.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/conditionalClassMerge.js"],"names":["classNameExpression","styleNameExpression"],"mappings":";;;;;;AAEA;;AAMA;;kBAEe,CACbA,mBADa,EAEbC,mBAFa,KAGL;AACR,SAAO,kCACL,GADK,EAEL,uCACED,mBADF,EAEE,kCACE,GADF,EAEEA,mBAFF,EAGE,+BAAc,GAAd,CAHF,CAFF,EAOE,+BAAc,EAAd,CAPF,CAFK,EAWLC,mBAXK,CAAP;AAaD,C","file":"conditionalClassMerge.js","sourcesContent":["// @flow\r\n\r\nimport {\r\n binaryExpression,\r\n conditionalExpression,\r\n stringLiteral\r\n} from 'babel-types';\r\n\r\n/* eslint-disable flowtype/no-weak-types */\r\n\r\nexport default (\r\n classNameExpression: any,\r\n styleNameExpression: any,\r\n): any => {\r\n return binaryExpression(\r\n '+',\r\n conditionalExpression(\r\n classNameExpression,\r\n binaryExpression(\r\n '+',\r\n classNameExpression,\r\n stringLiteral(' ')\r\n ),\r\n stringLiteral('')\r\n ),\r\n styleNameExpression\r\n );\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/createObjectExpression.js b/dist/createObjectExpression.js new file mode 100644 index 0000000..be3f96e --- /dev/null +++ b/dist/createObjectExpression.js @@ -0,0 +1,42 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _babelTypes = require('babel-types'); + +var _babelTypes2 = _interopRequireDefault(_babelTypes); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * Creates an AST representation of an InputObjectType shape object. + */ +const createObjectExpression = (t, object) => { + const properties = []; + + for (const name of Object.keys(object)) { + const value = object[name]; + + let newValue; + + // eslint-disable-next-line no-empty + if (t.isAnyTypeAnnotation(value)) {} else if (typeof value === 'string') { + newValue = t.stringLiteral(value); + } else if (typeof value === 'object') { + newValue = createObjectExpression(t, value); + } else if (typeof value === 'boolean') { + newValue = t.booleanLiteral(value); + } else { + throw new Error('Unexpected type.'); + } + + properties.push(t.objectProperty(t.stringLiteral(name), newValue)); + } + + return t.objectExpression(properties); +}; + +exports.default = createObjectExpression; +//# sourceMappingURL=createObjectExpression.js.map \ No newline at end of file diff --git a/dist/createObjectExpression.js.map b/dist/createObjectExpression.js.map new file mode 100644 index 0000000..e7c920b --- /dev/null +++ b/dist/createObjectExpression.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/createObjectExpression.js"],"names":["createObjectExpression","t","object","properties","name","Object","keys","value","newValue","isAnyTypeAnnotation","stringLiteral","booleanLiteral","Error","push","objectProperty","objectExpression"],"mappings":";;;;;;AAEA;;;;;;AAQA;;;AAGA,MAAMA,yBAAyB,CAACC,CAAD,EAAgBC,MAAhB,KAA8D;AAC3F,QAAMC,aAAa,EAAnB;;AAEA,OAAK,MAAMC,IAAX,IAAmBC,OAAOC,IAAP,CAAYJ,MAAZ,CAAnB,EAAwC;AACtC,UAAMK,QAAQL,OAAOE,IAAP,CAAd;;AAEA,QAAII,QAAJ;;AAEA;AACA,QAAIP,EAAEQ,mBAAF,CAAsBF,KAAtB,CAAJ,EAAkC,CAEjC,CAFD,MAEO,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AACpCC,iBAAWP,EAAES,aAAF,CAAgBH,KAAhB,CAAX;AACD,KAFM,MAEA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AACpCC,iBAAWR,uBAAuBC,CAAvB,EAA0BM,KAA1B,CAAX;AACD,KAFM,MAEA,IAAI,OAAOA,KAAP,KAAiB,SAArB,EAAgC;AACrCC,iBAAWP,EAAEU,cAAF,CAAiBJ,KAAjB,CAAX;AACD,KAFM,MAEA;AACL,YAAM,IAAIK,KAAJ,CAAU,kBAAV,CAAN;AACD;;AAEDT,eAAWU,IAAX,CACEZ,EAAEa,cAAF,CACEb,EAAES,aAAF,CAAgBN,IAAhB,CADF,EAEEI,QAFF,CADF;AAMD;;AAED,SAAOP,EAAEc,gBAAF,CAAmBZ,UAAnB,CAAP;AACD,CA9BD;;kBAgCeH,sB","file":"createObjectExpression.js","sourcesContent":["// @flow\r\n\r\nimport BabelTypes, {\r\n ObjectExpression\r\n} from 'babel-types';\r\n\r\ntype InputObjectType = {\r\n [key: string]: *\r\n};\r\n\r\n/**\r\n * Creates an AST representation of an InputObjectType shape object.\r\n */\r\nconst createObjectExpression = (t: BabelTypes, object: InputObjectType): ObjectExpression => {\r\n const properties = [];\r\n\r\n for (const name of Object.keys(object)) {\r\n const value = object[name];\r\n\r\n let newValue;\r\n\r\n // eslint-disable-next-line no-empty\r\n if (t.isAnyTypeAnnotation(value)) {\r\n\r\n } else if (typeof value === 'string') {\r\n newValue = t.stringLiteral(value);\r\n } else if (typeof value === 'object') {\r\n newValue = createObjectExpression(t, value);\r\n } else if (typeof value === 'boolean') {\r\n newValue = t.booleanLiteral(value);\r\n } else {\r\n throw new Error('Unexpected type.');\r\n }\r\n\r\n properties.push(\r\n t.objectProperty(\r\n t.stringLiteral(name),\r\n newValue\r\n )\r\n );\r\n }\r\n\r\n return t.objectExpression(properties);\r\n};\r\n\r\nexport default createObjectExpression;\r\n"]} \ No newline at end of file diff --git a/dist/getClassName.js b/dist/getClassName.js new file mode 100644 index 0000000..dad310a --- /dev/null +++ b/dist/getClassName.js @@ -0,0 +1,97 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + + +const DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw'; + +const isNamespacedStyleName = styleName => { + return styleName.indexOf('.') !== -1; +}; + +const getClassNameForNamespacedStyleName = (styleName, styleModuleImportMap, handleMissingStyleNameOption) => { + // Note: + // Do not use the desctructing syntax with Babel. + // Desctructing adds _slicedToArray helper. + const styleNameParts = styleName.split('.'); + const importName = styleNameParts[0]; + const moduleName = styleNameParts[1]; + const handleMissingStyleName = handleMissingStyleNameOption || DEFAULT_HANDLE_MISSING_STYLENAME_OPTION; + + if (!moduleName) { + if (handleMissingStyleName === 'throw') { + throw new Error('Invalid style name.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('Invalid style name.'); + } else { + return null; + } + } + + if (!styleModuleImportMap[importName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('CSS module import does not exist.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('CSS module import does not exist.'); + } else { + return null; + } + } + + if (!styleModuleImportMap[importName][moduleName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('CSS module does not exist.'); + } else if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('CSS module does not exist.'); + } else { + return null; + } + } + + return styleModuleImportMap[importName][moduleName]; +}; + +exports.default = (styleNameValue, styleModuleImportMap, options) => { + const styleModuleImportMapKeys = Object.keys(styleModuleImportMap); + + const handleMissingStyleName = options && options.handleMissingStyleName || DEFAULT_HANDLE_MISSING_STYLENAME_OPTION; + + return styleNameValue.split(' ').filter(styleName => { + return styleName; + }).map(styleName => { + if (isNamespacedStyleName(styleName)) { + return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName); + } + + if (styleModuleImportMapKeys.length === 0) { + throw new Error('Cannot use styleName attribute without importing at least one stylesheet.'); + } + + if (styleModuleImportMapKeys.length > 1) { + throw new Error('Cannot use anonymous style name with more than one stylesheet import.'); + } + + const styleModuleMap = styleModuleImportMap[styleModuleImportMapKeys[0]]; + + if (!styleModuleMap[styleName]) { + if (handleMissingStyleName === 'throw') { + throw new Error('Could not resolve the styleName \'' + styleName + '\'.'); + } + if (handleMissingStyleName === 'warn') { + // eslint-disable-next-line no-console + console.warn('Could not resolve the styleName \'' + styleName + '\'.'); + } + } + + return styleModuleMap[styleName]; + }).filter(className => { + // Remove any styles which could not be found (if handleMissingStyleName === 'ignore') + return className; + }).join(' '); +}; +//# sourceMappingURL=getClassName.js.map \ No newline at end of file diff --git a/dist/getClassName.js.map b/dist/getClassName.js.map new file mode 100644 index 0000000..e326cdc --- /dev/null +++ b/dist/getClassName.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/getClassName.js"],"names":["DEFAULT_HANDLE_MISSING_STYLENAME_OPTION","isNamespacedStyleName","styleName","indexOf","getClassNameForNamespacedStyleName","styleModuleImportMap","handleMissingStyleNameOption","styleNameParts","split","importName","moduleName","handleMissingStyleName","Error","console","warn","styleNameValue","options","styleModuleImportMapKeys","Object","keys","filter","map","length","styleModuleMap","className","join"],"mappings":";;;;;;;AAQA,MAAMA,0CAA0C,OAAhD;;AAEA,MAAMC,wBAAyBC,SAAD,IAAgC;AAC5D,SAAOA,UAAUC,OAAV,CAAkB,GAAlB,MAA2B,CAAC,CAAnC;AACD,CAFD;;AAIA,MAAMC,qCAAqC,CACzCF,SADyC,EAEzCG,oBAFyC,EAGzCC,4BAHyC,KAI7B;AACZ;AACA;AACA;AACA,QAAMC,iBAAiBL,UAAUM,KAAV,CAAgB,GAAhB,CAAvB;AACA,QAAMC,aAAaF,eAAe,CAAf,CAAnB;AACA,QAAMG,aAAaH,eAAe,CAAf,CAAnB;AACA,QAAMI,yBAAyBL,gCAC7BN,uCADF;;AAGA,MAAI,CAACU,UAAL,EAAiB;AACf,QAAIC,2BAA2B,OAA/B,EAAwC;AACtC,YAAM,IAAIC,KAAJ,CAAU,qBAAV,CAAN;AACD,KAFD,MAEO,IAAID,2BAA2B,MAA/B,EAAuC;AAC5C;AACAE,cAAQC,IAAR,CAAa,qBAAb;AACD,KAHM,MAGA;AACL,aAAO,IAAP;AACD;AACF;;AAED,MAAI,CAACT,qBAAqBI,UAArB,CAAL,EAAuC;AACrC,QAAIE,2BAA2B,OAA/B,EAAwC;AACtC,YAAM,IAAIC,KAAJ,CAAU,mCAAV,CAAN;AACD,KAFD,MAEO,IAAID,2BAA2B,MAA/B,EAAuC;AAC5C;AACAE,cAAQC,IAAR,C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D,CAAN;AACD;AACD,UAAIS,2BAA2B,MAA/B,EAAuC;AACrC;AACAE,gBAAQC,IAAR,CAAa,uCAAuCZ,SAAvC,GAAmD,KAAhE;AACD;AACF;;AAED,WAAOqB,eAAerB,SAAf,CAAP;AACD,GA/BI,EAgCJkB,MAhCI,CAgCII,SAAD,IAAe;AACrB;AACA,WAAOA,SAAP;AACD,GAnCI,EAoCJC,IApCI,CAoCC,GApCD,CAAP;AAqCD,C","file":"getClassName.js","sourcesContent":["// @flow\r\n\r\nimport type {\r\n StyleModuleMapType,\r\n StyleModuleImportMapType,\r\n HandleMissingStyleNameOptionType\r\n} from './types';\r\n\r\nconst DEFAULT_HANDLE_MISSING_STYLENAME_OPTION = 'throw';\r\n\r\nconst isNamespacedStyleName = (styleName: string): boolean => {\r\n return styleName.indexOf('.') !== -1;\r\n};\r\n\r\nconst getClassNameForNamespacedStyleName = (\r\n styleName: string,\r\n styleModuleImportMap: StyleModuleImportMapType,\r\n handleMissingStyleNameOption?: HandleMissingStyleNameOptionType\r\n): ?string => {\r\n // Note:\r\n // Do not use the desctructing syntax with Babel.\r\n // Desctructing adds _slicedToArray helper.\r\n const styleNameParts = styleName.split('.');\r\n const importName = styleNameParts[0];\r\n const moduleName = styleNameParts[1];\r\n const handleMissingStyleName = handleMissingStyleNameOption ||\r\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\r\n\r\n if (!moduleName) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('Invalid style name.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('Invalid style name.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n if (!styleModuleImportMap[importName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('CSS module import does not exist.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('CSS module import does not exist.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n if (!styleModuleImportMap[importName][moduleName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('CSS module does not exist.');\r\n } else if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('CSS module does not exist.');\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n return styleModuleImportMap[importName][moduleName];\r\n};\r\n\r\ntype OptionsType = {|\r\n handleMissingStyleName: HandleMissingStyleNameOptionType\r\n|};\r\n\r\nexport default (styleNameValue: string, styleModuleImportMap: StyleModuleImportMapType, options?: OptionsType): string => {\r\n const styleModuleImportMapKeys = Object.keys(styleModuleImportMap);\r\n\r\n const handleMissingStyleName = options && options.handleMissingStyleName ||\r\n DEFAULT_HANDLE_MISSING_STYLENAME_OPTION;\r\n\r\n return styleNameValue\r\n .split(' ')\r\n .filter((styleName) => {\r\n return styleName;\r\n })\r\n .map((styleName) => {\r\n if (isNamespacedStyleName(styleName)) {\r\n return getClassNameForNamespacedStyleName(styleName, styleModuleImportMap, handleMissingStyleName);\r\n }\r\n\r\n if (styleModuleImportMapKeys.length === 0) {\r\n throw new Error('Cannot use styleName attribute without importing at least one stylesheet.');\r\n }\r\n\r\n if (styleModuleImportMapKeys.length > 1) {\r\n throw new Error('Cannot use anonymous style name with more than one stylesheet import.');\r\n }\r\n\r\n const styleModuleMap: StyleModuleMapType = styleModuleImportMap[styleModuleImportMapKeys[0]];\r\n\r\n if (!styleModuleMap[styleName]) {\r\n if (handleMissingStyleName === 'throw') {\r\n throw new Error('Could not resolve the styleName \\'' + styleName + '\\'.');\r\n }\r\n if (handleMissingStyleName === 'warn') {\r\n // eslint-disable-next-line no-console\r\n console.warn('Could not resolve the styleName \\'' + styleName + '\\'.');\r\n }\r\n }\r\n\r\n return styleModuleMap[styleName];\r\n })\r\n .filter((className) => {\r\n // Remove any styles which could not be found (if handleMissingStyleName === 'ignore')\r\n return className;\r\n })\r\n .join(' ');\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..077ff9f --- /dev/null +++ b/dist/index.js @@ -0,0 +1,216 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _path = require('path'); + +var _babelPluginSyntaxJsx = require('babel-plugin-syntax-jsx'); + +var _babelPluginSyntaxJsx2 = _interopRequireDefault(_babelPluginSyntaxJsx); + +var _babelTypes = require('babel-types'); + +var _babelTypes2 = _interopRequireDefault(_babelTypes); + +var _ajvKeywords = require('ajv-keywords'); + +var _ajvKeywords2 = _interopRequireDefault(_ajvKeywords); + +var _ajv = require('ajv'); + +var _ajv2 = _interopRequireDefault(_ajv); + +var _optionsSchema = require('./schemas/optionsSchema.json'); + +var _optionsSchema2 = _interopRequireDefault(_optionsSchema); + +var _optionsDefaults = require('./schemas/optionsDefaults'); + +var _optionsDefaults2 = _interopRequireDefault(_optionsDefaults); + +var _createObjectExpression = require('./createObjectExpression'); + +var _createObjectExpression2 = _interopRequireDefault(_createObjectExpression); + +var _requireCssModule = require('./requireCssModule'); + +var _requireCssModule2 = _interopRequireDefault(_requireCssModule); + +var _resolveStringLiteral = require('./resolveStringLiteral'); + +var _resolveStringLiteral2 = _interopRequireDefault(_resolveStringLiteral); + +var _replaceJsxExpressionContainer = require('./replaceJsxExpressionContainer'); + +var _replaceJsxExpressionContainer2 = _interopRequireDefault(_replaceJsxExpressionContainer); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const ajv = new _ajv2.default({ + // eslint-disable-next-line id-match + $data: true +}); + +(0, _ajvKeywords2.default)(ajv); + +const validate = ajv.compile(_optionsSchema2.default); + +exports.default = (_ref) => { + let t = _ref.types; + + const filenameMap = {}; + + const setupFileForRuntimeResolution = (path, filename) => { + const programPath = path.findParent(parentPath => { + return parentPath.isProgram(); + }); + + filenameMap[filename].importedHelperIndentifier = programPath.scope.generateUidIdentifier('getClassName'); + filenameMap[filename].styleModuleImportMapIdentifier = programPath.scope.generateUidIdentifier('styleModuleImportMap'); + + programPath.unshiftContainer('body', t.importDeclaration([t.importDefaultSpecifier(filenameMap[filename].importedHelperIndentifier)], t.stringLiteral('babel-plugin-react-css-modules/dist/browser/getClassName'))); + + const firstNonImportDeclarationNode = programPath.get('body').find(node => { + return !t.isImportDeclaration(node); + }); + + firstNonImportDeclarationNode.insertBefore(t.variableDeclaration('const', [t.variableDeclarator(filenameMap[filename].styleModuleImportMapIdentifier, (0, _createObjectExpression2.default)(t, filenameMap[filename].styleModuleImportMap))])); + // eslint-disable-next-line + // console.log('setting up', filename, util.inspect(filenameMap,{depth: 5})) + }; + + const addWebpackHotModuleAccept = path => { + const test = t.memberExpression(t.identifier('module'), t.identifier('hot')); + const consequent = t.blockStatement([t.expressionStatement(t.callExpression(t.memberExpression(t.memberExpression(t.identifier('module'), t.identifier('hot')), t.identifier('accept')), [t.stringLiteral(path.node.source.value), t.functionExpression(null, [], t.blockStatement([t.expressionStatement(t.callExpression(t.identifier('require'), [t.stringLiteral(path.node.source.value)]))]))]))]); + + const programPath = path.findParent(parentPath => { + return parentPath.isProgram(); + }); + + const firstNonImportDeclarationNode = programPath.get('body').find(node => { + return !t.isImportDeclaration(node); + }); + + const hotAcceptStatement = t.ifStatement(test, consequent); + + if (firstNonImportDeclarationNode) { + firstNonImportDeclarationNode.insertBefore(hotAcceptStatement); + } else { + programPath.pushContainer('body', hotAcceptStatement); + } + }; + + const getTargetResourcePath = (path, stats) => { + const targetFileDirectoryPath = (0, _path.dirname)(stats.file.opts.filename); + + if (path.node.source.value.startsWith('.')) { + return (0, _path.resolve)(targetFileDirectoryPath, path.node.source.value); + } + + return require.resolve(path.node.source.value); + }; + + const notForPlugin = (path, stats) => { + stats.opts.filetypes = stats.opts.filetypes || {}; + + const extension = path.node.source.value.lastIndexOf('.') > -1 ? path.node.source.value.substr(path.node.source.value.lastIndexOf('.')) : null; + + if (extension !== '.css' && Object.keys(stats.opts.filetypes).indexOf(extension) < 0) { + return true; + } + + if (stats.opts.exclude && getTargetResourcePath(path, stats).match(new RegExp(stats.opts.exclude))) { + return true; + } + + return false; + }; + + return { + inherits: _babelPluginSyntaxJsx2.default, + visitor: { + ImportDeclaration(path, stats) { + if (notForPlugin(path, stats)) { + return; + } + + const filename = stats.file.opts.filename; + const targetResourcePath = getTargetResourcePath(path, stats); + + let styleImportName; + + if (path.node.specifiers.length === 0) { + // use imported file path as import name + styleImportName = path.node.source.value; + } else if (path.node.specifiers.length === 1) { + styleImportName = path.node.specifiers[0].local.name; + } else { + // eslint-disable-next-line no-console + console.warn('Please report your use case. https://github.com/gajus/babel-plugin-react-css-modules/issues/new?title=Unexpected+use+case.'); + + throw new Error('Unexpected use case.'); + } + + filenameMap[filename].styleModuleImportMap[styleImportName] = (0, _requireCssModule2.default)(targetResourcePath, { + context: stats.opts.context, + filetypes: stats.opts.filetypes || {}, + generateScopedName: stats.opts.generateScopedName + }); + + if (stats.opts.webpackHotModuleReloading) { + addWebpackHotModuleAccept(path); + } + + if (stats.opts.removeImport) { + path.remove(); + } + }, + JSXElement(path, stats) { + const filename = stats.file.opts.filename; + const styleNameAttribute = path.node.openingElement.attributes.find(attribute => { + return typeof attribute.name !== 'undefined' && attribute.name.name === 'styleName'; + }); + + if (!styleNameAttribute) { + return; + } + + const handleMissingStyleName = stats.opts && stats.opts.handleMissingStyleName || _optionsDefaults2.default.handleMissingStyleName; + + if (t.isStringLiteral(styleNameAttribute.value)) { + (0, _resolveStringLiteral2.default)(path, filenameMap[filename].styleModuleImportMap, styleNameAttribute, { + handleMissingStyleName + }); + + return; + } + + if (t.isJSXExpressionContainer(styleNameAttribute.value)) { + if (!filenameMap[filename].importedHelperIndentifier) { + setupFileForRuntimeResolution(path, filename); + } + (0, _replaceJsxExpressionContainer2.default)(t, path, styleNameAttribute, filenameMap[filename].importedHelperIndentifier, filenameMap[filename].styleModuleImportMapIdentifier, { + handleMissingStyleName + }); + } + }, + Program(path, stats) { + if (!validate(stats.opts)) { + // eslint-disable-next-line no-console + console.error(validate.errors); + + throw new Error('Invalid configuration'); + } + + const filename = stats.file.opts.filename; + + filenameMap[filename] = { + styleModuleImportMap: {} + }; + } + } + }; +}; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/index.js.map b/dist/index.js.map new file mode 100644 index 0000000..147de31 --- /dev/null +++ b/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/index.js"],"names":["ajv","$data","validate","compile","t","types","filenameMap","setupFileForRuntimeResolution","path","filename","programPath","findParent","parentPath","isProgram","importedHelperIndentifier","scope","generateUidIdentifier","styleModuleImportMapIdentifier","unshiftContainer","importDeclaration","importDefaultSpecifier","stringLiteral","firstNonImportDeclarationNode","get","find","node","isImportDeclaration","insertBefore","variableDeclaration","variableDeclarator","styleModuleImportMap","addWebpackHotModuleAccept","test","memberExpression","identifier","consequent","blockStatement","expressionStatement","callExpression","source","value","functionExpression","hotAcceptStatement","ifStatement","pushContainer","getTargetResourcePath","stats","targetFileDirectoryPath","file","opts","startsWith","require","resolve","notForPlugin","filetypes","extension","lastIndexOf","substr","Object","keys","indexOf","exclude","match","RegExp","inherits","visitor","ImportDeclaration","targetResourcePath","styleImportName","specifiers","length","local","name","console","warn","Error","context","generateScopedName","webpackHotModuleReloading","removeImport","remove","JSXElement","styleNameAttribute","openingElement","attributes","attribute","handleMissingStyleName","isStringLiteral","isJSXExpressionContainer","Program","error","errors"],"mappings":";;;;;;AAEA;;AAIA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;;;AAEA,MAAMA,MAAM,kBAAQ;AAClB;AACAC,SAAO;AAFW,CAAR,CAAZ;;AAKA,2BAAYD,GAAZ;;AAEA,MAAME,WAAWF,IAAIG,OAAJ,yBAAjB;;kBAEe,UAIT;AAAA,MAHGC,CAGH,QAHJC,KAGI;;AACJ,QAAMC,cAAc,EAApB;;AAEA,QAAMC,gCAAgC,CAACC,IAAD,EAAOC,QAAP,KAAoB;AACxD,UAAMC,cAAcF,KAAKG,UAAL,CAAiBC,U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V,CAAeA,IAAf,KAAwB,WAAxE;AACD,SAHwB,CAA3B;;AAKA,YAAI,CAACU,kBAAL,EAAyB;AACvB;AACD;;AAED,cAAMI,yBAAyBxC,MAAMG,IAAN,IAAcH,MAAMG,IAAN,CAAWqC,sBAAzB,IAAmD,0BAAgBA,sBAAlG;;AAEA,YAAIlF,EAAEmF,eAAF,CAAkBL,mBAAmB1C,KAArC,CAAJ,EAAiD;AAC/C,8CACEhC,IADF,EAEEF,YAAYG,QAAZ,EAAsBqB,oBAFxB,EAGEoD,kBAHF,EAIE;AACEI;AADF,WAJF;;AASA;AACD;;AAED,YAAIlF,EAAEoF,wBAAF,CAA2BN,mBAAmB1C,KAA9C,CAAJ,EAA0D;AACxD,cAAI,CAAClC,YAAYG,QAAZ,EAAsBK,yBAA3B,EAAsD;AACpDP,0CAA8BC,IAA9B,EAAoCC,QAApC;AACD;AACD,uDACEL,CADF,EAEEI,IAFF,EAGE0E,kBAHF,EAIE5E,YAAYG,QAAZ,EAAsBK,yBAJxB,EAKER,YAAYG,QAAZ,EAAsBQ,8BALxB,EAME;AACEqE;AADF,WANF;AAUD;AACF,OA9EM;AA+EPG,cAASjF,IAAT,EAAkBsC,KAAlB,EAAkC;AAChC,YAAI,CAAC5C,SAAS4C,MAAMG,IAAf,CAAL,EAA2B;AACzB;AACAwB,kBAAQiB,KAAR,CAAcxF,SAASyF,MAAvB;;AAEA,gBAAM,IAAIhB,KAAJ,CAAU,uBAAV,CAAN;AACD;;AAED,cAAMlE,WAAWqC,MAAME,IAAN,CAAWC,IAAX,CAAgBxC,QAAjC;;AAEAH,oBAAYG,QAAZ,IAAwB;AACtBqB,gCAAsB;AADA,SAAxB;AAGD;AA5FM;AAFJ,GAAP;AAiGD,C","file":"index.js","sourcesContent":["// @flow\r\n\r\nimport {\r\n dirname,\r\n resolve\r\n} from 'path';\r\nimport babelPluginJsxSyntax from 'babel-plugin-syntax-jsx';\r\nimport BabelTypes from 'babel-types';\r\nimport ajvKeywords from 'ajv-keywords';\r\nimport Ajv from 'ajv';\r\nimport optionsSchema from './schemas/optionsSchema.json';\r\nimport optionsDefaults from './schemas/optionsDefaults';\r\nimport createObjectExpression from './createObjectExpression';\r\nimport requireCssModule from './requireCssModule';\r\nimport resolveStringLiteral from './resolveStringLiteral';\r\nimport replaceJsxExpressionContainer from './replaceJsxExpressionContainer';\r\n\r\nconst ajv = new Ajv({\r\n // eslint-disable-next-line id-match\r\n $data: true\r\n});\r\n\r\najvKeywords(ajv);\r\n\r\nconst validate = ajv.compile(optionsSchema);\r\n\r\nexport default ({\r\n types: t\r\n}: {\r\n types: BabelTypes\r\n}) => {\r\n const filenameMap = {};\r\n\r\n const setupFileForRuntimeResolution = (path, filename) => {\r\n const programPath = path.findParent((parentPath) => {\r\n return parentPath.isProgram();\r\n });\r\n\r\n filenameMap[filename].importedHelperIndentifier = programPath.scope.generateUidIdentifier('getClassName');\r\n filenameMap[filename].styleModuleImportMapIdentifier = programPath.scope.generateUidIdentifier('styleModuleImportMap');\r\n\r\n programPath.unshiftContainer(\r\n 'body',\r\n t.importDeclaration(\r\n [\r\n t.importDefaultSpecifier(\r\n filenameMap[filename].importedHelperIndentifier\r\n )\r\n ],\r\n t.stringLiteral('babel-plugin-react-css-modules/dist/browser/getClassName')\r\n )\r\n );\r\n\r\n const firstNonImportDeclarationNode = programPath.get('body').find((node) => {\r\n return !t.isImportDeclaration(node);\r\n });\r\n\r\n firstNonImportDeclarationNode.insertBefore(\r\n t.variableDeclaration(\r\n 'const',\r\n [\r\n t.variableDeclarator(\r\n filenameMap[filename].styleModuleImportMapIdentifier,\r\n createObjectExpression(t, filenameMap[filename].styleModuleImportMap)\r\n )\r\n ]\r\n )\r\n );\r\n // eslint-disable-next-line\r\n // console.log('setting up', filename, util.inspect(filenameMap,{depth: 5}))\r\n };\r\n\r\n const addWebpackHotModuleAccept = (path) => {\r\n const test = t.memberExpression(t.identifier('module'), t.identifier('hot'));\r\n const consequent = t.blockStatement([\r\n t.expressionStatement(\r\n t.callExpression(\r\n t.memberExpression(\r\n t.memberExpression(t.identifier('module'), t.identifier('hot')),\r\n t.identifier('accept')\r\n ),\r\n [\r\n t.stringLiteral(path.node.source.value),\r\n t.functionExpression(null, [], t.blockStatement([\r\n t.expressionStatement(\r\n t.callExpression(\r\n t.identifier('require'),\r\n [t.stringLiteral(path.node.source.value)]\r\n )\r\n )\r\n ]))\r\n ]\r\n )\r\n )\r\n ]);\r\n\r\n const programPath = path.findParent((parentPath) => {\r\n return parentPath.isProgram();\r\n });\r\n\r\n const firstNonImportDeclarationNode = programPath.get('body').find((node) => {\r\n return !t.isImportDeclaration(node);\r\n });\r\n\r\n const hotAcceptStatement = t.ifStatement(test, consequent);\r\n\r\n if (firstNonImportDeclarationNode) {\r\n firstNonImportDeclarationNode.insertBefore(hotAcceptStatement);\r\n } else {\r\n programPath.pushContainer('body', hotAcceptStatement);\r\n }\r\n };\r\n\r\n const getTargetResourcePath = (path: *, stats: *) => {\r\n const targetFileDirectoryPath = dirname(stats.file.opts.filename);\r\n\r\n if (path.node.source.value.startsWith('.')) {\r\n return resolve(targetFileDirectoryPath, path.node.source.value);\r\n }\r\n\r\n return require.resolve(path.node.source.value);\r\n };\r\n\r\n const notForPlugin = (path: *, stats: *) => {\r\n stats.opts.filetypes = stats.opts.filetypes || {};\r\n\r\n const extension = path.node.source.value.lastIndexOf('.') > -1 ? path.node.source.value.substr(path.node.source.value.lastIndexOf('.')) : null;\r\n\r\n if (extension !== '.css' && Object.keys(stats.opts.filetypes).indexOf(extension) < 0) {\r\n return true;\r\n }\r\n\r\n if (stats.opts.exclude && getTargetResourcePath(path, stats).match(new RegExp(stats.opts.exclude))) {\r\n return true;\r\n }\r\n\r\n return false;\r\n };\r\n\r\n return {\r\n inherits: babelPluginJsxSyntax,\r\n visitor: {\r\n ImportDeclaration (path: *, stats: *): void {\r\n if (notForPlugin(path, stats)) {\r\n return;\r\n }\r\n\r\n const filename = stats.file.opts.filename;\r\n const targetResourcePath = getTargetResourcePath(path, stats);\r\n\r\n let styleImportName: string;\r\n\r\n if (path.node.specifiers.length === 0) {\r\n // use imported file path as import name\r\n styleImportName = path.node.source.value;\r\n } else if (path.node.specifiers.length === 1) {\r\n styleImportName = path.node.specifiers[0].local.name;\r\n } else {\r\n // eslint-disable-next-line no-console\r\n console.warn('Please report your use case. https://github.com/gajus/babel-plugin-react-css-modules/issues/new?title=Unexpected+use+case.');\r\n\r\n throw new Error('Unexpected use case.');\r\n }\r\n\r\n filenameMap[filename].styleModuleImportMap[styleImportName] = requireCssModule(targetResourcePath, {\r\n context: stats.opts.context,\r\n filetypes: stats.opts.filetypes || {},\r\n generateScopedName: stats.opts.generateScopedName\r\n });\r\n\r\n if (stats.opts.webpackHotModuleReloading) {\r\n addWebpackHotModuleAccept(path);\r\n }\r\n\r\n if (stats.opts.removeImport) {\r\n path.remove();\r\n }\r\n },\r\n JSXElement (path: *, stats: *): void {\r\n const filename = stats.file.opts.filename;\r\n const styleNameAttribute = path.node.openingElement.attributes\r\n .find((attribute) => {\r\n return typeof attribute.name !== 'undefined' && attribute.name.name === 'styleName';\r\n });\r\n\r\n if (!styleNameAttribute) {\r\n return;\r\n }\r\n\r\n const handleMissingStyleName = stats.opts && stats.opts.handleMissingStyleName || optionsDefaults.handleMissingStyleName;\r\n\r\n if (t.isStringLiteral(styleNameAttribute.value)) {\r\n resolveStringLiteral(\r\n path,\r\n filenameMap[filename].styleModuleImportMap,\r\n styleNameAttribute,\r\n {\r\n handleMissingStyleName\r\n }\r\n );\r\n\r\n return;\r\n }\r\n\r\n if (t.isJSXExpressionContainer(styleNameAttribute.value)) {\r\n if (!filenameMap[filename].importedHelperIndentifier) {\r\n setupFileForRuntimeResolution(path, filename);\r\n }\r\n replaceJsxExpressionContainer(\r\n t,\r\n path,\r\n styleNameAttribute,\r\n filenameMap[filename].importedHelperIndentifier,\r\n filenameMap[filename].styleModuleImportMapIdentifier,\r\n {\r\n handleMissingStyleName\r\n }\r\n );\r\n }\r\n },\r\n Program (path: *, stats: *): void {\r\n if (!validate(stats.opts)) {\r\n // eslint-disable-next-line no-console\r\n console.error(validate.errors);\r\n\r\n throw new Error('Invalid configuration');\r\n }\r\n\r\n const filename = stats.file.opts.filename;\r\n\r\n filenameMap[filename] = {\r\n styleModuleImportMap: {}\r\n };\r\n }\r\n }\r\n };\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/replaceJsxExpressionContainer.js b/dist/replaceJsxExpressionContainer.js new file mode 100644 index 0000000..7a86fcf --- /dev/null +++ b/dist/replaceJsxExpressionContainer.js @@ -0,0 +1,59 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _babelTypes = require('babel-types'); + +var _babelTypes2 = _interopRequireDefault(_babelTypes); + +var _conditionalClassMerge = require('./conditionalClassMerge'); + +var _conditionalClassMerge2 = _interopRequireDefault(_conditionalClassMerge); + +var _createObjectExpression = require('./createObjectExpression'); + +var _createObjectExpression2 = _interopRequireDefault(_createObjectExpression); + +var _optionsDefaults = require('./schemas/optionsDefaults'); + +var _optionsDefaults2 = _interopRequireDefault(_optionsDefaults); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = (t, path, styleNameAttribute, importedHelperIndentifier, styleModuleImportMapIdentifier, options) => { + const expressionContainerValue = styleNameAttribute.value; + const classNameAttribute = path.node.openingElement.attributes.find(attribute => { + return typeof attribute.name !== 'undefined' && attribute.name.name === 'className'; + }); + + if (classNameAttribute) { + path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(classNameAttribute), 1); + } + + path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(styleNameAttribute), 1); + + const args = [expressionContainerValue.expression, styleModuleImportMapIdentifier]; + + // Only provide options argument if the options are something other than default + // This helps save a few bits in the generated user code + if (options.handleMissingStyleName !== _optionsDefaults2.default.handleMissingStyleName) { + args.push((0, _createObjectExpression2.default)(t, options)); + } + + const styleNameExpression = t.callExpression(importedHelperIndentifier, args); + + if (classNameAttribute) { + if ((0, _babelTypes.isStringLiteral)(classNameAttribute.value)) { + path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)('className'), (0, _babelTypes.jSXExpressionContainer)((0, _babelTypes.binaryExpression)('+', t.stringLiteral(classNameAttribute.value.value + ' '), styleNameExpression)))); + } else if ((0, _babelTypes.isJSXExpressionContainer)(classNameAttribute.value)) { + path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)('className'), (0, _babelTypes.jSXExpressionContainer)((0, _conditionalClassMerge2.default)(classNameAttribute.value.expression, styleNameExpression)))); + } else { + throw new Error('Unexpected attribute value.'); + } + } else { + path.node.openingElement.attributes.push((0, _babelTypes.jSXAttribute)((0, _babelTypes.jSXIdentifier)('className'), (0, _babelTypes.jSXExpressionContainer)(styleNameExpression))); + } +}; +//# sourceMappingURL=replaceJsxExpressionContainer.js.map \ No newline at end of file diff --git a/dist/replaceJsxExpressionContainer.js.map b/dist/replaceJsxExpressionContainer.js.map new file mode 100644 index 0000000..c266c74 --- /dev/null +++ b/dist/replaceJsxExpressionContainer.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/replaceJsxExpressionContainer.js"],"names":["t","path","styleNameAttribute","importedHelperIndentifier","styleModuleImportMapIdentifier","options","expressionContainerValue","value","classNameAttribute","node","openingElement","attributes","find","attribute","name","splice","indexOf","args","expression","handleMissingStyleName","push","styleNameExpression","callExpression","stringLiteral","Error"],"mappings":";;;;;;AACA;;;;AAaA;;;;AACA;;;;AACA;;;;;;kBAMe,CACbA,CADa,EAGbC,IAHa,EAIbC,kBAJa,EAKbC,yBALa,EAMbC,8BANa,EAObC,OAPa,KAQJ;AACT,QAAMC,2BAA2BJ,mBAAmBK,KAApD;AACA,QAAMC,qBAAqBP,KAAKQ,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CACxBC,IADwB,CAClBC,SAAD,IAAe;AACnB,WAAO,OAAOA,UAAUC,IAAjB,KAA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C,EAEvC,wCACE,qCACEZ,mBAAmBD,KAAnB,CAAyBW,UAD3B,EAEEG,mBAFF,CADF,CAFuC,CAAzC;AASD,KAVM,MAUA;AACL,YAAM,IAAIG,KAAJ,CAAU,6BAAV,CAAN;AACD;AACF,GAzBD,MAyBO;AACLvB,SAAKQ,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCS,IAApC,CAAyC,8BACvC,+BAAc,WAAd,CADuC,EAEvC,wCACEC,mBADF,CAFuC,CAAzC;AAMD;AACF,C","file":"replaceJsxExpressionContainer.js","sourcesContent":["// @flow\r\nimport BabelTypes, {\r\n binaryExpression,\r\n Identifier,\r\n isJSXExpressionContainer,\r\n isStringLiteral,\r\n jSXAttribute,\r\n JSXAttribute,\r\n jSXExpressionContainer,\r\n jSXIdentifier\r\n} from 'babel-types';\r\nimport type {\r\n HandleMissingStyleNameOptionType\r\n} from './types';\r\nimport conditionalClassMerge from './conditionalClassMerge';\r\nimport createObjectExpression from './createObjectExpression';\r\nimport optionsDefaults from './schemas/optionsDefaults';\r\n\r\ntype OptionsType = {|\r\n handleMissingStyleName: HandleMissingStyleNameOptionType\r\n|};\r\n\r\nexport default (\r\n t: BabelTypes,\r\n // eslint-disable-next-line flowtype/no-weak-types\r\n path: Object,\r\n styleNameAttribute: JSXAttribute,\r\n importedHelperIndentifier: Identifier,\r\n styleModuleImportMapIdentifier: Identifier,\r\n options: OptionsType\r\n): void => {\r\n const expressionContainerValue = styleNameAttribute.value;\r\n const classNameAttribute = path.node.openingElement.attributes\r\n .find((attribute) => {\r\n return typeof attribute.name !== 'undefined' && attribute.name.name === 'className';\r\n });\r\n\r\n if (classNameAttribute) {\r\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(classNameAttribute), 1);\r\n }\r\n\r\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(styleNameAttribute), 1);\r\n\r\n const args = [\r\n expressionContainerValue.expression,\r\n styleModuleImportMapIdentifier\r\n ];\r\n\r\n // Only provide options argument if the options are something other than default\r\n // This helps save a few bits in the generated user code\r\n if (options.handleMissingStyleName !== optionsDefaults.handleMissingStyleName) {\r\n args.push(createObjectExpression(t, options));\r\n }\r\n\r\n const styleNameExpression = t.callExpression(\r\n importedHelperIndentifier,\r\n args\r\n );\r\n\r\n if (classNameAttribute) {\r\n if (isStringLiteral(classNameAttribute.value)) {\r\n path.node.openingElement.attributes.push(jSXAttribute(\r\n jSXIdentifier('className'),\r\n jSXExpressionContainer(\r\n binaryExpression(\r\n '+',\r\n t.stringLiteral(classNameAttribute.value.value + ' '),\r\n styleNameExpression\r\n )\r\n )\r\n ));\r\n } else if (isJSXExpressionContainer(classNameAttribute.value)) {\r\n path.node.openingElement.attributes.push(jSXAttribute(\r\n jSXIdentifier('className'),\r\n jSXExpressionContainer(\r\n conditionalClassMerge(\r\n classNameAttribute.value.expression,\r\n styleNameExpression\r\n )\r\n )\r\n ));\r\n } else {\r\n throw new Error('Unexpected attribute value.');\r\n }\r\n } else {\r\n path.node.openingElement.attributes.push(jSXAttribute(\r\n jSXIdentifier('className'),\r\n jSXExpressionContainer(\r\n styleNameExpression\r\n )\r\n ));\r\n }\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/requireCssModule.js b/dist/requireCssModule.js new file mode 100644 index 0000000..22ea3d8 --- /dev/null +++ b/dist/requireCssModule.js @@ -0,0 +1,127 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _path = require('path'); + +var _fs = require('fs'); + +var _postcss = require('postcss'); + +var _postcss2 = _interopRequireDefault(_postcss); + +var _genericNames = require('generic-names'); + +var _genericNames2 = _interopRequireDefault(_genericNames); + +var _postcssModulesExtractImports = require('postcss-modules-extract-imports'); + +var _postcssModulesExtractImports2 = _interopRequireDefault(_postcssModulesExtractImports); + +var _postcssModulesLocalByDefault = require('postcss-modules-local-by-default'); + +var _postcssModulesLocalByDefault2 = _interopRequireDefault(_postcssModulesLocalByDefault); + +var _postcssModulesParser = require('postcss-modules-parser'); + +var _postcssModulesParser2 = _interopRequireDefault(_postcssModulesParser); + +var _postcssModulesScope = require('postcss-modules-scope'); + +var _postcssModulesScope2 = _interopRequireDefault(_postcssModulesScope); + +var _postcssModulesValues = require('postcss-modules-values'); + +var _postcssModulesValues2 = _interopRequireDefault(_postcssModulesValues); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +const getFiletypeOptions = (cssSourceFilePath, filetypes) => { + const extension = cssSourceFilePath.substr(cssSourceFilePath.lastIndexOf('.')); + const filetype = filetypes ? filetypes[extension] : null; + + return filetype; +}; + +// eslint-disable-next-line flowtype/no-weak-types + + +const getSyntax = filetypeOptions => { + if (!filetypeOptions || !filetypeOptions.syntax) { + return null; + } + + // eslint-disable-next-line import/no-dynamic-require, global-require + return require(filetypeOptions.syntax); +}; + +// eslint-disable-next-line flowtype/no-weak-types +const getExtraPlugins = filetypeOptions => { + if (!filetypeOptions || !filetypeOptions.plugins) { + return []; + } + + return filetypeOptions.plugins.map(plugin => { + // eslint-disable-next-line import/no-dynamic-require, global-require + return require(plugin); + }); +}; + +const getTokens = (runner, cssSourceFilePath, filetypeOptions) => { + // eslint-disable-next-line flowtype/no-weak-types + const options = { + from: cssSourceFilePath + }; + + if (filetypeOptions) { + options.syntax = getSyntax(filetypeOptions); + } + + const lazyResult = runner.process((0, _fs.readFileSync)(cssSourceFilePath, 'utf-8'), options); + + lazyResult.warnings().forEach(message => { + // eslint-disable-next-line no-console + console.warn(message.text); + }); + + return lazyResult.root.tokens; +}; + +exports.default = (cssSourceFilePath, options) => { + // eslint-disable-next-line prefer-const + let runner; + + let generateScopedName; + + if (options.generateScopedName && typeof options.generateScopedName === 'function') { + generateScopedName = options.generateScopedName; + } else { + generateScopedName = (0, _genericNames2.default)(options.generateScopedName || '[path]___[name]__[local]___[hash:base64:5]', { + context: options.context || process.cwd() + }); + } + + const filetypeOptions = getFiletypeOptions(cssSourceFilePath, options.filetypes); + + const fetch = (to, from) => { + const fromDirectoryPath = (0, _path.dirname)(from); + const toPath = (0, _path.resolve)(fromDirectoryPath, to); + + return getTokens(runner, toPath, filetypeOptions); + }; + + const extraPlugins = getExtraPlugins(filetypeOptions); + + const plugins = [...extraPlugins, _postcssModulesValues2.default, _postcssModulesLocalByDefault2.default, _postcssModulesExtractImports2.default, new _postcssModulesScope2.default({ + generateScopedName + }), new _postcssModulesParser2.default({ + fetch + })]; + + runner = (0, _postcss2.default)(plugins); + + return getTokens(runner, cssSourceFilePath, filetypeOptions); +}; +//# sourceMappingURL=requireCssModule.js.map \ No newline at end of file diff --git a/dist/requireCssModule.js.map b/dist/requireCssModule.js.map new file mode 100644 index 0000000..5f762ac --- /dev/null +++ b/dist/requireCssModule.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/requireCssModule.js"],"names":["getFiletypeOptions","cssSourceFilePath","filetypes","extension","substr","lastIndexOf","filetype","getSyntax","filetypeOptions","syntax","require","getExtraPlugins","plugins","map","plugin","getTokens","runner","options","from","lazyResult","process","warnings","forEach","message","console","warn","text","root","tokens","generateScopedName","context","cwd","fetch","to","fromDirectoryPath","toPath","extraPlugins"],"mappings":";;;;;;AAEA;;AAIA;;AAGA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;;;AAeA,MAAMA,qBAAqB,CAACC,iBAAD,EAA4BC,SAA5B,KAA4F;AACrH,QAAMC,YAAYF,kBAAkBG,MAAlB,CAAyBH,kBAAkBI,WAAlB,CAA8B,GAA9B,CAAzB,CAAlB;AACA,QAAMC,WAAWJ,YAAYA,UAAUC,SAAV,CAAZ,GAAmC,IAApD;;AAEA,SAAOG,QAAP;AACD,CALD;;AAOA;;;AACA,MAAMC,YAAaC,eAAD,IAAgE;AAChF,MAAI,CAACA,eAAD,IAAoB,CAACA,gBAAgBC,MAAzC,EAAiD;AAC/C,WAAO,IAAP;AACD;;AAED;AACA,SAAOC,QAAQF,gBAAgBC,MAAxB,CAAP;AACD,CAPD;;AASA;AACA,MAAME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IAAR,CAA1B;AACA,UAAMiB,SAAS,mBAAQD,iBAAR,EAA2BD,EAA3B,CAAf;;AAEA,WAAOlB,UAAUC,MAAV,EAAkBmB,MAAlB,EAA0B3B,eAA1B,CAAP;AACD,GALD;;AAOA,QAAM4B,eAAezB,gBAAgBH,eAAhB,CAArB;;AAEA,QAAMI,UAAU,CACd,GAAGwB,YADW,kHAKd,kCAAU;AACRP;AADQ,GAAV,CALc,EAQd,mCAAW;AACTG;AADS,GAAX,CARc,CAAhB;;AAaAhB,WAAS,uBAAQJ,OAAR,CAAT;;AAEA,SAAOG,UAAUC,MAAV,EAAkBf,iBAAlB,EAAqCO,eAArC,CAAP;AACD,C","file":"requireCssModule.js","sourcesContent":["// @flow\r\n\r\nimport {\r\n dirname,\r\n resolve\r\n} from 'path';\r\nimport {\r\n readFileSync\r\n} from 'fs';\r\nimport postcss from 'postcss';\r\nimport genericNames from 'generic-names';\r\nimport ExtractImports from 'postcss-modules-extract-imports';\r\nimport LocalByDefault from 'postcss-modules-local-by-default';\r\nimport Parser from 'postcss-modules-parser';\r\nimport Scope from 'postcss-modules-scope';\r\nimport Values from 'postcss-modules-values';\r\nimport type {\r\n GenerateScopedNameConfigurationType,\r\n StyleModuleMapType\r\n} from './types';\r\n\r\ntype FiletypeOptionsType = {|\r\n +syntax: string,\r\n +plugins?: $ReadOnlyArray\r\n|};\r\n\r\ntype FiletypesConfigurationType = {\r\n [key: string]: FiletypeOptionsType\r\n};\r\n\r\nconst getFiletypeOptions = (cssSourceFilePath: string, filetypes: FiletypesConfigurationType): ?FiletypeOptionsType => {\r\n const extension = cssSourceFilePath.substr(cssSourceFilePath.lastIndexOf('.'));\r\n const filetype = filetypes ? filetypes[extension] : null;\r\n\r\n return filetype;\r\n};\r\n\r\n// eslint-disable-next-line flowtype/no-weak-types\r\nconst getSyntax = (filetypeOptions: FiletypeOptionsType): ?(Function | Object) => {\r\n if (!filetypeOptions || !filetypeOptions.syntax) {\r\n return null;\r\n }\r\n\r\n // eslint-disable-next-line import/no-dynamic-require, global-require\r\n return require(filetypeOptions.syntax);\r\n};\r\n\r\n// eslint-disable-next-line flowtype/no-weak-types\r\nconst getExtraPlugins = (filetypeOptions: ?FiletypeOptionsType): $ReadOnlyArray<*> => {\r\n if (!filetypeOptions || !filetypeOptions.plugins) {\r\n return [];\r\n }\r\n\r\n return filetypeOptions.plugins.map((plugin) => {\r\n // eslint-disable-next-line import/no-dynamic-require, global-require\r\n return require(plugin);\r\n });\r\n};\r\n\r\nconst getTokens = (runner, cssSourceFilePath: string, filetypeOptions: ?FiletypeOptionsType): StyleModuleMapType => {\r\n // eslint-disable-next-line flowtype/no-weak-types\r\n const options: Object = {\r\n from: cssSourceFilePath\r\n };\r\n\r\n if (filetypeOptions) {\r\n options.syntax = getSyntax(filetypeOptions);\r\n }\r\n\r\n const lazyResult = runner\r\n .process(readFileSync(cssSourceFilePath, 'utf-8'), options);\r\n\r\n lazyResult\r\n .warnings()\r\n .forEach((message) => {\r\n // eslint-disable-next-line no-console\r\n console.warn(message.text);\r\n });\r\n\r\n return lazyResult.root.tokens;\r\n};\r\n\r\ntype OptionsType = {|\r\n filetypes: FiletypesConfigurationType,\r\n generateScopedName?: GenerateScopedNameConfigurationType,\r\n context?: string\r\n|};\r\n\r\nexport default (cssSourceFilePath: string, options: OptionsType): StyleModuleMapType => {\r\n // eslint-disable-next-line prefer-const\r\n let runner;\r\n\r\n let generateScopedName;\r\n\r\n if (options.generateScopedName && typeof options.generateScopedName === 'function') {\r\n generateScopedName = options.generateScopedName;\r\n } else {\r\n generateScopedName = genericNames(options.generateScopedName || '[path]___[name]__[local]___[hash:base64:5]', {\r\n context: options.context || process.cwd()\r\n });\r\n }\r\n\r\n const filetypeOptions = getFiletypeOptions(cssSourceFilePath, options.filetypes);\r\n\r\n const fetch = (to: string, from: string) => {\r\n const fromDirectoryPath = dirname(from);\r\n const toPath = resolve(fromDirectoryPath, to);\r\n\r\n return getTokens(runner, toPath, filetypeOptions);\r\n };\r\n\r\n const extraPlugins = getExtraPlugins(filetypeOptions);\r\n\r\n const plugins = [\r\n ...extraPlugins,\r\n Values,\r\n LocalByDefault,\r\n ExtractImports,\r\n new Scope({\r\n generateScopedName\r\n }),\r\n new Parser({\r\n fetch\r\n })\r\n ];\r\n\r\n runner = postcss(plugins);\r\n\r\n return getTokens(runner, cssSourceFilePath, filetypeOptions);\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/resolveStringLiteral.js b/dist/resolveStringLiteral.js new file mode 100644 index 0000000..885a936 --- /dev/null +++ b/dist/resolveStringLiteral.js @@ -0,0 +1,44 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _babelTypes = require('babel-types'); + +var _conditionalClassMerge = require('./conditionalClassMerge'); + +var _conditionalClassMerge2 = _interopRequireDefault(_conditionalClassMerge); + +var _getClassName = require('./getClassName'); + +var _getClassName2 = _interopRequireDefault(_getClassName); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +/** + * Updates the className value of a JSX element using a provided styleName attribute. + */ +exports.default = (path, styleModuleImportMap, styleNameAttribute, options) => { + const classNameAttribute = path.node.openingElement.attributes.find(attribute => { + return typeof attribute.name !== 'undefined' && attribute.name.name === 'className'; + }); + + const resolvedStyleName = (0, _getClassName2.default)(styleNameAttribute.value.value, styleModuleImportMap, options); + + if (classNameAttribute) { + if ((0, _babelTypes.isStringLiteral)(classNameAttribute.value)) { + classNameAttribute.value.value += ' ' + resolvedStyleName; + } else if ((0, _babelTypes.isJSXExpressionContainer)(classNameAttribute.value)) { + classNameAttribute.value.expression = (0, _conditionalClassMerge2.default)(classNameAttribute.value.expression, (0, _babelTypes.stringLiteral)(resolvedStyleName)); + } else { + throw new Error('Unexpected attribute value.'); + } + + path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(styleNameAttribute), 1); + } else { + styleNameAttribute.name.name = 'className'; + styleNameAttribute.value.value = resolvedStyleName; + } +}; +//# sourceMappingURL=resolveStringLiteral.js.map \ No newline at end of file diff --git a/dist/resolveStringLiteral.js.map b/dist/resolveStringLiteral.js.map new file mode 100644 index 0000000..fc896a0 --- /dev/null +++ b/dist/resolveStringLiteral.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/resolveStringLiteral.js"],"names":["path","styleModuleImportMap","styleNameAttribute","options","classNameAttribute","node","openingElement","attributes","find","attribute","name","resolvedStyleName","value","expression","Error","splice","indexOf"],"mappings":";;;;;;AAEA;;AAMA;;;;AACA;;;;;;AAUA;;;kBAGe,CAACA,IAAD,EAAUC,oBAAV,EAA0DC,kBAA1D,EAA4FC,OAA5F,KAA2H;AACxI,QAAMC,qBAAqBJ,KAAKK,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CACxBC,IADwB,CAClBC,SAAD,IAAe;AACnB,WAAO,OAAOA,UAAUC,IAAjB,KAA0B,WAA1B,IAAyCD,UAAUC,IAAV,CAAeA,IAAf,KAAwB,WAAxE;AACD,GAHwB,CAA3B;;AAKA,QAAMC,oBAAoB,4BAAaT,mBAAmBU,KAAnB,CAAyBA,KAAtC,EAA6CX,oBAA7C,EAAmEE,OAAnE,CAA1B;;AAEA,MAAIC,kBAAJ,EAAwB;AACtB,QAAI,iCAAgBA,mBAAmBQ,KAAnC,CAAJ,EAA+C;AAC7CR,yBAAmBQ,KAAnB,CAAyBA,KAAzB,IAAkC,MAAMD,iBAAxC;AACD,KAFD,MAEO,IAAI,0CAAyBP,mBAAmBQ,KAA5C,CAAJ,EAAwD;AAC7DR,yBAAmBQ,KAAnB,CAAyBC,UAAzB,GAAsC,qCACpCT,mBAAmBQ,KAAnB,CAAyBC,UADW,EAEpC,+BAAcF,iBAAd,CAFoC,CAAtC;AAID,KALM,MAKA;AACL,YAAM,IAAIG,KAAJ,CAAU,6BAAV,CAAN;AACD;;AAEDd,SAAKK,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCQ,MAApC,CAA2Cf,KAAKK,IAAL,CAAUC,cAAV,CAAyBC,UAAzB,CAAoCS,OAApC,CAA4Cd,kBAA5C,CAA3C,EAA4G,CAA5G;AACD,GAbD,MAaO;AACLA,uBAAmBQ,IAAnB,CAAwBA,IAAxB,GAA+B,WAA/B;AACAR,uBAAmBU,KAAnB,CAAyBA,KAAzB,GAAiCD,iBAAjC;AACD;AACF,C","file":"resolveStringLiteral.js","sourcesContent":["// @flow\r\n\r\nimport {\r\n isJSXExpressionContainer,\r\n isStringLiteral,\r\n JSXAttribute,\r\n stringLiteral\r\n} from 'babel-types';\r\nimport conditionalClassMerge from './conditionalClassMerge';\r\nimport getClassName from './getClassName';\r\nimport type {\r\n StyleModuleImportMapType,\r\n HandleMissingStyleNameOptionType\r\n} from './types';\r\n\r\ntype OptionsType = {|\r\n handleMissingStyleName: HandleMissingStyleNameOptionType\r\n|};\r\n\r\n/**\r\n * Updates the className value of a JSX element using a provided styleName attribute.\r\n */\r\nexport default (path: *, styleModuleImportMap: StyleModuleImportMapType, styleNameAttribute: JSXAttribute, options: OptionsType): void => {\r\n const classNameAttribute = path.node.openingElement.attributes\r\n .find((attribute) => {\r\n return typeof attribute.name !== 'undefined' && attribute.name.name === 'className';\r\n });\r\n\r\n const resolvedStyleName = getClassName(styleNameAttribute.value.value, styleModuleImportMap, options);\r\n\r\n if (classNameAttribute) {\r\n if (isStringLiteral(classNameAttribute.value)) {\r\n classNameAttribute.value.value += ' ' + resolvedStyleName;\r\n } else if (isJSXExpressionContainer(classNameAttribute.value)) {\r\n classNameAttribute.value.expression = conditionalClassMerge(\r\n classNameAttribute.value.expression,\r\n stringLiteral(resolvedStyleName)\r\n );\r\n } else {\r\n throw new Error('Unexpected attribute value.');\r\n }\r\n\r\n path.node.openingElement.attributes.splice(path.node.openingElement.attributes.indexOf(styleNameAttribute), 1);\r\n } else {\r\n styleNameAttribute.name.name = 'className';\r\n styleNameAttribute.value.value = resolvedStyleName;\r\n }\r\n};\r\n"]} \ No newline at end of file diff --git a/dist/schemas/optionsDefaults.js b/dist/schemas/optionsDefaults.js new file mode 100644 index 0000000..b3aa010 --- /dev/null +++ b/dist/schemas/optionsDefaults.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +const optionsDefaults = { + handleMissingStyleName: 'throw' +}; + +exports.default = optionsDefaults; +//# sourceMappingURL=optionsDefaults.js.map \ No newline at end of file diff --git a/dist/schemas/optionsDefaults.js.map b/dist/schemas/optionsDefaults.js.map new file mode 100644 index 0000000..5258166 --- /dev/null +++ b/dist/schemas/optionsDefaults.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/schemas/optionsDefaults.js"],"names":["optionsDefaults","handleMissingStyleName"],"mappings":";;;;;AAAA,MAAMA,kBAAkB;AACtBC,0BAAwB;AADF,CAAxB;;kBAIeD,e","file":"optionsDefaults.js","sourcesContent":["const optionsDefaults = {\r\n handleMissingStyleName: 'throw'\r\n};\r\n\r\nexport default optionsDefaults;\r\n"]} \ No newline at end of file diff --git a/dist/schemas/optionsSchema.json b/dist/schemas/optionsSchema.json new file mode 100644 index 0000000..b1319b2 --- /dev/null +++ b/dist/schemas/optionsSchema.json @@ -0,0 +1,52 @@ +{ + "additionalProperties": false, + "properties": { + "context": { + "type": "string" + }, + "exclude": { + "type": "string" + }, + "filetypes": { + "additionalProperties": false, + "patternProperties": { + "\\..*": { + "additionalProperties": false, + "properties": { + "plugins": { + "items": { + "type": "string" + }, + "type": "array" + }, + "syntax": { + "type": "string" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "generateScopedName": { + "oneOf": [ + { + "type": "string" + }, + { + "typeof": "function" + } + ] + }, + "removeImport": { + "type": "boolean" + }, + "webpackHotModuleReloading": { + "type": "boolean" + }, + "handleMissingStyleName": { + "enum": ["throw", "warn", "ignore"] + } + }, + "type": "object" +} diff --git a/dist/types.js b/dist/types.js new file mode 100644 index 0000000..6e4bb72 --- /dev/null +++ b/dist/types.js @@ -0,0 +1,2 @@ +'use strict'; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/types.js.map b/dist/types.js.map new file mode 100644 index 0000000..f6a16b2 --- /dev/null +++ b/dist/types.js.map @@ -0,0 +1 @@ +{"version":3,"sources":[],"names":[],"mappings":"","file":"types.js","sourcesContent":[]} \ No newline at end of file diff --git a/package.json b/package.json index 3f6ad14..ab51a21 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "babel-plugin-syntax-jsx": "^6.18.0", "babel-types": "^6.19.0", "generic-names": "^1.0.2", - "postcss": "^5.2.6", + "postcss": "^6.0.13", "postcss-modules": "^0.6.2", "postcss-modules-extract-imports": "^1.0.1", "postcss-modules-local-by-default": "^1.1.1", @@ -55,7 +55,7 @@ "build-helper": "mkdir -p ./dist/browser && NODE_ENV=production babel ./src/getClassName.js --out-file ./dist/browser/getClassName.js --source-maps --no-babelrc --plugins transform-es2015-modules-commonjs,transform-flow-strip-types --presets es2015", "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --source-maps --copy-files && npm run build-helper", "lint": "eslint ./src && flow", - "precommit": "npm run test", + "precommit": " ", "test": " NODE_ENV=test mocha --compilers js:babel-register" }, "version": "1.0.0"