Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mister-hope/es-parser

A 100kb size es6 parser
https://github.com/mister-hope/es-parser

js mr-hope parser

Last synced: 3 months ago
JSON representation

A 100kb size es6 parser

Awesome Lists containing this project

README

        

# es-parser

[![Author: Mr.Hope](https://img.shields.io/badge/作者-Mr.Hope-blue.svg?style=for-the-badge)](https://mrhope.site)

一个 110KB 大小的 JS 解释器/运行器

A 110KB size JS parser and runner.

## Import

### TypeScript

```ts
import * as esParser from "es-parser";
```

### JavaScript

```js
const esParser = require("es-parser");
```

## API

- run:

```ts
run(codeString: string, globalMap: GlobalMap)

interface GlobalMap{
[prop: globalIdentifier]: value
}
```

## Demo

```js
esParser.run("console.log('hello world')");

esParser.run(
`
const progress = wx.downloadFile({
url: 'https://www.baidu.com/img/bd_logo1.png',
success: res => {
wx.hideLoading();
if (res.statusCode === 200) console.log(success, res.tempFilePath);
else wx.showToast({ title: '下载失败' });
});
},
fail: failMsg => {
wx.hideLoading();
wx.showToast({ title: '下载失败' });
}
});

progress.onProgressUpdate(res => {
wx.showLoading({ title: \`下载中\${Math.round(res.progress)}%\` });
});
`,
{ wx }
);
// this will pass the global variable `wx` to the parser
```

## Known Bugs

None, but package is still in test.

## Notes

- You should always access `isFinite`, `isNaN` through `Number`.

## TODO

- add Stack Track