ericmckean / traceur-compiler

Automatically exported from code.google.com/p/traceur-compiler
Apache License 2.0
0 stars 0 forks source link

Function Declarations are expressions #161

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In syntax/trees/ParseTree.js we read

    isMemberExpression: function() {
      switch (this.type) {
        // PrimaryExpression
        case ParseTreeType.THIS_EXPRESSION:
        case ParseTreeType.CLASS_EXPRESSION:
        case ParseTreeType.SUPER_EXPRESSION:
        case ParseTreeType.IDENTIFIER_EXPRESSION:
        case ParseTreeType.LITERAL_EXPRESSION:
        case ParseTreeType.ARRAY_LITERAL_EXPRESSION:
        case ParseTreeType.OBJECT_LITERAL_EXPRESSION:
        case ParseTreeType.PAREN_EXPRESSION:
        case ParseTreeType.QUASI_LITERAL_EXPRESSION:
        // FunctionExpression
        case ParseTreeType.FUNCTION_DECLARATION:
Ouch. 

The statement-like construct
function foo() {}
gets reported as an expression. Since there is no FUNCTION_EXPRESSION, I 
presume that 
var foo = function() {}
is marked incorrectly as a FUNCTION_DECLARATION but reports correctly as an 
expression.

I guess a fix would involve re-classifying all FUNCTION_DECLARATION as 
FUNCTION_EXPRESSION nodes then re-re-classifying FUNCTION_EXPRESSION nodes the 
arrive in statement contexts like blocks.  

I'll try a workaround in my code first. 

Original issue reported on code.google.com by johnjbar...@chromium.org on 1 Nov 2012 at 11:34

GoogleCodeExporter commented 9 years ago
I've thought about this issue too. I think it would simplify certain things to 
have two different parse trees for them. My concern is that it might make some 
things more complicated but overall I think it is worth doing.

Original comment by arv@chromium.org on 2 Nov 2012 at 1:42

GoogleCodeExporter commented 9 years ago
Did you fix this in 
http://code.google.com/p/traceur-compiler/source/detail?r=3ad989a19130f60746cff7
8c4bca33d125da0548
?

Original comment by johnjbar...@chromium.org on 1 Dec 2012 at 4:23

GoogleCodeExporter commented 9 years ago
Indeeed, this was fixed.

Original comment by arv@chromium.org on 3 Dec 2012 at 5:34