{"action":"created","issue":{"url":"https://api.github.com/repos/google/closure-compiler/issues/1933","repository_url":"https://api.github.com/repos/google/closure-compiler","labels_url":"https://api.github.com/repos/google/closure-compiler/issues/1933/labels{/name}","comments_url":"https://api.github.com/repos/google/closure-compiler/issues/1933/comments","events_url":"https://api.github.com/repos/google/closure-compiler/issues/1933/events","html_url":"https://github.com/google/closure-compiler/issues/1933","id":169222856,"number":1933,"title":"Using WHITESPACE_ONLY to do an ES6 -> ES5 transpilation wraps goog.modules in a goog.loadModule","user":{"login":"lewistg","id":2227953,"avatar_url":"https://avatars.githubusercontent.com/u/2227953?v=3","gravatar_id":"","url":"https://api.github.com/users/lewistg","html_url":"https://github.com/lewistg","followers_url":"https://api.github.com/users/lewistg/followers","following_url":"https://api.github.com/users/lewistg/following{/other_user}","gists_url":"https://api.github.com/users/lewistg/gists{/gist_id}","starred_url":"https://api.github.com/users/lewistg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewistg/subscriptions","organizations_url":"https://api.github.com/users/lewistg/orgs","repos_url":"https://api.github.com/users/lewistg/repos","events_url":"https://api.github.com/users/lewistg/events{/privacy}","received_events_url":"https://api.github.com/users/lewistg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-03T20:13:10Z","updated_at":"2016-08-04T14:13:57Z","closed_at":null,"body":"Given the following ES6 code:\r\n```javascript\r\ngoog.module('greeter');\r\n\r\nclass Greeter {\r\n    constructor() {\r\n        this.greeting = 'hello, world';\r\n    }\r\n\r\n    greet() {\r\n        console.log(this.greeting);\r\n    }\r\n}\r\nexports.Greeter = Greeter;\r\n```\r\nWhen I compile it using `$ java -jar closure-compiler.jar --formatting=PRETTY_PRINT --compilation_level=WHITESPACE_ONLY`, I am given the following as output:\r\n```javascript\r\ngoog.loadModule(function(exports) {\r\n  \"use strict\";\r\n  goog.module(\"greeter\");\r\n  var Greeter = function() {\r\n    this.greeting = \"hello, world\";\r\n  };\r\n  Greeter.prototype.greet = function() {\r\n    console.log(this.greeting);\r\n  };\r\n  exports.Greeter = Greeter;\r\n  return exports;\r\n});\r\n```\r\nFrom what I gather from the discussions around the issues [here](https://github.com/google/closure-compiler/issues/1479) and [here](https://github.com/google/closure-compiler/issues/1261), doing a WHITESPACE_ONLY compilation, can be thought of as just a transpile step. Wrapping the module with the `goog.loadModule` seems to go beyond that. \r\n\r\nNow, I can understand if this assumption about WHITESPACE_ONLY and transpilation is not technically true, and it is working as designed...\r\n\r\n**_Background_**\r\n\r\nThe specific problem I am facing involves trying to use this transpiled code in debug mode. When the above example gets processed by `depswriter.py`, the following `goog.addDependency` is added to the output:\r\n```javascript \r\ngoog.addDependency('../../../bin/greeter.js', ['greeter'], [], true);\r\n```\r\nNote that the last parameter in the `goog.addDependency` marks the contents of the file as a module. When `greeter` is goog.require'd, the closure library sees that it has been marked as a module, downloads its contents, and wraps it in _another_ goog.loadModule call. (This seems to be its special module loading process.) The doubly wrapped goog.loadModule throws an error. \r\n\r\nIt is kind of an edge case, and I can understand if I will just have to find a workaround. For example, you might ask why do I use `goog.module` with ES6 code. Well, this is the output from Angular 2's tsickle tool. I do not have much control over it. But, I just thought I would raise the goog.loadModule issue.\r\n"},"comment":{"url":"https://api.github.com/repos/google/closure-compiler/issues/comments/237565584","html_url":"https://github.com/google/closure-compiler/issues/1933#issuecomment-237565584","issue_url":"https://api.github.com/repos/google/closure-compiler/issues/1933","id":237565584,"user":{"login":"lewistg","id":2227953,"avatar_url":"https://avatars.githubusercontent.com/u/2227953?v=3","gravatar_id":"","url":"https://api.github.com/users/lewistg","html_url":"https://github.com/lewistg","followers_url":"https://api.github.com/users/lewistg/followers","following_url":"https://api.github.com/users/lewistg/following{/other_user}","gists_url":"https://api.github.com/users/lewistg/gists{/gist_id}","starred_url":"https://api.github.com/users/lewistg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lewistg/subscriptions","organizations_url":"https://api.github.com/users/lewistg/orgs","repos_url":"https://api.github.com/users/lewistg/repos","events_url":"https://api.github.com/users/lewistg/events{/privacy}","received_events_url":"https://api.github.com/users/lewistg/received_events","type":"User","site_admin":false},"created_at":"2016-08-04T14:13:56Z","updated_at":"2016-08-04T14:13:56Z","body":"Never mind. I can see why this is necessary for concatenation of multiple files. Just makes per file transpilation hard. I will have to ask in the forums if there are better ways to use closure to do per-file transpilation."}}
{"actor":{"display_login":"lewistg"}}