homunculus
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -53,2 +53,3 @@ (function(factory) { | ||
this.hasMoveLine = false; | ||
this.module = false; | ||
this.tree = {}; | ||
@@ -74,11 +75,6 @@ if(lexer) { | ||
node.add(this.modulebody()); | ||
//未出现export时,此script不是一个模块 | ||
var leaves = node.leaf(0).leaves(); | ||
for(i = 0; i < leaves.length; i++) { | ||
if(leaves[i].name() == Node.EXPORTDECL) { | ||
return node; | ||
} | ||
//未出现module,import,export时,此script不是一个模块 | ||
if(!this.module) { | ||
node.leaf(0).name(Node.SCRIPTBODY); | ||
} | ||
node.leaf(0).name(Node.SCRIPTBODY); | ||
return node; | ||
} | ||
@@ -96,8 +92,11 @@ return node; | ||
if(this.look.content() == 'module') { | ||
this.module = true; | ||
return this.moduleimport(); | ||
} | ||
else if(this.look.content() == 'import') { | ||
this.module = true; | ||
return this.importdecl(); | ||
} | ||
else if(this.look.content() == 'export') { | ||
this.module = true; | ||
return this.exportdecl(); | ||
@@ -2007,6 +2006,3 @@ } | ||
} | ||
if(['get', 'set'].indexOf(this.look.content()) > -1) { | ||
node.add(this.method(noIn, noOf)); | ||
} | ||
else if(this.look.content() == '[') { | ||
if(this.look.content() == '[') { | ||
var cmpt = this.cmptpropt(noIn, noOf); | ||
@@ -2035,3 +2031,3 @@ if(!this.look) { | ||
if(!S[next.type()]) { | ||
if(next.content() == '(') { | ||
if([Token.KEYWORD, Token.ID].indexOf(next.type()) > -1 || next.content() == '(') { | ||
node.add(this.method(noIn, noOf)); | ||
@@ -2038,0 +2034,0 @@ end = true; |
{ | ||
"name": "homunculus", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
@@ -45,2 +45,3 @@ var IParser = require('../Parser'); | ||
this.hasMoveLine = false; | ||
this.module = false; | ||
this.tree = {}; | ||
@@ -66,11 +67,6 @@ if(lexer) { | ||
node.add(this.modulebody()); | ||
//未出现export时,此script不是一个模块 | ||
var leaves = node.leaf(0).leaves(); | ||
for(i = 0; i < leaves.length; i++) { | ||
if(leaves[i].name() == Node.EXPORTDECL) { | ||
return node; | ||
} | ||
//未出现module,import,export时,此script不是一个模块 | ||
if(!this.module) { | ||
node.leaf(0).name(Node.SCRIPTBODY); | ||
} | ||
node.leaf(0).name(Node.SCRIPTBODY); | ||
return node; | ||
} | ||
@@ -88,8 +84,11 @@ return node; | ||
if(this.look.content() == 'module') { | ||
this.module = true; | ||
return this.moduleimport(); | ||
} | ||
else if(this.look.content() == 'import') { | ||
this.module = true; | ||
return this.importdecl(); | ||
} | ||
else if(this.look.content() == 'export') { | ||
this.module = true; | ||
return this.exportdecl(); | ||
@@ -1999,6 +1998,3 @@ } | ||
} | ||
if(['get', 'set'].indexOf(this.look.content()) > -1) { | ||
node.add(this.method(noIn, noOf)); | ||
} | ||
else if(this.look.content() == '[') { | ||
if(this.look.content() == '[') { | ||
var cmpt = this.cmptpropt(noIn, noOf); | ||
@@ -2027,3 +2023,3 @@ if(!this.look) { | ||
if(!S[next.type()]) { | ||
if(next.content() == '(') { | ||
if([Token.KEYWORD, Token.ID].indexOf(next.type()) > -1 || next.content() == '(') { | ||
node.add(this.method(noIn, noOf)); | ||
@@ -2030,0 +2026,0 @@ end = true; |
@@ -338,2 +338,7 @@ var homunculus = require('../'); | ||
}); | ||
it('get be an property', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var o = {get:1}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["get",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]); | ||
}); | ||
it('getter error 1', function() { | ||
@@ -363,2 +368,8 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('getter error 5', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var o = {get 3(){}}'); | ||
}).to.throwError(); | ||
}); | ||
it('setter', function() { | ||
@@ -369,2 +380,7 @@ var parser = homunculus.getParser('js'); | ||
}); | ||
it('set be an property', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var o = {set:1}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["set",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]); | ||
}); | ||
it('setter error 1', function() { | ||
@@ -391,2 +407,8 @@ var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var o = {set 4}'); | ||
}).to.throwError(); | ||
}); | ||
it('setter error 5', function() { | ||
var parser = homunculus.getParser('js'); | ||
expect(function() { | ||
parser.parse('var o = {set a(){}}'); | ||
@@ -393,0 +415,0 @@ }).to.throwError(); |
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
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
1294211
33123