Skip to content

Commit 650c056

Browse files
sandersnDanielRosenwassertypescript-bot
authored
No error on toplevel return in JS (microsoft#48874)
* 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 microsoft#48224 * Restore 'return' statement. * Update Baselines and/or Applied Lint Fixes * Re-add missing baselines * No error in toplevel script files Only issue "no top-level return" error for modules, not scripts, regardless of whether it's TS or JS. * Keep Disallowing return in ambient locations * Allow toplevel return only in non-ESM JS files * Add test of toplevel return in JS script * Revert "Add test of toplevel return in JS script" This reverts commit 2a6dec4. * Revert "Allow toplevel return only in non-ESM JS files" This reverts commit 6291ae3. * Revert "Keep Disallowing return in ambient locations" This reverts commit 714ea8e. * Revert "No error in toplevel script files" This reverts commit 2056e13. * restore orphaned baseline Co-authored-by: Daniel Rosenwasser <[email protected]> Co-authored-by: TypeScript Bot <[email protected]>
1 parent 46e8306 commit 650c056

6 files changed

+1
-297
lines changed

src/compiler/program.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,6 @@ namespace ts {
913913
Diagnostics.A_rest_parameter_cannot_have_an_initializer.code,
914914
Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list.code,
915915
Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma.code,
916-
Diagnostics.A_return_statement_can_only_be_used_within_a_function_body.code,
917916
Diagnostics.A_return_statement_cannot_be_used_inside_a_class_static_block.code,
918917
Diagnostics.A_set_accessor_cannot_have_rest_parameter.code,
919918
Diagnostics.A_set_accessor_must_have_exactly_one_parameter.code,

tests/baselines/reference/emitDecoratorMetadata_isolatedModules.errors.txt

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/baselines/reference/emitDecoratorMetadata_isolatedModules.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

tests/baselines/reference/emitDecoratorMetadata_isolatedModules.symbols

Lines changed: 0 additions & 72 deletions
This file was deleted.

tests/baselines/reference/emitDecoratorMetadata_isolatedModules.types

Lines changed: 0 additions & 74 deletions
This file was deleted.

tests/baselines/reference/plainJSGrammarErrors.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(202,22): error TS17012: 't
100100
tests/cases/conformance/salsa/plainJSGrammarErrors.js(203,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
101101
tests/cases/conformance/salsa/plainJSGrammarErrors.js(204,30): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
102102
tests/cases/conformance/salsa/plainJSGrammarErrors.js(205,36): error TS1325: Argument of dynamic import cannot be spread element.
103-
tests/cases/conformance/salsa/plainJSGrammarErrors.js(207,1): error TS1108: A 'return' statement can only be used within a function body.
104103

105104

106-
==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (103 errors) ====
105+
==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (102 errors) ====
107106
class C {
108107
// #private mistakes
109108
q = #unbound
@@ -515,6 +514,4 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(207,1): error TS1108: A 'r
515514
!!! error TS1325: Argument of dynamic import cannot be spread element.
516515

517516
return
518-
~~~~~~
519-
!!! error TS1108: A 'return' statement can only be used within a function body.
520517

0 commit comments

Comments
 (0)