Chrome Dev Tools Issue With ES6 String Literals/Typescript

后端 未结 3 2014
离开以前
离开以前 2021-02-01 00:37

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`.<

相关标签:
3条回答
  • 2021-02-01 01:08

    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.

    0 讨论(0)
  • 2021-02-01 01:08

    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.

    0 讨论(0)
  • 2021-02-01 01:32

    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.

    0 讨论(0)
提交回复
热议问题