Coly010 / nx-ng-esbuild

MIT License
16 stars 0 forks source link

ng-estest: comments break transform process #1

Open Dyqmin opened 2 years ago

Dyqmin commented 2 years ago

After setup process on existing workspace, I tried to test an app with nx estest app command and every test did fail with esbuild error (similar to the one on the bottom). I spent some time on debugging and I found out that comments containing special characters can lead to code injection which fails transform process.

Steps to reproduce

Add comment with : character between constructor parameters in any component and run its tests.

constructor(
    // :
  ) {
  }

Failure logs

 FAIL   app2  apps/app2/src/app/app.component.spec.ts
  ● Test suite failed to run

    Transform failed with 1 error:
    <stdin>:23:2: ERROR: Expected identifier but found "}"

      at failureErrorWithLog (../../node_modules/esbuild/lib/main.js:1602:15)
      at ../../node_modules/esbuild/lib/main.js:1391:29
      at ../../node_modules/esbuild/lib/main.js:665:9
      at handleIncomingPacket (../../node_modules/esbuild/lib/main.js:762:9)
      at Socket.readFromStdout (../../node_modules/esbuild/lib/main.js:632:7)
Coly010 commented 2 years ago

Hey! :)

Yeah it's an underlying problem from the original code.

I've an idea to solve it with AST parsing, and I'll get round to that once I have some time :)