Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically bound this not being generated within switch statements as of 1.8.0-dev.20151110 #5637

Closed
myitcv opened this issue Nov 12, 2015 · 2 comments · Fixed by #5639
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@myitcv
Copy link

myitcv commented Nov 12, 2015

This is as minimal an example as I have for now (tsc version and tsconfig.json details at the bottom of this issue)

class A {
    doIt(x: Array<string>): void {
        x.forEach((v) => {
            switch(v) {
                case "test": console.log(this);
            }
        });
    }
}

Comparing the transpiled output from 1.8.0-dev.20151109 and 1.8.0-dev.20151110 we see:

--- app.js.1.8.0-dev.20151109   2015-11-12 16:02:01.064780316 +0000
+++ app.js.1.8.0-dev.20151110   2015-11-12 16:05:07.933061708 +0000
@@ -2,10 +2,9 @@
     function A() {
     }
     A.prototype.doIt = function (x) {
-        var _this = this;
         x.forEach(function (v) {
             switch (v) {
-                case "test": console.log(_this);
+                case "test": console.log(this);
             }
         });
     };

This feels like a bug to me... but I might have missed something?

Thanks

message TS6029: Version 1.8.0-dev.20151110

{
  "compilerOptions": {
    "declaration": false,
    "jsx": "react",
    "module": "system",
    "noImplicitAny": true,
    "noLib": true,
    "outDir": "../dist/",
    "removeComments": false,
    "rootDir": ".",
    "sourceMap": true,
    "target": "es5"
  }
}
@vladima vladima added the Bug A bug in TypeScript label Nov 12, 2015
@vladima vladima self-assigned this Nov 12, 2015
@vladima
Copy link
Contributor

vladima commented Nov 12, 2015

pinging @mhegazy

@vladima vladima added the Fixed A PR has been merged for this issue label Nov 12, 2015
@myitcv
Copy link
Author

myitcv commented Nov 12, 2015

@vladima thanks very much

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants