Skip to content
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

TypeScript code generated with a syntax error #279

Open
BenoitZugmeyer opened this issue Nov 29, 2022 · 0 comments
Open

TypeScript code generated with a syntax error #279

BenoitZugmeyer opened this issue Nov 29, 2022 · 0 comments

Comments

@BenoitZugmeyer
Copy link

This plugin can output code with a syntax error. Taking the following TypeScript code as input:

toto = (function () {
  // tata
} as any)

The following output is emitted by the plugin:

[...]
toto = (function () {
  cov_131zeqpl6j().f[0]++;
} // tata
as any);

As you can see, the comment has been moved outside the function, and now the as operator is on a new line. It seems that this syntax is not supported by typescript.

Minimal Node.js script to reproduce:

const { transformSync } = require("@babel/core");

const result = transformSync(
  `
toto = (function () {
  // tata
} as any)
`,
  {
    filename: "toto.ts",
    plugins: [["@babel/plugin-syntax-typescript"], ["istanbul"]],
  }
);

console.log(result.code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant