Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

support .withConfig() method #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const {
isStyled,
isHelper,
isStyledImport,
hasAttrsCall,
getAttrsObject,
hasMethodsCall,
getMethodsObject,
isExtendCall
} = require('../utils/styled')
const {
Expand Down Expand Up @@ -54,8 +54,8 @@ const processStyledComponentsFile = (ast, absolutePath, options) => {
? isHelper(node, importedNames)
: isHelper(node, [importedNames[options.importName]])
const processedNode = { ...node }
if (hasAttrsCall(node)) {
processedNode.tag = getAttrsObject(node)
while (hasMethodsCall(processedNode)) {
processedNode.tag = getMethodsObject(processedNode)
}
if (
!helper &&
Expand Down
12 changes: 6 additions & 6 deletions src/utils/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ const isStyledCall = (node, styledVariableName) =>
/**
* Check if it has a .attrs postfix which we in that case handle specially
*/
const hasAttrsCall = node =>
const hasMethodsCall = node =>
// Check that it's a function call
node.tag &&
node.tag.callee &&
// Check that the last member of the call is attrs
node.tag.callee.property &&
node.tag.callee.property.name === 'attrs'
(node.tag.callee.property.name === 'attrs' || node.tag.callee.property.name === 'withConfig')

// We don't need the checks here as they were checked in hasAttrsCall
const getAttrsObject = node => node.tag.callee.object
// We don't need the checks here as they were checked in hasMethodsCall
const getMethodsObject = node => node.tag.callee.object

/**
* Check if something is a styled component call
Expand Down Expand Up @@ -85,6 +85,6 @@ exports.isStyledShorthand = isStyledShorthand
exports.isStyledCall = isStyledCall
exports.isStyled = isStyled
exports.isHelper = isHelper
exports.hasAttrsCall = hasAttrsCall
exports.getAttrsObject = getAttrsObject
exports.hasMethodsCall = hasMethodsCall
exports.getMethodsObject = getMethodsObject
exports.isExtendCall = isExtendCall
2 changes: 1 addition & 1 deletion test/fixtures/simple/identify-styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Image1 = styled.img.attrs({ src: 'url' })`
}
`;

const Image2 = styled(Image1).attrs({ src: 'newUrl' })`
const Image2 = styled(Image1).withConfig({ shouldForwardProp: prop => prop }).attrs({ src: 'url' })`
bad-selector {
color: red;
}
Expand Down