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

createTypeAnnotationBasedOnTypeof(type) throwing error when not supposed to #6880

Closed
gchamon opened this issue Nov 22, 2017 · 6 comments
Closed
Labels
awaiting reply outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@gchamon
Copy link

gchamon commented Nov 22, 2017

Ran into an issue using babel with gulp, where the mentioned function was throwing the following error:

events.js:160                                   
      throw er; // Unhandled 'error' event      
      ^                                         
Error: /home/gchamon/WayCarbon/projetos/eclimas/src/app/admin/factorBuilder/libs/nerdamer.core.js: Invalid typeof value                                                                                
at Object.createTypeAnnotationBasedOnTypeof (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-types/lib/flow.js:106:11)                                                                 
at inferAnnotationFromBinaryExpression (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/inferer-reference.js:136:12)                                       
at getConditionalAnnotation (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/inferer-reference.js:171:18)                                                 
at getTypeAnnotationBindingConstantViolations (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/inferer-reference.js:45:18)                                
at NodePath.exports.default (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/inferer-reference.js:17:14)                                                   
at NodePath._getTypeAnnotation (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/index.js:64:20)                                                            
at NodePath.getTypeAnnotation (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/inference/index.js:31:19)
at Identifier (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-plugin-minify-simplify/lib/index.js:509:18)
at NodePath._call (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/context.js:76:18)
at NodePath.call (/home/gchamon/WayCarbon/projetos/eclimas/node_modules/babel-traverse/lib/path/context.js:48:17)  

upon investigation, I decided to verify what was actually inside type by modifying the function createTypeAnnotationBasedOnTypeof(type) inside flow.js, altering the error throwing line to:

throw new Error(`Invalid typeof value: '${type}' (${typeof type})`);

which now, interestingly, yelds the error:

Invalid typeof value: 'undefined ' (string)

Notice the blank space after undefined. Trying a hack to make it work, replacing " " to "" as in:

type = type.replace(" ", "");

gulp runs fine alright. What is going on?

@babel-bot
Copy link
Collaborator

Hey @gchamon! 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.

@nicolo-ribaudo
Copy link
Member

Which is the code that causes babel to throw? A starting point for a proper fix would be to understand why there is that space.

@gchamon
Copy link
Author

gchamon commented Nov 22, 2017

That goes without saying, but following the traceback we can see that the error is raised in the scope of the babel-traverse -> minify then all the way to babel-type so it is all self contained inside babel-maintained code, which means that even if I pinpointed the source of the issue I wouldn't be able to correct it myself without diverging from this repo.

Anyway, the provided "hack" works and everything minifies as expected (too well actually, I need to figure out how to make it respect angular names so it doesn't break the framework) I just wanted to know if there was another workaround that doesn't involve modifying third party code, because we don't have the resources to maintain modified code

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Nov 23, 2017

Can you provide an example of code which, when run trought Babel with the babel-minify preset, generates that error? "undefind " should never be passed to that function, so the bug is somewhere else. Without reproducing the error, it is impossible to know where it exactly is.

@gchamon
Copy link
Author

gchamon commented Sep 12, 2018

I am sorry I did not update you guys on the issue. I believe the issue was with our code, some typo an ex-employee left and nobody knew what was going on. Really sorry to waste your time on it. This should be closed and, hopefully, forgotten.

@existentialism
Copy link
Member

@gchamon thanks for the update! let us know if you run into it again!

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Dec 12, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Dec 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting reply outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants