{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/24610313","id":24610313,"diff_hunk":"@@ -3991,63 +3999,146 @@ module ts {\n                 emitEnd(node);\r\n             }\r\n \r\n-            function emitImportDeclaration(node: ImportDeclaration) {\r\n-                var emitImportDeclaration = resolver.isReferencedImportDeclaration(node);\r\n-\r\n-                if (!emitImportDeclaration) {\r\n-                    // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when\r\n-                    // - current file is not external module\r\n-                    // - import declaration is top level and target is value imported by entity name\r\n-                    emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node);\r\n+            function emitRequire(moduleName: Expression) {\r\n+                if (moduleName.kind === SyntaxKind.StringLiteral) {\r\n+                    write(\"require(\");\r\n+                    emitStart(moduleName);\r\n+                    emitLiteral(<LiteralExpression>moduleName);\r\n+                    emitEnd(moduleName);\r\n+                    emitToken(SyntaxKind.CloseParenToken, moduleName.end);\r\n+                    write(\";\");\r\n                 }\r\n+                else {\r\n+                    write(\"require();\");\r\n+                }\r\n+            }\r\n \r\n-                if (emitImportDeclaration) {\r\n-                    if (isExternalModuleImportDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) {\r\n-                        if (node.flags & NodeFlags.Export) {\r\n-                            writeLine();\r\n-                            emitLeadingComments(node);\r\n-                            emitStart(node);\r\n-                            emitModuleMemberName(node);\r\n-                            write(\" = \");\r\n-                            emit(node.name);\r\n-                            write(\";\");\r\n-                            emitEnd(node);\r\n-                            emitTrailingComments(node);\r\n-                        }\r\n-                    }\r\n-                    else {\r\n-                        writeLine();\r\n+            function emitImportAssignment(node: Declaration, moduleName: Expression) {\r\n+                if (!(node.flags & NodeFlags.Export)) write(\"var \");\r\n+                emitModuleMemberName(<Declaration>node);\r\n+                write(\" = \");\r\n+                emitRequire(moduleName);\r\n+            }\r\n+\r\n+            function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) {\r\n+                var info = getExternalImportInfo(node);\r\n+                if (info) {\r\n+                    var declarationNode = info.declarationNode;\r\n+                    var namedImports = info.namedImports;\r\n+                    if (compilerOptions.module !== ModuleKind.AMD) {\r\n                         emitLeadingComments(node);\r\n                         emitStart(node);\r\n-                        if (!(node.flags & NodeFlags.Export)) write(\"var \");\r\n-                        emitModuleMemberName(node);\r\n-                        write(\" = \");\r\n-                        if (isInternalModuleImportDeclaration(node)) {\r\n-                            emit(node.moduleReference);\r\n+                        var moduleName = getImportedModuleName(node);\r\n+                        if (declarationNode) {\r\n+                            if (!(declarationNode.flags & NodeFlags.Export)) write(\"var \");\r\n+                            emitModuleMemberName(declarationNode);\r","path":"src/compiler/emitter.ts","position":278,"original_position":278,"commit_id":"3b39e9f4a153d9d9c08d27ed141c075c856faef2","original_commit_id":"e8cc2bf5f7f5feba2606e240bc217f3da9f4ad43","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"body":"Ah, because this is used for both definitions and references","created_at":"2015-02-12T19:14:08Z","updated_at":"2015-02-12T19:14:08Z","html_url":"https://github.com/Microsoft/TypeScript/pull/1983#discussion_r24610313","pull_request_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/24610313"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/1983#discussion_r24610313"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983","id":28892052,"html_url":"https://github.com/Microsoft/TypeScript/pull/1983","diff_url":"https://github.com/Microsoft/TypeScript/pull/1983.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/1983.patch","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1983","number":1983,"state":"open","locked":false,"title":"Support ES6 import declarations end-to-end","user":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"body":"This PR extends @sheetalkamat's import parsing with end-to-end binding, checking, and emit. Remaining work to finish ES6 modules includes:\r\n\r\n* Support `-module ES6` (currently we only emit down-level ES3/ES5 code).\r\n* ~~Rewrite imported bindings to reference properties on module instance (see below).~~\r\n* Parsing of ES6 `export` declarations.\r\n* Support `export default` in checker.\r\n* Support `export { x, y }` syntax in binder and checker.\r\n* Support `export xxx from \"foo\"` in checker and emitter.\r\n\r\nCurrently, an import of the form\r\n```typescript\r\nimport { x, y } from \"foo\";\r\n```\r\ngenerates\r\n```javascript\r\nvar _a = require(\"foo\");\r\nvar x = _a.x;\r\nvar y = _a.y;\r\n```\r\nThis isn't ideal when modules circularly reference each other. Instead, we need to rewrite references to `x` and `y` to `_a.x` and `_a.y` similarly to how we rewrite references to exported module members.\r\n\r\nEDIT: Named imports are now rewritten to property references on the imported module instance.","created_at":"2015-02-09T01:58:10Z","updated_at":"2015-02-12T19:14:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3437c99541abb602be6ff5d0eb701efd50de84dc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983/commits","review_comments_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983/comments","review_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1983/comments","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/3b39e9f4a153d9d9c08d27ed141c075c856faef2","head":{"label":"Microsoft:es6Import","ref":"es6Import","sha":"3b39e9f4a153d9d9c08d27ed141c075c856faef2","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/{number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-02-12T19:06:10Z","pushed_at":"2015-02-12T19:03:51Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":513125,"stargazers_count":3447,"watchers_count":3447,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":325,"mirror_url":null,"open_issues_count":504,"forks":325,"open_issues":504,"watchers":3447,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"f2c98ba95eebfd544aa17d479ed574d59bd7bef1","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":20929025,"name":"TypeScript","full_name":"Microsoft/TypeScript","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/TypeScript","description":"TypeScript is a superset of JavaScript that compiles to clean JavaScript output.","fork":false,"url":"https://api.github.com/repos/Microsoft/TypeScript","forks_url":"https://api.github.com/repos/Microsoft/TypeScript/forks","keys_url":"https://api.github.com/repos/Microsoft/TypeScript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/TypeScript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/TypeScript/teams","hooks_url":"https://api.github.com/repos/Microsoft/TypeScript/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/TypeScript/events","assignees_url":"https://api.github.com/repos/Microsoft/TypeScript/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/TypeScript/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/TypeScript/tags","blobs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/TypeScript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/TypeScript/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/TypeScript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/TypeScript/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/TypeScript/languages","stargazers_url":"https://api.github.com/repos/Microsoft/TypeScript/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/TypeScript/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/TypeScript/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/TypeScript/subscription","commits_url":"https://api.github.com/repos/Microsoft/TypeScript/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/TypeScript/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/{number}","contents_url":"https://api.github.com/repos/Microsoft/TypeScript/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/TypeScript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/TypeScript/merges","archive_url":"https://api.github.com/repos/Microsoft/TypeScript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/TypeScript/downloads","issues_url":"https://api.github.com/repos/Microsoft/TypeScript/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/TypeScript/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/TypeScript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/TypeScript/releases{/id}","created_at":"2014-06-17T15:28:39Z","updated_at":"2015-02-12T19:06:10Z","pushed_at":"2015-02-12T19:03:51Z","git_url":"git://github.com/Microsoft/TypeScript.git","ssh_url":"git@github.com:Microsoft/TypeScript.git","clone_url":"https://github.com/Microsoft/TypeScript.git","svn_url":"https://github.com/Microsoft/TypeScript","homepage":"http://www.typescriptlang.org","size":513125,"stargazers_count":3447,"watchers_count":3447,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":325,"mirror_url":null,"open_issues_count":504,"forks":325,"open_issues":504,"watchers":3447,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983"},"html":{"href":"https://github.com/Microsoft/TypeScript/pull/1983"},"issue":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/1983"},"comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/issues/1983/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/TypeScript/pulls/1983/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/TypeScript/statuses/3b39e9f4a153d9d9c08d27ed141c075c856faef2"}}}}