Skip to content

Async await transformed to ES5 generators not debuggable in Chrome #12390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jasonpang opened this issue Nov 19, 2016 · 9 comments
Closed

Async await transformed to ES5 generators not debuggable in Chrome #12390

jasonpang opened this issue Nov 19, 2016 · 9 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jasonpang
Copy link

jasonpang commented Nov 19, 2016

TypeScript Version: nightly (2.2.0-dev.20161118)

Chrome Version: Stable 54.0.2840.99 (Official Build) m (64-bit) (Revision 7eca4ce1e662f12cadaf96c30cd2335fd03e7140-refs/branch-heads/2840@{#830})

TypeScript Code:

function work() {
  return Promise.resolve(67);
}

async function method() {
  var number = await work();
  console.log(number);
}

debugger; method();

GIF of Issue:

asyncawaitissue

Expected behavior:

Stepping into method() on Chrome should step into the original TypeScript file just a few lines up.

Actual behavior:

Stepping into method() on Chrome steps into the generated ES5 JavaScript file.

Instructions to Reproduce:

  1. Download the self-contained project at my Google Drive link: https://goo.gl/8tmMXh (GitHub did not allow me to upload a .ZIP file).
  2. Open index.html and follow the instructions on-screen.

Possibly related to:

@tonyn4444
Copy link

Yeah I've run into this problem too many times

@meakyl
Copy link

meakyl commented Nov 21, 2016

I have the same problem with the 2.1.1rc

@jasonpang
Copy link
Author

jasonpang commented Nov 28, 2016

Hey @rbuckton @mhegazy,

From Chromium Bug 496865, using Chrome to step into or over lines with await in an async function work. In other words, running this code works. Interestingly enough, it also works in Chrome Stable 54.0.2840.98, so I don't think I understand what the original bug really was and what got fixed here. The Chromium bug is now closed and marked as Fixed.

Problems that remain:

  • After TypeScript transpiles async/await down to ES5, debugging the async function produces the behavior shown in the GIF in the first comment. Using async / await natively in Chrome without transpiling works perfectly
  • Breakpoints cannot be set on lines with await

@jasonpang
Copy link
Author

jasonpang commented Dec 2, 2016

I have no idea what this means but it's really cool.

Using the target: "es6" option, I'm able to debug async/await perfectly! There are some slight jumps when you go into a method (it jumps to the end of the file and you have to step into it twice), but then it does step into the target function and it works beautifully:

{
  "compilerOptions": {
    "lib": [
      "dom",
      "es6",
      "dom.iterable",
      "scripthost"
    ],
    "module": "commonjs",
    "target": "es6"
}

Does not work with target es5.

Works best in Chrome Canary 57 since Chrome Stable 54 seems to syntax-highlight TypeScript incorrectly and make most of the file one large comment.

@mhegazy mhegazy added this to the TypeScript 2.2 milestone Dec 2, 2016
@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 2, 2016
@rbuckton
Copy link
Contributor

rbuckton commented Dec 5, 2016

Unfortunately, the Chrome Dev Tools do not provide a means to step over generated code that is unmapped, such as the __generator helper emitted at the top of the file for ES5 and ES3 targets.. VS Code supports debugging Chrome and can skip over this generated content if you set "smartStep": true in the debugger launch configuration.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 22, 2016
@mhegazy mhegazy closed this as completed Dec 22, 2016
@Gambero81
Copy link

@mhegazy is this bug fixed also for chrome debugging? will be available in next typescript release?
Thanks

@kachalkov
Copy link

kachalkov commented Jan 18, 2017 via email

@mikecg
Copy link

mikecg commented Apr 30, 2018

@kachalkov does your last comment still apply? It seems that Chrome dev tools still has issues with transpiled async arrow functions. Do you know how to workaround that?

@kachalkov
Copy link

kachalkov commented May 1, 2018 via email

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

8 participants