Skip to content

Commit

Permalink
Keep Disallowing return in ambient locations
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn committed May 2, 2022
1 parent 2056e13 commit 714ea8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38913,7 +38913,7 @@ namespace ts {
}

if (!container) {
if (!!getSourceFileOfNode(node).externalModuleIndicator) {
if (!!getSourceFileOfNode(node).externalModuleIndicator || node.flags & NodeFlags.Ambient) {
grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
}
return;
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/ambientWithStatements.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
tests/cases/compiler/ambientWithStatements.ts(2,5): error TS1036: Statements are not allowed in ambient contexts.
tests/cases/compiler/ambientWithStatements.ts(3,5): error TS1104: A 'continue' statement can only be used within an enclosing iteration statement.
tests/cases/compiler/ambientWithStatements.ts(11,5): error TS1108: A 'return' statement can only be used within a function body.
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'.


==== tests/cases/compiler/ambientWithStatements.ts (3 errors) ====
==== tests/cases/compiler/ambientWithStatements.ts (4 errors) ====
declare module M {
break;
~~~~~
Expand All @@ -19,6 +20,8 @@ tests/cases/compiler/ambientWithStatements.ts(25,5): error TS2410: The 'with' st
1;
L: var y;
return;
~~~~~~
!!! error TS1108: A 'return' statement can only be used within a function body.
switch (x) {
case 1:
break;
Expand Down

0 comments on commit 714ea8e

Please sign in to comment.