Skip to content

Conversation

@layershifter
Copy link
Member

Fixes a problem from microsoft/fluentui#25216.

if (!definitionsPath.isObjectExpression()) {
throw definitionsPath.buildCodeFrameError(`${functionKind}() function accepts only an object as a param`);
}

The check that we have currently is too strict and breaks legit cases:

ERR! ERR! SyntaxError: /mnt/vss/_work/1/s/packages/react-components/react-button/src/components/Button/useButtonStyles.ts: makeResetStyles() function accepts only an object as a param
ERR! ERR!   13 | var buttonSpacingSmall = '3px';
ERR! ERR!   14 | var buttonSpacingMedium = '5px';
ERR! ERR! > 15 | var useBaseClassName = makeResetStyles(Object.assign({
ERR! ERR!      |                                        ^
ERR! ERR!   16 |   alignItems: 'center',
ERR! ERR!   17 |   boxSizing: 'border-box',
ERR! ERR!   18 |   display: 'inline-flex',

This PR simplifies it to match returned types. The test was removed as I can't build a compilable code to throw there: t.callExpression accepts Array<Expression | SpreadElement | JSXNamespacedName | ArgumentPlaceholder>, but I can't imagine/create a case when JSXNamespacedName | ArgumentPlaceholder will be arguments.

@github-actions
Copy link

📊 Bundle size report

🤖 This report was generated against a119921ad567daea43419a84c86e405af42f6de4

@layershifter layershifter marked this pull request as ready for review October 18, 2022 16:27
@layershifter layershifter requested a review from a team as a code owner October 18, 2022 16:27

if (!definitionsPath.isObjectExpression()) {
throw definitionsPath.buildCodeFrameError(`${functionKind}() function accepts only an object as a param`);
if (definitionsPath.isExpression() || definitionsPath.isSpreadElement()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a check for those cases you don't imagine happening... JSXNamespacedName | ArgumentPlaceholder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that it's a futureproof way: if something else will start to appear with new versions of Babel - we will not handle it.

@layershifter layershifter merged commit fe93c5f into microsoft:main Oct 19, 2022
@layershifter layershifter deleted the fix/remove-check branch October 19, 2022 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants