Semgrep: [typescript] Probable bug in parsing

Created on 22 Sep 2020  ·  12Comments  ·  Source: returntocorp/semgrep

Describe the bug

Running semgrep on my large-ish code base yielded these remarkably few probable parsing problems--nice job, folks!

These files compile cleanly and are currently running in production so, as far as I know, they should be parsable.

warn: parse error
  --> data-bags.requests.ts:1
1 | import { Injectable } from '@angular/core';
  | 
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse data-bags.requests.ts as ts

warn: parse error
  --> cookbook-details.component.ts:1
1 | import { Component, OnInit, OnDestroy } from '@angular/core';
  | 
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse cookbook-details.component.ts as ts

warn: parse error
  --> entities.ts:1
1 | import {
  | 
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse entities.ts as ts

To Reproduce

My codebase is open source so you can go right to, well, the source: https://github.com/chef/automate/tree/master/components/automate-ui

Expected behavior
No parsing errors.

Environment
Version 0.24.0

bug external-user fixed typescript

All 12 comments

Thanks for the report, @msorens. I'll look into this.

With the better error reporting I now get those parse error locations:

warn: parse error
  --> entities.ts:20
20 |   readonly [id: string]: T;
   |             ^^^
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse entities.ts as ts

warn: parse error
  --> data-bags.requests.ts:20
20 |   : Observable<DataBagDetailsSuccessPayload> {
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse data-bags.requests.ts as ts

Warnings exist. Run with `--strict` to turn warnings into errors.

This can help in the futur to provide more information on the kind of constructs we do not parse well, which also makes it
easier to create simpler test file showing the issue (minimal test case).

Some additional feedback: I just upgraded from 0.24 to 0.26 and I am seeing errors on the same two files as you show @aryx , but they are different errors !?!

warn: parse error
  --> data-bags.requests.ts:1
1 | import { Injectable } from '@angular/core';
  | 
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse data-bags.requests.ts as ts

warn: parse error
  --> entities.ts:1
1 | import {
  | 
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse entities.ts as ts

yes the latest code for better error location is not yet in the release, it will be in 0.27

Just to be explicit, with 0.27.0 I am now seeing the revised error messages @aryx indicated. However, those files are all valid code, so those errors should not be present.

@msorens a number of fixes are coming for typescript but still need integration work. They will become available most likely in the semgrep release two weeks from now. This includes:

Let's keep this open until we double check that the new release really fix the issue.

Unless this is already working with the develop version @mjambon ?

@aryx @mjambon This appears to still not parse. I ran a subset of the rules on one of the problematic files via Semgrep.dev:

❌ 0.27.0: https://semgrep.dev/s/GRBn/?version=0.27.0
❌ develop: https://semgrep.dev/s/GRBn/?version=develop

Can we close this now?

This is now fixed:

warn: parse error
  --> entities.ts:20
20 |   readonly [id: string]: T;
   |             ^^^
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse entities.ts as ts

This is fixed too:

warn: parse error
  --> data-bags.requests.ts:20
20 |   : Observable<DataBagDetailsSuccessPayload> {
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: If the code appears to be valid, this may be a semgrep bug.
Could not parse data-bags.requests.ts as ts

It's all good now, already released.

Was this page helpful?
0 / 5 - 0 ratings