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

exportSpecifier builder and probably others are broken in ^0.14.0 #425

Open
jedwards1211 opened this issue Oct 6, 2020 · 5 comments
Open

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Oct 6, 2020

I don't fully understand what's supposed to happen when a node type is defined in two places (esprima and es6) but it seems to be causing problems for exportSpecifier:

> var t = require('ast-types').builders
undefined
> t.exportSpecifier()
Uncaught:
Error: no value or default function given for field "exported" of ExportSpecifier("id": Identifier | null, "name": Identifier | null)
    at addParam (/Users/andy/temp/node_modules/ast-types/lib/types.js:443:27)
    at /Users/andy/temp/node_modules/ast-types/lib/types.js:477:21
    at Array.forEach (<anonymous>)
    at Object.builder [as exportSpecifier] (/Users/andy/temp/node_modules/ast-types/lib/types.js:475:46)
> t.exportSpecifier(t.identifier('foo'), t.identifier('bar'))
Uncaught:
Error: no value or default function given for field "exported" of ExportSpecifier("id": Identifier | null, "name": Identifier | null)
    at addParam (/Users/andy/temp/node_modules/ast-types/lib/types.js:443:27)
    at /Users/andy/temp/node_modules/ast-types/lib/types.js:477:21
    at Array.forEach (<anonymous>)
    at Object.builder [as exportSpecifier] (/Users/andy/temp/node_modules/ast-types/lib/types.js:475:46)

Can't reproduce this issue in 0.13.4.

I noticed that field names id and name come from the esprima defs, whereas the field name exported comes from the es6 defs.

@jedwards1211
Copy link
Contributor Author

jedwards1211 commented Oct 6, 2020

Oh I see now what the problem is: in 0.13.4, ExportSpecifier was declared in the babel defs which come after esprima.

But ExportSpecifier was moved to the es6 defs in 0.14.0, which come before esprima.

There's probably a problem with some of the other defs that got moved. Seems like the ordering is tricky. Should all the es6+ defs be moved after esprima?

@jedwards1211 jedwards1211 changed the title t.exportSpecifier doesn't work in ^0.14.0 exportSpecifier builder and probably others are broken in ^0.14.0 Oct 6, 2020
@sibelius
Copy link

sibelius commented Nov 4, 2020

I've got this problem as well

what is the best way to fix it? downgrade for now?

is there a changelog for this?

@jedwards1211
Copy link
Contributor Author

I downgraded for the time being.

If you look at https://github.com/benjamn/ast-types/blob/master/main.ts, you can see how you could copy this code into your own bootstrapper and tweak the available defs/ordering -- assuming you're not using a tool like jscodeshift which imports the main module.

@sibelius
Copy link

sibelius commented Nov 5, 2020

where is a good place to add these regressions tests?

@fersilva16
Copy link

You can use the .from function as a workaround for it

j.exportSpecifier.from({
  exported: j.identifier('something'),
  local: j.identifier('something'), // Optional
})

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

No branches or pull requests

3 participants