Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Address reviews

Address reviews
  • Loading branch information
sosukesuzuki committed Feb 8, 2021
1 parent c1b6e46 commit 7d1e3d8
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
6 changes: 2 additions & 4 deletions packages/babel-parser/src/parser/util.js
Expand Up @@ -90,10 +90,8 @@ export default class UtilParser extends Tokenizer {
);
}

hasPrecedingLineBreak(): boolean {
return lineBreak.test(
this.input.slice(this.state.lastTokEnd, this.state.start),
);
hasPrecedingLineBreak(state: State = this.state): boolean {
return lineBreak.test(this.input.slice(state.lastTokEnd, state.start));
}

// TODO
Expand Down
35 changes: 20 additions & 15 deletions packages/babel-parser/src/plugins/typescript/index.js
Expand Up @@ -2848,27 +2848,32 @@ export default (superClass: Class<Parser>): Class<Parser> =>
tsParseAbstractDeclaration(
node: any,
): N.ClassDeclaration | N.TsInterfaceDeclaration {
const isClass = this.match(tt._class);
if (!isClass && !this.isContextual("interface")) {
this.unexpected(null, tt._class);
}
node.abstract = true;
if (isClass) {
if (this.match(tt._class)) {
node.abstract = true;
return this.parseClass(
(node: N.ClassDeclaration),
/* isStatement */ true,
/* optionalId */ false,
);
} else {
} else if (this.isContextual("interface")) {
// for invalid abstract interface
this.raise(
node.start,
TSErrors.NonClassMethodPropertyHasAbstractModifer,
);
this.next();
return this.tsParseInterfaceDeclaration(
(node: N.TsInterfaceDeclaration),
);

// To avoid
// abstract interface
// Foo {}
if (!this.hasPrecedingLineBreak(this.lookahead())) {
node.abstract = true;
this.raise(
node.start,
TSErrors.NonClassMethodPropertyHasAbstractModifer,
);
this.next();
return this.tsParseInterfaceDeclaration(
(node: N.TsInterfaceDeclaration),
);
}
} else {
this.unexpected(null, tt._class);
}
}
};
@@ -0,0 +1,2 @@
abstract interface
Foo {}
@@ -0,0 +1,50 @@
{
"type": "File",
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":6}},
"errors": [
"SyntaxError: Missing semicolon (1:8)",
"SyntaxError: Missing semicolon (2:3)"
],
"program": {
"type": "Program",
"start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":6}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}},
"expression": {
"type": "Identifier",
"start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8},"identifierName":"abstract"},
"name": "abstract"
}
},
{
"type": "ExpressionStatement",
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18}},
"expression": {
"type": "Identifier",
"start":9,"end":18,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":18},"identifierName":"interface"},
"name": "interface"
}
},
{
"type": "ExpressionStatement",
"start":19,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}},
"expression": {
"type": "Identifier",
"start":19,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3},"identifierName":"Foo"},
"name": "Foo"
}
},
{
"type": "BlockStatement",
"start":23,"end":25,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":6}},
"body": [],
"directives": []
}
],
"directives": []
}
}

0 comments on commit 7d1e3d8

Please sign in to comment.