semgrep / pfff

pfff is mainly an OCaml API to write static analysis, dynamic analysis, code visualizations, code navigations, or style-preserving source-to-source transformations such as refactorings on source code.
https://semgrep.dev
Other
186 stars 29 forks source link

[js] Add parameters' type annotations as casts #517

Closed IagoAbal closed 2 years ago

IagoAbal commented 2 years ago

This mimics what our tree-sitter front-end does, so both pattern and code result in Generic ASTs that can be matched.

It's OK-ish to use an unsafe fake token because we only use Pfff to parse patterns.

Helps PA-1149

test plan:

% cat pa1149.sgrep
({$VAR} : $REQ) => {...}
% pfff -dump_ts pa1149.sgrep
[(ExprStmt (
    (Fun (
       { f_kind = (AST_generic_.Arrow, ()); f_attrs = [];
         f_params =
         [(ParamPattern
             (Cast (
                (Obj
                   ((),
                    [(FieldColon
                        { fld_name = (PN ("$VAR", ())); fld_attrs = [];
                          fld_type = None;
                          fld_body = (Some (Id ("$VAR", ()))) })
                      ],
                    ())),
                (), (TyName [("$REQ", ())]))))
           ];
         f_rettype = None;
         f_body = (Block ((), [(ExprStmt ((Ellipsis ()), ()))], ())) },
       None)),
    ()))
  ]

Security