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.5.10 to 0.6.0

2

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

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

@@ -17,2 +17,5 @@ var Token = require('../../lexer/Token');

else {
if([Node.ADDEXPR, Node.MTPLEXPR].indexOf(node.name()) > -1) {
res = false;
}
var leaves = node.leaves();

@@ -19,0 +22,0 @@ leaves.forEach(function(leaf) {

@@ -302,3 +302,3 @@ var IParser = require('../Parser');

node.add(this.match());
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(';'));

@@ -329,3 +329,3 @@ return node;

else {
node2.add(this.match());
node2.add(this.addexpr());
if(this.look && this.look.content() == ':') {

@@ -428,3 +428,3 @@ node2.add(

}
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(';'));

@@ -443,3 +443,3 @@ return node;

|| this.look.type() == Token.VARS)) {
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
}

@@ -456,3 +456,3 @@ node.add(this.match(')'));

|| this.look.type() == Token.VARS)) {
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
}

@@ -569,3 +569,3 @@ }

else {
node.add(this.match());
node.add(this.addexpr());
if(this.look && this.look.content() == ':') {

@@ -623,3 +623,3 @@ node.add(

else {
node.add(this.match([Token.STRING, Token.KEYWORD]));
node.add(this.addexpr([Token.STRING, Token.KEYWORD]));
}

@@ -665,2 +665,16 @@ return node;

break;
case 'calc':
node.add(this.calc());
break;
//这几个语法完全一样
//cycle是toggle的老版本写法
case 'cycle':
case 'toggle':
case 'counter':
case 'attr':
case 'translate':
case 'rect':
case 'translate3d':
node.add(this.counter(s));
break;
case 'linear-gradient':

@@ -674,2 +688,19 @@ case 'repeating-linear-gradient':

break;
case 'alpha':
case 'blur':
case 'chroma':
case 'dropshadow':
case 'fliph':
case 'flipv':
case 'glow':
case 'gray':
case 'invert':
case 'light':
case 'mask':
case 'shadow':
case 'wave':
case 'xray':
case 'dximagetransform.microsoft.gradient':
node.add(this.filter());
break;
default:

@@ -685,3 +716,3 @@ if(s == '(') {

}
node.add(this.match());
node.add(this.addexpr());
break;

@@ -726,2 +757,16 @@ }

break;
case 'calc':
node.add(this.calc());
break;
//这几个语法完全一样
//cycle是toggle的老版本写法
case 'cycle':
case 'toggle':
case 'counter':
case 'attr':
case 'translate':
case 'rect':
case 'translate3d':
node.add(this.counter(s));
break;
case 'linear-gradient':

@@ -735,2 +780,19 @@ case 'repeating-linear-gradient':

break;
case 'alpha':
case 'blur':
case 'chroma':
case 'dropshadow':
case 'fliph':
case 'flipv':
case 'glow':
case 'gray':
case 'invert':
case 'light':
case 'mask':
case 'shadow':
case 'wave':
case 'xray':
case 'dximagetransform.microsoft.gradient':
node.add(this.filter());
break;
default:

@@ -749,3 +811,3 @@ if(s == '(') {

}
node.add(this.match());
node.add(this.addexpr());
break;

@@ -933,3 +995,3 @@ }

},
param: function() {
param: function(expr) {
var node = new Node(Node.PARAM);

@@ -939,3 +1001,3 @@ var s = this.look.content().toLowerCase();

&& [';', '}', ')', ','].indexOf(s) == -1) {
node.add(this.match());
node.add(expr ? this.addexpr() : this.match());
}

@@ -949,3 +1011,3 @@ else {

&& [';', '}', ')', ','].indexOf(this.look.content()) == -1) {
node.add(this.match());
node.add(expr ? this.addexpr() : this.match());
}

@@ -963,3 +1025,13 @@ else {

this.match('('),
this.addexpr(),
this.match(')')
);
return node;
},
calc: function() {
var node = new Node(Node.CALC);
node.add(
this.match(),
this.match('('),
this.addexpr(),
this.match(')')

@@ -969,2 +1041,45 @@ );

},
counter: function(name) {
var node = new Node(Node[name.toUpperCase()]);
node.add(
this.match(),
this.match('('),
this.param(true)
);
while(this.look && this.look.content() == ',') {
node.add(
this.match(),
this.param(true)
);
}
node.add(this.match(')'));
return node;
},
filter: function() {
var node = new Node(Node.FILTER);
var isFn = false;
for(var i = this.index; i < this.length; i++) {
var t = this.tokens[i];
if(!S.hasOwnProperty(t.type())) {
isFn = t.content() == '(';
break;
}
}
if(!isFn) {
return this.match();
}
node.add(
this.match(),
this.match('(')
);
node.add(this.param(true));
while(this.look && this.look.content() == ',') {
node.add(
this.match(),
this.param(true)
);
}
node.add(this.match(')'));
return node;
},
rgb: function(alpha) {

@@ -975,7 +1090,7 @@ var node = new Node(alpha ? Node.RGBA : Node.RGB);

this.match('('),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(','),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -985,3 +1100,3 @@ if(alpha) {

this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -997,11 +1112,12 @@ }

this.match('('),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(',')
);
var isZero = this.look && this.look.content() == '0';
node.add(this.match(Token.NUMBER));
var isVar = this.look && this.look.type() == Token.VARS;
node.add(this.addexpr(Token.NUMBER, true));
if(this.look && this.look.content() == '%') {
node.add(this.match());
}
else if(!isZero) {
else if(!isZero && !isVar) {
this.error();

@@ -1011,7 +1127,8 @@ }

var isZero = this.look && this.look.content() == '0';
node.add(this.match(Token.NUMBER));
var isVar = this.look && this.look.type() == Token.VARS;
node.add(this.addexpr(Token.NUMBER, true));
if(this.look && this.look.content() == '%') {
node.add(this.match());
}
else if(!isZero) {
else if(!isZero && !isVar) {
this.error();

@@ -1022,3 +1139,3 @@ }

this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -1046,3 +1163,3 @@ }

this.match('('),
this.match([Token.VARS, Token.STRING]),
this.addexpr(Token.STRING),
this.match(')')

@@ -1057,6 +1174,89 @@ );

node.add(this.match('('));
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(')'));
return node;
},
addexpr: function(accepts, noUnit) {
if(accepts && !Array.isArray(accepts)) {
accepts = [accepts];
}
if(accepts && accepts.indexOf(Token.VARS) == -1) {
accepts = accepts.concat([Token.VARS]);
}
if(accepts && accepts.indexOf(Token.NUMBER) == -1) {
accepts = accepts.concat([Token.NUMBER]);
}
var node = new Node(Node.ADDEXPR);
var mtplexpr = this.mtplexpr(accepts, noUnit);
if(this.look && ['+', '-'].indexOf(this.look.content()) != -1) {
node.add(mtplexpr);
while(this.look && ['+', '-'].indexOf(this.look.content()) != -1) {
node.add(
this.match(),
this.mtplexpr(accepts, noUnit)
);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
node.add(this.match());
}
}
}
else {
return mtplexpr;
}
return node;
},
mtplexpr: function(accepts, noUnit) {
var node = new Node(Node.MTPLEXPR);
var prmrexpr = this.prmrexpr(accepts, noUnit);
if(this.look && ['*', '/'].indexOf(this.look.content()) != -1) {
node.add(prmrexpr);
while(this.look && ['*', '/'].indexOf(this.look.content()) != -1) {
node.add(
this.match(),
this.prmrexpr(accepts)
);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
node.add(this.match());
}
}
}
else {
return prmrexpr;
}
return node;
},
prmrexpr: function(accepts, noUnit) {
var node = new Node(Node.PRMREXPR);
if(this.look && this.look.content() == '(') {
node.add(
this.match('('),
this.addexpr(accepts, noUnit),
this.match(')')
);
return node;
}
//紧接着的(说明这是个未知的css内置id()
var next = this.tokens[this.index];
if(next && next.content() == '('
&& [Token.PROPERTY, Token.ID].indexOf(this.look.type()) > -1) {
return this.bracket();
}
var temp = this.match(accepts);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
temp = [temp, this.match()];
}
return temp;
},
bracket: function() {
var node = new Node(Node.BRACKET);
node.add(
this.match(),
this.match('(')
);
while(this.look && this.look.content() != ')') {
node.add(this.addexpr());
}
node.add(this.match(')'));
return node;
},
match: function(type, msg) {

@@ -1063,0 +1263,0 @@ //未定义为所有

@@ -17,2 +17,5 @@ define(function(require, exports, module) {var Token = require('../../lexer/Token');

else {
if([Node.ADDEXPR, Node.MTPLEXPR].indexOf(node.name()) > -1) {
res = false;
}
var leaves = node.leaves();

@@ -19,0 +22,0 @@ leaves.forEach(function(leaf) {

@@ -302,3 +302,3 @@ define(function(require, exports, module) {var IParser = require('../Parser');

node.add(this.match());
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(';'));

@@ -329,3 +329,3 @@ return node;

else {
node2.add(this.match());
node2.add(this.addexpr());
if(this.look && this.look.content() == ':') {

@@ -428,3 +428,3 @@ node2.add(

}
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(';'));

@@ -443,3 +443,3 @@ return node;

|| this.look.type() == Token.VARS)) {
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
}

@@ -456,3 +456,3 @@ node.add(this.match(')'));

|| this.look.type() == Token.VARS)) {
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
}

@@ -569,3 +569,3 @@ }

else {
node.add(this.match());
node.add(this.addexpr());
if(this.look && this.look.content() == ':') {

@@ -623,3 +623,3 @@ node.add(

else {
node.add(this.match([Token.STRING, Token.KEYWORD]));
node.add(this.addexpr([Token.STRING, Token.KEYWORD]));
}

@@ -665,2 +665,16 @@ return node;

break;
case 'calc':
node.add(this.calc());
break;
//这几个语法完全一样
//cycle是toggle的老版本写法
case 'cycle':
case 'toggle':
case 'counter':
case 'attr':
case 'translate':
case 'rect':
case 'translate3d':
node.add(this.counter(s));
break;
case 'linear-gradient':

@@ -674,2 +688,19 @@ case 'repeating-linear-gradient':

break;
case 'alpha':
case 'blur':
case 'chroma':
case 'dropshadow':
case 'fliph':
case 'flipv':
case 'glow':
case 'gray':
case 'invert':
case 'light':
case 'mask':
case 'shadow':
case 'wave':
case 'xray':
case 'dximagetransform.microsoft.gradient':
node.add(this.filter());
break;
default:

@@ -685,3 +716,3 @@ if(s == '(') {

}
node.add(this.match());
node.add(this.addexpr());
break;

@@ -726,2 +757,16 @@ }

break;
case 'calc':
node.add(this.calc());
break;
//这几个语法完全一样
//cycle是toggle的老版本写法
case 'cycle':
case 'toggle':
case 'counter':
case 'attr':
case 'translate':
case 'rect':
case 'translate3d':
node.add(this.counter(s));
break;
case 'linear-gradient':

@@ -735,2 +780,19 @@ case 'repeating-linear-gradient':

break;
case 'alpha':
case 'blur':
case 'chroma':
case 'dropshadow':
case 'fliph':
case 'flipv':
case 'glow':
case 'gray':
case 'invert':
case 'light':
case 'mask':
case 'shadow':
case 'wave':
case 'xray':
case 'dximagetransform.microsoft.gradient':
node.add(this.filter());
break;
default:

@@ -749,3 +811,3 @@ if(s == '(') {

}
node.add(this.match());
node.add(this.addexpr());
break;

@@ -933,3 +995,3 @@ }

},
param: function() {
param: function(expr) {
var node = new Node(Node.PARAM);

@@ -939,3 +1001,3 @@ var s = this.look.content().toLowerCase();

&& [';', '}', ')', ','].indexOf(s) == -1) {
node.add(this.match());
node.add(expr ? this.addexpr() : this.match());
}

@@ -949,3 +1011,3 @@ else {

&& [';', '}', ')', ','].indexOf(this.look.content()) == -1) {
node.add(this.match());
node.add(expr ? this.addexpr() : this.match());
}

@@ -963,3 +1025,13 @@ else {

this.match('('),
this.addexpr(),
this.match(')')
);
return node;
},
calc: function() {
var node = new Node(Node.CALC);
node.add(
this.match(),
this.match('('),
this.addexpr(),
this.match(')')

@@ -969,2 +1041,45 @@ );

},
counter: function(name) {
var node = new Node(Node[name.toUpperCase()]);
node.add(
this.match(),
this.match('('),
this.param(true)
);
while(this.look && this.look.content() == ',') {
node.add(
this.match(),
this.param(true)
);
}
node.add(this.match(')'));
return node;
},
filter: function() {
var node = new Node(Node.FILTER);
var isFn = false;
for(var i = this.index; i < this.length; i++) {
var t = this.tokens[i];
if(!S.hasOwnProperty(t.type())) {
isFn = t.content() == '(';
break;
}
}
if(!isFn) {
return this.match();
}
node.add(
this.match(),
this.match('(')
);
node.add(this.param(true));
while(this.look && this.look.content() == ',') {
node.add(
this.match(),
this.param(true)
);
}
node.add(this.match(')'));
return node;
},
rgb: function(alpha) {

@@ -975,7 +1090,7 @@ var node = new Node(alpha ? Node.RGBA : Node.RGB);

this.match('('),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(','),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -985,3 +1100,3 @@ if(alpha) {

this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -997,11 +1112,12 @@ }

this.match('('),
this.match(Token.NUMBER),
this.addexpr(Token.NUMBER),
this.match(',')
);
var isZero = this.look && this.look.content() == '0';
node.add(this.match(Token.NUMBER));
var isVar = this.look && this.look.type() == Token.VARS;
node.add(this.addexpr(Token.NUMBER, true));
if(this.look && this.look.content() == '%') {
node.add(this.match());
}
else if(!isZero) {
else if(!isZero && !isVar) {
this.error();

@@ -1011,7 +1127,8 @@ }

var isZero = this.look && this.look.content() == '0';
node.add(this.match(Token.NUMBER));
var isVar = this.look && this.look.type() == Token.VARS;
node.add(this.addexpr(Token.NUMBER, true));
if(this.look && this.look.content() == '%') {
node.add(this.match());
}
else if(!isZero) {
else if(!isZero && !isVar) {
this.error();

@@ -1022,3 +1139,3 @@ }

this.match(','),
this.match(Token.NUMBER)
this.addexpr(Token.NUMBER)
);

@@ -1046,3 +1163,3 @@ }

this.match('('),
this.match([Token.VARS, Token.STRING]),
this.addexpr(Token.STRING),
this.match(')')

@@ -1057,6 +1174,89 @@ );

node.add(this.match('('));
node.add(this.match([Token.VARS, Token.STRING]));
node.add(this.addexpr(Token.STRING));
node.add(this.match(')'));
return node;
},
addexpr: function(accepts, noUnit) {
if(accepts && !Array.isArray(accepts)) {
accepts = [accepts];
}
if(accepts && accepts.indexOf(Token.VARS) == -1) {
accepts = accepts.concat([Token.VARS]);
}
if(accepts && accepts.indexOf(Token.NUMBER) == -1) {
accepts = accepts.concat([Token.NUMBER]);
}
var node = new Node(Node.ADDEXPR);
var mtplexpr = this.mtplexpr(accepts, noUnit);
if(this.look && ['+', '-'].indexOf(this.look.content()) != -1) {
node.add(mtplexpr);
while(this.look && ['+', '-'].indexOf(this.look.content()) != -1) {
node.add(
this.match(),
this.mtplexpr(accepts, noUnit)
);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
node.add(this.match());
}
}
}
else {
return mtplexpr;
}
return node;
},
mtplexpr: function(accepts, noUnit) {
var node = new Node(Node.MTPLEXPR);
var prmrexpr = this.prmrexpr(accepts, noUnit);
if(this.look && ['*', '/'].indexOf(this.look.content()) != -1) {
node.add(prmrexpr);
while(this.look && ['*', '/'].indexOf(this.look.content()) != -1) {
node.add(
this.match(),
this.prmrexpr(accepts)
);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
node.add(this.match());
}
}
}
else {
return prmrexpr;
}
return node;
},
prmrexpr: function(accepts, noUnit) {
var node = new Node(Node.PRMREXPR);
if(this.look && this.look.content() == '(') {
node.add(
this.match('('),
this.addexpr(accepts, noUnit),
this.match(')')
);
return node;
}
//紧接着的(说明这是个未知的css内置id()
var next = this.tokens[this.index];
if(next && next.content() == '('
&& [Token.PROPERTY, Token.ID].indexOf(this.look.type()) > -1) {
return this.bracket();
}
var temp = this.match(accepts);
if(!noUnit && this.look && this.look.type() == Token.UNITS) {
temp = [temp, this.match()];
}
return temp;
},
bracket: function() {
var node = new Node(Node.BRACKET);
node.add(
this.match(),
this.match('(')
);
while(this.look && this.look.content() != ')') {
node.add(this.addexpr());
}
node.add(this.match(')'));
return node;
},
match: function(type, msg) {

@@ -1063,0 +1263,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