{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/21948","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/21948/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/21948/comments","events_url":"https://api.github.com/repos/angular/angular/issues/21948/events","html_url":"https://github.com/angular/angular/issues/21948","id":293369122,"number":21948,"title":"Incorrect output when transpiling to target ES6 and --prod","user":{"login":"jgutix","id":1747459,"avatar_url":"https://avatars2.githubusercontent.com/u/1747459?v=4","gravatar_id":"","url":"https://api.github.com/users/jgutix","html_url":"https://github.com/jgutix","followers_url":"https://api.github.com/users/jgutix/followers","following_url":"https://api.github.com/users/jgutix/following{/other_user}","gists_url":"https://api.github.com/users/jgutix/gists{/gist_id}","starred_url":"https://api.github.com/users/jgutix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgutix/subscriptions","organizations_url":"https://api.github.com/users/jgutix/orgs","repos_url":"https://api.github.com/users/jgutix/repos","events_url":"https://api.github.com/users/jgutix/events{/privacy}","received_events_url":"https://api.github.com/users/jgutix/received_events","type":"User","site_admin":false},"labels":[{"id":279828207,"url":"https://api.github.com/repos/angular/angular/labels/comp:%20http","name":"comp: http","color":"c7def8","default":false},{"id":375496864,"url":"https://api.github.com/repos/angular/angular/labels/freq1:%20low","name":"freq1: low","color":"fbca04","default":false},{"id":375498203,"url":"https://api.github.com/repos/angular/angular/labels/severity3:%20broken","name":"severity3: broken","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/angular/angular/milestones/83","html_url":"https://github.com/angular/angular/milestone/83","labels_url":"https://api.github.com/repos/angular/angular/milestones/83/labels","id":3143880,"number":83,"title":"needsTriage","description":"Milestone for all issues that haven't been triaged yet","creator":{"login":"ocombe","id":265378,"avatar_url":"https://avatars0.githubusercontent.com/u/265378?v=4","gravatar_id":"","url":"https://api.github.com/users/ocombe","html_url":"https://github.com/ocombe","followers_url":"https://api.github.com/users/ocombe/followers","following_url":"https://api.github.com/users/ocombe/following{/other_user}","gists_url":"https://api.github.com/users/ocombe/gists{/gist_id}","starred_url":"https://api.github.com/users/ocombe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ocombe/subscriptions","organizations_url":"https://api.github.com/users/ocombe/orgs","repos_url":"https://api.github.com/users/ocombe/repos","events_url":"https://api.github.com/users/ocombe/events{/privacy}","received_events_url":"https://api.github.com/users/ocombe/received_events","type":"User","site_admin":false},"open_issues":379,"closed_issues":23,"state":"open","created_at":"2018-02-26T14:22:18Z","updated_at":"2018-03-02T19:43:02Z","due_on":null,"closed_at":null},"comments":14,"created_at":"2018-02-01T01:09:01Z","updated_at":"2018-03-02T20:19:33Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a...\r\n<!-- Check one of the following options with \"x\" -->\r\n<pre><code>\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[X] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Feature request\r\n[ ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n</code></pre>\r\n\r\n## Current behavior\r\nThe bundle for production environment is outputting the following invalid code, when using the HttpClientModule\r\n```\r\n  return new ue.a(t=>{\r\n    const n = this.xhrFactory.build();\r\n    if (n.open(e.method, e.urlWithParams),\r\n      e.withCredentials && (n.withCredentials = !0),\r\n        e.headers.forEach((e,t)=>n.setRequestHeader(e, t.join(\",\"))),\r\n      e.headers.has(\"Accept\") || n.setRequestHeader(\"Accept\", \"application/json, text/plain, */*\"),\r\n        !e.headers.has(\"Content-Type\")) {\r\n      const t = e.detectContentTypeHeader();\r\n      null !== t && n.setRequestHeader(\"Content-Type\", t)\r\n    }\r\n    if (e.responseType) {\r\n      const t = e.responseType.toLowerCase();\r\n      n.responseType = \"json\" !== t ? t : \"text\"\r\n    }\r\n    const r = e.serializeBody();\r\n    let s = null;\r\n    const o = ()=>{\r\n      if (null !== s)\r\n        return s;\r\n      const t = 1223 === n.status ? 204 : n.status\r\n        , r = n.statusText || \"OK\"\r\n        , o = new zo(n.getAllResponseHeaders())\r\n        , i = (\"responseURL\"in (n = n) && n.responseURL ? n.responseURL : /^X-Request-URL:/m.test(n.getAllResponseHeaders()) ? n.getResponseHeader(\"X-Request-URL\") : null) || e.url;\r\n      return s = new ei({\r\n        headers: o,\r\n        status: t,\r\n        statusText: r,\r\n        url: i\r\n      })\r\n    }\r\n```\r\n\r\nEspecifically the error is in this line:\r\n```\r\n, i = (\"responseURL\"in (n = n) && n.responseURL ? n.responseURL : /^X-Request-URL:/m.test(n.getAllResponseHeaders()) ? n.getResponseHeader(\"X-Request-URL\") : null) || e.url;\r\n```\r\nBecause in the above lines the `n` was declared as constant: `const n = this.xhrFactory.build();`\r\n\r\nProducing the following error in chrome:\r\n```\r\nERROR TypeError: Assignment to constant variable.\r\n    at o (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:13612)\r\n    at XMLHttpRequest.i (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:13621)\r\n    at e.invokeTask (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n    at Object.onInvokeTask (main.afd9c695ba9c5bcbf50d.bundle.js:formatted:1694)\r\n    at e.invokeTask (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n    at t.runTask (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n    at t.invokeTask [as invoke] (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n    at _ (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n    at XMLHttpRequest.k (polyfills.d14582d1423c077d31d1.bundle.js:1)\r\n```\r\n\r\nSimilar in firefox:\r\n```\r\nERROR \r\nTypeError: invalid assignment to const `n'\r\nStack trace:\r\no@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:298093\r\ni@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:298355\r\neFQL/</</</c</e.prototype.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:22948\r\nonInvokeTask@http://localhost:4201/main.afd9c695ba9c5bcbf50d.bundle.js:1:27946\r\neFQL/</</</c</e.prototype.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:22861\r\neFQL/</</</o</t.prototype.runTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:18118\r\neFQL/</</</u</t.invokeTask@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:24042\r\n_@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:34743\r\nk@http://localhost:4201/polyfills.d14582d1423c077d31d1.bundle.js:1:34975\r\n```\r\n## Expected behavior\r\nA valid code should be outputted when targeting ES6 for production\r\n\r\n\r\n## Minimal reproduction of the problem with instructions\r\n<!--\r\nFor bug reports please provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\r\nhttps://plnkr.co or similar (you can use this template as a starting point: http://plnkr.co/edit/tpl:AvJOMERrnz94ekVua0u5).\r\n-->\r\nGiven the downloadable example at the HTTP chapter of the Tour of heroes tutorial (https://angular.io/generated/zips/toh-pt6/toh-pt6.zip)\r\n1. Disable `HttpClientInMemoryWebApiModule` and `HttpClientInMemoryWebApiModule` in `src/app/app.module.ts`, so the app try to make an actual XhttpRequest\r\n2. Change the target to `\"target\": \"es6\",` in `tsconfig.json`\r\n3. Run the app like: `ng serve --prod`\r\n\r\n## What is the motivation / use case for changing the behavior?\r\n<!-- Describe the motivation or the concrete use case. -->\r\nThe output from the compilation for ES6 is broken\r\n\r\n## Environment\r\n\r\n<pre><code>\r\nAngular version: 5.0.0 and 5.2.2\r\n<!-- Check whether this is still an issue in the most recent Angular version -->\r\n\r\nBrowser:\r\n- [X] Chrome (desktop) version XX\r\n- [ ] Chrome (Android) version XX\r\n- [ ] Chrome (iOS) version XX\r\n- [X] Firefox version XX\r\n- [ ] Safari (desktop) version XX\r\n- [ ] Safari (iOS) version XX\r\n- [ ] IE version XX\r\n- [ ] Edge version XX\r\n \r\nFor Tooling issues:\r\n- Node version: 8.9.1  <!-- run `node --version` -->\r\n- Platform:  Mac\r\n\r\nOthers:\r\n<!-- Anything else relevant?  Operating system version, IDE, package manager, HTTP server, ... -->\r\n</code></pre>\r\nWorth noting this issue arises only with these three factors combined: \r\n1. Use of `HttpClientModule`\r\n2. Target = es6\r\n3. Building/serving with `prod`\r\n\r\nProbably this is an issue that should be fixed in the angular-cli or uglify-webpack-plugin level, but I had no time to dig deeper."},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/370041011","html_url":"https://github.com/angular/angular/issues/21948#issuecomment-370041011","issue_url":"https://api.github.com/repos/angular/angular/issues/21948","id":370041011,"user":{"login":"zijianhuang","id":8484970,"avatar_url":"https://avatars1.githubusercontent.com/u/8484970?v=4","gravatar_id":"","url":"https://api.github.com/users/zijianhuang","html_url":"https://github.com/zijianhuang","followers_url":"https://api.github.com/users/zijianhuang/followers","following_url":"https://api.github.com/users/zijianhuang/following{/other_user}","gists_url":"https://api.github.com/users/zijianhuang/gists{/gist_id}","starred_url":"https://api.github.com/users/zijianhuang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zijianhuang/subscriptions","organizations_url":"https://api.github.com/users/zijianhuang/orgs","repos_url":"https://api.github.com/users/zijianhuang/repos","events_url":"https://api.github.com/users/zijianhuang/events{/privacy}","received_events_url":"https://api.github.com/users/zijianhuang/received_events","type":"User","site_admin":false},"created_at":"2018-03-02T20:19:33Z","updated_at":"2018-03-02T20:19:33Z","author_association":"NONE","body":"Apparently the solution is that NG CLI provides such switch for es2015. It seems this issue could be closed here, while I had reported to https://github.com/angular/angular-cli/issues/9495."}}
{"actor":{"display_login":"zijianhuang"}}