Skip to content

Strict mode runtime error without warning #7122

@ghost

Description

With the following tsconfig.json:

{
    "compilerOptions": {
        "target": "es5",
        "module": "amd"
    }
}

The following file:

if( true ) {
    function foo() {}
}

export = foo;

Compiles with no errors or warnings, and emits:

define(["require", "exports"], function (require, exports) {
    "use strict";
    if (true) {
        function foo() {
        }
    }
    return foo;
});

This, however, results in a runtime error in Firefox, because in strict mode, function declarations may not appear within if blocks.

I believe this should cause a compiler error, or at very least, a warning.

This caused an issue on our production website today. When we updated our TypeScript compiler, our code, which was working without "use strict", stopped working (without any warning or build issues). I'm currently trying to make sure nothing else broke because of "use strict", but the lack of warnings makes finding these issues difficult.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions