Skip to content

Commit 714ea8e

Browse files
committed
Keep Disallowing return in ambient locations
1 parent 2056e13 commit 714ea8e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38913,7 +38913,7 @@ namespace ts {
3891338913
}
3891438914

3891538915
if (!container) {
38916-
if (!!getSourceFileOfNode(node).externalModuleIndicator) {
38916+
if (!!getSourceFileOfNode(node).externalModuleIndicator || node.flags & NodeFlags.Ambient) {
3891738917
grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
3891838918
}
3891938919
return;

tests/baselines/reference/ambientWithStatements.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
tests/cases/compiler/ambientWithStatements.ts(2,5): error TS1036: Statements are not allowed in ambient contexts.
22
tests/cases/compiler/ambientWithStatements.ts(3,5): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
3+
tests/cases/compiler/ambientWithStatements.ts(11,5): error TS1108: A 'return' statement can only be used within a function body.
34
tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.
45

56

6-
==== tests/cases/compiler/ambientWithStatements.ts (3 errors) ====
7+
==== tests/cases/compiler/ambientWithStatements.ts (4 errors) ====
78
declare module M {
89
break;
910
~~~~~
@@ -19,6 +20,8 @@ tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' st
1920
1;
2021
L: var y;
2122
return;
23+
~~~~~~
24+
!!! error TS1108: A 'return' statement can only be used within a function body.
2225
switch (x) {
2326
case 1:
2427
break;

0 commit comments

Comments
 (0)