-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Crash in compiler when trying to use externs to define CommonJS loaded React #1145
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
Comments
Another simple case which crashes the debugger - related? Externs: class Y {} Code: class X extends Y {} Crash:
|
The second case is a dup of #1125, which I'll be pushing a fix out for today. |
@blickly Second case indeed fixed in debugger |
You need the default externs (or rather, there are a few core externs you need, like Array and Symbol, otherwise nothing will work). I have it on my TODO list to make sure the error here is much clearer rather than a crash. |
I believe it's now fairly difficult to forget the default externs when using the command-line, so this should only happen if you go out of your way to pass unusual flags, or specifically uncheck the default externs box on the debugger. I also don't see a good way to fix this (hard-coding checks for built-ins like Array is pretty hacky) so marking these crashes as P3. |
@MatrixFrog My bad, I was trying to isolate the problem by unchecking that. In practice I do use default externs so I don't need a fix. Also I've dropped the original ambition of using runtime CommonJS "require()" to load React because I couldn't get it to work ( |
Update: having revisited this with ES6 modules I now realise it was my JSX transformation that was stripping the () needed in a cast. This probably helps identify the original crash, and entirely explains the misplaced type annotation error. See #1782 |
Test case:
https://closure-compiler-debugger.appspot.com/#input0%3Dgoog.module(%2522test%2522)%253B%250A%250A%250Alet%2520React%2520%253D%2520%252F**%2520%2540type%2520%257BReact%257D%2520*%252F(require(%2522React%2522))%253B%250A%250Aclass%2520MyClass%2520extends%2520React.Component%2520%257B%250A%257D%250A%250Aexports%2520%253D%2520MyClass%253B%250A%26input1%26conformanceConfig%26externs%3D%252F**%250A%2520*%2520%2540type%2520%257BObject%257D%250A%2520*%2520%2540const%250A%2520*%252F%250Avar%2520React%2520%253D%2520%257B%257D%253B%250A%250A%252F**%250A*%2520%2540constructor%250A*%252F%250AReact.Component%2520%253D%2520function()%2520%257B%257D%253B%250A%250A%252F**%250A*%2520%2540param%2520%257Bstring%257D%2520module%250A*%2520%2540return%2520%257B*%257D%250A*%252F%250Avar%2520require%2520%253D%2520function(module)%2520%257B%2520return%2520%257B%257D%253B%2520%257D%253B%250A%26refasterjs-template%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1
Externs
Code
See discussion:
https://groups.google.com/forum/#!topic/closure-compiler-discuss/-r7XK8j5yfA
When I run it locally I don't get this crash, instead I get:
The text was updated successfully, but these errors were encountered: