CanJS is a javascript interpreter, which can run JS code in JS.
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist fix: fix a bug about varDeclaration Dec 11, 2018
src fix: fix a bug about varDeclaration Dec 11, 2018
.gitignore update Dec 3, 2018
Article.md update Dec 3, 2018
LICENSE Initial commit Nov 30, 2018
README.md chores: use parcel to generate UMD lib Dec 11, 2018
demo.js fix: fix a bug about varDeclaration Dec 11, 2018
package.json fix: fix a bug about varDeclaration Dec 11, 2018

README.md

CanJS

CanJS is a javascript interpreter, which can run JS code in JS.

Relate article: 《 前端与编译原理——用JS写一个JS解释器》

Install

git clone https://github.com/jrainlau/canjs.git

Usage

It's fine to run the JS code in string directly.

const Canjs = require('./dist/index.js')

new Canjs(`
  console.log('Hello World!')
`).run()

CanJS uses ES5 standard library, but you can also provide custom variables to it:

const Canjs = require('./dist/index.js')

const wx = {
  name: 'wx'
}

new Canjs(`
  console.log(wx.name)
`, { wx }).run()

License

MIT