Skip to content

Commit 228ddde

Browse files
author
Andy Hanson
committed
Ensure that checkGrammarModuleElementContext reliably returns true when there is bad grammar.
1 parent 60ab007 commit 228ddde

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17706,9 +17706,11 @@ namespace ts {
1770617706
}
1770717707

1770817708
function checkGrammarModuleElementContext(node: Statement, errorMessage: DiagnosticMessage): boolean {
17709-
if (node.parent.kind !== SyntaxKind.SourceFile && node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.ModuleDeclaration) {
17710-
return grammarErrorOnFirstToken(node, errorMessage);
17709+
const isInAppropriateContext = node.parent.kind === SyntaxKind.SourceFile || node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.ModuleDeclaration;
17710+
if (!isInAppropriateContext) {
17711+
grammarErrorOnFirstToken(node, errorMessage);
1771117712
}
17713+
return !isInAppropriateContext;
1771217714
}
1771317715

1771417716
function checkExportSpecifier(node: ExportSpecifier) {
@@ -17749,7 +17751,7 @@ namespace ts {
1774917751
checkExpressionCached(node.expression);
1775017752
}
1775117753

17752-
checkExternalModuleExports(<SourceFile | ModuleDeclaration>container);
17754+
checkExternalModuleExports(container);
1775317755

1775417756
if (node.isExportEquals && !isInAmbientContext(node)) {
1775517757
if (modulekind === ModuleKind.ES6) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tests/cases/compiler/exportInFunction.ts(3,1): error TS1005: '}' expected.
2+
3+
4+
==== tests/cases/compiler/exportInFunction.ts (1 errors) ====
5+
function f() {
6+
export = 0;
7+
8+
9+
!!! error TS1005: '}' expected.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [exportInFunction.ts]
2+
function f() {
3+
export = 0;
4+
5+
6+
//// [exportInFunction.js]
7+
function f() {
8+
export = 0;
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
function f() {
2+
export = 0;

0 commit comments

Comments
 (0)