exportSpecifier builder and probably others are broken in ^0.14.0
jedwards1211 opened this issue · comments
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.
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?
I've got this problem as well
what is the best way to fix it? downgrade for now?
is there a changelog for this?
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.
where is a good place to add these regressions tests?
You can use the .from
function as a workaround for it
j.exportSpecifier.from({
exported: j.identifier('something'),
local: j.identifier('something'), // Optional
})