{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12823","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12823/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12823/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12823/events","html_url":"https://github.com/Microsoft/TypeScript/issues/12823","id":194769528,"number":12823,"title":"code generation of imported default exports","user":{"login":"postspectacular","id":52302,"avatar_url":"https://avatars.githubusercontent.com/u/52302?v=3","gravatar_id":"","url":"https://api.github.com/users/postspectacular","html_url":"https://github.com/postspectacular","followers_url":"https://api.github.com/users/postspectacular/followers","following_url":"https://api.github.com/users/postspectacular/following{/other_user}","gists_url":"https://api.github.com/users/postspectacular/gists{/gist_id}","starred_url":"https://api.github.com/users/postspectacular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postspectacular/subscriptions","organizations_url":"https://api.github.com/users/postspectacular/orgs","repos_url":"https://api.github.com/users/postspectacular/repos","events_url":"https://api.github.com/users/postspectacular/events{/privacy}","received_events_url":"https://api.github.com/users/postspectacular/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-10T14:02:42Z","updated_at":"2016-12-11T12:04:30Z","closed_at":"2016-12-11T12:04:30Z","body":"**TypeScript Version:**  2.1.1\r\n\r\n**Code**\r\n\r\n```ts\r\nimport foo from \"./foo\";\r\nconsole.log(foo);\r\n```\r\n\r\nIn the resulting JS...\r\n\r\n**Expected behavior:**\r\n```js\r\nvar foo = require(\"./foo\").default;\r\nconsole.log(foo);\r\n```\r\n**Actual behavior:**\r\n```js\r\nvar foo_1 = require(\"./foo\");\r\nconsole.log(foo.default);\r\n```\r\n\r\nThe current code generator of imported default exports results in an inefficient duplication of `.default` property accesses (for each use of each imported default symbol) instead of doing the lookup only once as part of the `require` call. Extensive use of default imports adds to serious bloat in emitted code.\r\n\r\nOf course one can work around this and achieve the expected behavior above by manually adding another module-local redefinition, but that IMHO defies the purpose of using default exports in the first place:\r\n\r\n```ts\r\nimport * as _foo from \"./foo\";\r\nconst foo = _foo.default;\r\nconsole.log(foo);\r\n```"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/266278205","html_url":"https://github.com/Microsoft/TypeScript/issues/12823#issuecomment-266278205","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/12823","id":266278205,"user":{"login":"postspectacular","id":52302,"avatar_url":"https://avatars.githubusercontent.com/u/52302?v=3","gravatar_id":"","url":"https://api.github.com/users/postspectacular","html_url":"https://github.com/postspectacular","followers_url":"https://api.github.com/users/postspectacular/followers","following_url":"https://api.github.com/users/postspectacular/following{/other_user}","gists_url":"https://api.github.com/users/postspectacular/gists{/gist_id}","starred_url":"https://api.github.com/users/postspectacular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/postspectacular/subscriptions","organizations_url":"https://api.github.com/users/postspectacular/orgs","repos_url":"https://api.github.com/users/postspectacular/repos","events_url":"https://api.github.com/users/postspectacular/events{/privacy}","received_events_url":"https://api.github.com/users/postspectacular/received_events","type":"User","site_admin":false},"created_at":"2016-12-11T12:04:30Z","updated_at":"2016-12-11T12:04:30Z","body":"@aluanhaddad thanks for clarifying, will have to work around it then..."}}
{"actor":{"display_login":"postspectacular"}}