From f6a55ebed0ef08b7d0eecf4299233ebf5839a1c9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 28 Apr 2022 08:50:25 -0700 Subject: [PATCH] No error on toplevel return in JS Turns out it's only an error in modules. It's possible to keep this error on the list of "OK for JS" errors and make the checker code stop issuing it for JS scripts only. However, I don't think the error is valuable enough to do that. Fixes #48224 --- src/compiler/program.ts | 1 - tests/baselines/reference/plainJSGrammarErrors.errors.txt | 7 +------ tests/baselines/reference/plainJSGrammarErrors.js | 3 --- tests/baselines/reference/plainJSGrammarErrors.symbols | 2 -- tests/baselines/reference/plainJSGrammarErrors.types | 2 -- tests/cases/conformance/salsa/plainJSGrammarErrors.ts | 2 -- 6 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c7f886ea311..8cacf4baa34 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -913,7 +913,6 @@ namespace ts { Diagnostics.A_rest_parameter_cannot_have_an_initializer.code, Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code, - Diagnostics.A_return_statement_can_only_be_used_within_a_function_body.code, Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code, Diagnostics.A_set_accessor_cannot_have_rest_parameter.code, Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code, diff --git a/tests/baselines/reference/plainJSGrammarErrors.errors.txt b/tests/baselines/reference/plainJSGrammarErrors.errors.txt index c49f7618bf4..ee29cb3fb3f 100644 --- a/tests/baselines/reference/plainJSGrammarErrors.errors.txt +++ b/tests/baselines/reference/plainJSGrammarErrors.errors.txt @@ -100,10 +100,9 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(202,22): error TS17012: 't tests/cases/conformance/salsa/plainJSGrammarErrors.js(203,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments tests/cases/conformance/salsa/plainJSGrammarErrors.js(204,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments tests/cases/conformance/salsa/plainJSGrammarErrors.js(205,36): error TS1325: Argument of dynamic import cannot be spread element. -tests/cases/conformance/salsa/plainJSGrammarErrors.js(207,1): error TS1108: A 'return' statement can only be used within a function body. -==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (103 errors) ==== +==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (102 errors) ==== class C { // #private mistakes q = #unbound @@ -513,8 +512,4 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(207,1): error TS1108: A 'r const spreadDynamicImport = import(...[]) ~~~~~ !!! error TS1325: Argument of dynamic import cannot be spread element. - - return - ~~~~~~ -!!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file diff --git a/tests/baselines/reference/plainJSGrammarErrors.js b/tests/baselines/reference/plainJSGrammarErrors.js index 4dcf2472ac6..2b257090ffe 100644 --- a/tests/baselines/reference/plainJSGrammarErrors.js +++ b/tests/baselines/reference/plainJSGrammarErrors.js @@ -204,8 +204,6 @@ function foo() { new.targe } const nullaryDynamicImport = import() const trinaryDynamicImport = import('1', '2', '3') const spreadDynamicImport = import(...[]) - -return //// [plainJSGrammarErrors.js] @@ -407,4 +405,3 @@ function foo() { new.targe; } const nullaryDynamicImport = import(); const trinaryDynamicImport = import('1', '2', '3'); const spreadDynamicImport = import(...[]); -return; diff --git a/tests/baselines/reference/plainJSGrammarErrors.symbols b/tests/baselines/reference/plainJSGrammarErrors.symbols index 340f1bc2a82..93506d40f82 100644 --- a/tests/baselines/reference/plainJSGrammarErrors.symbols +++ b/tests/baselines/reference/plainJSGrammarErrors.symbols @@ -465,5 +465,3 @@ const trinaryDynamicImport = import('1', '2', '3') const spreadDynamicImport = import(...[]) >spreadDynamicImport : Symbol(spreadDynamicImport, Decl(plainJSGrammarErrors.js, 204, 5)) -return - diff --git a/tests/baselines/reference/plainJSGrammarErrors.types b/tests/baselines/reference/plainJSGrammarErrors.types index 0d9a941af36..6b91c3287cb 100644 --- a/tests/baselines/reference/plainJSGrammarErrors.types +++ b/tests/baselines/reference/plainJSGrammarErrors.types @@ -624,5 +624,3 @@ const spreadDynamicImport = import(...[]) >...[] : undefined >[] : undefined[] -return - diff --git a/tests/cases/conformance/salsa/plainJSGrammarErrors.ts b/tests/cases/conformance/salsa/plainJSGrammarErrors.ts index 9697e9f8ac3..c8d1291457f 100644 --- a/tests/cases/conformance/salsa/plainJSGrammarErrors.ts +++ b/tests/cases/conformance/salsa/plainJSGrammarErrors.ts @@ -208,5 +208,3 @@ function foo() { new.targe } const nullaryDynamicImport = import() const trinaryDynamicImport = import('1', '2', '3') const spreadDynamicImport = import(...[]) - -return