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

Error when trying to parse es6 js file with import statement #16

Open
seveves opened this issue Dec 7, 2016 · 2 comments
Open

Error when trying to parse es6 js file with import statement #16

seveves opened this issue Dec 7, 2016 · 2 comments

Comments

@seveves
Copy link

seveves commented Dec 7, 2016

This is the error when parsing this file using "closure2ts Clustering.js Clustering.d.ts". Of course this happens with every file containing import statements :)

C:\Users\sevef\Code\vis\lib\network\modules>closure2ts Clustering.js Clustering.d.ts

C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:3385
throw error;
^
Error: Line 2: Unexpected token
at ErrorHandler.constructError (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:3390:22)
at ErrorHandler.createError (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:3408:27)
at Parser.unexpectedTokenError (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:542:39)
at Parser.tolerateUnexpectedToken (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:555:42)
at Parser.parseStatementListItem (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:1801:31)
at Parser.parseProgram (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:3054:29)
at Object.parse (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\node_modules\esprima\dist\esprima.js:117:24)
at Object.jsdoc (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\definition-generator\src\parser.js:412:24)
at symbols (C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\definition-generator\src\finder.js:30:59)
at C:\Users\sevef\AppData\Roaming\npm\node_modules\typescript-closure-tools\definition-generator\src\finder.js:70:21

@seveves
Copy link
Author

seveves commented Dec 7, 2016

I know this has something to do with the esprima parsing infrastructure and it seems it doesn't like the "import" and "export" statements but maybe you have experienced this issue before and can help me.
Btw it works with the esprima online parser.

Otherwise I'm going to create an issue at the esprima project.

Kind regards

@seveves
Copy link
Author

seveves commented Dec 7, 2016

I've debugged the code and I think the problem is that there is a difference parsing a "script" or a "module". You have to set 'sourceType' to "script" or "module" in the esprima.parse options, f.e. (end of parser.js):
var tree = esprima.parse(code, { attachComment: true, sourceType; 'script' });

When setting it to module my file will be parsed without any errors.

Do you want me to create a PR for this or do you fix it on your own?

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

1 participant