jrainlau / canjs Goto Github PK
View Code? Open in Web Editor NEWCanJS is a javascript interpreter, which can run JS code in JS.
Home Page: https://codepen.io/jrainlau/pen/YRgQXo
License: MIT License
CanJS is a javascript interpreter, which can run JS code in JS.
Home Page: https://codepen.io/jrainlau/pen/YRgQXo
License: MIT License
varDeclare中,在递归查找父作用域之后,不是应该定义到最终查找到的父作用域上吗,怎么还是赋给了this.declaration?
varDeclare (name, value) {
let scope = this
// 若当前作用域存在非函数类型的父级作用域时,就把变量定义到父级作用域
while (scope.parentScope && scope.type !== 'function') {
scope = scope.parentScope
}
this.declaration[name] = new SimpleValue(value, 'var')
return this.declaration[name]
}
和 new Function( ...args, code)(...values); 有什么区别吗
比如逻辑操作符的短路求值策略;模块内的代码需要顺序执行,可能提前返回;UpdateExpression的变量类型不一定是Identifier;表达式优先要计算右值等等。运行大部分代码应该都可以了
es5.js 第63行是否有问题呢?
个人感觉 key.type === 'Identifier'的情况 可能是:
let a = 'key1'
let b = {
[a]: '123'
}
这里b中 [a]的key.type就是Identifier 所以key取值应该 也得从scope中获取
Here is an example
const a = {}
a.b = 1
console.log(a.b)
Expected:
1
Actual:
undefined
And more, Why you throw an error when setting a global variable?
https://github.com/jrainlau/canjs/blob/master/src/scope.js#L44
acorn对于这类写法的编译结果跟点语法的不一样,用这个nodeIterator.node.property.value才能取到
MemberExpression (nodeIterator) { const obj = nodeIterator.traverse(nodeIterator.node.object) const name = nodeIterator.node.property.name return obj[name] }
53行应为:const name = getPropertyName(nodeIterator.node, nodeIterator)
否则,某些情况下会出错误
const a = 1;a = 2;
在run()
的时候不会报错,原因:
AssignmentExpressionOperatortraverseMap
内部
"=": (value, v) => value instanceof MemberValue ? (value.obj[value.prop] = v) : (value.value = v),
应该写成:(value.set(v)),
原解析方式是自增自减动作完成后再return,导致return的结果为自运算动作完成后的值
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.