{"action":"created","comment":{"url":"https://api.github.com/repos/google/closure-compiler/pulls/comments/41440557","id":41440557,"diff_hunk":"@@ -0,0 +1,78 @@\n+/*\n+ * Copyright 2015 The Closure Compiler Authors.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.google.javascript.jscomp;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.javascript.rhino.IR;\n+import com.google.javascript.rhino.Node;\n+\n+/**\n+ * Replicates the effect of ClosureBundler in whitespace-only mode and wraps goog.modules\n+ * in goog.loadModule calls. See comment block below.\n+ */\n+public class WhitespaceWrapGoogModules implements HotSwapCompilerPass {\n+\n+  private final AbstractCompiler compiler;\n+\n+  WhitespaceWrapGoogModules(AbstractCompiler compiler) {\n+    this.compiler = compiler;\n+  }\n+\n+  @Override\n+  public void process(Node externs, Node root) {\n+    for (Node c = root.getFirstChild(); c != null; c = c.getNext()) {\n+      Preconditions.checkState(c.isScript());\n+      hotSwapScript(c, null);\n+    }\n+  }\n+\n+  @Override\n+  public void hotSwapScript(Node scriptRoot, Node originalRoot) {\n+    if (!NodeUtil.isModuleFile(scriptRoot)) return;\n+\n+    // As per ClosureBundler:\n+    /*\n+      // add the prefix on the first line so the line numbers aren't affected.\n+      out.append(\n+          \"goog.loadModule(function(exports) {\"\n+          + \"'use strict';\");\n+      append(out, Mode.NORMAL, contents);\n+      out.append(\n+          \"\\n\" // terminate any trailing single line comment.\n+          + \";\" // terminate any trailing expression.\n+          + \"return exports;});\\n\");\n+      appendSourceUrl(out, Mode.NORMAL);\n+     */\n+\n+    Node block = IR.block();\n+    block.addChildToBack(IR.exprResult(IR.string(\"use strict\"))); // needs to be explicit, to match ClosureBundler\n+\n+    Node loadMod = IR.exprResult(IR.call(\n+        IR.getprop(IR.name(\"goog\"), IR.string(\"loadModule\")),\n+        IR.function(IR.name(\"\"), IR.paramList(IR.name(\"exports\")), block)))\n+        .srcrefTree(scriptRoot);\n+\n+    if (scriptRoot.hasChildren()) {\n+      block.addChildrenToBack(scriptRoot.removeChildren());\n+    }\n+    block.addChildToBack(IR.returnNode(IR.name(\"exports\")).srcrefTree(scriptRoot));\n+    \n+    scriptRoot.removeChildren();","path":"src/com/google/javascript/jscomp/WhitespaceWrapGoogModules.java","position":73,"original_position":73,"commit_id":"9cb070cdc63624e7b57d53a440dadeb45182e3ef","original_commit_id":"9cb070cdc63624e7b57d53a440dadeb45182e3ef","user":{"login":"blickly","id":36416,"avatar_url":"https://avatars.githubusercontent.com/u/36416?v=3","gravatar_id":"","url":"https://api.github.com/users/blickly","html_url":"https://github.com/blickly","followers_url":"https://api.github.com/users/blickly/followers","following_url":"https://api.github.com/users/blickly/following{/other_user}","gists_url":"https://api.github.com/users/blickly/gists{/gist_id}","starred_url":"https://api.github.com/users/blickly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blickly/subscriptions","organizations_url":"https://api.github.com/users/blickly/orgs","repos_url":"https://api.github.com/users/blickly/repos","events_url":"https://api.github.com/users/blickly/events{/privacy}","received_events_url":"https://api.github.com/users/blickly/received_events","type":"User","site_admin":false},"body":"This looks redundant, since the children have already been removed.","created_at":"2015-10-07T20:15:07Z","updated_at":"2015-10-07T20:15:07Z","html_url":"https://github.com/google/closure-compiler/pull/1123#discussion_r41440557","pull_request_url":"https://api.github.com/repos/google/closure-compiler/pulls/1123","_links":{"self":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/comments/41440557"},"html":{"href":"https://github.com/google/closure-compiler/pull/1123#discussion_r41440557"},"pull_request":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/1123"}}},"pull_request":{"url":"https://api.github.com/repos/google/closure-compiler/pulls/1123","id":44524535,"html_url":"https://github.com/google/closure-compiler/pull/1123","diff_url":"https://github.com/google/closure-compiler/pull/1123.diff","patch_url":"https://github.com/google/closure-compiler/pull/1123.patch","issue_url":"https://api.github.com/repos/google/closure-compiler/issues/1123","number":1123,"state":"open","locked":false,"title":"New pass WhitespaceWrapGoogModules in specialist \"always pre-check\" phase (fixes #611) [rebased]","user":{"login":"supersteves","id":10280734,"avatar_url":"https://avatars.githubusercontent.com/u/10280734?v=3","gravatar_id":"","url":"https://api.github.com/users/supersteves","html_url":"https://github.com/supersteves","followers_url":"https://api.github.com/users/supersteves/followers","following_url":"https://api.github.com/users/supersteves/following{/other_user}","gists_url":"https://api.github.com/users/supersteves/gists{/gist_id}","starred_url":"https://api.github.com/users/supersteves/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/supersteves/subscriptions","organizations_url":"https://api.github.com/users/supersteves/orgs","repos_url":"https://api.github.com/users/supersteves/repos","events_url":"https://api.github.com/users/supersteves/events{/privacy}","received_events_url":"https://api.github.com/users/supersteves/received_events","type":"User","site_admin":false},"body":"Rebased version of https://github.com/google/closure-compiler/pull/1094 with redundant reverted commits removed.\r\n\r\nCopied from original PR:\r\n\r\n> I predict this will be rejected since it is arguable that the WHITESPACE_ONLY mode should mean just that. However my argument is that goog.modules are unusable without this (#611), therefore it is forgiveable.\r\n\r\n> For a large codebase, you need to be able to develop rapidly without waiting for the ~ 40 second compile time we're currently seeing. Whitespace only mode drops this to ~2 seconds.\r\n\r\n> Also I'm adding a new pass phase \"always pre-check\" (which happens always, even in whitespace only mode) immediately prior to the \"checks\" phase (which only happens in simple or advanced mode). Even more debatable! I first tried using a custom pass in the options (see reverted commits), but I don't have the Compiler instance yet (needed for compiler.reportCodeChange()) when I build the options in my external Java compiler front-end. If you don't like this, I could find a way to do it using custom passes, but that's not going to help other users as much.\r\n\r\n> Currently WhitespaceWrapGoogModules is opt-in, but should be made default in WHITESPACE_ONLY once approved.\r\n\r\n\r\n","created_at":"2015-09-09T08:52:13Z","updated_at":"2015-10-07T20:15:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c0f59a2e3ee53f5b740187b7ad3dd421f180e875","assignee":{"login":"blickly","id":36416,"avatar_url":"https://avatars.githubusercontent.com/u/36416?v=3","gravatar_id":"","url":"https://api.github.com/users/blickly","html_url":"https://github.com/blickly","followers_url":"https://api.github.com/users/blickly/followers","following_url":"https://api.github.com/users/blickly/following{/other_user}","gists_url":"https://api.github.com/users/blickly/gists{/gist_id}","starred_url":"https://api.github.com/users/blickly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blickly/subscriptions","organizations_url":"https://api.github.com/users/blickly/orgs","repos_url":"https://api.github.com/users/blickly/repos","events_url":"https://api.github.com/users/blickly/events{/privacy}","received_events_url":"https://api.github.com/users/blickly/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/google/closure-compiler/pulls/1123/commits","review_comments_url":"https://api.github.com/repos/google/closure-compiler/pulls/1123/comments","review_comment_url":"https://api.github.com/repos/google/closure-compiler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/closure-compiler/issues/1123/comments","statuses_url":"https://api.github.com/repos/google/closure-compiler/statuses/9cb070cdc63624e7b57d53a440dadeb45182e3ef","head":{"label":"visokio:master2","ref":"master2","sha":"9cb070cdc63624e7b57d53a440dadeb45182e3ef","user":{"login":"visokio","id":13541812,"avatar_url":"https://avatars.githubusercontent.com/u/13541812?v=3","gravatar_id":"","url":"https://api.github.com/users/visokio","html_url":"https://github.com/visokio","followers_url":"https://api.github.com/users/visokio/followers","following_url":"https://api.github.com/users/visokio/following{/other_user}","gists_url":"https://api.github.com/users/visokio/gists{/gist_id}","starred_url":"https://api.github.com/users/visokio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/visokio/subscriptions","organizations_url":"https://api.github.com/users/visokio/orgs","repos_url":"https://api.github.com/users/visokio/repos","events_url":"https://api.github.com/users/visokio/events{/privacy}","received_events_url":"https://api.github.com/users/visokio/received_events","type":"Organization","site_admin":false},"repo":{"id":41148369,"name":"closure-compiler","full_name":"visokio/closure-compiler","owner":{"login":"visokio","id":13541812,"avatar_url":"https://avatars.githubusercontent.com/u/13541812?v=3","gravatar_id":"","url":"https://api.github.com/users/visokio","html_url":"https://github.com/visokio","followers_url":"https://api.github.com/users/visokio/followers","following_url":"https://api.github.com/users/visokio/following{/other_user}","gists_url":"https://api.github.com/users/visokio/gists{/gist_id}","starred_url":"https://api.github.com/users/visokio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/visokio/subscriptions","organizations_url":"https://api.github.com/users/visokio/orgs","repos_url":"https://api.github.com/users/visokio/repos","events_url":"https://api.github.com/users/visokio/events{/privacy}","received_events_url":"https://api.github.com/users/visokio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/visokio/closure-compiler","description":"A JavaScript checker and optimizer.","fork":true,"url":"https://api.github.com/repos/visokio/closure-compiler","forks_url":"https://api.github.com/repos/visokio/closure-compiler/forks","keys_url":"https://api.github.com/repos/visokio/closure-compiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/visokio/closure-compiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/visokio/closure-compiler/teams","hooks_url":"https://api.github.com/repos/visokio/closure-compiler/hooks","issue_events_url":"https://api.github.com/repos/visokio/closure-compiler/issues/events{/number}","events_url":"https://api.github.com/repos/visokio/closure-compiler/events","assignees_url":"https://api.github.com/repos/visokio/closure-compiler/assignees{/user}","branches_url":"https://api.github.com/repos/visokio/closure-compiler/branches{/branch}","tags_url":"https://api.github.com/repos/visokio/closure-compiler/tags","blobs_url":"https://api.github.com/repos/visokio/closure-compiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/visokio/closure-compiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/visokio/closure-compiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/visokio/closure-compiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/visokio/closure-compiler/statuses/{sha}","languages_url":"https://api.github.com/repos/visokio/closure-compiler/languages","stargazers_url":"https://api.github.com/repos/visokio/closure-compiler/stargazers","contributors_url":"https://api.github.com/repos/visokio/closure-compiler/contributors","subscribers_url":"https://api.github.com/repos/visokio/closure-compiler/subscribers","subscription_url":"https://api.github.com/repos/visokio/closure-compiler/subscription","commits_url":"https://api.github.com/repos/visokio/closure-compiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/visokio/closure-compiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/visokio/closure-compiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/visokio/closure-compiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/visokio/closure-compiler/contents/{+path}","compare_url":"https://api.github.com/repos/visokio/closure-compiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/visokio/closure-compiler/merges","archive_url":"https://api.github.com/repos/visokio/closure-compiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/visokio/closure-compiler/downloads","issues_url":"https://api.github.com/repos/visokio/closure-compiler/issues{/number}","pulls_url":"https://api.github.com/repos/visokio/closure-compiler/pulls{/number}","milestones_url":"https://api.github.com/repos/visokio/closure-compiler/milestones{/number}","notifications_url":"https://api.github.com/repos/visokio/closure-compiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/visokio/closure-compiler/labels{/name}","releases_url":"https://api.github.com/repos/visokio/closure-compiler/releases{/id}","created_at":"2015-08-21T09:44:59Z","updated_at":"2015-08-21T09:45:04Z","pushed_at":"2015-10-07T19:11:41Z","git_url":"git://github.com/visokio/closure-compiler.git","ssh_url":"git@github.com:visokio/closure-compiler.git","clone_url":"https://github.com/visokio/closure-compiler.git","svn_url":"https://github.com/visokio/closure-compiler","homepage":" https://developers.google.com/closure/compiler/","size":100921,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"newmaster"}},"base":{"label":"google:master","ref":"master","sha":"6fc04e3e9996c0e6c2892fa84962a057dd306c0c","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":18845024,"name":"closure-compiler","full_name":"google/closure-compiler","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/closure-compiler","description":"A JavaScript checker and optimizer.","fork":false,"url":"https://api.github.com/repos/google/closure-compiler","forks_url":"https://api.github.com/repos/google/closure-compiler/forks","keys_url":"https://api.github.com/repos/google/closure-compiler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/closure-compiler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/closure-compiler/teams","hooks_url":"https://api.github.com/repos/google/closure-compiler/hooks","issue_events_url":"https://api.github.com/repos/google/closure-compiler/issues/events{/number}","events_url":"https://api.github.com/repos/google/closure-compiler/events","assignees_url":"https://api.github.com/repos/google/closure-compiler/assignees{/user}","branches_url":"https://api.github.com/repos/google/closure-compiler/branches{/branch}","tags_url":"https://api.github.com/repos/google/closure-compiler/tags","blobs_url":"https://api.github.com/repos/google/closure-compiler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/closure-compiler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/closure-compiler/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/closure-compiler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/closure-compiler/statuses/{sha}","languages_url":"https://api.github.com/repos/google/closure-compiler/languages","stargazers_url":"https://api.github.com/repos/google/closure-compiler/stargazers","contributors_url":"https://api.github.com/repos/google/closure-compiler/contributors","subscribers_url":"https://api.github.com/repos/google/closure-compiler/subscribers","subscription_url":"https://api.github.com/repos/google/closure-compiler/subscription","commits_url":"https://api.github.com/repos/google/closure-compiler/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/closure-compiler/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/closure-compiler/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/closure-compiler/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/closure-compiler/contents/{+path}","compare_url":"https://api.github.com/repos/google/closure-compiler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/closure-compiler/merges","archive_url":"https://api.github.com/repos/google/closure-compiler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/closure-compiler/downloads","issues_url":"https://api.github.com/repos/google/closure-compiler/issues{/number}","pulls_url":"https://api.github.com/repos/google/closure-compiler/pulls{/number}","milestones_url":"https://api.github.com/repos/google/closure-compiler/milestones{/number}","notifications_url":"https://api.github.com/repos/google/closure-compiler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/closure-compiler/labels{/name}","releases_url":"https://api.github.com/repos/google/closure-compiler/releases{/id}","created_at":"2014-04-16T15:30:36Z","updated_at":"2015-10-07T19:24:07Z","pushed_at":"2015-10-07T19:11:42Z","git_url":"git://github.com/google/closure-compiler.git","ssh_url":"git@github.com:google/closure-compiler.git","clone_url":"https://github.com/google/closure-compiler.git","svn_url":"https://github.com/google/closure-compiler","homepage":" https://developers.google.com/closure/compiler/","size":111878,"stargazers_count":1693,"watchers_count":1693,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":384,"mirror_url":null,"open_issues_count":417,"forks":384,"open_issues":417,"watchers":1693,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/1123"},"html":{"href":"https://github.com/google/closure-compiler/pull/1123"},"issue":{"href":"https://api.github.com/repos/google/closure-compiler/issues/1123"},"comments":{"href":"https://api.github.com/repos/google/closure-compiler/issues/1123/comments"},"review_comments":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/1123/comments"},"review_comment":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/closure-compiler/pulls/1123/commits"},"statuses":{"href":"https://api.github.com/repos/google/closure-compiler/statuses/9cb070cdc63624e7b57d53a440dadeb45182e3ef"}}}}