Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homunculus

Package Overview
Dependencies
Maintainers
2
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homunculus - npm Package Compare versions

Comparing version 0.0.16 to 0.0.17

2

package.json
{
"name": "homunculus",
"version": "0.0.16",
"version": "0.0.17",
"description": "A lexer&parser by Javascript",

@@ -5,0 +5,0 @@ "maintainers": [

@@ -11,3 +11,2 @@ var Class = require('../../util/Class');

this.name = name || null; //上下文名称,即函数名,函数表达式为空,全局也为空
this.thisIs = null; //上下文环境中this的值,函数表达式中可能会赋值
this.children = []; //函数声明或函数表达式所产生的上下文

@@ -23,2 +22,3 @@ this.childrenMap = {}; //键是函数名,值是上下文,匿名函数表达式键为cid

this.returns = []; //上下文环境里return语句
this.node = null; //对应的ast的节点
if(!this.isTop()) {

@@ -48,9 +48,2 @@ this.parent.addChild(this);

},
getThis: function() {
return this.thisIs;
},
setThis: function(t) {
this.thisIs = t;
return this;
},
isTop: function() {

@@ -164,2 +157,9 @@ return !this.parent;

return this.vids;
},
getNode: function() {
return this.node;
},
setNode: function(n) {
this.node = n;
return this;
}

@@ -206,2 +206,3 @@ });

var child = new Context(context, v);
child.setNode(node);
var params = node.leaves()[3];

@@ -216,6 +217,7 @@ if(params.name() == JsNode.FNPARAMS) {

var child = new Context(context);
child.setNode(node);
//记录形参
var params;
var v = node.leaves()[1];
if(v.name() == JsNode.TOKEN) {
if(v.token().content() != '(') {
params = node.leaves()[3];

@@ -222,0 +224,0 @@ }

@@ -65,2 +65,37 @@ var homunculus = require('../homunculus');

});
it('fnexpr with name', function() {
var context = homunculus.getContext('js');
context.parse('~function a(){}();');
var first = context.getChildren()[0];
expect(first.getName()).to.be(null);
});
it('fnexpr with params', function() {
var context = homunculus.getContext('js');
context.parse('~function a(b){}();');
var first = context.getChildren()[0];
expect(first.hasParam('b')).to.ok();
});
it('fnexpr in ()', function() {
var context = homunculus.getContext('js');
context.parse('(function a(){})();');
expect(context.getChildren().length).to.be(1);
});
it('fnexpr in () with params', function() {
var context = homunculus.getContext('js');
context.parse('(function(b){})(0);');
var first = context.getChildren()[0];
expect(first.hasParam('b')).to.ok();
});
it('fnexpr in () with params & with name', function() {
var context = homunculus.getContext('js');
context.parse('(function a(b){})();');
var first = context.getChildren()[0];
expect(first.hasParam('b')).to.ok();
});
it('isFnexpr', function() {
var context = homunculus.getContext('js');
context.parse('~function(){}();');
var first = context.getChildren()[0];
expect(first.isFnexpr()).to.ok();
});
it('vid 1', function() {

@@ -108,3 +143,35 @@ var context = homunculus.getContext('js');

});
it('#getParent top', function() {
var context = homunculus.getContext('js');
context.parse('function a(){}');
var first = context.getChild('a');
expect(context.getParent()).to.be(null);
});
it('#getParent child', function() {
var context = homunculus.getContext('js');
context.parse('function a(){}');
var first = context.getChild('a');
expect(first.getParent()).to.be(context);
});
it('#getNode', function() {
var context = homunculus.getContext('js');
context.parse('function a(){}');
var first = context.getChild('a');
var ast = context.parser.ast();
expect(first.getNode()).to.be(ast.leaves()[0]);
});
it('parse ast', function() {
var Context = homunculus.getClass('context', 'js');
var parser = homunculus.getParser('js');
parser.parse('function a(){}');
var context = new Context();
context.parse(parser.ast());
expect(context.hasChild('a')).to.ok();
});
it('#addVid duplicate', function() {
var context = homunculus.getContext('js');
context.parse('a.b = 1;a = 2;');
expect(context.getVids().length).to.be(1);
});
});
});

@@ -12,3 +12,2 @@ define(function(require, exports, module) {

this.name = name || null; //上下文名称,即函数名,函数表达式为空,全局也为空
this.thisIs = null; //上下文环境中this的值,函数表达式中可能会赋值
this.children = []; //函数声明或函数表达式所产生的上下文

@@ -24,2 +23,3 @@ this.childrenMap = {}; //键是函数名,值是上下文,匿名函数表达式键为cid

this.returns = []; //上下文环境里return语句
this.node = null; //对应的ast的节点
if(!this.isTop()) {

@@ -49,9 +49,2 @@ this.parent.addChild(this);

},
getThis: function() {
return this.thisIs;
},
setThis: function(t) {
this.thisIs = t;
return this;
},
isTop: function() {

@@ -165,2 +158,9 @@ return !this.parent;

return this.vids;
},
getNode: function() {
return this.node;
},
setNode: function(n) {
this.node = n;
return this;
}

@@ -207,2 +207,3 @@ });

var child = new Context(context, v);
child.setNode(node);
var params = node.leaves()[3];

@@ -217,6 +218,7 @@ if(params.name() == JsNode.FNPARAMS) {

var child = new Context(context);
child.setNode(node);
//记录形参
var params;
var v = node.leaves()[1];
if(v.name() == JsNode.TOKEN) {
if(v.token().content() != '(') {
params = node.leaves()[3];

@@ -223,0 +225,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc