homunculus
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -0,0 +0,0 @@ (function() { |
@@ -0,0 +0,0 @@ var gulp = require('gulp'); |
@@ -0,0 +0,0 @@ var Lexer = require('./src/lexer/Lexer'); |
{ | ||
"name": "homunculus", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -14,2 +14,13 @@ "maintainers": [ | ||
}, | ||
"config": { | ||
"blanket": { | ||
"pattern": ["src/lexer/Lexer", | ||
"src/lexer/Token", | ||
"src/lexer/match", | ||
"src/lexer/rule/Rule", | ||
"src/lexer/rule/EcmascriptRule", | ||
"src/parser/js", | ||
"src/util"] | ||
} | ||
}, | ||
"repository": { | ||
@@ -35,4 +46,7 @@ "type": "git", | ||
"gulp": "^3.6.0", | ||
"expect.js": "^0.3.1" | ||
"expect.js": "^0.3.1", | ||
"blanket": "^1.1.6", | ||
"coveralls": "^2.10.0", | ||
"mocha-lcov-reporter": "0.0.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
A lexer&parser by Javascript | ||
# A lexer&parser by Javascript | ||
@@ -6,2 +6,7 @@ [![NPM version](https://badge.fury.io/js/homunculus.png)](https://npmjs.org/package/homunculus) | ||
[![Coverage Status](https://coveralls.io/repos/army8735/homunculus/badge.png)](https://coveralls.io/r/army8735/homunculus) | ||
[![Dependency Status](https://david-dm.org/army8735/homunculus.png)](https://david-dm.org/army8735/homunculus) | ||
[![Dependency Status](https://david-dm.org/army8735/homunculus.png)](https://david-dm.org/army8735/homunculus) | ||
## INSTALL | ||
``` | ||
npm install homunculus | ||
``` |
@@ -0,0 +0,0 @@ var Lexer = require('./Lexer'); |
@@ -21,7 +21,4 @@ var Class = require('../util/Class'); | ||
}, | ||
parse: function(code, start) { | ||
parse: function(code) { | ||
this.code = code || ''; | ||
if(!character.isUndefined(start)) { | ||
this.totalLine = start; | ||
} | ||
var temp = []; | ||
@@ -198,12 +195,6 @@ this.scan(temp); | ||
} | ||
else if(Lexer.mode() === Lexer.LOOSE && window.console) { | ||
else if(Lexer.mode() === Lexer.LOOSE && !character.isUndefined(console)) { | ||
if(console.warn) { | ||
console.warn(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
else if(console.error) { | ||
console.error(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
else if(console.log) { | ||
console.log(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
} | ||
@@ -210,0 +201,0 @@ return this; |
@@ -0,0 +0,0 @@ var Match = require('./Match'); |
@@ -0,0 +0,0 @@ var Match = require('./Match'); |
@@ -0,0 +0,0 @@ var Match = require('./Match'); |
@@ -0,0 +0,0 @@ var Match = require('./Match'); |
@@ -0,0 +0,0 @@ var Class = require('../../util/Class'); |
@@ -0,0 +0,0 @@ var Match = require('./Match'); |
@@ -0,0 +0,0 @@ var Rule = require('./Rule'); |
@@ -0,0 +0,0 @@ var Rule = require('./Rule'); |
@@ -0,0 +0,0 @@ var Rule = require('./Rule'); |
@@ -0,0 +0,0 @@ var Rule = require('./Rule'); |
@@ -0,0 +0,0 @@ var Class = require('../../util/Class'); |
@@ -0,0 +0,0 @@ var Class = require('../util/Class'); |
@@ -0,0 +0,0 @@ var character = require('../../util/character'); |
@@ -0,0 +0,0 @@ var Class = require('../../util/Class'); |
@@ -0,0 +0,0 @@ var Class = require('../../util/Class'); |
@@ -0,0 +0,0 @@ var Class = require('../../util/Class'); |
@@ -132,2 +132,5 @@ var Class = require('../../util/Class'); | ||
getKey: function(s) { | ||
if(!s) { | ||
throw new Error('empty value'); | ||
} | ||
if(!keys) { | ||
@@ -134,0 +137,0 @@ var self = this; |
@@ -76,12 +76,8 @@ var Class = require('../../util/Class'); | ||
return this.varstmt(); | ||
break; | ||
case '{': | ||
return this.block(); | ||
break; | ||
case ';': | ||
return this.emptstmt(); | ||
break; | ||
case 'if': | ||
return this.ifstmt(); | ||
break; | ||
case 'do': | ||
@@ -91,27 +87,18 @@ case 'while': | ||
return this.iterstmt(); | ||
break; | ||
case 'continue': | ||
return this.cntnstmt(); | ||
break; | ||
case 'break': | ||
return this.brkstmt(); | ||
break; | ||
case 'return': | ||
return this.retstmt(); | ||
break; | ||
case 'with': | ||
return this.withstmt(); | ||
break; | ||
case 'switch': | ||
return this.swchstmt(); | ||
break; | ||
case 'throw': | ||
return this.thrstmt(); | ||
break; | ||
case 'try': | ||
return this.trystmt(); | ||
break; | ||
case 'debugger': | ||
return this.debstmt(); | ||
break; | ||
case 'super': | ||
@@ -255,5 +242,2 @@ if(!allowSuper) { | ||
var node = new Node(Node.ITERSTMT); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
switch(this.look.content()) { | ||
@@ -1008,5 +992,2 @@ case 'do': | ||
leftexpr: function() { | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
if(this.look.content() == 'new') { | ||
@@ -1103,5 +1084,2 @@ return this.newexpr(); | ||
var node = new Node(Node.MMBEXPR); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
var mmb; | ||
@@ -1142,5 +1120,2 @@ if(this.look.content() == 'function') { | ||
var node = new Node(Node.PRMREXPR); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
switch(this.look.type()) { | ||
@@ -1417,3 +1392,3 @@ case Token.ID: | ||
msg = 'SyntaxError: ' + (msg || ' syntax error'); | ||
throw new Error(msg + ' line ' + this.lastLine + ' col ' + this.lastCol + ' index ' + this.look.sIndex()); | ||
throw new Error(msg + ' line ' + this.lastLine + ' col ' + this.lastCol); | ||
}, | ||
@@ -1420,0 +1395,0 @@ ignore: function() { |
@@ -52,12 +52,2 @@ exports.LINE = '\n'; | ||
return Object.prototype.toString.call(s) == "[object Number]"; | ||
}; | ||
exports.escapeHTML = function(str) { | ||
var xmlchar = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>' | ||
}; | ||
return str.replace(/[<>&]/g, function($1){ | ||
return xmlchar[$1]; | ||
}); | ||
}; |
@@ -0,0 +0,0 @@ function inheritPrototype(subType, superType) { |
@@ -0,0 +0,0 @@ function quickSort(arr, begin, end, compare) { |
@@ -0,0 +0,0 @@ var homunculus = require('../homunculus'); |
@@ -0,0 +0,0 @@ var homunculus = require('../homunculus'); |
@@ -7,2 +7,5 @@ var homunculus = require('../homunculus'); | ||
var Token = homunculus.getClass('token', 'js'); | ||
var Lexer = homunculus.getClass('lexer', 'js'); | ||
function join(tokens) { | ||
@@ -27,2 +30,8 @@ var arr = tokens.map(function(token) { | ||
}); | ||
it('string literal no end', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
expect(function() { | ||
lexer.parse('"sdfsdf'); | ||
}).to.throwError(); | ||
}); | ||
it('id and sign in var stmt', function() { | ||
@@ -53,2 +62,14 @@ var lexer = homunculus.getLexer('js'); | ||
}); | ||
it('perl style regular with unknow flag', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
expect(function() { | ||
lexer.parse('/reg/op;'); | ||
}).to.throwError(); | ||
}); | ||
it('perl style regular no end 2', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
expect(function() { | ||
lexer.parse('/reg'); | ||
}).to.throwError(); | ||
}); | ||
it('signle line comment', function() { | ||
@@ -74,2 +95,8 @@ var lexer = homunculus.getLexer('js'); | ||
}); | ||
it('unknow token', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
expect(function() { | ||
lexer.parse('€'); | ||
}).to.throwError(); | ||
}); | ||
}); | ||
@@ -176,2 +203,62 @@ describe('complex test', function() { | ||
}); | ||
describe('other tests', function() { | ||
it('Token#type', function() { | ||
expect(Token.type(18)).to.eql('IMPORTANT'); | ||
}); | ||
it('Token#content', function() { | ||
var token = new Token(Token.STRING, '', 0); | ||
token.content('a'); | ||
expect(token.content()).eql('a'); | ||
}); | ||
it('Token#val', function() { | ||
var token = new Token(Token.STRING, '', 0); | ||
token.val('a'); | ||
expect(token.val()).eql('a'); | ||
}); | ||
it('Token#tag', function() { | ||
var token = new Token(Token.NUMBER, '', 0); | ||
token.tag(Token.STRING); | ||
expect(token.tag()).eql('STRING'); | ||
}); | ||
it('Token#tid', function() { | ||
var token = new Token(Token.NUMBER, '', 0); | ||
token.tid(0); | ||
expect(token.tid()).eql(0); | ||
}); | ||
it('Token#sIndex', function() { | ||
var token = new Token(Token.NUMBER, '', 0); | ||
token.sIndex(1); | ||
expect(token.sIndex()).eql(1); | ||
}); | ||
it('cache parse', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
lexer.cache(1); | ||
lexer.parse('var a;\nvar b;'); | ||
expect(lexer.finish()).to.not.ok(); | ||
expect(lexer.line()).to.be(2); | ||
lexer.parseOn(); | ||
expect(lexer.finish()).to.ok(); | ||
expect(lexer.col()).to.be(7); | ||
}); | ||
it('mode test', function() { | ||
expect(Lexer.mode()).to.eql(Lexer.STRICT); | ||
Lexer.mode(Lexer.LOOSE); | ||
expect(Lexer.mode()).to.eql(Lexer.LOOSE); | ||
Lexer.mode(Lexer.STRICT); | ||
}); | ||
it('mode error in strict', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
expect(function() { | ||
lexer.parse('0.3E'); | ||
}).to.throwError(); | ||
}); | ||
it('mode console in loose', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
Lexer.mode(Lexer.LOOSE); | ||
expect(function() { | ||
lexer.parse('0.3E'); | ||
}).to.not.throwError(); | ||
Lexer.mode(Lexer.STRICT); | ||
}); | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ //javascript |
@@ -0,0 +0,0 @@ ["//javascript", |
@@ -0,0 +0,0 @@ // Simple JavaScript Templating |
@@ -0,0 +0,0 @@ ["// Simple JavaScript Templating", |
@@ -0,0 +0,0 @@ function f(test) { |
@@ -0,0 +0,0 @@ ["function", |
@@ -8,2 +8,3 @@ var homunculus = require('../homunculus'); | ||
var Token = homunculus.getClass('token'); | ||
var Parser = homunculus.getClass('parser', 'js'); | ||
var JsNode = homunculus.getClass('node', 'js'); | ||
@@ -105,2 +106,13 @@ | ||
}); | ||
it('newexpr 6', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('new A()[1]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",")"]],"[",JsNode.PRMREXPR,["1"],"]"]]]]); | ||
}); | ||
it('newexpr error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('new'); | ||
}).to.throwError(); | ||
}); | ||
it('mmbexpr 1', function() { | ||
@@ -156,2 +168,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('postfixexpr error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('++'); | ||
}).to.throwError(); | ||
}); | ||
it('fndecl', function() { | ||
@@ -177,2 +195,26 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('fnexpr error 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('(function'); | ||
}).to.throwError(); | ||
}); | ||
it('fnexpr error 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('(function('); | ||
}).to.throwError(); | ||
}); | ||
it('fnexpr error 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('(function(a,'); | ||
}).to.throwError(); | ||
}); | ||
it('fnexpr error 4', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('(function(a,1'); | ||
}).to.throwError(); | ||
}); | ||
it('labelstmt', function() { | ||
@@ -218,2 +260,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('prmrexpr error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('.'); | ||
}).to.throwError(); | ||
}); | ||
it('mmbexpr 1', function() { | ||
@@ -244,2 +292,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('callexpr error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('f('); | ||
}).to.throwError(); | ||
}); | ||
it('unaryexpr 1', function() { | ||
@@ -255,2 +309,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('unaryexpr error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('!'); | ||
}).to.throwError(); | ||
}); | ||
it('mtplexpr 1', function() { | ||
@@ -391,2 +451,19 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('varstmt 4', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a = [{}]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],"]"]]]]]]]); | ||
}); | ||
it('varstmt error 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var') | ||
}).to.throwError(); | ||
}); | ||
it('varstmt error 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var a='); | ||
}).to.throwError(); | ||
}); | ||
it('emptstmt', function() { | ||
@@ -407,2 +484,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('ifstmt missing stmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('if(true)'); | ||
}).to.throwError(); | ||
}); | ||
it('whilestmt 1', function() { | ||
@@ -448,2 +531,62 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('forstmt missing expr', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for('); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(var a'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(var a;'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(var a;a > 10;'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 4', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(a'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 5', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(a;'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 6', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(a;b'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt missing ; 7', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(a;b;'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt with in could not has multi varstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(var a,b in {});'); | ||
}).to.throwError(); | ||
}); | ||
it('forstmt with in first', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('for(in {});'); | ||
}).to.throwError(); | ||
}); | ||
it('cntnstmt 1', function() { | ||
@@ -489,2 +632,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('swchstmt error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('switch(a){else:;}'); | ||
}).to.throwError(); | ||
}); | ||
it('labstmt', function() { | ||
@@ -500,3 +649,3 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('trystmt', function() { | ||
it('trystmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
@@ -506,2 +655,7 @@ var node = parser.parse('try{}catch(e){}finally{}'); | ||
}); | ||
it('trystmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('try{}finally{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]); | ||
}); | ||
it('debstmt', function() { | ||
@@ -517,16 +671,80 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('node parent,prev,next', function() { | ||
it('empty 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a, b;'); | ||
var varstmt = node.leaves()[0]; | ||
var children = varstmt.leaves(); | ||
var a = children[0]; | ||
var b = children[1]; | ||
expect(node.parent()).to.be(null); | ||
expect(a.parent()).to.be(varstmt); | ||
expect(b.parent()).to.be(varstmt); | ||
expect(a.prev()).to.be(null); | ||
expect(a.next()).to.be(b); | ||
expect(b.prev()).to.be(a); | ||
var node = parser.parse(''); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[]]); | ||
}); | ||
it('empty 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse(); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[]]); | ||
}); | ||
it('letstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('let a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.LETSTMT,["let",JsNode.VARDECL,["a"]]]]); | ||
}); | ||
it('letstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('let a, b = 1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.LETSTMT,["let",JsNode.VARDECL,["a"],",",JsNode.VARDECL,["b",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]]]]); | ||
}); | ||
it('cststmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('const a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CSTSTMT,["const",JsNode.VARDECL,["a"]]]]); | ||
}); | ||
it('cststmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('const a, b = 1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CSTSTMT,["const",JsNode.VARDECL,["a"],",",JsNode.VARDECL,["b",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]]]]); | ||
}); | ||
it('class decl', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,[';'],"}"]]]); | ||
}); | ||
it('class extend', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{}class B extends A{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,[],"}"],JsNode.CLASSDECL,["class","B",JsNode.HERITAGE,["extends","A"],"{",JsNode.CLASSBODY,[],"}"]]]); | ||
}); | ||
it('class method', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{ method(param){} }'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,[JsNode.METHOD,["method","(",JsNode.FNPARAMS,["param"],")","{",JsNode.FNBODY,[],"}"]],"}"]]]); | ||
}); | ||
it('class static method', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{ static method(){} }'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,["static",JsNode.METHOD,["method","(",")","{",JsNode.FNBODY,[],"}"]],"}"]]]); | ||
}); | ||
it('class error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('class A'); | ||
}).to.throwError(); | ||
}); | ||
it('class method error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('class A{ method'); | ||
}).to.throwError(); | ||
}); | ||
it('class method duplicate error', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('class A{ A(){} A(){} }'); | ||
}).to.throwError(); | ||
}); | ||
it('set', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{set a(p){}}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,[JsNode.METHOD,["set",JsNode.SETFN,[JsNode.PROPTNAME,["a"],"(",JsNode.PROPTSETS,["p"],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]); | ||
}); | ||
it('get', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('class A{get a(){}}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.CLASSDECL,["class","A","{",JsNode.CLASSBODY,[JsNode.METHOD,["get",JsNode.GETFN,[JsNode.PROPTNAME,["a"],"(",")","{",JsNode.FNBODY,[],"}"]]],"}"]]]); | ||
}); | ||
}); | ||
@@ -591,2 +809,38 @@ describe('js lib exec test', function() { | ||
}); | ||
describe('other test', function() { | ||
it('node parent,prev,next', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a, b;'); | ||
var varstmt = node.leaves()[0]; | ||
var children = varstmt.leaves(); | ||
var a = children[0]; | ||
var b = children[1]; | ||
expect(node.parent()).to.be(null); | ||
expect(a.parent()).to.be(varstmt); | ||
expect(b.parent()).to.be(varstmt); | ||
expect(a.prev()).to.be(null); | ||
expect(a.next()).to.be(b); | ||
expect(b.prev()).to.be(a); | ||
}); | ||
it('#ast should return as parse return', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a, b;'); | ||
expect(node).to.equal(parser.ast()); | ||
}); | ||
it('init class Parser(lexer) with a lexer', function() { | ||
var lexer = homunculus.getLexer('js'); | ||
var parser = new Parser(lexer); | ||
var node = parser.parse('var a, b;'); | ||
expect(node).to.equal(parser.ast()); | ||
expect(function() { | ||
parser.init(); | ||
}).to.not.throwError(); | ||
}); | ||
it('JsNode#getKey', function() { | ||
expect(JsNode.getKey('program')).to.eql('PROGRAM'); | ||
expect(function() { | ||
JsNode.getKey(''); | ||
}).to.throwError(); | ||
}); | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ // Backbone.js 1.1.0 |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ |
@@ -0,0 +0,0 @@ /*! HTML5 Shiv v3.6.1 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */ |
@@ -0,0 +0,0 @@ /*! |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -22,7 +22,4 @@ define(function(require, exports, module) { | ||
}, | ||
parse: function(code, start) { | ||
parse: function(code) { | ||
this.code = code || ''; | ||
if(!character.isUndefined(start)) { | ||
this.totalLine = start; | ||
} | ||
var temp = []; | ||
@@ -199,12 +196,6 @@ this.scan(temp); | ||
} | ||
else if(Lexer.mode() === Lexer.LOOSE && window.console) { | ||
else if(Lexer.mode() === Lexer.LOOSE && !character.isUndefined(console)) { | ||
if(console.warn) { | ||
console.warn(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
else if(console.error) { | ||
console.error(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
else if(console.log) { | ||
console.log(s + ', line ' + this.line() + ' col ' + this.colNum + '\n' + str); | ||
} | ||
} | ||
@@ -211,0 +202,0 @@ return this; |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -133,2 +133,5 @@ define(function(require, exports, module) { | ||
getKey: function(s) { | ||
if(!s) { | ||
throw new Error('empty value'); | ||
} | ||
if(!keys) { | ||
@@ -135,0 +138,0 @@ var self = this; |
@@ -77,12 +77,8 @@ define(function(require, exports, module) { | ||
return this.varstmt(); | ||
break; | ||
case '{': | ||
return this.block(); | ||
break; | ||
case ';': | ||
return this.emptstmt(); | ||
break; | ||
case 'if': | ||
return this.ifstmt(); | ||
break; | ||
case 'do': | ||
@@ -92,27 +88,18 @@ case 'while': | ||
return this.iterstmt(); | ||
break; | ||
case 'continue': | ||
return this.cntnstmt(); | ||
break; | ||
case 'break': | ||
return this.brkstmt(); | ||
break; | ||
case 'return': | ||
return this.retstmt(); | ||
break; | ||
case 'with': | ||
return this.withstmt(); | ||
break; | ||
case 'switch': | ||
return this.swchstmt(); | ||
break; | ||
case 'throw': | ||
return this.thrstmt(); | ||
break; | ||
case 'try': | ||
return this.trystmt(); | ||
break; | ||
case 'debugger': | ||
return this.debstmt(); | ||
break; | ||
case 'super': | ||
@@ -256,5 +243,2 @@ if(!allowSuper) { | ||
var node = new Node(Node.ITERSTMT); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
switch(this.look.content()) { | ||
@@ -1009,5 +993,2 @@ case 'do': | ||
leftexpr: function() { | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
if(this.look.content() == 'new') { | ||
@@ -1104,5 +1085,2 @@ return this.newexpr(); | ||
var node = new Node(Node.MMBEXPR); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
var mmb; | ||
@@ -1143,5 +1121,2 @@ if(this.look.content() == 'function') { | ||
var node = new Node(Node.PRMREXPR); | ||
if(!this.look) { | ||
this.error(); | ||
} | ||
switch(this.look.type()) { | ||
@@ -1418,3 +1393,3 @@ case Token.ID: | ||
msg = 'SyntaxError: ' + (msg || ' syntax error'); | ||
throw new Error(msg + ' line ' + this.lastLine + ' col ' + this.lastCol + ' index ' + this.look.sIndex()); | ||
throw new Error(msg + ' line ' + this.lastLine + ' col ' + this.lastCol); | ||
}, | ||
@@ -1421,0 +1396,0 @@ ignore: function() { |
@@ -54,12 +54,2 @@ define(function(require, exports, module) { | ||
}; | ||
exports.escapeHTML = function(str) { | ||
var xmlchar = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>' | ||
}; | ||
return str.replace(/[<>&]/g, function($1){ | ||
return xmlchar[$1]; | ||
}); | ||
}; | ||
}); |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
@@ -0,0 +0,0 @@ define(function(require, exports, module) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1337087
77
25395
12
6
5