mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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.
This commit is contained in:
@@ -38913,7 +38913,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!container) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
|
||||
if (!!getSourceFileOfNode(node).externalModuleIndicator) {
|
||||
grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -913,6 +913,7 @@ 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,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
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 (4 errors) ====
|
||||
==== tests/cases/compiler/ambientWithStatements.ts (3 errors) ====
|
||||
declare module M {
|
||||
break;
|
||||
~~~~~
|
||||
@@ -20,8 +19,6 @@ 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;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
tests/cases/compiler/asiReturn.ts(2,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/compiler/asiReturn.ts (1 errors) ====
|
||||
// This should be an error for using a return outside a function, but ASI should work properly
|
||||
return
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
@@ -1,9 +0,0 @@
|
||||
tests/cases/compiler/fileWithNextLine3.ts(3,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/compiler/fileWithNextLine3.ts (1 errors) ====
|
||||
// Note: there is a nextline (0x85) between the return and the
|
||||
// 0. It should be counted as a space and should not trigger ASI
|
||||
return
0;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
@@ -1,11 +0,0 @@
|
||||
tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (1 errors) ====
|
||||
return this.edit(role)
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
.then((role: Role) =>
|
||||
this.roleService.add(role)
|
||||
.then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data));
|
||||
|
||||
@@ -6,12 +6,12 @@ return this.edit(role)
|
||||
>this.edit : any
|
||||
>this : typeof globalThis
|
||||
>edit : any
|
||||
>role : any
|
||||
>role : error
|
||||
|
||||
.then((role: Role) =>
|
||||
>then : any
|
||||
>(role: Role) => this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data) : (role: Role) => any
|
||||
>role : Role
|
||||
>role : error
|
||||
|
||||
this.roleService.add(role)
|
||||
>this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data) : any
|
||||
@@ -22,14 +22,14 @@ return this.edit(role)
|
||||
>this : typeof globalThis
|
||||
>roleService : any
|
||||
>add : any
|
||||
>role : Role
|
||||
>role : error
|
||||
|
||||
.then((data: ng.IHttpPromiseCallbackArg<Role>) => data.data));
|
||||
>then : any
|
||||
>(data: ng.IHttpPromiseCallbackArg<Role>) => data.data : (data: ng.IHttpPromiseCallbackArg<Role>) => any
|
||||
>data : ng.IHttpPromiseCallbackArg<Role>
|
||||
>data : error
|
||||
>ng : any
|
||||
>data.data : any
|
||||
>data.data : error
|
||||
>data : ng.IHttpPromiseCallbackArg<Role>
|
||||
>data : any
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(1,6): error TS1009: Trailing comma not allowed.
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts(2,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (2 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (1 errors) ====
|
||||
var a,
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
return;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
return;
|
||||
@@ -1,13 +1,10 @@
|
||||
tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts(1,7): error TS2304: Cannot find name 'a'.
|
||||
tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts(3,5): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts (2 errors) ====
|
||||
==== tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts (1 errors) ====
|
||||
if (a.indexOf(-(4/3))) // We should not get a regex here because of the / in the comment.
|
||||
~
|
||||
!!! error TS2304: Cannot find name 'a'.
|
||||
{
|
||||
return true;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/RegularExpressions/parserRegularExpression1.ts (1 errors) ====
|
||||
return /(#?-?\d*\.\d\w*%?)|(@?#?[\w-?]+%?)/g;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
@@ -1,7 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement1.ts (1 errors) ====
|
||||
return;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
@@ -1,9 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement2.ts(2,4): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/Statements/ReturnStatements/parserReturnStatement2.ts (1 errors) ====
|
||||
{
|
||||
return;
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserStatementIsNotAMemberVariableDeclaration1.ts (1 errors) ====
|
||||
return {
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
"set": function (key, value) {
|
||||
|
||||
// 'private' should not be considered a member variable here.
|
||||
private[key] = value;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -11,8 +11,8 @@ return {
|
||||
// 'private' should not be considered a member variable here.
|
||||
private[key] = value;
|
||||
>private[key] = value : any
|
||||
>private[key] : any
|
||||
>private : any
|
||||
>private[key] : error
|
||||
>private : error
|
||||
>key : any
|
||||
>value : any
|
||||
|
||||
|
||||
@@ -100,9 +100,10 @@ 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 (102 errors) ====
|
||||
==== tests/cases/conformance/salsa/plainJSGrammarErrors.js (103 errors) ====
|
||||
class C {
|
||||
// #private mistakes
|
||||
q = #unbound
|
||||
@@ -514,4 +515,6 @@ tests/cases/conformance/salsa/plainJSGrammarErrors.js(205,36): error TS1325: Arg
|
||||
!!! error TS1325: Argument of dynamic import cannot be spread element.
|
||||
|
||||
return
|
||||
~~~~~~
|
||||
!!! error TS1108: A 'return' statement can only be used within a function body.
|
||||
|
||||
Reference in New Issue
Block a user