Skip to content

Commit

Permalink
fix(13520): disallow default exporting interface without a name
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Jul 31, 2021
1 parent d3a7cd5 commit 4ecb14a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/babel-parser/src/plugins/typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const TSErrors = makeErrorTemplates(
EmptyTypeParameters: "Type parameter list cannot be empty.",
ExpectedAmbientAfterExportDeclare:
"'export declare' must be followed by an ambient declaration.",
IdentifierExpected: "Identifier expected.",
ImportAliasHasImportType: "An import alias can not use 'import type'.",
IncompatibleModifiers: "'%0' modifier cannot be used with '%1' modifier.",
IndexSignatureHasAbstract:
Expand Down Expand Up @@ -2305,13 +2306,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// export default interface allowed in:
// https://github.com/Microsoft/TypeScript/pull/16040
if (this.state.value === "interface") {
const result = this.tsParseDeclaration(
this.startNode(),
this.state.value,
true,
);

if (result) return result;
if (this.lookahead().type === tt.name) {
const result = this.tsParseDeclaration(
this.startNode(),
this.state.value,
true,
);
if (result) return result;
} else {
this.raise(this.state.start, TSErrors.IdentifierExpected);
this.next();
}
}

return super.parseExportDefaultExpression();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default interface {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "File",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"errors": [
"SyntaxError: Identifier expected. (1:26)"
],
"program": {
"type": "Program",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportDefaultDeclaration",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"exportKind": "value",
"declaration": {
"type": "ObjectExpression",
"start":25,"end":27,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":27}},
"properties": []
}
}
],
"directives": []
}
}

0 comments on commit 4ecb14a

Please sign in to comment.