Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relax check in transform plugin #255

Merged
merged 1 commit into from
Oct 19, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: relax check in transform plugin",
"packageName": "@griffel/babel-preset",
"email": "[email protected]",
"dependentChangeType": "patch"
}

This file was deleted.

5 changes: 0 additions & 5 deletions packages/babel-preset/src/transformPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ pluginTester({
};
},
},
{
title: 'errors: throws on invalid argument type',
fixture: path.resolve(fixturesDir, 'error-argument-type', 'fixture.js'),
error: /function accepts only an object as a param/,
},
{
title: 'errors: throws on invalid argument count',
fixture: path.resolve(fixturesDir, 'error-argument-count', 'fixture.js'),
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-preset/src/transformPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getDefinitionPathFromCallExpression(
functionKind: FunctionKinds,
callExpression: NodePath<t.CallExpression>,
): NodePath<t.Expression | t.SpreadElement> {
const argumentPaths = callExpression.get('arguments') as NodePath<t.Node>[];
const argumentPaths = callExpression.get('arguments');
const hasValidArguments = Array.isArray(argumentPaths) && argumentPaths.length === 1;

if (!hasValidArguments) {
Expand All @@ -41,11 +41,11 @@ function getDefinitionPathFromCallExpression(

const definitionsPath = argumentPaths[0];

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.

return definitionsPath;
}

return definitionsPath;
throw definitionsPath.buildCodeFrameError(`${functionKind}() function accepts only expressions and spreads`);
}

/**
Expand Down