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

@babel/types. Wrong arity while executing callExpression #11169

Closed
1 task done
fforres opened this issue Feb 25, 2020 · 5 comments
Closed
1 task done

@babel/types. Wrong arity while executing callExpression #11169

fforres opened this issue Feb 25, 2020 · 5 comments
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@fforres
Copy link

fforres commented Feb 25, 2020

Bug Report

  • I would like to work on a fix!

Current Behavior
Been looking into running a code-mod for our codebase.
Our codebase is running Typescript through Babel.
We are looking into extracting some types of some function calls to be reused in other parts of said codemod, but we cannot seem to be able to create a callExpression with more than 2 arguments.

On @babel/types it shoes a conflicting doc. https://babeljs.io/docs/en/babel-types#callexpression

Input Code

Expected behavior/code
I can execute t.callExpression to create an expression with types for their arguments or parameters.

https://babeljs.io/docs/en/babel-types#callexpression

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

Added a simple code-sandbox here (I can work on a more complex environment if needed)

Environment

- Babel version(s):

    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.8.4",
    "@babel/types": "^7.8.3",
    "@babel/plugin-proposal-class-properties": "^7.1.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.3.4",
    "@babel/plugin-proposal-optional-chaining": "^7.6.0",
    "@babel/polyfill": "7.0.0",
    "@babel/preset-env": "^7.1.0",
    "@babel/preset-react": "^7.0.0",
    "@babel/preset-typescript": "^7.8.3",
    "@babel/register": "^7.8.3",

- Node/npm version: v12.13.1 (using yarn)
- OS:  OSX 10.14.6 (18G3020)
- Monorepo: No
- How you are using Babel: `cli` + `register`

Additional context/Screenshots

Actual error when running our code-mod

(node:48825) UnhandledPromiseRejectionWarning: Error: CallExpression: Too many arguments passed. Received 5 but can receive no more than 2
    at builder (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/types/lib/builders/builder.js:21:11)
    at Object.callExpression (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/types/lib/builders/generated/index.js:282:31)
    at CallExpression (/Users/fforres/BREX/credit_card/product/dashboard/code_mods/styled_components/mod.ts:156:30)
    at NodePath._call (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/path/context.js:40:17)
    at NodePath.visit (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/path/context.js:88:12)
    at TraversalContext.visitQueue (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/context.js:118:16)
    at TraversalContext.visitSingle (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/context.js:90:19)
    at TraversalContext.visit (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/context.js:146:19)
    at Function.traverse.node (/Users/fforres/BREX/credit_card/product/dashboard/node_modules/@babel/traverse/lib/index.js:94:17)
@babel-bot
Copy link
Collaborator

Hey @fforres! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@nicolo-ribaudo
Copy link
Member

Type builders only have parameters for common/standard attributes. If you need to set more, you can use Object.assign:

const expression = Object.assign(t.callExpression(
  t.memberExpression(t.identifier("styled"), t.identifier("asd")),
  [],
), {
  typeArguments: [],
  optional: false,
  ...
});

@JLHwung
Copy link
Contributor

JLHwung commented Feb 26, 2020

The signature of t.callExpression only accepts 2 argument:

t.callExpression(callee, arguments)

In https://babeljs.io/docs/en/babel-types#callexpression the other properties listed below the signature are not extra arguments, but the shape of the CallExpression AST node, which is returned from t.callExpression, so you can assign typeArguments, optional, etc. to the AST node.

We may need to clarify that in the babel types doc.

@jridgewell
Copy link
Member

CallExpression AST node docs may be out of date. optional is only on OptionalCallExpression.

@nicolo-ribaudo
Copy link
Member

It's @babel/types which is outdated. Fixed in a PR opened 5 mins ago 😛

#11172

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

5 participants