diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0be4b468746..b50bae43be7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -38913,7 +38913,7 @@ namespace ts { } if (!container) { - if (!!getSourceFileOfNode(node).externalModuleIndicator || node.flags & NodeFlags.Ambient) { + if (!!getSourceFileOfNode(node).externalModuleIndicator || !isInJSFile(node)) { grammarErrorOnFirstToken(node, Diagnostics.A_return_statement_can_only_be_used_within_a_function_body); } return; diff --git a/tests/baselines/reference/asiReturn.errors.txt b/tests/baselines/reference/asiReturn.errors.txt new file mode 100644 index 00000000000..1cc3ec8a3c1 --- /dev/null +++ b/tests/baselines/reference/asiReturn.errors.txt @@ -0,0 +1,8 @@ +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. \ No newline at end of file diff --git a/tests/baselines/reference/fileWithNextLine3.errors.txt b/tests/baselines/reference/fileWithNextLine3.errors.txt new file mode 100644 index 00000000000..647ec722549 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.errors.txt @@ -0,0 +1,9 @@ +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. \ No newline at end of file diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt new file mode 100644 index 00000000000..48a1da7d22c --- /dev/null +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -0,0 +1,11 @@ +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) => data.data)); + \ No newline at end of file diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types index 51877e2f09d..f311c6093cf 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types @@ -6,12 +6,12 @@ return this.edit(role) >this.edit : any >this : typeof globalThis >edit : any ->role : error +>role : any .then((role: Role) => >then : any >(role: Role) => this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg) => data.data) : (role: Role) => any ->role : error +>role : Role this.roleService.add(role) >this.roleService.add(role) .then((data: ng.IHttpPromiseCallbackArg) => data.data) : any @@ -22,14 +22,14 @@ return this.edit(role) >this : typeof globalThis >roleService : any >add : any ->role : error +>role : Role .then((data: ng.IHttpPromiseCallbackArg) => data.data)); >then : any >(data: ng.IHttpPromiseCallbackArg) => data.data : (data: ng.IHttpPromiseCallbackArg) => any ->data : error +>data : ng.IHttpPromiseCallbackArg >ng : any ->data.data : error +>data.data : any >data : ng.IHttpPromiseCallbackArg >data : any diff --git a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt index 2abf07e719b..b69cab688f0 100644 --- a/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt +++ b/tests/baselines/reference/parserErrorRecovery_VariableList1.errors.txt @@ -1,8 +1,11 @@ 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 (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/ErrorRecovery/VariableLists/parserErrorRecovery_VariableList1.ts (2 errors) ==== var a, ~ !!! error TS1009: Trailing comma not allowed. - return; \ No newline at end of file + 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/parserNotRegex1.errors.txt b/tests/baselines/reference/parserNotRegex1.errors.txt index cba48155c50..63b78ce50d2 100644 --- a/tests/baselines/reference/parserNotRegex1.errors.txt +++ b/tests/baselines/reference/parserNotRegex1.errors.txt @@ -1,10 +1,13 @@ 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 (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/parserNotRegex1.ts (2 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. } \ No newline at end of file diff --git a/tests/baselines/reference/parserRegularExpression1.errors.txt b/tests/baselines/reference/parserRegularExpression1.errors.txt new file mode 100644 index 00000000000..724b8e703ea --- /dev/null +++ b/tests/baselines/reference/parserRegularExpression1.errors.txt @@ -0,0 +1,7 @@ +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. \ No newline at end of file diff --git a/tests/baselines/reference/parserReturnStatement1.errors.txt b/tests/baselines/reference/parserReturnStatement1.errors.txt new file mode 100644 index 00000000000..8c80b45c4c3 --- /dev/null +++ b/tests/baselines/reference/parserReturnStatement1.errors.txt @@ -0,0 +1,7 @@ +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. \ No newline at end of file diff --git a/tests/baselines/reference/parserReturnStatement2.errors.txt b/tests/baselines/reference/parserReturnStatement2.errors.txt new file mode 100644 index 00000000000..5f335efbeae --- /dev/null +++ b/tests/baselines/reference/parserReturnStatement2.errors.txt @@ -0,0 +1,9 @@ +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. + } \ No newline at end of file diff --git a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt new file mode 100644 index 00000000000..0532fd28d63 --- /dev/null +++ b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.errors.txt @@ -0,0 +1,16 @@ +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; + + } + + }; \ No newline at end of file diff --git a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.types b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.types index 0c6f01372ad..b7d836b0ad5 100644 --- a/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.types +++ b/tests/baselines/reference/parserStatementIsNotAMemberVariableDeclaration1.types @@ -11,8 +11,8 @@ return { // 'private' should not be considered a member variable here. private[key] = value; >private[key] = value : any ->private[key] : error ->private : error +>private[key] : any +>private : any >key : any >value : any