question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@babel/types. Wrong arity while executing callExpression

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
nicolo-ribaudocommented, Feb 26, 2020

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,
  ...
});
0reactions
nicolo-ribaudocommented, Feb 26, 2020

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

https://github.com/babel/babel/pull/11172

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to run babel : "cannot find module @babel/core"
This works as expected and desired. However, when I run 'gulp' I get "Error: cannot find module 'babel-core'. So the issue must be...
Read more >
babel/types
AST Node CallExpression shape: callee : Expression | V8IntrinsicIdentifier (required); arguments : Array<Expression | SpreadElement | JSXNamespacedName | ...
Read more >
@babel/types | Yarn - Package Manager
Intro. Babel is a tool that helps you write code in the latest version of JavaScript. When your supported environments don't support certain...
Read more >
Babel issue running npm run dev after upgrade to Mix
I have an old Laravel App which I updated to Laravel 5.8. I removed all old resources files, package-lock.json, yarn.lock and gulp files....
Read more >
@babel/template - NPM Package Overview - Socket - Socket.dev
#12689 fix: throw error when accessing private method without a getter (@fedeci) ... babel-helper-get-function-arity , babel-helper-hoist-variables ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found