Throw error if TypeScript class has empty implements (#9292)
This commit is contained in:
parent
9803253363
commit
03022d169e
@ -905,11 +905,21 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return this.finishNode(node, "TSTypeAssertion");
|
||||
}
|
||||
|
||||
tsParseHeritageClause(): $ReadOnlyArray<N.TsExpressionWithTypeArguments> {
|
||||
return this.tsParseDelimitedList(
|
||||
tsParseHeritageClause(
|
||||
descriptor: string,
|
||||
): $ReadOnlyArray<N.TsExpressionWithTypeArguments> {
|
||||
const originalStart = this.state.start;
|
||||
|
||||
const delimitedList = this.tsParseDelimitedList(
|
||||
"HeritageClauseElement",
|
||||
this.tsParseExpressionWithTypeArguments.bind(this),
|
||||
);
|
||||
|
||||
if (!delimitedList.length) {
|
||||
this.raise(originalStart, `'${descriptor}' list cannot be empty.`);
|
||||
}
|
||||
|
||||
return delimitedList;
|
||||
}
|
||||
|
||||
tsParseExpressionWithTypeArguments(): N.TsExpressionWithTypeArguments {
|
||||
@ -930,7 +940,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
node.id = this.parseIdentifier();
|
||||
node.typeParameters = this.tsTryParseTypeParameters();
|
||||
if (this.eat(tt._extends)) {
|
||||
node.extends = this.tsParseHeritageClause();
|
||||
node.extends = this.tsParseHeritageClause("extends");
|
||||
}
|
||||
const body: N.TSInterfaceBody = this.startNode();
|
||||
body.body = this.tsInType(this.tsParseObjectTypeMembers.bind(this));
|
||||
@ -1879,7 +1889,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
node.superTypeParameters = this.tsParseTypeArguments();
|
||||
}
|
||||
if (this.eatContextual("implements")) {
|
||||
node.implements = this.tsParseHeritageClause();
|
||||
node.implements = this.tsParseHeritageClause("implements");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
packages/babel-parser/test/fixtures/typescript/class/extends-empty/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/typescript/class/extends-empty/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
interface foo extends {
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/class/extends-empty/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/class/extends-empty/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'extends' list cannot be empty. (1:22)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/typescript/class/extends-implements-empty/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/typescript/class/extends-implements-empty/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
class Foo extends Bar implements {
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/class/extends-implements-empty/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/class/extends-implements-empty/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'implements' list cannot be empty. (1:33)"
|
||||
}
|
||||
2
packages/babel-parser/test/fixtures/typescript/class/implements-empty/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/typescript/class/implements-empty/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
class Foo implements {
|
||||
}
|
||||
3
packages/babel-parser/test/fixtures/typescript/class/implements-empty/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/typescript/class/implements-empty/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'implements' list cannot be empty. (1:21)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/typescript/type-arguments/empty/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/typescript/type-arguments/empty/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
foo<>()
|
||||
99
packages/babel-parser/test/fixtures/typescript/type-arguments/empty/output.json
vendored
Normal file
99
packages/babel-parser/test/fixtures/typescript/type-arguments/empty/output.json
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"interpreter": null,
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "CallExpression",
|
||||
"start": 0,
|
||||
"end": 7,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 7
|
||||
}
|
||||
},
|
||||
"callee": {
|
||||
"type": "Identifier",
|
||||
"start": 0,
|
||||
"end": 3,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "foo"
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"arguments": [],
|
||||
"typeParameters": {
|
||||
"type": "TSTypeParameterInstantiation",
|
||||
"start": 3,
|
||||
"end": 5,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"params": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user