homunculus
Advanced tools
Comparing version 0.0.14 to 0.0.15
{ | ||
"name": "homunculus", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "A lexer&parser by Javascript", | ||
@@ -32,6 +32,6 @@ "maintainers": [ | ||
"devDependencies": { | ||
"mocha": "^1.17.1", | ||
"gulp": "^3.5.5", | ||
"mocha": "^1.18.2", | ||
"gulp": "^3.6.0", | ||
"expect.js": "^0.3.1" | ||
} | ||
} |
@@ -1,1 +0,6 @@ | ||
A lexer&parser by Javascript | ||
A lexer&parser by Javascript | ||
[![NPM version](https://badge.fury.io/js/homunculus.png)](https://npmjs.org/package/homunculus) | ||
[![Build Status](https://travis-ci.org/army8735/homunculus.svg?branch=master)](https://travis-ci.org/army8735/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) |
@@ -100,2 +100,3 @@ var Class = require('../../util/Class'); | ||
DEBSTMT: 'debstmt', | ||
EXPRSTMT: 'exprstmt', | ||
CACH: 'cach', | ||
@@ -102,0 +103,0 @@ FINL: 'finl', |
@@ -66,3 +66,2 @@ var Class = require('../../util/Class'); | ||
stmt: function(allowSuper) { | ||
var node = new Node(Node.STMT); | ||
if(!this.look) { | ||
@@ -133,3 +132,3 @@ this.error(); | ||
else { | ||
break; | ||
return this.exprstmt(); | ||
} | ||
@@ -139,4 +138,8 @@ } | ||
} | ||
node.add(this.expr(), this.match(';')); | ||
return this.exprstmt(); | ||
} | ||
}, | ||
exprstmt: function() { | ||
var node = new Node(Node.EXPRSTMT); | ||
node.add(this.expr(), this.match(';')); | ||
return node; | ||
@@ -143,0 +146,0 @@ }, |
@@ -82,3 +82,3 @@ var homunculus = require('../homunculus'); | ||
var node = parser.parse('new A'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A']]]]]); | ||
}); | ||
@@ -88,3 +88,3 @@ it('newexpr 2', function() { | ||
var node = parser.parse('new A()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']]]]]); | ||
}); | ||
@@ -94,3 +94,3 @@ it('newexpr 3', function() { | ||
var node = parser.parse('new A().f'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f']]]]); | ||
}); | ||
@@ -100,3 +100,3 @@ it('newexpr 4', function() { | ||
var node = parser.parse('new A().f()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]); | ||
}); | ||
@@ -106,3 +106,3 @@ it('newexpr 5', function() { | ||
var node = parser.parse('new new A().f()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.NEWEXPR, ['new', JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]); | ||
}); | ||
@@ -112,3 +112,3 @@ it('mmbexpr 1', function() { | ||
var node = parser.parse('a.b.c'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b', '.', 'c']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b', '.', 'c']]]]); | ||
}); | ||
@@ -118,3 +118,3 @@ it('mmbexpr 2', function() { | ||
var node = parser.parse('a.b[c]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b', '[', JsNode.PRMREXPR, ['c'], ']']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b', '[', JsNode.PRMREXPR, ['c'], ']']]]]); | ||
}); | ||
@@ -129,3 +129,3 @@ it('returnstmt 1', function() { | ||
var node = parser.parse('return\na'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.STMT, [JsNode.PRMREXPR, ['a']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]); | ||
}); | ||
@@ -135,3 +135,3 @@ it('returnstmt 3', function() { | ||
var node = parser.parse('return/*\n*/a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.STMT, [JsNode.PRMREXPR, ['a']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]); | ||
}); | ||
@@ -151,3 +151,3 @@ it('returnstmt 4', function() { | ||
var node = parser.parse('a++ + b'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.ADDEXPR, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['a'], '++'], '+', JsNode.PRMREXPR, ['b']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['a'], '++'], '+', JsNode.PRMREXPR, ['b']]]]]); | ||
}); | ||
@@ -157,3 +157,3 @@ it('postfixexpr 2', function() { | ||
var node = parser.parse('a\nb++'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['a']], JsNode.STMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']], JsNode.EXPRSTMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]); | ||
}); | ||
@@ -163,3 +163,3 @@ it('postfixexpr 3', function() { | ||
var node = parser.parse('a/*\n*/b++'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['a']], JsNode.STMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']], JsNode.EXPRSTMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]); | ||
}); | ||
@@ -179,3 +179,3 @@ it('fndecl', function() { | ||
var node = parser.parse('~function() {}()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.UNARYEXPR, ['~', JsNode.CALLEXPR, [JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], JsNode.ARGS, ['(', ')']]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['~', JsNode.CALLEXPR, [JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], JsNode.ARGS, ['(', ')']]]]]]); | ||
}); | ||
@@ -185,3 +185,3 @@ it('fnexpr 2', function() { | ||
var node = parser.parse('(function() {})()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['(', JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], ')'], JsNode.ARGS, ['(', ')']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['(', JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], ')'], JsNode.ARGS, ['(', ')']]]]]); | ||
}); | ||
@@ -196,3 +196,3 @@ it('labelstmt', function() { | ||
var node = parser.parse('a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['a']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]); | ||
}); | ||
@@ -202,3 +202,3 @@ it('prmrexpr 2', function() { | ||
var node = parser.parse('true'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['true']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['true']]]]); | ||
}); | ||
@@ -208,3 +208,3 @@ it('prmrexpr 3', function() { | ||
var node = parser.parse('null'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['null']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['null']]]]); | ||
}); | ||
@@ -214,3 +214,3 @@ it('prmrexpr 4', function() { | ||
var node = parser.parse('this'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['this']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['this']]]]); | ||
}); | ||
@@ -220,3 +220,3 @@ it('prmrexpr 5', function() { | ||
var node = parser.parse('false'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ['false']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['false']]]]); | ||
}); | ||
@@ -226,3 +226,3 @@ it('prmrexpr 6', function() { | ||
var node = parser.parse('[]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, [JsNode.ARRLTR, ['[', ']']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, [JsNode.ARRLTR, ['[', ']']]]]]); | ||
}); | ||
@@ -232,3 +232,3 @@ it('prmrexpr 7', function() { | ||
var node = parser.parse('!{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, [JsNode.OBJLTR, ['{', '}']]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, [JsNode.OBJLTR, ['{', '}']]]]]]); | ||
}); | ||
@@ -238,3 +238,3 @@ it('mmbexpr 1', function() { | ||
var node = parser.parse('a.b'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b']]]]); | ||
}); | ||
@@ -244,3 +244,3 @@ it('mmbexpr 2', function() { | ||
var node = parser.parse('a[2]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '[', JsNode.PRMREXPR, ['2'], ']']]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '[', JsNode.PRMREXPR, ['2'], ']']]]]); | ||
}); | ||
@@ -250,3 +250,3 @@ it('callexpr 1', function() { | ||
var node = parser.parse('a()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']]]]]) | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']]]]]) | ||
}); | ||
@@ -256,3 +256,3 @@ it('callexpr 2', function() { | ||
var node = parser.parse('a.b()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b'], JsNode.ARGS, ['(', ')']]]]]) | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b'], JsNode.ARGS, ['(', ')']]]]]) | ||
}); | ||
@@ -262,3 +262,3 @@ it('callexpr 3', function() { | ||
var node = parser.parse('new A().f()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]) | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]) | ||
}); | ||
@@ -268,3 +268,3 @@ it('unaryexpr 1', function() { | ||
var node = parser.parse('typeof a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.UNARYEXPR, ['typeof', JsNode.PRMREXPR, ['a']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['typeof', JsNode.PRMREXPR, ['a']]]]]); | ||
}); | ||
@@ -274,3 +274,3 @@ it('unaryexpr 2', function() { | ||
var node = parser.parse('!!0'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.UNARYEXPR, ['!', JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['0']]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['!', JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['0']]]]]]); | ||
}); | ||
@@ -280,3 +280,3 @@ it('mtplexpr 1', function() { | ||
var node = parser.parse('a * b'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ['a'], '*', JsNode.PRMREXPR, ['b']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ['a'], '*', JsNode.PRMREXPR, ['b']]]]]); | ||
}); | ||
@@ -286,3 +286,3 @@ it('mtplexpr 2', function() { | ||
var node = parser.parse('a() * b[0]'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MTPLEXPR, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']], '*', JsNode.MMBEXPR, [JsNode.PRMREXPR, ['b'], '[', JsNode.PRMREXPR, ['0'], ']']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']], '*', JsNode.MMBEXPR, [JsNode.PRMREXPR, ['b'], '[', JsNode.PRMREXPR, ['0'], ']']]]]]); | ||
}); | ||
@@ -292,3 +292,3 @@ it('mtplexpr 3', function() { | ||
var node = parser.parse('!a * b--'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.MTPLEXPR, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['a']], '*', JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '--']]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['a']], '*', JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '--']]]]]); | ||
}); | ||
@@ -298,3 +298,3 @@ it('addexpr 1', function() { | ||
var node = parser.parse('a + b * 2 - c'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["b"], "*", JsNode.PRMREXPR, ["2"]], "-", JsNode.PRMREXPR, ["c"]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["b"], "*", JsNode.PRMREXPR, ["2"]], "-", JsNode.PRMREXPR, ["c"]]]]]); | ||
}); | ||
@@ -304,3 +304,3 @@ it('addexpr 2', function() { | ||
var node = parser.parse('~a + a++ + ++a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.ADDEXPR, [JsNode.UNARYEXPR, ["~", JsNode.PRMREXPR, ["a"]], "+", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["a"], "++"], "+", JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["a"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.UNARYEXPR, ["~", JsNode.PRMREXPR, ["a"]], "+", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["a"], "++"], "+", JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["a"]]]]]]); | ||
}); | ||
@@ -310,3 +310,3 @@ it('shiftexpr 1', function() { | ||
var node = parser.parse('a>>a+1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["a"], ">>", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.PRMREXPR, ["1"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["a"], ">>", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.PRMREXPR, ["1"]]]]]]); | ||
}); | ||
@@ -316,3 +316,3 @@ it('shiftexpr 2', function() { | ||
var node = parser.parse('a*b>>>c/d<<--e'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.SHIFTEXPR, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["a"], "*", JsNode.PRMREXPR, ["b"]], ">>>", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["c"], "/", JsNode.PRMREXPR, ["d"]], "<<", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["e"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.SHIFTEXPR, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["a"], "*", JsNode.PRMREXPR, ["b"]], ">>>", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["c"], "/", JsNode.PRMREXPR, ["d"]], "<<", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["e"]]]]]]); | ||
}); | ||
@@ -322,3 +322,3 @@ it('reltexpr 1', function() { | ||
var node = parser.parse('a > b'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["b"]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["b"]]]]]); | ||
}); | ||
@@ -328,3 +328,3 @@ it('reltexpr 2', function() { | ||
var node = parser.parse('a <= b+1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "<=", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["1"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "<=", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["1"]]]]]]); | ||
}); | ||
@@ -334,3 +334,3 @@ it('reltexpr 3', function() { | ||
var node = parser.parse('a instanceof new A()'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "instanceof", JsNode.NEWEXPR, ["new", JsNode.PRMREXPR, ["A"], JsNode.ARGS, ["(", ")"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "instanceof", JsNode.NEWEXPR, ["new", JsNode.PRMREXPR, ["A"], JsNode.ARGS, ["(", ")"]]]]]]); | ||
}); | ||
@@ -340,3 +340,3 @@ it('eqexpr 1', function() { | ||
var node = parser.parse('a == 3'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "==", JsNode.PRMREXPR, ["3"]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "==", JsNode.PRMREXPR, ["3"]]]]]); | ||
}); | ||
@@ -346,3 +346,3 @@ it('eqexpr 2', function() { | ||
var node = parser.parse('a == b + 3'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "==", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["3"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "==", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["3"]]]]]]); | ||
}); | ||
@@ -352,3 +352,3 @@ it('eqexpr 3', function() { | ||
var node = parser.parse('a !== b >>> 4'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "!==", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["b"], ">>>", JsNode.PRMREXPR, ["4"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "!==", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["b"], ">>>", JsNode.PRMREXPR, ["4"]]]]]]); | ||
}); | ||
@@ -358,3 +358,3 @@ it('bitandexpr', function() { | ||
var node = parser.parse('void a & --b'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.BITANDEXPR, [JsNode.UNARYEXPR, ["void", JsNode.PRMREXPR, ["a"]], "&", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["b"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITANDEXPR, [JsNode.UNARYEXPR, ["void", JsNode.PRMREXPR, ["a"]], "&", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["b"]]]]]]); | ||
}); | ||
@@ -364,3 +364,3 @@ it('bitxorexpr', function() { | ||
var node = parser.parse('a>1 & b--'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.BITANDEXPR, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["1"]], "&", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["b"], "--"]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITANDEXPR, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["1"]], "&", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["b"], "--"]]]]]); | ||
}); | ||
@@ -370,3 +370,3 @@ it('bitorexpr', function() { | ||
var node = parser.parse('++b | -a'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.BITOREXPR, [JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["b"]], "|", JsNode.UNARYEXPR, ["-", JsNode.PRMREXPR, ["a"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITOREXPR, [JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["b"]], "|", JsNode.UNARYEXPR, ["-", JsNode.PRMREXPR, ["a"]]]]]]); | ||
}); | ||
@@ -376,3 +376,3 @@ it('logandexpr', function() { | ||
var node = parser.parse('a.b && c >> 1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.LOGANDEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ["a"], ".", "b"], "&&", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["c"], ">>", JsNode.PRMREXPR, ["1"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.LOGANDEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ["a"], ".", "b"], "&&", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["c"], ">>", JsNode.PRMREXPR, ["1"]]]]]]); | ||
}); | ||
@@ -382,3 +382,3 @@ it('logorexpr', function() { | ||
var node = parser.parse('a || b && c || d && f'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["a"], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["b"], "&&", JsNode.PRMREXPR, ["c"]], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["d"], "&&", JsNode.PRMREXPR, ["f"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["a"], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["b"], "&&", JsNode.PRMREXPR, ["c"]], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["d"], "&&", JsNode.PRMREXPR, ["f"]]]]]]); | ||
}); | ||
@@ -388,3 +388,3 @@ it('condexpr', function() { | ||
var node = parser.parse('a && b ? false || true : typeof null'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.CNDTEXPR, [JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["a"], "&&", JsNode.PRMREXPR, ["b"]], "?", JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["false"], "||", JsNode.PRMREXPR, ["true"]], ":", JsNode.UNARYEXPR, ["typeof", JsNode.PRMREXPR, ["null"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CNDTEXPR, [JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["a"], "&&", JsNode.PRMREXPR, ["b"]], "?", JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["false"], "||", JsNode.PRMREXPR, ["true"]], ":", JsNode.UNARYEXPR, ["typeof", JsNode.PRMREXPR, ["null"]]]]]]); | ||
}); | ||
@@ -394,3 +394,3 @@ it('assignexpr 1', function() { | ||
var node = parser.parse('a = b = c'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "=", JsNode.PRMREXPR, ["c"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "=", JsNode.PRMREXPR, ["c"]]]]]]); | ||
}); | ||
@@ -400,3 +400,3 @@ it('assignexpr 2', function() { | ||
var node = parser.parse('a += b %= c'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "+=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "%=", JsNode.PRMREXPR, ["c"]]]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "+=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "%=", JsNode.PRMREXPR, ["c"]]]]]]); | ||
}); | ||
@@ -406,3 +406,3 @@ it('expr 1', function() { | ||
var node = parser.parse('(1)'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.STMT, [JsNode.PRMREXPR, ["(", JsNode.PRMREXPR, ["1"], ")"]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ["(", JsNode.PRMREXPR, ["1"], ")"]]]]); | ||
}); | ||
@@ -412,4 +412,144 @@ it('expr 2', function() { | ||
var node = parser.parse('(a, !b, c+d)'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.STMT,[JsNode.PRMREXPR,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]); | ||
}); | ||
it('block', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('{}{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.BLOCK,["{","}"],JsNode.BLOCK,["{","}"]]]); | ||
}); | ||
it('varstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a, b;'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a"],",",JsNode.VARDECL,["b"],";"]]]); | ||
}); | ||
it('varstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a = 1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]]]]); | ||
}); | ||
it('varstmt 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('var a = b = 1'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]]]]]]); | ||
}); | ||
it('emptstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse(';{;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EMPTSTMT,[";"],JsNode.BLOCK,["{",JsNode.EMPTSTMT,[";"],"}"]]]); | ||
}); | ||
it('ifstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('if(true);'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.EMPTSTMT,[";"]]]]); | ||
}); | ||
it('ifstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('if(true){}else if(true){}else{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCK,["{","}"],"else",JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCK,["{","}"],"else",JsNode.BLOCK,["{","}"]]]]]); | ||
}); | ||
it('whilestmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false);'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.EMPTSTMT,[";"]]]]); | ||
}); | ||
it('whilestmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{","}"]]]]); | ||
}); | ||
it('dowhilestmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('do;while(false)'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["do",JsNode.EMPTSTMT,[";"],"while","(",JsNode.PRMREXPR,["false"],")"]]]); | ||
}); | ||
it('dowhilestmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('do{}while(false)'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["do",JsNode.BLOCK,["{","}"],"while","(",JsNode.PRMREXPR,["false"],")"]]]); | ||
}); | ||
it('forstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('for(;;){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",";",";",")",JsNode.BLOCK,["{","}"]]]]); | ||
}); | ||
it('forstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('for(var a = 1; a < len; a++){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]],";",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<",JsNode.PRMREXPR,["len"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],")",JsNode.BLOCK,["{","}"]]]]); | ||
}); | ||
it('forstmt 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('for(o in {});'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,["o"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]); | ||
}); | ||
it('forstmt 4', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('for(var k in {}){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,["k"]],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.BLOCK,["{","}"]]]]); | ||
}); | ||
it('cntnstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){continue;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue",";"],"}"]]]]); | ||
}); | ||
it('cntnstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){continue a;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue","a",";"],"}"]]]]); | ||
}); | ||
it('cntnstmt 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){continue\na;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]); | ||
}); | ||
it('brkstmt 1', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){break;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break",";"],"}"]]]]); | ||
}); | ||
it('brkstmt 2', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){break a;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break","a",";"],"}"]]]]); | ||
}); | ||
it('brkstmt 3', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('while(false){break\na;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]); | ||
}); | ||
it('withstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('with(a){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.WITHSTMT,["with","(",JsNode.PRMREXPR,["a"],")",JsNode.BLOCK,["{","}"]]]]); | ||
}); | ||
it('swchstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('switch(a){case 1:case 2:;break;default:;}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.CASECLAUSE,["case",JsNode.PRMREXPR,["1"],":"],JsNode.CASECLAUSE,["case",JsNode.PRMREXPR,["2"],":",JsNode.EMPTSTMT,[";"],JsNode.BRKSTMT,["break",";"]],JsNode.DFTCLAUSE,["default",":",JsNode.EMPTSTMT,[";"]],"}"]]]]); | ||
}); | ||
it('labstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('label:;'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.LABSTMT,["label",":",JsNode.EMPTSTMT,[";"]]]]); | ||
}); | ||
it('thrstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('throw e;'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.THRSTMT,["throw",JsNode.PRMREXPR,["e"],";"]]]); | ||
}); | ||
it('trystmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('try{}catch(e){}finally{}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.CACH,["catch","(","e",")",JsNode.BLOCK,["{","}"]],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]); | ||
}); | ||
it('debstmt', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('debugger;'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.DEBSTMT,["debugger",";"]]]); | ||
}); | ||
it('fndecl', function() { | ||
var parser = homunculus.getParser('js'); | ||
var node = parser.parse('function a(b, c = 1, ...d){}'); | ||
expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.FNDECL,["function","a","(",JsNode.FNPARAMS,["b",",","c",JsNode.BINDELEMENT,["=",JsNode.PRMREXPR,["1"]],",",JsNode.RESTPARAM,["...","d"]],")","{",JsNode.FNBODY,[],"}"]]]); | ||
}); | ||
it('node parent,prev,next', function() { | ||
@@ -416,0 +556,0 @@ var parser = homunculus.getParser('js'); |
@@ -101,2 +101,3 @@ define(function(require, exports, module) { | ||
DEBSTMT: 'debstmt', | ||
EXPRSTMT: 'exprstmt', | ||
CACH: 'cach', | ||
@@ -103,0 +104,0 @@ FINL: 'finl', |
@@ -67,3 +67,2 @@ define(function(require, exports, module) { | ||
stmt: function(allowSuper) { | ||
var node = new Node(Node.STMT); | ||
if(!this.look) { | ||
@@ -134,3 +133,3 @@ this.error(); | ||
else { | ||
break; | ||
return this.exprstmt(); | ||
} | ||
@@ -140,4 +139,8 @@ } | ||
} | ||
node.add(this.expr(), this.match(';')); | ||
return this.exprstmt(); | ||
} | ||
}, | ||
exprstmt: function() { | ||
var node = new Node(Node.EXPRSTMT); | ||
node.add(this.expr(), this.match(';')); | ||
return node; | ||
@@ -144,0 +147,0 @@ }, |
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
1046942
25137
6