Merge 7dc9866681 into caf96acb08
This commit is contained in:
commit
6c6a93b595
|
|
@ -253,9 +253,12 @@ function run() {
|
||||||
var result = {
|
var result = {
|
||||||
_class: "AST_" + value.TYPE
|
_class: "AST_" + value.TYPE
|
||||||
};
|
};
|
||||||
value.CTOR.PROPS.forEach(function(prop) {
|
var ctor = value.CTOR;
|
||||||
|
do {
|
||||||
|
ctor.SELF_PROPS.forEach(function(prop) {
|
||||||
result[prop] = value[prop];
|
result[prop] = value[prop];
|
||||||
});
|
});
|
||||||
|
} while (ctor = ctor.BASE);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
|
||||||
32
lib/ast.js
32
lib/ast.js
|
|
@ -47,31 +47,35 @@ function DEFNODE(type, props, methods, base) {
|
||||||
if (arguments.length < 4) base = AST_Node;
|
if (arguments.length < 4) base = AST_Node;
|
||||||
if (!props) props = [];
|
if (!props) props = [];
|
||||||
else props = props.split(/\s+/);
|
else props = props.split(/\s+/);
|
||||||
var self_props = props;
|
var code = "return function AST_" + type + "(props) {\
|
||||||
if (base && base.PROPS)
|
if (props) {\
|
||||||
props = props.concat(base.PROPS);
|
var ctor = this.CTOR;\
|
||||||
var code = "return function AST_" + type + "(props){ if (props) { ";
|
do {\
|
||||||
for (var i = props.length; --i >= 0;) {
|
var self_props = ctor.SELF_PROPS;\
|
||||||
code += "this." + props[i] + " = props." + props[i] + ";";
|
for (var i = self_props.length; i;) {\
|
||||||
}
|
var k = self_props[--i];\
|
||||||
var proto = base && new base;
|
this[k] = props[k];\
|
||||||
if (proto && proto.initialize || (methods && methods.initialize))
|
}\
|
||||||
code += "this.initialize();";
|
} while (ctor = ctor.BASE);\
|
||||||
code += "}}";
|
if (this.initialize) {\
|
||||||
|
this.initialize();\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
}";
|
||||||
var ctor = new Function(code)();
|
var ctor = new Function(code)();
|
||||||
|
var proto = base && new base;
|
||||||
if (proto) {
|
if (proto) {
|
||||||
ctor.prototype = proto;
|
ctor.prototype = proto;
|
||||||
ctor.BASE = base;
|
ctor.BASE = base;
|
||||||
}
|
}
|
||||||
if (base) base.SUBCLASSES.push(ctor);
|
if (base) base.SUBCLASSES.push(ctor);
|
||||||
ctor.prototype.CTOR = ctor;
|
ctor.prototype.CTOR = ctor;
|
||||||
ctor.PROPS = props || null;
|
ctor.SELF_PROPS = props;
|
||||||
ctor.SELF_PROPS = self_props;
|
|
||||||
ctor.SUBCLASSES = [];
|
ctor.SUBCLASSES = [];
|
||||||
if (type) {
|
if (type) {
|
||||||
ctor.prototype.TYPE = ctor.TYPE = type;
|
ctor.prototype.TYPE = ctor.TYPE = type;
|
||||||
}
|
}
|
||||||
if (methods) for (i in methods) if (HOP(methods, i)) {
|
if (methods) for (var i in methods) if (HOP(methods, i)) {
|
||||||
if (/^\$/.test(i)) {
|
if (/^\$/.test(i)) {
|
||||||
ctor[i.substr(1)] = methods[i];
|
ctor[i.substr(1)] = methods[i];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user