fix(parser): throw error with wrong typescript 'export declare' (#12684)

This commit is contained in:
Federico Ciardi
2021-01-27 05:51:12 +01:00
committed by GitHub
parent 9907bd86c9
commit fbfd1b2aa6
7 changed files with 90 additions and 2 deletions

View File

@@ -74,6 +74,8 @@ const TSErrors = Object.freeze({
EmptyHeritageClauseType: "'%0' list cannot be empty.",
EmptyTypeArguments: "Type argument list cannot be empty.",
EmptyTypeParameters: "Type parameter list cannot be empty.",
ExpectedAmbientAfterExportDeclare:
"'export declare' must be followed by an ambient declaration.",
IndexSignatureHasAbstract:
"Index signatures cannot have the 'abstract' modifier",
IndexSignatureHasAccessibility:
@@ -2281,6 +2283,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// "export declare" is equivalent to just "export".
const isDeclare = this.eatContextual("declare");
if (
isDeclare &&
(this.isContextual("declare") || !this.shouldParseExportDeclaration())
) {
throw this.raise(
this.state.start,
TSErrors.ExpectedAmbientAfterExportDeclare,
);
}
let declaration: ?N.Declaration;
if (this.match(tt.name)) {