Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #515 from babel/backport1
Browse files Browse the repository at this point in the history
Backport #499, #510, #475, #479
  • Loading branch information
danez committed May 10, 2017
2 parents a2c1432 + 7c56c24 commit 8c885ea
Show file tree
Hide file tree
Showing 21 changed files with 1,403 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ pp.parseExprAtom = function (refShorthandDefaultPos) {

switch (this.state.type) {
case tt._super:
if (!this.state.inMethod && !this.options.allowSuperOutsideMethod) {
if (
!this.state.inMethod &&
!this.state.inClassProperty &&
!this.options.allowSuperOutsideMethod
) {
this.raise(this.state.start, "'super' outside of function or class");
}

Expand Down Expand Up @@ -880,8 +884,9 @@ pp.parseObjectProperty = function (prop, startPos, startLoc, isPattern, refShort
}

if (!prop.computed && prop.key.type === "Identifier") {
this.checkReservedWord(prop.key.name, prop.key.start, true, true);

if (isPattern) {
this.checkReservedWord(prop.key.name, prop.key.start, true, true);
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key.__clone());
} else if (this.match(tt.eq) && refShorthandDefaultPos) {
if (!refShorthandDefaultPos.start) {
Expand Down
2 changes: 2 additions & 0 deletions src/parser/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ pp.parseClassBody = function (node) {
};

pp.parseClassProperty = function (node) {
this.state.inClassProperty = true;
if (this.match(tt.eq)) {
if (!this.hasPlugin("classProperties")) this.unexpected();
this.next();
Expand All @@ -791,6 +792,7 @@ pp.parseClassProperty = function (node) {
node.value = null;
}
this.semicolon();
this.state.inClassProperty = false;
return this.finishNode(node, "ClassProperty");
};

Expand Down
17 changes: 12 additions & 5 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint max-len: 0 */

import { types as tt } from "../tokenizer/types";
import { types as ct } from "../tokenizer/context";
import Parser from "../parser";

const primitiveTypes = [
Expand Down Expand Up @@ -1139,6 +1138,12 @@ export default function (instance) {
};
});

instance.extend("isNonstaticConstructor", function(inner) {
return function (method) {
return !this.match(tt.colon) && inner.call(this, method);
};
});

// parse type parameters for class methods
instance.extend("parseClassMethod", function (inner) {
return function (classBody, method, ...args) {
Expand Down Expand Up @@ -1386,6 +1391,12 @@ export default function (instance) {
} catch (err) {
if (err instanceof SyntaxError) {
this.state = state;

// Remove `tc.j_expr` and `tc.j_oTag` from context added
// by parsing `jsxTagStart` to stop the JSX plugin from
// messing with the tokens
this.state.context.length -= 2;

jsxError = err;
} else {
// istanbul ignore next: no such error is expected
Expand All @@ -1394,9 +1405,6 @@ export default function (instance) {
}
}

// Need to push something onto the context to stop
// the JSX plugin from messing with the tokens
this.state.context.push(ct.parenExpression);
if (jsxError != null || this.isRelational("<")) {
let arrowExpression;
let typeParameters;
Expand All @@ -1422,7 +1430,6 @@ export default function (instance) {
);
}
}
this.state.context.pop();

return inner.apply(this, args);
};
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class State {
this.inAsync =
this.inPropertyName =
this.inType =
this.inClassProperty =
this.noAnonFunctionType =
false;

Expand Down Expand Up @@ -73,6 +74,7 @@ export default class State {
inAsync: boolean;
inType: boolean;
inPropertyName: boolean;
inClassProperty: boolean;

// Labels in scope.
labels: Array<Object>;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es2015/shorthand/1/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var x = ({ const });
3 changes: 3 additions & 0 deletions test/fixtures/es2015/shorthand/1/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "const is a reserved word (1:11)"
}
1 change: 1 addition & 0 deletions test/fixtures/es2015/shorthand/2/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
({ get, this, if });
3 changes: 3 additions & 0 deletions test/fixtures/es2015/shorthand/2/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "this is a reserved word (1:8)"
}
3 changes: 3 additions & 0 deletions test/fixtures/experimental/class-properties/super/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Fails extends class { c(){} } {
c = super.c();
}
272 changes: 272 additions & 0 deletions test/fixtures/experimental/class-properties/super/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
"type": "File",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 11,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 11
},
"identifierName": "Fails"
},
"name": "Fails"
},
"superClass": {
"type": "ClassExpression",
"start": 20,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 20
},
"end": {
"line": 1,
"column": 35
}
},
"id": null,
"superClass": null,
"body": {
"type": "ClassBody",
"start": 26,
"end": 35,
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 35
}
},
"body": [
{
"type": "ClassMethod",
"start": 28,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 33
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
},
"identifierName": "c"
},
"name": "c"
},
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 31,
"end": 33,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 33
}
},
"body": [],
"directives": []
}
}
]
}
},
"body": {
"type": "ClassBody",
"start": 36,
"end": 56,
"loc": {
"start": {
"line": 1,
"column": 36
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "ClassProperty",
"start": 40,
"end": 54,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 16
}
},
"static": false,
"computed": false,
"key": {
"type": "Identifier",
"start": 40,
"end": 41,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 3
},
"identifierName": "c"
},
"name": "c"
},
"value": {
"type": "CallExpression",
"start": 44,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 15
}
},
"callee": {
"type": "MemberExpression",
"start": 44,
"end": 51,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 13
}
},
"object": {
"type": "Super",
"start": 44,
"end": 49,
"loc": {
"start": {
"line": 2,
"column": 6
},
"end": {
"line": 2,
"column": 11
}
}
},
"property": {
"type": "Identifier",
"start": 50,
"end": 51,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 13
},
"identifierName": "c"
},
"name": "c"
},
"computed": false
},
"arguments": []
}
}
]
}
}
],
"directives": []
}
}
Loading

0 comments on commit 8c885ea

Please sign in to comment.