Keep Disallowing return in ambient locations

This commit is contained in:
Nathan Shively-Sanders
2022-05-02 11:18:00 -07:00
parent 2056e13d52
commit 714ea8e524
2 changed files with 5 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;
~~~~~
@@ -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;