Skip to content
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

Fix parsing typescript bodiless methods with the estree plugin also enabled #9890

Merged
merged 1 commit into from Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -220,7 +220,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isAsync,
isConstructor,
allowsDirectSuper,
"MethodDefinition",
"ClassMethod",
true,
);
if (method.typeParameters) {
Expand Down Expand Up @@ -293,13 +293,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
isAsync,
isConstructor,
allowDirectSuper,
"FunctionExpression",
type,
inClassScope,
);
funcNode.type = "FunctionExpression";
delete funcNode.kind;
// $FlowIgnore
node.value = funcNode;

type = type === "ClassMethod" ? "MethodDefinition" : type;
return this.finishNode(node, type);
}

Expand Down
@@ -0,0 +1,3 @@
abstract class TSAbstractClass {
abstract foo(name: string): boolean;
}
@@ -0,0 +1,3 @@
{
"plugins": ["typescript", "estree"]
}
@@ -0,0 +1,219 @@
{
"type": "File",
"start": 0,
"end": 73,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 73,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 73,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"abstract": true,
"id": {
"type": "Identifier",
"start": 15,
"end": 30,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 30
},
"identifierName": "TSAbstractClass"
},
"name": "TSAbstractClass"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 31,
"end": 73,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 3,
"column": 1
}
},
"body": [
{
"type": "MethodDefinition",
"start": 35,
"end": 71,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 38
}
},
"abstract": true,
"static": false,
"key": {
"type": "Identifier",
"start": 44,
"end": 47,
"loc": {
"start": {
"line": 2,
"column": 11
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "foo"
},
"name": "foo"
},
"computed": false,
"kind": "method",
"value": {
"type": "FunctionExpression",
"start": 47,
"end": 71,
"loc": {
"start": {
"line": 2,
"column": 14
},
"end": {
"line": 2,
"column": 38
}
},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [
{
"type": "Identifier",
"start": 48,
"end": 60,
"loc": {
"start": {
"line": 2,
"column": 15
},
"end": {
"line": 2,
"column": 27
},
"identifierName": "name"
},
"name": "name",
"typeAnnotation": {
"type": "TSTypeAnnotation",
"start": 52,
"end": 60,
"loc": {
"start": {
"line": 2,
"column": 19
},
"end": {
"line": 2,
"column": 27
}
},
"typeAnnotation": {
"type": "TSStringKeyword",
"start": 54,
"end": 60,
"loc": {
"start": {
"line": 2,
"column": 21
},
"end": {
"line": 2,
"column": 27
}
}
}
}
}
],
"returnType": {
"type": "TSTypeAnnotation",
"start": 61,
"end": 70,
"loc": {
"start": {
"line": 2,
"column": 28
},
"end": {
"line": 2,
"column": 37
}
},
"typeAnnotation": {
"type": "TSBooleanKeyword",
"start": 63,
"end": 70,
"loc": {
"start": {
"line": 2,
"column": 30
},
"end": {
"line": 2,
"column": 37
}
}
}
}
}
}
]
}
}
]
}
}