🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

jsdc

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdc - npm Package Compare versions

Comparing version

to
0.5.5

4

package.json
{
"name": "jsdc",
"version": "0.5.4",
"version": "0.5.5",
"description": "compiler ecmascript6 to ecmascript5",

@@ -55,3 +55,3 @@ "maintainers": [

"dependencies": {
"homunculus": "^0.7.6"
"homunculus": "^0.7.9"
},

@@ -58,0 +58,0 @@ "devDependencies": {

@@ -5,2 +5,3 @@ var homunculus = require('homunculus');

var Class = require('./util/Class');
var eventbus = require('./eventbus');

@@ -10,18 +11,26 @@ var ArrowFn = Class(function(jsdc) {

this.hash = {};
this.scope = [];
}).methods({
parse: function(node) {
//var nid = node.nid();
////遍历查看是否有调用this和arguments,存储引用实现lexical绑定
//this.recursion(node.last(), nid);
//if(this.hash.hasOwnProperty(nid)) {
// var o = this.hash[nid];
// if(o.this) {
// this.jsdc.append('var ' + o.this + '=this;');
// }
// if(o.arguments) {
// this.jsdc.append('var ' + o.arguments + '=arguments;');
// }
//}
this.jsdc.append('function');
},
lexical: function(node) {
var self = this;
var nid = node.nid();
//遍历查看是否有调用this和arguments,存储引用实现lexical绑定
this.find(node, nid);
if(this.hash.hasOwnProperty(nid)) {
var o = this.hash[nid];
eventbus.on(nid, function(node, start) {
if(start) {
if(o.hasOwnProperty('_this')) {
self.jsdc.append('var ' + o._this + '=this;');
}
if(o.hasOwnProperty('_arguments')) {
self.jsdc.append('var ' + o._arguments + '=arguments;');
}
}
});
}
},
params: function(node, start) {

@@ -55,4 +64,17 @@ //默认一个参数需要加()

},
recursion: function(node, nid) {
find: function(node, pid) {
var self = this;
if(!node.isToken()) {
if(node.name() == JsNode.ARROWFN) {
self.recursion(node, node.nid(), pid);
}
else {
node.leaves().forEach(function(leaf) {
self.find(leaf, pid);
});
}
}
},
recursion: function(node, nid, pid) {
var self = this;
if(node.isToken()) {

@@ -63,4 +85,10 @@ var token = node.token();

if(s == 'this' || s == 'arguments') {
this.hash[nid] = this.hash[nid] || {};
this.hash[nid][s] = this.jsdc.uid();
this.hash[pid] = this.hash[pid] || {};
this.hash[pid]['_' + s] = this.hash[pid]['_' + s] || this.jsdc.uid();
self.jsdc.ignore(node, 'arrow1');
eventbus.on(node.nid(), function(node, start) {
if(start) {
self.jsdc.append(self.hash[pid]['_' + s]);
}
});
}

@@ -83,3 +111,3 @@ }

default:
self.recursion(leaf, nid);
self.recursion(leaf, nid, pid);
}

@@ -86,0 +114,0 @@ });

@@ -188,2 +188,5 @@ var homunculus = require('homunculus');

}
else if(content == 'this' || content == 'arguments') {
eventbus.emit(node.nid(), [node, true]);
}
//替换操作会设置ignore属性将其忽略

@@ -190,0 +193,0 @@ if(!token.ignore) {

@@ -17,4 +17,6 @@ var homunculus = require('homunculus');

this.index = [jsdc.res.length];
this.hash2 = {};
}).methods({
parse: function(node) {
this.hash2[node.nid()] = true;
this.recursion(node);

@@ -42,2 +44,17 @@ },

}
//记录lexical绑定的作用域,为arrowFn中的this和arguments替换
if(name == JsNode.FNBODY) {
self.hash2[node.nid()] = true;
}
else if(name == JsNode.WITHSTMT) {
var block = node.leaf(4).first();
if(block.size() > 2) {
var node2 = block.leaf(1);
self.hash2[node2.nid()] = true;
}
}
else if(name == JsNode.ARROWFN) {
var parent = self.closest2(node);
self.jsdc.arrowFn.lexical(parent);
}
node.leaves().forEach(function(leaf) {

@@ -155,2 +172,10 @@ self.recursion(leaf);

},
closest2: function(node) {
var parent = node;
while(parent = parent.parent()) {
if(this.hash2.hasOwnProperty(parent.nid())) {
return parent;
}
}
},
inGen: function(node) {

@@ -157,0 +182,0 @@ var parent = node;

@@ -5,2 +5,3 @@ define(function(require, exports, module){var homunculus = require('homunculus');

var Class = require('./util/Class');
var eventbus = require('./eventbus');

@@ -10,18 +11,26 @@ var ArrowFn = Class(function(jsdc) {

this.hash = {};
this.scope = [];
}).methods({
parse: function(node) {
//var nid = node.nid();
////遍历查看是否有调用this和arguments,存储引用实现lexical绑定
//this.recursion(node.last(), nid);
//if(this.hash.hasOwnProperty(nid)) {
// var o = this.hash[nid];
// if(o.this) {
// this.jsdc.append('var ' + o.this + '=this;');
// }
// if(o.arguments) {
// this.jsdc.append('var ' + o.arguments + '=arguments;');
// }
//}
this.jsdc.append('function');
},
lexical: function(node) {
var self = this;
var nid = node.nid();
//遍历查看是否有调用this和arguments,存储引用实现lexical绑定
this.find(node, nid);
if(this.hash.hasOwnProperty(nid)) {
var o = this.hash[nid];
eventbus.on(nid, function(node, start) {
if(start) {
if(o.hasOwnProperty('_this')) {
self.jsdc.append('var ' + o._this + '=this;');
}
if(o.hasOwnProperty('_arguments')) {
self.jsdc.append('var ' + o._arguments + '=arguments;');
}
}
});
}
},
params: function(node, start) {

@@ -55,4 +64,17 @@ //默认一个参数需要加()

},
recursion: function(node, nid) {
find: function(node, pid) {
var self = this;
if(!node.isToken()) {
if(node.name() == JsNode.ARROWFN) {
self.recursion(node, node.nid(), pid);
}
else {
node.leaves().forEach(function(leaf) {
self.find(leaf, pid);
});
}
}
},
recursion: function(node, nid, pid) {
var self = this;
if(node.isToken()) {

@@ -63,4 +85,10 @@ var token = node.token();

if(s == 'this' || s == 'arguments') {
this.hash[nid] = this.hash[nid] || {};
this.hash[nid][s] = this.jsdc.uid();
this.hash[pid] = this.hash[pid] || {};
this.hash[pid]['_' + s] = this.hash[pid]['_' + s] || this.jsdc.uid();
self.jsdc.ignore(node, 'arrow1');
eventbus.on(node.nid(), function(node, start) {
if(start) {
self.jsdc.append(self.hash[pid]['_' + s]);
}
});
}

@@ -83,3 +111,3 @@ }

default:
self.recursion(leaf, nid);
self.recursion(leaf, nid, pid);
}

@@ -86,0 +114,0 @@ });

@@ -188,2 +188,5 @@ define(function(require, exports, module){var homunculus = require('homunculus');

}
else if(content == 'this' || content == 'arguments') {
eventbus.emit(node.nid(), [node, true]);
}
//替换操作会设置ignore属性将其忽略

@@ -190,0 +193,0 @@ if(!token.ignore) {

@@ -17,4 +17,6 @@ define(function(require, exports, module){var homunculus = require('homunculus');

this.index = [jsdc.res.length];
this.hash2 = {};
}).methods({
parse: function(node) {
this.hash2[node.nid()] = true;
this.recursion(node);

@@ -42,2 +44,17 @@ },

}
//记录lexical绑定的作用域,为arrowFn中的this和arguments替换
if(name == JsNode.FNBODY) {
self.hash2[node.nid()] = true;
}
else if(name == JsNode.WITHSTMT) {
var block = node.leaf(4).first();
if(block.size() > 2) {
var node2 = block.leaf(1);
self.hash2[node2.nid()] = true;
}
}
else if(name == JsNode.ARROWFN) {
var parent = self.closest2(node);
self.jsdc.arrowFn.lexical(parent);
}
node.leaves().forEach(function(leaf) {

@@ -155,2 +172,10 @@ self.recursion(leaf);

},
closest2: function(node) {
var parent = node;
while(parent = parent.parent()) {
if(this.hash2.hasOwnProperty(parent.nid())) {
return parent;
}
}
},
inGen: function(node) {

@@ -157,0 +182,0 @@ var parent = node;

Sorry, the diff of this file is not supported yet