58

I am working on a project using Typescript and some of the ES6 features exposed by Typescript like ES6 String Literals e.g. `Something ${variable} Something else`.

Whilst debugging a problem I dropped a breakpoint into my typescript file to step through it in the source panel, which usually works fine.

But Chrome Dev Tools has an issue with ES6 String literals and doesn't seem to recognise the end of an ES6 String literal.

Instead all code following the string literal is marked red (string highlighting in debugger) and blocked from variable inspection as chrome debugger seems to think it is all one massive string.

Has someone encountered this issue, found a fix or knows whether this is on Google's roadmap for Chrome Dev Tools?

EDIT 1:
Looks like this issue is currently being worked on by the Chromium team. See issue report for updates:
bugs.chromium.org/p/chromium/issues/detail?id=659515

EDIT 2: Bug has been open for quite some time, but doesn't seem to have been prioritised. If you experience the issue go to the chromium link above and star/comment on it with helpful info to move it into focus of the Dev Tools team.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
bbop99
  • 1,625
  • 1
  • 11
  • 25
  • 1
    Did you manage this find anything? A bug report maybe? It's driving me nuts too. – Roger Far Dec 19 '16 at 03:30
  • 3
    @YesMan85 Found an open bug report - looks like they are still working on a fix: https://bugs.chromium.org/p/chromium/issues/detail?id=659515 – bbop99 Dec 19 '16 at 13:46
  • Ok thanks, I put in a bug too yesterday with a repo case, hope they can pick it up. – Roger Far Dec 19 '16 at 14:22
  • 7
    Anybody running into this issue should star the chromium bug / add more info and evidence. Hoping this gets picked up as its very annoying – darudude Dec 28 '16 at 15:48
  • 2
    In the link, you provided this issue is marked as "fixed" but actually it's still broken. Does anybody know if there is a new link to this issue which we could upvote to enforce this bug fixing? – Oleg Pro May 29 '18 at 05:03
  • @OlegPro: https://bugs.chromium.org/p/chromium/issues/detail?id=859872 – Marcin Pevik Jul 03 '18 at 13:35
  • Version 70.0.3538.102 (Official Build) (64-bit) – chad steele Nov 12 '18 at 01:49

3 Answers3

36

As for version 69.0.3497.100 (Official Build) (64-bit) in Ubuntu is still a bug.

As a workaround you can start adding: //` to the end of lines containing templated strings, which fixes the formatting in the chrome sources tab.

Here some examples of my working jsx code.


In component props:

  <Field
    name={`${fields.name}[${index}].comments`}// `
    component="input"
    type="text"
  />

As a child element:

  <label>
    {`${t('Condone')}  `}{/* ` */}
  </label>

In a statement:

  switch (DEBTTYPE) {
    case DEBTTYPE_MACHINE_PRODUCT:
      id = `machine_product_difference_row_${row.id_productdebt}`;// `
      break;
      ....

I really hope that they can fix this issue as fast as possible.

Rodrigo García
  • 1,357
  • 15
  • 26
3

This December 14, 2017 comment from the DevTools team says that they updated the CodeMirror version used in DevTools, and the issue should be fixed now. In Chrome 64 and beyond it should work. In earlier versions of Chrome it'll still be broken. You can check your version at chrome://version.

Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
-4

If you are using Typescript, you can work around this issue by compiling your code to ES2015 and using source maps. This way, the backtick interpolated strings would be converted to the good ol' "string " + variable + " string", but you would still be able to debug while looking at the original typescript code with backticks.

This would require adding the following to your tsconfig.json:

{
    "compilerOptions": {
        "target": "ES2015",
        "sourceMap": true, 
        ...
    }
    ...
}

And if you serve locally the generated source map files (.js.map) alongside the generated .js files, you should be able to open the typescript files in chrome dev tools under "Sources" with Ctrl-p.

Yaar Hever
  • 81
  • 1
  • 6
  • The issue is that the syntax highlighting does not work on TS source maps with backticks. Your method still ends up showing a TypeScript file with backticks in the Chrome debugger. – rikkit Oct 17 '17 at 13:08
  • This is not a solution to OP's question, it is not even related to what he is asking. – Rodrigo García Oct 08 '18 at 20:49