UNPKG

@dr.pogodin/babel-plugin-react-css-modules

Version:

Transforms styleName to className using compile time CSS module resolution.

33 lines 1.06 kB
import * as BabelTypes from '@babel/types'; import { ObjectExpression } from '@babel/types'; /** * Creates an AST representation of an InputObjectType shape object. */ const createObjectExpression = (types, object) => { const properties = []; Object.keys(object).forEach(name => { const value = object[name]; let newValue; if (!types.isAnyTypeAnnotation(value)) { switch (typeof value) { case 'boolean': newValue = types.booleanLiteral(value); break; case 'object': newValue = createObjectExpression(types, value); break; case 'string': newValue = types.stringLiteral(value); break; case 'undefined': return; default: throw new TypeError(`Unexpected type: ${typeof value}`); } } properties.push(types.objectProperty(types.stringLiteral(name), newValue)); }); return types.objectExpression(properties); }; export default createObjectExpression; //# sourceMappingURL=createObjectExpression.js.map