Skip to content

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

Open
supersteves opened this issue Sep 15, 2015 · 8 comments
Labels

Comments

@supersteves
Copy link
Contributor

java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please email [email protected] with this stack trace and repro steps (a CL# and a build target).

Unexpected variable Symbol
  Node(NAME Symbol):  [synthetic:2] :34:2
  Symbol = $jscomp.global.Symbol || {};
  Parent(ASSIGN):  [synthetic:2] :34:2
  Symbol = $jscomp.global.Symbol || {};

    at com.google.javascript.jscomp.VarCheck.visit(VarCheck.java:202)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:607)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBlockScope(NodeTraversal.java:650)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:595)
    at com.google.javascript.jscomp.NodeTraversal.traverseFunction(NodeTraversal.java:641)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:593)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseRoots(NodeTraversal.java:318)
    at com.google.javascript.jscomp.VarCheck.process(VarCheck.java:142)
    at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:285)
    at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:217)
    at com.google.javascript.jscomp.Compiler.optimize(Compiler.java:1912)
    at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:692)

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

/**
 * @type {Object}
 * @const
 */
var React = {};

/**
* @constructor
*/
React.Component = function() {};

/**
* @param {string} module
* @return {*}
*/
var require = function(module) { return {}; };

Code

goog.module("test");

let React = /** @type {React} */(require("React"));

class MyClass extends React.Component {
}

exports = MyClass;

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:

WARNING - Misplaced type annotation. Type annotations are not allowed here. Are you missing parentheses?
@MatrixFrog MatrixFrog self-assigned this Sep 15, 2015
@supersteves
Copy link
Contributor Author

Another simple case which crashes the debugger - related? Externs:

class Y {}

Code:

class X extends Y {}

Crash:

java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please email [email protected] with this stack trace and repro steps (a CL# and a build target).

Unexpected variable arguments
  Node(NAME arguments): input0:1:0
class X extends Y {}
  Parent(CALL): input0:1:0
class X extends Y {}

    at com.google.javascript.jscomp.VarCheck.visit(VarCheck.java:202)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:607)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBlockScope(NodeTraversal.java:650)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:595)
    at com.google.javascript.jscomp.NodeTraversal.traverseFunction(NodeTraversal.java:641)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:593)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:601)
    at com.google.javascript.jscomp.NodeTraversal.traverseRoots(NodeTraversal.java:318)
    at com.google.javascript.jscomp.VarCheck.process(VarCheck.java:142)
    at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:285)
    at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:217)
    at com.google.javascript.jscomp.Compiler.optimize(Compiler.java:1912)
    at com.google.javascript.jscomp.Compiler.compileInternal(Compiler.java:692)
    at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:91)
    at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:643)
    at com.google.javascript.jscomp.Compiler$2.call(Compiler.java:640)
    at com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread(CompilerExecutor.java:118)
    at com.google.javascript.jscomp.Compiler.runInCompilerThread(Compiler.java:666)
    at com.google.javascript.jscomp.Compiler.compile(Compiler.java:640)

https://closure-compiler-debugger.appspot.com/#input0%3Dclass%2520X%2520extends%2520Y%2520%257B%250A%257D%250A%26input1%26conformanceConfig%26externs%3Dclass%2520Y%2520%257B%257D%250A%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1%26MISSING_PROPERTIES%3D1

@blickly
Copy link
Contributor

blickly commented Sep 16, 2015

The second case is a dup of #1125, which I'll be pushing a fix out for today.

@supersteves
Copy link
Contributor Author

@blickly Second case indeed fixed in debugger

@MatrixFrog
Copy link
Contributor

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.

@MatrixFrog
Copy link
Contributor

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 MatrixFrog removed their assignment Oct 6, 2015
@supersteves
Copy link
Contributor Author

@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 (WARNING - Misplaced type annotation. Type annotations are not allowed here. Are you missing parentheses?) and now I can't figure out how to reproduce this in the debugger (perhaps it's fixed).

@supersteves
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants