sukyoung / safe

Scalable Analysis Framework for ECMAScript
Other
118 stars 37 forks source link

analyse Error: example.js:7:8: opensquare expected #39

Closed DiffYao closed 2 years ago

DiffYao commented 2 years ago

import fetch from "node-fetch";

// Plain text or HTML let response = await fetch("https://github.com/"); let body = await response.text();

console.log(body);

// JSON response = await fetch("https://github.com/"); json = await response.json();

console.log(json);

// Simple Post response = await fetch("https://httpbin.org/post", { method: "POST", body: "a=1", }); json = await response.json();

console.log(json);

// Post with JSON body = { a: 1 };

response = await fetch("https://httpbin.org/post", { method: "post", body: JSON.stringify(body), headers: { "Content-Type": "application/json" }, }); const json = await response.json();

console.log(json);



- ERR Msg
<img width="1511" alt="image" src="https://user-images.githubusercontent.com/50076801/163670914-4f68e012-ecad-473c-ad74-3f603b9bb584.png">

#### Why am I getting this error? 

Thanks for your reply!
YichaoXu commented 2 years ago

Hi Diffyao,

It seems like the SAFE does not support the keyword "let". If you change the let to var, it may solve the issue, but there may be some other syntax issues that SAFE cannot handle. I also have those issues when I try to use SAFE on the "aws-lambda".

Hi @jhnaldo , I was also wondering why SAFE will have such an issue. I briefly review the code, and the error messages seem like about the square brackets "[". Whether you can provide us with some suggestions about how to solve the issue? or whether we can ignore the issues and make SAFE skip those lines that it cannot handle.

Best, Yichao.

jhnaldo commented 2 years ago

Hi @DiffYao and @YichaoXu, SAFE only supports JavaScript language features defined in ES5.1. So, the JavaScript parser used in SAFE does not support ES6+ features, such as let binding you mentioned. We do not have a plan to support such features in SAFE, but you can desugar ES6+ features to ES5.1 features using Babel before analyzing JavaScript code.

YichaoXu commented 2 years ago

Hi Jhnaldo, thank you a lot for your reply. That's helpful.

Best, Yichao

DiffYao commented 2 years ago

Thanks for your reply!