Skip to content

Commit

Permalink
Don't throw for invalid super usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 31, 2019
1 parent 2743376 commit 43f7bcd
Show file tree
Hide file tree
Showing 9 changed files with 722 additions and 11 deletions.
6 changes: 5 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Expand Up @@ -885,7 +885,11 @@ export default class ExpressionParser extends LValParser {
!this.match(tt.bracketL) &&
!this.match(tt.dot)
) {
this.unexpected();
this.raise(
node.start,
"super can only be used with function calls (i.e. super()) or " +
"in property accesses (i.e. super.prop or super[prop])",
);
}

return this.finishNode(node, "Super");
Expand Down

This file was deleted.

@@ -0,0 +1,211 @@
{
"type": "File",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"errors": [
"SyntaxError: super can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]) (3:4)"
],
"program": {
"type": "Program",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "A"
},
"name": "A"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 5,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 12,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 4,
"column": 3
}
},
"static": false,
"key": {
"type": "Identifier",
"start": 12,
"end": 13,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "x"
},
"name": "x"
},
"computed": false,
"kind": "method",
"id": null,
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 17,
"end": 37,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 4,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 23,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 14
}
},
"expression": {
"type": "BinaryExpression",
"start": 23,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 13
}
},
"left": {
"type": "Super",
"start": 23,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 4
},
"end": {
"line": 3,
"column": 9
}
}
},
"operator": "-",
"right": {
"type": "NumericLiteral",
"start": 31,
"end": 32,
"loc": {
"start": {
"line": 3,
"column": 12
},
"end": {
"line": 3,
"column": 13
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
}
],
"directives": []
}
}
]
}
}
],
"directives": []
}
}

This file was deleted.

@@ -0,0 +1,69 @@
{
"type": "File",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"errors": [
"SyntaxError: super is only allowed in object methods and classes (1:0)",
"SyntaxError: super can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop]) (1:0)"
],
"program": {
"type": "Program",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
},
"expression": {
"type": "Super",
"start": 0,
"end": 5,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 5
}
}
}
}
],
"directives": []
}
}
@@ -1,4 +1,3 @@
{
"plugins": ["optionalChaining"],
"throws": "Unexpected token (3:20)"
"plugins": ["optionalChaining"]
}

0 comments on commit 43f7bcd

Please sign in to comment.