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

ES6 import/export declaration building fails #206

Closed
gcazaciuc opened this issue Aug 5, 2015 · 5 comments
Closed

ES6 import/export declaration building fails #206

gcazaciuc opened this issue Aug 5, 2015 · 5 comments

Comments

@gcazaciuc
Copy link

I have the following declaration and I'm trying to create a simple ES6 import:

astBuilder.importDeclaration(
[astBuilder.importSpecifier( astBuilder.identifier("test"), astBuilder.identifier("test") )], astBuilder.literal(modulePath)
);

However, this fails with:

AssertionError: no value or default function given for field "id" of ImportSpecifier("imported": Identifier, "local": Identifier)
at add node_modules/ast-types/lib/types.js:541:28)
at node_modules/ast-types/lib/types.js:563:17
at Array.forEach (native)
at Object.defineProperty.value as importSpecifier

Tried also similar approaches with importDefaultSpecifier but got the same result.

This used to work without any issues in previous versions of recast.

I'm using the latest version published on NPM for recast

@gcazaciuc
Copy link
Author

It seems that if i comment out the line "require("./def/babel");" in node_modules/ast-types/main.js the code works as it used to and the import declarations are properly generated.

@gcazaciuc
Copy link
Author

The same issue and error occurs also for:
return b.exportDeclaration(
false,
b.identifier("Login"),
[b.exportSpecifier( b.identifier(exp.symb), b.identifier(exp.symb) ) ]
);

@gcazaciuc gcazaciuc changed the title ES6 import declaration building fails ES6 import/export declaration building fails Aug 5, 2015
@benjamn
Copy link
Owner

benjamn commented Aug 7, 2015

Commenting out require("./def/babel") is exactly the right solution, in principle. I want ast-types to handle as many AST formats as it reasonably can, and ImportSpecifier and ExportSpecifier are two cases where def/esprima.js and def/babel.js disagree on the structure of the same types.

Longer-term, I want to make it easier to instantiate ast-types with only def/esprima.js or def/babel.js and not both, but doing that right requires some bigger changes to ast-types that I haven't quite figured out. Roughly it means allowing users to set recast.types to an arbitrary ast-types implementation, and making it possible to set recast.types = require("ast-types").load("def/esprima.js").

In the meantime, I'm still trying to come up with a good temporary solution.

benjamn added a commit to benjamn/ast-types that referenced this issue Aug 7, 2015
This is a temporary workaround for
benjamn/recast#206 until something along the
lines of #57 is implemented.
@benjamn
Copy link
Owner

benjamn commented Aug 7, 2015

Ok, I think this should be fixed by benjamn/ast-types@a4cd3e9, which is part of ast-types 0.8.8, which is what recast 0.10.27 depends on.

@benjamn benjamn closed this as completed Aug 7, 2015
@marcioj
Copy link

marcioj commented Aug 10, 2015

I'm hitting this issue when using the importDefaultSpecifier. I think it's related with this issue.

When evaluating b.importDeclaration([b.importDefaultSpecifier( b.identifier("test") )], b.literal('test')), it throws:

AssertionError: no value or default function given for field "id" of ImportDefaultSpecifier("local": Identifier | null)
    at add (/home/marcio/workspace/javascript/ember-watson/node_modules/recast/node_modules/ast-types/lib/types.js:540:28)
    at /home/marcio/workspace/javascript/ember-watson/node_modules/recast/node_modules/ast-types/lib/types.js:562:17
    at Array.forEach (native)
    at Object.defineProperty.value [as importDefaultSpecifier] (/home/marcio/workspace/javascript/ember-watson/node_modules/recast/node_modules/ast-types/lib/types.js:561:41)
    at repl:1:24
    at REPLServer.defaultEval (repl.js:132:27)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)

divanutq added a commit to divanutq/ast-types that referenced this issue Aug 1, 2024
This is a temporary workaround for
benjamn/recast#206 until something along the
lines of benjamn/ast-types#57 is implemented.
citiranom2w added a commit to citiranom2w/ast-types that referenced this issue Aug 4, 2024
This is a temporary workaround for
benjamn/recast#206 until something along the
lines of benjamn/ast-types#57 is implemented.
adriaticaz9 added a commit to adriaticaz9/ast-types that referenced this issue Aug 26, 2024
This is a temporary workaround for
benjamn/recast#206 until something along the
lines of benjamn/ast-types#57 is implemented.
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