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
this.hub is undefined in Babel traverse #11350
Comments
Hey @coderaiser! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite." |
You can wrap the parsed ast into a I admit that this workaround is not ideal as ultimately @coderaiser I think we can surely revisit this issue and see if we can re-land #5050. PR is welcome. |
@JLHwung do you mind providing an example? This code fails when my visitor uses import * as babel from '@babel/core';
// ...
const parsed = babel.parseSync(code, { filename, plugins });
const traversed = babel.traverse(parsed!, visitor); How do I wrap things in a Edit Ok, I see now, thanks. import File from '@babel/core/lib/transformation/file/file';
const _file = new File({ filename }, { code, ast: parsed }); |
@rob-myers Please don't rely on the internal file structures on import * as babel from '@babel/core';
const File = babel.File; |
ok |
Bug Report
This related to #8617
Current Behavior
@babel/parser
has a different behavior whenestree
enabled, and when not.Input Code
When
estree
disabled code withDuplicated variable declaration
throws while parsing:When
estree
mode enabled code is parsed, but can't be traversed because ofthis.hub
is undefined:Same result when instead of
estree
plugin,errorRecovery
enabled.Expected behavior/code
Would be great if in
estree
modebabel
throws while parsing and/or can throw while traversingabout
Duplicate declaration
.Environment
v7.9.4
Ubuntu
parse
,traverse
Possible Solution
I suggest to use
TypeError
, because this is what hub actually does, this way:If of course
buildError
doesn't used in development purpose to set breakpoint on error building, anywaysChrome Developer Tools
debugger already suggest similar featurepause on exceptions
(caught and uncaught).The text was updated successfully, but these errors were encountered: