How to use getParser method in Appium

Best JavaScript code snippet using appium

es6parser.js

Source:es6parser.js Github

copy

Full Screen

...56}57describe('es6parser', function() {58 describe('simple test', function () {59 it('varstmt no assign', function() {60 var parser = homunculus.getParser('es6');61 var node = parser.parse('var a;');62 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],";"]]]]);63 });64 it('varstmt with assign', function() {65 var parser = homunculus.getParser('es6');66 var node = parser.parse('var a = 1;');67 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);68 });69 it('varstmt with multi', function() {70 var parser = homunculus.getParser('es6');71 var node = parser.parse('var a, b = 1;');72 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);73 });74 it('destructuring array', function() {75 var parser = homunculus.getParser('es6');76 var node = parser.parse('var [a] = [1]');77 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]]]]]]);78 });79 it('destructuring with restparam', function() {80 var parser = homunculus.getParser('es6');81 var node = parser.parse('var [a, ...b] = [1, 2, 3]');82 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],"]"]]]]]]]]);83 });84 it('destructuring with default value', function() {85 var parser = homunculus.getParser('es6');86 var node = parser.parse('var [a = 1, [b] = [2]] = [, []]');87 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["2"],"]"]]]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]],"]"]]]]]]]]);88 });89 it('destructuring object', function() {90 var parser = homunculus.getParser('es6');91 var node = parser.parse('var {x, y = 1, "f": [z]} = {}');92 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["x"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],",",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"f\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["z"]],"]"]]],"}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);93 });94 it('destructuring object with keyword property', function() {95 var parser = homunculus.getParser('es6');96 var node = parser.parse('var {var, f,} = {}');97 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["var"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["f"]]],",","}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);98 });99 it('destructuring complex', function() {100 var parser = homunculus.getParser('es6');101 var node = parser.parse('var [x, {"a":[y=1,{z=2},...o]}] = []');102 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["x"]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"a\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["z"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["2"]]]],"}"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["o"]],"]"]]],"}"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]]]);103 });104 it('destructuring without assign should throw error', function() {105 var parser = homunculus.getParser('es6');106 expect(function() {107 parser.parse('var [a];');108 }).to.throwError();109 });110 it('destructuring array error 1', function() {111 var parser = homunculus.getParser('es6');112 expect(function() {113 parser.parse('var [');114 }).to.throwError();115 });116 it('destructuring array error 1', function() {117 var parser = homunculus.getParser('es6');118 expect(function() {119 parser.parse('var [a');120 }).to.throwError();121 });122 it('destructuring array error 1', function() {123 var parser = homunculus.getParser('es6');124 expect(function() {125 parser.parse('var [a,');126 }).to.throwError();127 });128 it('destructuring array error 2', function() {129 var parser = homunculus.getParser('es6');130 expect(function() {131 parser.parse('var [a,[b]=');132 }).to.throwError();133 });134 it('destructuring object error 1', function() {135 var parser = homunculus.getParser('es6');136 expect(function() {137 parser.parse('var {');138 }).to.throwError();139 });140 it('destructuring object error 2', function() {141 var parser = homunculus.getParser('es6');142 expect(function() {143 parser.parse('var {a');144 }).to.throwError();145 });146 it('destructuring object error 3', function() {147 var parser = homunculus.getParser('es6');148 expect(function() {149 parser.parse('var {!');150 }).to.throwError();151 });152 it('destructuring object error 4', function() {153 var parser = homunculus.getParser('es6');154 expect(function() {155 parser.parse('var {a ');156 }).to.throwError();157 });158 it('destructuring error: kw can not in array 1', function() {159 var parser = homunculus.getParser('es6');160 expect(function() {161 parser.parse('var [var] = [1]');162 }).to.throwError();163 });164 it('destructuring error: kw can not in array 2', function() {165 var parser = homunculus.getParser('es6');166 expect(function() {167 parser.parse('var [x, {"a":[var=1,{z=2},...o]}] = []');168 }).to.throwError();169 });170 it('letdecl 1', function() {171 var parser = homunculus.getParser('es6');172 var node = parser.parse('let a');173 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);174 });175 it('letdecl 2', function() {176 var parser = homunculus.getParser('es6');177 var node = parser.parse('let a, b = 1');178 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);179 });180 it('cstdecl 1', function() {181 var parser = homunculus.getParser('es6');182 var node = parser.parse('const a');183 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);184 });185 it('cstdecl 2', function() {186 var parser = homunculus.getParser('es6');187 var node = parser.parse('const a, b = 1');188 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);189 });190 it('fndecl', function() {191 var parser = homunculus.getParser('es6');192 var node = parser.parse('function a() {}');193 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]);194 });195 it('fndecl with params', function() {196 var parser = homunculus.getParser('es6');197 var node = parser.parse('function a(b,c) {}');198 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"]]],")","{",JsNode.FNBODY,[],"}"]]]]);199 });200 it('fndecl bindelem', function() {201 var parser = homunculus.getParser('es6');202 var node = parser.parse('function a(b, c = 1, ...d){}');203 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDREST,["...",JsNode.BINDID,["d"]]],")","{",JsNode.FNBODY,[],"}"]]]]);204 });205 it('fndecl bindelem 2', function() {206 var parser = homunculus.getParser('es6');207 var node = parser.parse('function a(b, c = d*2){}');208 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["d"],"*",JsNode.PRMREXPR,["2"]]]]],")","{",JsNode.FNBODY,[],"}"]]]]);209 });210 it('fndecl with fnbody', function() {211 var parser = homunculus.getParser('es6');212 var node = parser.parse('function a() {;}');213 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EMPTSTMT,[";"]],"}"]]]]);214 });215 it('fndecl rest', function() {216 var parser = homunculus.getParser('es6');217 var node = parser.parse('function a(...b){}');218 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.BINDREST,["...",JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]]]);219 });220 it('fndecl error 1', function() {221 var parser = homunculus.getParser('es6');222 expect(function() {223 parser.parse('function');224 }).to.throwError();225 });226 it('fndecl error 2', function() {227 var parser = homunculus.getParser('es6');228 expect(function() {229 parser.parse('function a');230 }).to.throwError();231 });232 it('fndecl error 3', function() {233 var parser = homunculus.getParser('es6');234 expect(function() {235 parser.parse('function a(');236 }).to.throwError();237 });238 it('fndecl error 4', function() {239 var parser = homunculus.getParser('es6');240 expect(function() {241 parser.parse('function a()');242 }).to.throwError();243 });244 it('fndecl error 5', function() {245 var parser = homunculus.getParser('es6');246 expect(function() {247 parser.parse('function a() {');248 }).to.throwError();249 });250 it('fnexpr 1', function() {251 var parser = homunculus.getParser('es6');252 var node = parser.parse('~function() {}()');253 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.FNEXPR,["function","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);254 });255 it('fnexpr 2', function() {256 var parser = homunculus.getParser('es6');257 var node = parser.parse('(function a() {})()');258 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.FNEXPR,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);259 });260 it('fnexpr error 1', function() {261 var parser = homunculus.getParser('es6');262 expect(function() {263 parser.parse('(function');264 }).to.throwError();265 });266 it('fnexpr error 2', function() {267 var parser = homunculus.getParser('es6');268 expect(function() {269 parser.parse('(function(');270 }).to.throwError();271 });272 it('fnexpr error 3', function() {273 var parser = homunculus.getParser('es6');274 expect(function() {275 parser.parse('(function(a,');276 }).to.throwError();277 });278 it('fnexpr error 4', function() {279 var parser = homunculus.getParser('es6');280 expect(function() {281 parser.parse('(function(a,1');282 }).to.throwError();283 });284 it('fnparams error', function() {285 var parser = homunculus.getParser('es6');286 expect(function() {287 parser.parse('function a(b,){}');288 }).to.throwError();289 });290 it('args error', function() {291 var parser = homunculus.getParser('es6');292 expect(function() {293 parser.parse('a(b,)');294 }).to.throwError();295 });296 it('gendecl with yield', function() {297 var parser = homunculus.getParser('es6');298 var node = parser.parse('function * a(){yield}');299 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]);300 });301 it('gendecl with var stmt yield', function() {302 var parser = homunculus.getParser('es6');303 var node = parser.parse('function * a(){var a = yield 1}');304 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.YIELDEXPR,["yield",JsNode.PRMREXPR,["1"]]]]]],"}"]]]]);305 });306 it('yield can not in gencmph', function() {307 var parser = homunculus.getParser('es6');308 expect(function() {309 parser.parse('[for(yield of b)yield]');310 }).to.throwError();311 });312 it('yield can not in ungenerator', function() {313 var parser = homunculus.getParser('es6');314 expect(function() {315 parser.parse('function a(){yield}');316 }).to.throwError();317 });318 it('yield can in generator', function() {319 var parser = homunculus.getParser('es6');320 var node = parser.parse('function *a(){if(false)yield;do yield;while(false);for(;;)yield;}');321 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["false"],")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]],JsNode.ITERSTMT,["do",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"],"while","(",JsNode.PRMREXPR,["false"],")",";"],JsNode.ITERSTMT,["for","(",";",";",")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]]],"}"]]]]);322 });323 it('genmethod', function() {324 var parser = homunculus.getParser('es6');325 var node = parser.parse('class A{*method(){}}');326 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.GENMETHOD,["*",JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);327 });328 it('gendecl error 1', function() {329 var parser = homunculus.getParser('es6');330 expect(function() {331 parser.parse('function *');332 }).to.throwError();333 });334 it('gendecl error 2', function() {335 var parser = homunculus.getParser('es6');336 expect(function() {337 parser.parse('function * a');338 }).to.throwError();339 });340 it('gendecl error 3', function() {341 var parser = homunculus.getParser('es6');342 expect(function() {343 parser.parse('function * a(');344 }).to.throwError();345 });346 it('gendecl error 4', function() {347 var parser = homunculus.getParser('es6');348 expect(function() {349 parser.parse('function * a()');350 }).to.throwError();351 });352 it('gendecl error 5', function() {353 var parser = homunculus.getParser('es6');354 expect(function() {355 parser.parse('function * a(){');356 }).to.throwError();357 });358 it('gendecl error 6', function() {359 var parser = homunculus.getParser('es6');360 expect(function() {361 parser.parse('function *(){}');362 }).to.throwError();363 });364 it('yield expr error', function() {365 var parser = homunculus.getParser('es6');366 expect(function() {367 parser.parse('yield');368 }).to.throwError();369 });370 it('genexpr', function() {371 var parser = homunculus.getParser('es6');372 var node = parser.parse('!function * a(){}');373 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]]]);374 });375 it('genexpr with yield', function() {376 var parser = homunculus.getParser('es6');377 var node = parser.parse('!function *(){yield}');378 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]]]]);379 });380 it('genexpr error 1', function() {381 var parser = homunculus.getParser('es6');382 expect(function() {383 parser.parse('!function *');384 }).to.throwError();385 });386 it('genexpr error 2', function() {387 var parser = homunculus.getParser('es6');388 expect(function() {389 parser.parse('!function * a');390 }).to.throwError();391 });392 it('genexpr error 3', function() {393 var parser = homunculus.getParser('es6');394 expect(function() {395 parser.parse('!function * a(');396 }).to.throwError();397 });398 it('genexpr error 4', function() {399 var parser = homunculus.getParser('es6');400 expect(function() {401 parser.parse('!function * a()');402 }).to.throwError();403 });404 it('genexpr error 5', function() {405 var parser = homunculus.getParser('es6');406 expect(function() {407 parser.parse('!function * a(){');408 }).to.throwError();409 });410 it('arrinit error', function() {411 var parser = homunculus.getParser('es6');412 expect(function() {413 parser.parse('[');414 }).to.throwError();415 });416 it('arrltr', function() {417 var parser = homunculus.getParser('es6');418 var node = parser.parse('[,,,2,3,]');419 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",",",",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],",","]"]]]]]]);420 });421 it('arrltr spread', function() {422 var parser = homunculus.getParser('es6');423 var node = parser.parse('[...a]');424 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],"]"]]]]]]);425 });426 it('arrltr multi spread', function() {427 var parser = homunculus.getParser('es6');428 var node = parser.parse('[...a,...b]');429 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],",",JsNode.SPREAD,["...",JsNode.PRMREXPR,["b"]],"]"]]]]]]);430 });431 it('arrltr error', function() {432 var parser = homunculus.getParser('es6');433 expect(function() {434 parser.parse('[,,,2,3,');435 }).to.throwError();436 });437 it('arrcmph no if', function() {438 var parser = homunculus.getParser('es6');439 var node = parser.parse('[for(a of b)a]');440 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);441 });442 it('arrcmph with if', function() {443 var parser = homunculus.getParser('es6');444 var node = parser.parse('[for(a of b)if(a>1)a]');445 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);446 });447 it('arrcmph recursion', function() {448 var parser = homunculus.getParser('es6');449 var node = parser.parse('[for(a of b)if(true)for(c of a)if(false)c]');450 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["true"],")"],JsNode.CMPHFOR,["for","(",JsNode.BINDID,["c"],"of",JsNode.PRMREXPR,["a"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["false"],")"],JsNode.PRMREXPR,["c"]],"]"]]]]]]);451 });452 it('arrcmph forbindpat', function() {453 var parser = homunculus.getParser('es6');454 var node = parser.parse('[for([a,b] of c)a+b]');455 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],"of",JsNode.PRMREXPR,["c"],")"],JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]],"]"]]]]]]);456 });457 it('arrcmph error 1', function() {458 var parser = homunculus.getParser('es6');459 expect(function() {460 parser.parse('[for');461 }).to.throwError();462 });463 it('arrcmph error 2', function() {464 var parser = homunculus.getParser('es6');465 expect(function() {466 parser.parse('[for(');467 }).to.throwError();468 });469 it('arrcmph error 3', function() {470 var parser = homunculus.getParser('es6');471 expect(function() {472 parser.parse('[for(a');473 }).to.throwError();474 });475 it('arrcmph error 4', function() {476 var parser = homunculus.getParser('es6');477 expect(function() {478 parser.parse('[for(a of');479 }).to.throwError();480 });481 it('arrcmph error 5', function() {482 var parser = homunculus.getParser('es6');483 expect(function() {484 parser.parse('[for(a of b');485 }).to.throwError();486 });487 it('arrcmph error 6', function() {488 var parser = homunculus.getParser('es6');489 expect(function() {490 parser.parse('[for(a of b)');491 }).to.throwError();492 });493 it('arrcmph error 7', function() {494 var parser = homunculus.getParser('es6');495 expect(function() {496 parser.parse('[for(a of b)if');497 }).to.throwError();498 });499 it('arrcmph error 8', function() {500 var parser = homunculus.getParser('es6');501 expect(function() {502 parser.parse('[for(a of b)if(');503 }).to.throwError();504 });505 it('arrcmph error 9', function() {506 var parser = homunculus.getParser('es6');507 expect(function() {508 parser.parse('[for(a of b)if(true');509 }).to.throwError();510 });511 it('arrcmph error 10', function() {512 var parser = homunculus.getParser('es6');513 expect(function() {514 parser.parse('[for(a of b)if(true)');515 }).to.throwError();516 });517 it('arrcmph error 11', function() {518 var parser = homunculus.getParser('es6');519 expect(function() {520 parser.parse('[for(a of b)if(true)a');521 }).to.throwError();522 });523 it('objlatr 1', function() {524 var parser = homunculus.getParser('es6');525 var node = parser.parse('({x,y}={"x":1,"y":2})');526 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],"}"]],"=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"x\""]],":",JsNode.PRMREXPR,["1"]],",",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"y\""]],":",JsNode.PRMREXPR,["2"]],"}"]]],")"]]]]]]);527 });528 it('objlatr 2', function() {529 var parser = homunculus.getParser('es6');530 var node = parser.parse('({x,y,[a]})');531 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",",JsNode.PROPTDEF,[JsNode.CMPTPROPT,["[",JsNode.PRMREXPR,["a"],"]"]],"}"]],")"]]]]]]);532 });533 it('objlatr 3', function() {534 var parser = homunculus.getParser('es6');535 var node = parser.parse('!{a(){}}');536 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);537 });538 it('objlatr 4', function() {539 var parser = homunculus.getParser('es6');540 var node = parser.parse('~{x,y,}');541 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",","}"]]]]]]]);542 });543 it('keyword can be obj\'s property', function() {544 var parser = homunculus.getParser('es6');545 var node = parser.parse('var o = {var:1}');546 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);547 });548 it('keyword can not be label', function() {549 var parser = homunculus.getParser('es6');550 expect(function() {551 parser.parse('var:');552 }).to.throwError();553 });554 it('keyword after get/set', function() {555 var parser = homunculus.getParser('es6');556 var node = parser.parse('~{get var(){}}');557 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);558 });559 it('newexpr 1', function() {560 var parser = homunculus.getParser('es6');561 var node = parser.parse('new A');562 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]]]]]]);563 });564 it('newexpr 2', function() {565 var parser = homunculus.getParser('es6');566 var node = parser.parse('new A()');567 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);568 });569 it('newexpr 3', function() {570 var parser = homunculus.getParser('es6');571 var node = parser.parse('new A().f');572 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"]]]]]);573 });574 it('newexpr 4', function() {575 var parser = homunculus.getParser('es6');576 var node = parser.parse('new A().f()');577 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);578 });579 it('newexpr 5', function() {580 var parser = homunculus.getParser('es6');581 var node = parser.parse('new new A().f()');582 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);583 });584 it('newexpr 6', function() {585 var parser = homunculus.getParser('es6');586 var node = parser.parse('new A()[1]');587 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);588 });589 it('newexpr error', function() {590 var parser = homunculus.getParser('es6');591 expect(function() {592 parser.parse('new');593 }).to.throwError();594 });595 it('super 1', function() {596 var parser = homunculus.getParser('es6');597 var node = parser.parse('new super');598 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super"]]]]]);599 });600 it('super 2', function() {601 var parser = homunculus.getParser('es6');602 var node = parser.parse('new super()');603 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);604 });605 it('super 3', function() {606 var parser = homunculus.getParser('es6');607 var node = parser.parse('new super.a');608 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"]]]]]]);609 });610 it('super 4', function() {611 var parser = homunculus.getParser('es6');612 var node = parser.parse('new super.a()');613 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);614 });615 it('super 5', function() {616 var parser = homunculus.getParser('es6');617 var node = parser.parse('new super.a().b');618 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"]]]]]);619 });620 it('super 6', function() {621 var parser = homunculus.getParser('es6');622 var node = parser.parse('super.a');623 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,["super",".","a"]]]]]);624 });625 it('super 7', function() {626 var parser = homunculus.getParser('es6');627 var node = parser.parse('super["a"]()');628 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,["super","[",JsNode.PRMREXPR,["\"a\""],"]"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);629 });630 it('super be an property', function() {631 var parser = homunculus.getParser('es6');632 var node = parser.parse('new a.super');633 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","super"]]]]]]);634 });635 it('super error', function() {636 var parser = homunculus.getParser('es6');637 expect(function() {638 parser.parse('super super');639 }).to.throwError();640 });641 it('super in method', function() {642 var parser = homunculus.getParser('es6');643 expect(function() {644 parser.parse('class A{f(){super()}}');645 }).to.throwError();646 });647 it('super in constructor', function() {648 var parser = homunculus.getParser('es6');649 var node = parser.parse('class A{constructor(){super()}}');650 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["constructor"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,["super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]],"}"]]],"}"]]]]);651 });652 it('mmbexpr 1', function() {653 var parser = homunculus.getParser('es6');654 var node = parser.parse('a.b.c');655 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],".","c"]]]]]);656 });657 it('mmbexpr 2', function() {658 var parser = homunculus.getParser('es6');659 var node = parser.parse('a.b[c]');660 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"[",JsNode.PRMREXPR,["c"],"]"]]]]]);661 });662 it('mmbexpr 3', function() {663 var parser = homunculus.getParser('es6');664 var node = parser.parse('a.b');665 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"]]]]]);666 });667 it('mmbexpr 4', function() {668 var parser = homunculus.getParser('es6');669 var node = parser.parse('a[2]');670 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],"[",JsNode.PRMREXPR,["2"],"]"]]]]]);671 });672 it('mmbexpr error', function() {673 var parser = homunculus.getParser('es6');674 expect(function() {675 parser.parse('a.');676 }).to.throwError();677 });678 it('postfixexpr 1', function() {679 var parser = homunculus.getParser('es6');680 var node = parser.parse('a++ + b');681 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.PRMREXPR,["b"]]]]]]);682 });683 it('postfixexpr 2', function() {684 var parser = homunculus.getParser('es6');685 var node = parser.parse('a\nb++');686 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);687 });688 it('postfixexpr 3', function() {689 var parser = homunculus.getParser('es6');690 var node = parser.parse('a/*\n*/b++');691 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);692 });693 it('postfixexpr 4', function() {694 var parser = homunculus.getParser('es6');695 var node = parser.parse('a++');696 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"]]]]]);697 });698 it('postfixexpr error 1', function() {699 var parser = homunculus.getParser('es6');700 expect(function() {701 parser.parse('a++ ++');702 }).to.throwError();703 });704 it('postfixexpr error 2', function() {705 var parser = homunculus.getParser('es6');706 expect(function() {707 parser.parse('++');708 }).to.throwError();709 });710 it('prmrexpr 1', function() {711 var parser = homunculus.getParser('es6');712 var node = parser.parse('a');713 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);714 });715 it('prmrexpr 2', function() {716 var parser = homunculus.getParser('es6');717 var node = parser.parse('true');718 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["true"]]]]]);719 });720 it('prmrexpr 3', function() {721 var parser = homunculus.getParser('es6');722 var node = parser.parse('null');723 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["null"]]]]]);724 });725 it('prmrexpr 4', function() {726 var parser = homunculus.getParser('es6');727 var node = parser.parse('this');728 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["this"]]]]]);729 });730 it('prmrexpr 5', function() {731 var parser = homunculus.getParser('es6');732 var node = parser.parse('false');733 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["false"]]]]]);734 });735 it('prmrexpr 6', function() {736 var parser = homunculus.getParser('es6');737 var node = parser.parse('[]');738 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]);739 });740 it('prmrexpr 7', function() {741 var parser = homunculus.getParser('es6');742 var node = parser.parse('!{}');743 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]);744 });745 it('prmrexpr error', function() {746 var parser = homunculus.getParser('es6');747 expect(function() {748 parser.parse('.');749 }).to.throwError();750 });751 it('callexpr 1', function() {752 var parser = homunculus.getParser('es6');753 var node = parser.parse('a()');754 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);755 });756 it('callexpr 2', function() {757 var parser = homunculus.getParser('es6');758 var node = parser.parse('a.b()');759 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);760 });761 it('callexpr 3', function() {762 var parser = homunculus.getParser('es6');763 var node = parser.parse('new A().f()');764 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);765 });766 it('callexpr 4', function() {767 var parser = homunculus.getParser('es6');768 var node = parser.parse('f()()');769 expect(tree(node)).to.eql(770 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);771 });772 it('callexpr 5', function() {773 var parser = homunculus.getParser('es6');774 var node = parser.parse('f().b[1]');775 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);776 });777 it('callexpr 6', function() {778 var parser = homunculus.getParser('es6');779 var node = parser.parse('a.b().c.d()');780 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","c"],".","d"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);781 });782 it('callexpr error', function() {783 var parser = homunculus.getParser('es6');784 expect(function() {785 parser.parse('f(');786 }).to.throwError();787 });788 it('unaryexpr 1', function() {789 var parser = homunculus.getParser('es6');790 var node = parser.parse('typeof a');791 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["typeof",JsNode.PRMREXPR,["a"]]]]]]);792 });793 it('unaryexpr 2', function() {794 var parser = homunculus.getParser('es6');795 var node = parser.parse('!!0');796 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["0"]]]]]]]);797 });798 it('unaryexpr error 1', function() {799 var parser = homunculus.getParser('es6');800 expect(function() {801 parser.parse('!');802 }).to.throwError();803 });804 it('unaryexpr error 2', function() {805 var parser = homunculus.getParser('es6');806 expect(function() {807 parser.parse('++ +a');808 }).to.throwError();809 });810 it('mtplexpr 1', function() {811 var parser = homunculus.getParser('es6');812 var node = parser.parse('a * b');813 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.PRMREXPR,["a"],"*",JsNode.PRMREXPR,["b"]]]]]]);814 });815 it('mtplexpr 2', function() {816 var parser = homunculus.getParser('es6');817 var node = parser.parse('a() * b[0]');818 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"*",JsNode.MMBEXPR,[JsNode.PRMREXPR,["b"],"[",JsNode.PRMREXPR,["0"],"]"]]]]]]);819 });820 it('mtplexpr 3', function() {821 var parser = homunculus.getParser('es6');822 var node = parser.parse('!a * b--');823 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["a"]],"*",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);824 });825 it('addexpr 1', function() {826 var parser = homunculus.getParser('es6');827 var node = parser.parse('a + b * 2 - c');828 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["b"],"*",JsNode.PRMREXPR,["2"]],"-",JsNode.PRMREXPR,["c"]]]]]]);829 });830 it('addexpr 2', function() {831 var parser = homunculus.getParser('es6');832 var node = parser.parse('~a + a++ + ++a');833 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,["a"]],"+",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["a"]]]]]]]);834 });835 it('shiftexpr 1', function() {836 var parser = homunculus.getParser('es6');837 var node = parser.parse('a>>a+1');838 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["a"],">>",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["1"]]]]]]]);839 });840 it('shiftexpr 2', function() {841 var parser = homunculus.getParser('es6');842 var node = parser.parse('a*b>>>c/d<<--e');843 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);844 });845 it('reltexpr 1', function() {846 var parser = homunculus.getParser('es6');847 var node = parser.parse('a > b');848 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["b"]]]]]]);849 });850 it('reltexpr 2', function() {851 var parser = homunculus.getParser('es6');852 var node = parser.parse('a <= b+1');853 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<=",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["1"]]]]]]]);854 });855 it('reltexpr 3', function() {856 var parser = homunculus.getParser('es6');857 var node = parser.parse('a instanceof new A()');858 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"instanceof",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);859 });860 it('reltexpr error', function() {861 var parser = homunculus.getParser('es6');862 expect(function() {863 parser.parse('a <');864 }).to.throwError();865 });866 it('eqexpr 1', function() {867 var parser = homunculus.getParser('es6');868 var node = parser.parse('a == 3');869 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"==",JsNode.PRMREXPR,["3"]]]]]]);870 });871 it('eqexpr 2', function() {872 var parser = homunculus.getParser('es6');873 var node = parser.parse('a === b + 3');874 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"===",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["3"]]]]]]]);875 });876 it('eqexpr 3', function() {877 var parser = homunculus.getParser('es6');878 var node = parser.parse('a !== b >>> 4');879 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"!==",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["b"],">>>",JsNode.PRMREXPR,["4"]]]]]]]);880 });881 it('eqexpr error', function() {882 var parser = homunculus.getParser('es6');883 expect(function() {884 parser.parse('a ==');885 }).to.throwError();886 });887 it('bitandexpr', function() {888 var parser = homunculus.getParser('es6');889 var node = parser.parse('void a & --b');890 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITANDEXPR,[JsNode.UNARYEXPR,["void",JsNode.PRMREXPR,["a"]],"&",JsNode.UNARYEXPR,["--",JsNode.PRMREXPR,["b"]]]]]]]);891 });892 it('bitxorexpr', function() {893 var parser = homunculus.getParser('es6');894 var node = parser.parse('a>1 ^ b--');895 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITXOREXPR,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],"^",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);896 });897 it('bitorexpr', function() {898 var parser = homunculus.getParser('es6');899 var node = parser.parse('++b | -a');900 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITOREXPR,[JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["b"]],"|",JsNode.UNARYEXPR,["-",JsNode.PRMREXPR,["a"]]]]]]]);901 });902 it('logandexpr', function() {903 var parser = homunculus.getParser('es6');904 var node = parser.parse('a.b && c >> 1');905 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGANDEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"&&",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["c"],">>",JsNode.PRMREXPR,["1"]]]]]]]);906 });907 it('logorexpr', function() {908 var parser = homunculus.getParser('es6');909 var node = parser.parse('a || b && c || d && f');910 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGOREXPR,[JsNode.PRMREXPR,["a"],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["b"],"&&",JsNode.PRMREXPR,["c"]],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["d"],"&&",JsNode.PRMREXPR,["f"]]]]]]]);911 });912 it('condexpr', function() {913 var parser = homunculus.getParser('es6');914 var node = parser.parse('a && b ? false || true : typeof null');915 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);916 });917 it('assignexpr 1', function() {918 var parser = homunculus.getParser('es6');919 var node = parser.parse('a = b = c');920 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["c"]]]]]]]);921 });922 it('assignexpr 2', function() {923 var parser = homunculus.getParser('es6');924 var node = parser.parse('a += b %= c');925 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"+=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"%=",JsNode.PRMREXPR,["c"]]]]]]]);926 });927 it('assignexpr error', function() {928 var parser = homunculus.getParser('es6');929 expect(function() {930 parser.parse('a + b = c');931 }).to.throwError();932 });933 it('expr 1', function() {934 var parser = homunculus.getParser('es6');935 var node = parser.parse('(1)');936 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["1"],")"]]]]]]);937 });938 it('expr 2', function() {939 var parser = homunculus.getParser('es6');940 var node = parser.parse('(a, !b, c+d)');941 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]]]);942 });943 it('expr 3', function() {944 var parser = homunculus.getParser('es6');945 var node = parser.parse('(a, ...b)');946 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["a"],",","...",JsNode.BINDID,["b"],")"]]]]]]);947 });948 it('expr error 1', function() {949 var parser = homunculus.getParser('es6');950 expect(function() {951 parser.parse('(a,');952 }).to.throwError();953 });954 it('expr error 2', function() {955 var parser = homunculus.getParser('es6');956 expect(function() {957 parser.parse('(a, b');958 }).to.throwError();959 });960 it('expr error 3', function() {961 var parser = homunculus.getParser('es6');962 expect(function() {963 parser.parse('(a...b)');964 }).to.throwError();965 });966 it('expr error 4', function() {967 var parser = homunculus.getParser('es6');968 expect(function() {969 parser.parse('(...a, b)');970 }).to.throwError();971 });972 it('returnstmt 1', function() {973 var parser = homunculus.getParser('es6');974 var node = parser.parse('return a');975 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]]]]]);976 });977 it('returnstmt 2', function() {978 var parser = homunculus.getParser('es6');979 var node = parser.parse('return\na');980 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);981 });982 it('returnstmt 3', function() {983 var parser = homunculus.getParser('es6');984 var node = parser.parse('return/*\n*/a');985 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);986 });987 it('returnstmt 4', function() {988 var parser = homunculus.getParser('es6');989 var node = parser.parse('return a\nreturn');990 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]],JsNode.RETSTMT,["return"]]]]);991 });992 it('returnstmt 5', function() {993 var parser = homunculus.getParser('es6');994 var node = parser.parse('{return}');995 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.RETSTMT,["return"],"}"]]]]]);996 });997 it('labelstmt', function() {998 var parser = homunculus.getParser('es6');999 var node = parser.parse('label:;');1000 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LABSTMT,["label",":",JsNode.EMPTSTMT,[";"]]]]]);1001 });1002 it('block', function() {1003 var parser = homunculus.getParser('es6');1004 var node = parser.parse('{}{}');1005 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]);1006 });1007 it('varstmt 1', function() {1008 var parser = homunculus.getParser('es6');1009 var node = parser.parse('var a, b;');1010 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"]],";"]]]]);1011 });1012 it('varstmt 2', function() {1013 var parser = homunculus.getParser('es6');1014 var node = parser.parse('var a = 1');1015 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);1016 });1017 it('varstmt 3', function() {1018 var parser = homunculus.getParser('es6');1019 var node = parser.parse('var a = b = 1');1020 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]]]]]]]);1021 });1022 it('varstmt 4', function() {1023 var parser = homunculus.getParser('es6');1024 var node = parser.parse('var a = [{}]');1025 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],"]"]]]]]]]]);1026 });1027 it('varstmt error 1', function() {1028 var parser = homunculus.getParser('es6');1029 expect(function() {1030 parser.parse('var')1031 }).to.throwError();1032 });1033 it('varstmt error 2', function() {1034 var parser = homunculus.getParser('es6');1035 expect(function() {1036 parser.parse('var a=');1037 }).to.throwError();1038 });1039 it('emptstmt', function() {1040 var parser = homunculus.getParser('es6');1041 var node = parser.parse(';{;}');1042 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EMPTSTMT,[";"],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.EMPTSTMT,[";"],"}"]]]]]);1043 });1044 it('ifstmt 1', function() {1045 var parser = homunculus.getParser('es6');1046 var node = parser.parse('if(true);');1047 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.EMPTSTMT,[";"]]]]]);1048 });1049 it('ifstmt 2', function() {1050 var parser = homunculus.getParser('es6');1051 var node = parser.parse('if(true){}else if(true){}else{}');1052 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]]);1053 });1054 it('ifstmt missing stmt', function() {1055 var parser = homunculus.getParser('es6');1056 expect(function() {1057 parser.parse('if(true)');1058 }).to.throwError();1059 });1060 it('whilestmt 1', function() {1061 var parser = homunculus.getParser('es6');1062 var node = parser.parse('while(false);');1063 expect(tree(node)).to.eql(1064 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.EMPTSTMT,[";"]]]]]);1065 });1066 it('whilestmt 2', function() {1067 var parser = homunculus.getParser('es6');1068 var node = parser.parse('while(false){}');1069 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1070 });1071 it('dowhilestmt 1', function() {1072 var parser = homunculus.getParser('es6');1073 var node = parser.parse('do;while(false)');1074 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.EMPTSTMT,[";"],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1075 });1076 it('dowhilestmt 2', function() {1077 var parser = homunculus.getParser('es6');1078 var node = parser.parse('do{}while(false)');1079 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1080 });1081 it('dowhilestmt 3', function() {1082 var parser = homunculus.getParser('es6');1083 var node = parser.parse('do{}while(g)/g/g');1084 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"while","(",JsNode.PRMREXPR,["g"],")"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["/g/g"]]]]]);1085 });1086 it('forstmt 1', function() {1087 var parser = homunculus.getParser('es6');1088 var node = parser.parse('for(;;){}');1089 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",";",";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1090 });1091 it('forstmt 2', function() {1092 var parser = homunculus.getParser('es6');1093 var node = parser.parse('for(var a = 1; a < len; a++){}');1094 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],";",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<",JsNode.PRMREXPR,["len"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1095 });1096 it('forstmt 3', function() {1097 var parser = homunculus.getParser('es6');1098 var node = parser.parse('for(o in {});');1099 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,["o"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1100 });1101 it('forstmt 4', function() {1102 var parser = homunculus.getParser('es6');1103 var node = parser.parse('for(var k in {}){}');1104 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.BINDID,["k"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1105 });1106 it('forstmt 5', function() {1107 var parser = homunculus.getParser('es6');1108 var node = parser.parse('for(new A in [1,2]);');1109 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1110 });1111 it('forstmt 6', function() {1112 var parser = homunculus.getParser('es6');1113 var node = parser.parse('for(a.b in [1,2]);');1114 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1115 });1116 it('forstmt 7', function() {1117 var parser = homunculus.getParser('es6');1118 var node = parser.parse('for(new A of [1,2]);');1119 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1120 });1121 it('forstmt 8', function() {1122 var parser = homunculus.getParser('es6');1123 var node = parser.parse('for(a.b of [1,2]);');1124 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1125 });1126 it('forstmt 9', function() {1127 var parser = homunculus.getParser('es6');1128 var node = parser.parse('for(let a in {});');1129 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1130 });1131 it('forstmt 10', function() {1132 var parser = homunculus.getParser('es6');1133 var node = parser.parse('for(var [a] of o){}');1134 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1135 });1136 it('forstmt 11', function() {1137 var parser = homunculus.getParser('es6');1138 var node = parser.parse('for({a,b} of o){}');1139 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["a"],",",JsNode.PROPTDEF,["b"],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1140 });1141 it('forstmt 12', function() {1142 var parser = homunculus.getParser('es6');1143 var node = parser.parse('for(let a of {});');1144 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1145 });1146 it('forstmt 13', function() {1147 var parser = homunculus.getParser('es6');1148 var node = parser.parse('for(let i = 0; i < 2; i++){}');1149 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["i"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["0"]]],";"],JsNode.RELTEXPR,[JsNode.PRMREXPR,["i"],"<",JsNode.PRMREXPR,["2"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["i"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1150 });1151 it('forstmt 14', function() {1152 var parser = homunculus.getParser('es6');1153 var node = parser.parse('for(let [a] = [1];;){}');1154 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]],";"],";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1155 });1156 it('forstmt 15', function() {1157 var parser = homunculus.getParser('es6');1158 var node = parser.parse('for(let a = 1;;);');1159 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"],";",")",JsNode.EMPTSTMT,[";"]]]]]);1160 });1161 it('forstmt 16', function() {1162 var parser = homunculus.getParser('es6');1163 var node = parser.parse('for({a:b=1} of o){}');1164 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],":",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1165 });1166 it('forstmt missing expr', function() {1167 var parser = homunculus.getParser('es6');1168 expect(function() {1169 parser.parse('for(');1170 }).to.throwError();1171 });1172 it('forstmt leftexpr error 1', function() {1173 var parser = homunculus.getParser('js');1174 expect(function() {1175 parser.parse('for(a() in b);');1176 }).to.throwError();1177 });1178 it('forstmt leftexpr error 2', function() {1179 var parser = homunculus.getParser('js');1180 expect(function() {1181 parser.parse('for(a() of b);');1182 }).to.throwError();1183 });1184 it('forstmt let error', function() {1185 var parser = homunculus.getParser('js');1186 expect(function() {1187 parser.parse('for(let ;;);');1188 }).to.throwError();1189 });1190 it('forstmt missing ; 1', function() {1191 var parser = homunculus.getParser('es6');1192 expect(function() {1193 parser.parse('for(var a');1194 }).to.throwError();1195 });1196 it('forstmt missing ; 2', function() {1197 var parser = homunculus.getParser('es6');1198 expect(function() {1199 parser.parse('for(var a;');1200 }).to.throwError();1201 });1202 it('forstmt missing ; 3', function() {1203 var parser = homunculus.getParser('es6');1204 expect(function() {1205 parser.parse('for(var a;a > 10;');1206 }).to.throwError();1207 });1208 it('forstmt missing ; 4', function() {1209 var parser = homunculus.getParser('es6');1210 expect(function() {1211 parser.parse('for(a');1212 }).to.throwError();1213 });1214 it('forstmt missing ; 5', function() {1215 var parser = homunculus.getParser('es6');1216 expect(function() {1217 parser.parse('for(a;');1218 }).to.throwError();1219 });1220 it('forstmt missing ; 6', function() {1221 var parser = homunculus.getParser('es6');1222 expect(function() {1223 parser.parse('for(a;b');1224 }).to.throwError();1225 });1226 it('forstmt missing ; 7', function() {1227 var parser = homunculus.getParser('es6');1228 expect(function() {1229 parser.parse('for(a;b;');1230 }).to.throwError();1231 });1232 it('forstmt with in could not has multi varstmt', function() {1233 var parser = homunculus.getParser('es6');1234 expect(function() {1235 parser.parse('for(var a,b in {});');1236 }).to.throwError();1237 });1238 it('forstmt with in first', function() {1239 var parser = homunculus.getParser('es6');1240 expect(function() {1241 parser.parse('for(in {});');1242 }).to.throwError();1243 });1244 it('cntnstmt 1', function() {1245 var parser = homunculus.getParser('es6');1246 var node = parser.parse('while(false){continue;}');1247 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue",";"],"}"]]]]]]);1248 });1249 it('cntnstmt 2', function() {1250 var parser = homunculus.getParser('es6');1251 var node = parser.parse('while(false){continue a;}');1252 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue","a",";"],"}"]]]]]]);1253 });1254 it('cntnstmt 3', function() {1255 var parser = homunculus.getParser('es6');1256 var node = parser.parse('while(false){continue\na;}');1257 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]]]);1258 });1259 it('brkstmt 1', function() {1260 var parser = homunculus.getParser('es6');1261 var node = parser.parse('while(false){break;}');1262 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break",";"],"}"]]]]]]);1263 });1264 it('brkstmt 2', function() {1265 var parser = homunculus.getParser('es6');1266 var node = parser.parse('while(false){break a;}');1267 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break","a",";"],"}"]]]]]]);1268 });1269 it('brkstmt 3', function() {1270 var parser = homunculus.getParser('es6');1271 var node = parser.parse('while(false){break\na;}');1272 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]]]);1273 });1274 it('swchstmt', function() {1275 var parser = homunculus.getParser('es6');1276 var node = parser.parse('switch(a){case 1:case 2:;break;default:;}');1277 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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,[";"]],"}"]]]]]);1278 });1279 it('caseclause', function() {1280 var parser = homunculus.getParser('es6');1281 var node = parser.parse('switch(a){case 1:let a=1}');1282 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.CASECLAUSE,["case",JsNode.PRMREXPR,["1"],":",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]],"}"]]]]]);1283 });1284 it('defaultstmt', function() {1285 var parser = homunculus.getParser('es6');1286 var node = parser.parse('switch(a){default:case 1:break;}');1287 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.DFTCLAUSE,["default",":","case",JsNode.PRMREXPR,["1"],":",JsNode.BRKSTMT,["break",";"]],"}"]]]]]);1288 });1289 it('withstmt', function() {1290 var parser = homunculus.getParser('es6');1291 var node = parser.parse('with(a){}');1292 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.WITHSTMT,["with","(",JsNode.PRMREXPR,["a"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1293 });1294 it('withstmt error', function() {1295 var parser = homunculus.getParser('es6');1296 expect(function() {1297 parser.parse('with(){}');1298 }).to.throwError();1299 });1300 it('swchstmt error', function() {1301 var parser = homunculus.getParser('es6');1302 expect(function() {1303 parser.parse('switch(a){else:;}');1304 }).to.throwError();1305 });1306 it('thrstmt', function() {1307 var parser = homunculus.getParser('es6');1308 var node = parser.parse('throw e;');1309 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.THRSTMT,["throw",JsNode.PRMREXPR,["e"],";"]]]]);1310 });1311 it('thrstmt error', function() {1312 var parser = homunculus.getParser('es6');1313 expect(function() {1314 parser.parse('throw');1315 }).to.throwError();1316 });1317 it('trystmt 1', function() {1318 var parser = homunculus.getParser('es6');1319 var node = parser.parse('try{}catch(e){}finally{}');1320 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.CACH,["catch","(",JsNode.CACHPARAM,[JsNode.BINDID,["e"]],")",JsNode.BLOCK,["{","}"]],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]]);1321 });1322 it('trystmt 2', function() {1323 var parser = homunculus.getParser('es6');1324 var node = parser.parse('try{}finally{}');1325 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]]);1326 });1327 it('trystmt error 1', function() {1328 var parser = homunculus.getParser('es6');1329 expect(function() {1330 parser.parse('try');1331 }).to.throwError();1332 });1333 it('trystmt error 2', function() {1334 var parser = homunculus.getParser('es6');1335 expect(function() {1336 parser.parse('try{');1337 }).to.throwError();1338 });1339 it('trystmt error 3', function() {1340 var parser = homunculus.getParser('es6');1341 expect(function() {1342 parser.parse('try{}catch');1343 }).to.throwError();1344 });1345 it('trystmt error 4', function() {1346 var parser = homunculus.getParser('es6');1347 expect(function() {1348 parser.parse('try{}catch{');1349 }).to.throwError();1350 });1351 it('trystmt error 5', function() {1352 var parser = homunculus.getParser('es6');1353 expect(function() {1354 parser.parse('try{}catch(');1355 }).to.throwError();1356 });1357 it('trystmt error 6', function() {1358 var parser = homunculus.getParser('es6');1359 expect(function() {1360 parser.parse('try{}catch()');1361 }).to.throwError();1362 });1363 it('trystmt error 7', function() {1364 var parser = homunculus.getParser('js');1365 expect(function() {1366 parser.parse('try{}catch(a,b)');1367 }).to.throwError();1368 });1369 it('trystmt error 8', function() {1370 var parser = homunculus.getParser('es6');1371 expect(function() {1372 parser.parse('try{}catch(a){');1373 }).to.throwError();1374 });1375 it('trystmt error 9', function() {1376 var parser = homunculus.getParser('es6');1377 expect(function() {1378 parser.parse('try{}finally');1379 }).to.throwError();1380 });1381 it('debstmt', function() {1382 var parser = homunculus.getParser('es6');1383 var node = parser.parse('debugger;');1384 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.DEBSTMT,["debugger",";"]]]]);1385 });1386 it('empty 1', function() {1387 var parser = homunculus.getParser('es6');1388 var node = parser.parse('');1389 expect(tree(node)).to.eql([JsNode.SCRIPT,[]]);1390 });1391 it('empty 2', function() {1392 var parser = homunculus.getParser('es6');1393 var node = parser.parse();1394 expect(tree(node)).to.eql([JsNode.SCRIPT,[]]);1395 });1396 it('class 1', function() {1397 var parser= homunculus.getParser('es6');1398 var node = parser.parse('class A{}');1399 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[],"}"]]]]);1400 });1401 it('class 2', function() {1402 var parser= homunculus.getParser('es6');1403 var node = parser.parse('class A{;;}');1404 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[";"],JsNode.CLASSELEM,[";"]],"}"]]]]);1405 });1406 it('class with extends', function() {1407 var parser= homunculus.getParser('es6');1408 var node = parser.parse('class A extends B{}');1409 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],JsNode.HERITAGE,["extends",JsNode.PRMREXPR,["B"]],"{",JsNode.CLASSBODY,[],"}"]]]]);1410 });1411 it('class method', function() {1412 var parser= homunculus.getParser('es6');1413 var node = parser.parse('class A{method(b){}}');1414 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1415 });1416 it('class static', function() {1417 var parser= homunculus.getParser('es6');1418 var node = parser.parse('class A{static method(){}}');1419 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,["static",JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1420 });1421 it('class get', function() {1422 var parser= homunculus.getParser('es6');1423 var node = parser.parse('class A{get a(){return}}');1424 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.RETSTMT,["return"]],"}"]]],"}"]]]]);1425 });1426 it('class set', function() {1427 var parser= homunculus.getParser('es6');1428 var node = parser.parse('class A{set a(b){}}');1429 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,["set",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1430 });1431 it('class error 1', function() {1432 var parser = homunculus.getParser('es6');1433 expect(function() {1434 parser.parse('class');1435 }).to.throwError();1436 });1437 it('class error 2', function() {1438 var parser = homunculus.getParser('es6');1439 expect(function() {1440 parser.parse('class A');1441 }).to.throwError();1442 });1443 it('class error 3', function() {1444 var parser = homunculus.getParser('es6');1445 expect(function() {1446 parser.parse('class A extends');1447 }).to.throwError();1448 });1449 it('class error 4', function() {1450 var parser = homunculus.getParser('es6');1451 expect(function() {1452 parser.parse('class A {');1453 }).to.throwError();1454 });1455 it('class error 4', function() {1456 var parser = homunculus.getParser('es6');1457 expect(function() {1458 parser.parse('class A {get method{');1459 }).to.throwError();1460 });1461 it('classexpr', function() {1462 var parser= homunculus.getParser('es6');1463 var node = parser.parse('!class A extends B{}');1464 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.CLASSEXPR,["class",JsNode.BINDID,["A"],JsNode.HERITAGE,["extends",JsNode.PRMREXPR,["B"]],"{",JsNode.CLASSBODY,[],"}"]]]]]]]);1465 });1466 it('classexpr error 1', function() {1467 var parser = homunculus.getParser('es6');1468 expect(function() {1469 parser.parse('!class A');1470 }).to.throwError();1471 });1472 it('classexpr error 2', function() {1473 var parser = homunculus.getParser('es6');1474 expect(function() {1475 parser.parse('!class A extends');1476 }).to.throwError();1477 });1478 it('classexpr error 3', function() {1479 var parser = homunculus.getParser('es6');1480 expect(function() {1481 parser.parse('!class A {');1482 }).to.throwError();1483 });1484 it('arrowfn 1', function() {1485 var parser= homunculus.getParser('es6');1486 var node = parser.parse('a => a');1487 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,["a"],"=>",JsNode.CNCSBODY,[JsNode.PRMREXPR,["a"]]]]]]]);1488 });1489 it('arrowfn 2', function() {1490 var parser= homunculus.getParser('es6');1491 var node = parser.parse('(a, b) => a + b');1492 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.PRMREXPR,["b"]],")"]],"=>",JsNode.CNCSBODY,[JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]]]]]]]);1493 });1494 it('arrowfn 3', function() {1495 var parser= homunculus.getParser('es6');1496 var node = parser.parse('(a, b) => {;return a-b}');1497 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.PRMREXPR,["b"]],")"]],"=>",JsNode.CNCSBODY,["{",JsNode.FNBODY,[JsNode.EMPTSTMT,[";"],JsNode.RETSTMT,["return",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"-",JsNode.PRMREXPR,["b"]]]],"}"]]]]]]);1498 });1499 it('arrowfn error 1', function() {1500 var parser = homunculus.getParser('es6');1501 expect(function() {1502 parser.parse('a =>');1503 }).to.throwError();1504 });1505 it('arrowfn error 2', function() {1506 var parser = homunculus.getParser('es6');1507 expect(function() {1508 parser.parse('a => {');1509 }).to.throwError();1510 });1511 it('arrowfn error disallowed a line break between ArrowParameters and the ⇒', function() {1512 var parser = homunculus.getParser('es6');1513 expect(function() {1514 parser.parse('(a, b)\n=> a + b');1515 }).to.throwError();1516 });1517 it('module from', function() {1518 var parser = homunculus.getParser('es6');1519 var node = parser.parse('module a from "a"');1520 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.MODULEIMPORT,["module",JsNode.BINDID,["a"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1521 });1522 it('module import', function() {1523 var parser = homunculus.getParser('es6');1524 var node = parser.parse('import "a"');1525 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import","\"a\""]]]]);1526 });1527 it('module import from 1', function() {1528 var parser = homunculus.getParser('es6');1529 var node = parser.parse('import {} from "a"');1530 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,[JsNode.NAMEIMPORT,["{","}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1531 });1532 it('module import from 2', function() {1533 var parser = homunculus.getParser('es6');1534 var node = parser.parse('import {x} from "a"');1535 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,[JsNode.NAMEIMPORT,["{",JsNode.IMPORTSPEC,["x"],"}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1536 });1537 it('module import from 3', function() {1538 var parser = homunculus.getParser('es6');1539 var node = parser.parse('import x from "a"');1540 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,["x"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1541 });1542 it('module import from as', function() {1543 var parser = homunculus.getParser('es6');1544 var node = parser.parse('import x,{y as z,} from "a"');1545 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,["x",",",JsNode.NAMEIMPORT,["{",JsNode.IMPORTSPEC,["y","as",JsNode.BINDID,["z"]],",","}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1546 });1547 it('module export *', function() {1548 var parser = homunculus.getParser('es6');1549 var node = parser.parse('export * from "a"');1550 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export","*",JsNode.FROMCAULSE,["from","\"a\""]]]]]);1551 });1552 it('module export from', function() {1553 var parser = homunculus.getParser('es6');1554 var node = parser.parse('export {x} from "a"');1555 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.EXPORTCAULSE,["{",JsNode.EXPORTSPEC,["x"],"}"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1556 });1557 it('module export error', function() {1558 var parser = homunculus.getParser('es6');1559 expect(function() {1560 parser.parse('export a');1561 }).to.throwError();1562 });1563 it('module var', function() {1564 var parser = homunculus.getParser('es6');1565 var node = parser.parse('export var a = 1');1566 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]]);1567 });1568 it('module decl', function() {1569 var parser = homunculus.getParser('es6');1570 var node = parser.parse('export function *a(){}');1571 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]);1572 });1573 it('module default', function() {1574 var parser = homunculus.getParser('es6');1575 var node = parser.parse('export default a+b');1576 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export","default",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]]]]]);1577 });1578 it('module be an id', function() {1579 var parser = homunculus.getParser('es6');1580 var node = parser.parse('var module');1581 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["module"]]]]]]);1582 });1583 it('module be an object', function() {1584 var parser = homunculus.getParser('es6');1585 var node = parser.parse('module.exports');1586 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["module"],".","exports"]]]]]);1587 });1588 it('module error 1', function() {1589 var parser = homunculus.getParser('es6');1590 expect(function() {1591 parser.parse('module a');1592 }).to.throwError();1593 });1594 it('module error 2', function() {1595 var parser = homunculus.getParser('es6');1596 expect(function() {1597 parser.parse('module a from');1598 }).to.throwError();1599 });1600 it('module error 3', function() {1601 var parser = homunculus.getParser('es6');1602 expect(function() {1603 parser.parse('import');1604 }).to.throwError();1605 });1606 it('module error 4', function() {1607 var parser = homunculus.getParser('es6');1608 expect(function() {1609 parser.parse('import x');1610 }).to.throwError();1611 });1612 it('module error 5', function() {1613 var parser = homunculus.getParser('es6');1614 expect(function() {1615 parser.parse('import x from');1616 }).to.throwError();1617 });1618 it('module error 6', function() {1619 var parser = homunculus.getParser('es6');1620 expect(function() {1621 parser.parse('export');1622 }).to.throwError();1623 });1624 it('module error 7', function() {1625 var parser = homunculus.getParser('es6');1626 expect(function() {1627 parser.parse('export x');1628 }).to.throwError();1629 });1630 it('module error 8', function() {1631 var parser = homunculus.getParser('es6');1632 expect(function() {1633 parser.parse('export "a"');1634 }).to.throwError();1635 });1636 it('module error 9', function() {1637 var parser = homunculus.getParser('es6');1638 expect(function() {1639 parser.parse('export x from');1640 }).to.throwError();1641 });1642 it('module not in global env', function() {1643 var parser = homunculus.getParser('es6');1644 expect(function() {1645 parser.parse('function a() { export * from "xxx" }');1646 }).to.throwError();1647 });1648 it('export module import be property name', function() {1649 var parser = homunculus.getParser('es6');1650 var node = parser.parse('a.export = 1');1651 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","export"],"=",JsNode.PRMREXPR,["1"]]]]]]);1652 });1653 it('getter', function() {1654 var parser = homunculus.getParser('es6');1655 var node = parser.parse('var o = {get a(){}}');1656 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]]);1657 });1658 it('get be an property', function() {1659 var parser = homunculus.getParser('es6');1660 var node = parser.parse('var o = {get:1}');1661 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["get"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);1662 });1663 it('getter error 1', function() {1664 var parser = homunculus.getParser('es6');1665 expect(function() {1666 parser.parse('var o = {get a}');1667 }).to.throwError();1668 });1669 it('getter error 2', function() {1670 var parser = homunculus.getParser('es6');1671 expect(function() {1672 parser.parse('var o = {get a(}');1673 }).to.throwError();1674 });1675 it('getter error 3', function() {1676 var parser = homunculus.getParser('es6');1677 expect(function() {1678 parser.parse('var o = {get a()}');1679 }).to.throwError();1680 });1681 it('getter error 4', function() {1682 var parser = homunculus.getParser('es6');1683 expect(function() {1684 parser.parse('var o = {get 3}');1685 }).to.throwError();1686 });1687 it('setter', function() {1688 var parser = homunculus.getParser('es6');1689 var node = parser.parse('var o = {set a(b){}}');1690 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["set",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]]);1691 });1692 it('set be an property', function() {1693 var parser = homunculus.getParser('es6');1694 var node = parser.parse('var o = {set:1}');1695 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["set"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);1696 });1697 it('setter error 1', function() {1698 var parser = homunculus.getParser('es6');1699 expect(function() {1700 parser.parse('var o = {set a}');1701 }).to.throwError();1702 });1703 it('setter error 2', function() {1704 var parser = homunculus.getParser('es6');1705 expect(function() {1706 parser.parse('var o = {set a(}');1707 }).to.throwError();1708 });1709 it('setter error 3', function() {1710 var parser = homunculus.getParser('es6');1711 expect(function() {1712 parser.parse('var o = {set a()}');1713 }).to.throwError();1714 });1715 it('setter error 4', function() {1716 var parser = homunculus.getParser('es6');1717 expect(function() {1718 parser.parse('var o = {set 3(){}}');1719 }).to.throwError();1720 });1721 it('annot', function() {1722 var parser = homunculus.getParser('es6');1723 var node = parser.parse('class A{@bind test(){} @link(a,b) get v(){}}');1724 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.ANNOT,["@bind"]],JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["test"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],JsNode.CLASSELEM,[JsNode.ANNOT,["@link","(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")"]],JsNode.CLASSELEM,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["v"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1725 });1726 it('class lexbind', function() {1727 var parser = homunculus.getParser('es6');1728 var node = parser.parse('class A{b=1}');1729 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]],"}"]]]]);1730 });1731 it('class lexbind 2', function() {1732 var parser = homunculus.getParser('es6');1733 var node = parser.parse('class A{[b]=[1]}');1734 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.LEXBIND,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]]]],"}"]]]]);1735 });1736 it('class lexbind 3', function() {1737 var parser = homunculus.getParser('es6');1738 var node = parser.parse('class A{{b}={b:1}}');1739 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.LEXBIND,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],"}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["b"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]],"}"]]]]);1740 });1741 it('template', function() {1742 var parser = homunculus.getParser('es6');1743 var node = parser.parse('`template`');1744 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["`template`"]]]]]);1745 });1746 it('template middle', function() {1747 var parser = homunculus.getParser('es6');1748 var node = parser.parse('`template${a}`');1749 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.TEMPLATE,["`template${",JsNode.PRMREXPR,["a"],"}`"]]]]]);1750 });1751 it('template middle2', function() {1752 var parser = homunculus.getParser('es6');1753 var node = parser.parse('`template${a}end`');1754 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.TEMPLATE,["`template${",JsNode.PRMREXPR,["a"],"}end`"]]]]]);1755 });1756 it('template multi middle', function() {1757 var parser = homunculus.getParser('es6');1758 var node = parser.parse('`template${a}b${c}${d}${}`');1759 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.TEMPLATE,["`template${",JsNode.PRMREXPR,["a"],"}b${",JsNode.PRMREXPR,["c"],"}${",JsNode.PRMREXPR,["d"],"}${","}`"]]]]]);1760 });1761 it('template in template', function() {1762 var parser = homunculus.getParser('es6');1763 var node = parser.parse('`template${a+`t${b}`}${c}`');1764 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.TEMPLATE,["`template${",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.TEMPLATE,["`t${",JsNode.PRMREXPR,["b"],"}`"]],"}${",JsNode.PRMREXPR,["c"],"}`"]]]]]);1765 });1766 it('asyncdecl', function() {1767 var parser = homunculus.getParser('es6');1768 var node = parser.parse('async function a() {}');1769 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ASYNCDECL,["async","function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]);1770 });1771 it('asyncdecl2', function() {1772 var parser = homunculus.getParser('es6');1773 var node = parser.parse('async function a(b) {}');1774 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ASYNCDECL,["async","function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]]]);1775 });1776 it('asyncdecl error', function() {1777 var parser = homunculus.getParser('es6');1778 expect(function() {1779 parser.parse('async function a {}');1780 }).to.throwError();1781 });1782 it('asyncarrowfn', function() {1783 var parser = homunculus.getParser('es6');1784 var node = parser.parse('async a => {}');1785 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ASYNCARROWFN,["async",JsNode.BINDID,["a"],"=>","{",JsNode.FNBODY,[],"}"]]]]);1786 });1787 it('asyncarrowfn2', function() {1788 var parser = homunculus.getParser('es6');1789 var node = parser.parse('async () => {}');1790 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ASYNCARROWFN,["async","(",")","=>","{",JsNode.FNBODY,[],"}"]]]]);1791 });1792 it('asyncarrowfn3', function() {1793 var parser = homunculus.getParser('es6');1794 var node = parser.parse('async (a) => {}');1795 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ASYNCARROWFN,["async","(",JsNode.BINDID,["a"],")","=>","{",JsNode.FNBODY,[],"}"]]]]);1796 });1797 it('asyncarrowfn error', function() {1798 var parser = homunculus.getParser('es6');1799 expect(function() {1800 parser.parse('async a() {}');1801 }).to.throwError();1802 });1803 it('asyncexpr', function() {1804 var parser = homunculus.getParser('es6');1805 var node = parser.parse('var a = async function() {}');1806 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASYNCEXPR,["async","function","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]]]);1807 });1808 it('asyncexpr2', function() {1809 var parser = homunculus.getParser('es6');1810 var node = parser.parse('var a = async function(b) {}');1811 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASYNCEXPR,["async","function","(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]]]]]]);1812 });1813 it('asyncexpr3', function() {1814 var parser = homunculus.getParser('es6');1815 var node = parser.parse('var a = async b => {}');1816 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.ASYNCARROWFN,["async",JsNode.BINDID,["b"],"=>","{",JsNode.FNBODY,[],"}"]]]]]]]]);1817 });1818 it('asyncexpr4', function() {1819 var parser = homunculus.getParser('es6');1820 var node = parser.parse('var a = async () => {}');1821 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.ASYNCARROWFN,["async","(",")","=>","{",JsNode.FNBODY,[],"}"]]]]]]]]);1822 });1823 it('asyncexpr5', function() {1824 var parser = homunculus.getParser('es6');1825 var node = parser.parse('var a = async (b) => {}');1826 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.ASYNCARROWFN,["async","(",JsNode.BINDID,["b"],")","=>","{",JsNode.FNBODY,[],"}"]]]]]]]]);1827 });1828 it('asyncmethod', function() {1829 var parser = homunculus.getParser('es6');1830 var node = parser.parse('class A{async a(){}}');1831 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.ASYNCMETHOD,["async",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1832 });1833 it('await', function() {1834 var parser = homunculus.getParser('es6');1835 var node = parser.parse('await a()');1836 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["await",JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);1837 });1838 it('decorator', function() {1839 var parser = homunculus.getParser('es6');1840 var node = parser.parse('@test var a=1;');1841 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ANNOT,["@test"],JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);1842 });1843 it('...obj', function() {1844 var parser = homunculus.getParser('es6');1845 var node = parser.parse('a={...b}');1846 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["...",JsNode.PRMREXPR,["b"]],"}"]]]]]]]);1847 });1848 });1849 describe('js lib exec test', function() {1850 it('jquery 1.11.0', function() {1851 var parser = homunculus.getParser('es6');1852 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.js'), { encoding: 'utf-8' });1853 var node = parser.parse(code);1854 var ignore = parser.ignore();1855 var str = jion(node, ignore);1856 expect(str).to.eql(code);1857 });1858 it('jquery 1.11.0 min', function() {1859 var parser = homunculus.getParser('es6');1860 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.min.js'), { encoding: 'utf-8' });1861 var node = parser.parse(code);1862 var ignore = parser.ignore();1863 var str = jion(node, ignore);1864 expect(str).to.eql(code);1865 });1866 it('backbone 1.1.0', function() {1867 var parser = homunculus.getParser('es6');1868 var code = fs.readFileSync(path.join(__dirname, './lib/backbone.js'), { encoding: 'utf-8' });1869 var node = parser.parse(code);1870 var ignore = parser.ignore();1871 var str = jion(node, ignore);1872 expect(str).to.eql(code);1873 });1874 it('handlebars', function() {1875 var parser = homunculus.getParser('es6');1876 var code = fs.readFileSync(path.join(__dirname, './lib/handlebars.js'), { encoding: 'utf-8' });1877 var node = parser.parse(code);1878 var ignore = parser.ignore();1879 var str = jion(node, ignore);1880 expect(str).to.eql(code);1881 });1882 it('bootstrap 3.0.0', function() {1883 var parser = homunculus.getParser('es6');1884 var code = fs.readFileSync(path.join(__dirname, './lib/bootstrap.js'), { encoding: 'utf-8' });1885 var node = parser.parse(code);1886 var ignore = parser.ignore();1887 var str = jion(node, ignore);1888 expect(str).to.eql(code);1889 });1890 it('expect 0.1.2', function() {1891 var parser = homunculus.getParser('es6');1892 var code = fs.readFileSync(path.join(__dirname, './lib/expect.js'), { encoding: 'utf-8' });1893 var node = parser.parse(code);1894 var ignore = parser.ignore();1895 var str = jion(node, ignore);1896 expect(str).to.eql(code);1897 });1898 it('html5shiv 3.6.1', function() {1899 var parser = homunculus.getParser('es6');1900 var code = fs.readFileSync(path.join(__dirname, './lib/html5shiv.js'), { encoding: 'utf-8' });1901 var node = parser.parse(code);1902 var ignore = parser.ignore();1903 var str = jion(node, ignore);1904 expect(str).to.eql(code);1905 });1906 it('formatter', function() {1907 var parser = homunculus.getParser('es6');1908 var code = fs.readFileSync(path.join(__dirname, './lib/formatter.js'), { encoding: 'utf-8' });1909 var node = parser.parse(code);1910 var ignore = parser.ignore();1911 var str = jion(node, ignore);1912 expect(str).to.eql(code);1913 });1914 });1915 describe('other test', function() {1916 it('node #parent,#prev,#next', function () {1917 var parser = homunculus.getParser('es6');1918 var node = parser.parse('var a, b;');1919 var varstmt = node.leaf(0).leaf(0);1920 var children = varstmt.leaves();1921 var a = children[0];1922 var b = children[1];1923 expect(node.parent()).to.be(null);1924 expect(a.parent()).to.be(varstmt);1925 expect(b.parent()).to.be(varstmt);1926 expect(a.prev()).to.be(null);1927 expect(a.next()).to.be(b);1928 expect(b.prev()).to.be(a);1929 });1930 it('node #leaf,#size,#leaves', function () {1931 var parser = homunculus.getParser('es6');1932 var node = parser.parse('var a');1933 var varstmt = node.leaf(0).leaf(0);1934 expect(varstmt.name()).to.be(JsNode.VARSTMT);1935 expect(varstmt.size()).to.be(3);1936 });1937 it('#ast should return as parse return', function () {1938 var parser = homunculus.getParser('es6');1939 var node = parser.parse('var a, b;');1940 expect(node).to.equal(parser.ast());1941 });1942 it('init class Parser(lexer) with a lexer', function () {1943 var lexer = homunculus.getLexer('es6');1944 var parser = new Parser(lexer);1945 var node = parser.parse('var a, b;');1946 expect(node).to.equal(parser.ast());1947 expect(function () {1948 parser.init();1949 }).to.not.throwError();1950 });1951 it('JsNode#getKey', function () {1952 expect(JsNode.getKey('script')).to.eql('SCRIPT');...

Full Screen

Full Screen

csxparser.js

Source:csxparser.js Github

copy

Full Screen

...56}57describe('csxparser', function() {58 describe('simple test', function () {59 it('varstmt no assign', function() {60 var parser = homunculus.getParser('es6');61 var node = parser.parse('var a;');62 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],";"]]]]);63 });64 it('varstmt with assign', function() {65 var parser = homunculus.getParser('es6');66 var node = parser.parse('var a = 1;');67 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);68 });69 it('varstmt with multi', function() {70 var parser = homunculus.getParser('es6');71 var node = parser.parse('var a, b = 1;');72 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);73 });74 it('destructuring array', function() {75 var parser = homunculus.getParser('es6');76 var node = parser.parse('var [a] = [1]');77 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]]]]]]);78 });79 it('destructuring with restparam', function() {80 var parser = homunculus.getParser('es6');81 var node = parser.parse('var [a, ...b] = [1, 2, 3]');82 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],"]"]]]]]]]]);83 });84 it('destructuring with default value', function() {85 var parser = homunculus.getParser('es6');86 var node = parser.parse('var [a = 1, [b] = [2]] = [, []]');87 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["2"],"]"]]]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]],"]"]]]]]]]]);88 });89 it('destructuring object', function() {90 var parser = homunculus.getParser('es6');91 var node = parser.parse('var {x, y = 1, "f": [z]} = {}');92 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["x"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],",",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"f\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["z"]],"]"]]],"}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);93 });94 it('destructuring object with keyword property', function() {95 var parser = homunculus.getParser('es6');96 var node = parser.parse('var {var, f,} = {}');97 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["var"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["f"]]],",","}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);98 });99 it('destructuring complex', function() {100 var parser = homunculus.getParser('es6');101 var node = parser.parse('var [x, {"a":[y=1,{z=2},...o]}] = []');102 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["x"]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"a\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["z"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["2"]]]],"}"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["o"]],"]"]]],"}"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]]]);103 });104 it('destructuring without assign should throw error', function() {105 var parser = homunculus.getParser('es6');106 expect(function() {107 parser.parse('var [a];');108 }).to.throwError();109 });110 it('destructuring array error 1', function() {111 var parser = homunculus.getParser('es6');112 expect(function() {113 parser.parse('var [');114 }).to.throwError();115 });116 it('destructuring array error 1', function() {117 var parser = homunculus.getParser('es6');118 expect(function() {119 parser.parse('var [a');120 }).to.throwError();121 });122 it('destructuring array error 1', function() {123 var parser = homunculus.getParser('es6');124 expect(function() {125 parser.parse('var [a,');126 }).to.throwError();127 });128 it('destructuring array error 2', function() {129 var parser = homunculus.getParser('es6');130 expect(function() {131 parser.parse('var [a,[b]=');132 }).to.throwError();133 });134 it('destructuring object error 1', function() {135 var parser = homunculus.getParser('es6');136 expect(function() {137 parser.parse('var {');138 }).to.throwError();139 });140 it('destructuring object error 2', function() {141 var parser = homunculus.getParser('es6');142 expect(function() {143 parser.parse('var {a');144 }).to.throwError();145 });146 it('destructuring object error 3', function() {147 var parser = homunculus.getParser('es6');148 expect(function() {149 parser.parse('var {!');150 }).to.throwError();151 });152 it('destructuring object error 4', function() {153 var parser = homunculus.getParser('es6');154 expect(function() {155 parser.parse('var {a ');156 }).to.throwError();157 });158 it('destructuring error: kw can not in array 1', function() {159 var parser = homunculus.getParser('es6');160 expect(function() {161 parser.parse('var [var] = [1]');162 }).to.throwError();163 });164 it('destructuring error: kw can not in array 2', function() {165 var parser = homunculus.getParser('es6');166 expect(function() {167 parser.parse('var [x, {"a":[var=1,{z=2},...o]}] = []');168 }).to.throwError();169 });170 it('letdecl 1', function() {171 var parser = homunculus.getParser('es6');172 var node = parser.parse('let a');173 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);174 });175 it('letdecl 2', function() {176 var parser = homunculus.getParser('es6');177 var node = parser.parse('let a, b = 1');178 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);179 });180 it('cstdecl 1', function() {181 var parser = homunculus.getParser('es6');182 var node = parser.parse('const a');183 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);184 });185 it('cstdecl 2', function() {186 var parser = homunculus.getParser('es6');187 var node = parser.parse('const a, b = 1');188 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);189 });190 it('fndecl', function() {191 var parser = homunculus.getParser('es6');192 var node = parser.parse('function a() {}');193 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]);194 });195 it('fndecl with params', function() {196 var parser = homunculus.getParser('es6');197 var node = parser.parse('function a(b,c) {}');198 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"]]],")","{",JsNode.FNBODY,[],"}"]]]]);199 });200 it('fndecl bindelem', function() {201 var parser = homunculus.getParser('es6');202 var node = parser.parse('function a(b, c = 1, ...d){}');203 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDREST,["...",JsNode.BINDID,["d"]]],")","{",JsNode.FNBODY,[],"}"]]]]);204 });205 it('fndecl bindelem 2', function() {206 var parser = homunculus.getParser('es6');207 var node = parser.parse('function a(b, c = d*2){}');208 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["d"],"*",JsNode.PRMREXPR,["2"]]]]],")","{",JsNode.FNBODY,[],"}"]]]]);209 });210 it('fndecl with fnbody', function() {211 var parser = homunculus.getParser('es6');212 var node = parser.parse('function a() {;}');213 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EMPTSTMT,[";"]],"}"]]]]);214 });215 it('fndecl rest', function() {216 var parser = homunculus.getParser('es6');217 var node = parser.parse('function a(...b){}');218 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.BINDREST,["...",JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]]]);219 });220 it('fndecl error 1', function() {221 var parser = homunculus.getParser('es6');222 expect(function() {223 parser.parse('function');224 }).to.throwError();225 });226 it('fndecl error 2', function() {227 var parser = homunculus.getParser('es6');228 expect(function() {229 parser.parse('function a');230 }).to.throwError();231 });232 it('fndecl error 3', function() {233 var parser = homunculus.getParser('es6');234 expect(function() {235 parser.parse('function a(');236 }).to.throwError();237 });238 it('fndecl error 4', function() {239 var parser = homunculus.getParser('es6');240 expect(function() {241 parser.parse('function a()');242 }).to.throwError();243 });244 it('fndecl error 5', function() {245 var parser = homunculus.getParser('es6');246 expect(function() {247 parser.parse('function a() {');248 }).to.throwError();249 });250 it('fnexpr 1', function() {251 var parser = homunculus.getParser('es6');252 var node = parser.parse('~function() {}()');253 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.FNEXPR,["function","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);254 });255 it('fnexpr 2', function() {256 var parser = homunculus.getParser('es6');257 var node = parser.parse('(function a() {})()');258 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.FNEXPR,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);259 });260 it('fnexpr error 1', function() {261 var parser = homunculus.getParser('es6');262 expect(function() {263 parser.parse('(function');264 }).to.throwError();265 });266 it('fnexpr error 2', function() {267 var parser = homunculus.getParser('es6');268 expect(function() {269 parser.parse('(function(');270 }).to.throwError();271 });272 it('fnexpr error 3', function() {273 var parser = homunculus.getParser('es6');274 expect(function() {275 parser.parse('(function(a,');276 }).to.throwError();277 });278 it('fnexpr error 4', function() {279 var parser = homunculus.getParser('es6');280 expect(function() {281 parser.parse('(function(a,1');282 }).to.throwError();283 });284 it('fnparams error', function() {285 var parser = homunculus.getParser('es6');286 expect(function() {287 parser.parse('function a(b,){}');288 }).to.throwError();289 });290 it('args error', function() {291 var parser = homunculus.getParser('es6');292 expect(function() {293 parser.parse('a(b,)');294 }).to.throwError();295 });296 it('gendecl with yield', function() {297 var parser = homunculus.getParser('es6');298 var node = parser.parse('function * a(){yield}');299 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]);300 });301 it('gendecl with var stmt yield', function() {302 var parser = homunculus.getParser('es6');303 var node = parser.parse('function * a(){var a = yield 1}');304 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.YIELDEXPR,["yield",JsNode.PRMREXPR,["1"]]]]]],"}"]]]]);305 });306 it('yield can not in gencmph', function() {307 var parser = homunculus.getParser('es6');308 expect(function() {309 parser.parse('[for(yield of b)yield]');310 }).to.throwError();311 });312 it('yield can not in ungenerator', function() {313 var parser = homunculus.getParser('es6');314 expect(function() {315 parser.parse('function a(){yield}');316 }).to.throwError();317 });318 it('yield can in generator', function() {319 var parser = homunculus.getParser('es6');320 var node = parser.parse('function *a(){if(false)yield;do yield;while(false);for(;;)yield;}');321 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["false"],")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]],JsNode.ITERSTMT,["do",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"],"while","(",JsNode.PRMREXPR,["false"],")",";"],JsNode.ITERSTMT,["for","(",";",";",")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]]],"}"]]]]);322 });323 it('genmethod', function() {324 var parser = homunculus.getParser('es6');325 var node = parser.parse('class A{*method(){}}');326 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.GENMETHOD,["*",JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);327 });328 it('gendecl error 1', function() {329 var parser = homunculus.getParser('es6');330 expect(function() {331 parser.parse('function *');332 }).to.throwError();333 });334 it('gendecl error 2', function() {335 var parser = homunculus.getParser('es6');336 expect(function() {337 parser.parse('function * a');338 }).to.throwError();339 });340 it('gendecl error 3', function() {341 var parser = homunculus.getParser('es6');342 expect(function() {343 parser.parse('function * a(');344 }).to.throwError();345 });346 it('gendecl error 4', function() {347 var parser = homunculus.getParser('es6');348 expect(function() {349 parser.parse('function * a()');350 }).to.throwError();351 });352 it('gendecl error 5', function() {353 var parser = homunculus.getParser('es6');354 expect(function() {355 parser.parse('function * a(){');356 }).to.throwError();357 });358 it('gendecl error 6', function() {359 var parser = homunculus.getParser('es6');360 expect(function() {361 parser.parse('function *(){}');362 }).to.throwError();363 });364 it('yield expr error', function() {365 var parser = homunculus.getParser('es6');366 expect(function() {367 parser.parse('yield');368 }).to.throwError();369 });370 it('genexpr', function() {371 var parser = homunculus.getParser('es6');372 var node = parser.parse('!function * a(){}');373 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]]]);374 });375 it('genexpr with yield', function() {376 var parser = homunculus.getParser('es6');377 var node = parser.parse('!function *(){yield}');378 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]]]]);379 });380 it('genexpr error 1', function() {381 var parser = homunculus.getParser('es6');382 expect(function() {383 parser.parse('!function *');384 }).to.throwError();385 });386 it('genexpr error 2', function() {387 var parser = homunculus.getParser('es6');388 expect(function() {389 parser.parse('!function * a');390 }).to.throwError();391 });392 it('genexpr error 3', function() {393 var parser = homunculus.getParser('es6');394 expect(function() {395 parser.parse('!function * a(');396 }).to.throwError();397 });398 it('genexpr error 4', function() {399 var parser = homunculus.getParser('es6');400 expect(function() {401 parser.parse('!function * a()');402 }).to.throwError();403 });404 it('genexpr error 5', function() {405 var parser = homunculus.getParser('es6');406 expect(function() {407 parser.parse('!function * a(){');408 }).to.throwError();409 });410 it('arrinit error', function() {411 var parser = homunculus.getParser('es6');412 expect(function() {413 parser.parse('[');414 }).to.throwError();415 });416 it('arrltr', function() {417 var parser = homunculus.getParser('es6');418 var node = parser.parse('[,,,2,3,]');419 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",",",",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],",","]"]]]]]]);420 });421 it('arrltr spread', function() {422 var parser = homunculus.getParser('es6');423 var node = parser.parse('[...a]');424 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],"]"]]]]]]);425 });426 it('arrltr multi spread', function() {427 var parser = homunculus.getParser('es6');428 var node = parser.parse('[...a,...b]');429 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],",",JsNode.SPREAD,["...",JsNode.PRMREXPR,["b"]],"]"]]]]]]);430 });431 it('arrltr error', function() {432 var parser = homunculus.getParser('es6');433 expect(function() {434 parser.parse('[,,,2,3,');435 }).to.throwError();436 });437 it('arrcmph no if', function() {438 var parser = homunculus.getParser('es6');439 var node = parser.parse('[for(a of b)a]');440 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);441 });442 it('arrcmph with if', function() {443 var parser = homunculus.getParser('es6');444 var node = parser.parse('[for(a of b)if(a>1)a]');445 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);446 });447 it('arrcmph recursion', function() {448 var parser = homunculus.getParser('es6');449 var node = parser.parse('[for(a of b)if(true)for(c of a)if(false)c]');450 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["true"],")"],JsNode.CMPHFOR,["for","(",JsNode.BINDID,["c"],"of",JsNode.PRMREXPR,["a"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["false"],")"],JsNode.PRMREXPR,["c"]],"]"]]]]]]);451 });452 it('arrcmph forbindpat', function() {453 var parser = homunculus.getParser('es6');454 var node = parser.parse('[for([a,b] of c)a+b]');455 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],"of",JsNode.PRMREXPR,["c"],")"],JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]],"]"]]]]]]);456 });457 it('arrcmph error 1', function() {458 var parser = homunculus.getParser('es6');459 expect(function() {460 parser.parse('[for');461 }).to.throwError();462 });463 it('arrcmph error 2', function() {464 var parser = homunculus.getParser('es6');465 expect(function() {466 parser.parse('[for(');467 }).to.throwError();468 });469 it('arrcmph error 3', function() {470 var parser = homunculus.getParser('es6');471 expect(function() {472 parser.parse('[for(a');473 }).to.throwError();474 });475 it('arrcmph error 4', function() {476 var parser = homunculus.getParser('es6');477 expect(function() {478 parser.parse('[for(a of');479 }).to.throwError();480 });481 it('arrcmph error 5', function() {482 var parser = homunculus.getParser('es6');483 expect(function() {484 parser.parse('[for(a of b');485 }).to.throwError();486 });487 it('arrcmph error 6', function() {488 var parser = homunculus.getParser('es6');489 expect(function() {490 parser.parse('[for(a of b)');491 }).to.throwError();492 });493 it('arrcmph error 7', function() {494 var parser = homunculus.getParser('es6');495 expect(function() {496 parser.parse('[for(a of b)if');497 }).to.throwError();498 });499 it('arrcmph error 8', function() {500 var parser = homunculus.getParser('es6');501 expect(function() {502 parser.parse('[for(a of b)if(');503 }).to.throwError();504 });505 it('arrcmph error 9', function() {506 var parser = homunculus.getParser('es6');507 expect(function() {508 parser.parse('[for(a of b)if(true');509 }).to.throwError();510 });511 it('arrcmph error 10', function() {512 var parser = homunculus.getParser('es6');513 expect(function() {514 parser.parse('[for(a of b)if(true)');515 }).to.throwError();516 });517 it('arrcmph error 11', function() {518 var parser = homunculus.getParser('es6');519 expect(function() {520 parser.parse('[for(a of b)if(true)a');521 }).to.throwError();522 });523 it('objlatr 1', function() {524 var parser = homunculus.getParser('es6');525 var node = parser.parse('({x,y}={"x":1,"y":2})');526 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],"}"]],"=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"x\""]],":",JsNode.PRMREXPR,["1"]],",",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"y\""]],":",JsNode.PRMREXPR,["2"]],"}"]]],")"]]]]]]);527 });528 it('objlatr 2', function() {529 var parser = homunculus.getParser('es6');530 var node = parser.parse('({x,y,[a]})');531 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",",JsNode.PROPTDEF,[JsNode.CMPTPROPT,["[",JsNode.PRMREXPR,["a"],"]"]],"}"]],")"]]]]]]);532 });533 it('objlatr 3', function() {534 var parser = homunculus.getParser('es6');535 var node = parser.parse('!{a(){}}');536 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);537 });538 it('objlatr 4', function() {539 var parser = homunculus.getParser('es6');540 var node = parser.parse('~{x,y,}');541 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",","}"]]]]]]]);542 });543 it('keyword can be obj\'s property', function() {544 var parser = homunculus.getParser('es6');545 var node = parser.parse('var o = {var:1}');546 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);547 });548 it('keyword can not be label', function() {549 var parser = homunculus.getParser('es6');550 expect(function() {551 parser.parse('var:');552 }).to.throwError();553 });554 it('keyword after get/set', function() {555 var parser = homunculus.getParser('es6');556 var node = parser.parse('~{get var(){}}');557 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);558 });559 it('newexpr 1', function() {560 var parser = homunculus.getParser('es6');561 var node = parser.parse('new A');562 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]]]]]]);563 });564 it('newexpr 2', function() {565 var parser = homunculus.getParser('es6');566 var node = parser.parse('new A()');567 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);568 });569 it('newexpr 3', function() {570 var parser = homunculus.getParser('es6');571 var node = parser.parse('new A().f');572 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"]]]]]);573 });574 it('newexpr 4', function() {575 var parser = homunculus.getParser('es6');576 var node = parser.parse('new A().f()');577 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);578 });579 it('newexpr 5', function() {580 var parser = homunculus.getParser('es6');581 var node = parser.parse('new new A().f()');582 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);583 });584 it('newexpr 6', function() {585 var parser = homunculus.getParser('es6');586 var node = parser.parse('new A()[1]');587 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);588 });589 it('newexpr error', function() {590 var parser = homunculus.getParser('es6');591 expect(function() {592 parser.parse('new');593 }).to.throwError();594 });595 it('super 1', function() {596 var parser = homunculus.getParser('es6');597 var node = parser.parse('new super');598 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super"]]]]]);599 });600 it('super 2', function() {601 var parser = homunculus.getParser('es6');602 var node = parser.parse('new super()');603 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);604 });605 it('super 3', function() {606 var parser = homunculus.getParser('es6');607 var node = parser.parse('new super.a');608 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"]]]]]]);609 });610 it('super 4', function() {611 var parser = homunculus.getParser('es6');612 var node = parser.parse('new super.a()');613 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);614 });615 it('super 5', function() {616 var parser = homunculus.getParser('es6');617 var node = parser.parse('new super.a().b');618 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"]]]]]);619 });620 it('super 6', function() {621 var parser = homunculus.getParser('es6');622 var node = parser.parse('super.a');623 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,["super",".","a"]]]]]);624 });625 it('super 7', function() {626 var parser = homunculus.getParser('es6');627 var node = parser.parse('super["a"]()');628 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,["super","[",JsNode.PRMREXPR,["\"a\""],"]"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);629 });630 it('super be an property', function() {631 var parser = homunculus.getParser('es6');632 var node = parser.parse('new a.super');633 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","super"]]]]]]);634 });635 it('super error', function() {636 var parser = homunculus.getParser('es6');637 expect(function() {638 parser.parse('super super');639 }).to.throwError();640 });641 it('super in method', function() {642 var parser = homunculus.getParser('es6');643 expect(function() {644 parser.parse('class A{f(){super()}}');645 }).to.throwError();646 });647 it('super in constructor', function() {648 var parser = homunculus.getParser('es6');649 var node = parser.parse('class A{constructor(){super()}}');650 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["constructor"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,["super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]],"}"]]],"}"]]]]);651 });652 it('mmbexpr 1', function() {653 var parser = homunculus.getParser('es6');654 var node = parser.parse('a.b.c');655 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],".","c"]]]]]);656 });657 it('mmbexpr 2', function() {658 var parser = homunculus.getParser('es6');659 var node = parser.parse('a.b[c]');660 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"[",JsNode.PRMREXPR,["c"],"]"]]]]]);661 });662 it('mmbexpr 3', function() {663 var parser = homunculus.getParser('es6');664 var node = parser.parse('a.b');665 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"]]]]]);666 });667 it('mmbexpr 4', function() {668 var parser = homunculus.getParser('es6');669 var node = parser.parse('a[2]');670 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],"[",JsNode.PRMREXPR,["2"],"]"]]]]]);671 });672 it('mmbexpr error', function() {673 var parser = homunculus.getParser('es6');674 expect(function() {675 parser.parse('a.');676 }).to.throwError();677 });678 it('postfixexpr 1', function() {679 var parser = homunculus.getParser('es6');680 var node = parser.parse('a++ + b');681 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.PRMREXPR,["b"]]]]]]);682 });683 it('postfixexpr 2', function() {684 var parser = homunculus.getParser('es6');685 var node = parser.parse('a\nb++');686 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);687 });688 it('postfixexpr 3', function() {689 var parser = homunculus.getParser('es6');690 var node = parser.parse('a/*\n*/b++');691 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);692 });693 it('postfixexpr 4', function() {694 var parser = homunculus.getParser('es6');695 var node = parser.parse('a++');696 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"]]]]]);697 });698 it('postfixexpr error 1', function() {699 var parser = homunculus.getParser('es6');700 expect(function() {701 parser.parse('a++ ++');702 }).to.throwError();703 });704 it('postfixexpr error 2', function() {705 var parser = homunculus.getParser('es6');706 expect(function() {707 parser.parse('++');708 }).to.throwError();709 });710 it('prmrexpr 1', function() {711 var parser = homunculus.getParser('es6');712 var node = parser.parse('a');713 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);714 });715 it('prmrexpr 2', function() {716 var parser = homunculus.getParser('es6');717 var node = parser.parse('true');718 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["true"]]]]]);719 });720 it('prmrexpr 3', function() {721 var parser = homunculus.getParser('es6');722 var node = parser.parse('null');723 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["null"]]]]]);724 });725 it('prmrexpr 4', function() {726 var parser = homunculus.getParser('es6');727 var node = parser.parse('this');728 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["this"]]]]]);729 });730 it('prmrexpr 5', function() {731 var parser = homunculus.getParser('es6');732 var node = parser.parse('false');733 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["false"]]]]]);734 });735 it('prmrexpr 6', function() {736 var parser = homunculus.getParser('es6');737 var node = parser.parse('[]');738 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]);739 });740 it('prmrexpr 7', function() {741 var parser = homunculus.getParser('es6');742 var node = parser.parse('!{}');743 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]);744 });745 it('prmrexpr error', function() {746 var parser = homunculus.getParser('es6');747 expect(function() {748 parser.parse('.');749 }).to.throwError();750 });751 it('callexpr 1', function() {752 var parser = homunculus.getParser('es6');753 var node = parser.parse('a()');754 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);755 });756 it('callexpr 2', function() {757 var parser = homunculus.getParser('es6');758 var node = parser.parse('a.b()');759 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);760 });761 it('callexpr 3', function() {762 var parser = homunculus.getParser('es6');763 var node = parser.parse('new A().f()');764 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);765 });766 it('callexpr 4', function() {767 var parser = homunculus.getParser('es6');768 var node = parser.parse('f()()');769 expect(tree(node)).to.eql(770 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);771 });772 it('callexpr 5', function() {773 var parser = homunculus.getParser('es6');774 var node = parser.parse('f().b[1]');775 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);776 });777 it('callexpr 6', function() {778 var parser = homunculus.getParser('es6');779 var node = parser.parse('a.b().c.d()');780 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","c"],".","d"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);781 });782 it('callexpr error', function() {783 var parser = homunculus.getParser('es6');784 expect(function() {785 parser.parse('f(');786 }).to.throwError();787 });788 it('unaryexpr 1', function() {789 var parser = homunculus.getParser('es6');790 var node = parser.parse('typeof a');791 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["typeof",JsNode.PRMREXPR,["a"]]]]]]);792 });793 it('unaryexpr 2', function() {794 var parser = homunculus.getParser('es6');795 var node = parser.parse('!!0');796 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["0"]]]]]]]);797 });798 it('unaryexpr error 1', function() {799 var parser = homunculus.getParser('es6');800 expect(function() {801 parser.parse('!');802 }).to.throwError();803 });804 it('unaryexpr error 2', function() {805 var parser = homunculus.getParser('es6');806 expect(function() {807 parser.parse('++ +a');808 }).to.throwError();809 });810 it('mtplexpr 1', function() {811 var parser = homunculus.getParser('es6');812 var node = parser.parse('a * b');813 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.PRMREXPR,["a"],"*",JsNode.PRMREXPR,["b"]]]]]]);814 });815 it('mtplexpr 2', function() {816 var parser = homunculus.getParser('es6');817 var node = parser.parse('a() * b[0]');818 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"*",JsNode.MMBEXPR,[JsNode.PRMREXPR,["b"],"[",JsNode.PRMREXPR,["0"],"]"]]]]]]);819 });820 it('mtplexpr 3', function() {821 var parser = homunculus.getParser('es6');822 var node = parser.parse('!a * b--');823 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["a"]],"*",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);824 });825 it('addexpr 1', function() {826 var parser = homunculus.getParser('es6');827 var node = parser.parse('a + b * 2 - c');828 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["b"],"*",JsNode.PRMREXPR,["2"]],"-",JsNode.PRMREXPR,["c"]]]]]]);829 });830 it('addexpr 2', function() {831 var parser = homunculus.getParser('es6');832 var node = parser.parse('~a + a++ + ++a');833 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,["a"]],"+",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["a"]]]]]]]);834 });835 it('shiftexpr 1', function() {836 var parser = homunculus.getParser('es6');837 var node = parser.parse('a>>a+1');838 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["a"],">>",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["1"]]]]]]]);839 });840 it('shiftexpr 2', function() {841 var parser = homunculus.getParser('es6');842 var node = parser.parse('a*b>>>c/d<<--e');843 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);844 });845 it('reltexpr 1', function() {846 var parser = homunculus.getParser('es6');847 var node = parser.parse('a > b');848 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["b"]]]]]]);849 });850 it('reltexpr 2', function() {851 var parser = homunculus.getParser('es6');852 var node = parser.parse('a <= b+1');853 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<=",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["1"]]]]]]]);854 });855 it('reltexpr 3', function() {856 var parser = homunculus.getParser('es6');857 var node = parser.parse('a instanceof new A()');858 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"instanceof",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);859 });860 it('reltexpr error', function() {861 var parser = homunculus.getParser('es6');862 expect(function() {863 parser.parse('a <');864 }).to.throwError();865 });866 it('eqexpr 1', function() {867 var parser = homunculus.getParser('es6');868 var node = parser.parse('a == 3');869 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"==",JsNode.PRMREXPR,["3"]]]]]]);870 });871 it('eqexpr 2', function() {872 var parser = homunculus.getParser('es6');873 var node = parser.parse('a === b + 3');874 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"===",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["3"]]]]]]]);875 });876 it('eqexpr 3', function() {877 var parser = homunculus.getParser('es6');878 var node = parser.parse('a !== b >>> 4');879 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"!==",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["b"],">>>",JsNode.PRMREXPR,["4"]]]]]]]);880 });881 it('eqexpr error', function() {882 var parser = homunculus.getParser('es6');883 expect(function() {884 parser.parse('a ==');885 }).to.throwError();886 });887 it('bitandexpr', function() {888 var parser = homunculus.getParser('es6');889 var node = parser.parse('void a & --b');890 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITANDEXPR,[JsNode.UNARYEXPR,["void",JsNode.PRMREXPR,["a"]],"&",JsNode.UNARYEXPR,["--",JsNode.PRMREXPR,["b"]]]]]]]);891 });892 it('bitxorexpr', function() {893 var parser = homunculus.getParser('es6');894 var node = parser.parse('a>1 ^ b--');895 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITXOREXPR,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],"^",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);896 });897 it('bitorexpr', function() {898 var parser = homunculus.getParser('es6');899 var node = parser.parse('++b | -a');900 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITOREXPR,[JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["b"]],"|",JsNode.UNARYEXPR,["-",JsNode.PRMREXPR,["a"]]]]]]]);901 });902 it('logandexpr', function() {903 var parser = homunculus.getParser('es6');904 var node = parser.parse('a.b && c >> 1');905 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGANDEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"&&",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["c"],">>",JsNode.PRMREXPR,["1"]]]]]]]);906 });907 it('logorexpr', function() {908 var parser = homunculus.getParser('es6');909 var node = parser.parse('a || b && c || d && f');910 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGOREXPR,[JsNode.PRMREXPR,["a"],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["b"],"&&",JsNode.PRMREXPR,["c"]],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["d"],"&&",JsNode.PRMREXPR,["f"]]]]]]]);911 });912 it('condexpr', function() {913 var parser = homunculus.getParser('es6');914 var node = parser.parse('a && b ? false || true : typeof null');915 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);916 });917 it('assignexpr 1', function() {918 var parser = homunculus.getParser('es6');919 var node = parser.parse('a = b = c');920 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["c"]]]]]]]);921 });922 it('assignexpr 2', function() {923 var parser = homunculus.getParser('es6');924 var node = parser.parse('a += b %= c');925 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"+=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"%=",JsNode.PRMREXPR,["c"]]]]]]]);926 });927 it('assignexpr error', function() {928 var parser = homunculus.getParser('es6');929 expect(function() {930 parser.parse('a + b = c');931 }).to.throwError();932 });933 it('expr 1', function() {934 var parser = homunculus.getParser('es6');935 var node = parser.parse('(1)');936 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["1"],")"]]]]]]);937 });938 it('expr 2', function() {939 var parser = homunculus.getParser('es6');940 var node = parser.parse('(a, !b, c+d)');941 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]]]);942 });943 it('expr 3', function() {944 var parser = homunculus.getParser('es6');945 var node = parser.parse('(a, ...b)');946 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["a"],",","...",JsNode.BINDID,["b"],")"]]]]]]);947 });948 it('expr error 1', function() {949 var parser = homunculus.getParser('es6');950 expect(function() {951 parser.parse('(a,');952 }).to.throwError();953 });954 it('expr error 2', function() {955 var parser = homunculus.getParser('es6');956 expect(function() {957 parser.parse('(a, b');958 }).to.throwError();959 });960 it('expr error 3', function() {961 var parser = homunculus.getParser('es6');962 expect(function() {963 parser.parse('(a...b)');964 }).to.throwError();965 });966 it('expr error 4', function() {967 var parser = homunculus.getParser('es6');968 expect(function() {969 parser.parse('(...a, b)');970 }).to.throwError();971 });972 it('returnstmt 1', function() {973 var parser = homunculus.getParser('es6');974 var node = parser.parse('return a');975 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]]]]]);976 });977 it('returnstmt 2', function() {978 var parser = homunculus.getParser('es6');979 var node = parser.parse('return\na');980 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);981 });982 it('returnstmt 3', function() {983 var parser = homunculus.getParser('es6');984 var node = parser.parse('return/*\n*/a');985 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);986 });987 it('returnstmt 4', function() {988 var parser = homunculus.getParser('es6');989 var node = parser.parse('return a\nreturn');990 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]],JsNode.RETSTMT,["return"]]]]);991 });992 it('returnstmt 5', function() {993 var parser = homunculus.getParser('es6');994 var node = parser.parse('{return}');995 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.RETSTMT,["return"],"}"]]]]]);996 });997 it('labelstmt', function() {998 var parser = homunculus.getParser('es6');999 var node = parser.parse('label:;');1000 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LABSTMT,["label",":",JsNode.EMPTSTMT,[";"]]]]]);1001 });1002 it('block', function() {1003 var parser = homunculus.getParser('es6');1004 var node = parser.parse('{}{}');1005 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]);1006 });1007 it('varstmt 1', function() {1008 var parser = homunculus.getParser('es6');1009 var node = parser.parse('var a, b;');1010 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"]],";"]]]]);1011 });1012 it('varstmt 2', function() {1013 var parser = homunculus.getParser('es6');1014 var node = parser.parse('var a = 1');1015 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);1016 });1017 it('varstmt 3', function() {1018 var parser = homunculus.getParser('es6');1019 var node = parser.parse('var a = b = 1');1020 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]]]]]]]);1021 });1022 it('varstmt 4', function() {1023 var parser = homunculus.getParser('es6');1024 var node = parser.parse('var a = [{}]');1025 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],"]"]]]]]]]]);1026 });1027 it('varstmt error 1', function() {1028 var parser = homunculus.getParser('es6');1029 expect(function() {1030 parser.parse('var')1031 }).to.throwError();1032 });1033 it('varstmt error 2', function() {1034 var parser = homunculus.getParser('es6');1035 expect(function() {1036 parser.parse('var a=');1037 }).to.throwError();1038 });1039 it('emptstmt', function() {1040 var parser = homunculus.getParser('es6');1041 var node = parser.parse(';{;}');1042 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EMPTSTMT,[";"],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.EMPTSTMT,[";"],"}"]]]]]);1043 });1044 it('ifstmt 1', function() {1045 var parser = homunculus.getParser('es6');1046 var node = parser.parse('if(true);');1047 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.EMPTSTMT,[";"]]]]]);1048 });1049 it('ifstmt 2', function() {1050 var parser = homunculus.getParser('es6');1051 var node = parser.parse('if(true){}else if(true){}else{}');1052 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]]);1053 });1054 it('ifstmt missing stmt', function() {1055 var parser = homunculus.getParser('es6');1056 expect(function() {1057 parser.parse('if(true)');1058 }).to.throwError();1059 });1060 it('whilestmt 1', function() {1061 var parser = homunculus.getParser('es6');1062 var node = parser.parse('while(false);');1063 expect(tree(node)).to.eql(1064 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.EMPTSTMT,[";"]]]]]);1065 });1066 it('whilestmt 2', function() {1067 var parser = homunculus.getParser('es6');1068 var node = parser.parse('while(false){}');1069 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1070 });1071 it('dowhilestmt 1', function() {1072 var parser = homunculus.getParser('es6');1073 var node = parser.parse('do;while(false)');1074 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.EMPTSTMT,[";"],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1075 });1076 it('dowhilestmt 2', function() {1077 var parser = homunculus.getParser('es6');1078 var node = parser.parse('do{}while(false)');1079 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1080 });1081 it('forstmt 1', function() {1082 var parser = homunculus.getParser('es6');1083 var node = parser.parse('for(;;){}');1084 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",";",";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1085 });1086 it('forstmt 2', function() {1087 var parser = homunculus.getParser('es6');1088 var node = parser.parse('for(var a = 1; a < len; a++){}');1089 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],";",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<",JsNode.PRMREXPR,["len"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1090 });1091 it('forstmt 3', function() {1092 var parser = homunculus.getParser('es6');1093 var node = parser.parse('for(o in {});');1094 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,["o"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1095 });1096 it('forstmt 4', function() {1097 var parser = homunculus.getParser('es6');1098 var node = parser.parse('for(var k in {}){}');1099 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.BINDID,["k"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1100 });1101 it('forstmt 5', function() {1102 var parser = homunculus.getParser('es6');1103 var node = parser.parse('for(new A in [1,2]);');1104 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1105 });1106 it('forstmt 6', function() {1107 var parser = homunculus.getParser('es6');1108 var node = parser.parse('for(a.b in [1,2]);');1109 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1110 });1111 it('forstmt 7', function() {1112 var parser = homunculus.getParser('es6');1113 var node = parser.parse('for(new A of [1,2]);');1114 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1115 });1116 it('forstmt 8', function() {1117 var parser = homunculus.getParser('es6');1118 var node = parser.parse('for(a.b of [1,2]);');1119 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1120 });1121 it('forstmt 9', function() {1122 var parser = homunculus.getParser('es6');1123 var node = parser.parse('for(let a in {});');1124 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1125 });1126 it('forstmt 10', function() {1127 var parser = homunculus.getParser('es6');1128 var node = parser.parse('for(var [a] of o){}');1129 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1130 });1131 it('forstmt 11', function() {1132 var parser = homunculus.getParser('es6');1133 var node = parser.parse('for({a,b} of o){}');1134 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["a"],",",JsNode.PROPTDEF,["b"],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1135 });1136 it('forstmt 12', function() {1137 var parser = homunculus.getParser('es6');1138 var node = parser.parse('for(let a of {});');1139 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1140 });1141 it('forstmt 13', function() {1142 var parser = homunculus.getParser('es6');1143 var node = parser.parse('for(let i = 0; i < 2; i++){}');1144 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["i"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["0"]]],";"],JsNode.RELTEXPR,[JsNode.PRMREXPR,["i"],"<",JsNode.PRMREXPR,["2"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["i"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1145 });1146 it('forstmt 14', function() {1147 var parser = homunculus.getParser('es6');1148 var node = parser.parse('for(let [a] = [1];;){}');1149 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]],";"],";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1150 });1151 it('forstmt 15', function() {1152 var parser = homunculus.getParser('es6');1153 var node = parser.parse('for(let a = 1;;);');1154 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"],";",")",JsNode.EMPTSTMT,[";"]]]]]);1155 });1156 it('forstmt 16', function() {1157 var parser = homunculus.getParser('es6');1158 var node = parser.parse('for({a:b=1} of o){}');1159 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],":",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1160 });1161 it('forstmt missing expr', function() {1162 var parser = homunculus.getParser('es6');1163 expect(function() {1164 parser.parse('for(');1165 }).to.throwError();1166 });1167 it('forstmt leftexpr error 1', function() {1168 var parser = homunculus.getParser('js');1169 expect(function() {1170 parser.parse('for(a() in b);');1171 }).to.throwError();1172 });1173 it('forstmt leftexpr error 2', function() {1174 var parser = homunculus.getParser('js');1175 expect(function() {1176 parser.parse('for(a() of b);');1177 }).to.throwError();1178 });1179 it('forstmt let error', function() {1180 var parser = homunculus.getParser('js');1181 expect(function() {1182 parser.parse('for(let ;;);');1183 }).to.throwError();1184 });1185 it('forstmt missing ; 1', function() {1186 var parser = homunculus.getParser('es6');1187 expect(function() {1188 parser.parse('for(var a');1189 }).to.throwError();1190 });1191 it('forstmt missing ; 2', function() {1192 var parser = homunculus.getParser('es6');1193 expect(function() {1194 parser.parse('for(var a;');1195 }).to.throwError();1196 });1197 it('forstmt missing ; 3', function() {1198 var parser = homunculus.getParser('es6');1199 expect(function() {1200 parser.parse('for(var a;a > 10;');1201 }).to.throwError();1202 });1203 it('forstmt missing ; 4', function() {1204 var parser = homunculus.getParser('es6');1205 expect(function() {1206 parser.parse('for(a');1207 }).to.throwError();1208 });1209 it('forstmt missing ; 5', function() {1210 var parser = homunculus.getParser('es6');1211 expect(function() {1212 parser.parse('for(a;');1213 }).to.throwError();1214 });1215 it('forstmt missing ; 6', function() {1216 var parser = homunculus.getParser('es6');1217 expect(function() {1218 parser.parse('for(a;b');1219 }).to.throwError();1220 });1221 it('forstmt missing ; 7', function() {1222 var parser = homunculus.getParser('es6');1223 expect(function() {1224 parser.parse('for(a;b;');1225 }).to.throwError();1226 });1227 it('forstmt with in could not has multi varstmt', function() {1228 var parser = homunculus.getParser('es6');1229 expect(function() {1230 parser.parse('for(var a,b in {});');1231 }).to.throwError();1232 });1233 it('forstmt with in first', function() {1234 var parser = homunculus.getParser('es6');1235 expect(function() {1236 parser.parse('for(in {});');1237 }).to.throwError();1238 });1239 it('cntnstmt 1', function() {1240 var parser = homunculus.getParser('es6');1241 var node = parser.parse('while(false){continue;}');1242 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue",";"],"}"]]]]]]);1243 });1244 it('cntnstmt 2', function() {1245 var parser = homunculus.getParser('es6');1246 var node = parser.parse('while(false){continue a;}');1247 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue","a",";"],"}"]]]]]]);1248 });1249 it('cntnstmt 3', function() {1250 var parser = homunculus.getParser('es6');1251 var node = parser.parse('while(false){continue\na;}');1252 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]]]);1253 });1254 it('brkstmt 1', function() {1255 var parser = homunculus.getParser('es6');1256 var node = parser.parse('while(false){break;}');1257 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break",";"],"}"]]]]]]);1258 });1259 it('brkstmt 2', function() {1260 var parser = homunculus.getParser('es6');1261 var node = parser.parse('while(false){break a;}');1262 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break","a",";"],"}"]]]]]]);1263 });1264 it('brkstmt 3', function() {1265 var parser = homunculus.getParser('es6');1266 var node = parser.parse('while(false){break\na;}');1267 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.BRKSTMT,["break"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]]]);1268 });1269 it('swchstmt', function() {1270 var parser = homunculus.getParser('es6');1271 var node = parser.parse('switch(a){case 1:case 2:;break;default:;}');1272 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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,[";"]],"}"]]]]]);1273 });1274 it('defaultstmt', function() {1275 var parser = homunculus.getParser('es6');1276 var node = parser.parse('switch(a){default:case 1:break;}');1277 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.DFTCLAUSE,["default",":","case",JsNode.PRMREXPR,["1"],":",JsNode.BRKSTMT,["break",";"]],"}"]]]]]);1278 });1279 it('withstmt', function() {1280 var parser = homunculus.getParser('es6');1281 var node = parser.parse('with(a){}');1282 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.WITHSTMT,["with","(",JsNode.PRMREXPR,["a"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1283 });1284 it('withstmt error', function() {1285 var parser = homunculus.getParser('es6');1286 expect(function() {1287 parser.parse('with(){}');1288 }).to.throwError();1289 });1290 it('swchstmt error', function() {1291 var parser = homunculus.getParser('es6');1292 expect(function() {1293 parser.parse('switch(a){else:;}');1294 }).to.throwError();1295 });1296 it('thrstmt', function() {1297 var parser = homunculus.getParser('es6');1298 var node = parser.parse('throw e;');1299 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.THRSTMT,["throw",JsNode.PRMREXPR,["e"],";"]]]]);1300 });1301 it('thrstmt error', function() {1302 var parser = homunculus.getParser('es6');1303 expect(function() {1304 parser.parse('throw');1305 }).to.throwError();1306 });1307 it('trystmt 1', function() {1308 var parser = homunculus.getParser('es6');1309 var node = parser.parse('try{}catch(e){}finally{}');1310 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.CACH,["catch","(",JsNode.CACHPARAM,[JsNode.BINDID,["e"]],")",JsNode.BLOCK,["{","}"]],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]]);1311 });1312 it('trystmt 2', function() {1313 var parser = homunculus.getParser('es6');1314 var node = parser.parse('try{}finally{}');1315 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]]);1316 });1317 it('trystmt error 1', function() {1318 var parser = homunculus.getParser('es6');1319 expect(function() {1320 parser.parse('try');1321 }).to.throwError();1322 });1323 it('trystmt error 2', function() {1324 var parser = homunculus.getParser('es6');1325 expect(function() {1326 parser.parse('try{');1327 }).to.throwError();1328 });1329 it('trystmt error 3', function() {1330 var parser = homunculus.getParser('es6');1331 expect(function() {1332 parser.parse('try{}catch');1333 }).to.throwError();1334 });1335 it('trystmt error 4', function() {1336 var parser = homunculus.getParser('es6');1337 expect(function() {1338 parser.parse('try{}catch{');1339 }).to.throwError();1340 });1341 it('trystmt error 5', function() {1342 var parser = homunculus.getParser('es6');1343 expect(function() {1344 parser.parse('try{}catch(');1345 }).to.throwError();1346 });1347 it('trystmt error 6', function() {1348 var parser = homunculus.getParser('es6');1349 expect(function() {1350 parser.parse('try{}catch()');1351 }).to.throwError();1352 });1353 it('trystmt error 7', function() {1354 var parser = homunculus.getParser('js');1355 expect(function() {1356 parser.parse('try{}catch(a,b)');1357 }).to.throwError();1358 });1359 it('trystmt error 8', function() {1360 var parser = homunculus.getParser('es6');1361 expect(function() {1362 parser.parse('try{}catch(a){');1363 }).to.throwError();1364 });1365 it('trystmt error 9', function() {1366 var parser = homunculus.getParser('es6');1367 expect(function() {1368 parser.parse('try{}finally');1369 }).to.throwError();1370 });1371 it('debstmt', function() {1372 var parser = homunculus.getParser('es6');1373 var node = parser.parse('debugger;');1374 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.DEBSTMT,["debugger",";"]]]]);1375 });1376 it('empty 1', function() {1377 var parser = homunculus.getParser('es6');1378 var node = parser.parse('');1379 expect(tree(node)).to.eql([JsNode.SCRIPT,[]]);1380 });1381 it('empty 2', function() {1382 var parser = homunculus.getParser('es6');1383 var node = parser.parse();1384 expect(tree(node)).to.eql([JsNode.SCRIPT,[]]);1385 });1386 it('class 1', function() {1387 var parser= homunculus.getParser('es6');1388 var node = parser.parse('class A{}');1389 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[],"}"]]]]);1390 });1391 it('class 2', function() {1392 var parser= homunculus.getParser('es6');1393 var node = parser.parse('class A{;;}');1394 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[";"],JsNode.CLASSELEM,[";"]],"}"]]]]);1395 });1396 it('class with extends', function() {1397 var parser= homunculus.getParser('es6');1398 var node = parser.parse('class A extends B{}');1399 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],JsNode.HERITAGE,["extends",JsNode.PRMREXPR,["B"]],"{",JsNode.CLASSBODY,[],"}"]]]]);1400 });1401 it('class method', function() {1402 var parser= homunculus.getParser('es6');1403 var node = parser.parse('class A{method(b){}}');1404 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1405 });1406 it('class static', function() {1407 var parser= homunculus.getParser('es6');1408 var node = parser.parse('class A{static method(){}}');1409 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,["static",JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1410 });1411 it('class get', function() {1412 var parser= homunculus.getParser('es6');1413 var node = parser.parse('class A{get a(){return}}');1414 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.RETSTMT,["return"]],"}"]]],"}"]]]]);1415 });1416 it('class set', function() {1417 var parser= homunculus.getParser('es6');1418 var node = parser.parse('class A{set a(b){}}');1419 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,["set",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);1420 });1421 it('class error 1', function() {1422 var parser = homunculus.getParser('es6');1423 expect(function() {1424 parser.parse('class');1425 }).to.throwError();1426 });1427 it('class error 2', function() {1428 var parser = homunculus.getParser('es6');1429 expect(function() {1430 parser.parse('class A');1431 }).to.throwError();1432 });1433 it('class error 3', function() {1434 var parser = homunculus.getParser('es6');1435 expect(function() {1436 parser.parse('class A extends');1437 }).to.throwError();1438 });1439 it('class error 4', function() {1440 var parser = homunculus.getParser('es6');1441 expect(function() {1442 parser.parse('class A {');1443 }).to.throwError();1444 });1445 it('class error 4', function() {1446 var parser = homunculus.getParser('es6');1447 expect(function() {1448 parser.parse('class A {get method{');1449 }).to.throwError();1450 });1451 it('classexpr', function() {1452 var parser= homunculus.getParser('es6');1453 var node = parser.parse('!class A extends B{}');1454 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.CLASSEXPR,["class",JsNode.BINDID,["A"],JsNode.HERITAGE,["extends",JsNode.PRMREXPR,["B"]],"{",JsNode.CLASSBODY,[],"}"]]]]]]]);1455 });1456 it('classexpr error 1', function() {1457 var parser = homunculus.getParser('es6');1458 expect(function() {1459 parser.parse('!class A');1460 }).to.throwError();1461 });1462 it('classexpr error 2', function() {1463 var parser = homunculus.getParser('es6');1464 expect(function() {1465 parser.parse('!class A extends');1466 }).to.throwError();1467 });1468 it('classexpr error 3', function() {1469 var parser = homunculus.getParser('es6');1470 expect(function() {1471 parser.parse('!class A {');1472 }).to.throwError();1473 });1474 it('arrowfn 1', function() {1475 var parser= homunculus.getParser('es6');1476 var node = parser.parse('a => a');1477 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,["a"],"=>",JsNode.CNCSBODY,[JsNode.PRMREXPR,["a"]]]]]]]);1478 });1479 it('arrowfn 2', function() {1480 var parser= homunculus.getParser('es6');1481 var node = parser.parse('(a, b) => a + b');1482 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.PRMREXPR,["b"]],")"]],"=>",JsNode.CNCSBODY,[JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]]]]]]]);1483 });1484 it('arrowfn 3', function() {1485 var parser= homunculus.getParser('es6');1486 var node = parser.parse('(a, b) => {;return a-b}');1487 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ARROWFN,[JsNode.ARROWPARAMS,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.PRMREXPR,["b"]],")"]],"=>",JsNode.CNCSBODY,["{",JsNode.FNBODY,[JsNode.EMPTSTMT,[";"],JsNode.RETSTMT,["return",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"-",JsNode.PRMREXPR,["b"]]]],"}"]]]]]]);1488 });1489 it('arrowfn error 1', function() {1490 var parser = homunculus.getParser('es6');1491 expect(function() {1492 parser.parse('a =>');1493 }).to.throwError();1494 });1495 it('arrowfn error 2', function() {1496 var parser = homunculus.getParser('es6');1497 expect(function() {1498 parser.parse('a => {');1499 }).to.throwError();1500 });1501 it('arrowfn error disallowed a line break between ArrowParameters and the ⇒', function() {1502 var parser = homunculus.getParser('es6');1503 expect(function() {1504 parser.parse('(a, b)\n=> a + b');1505 }).to.throwError();1506 });1507 it('module from', function() {1508 var parser = homunculus.getParser('es6');1509 var node = parser.parse('module a from "a"');1510 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.MODULEIMPORT,["module",JsNode.BINDID,["a"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1511 });1512 it('module import', function() {1513 var parser = homunculus.getParser('es6');1514 var node = parser.parse('import "a"');1515 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import","\"a\""]]]]);1516 });1517 it('module import from 1', function() {1518 var parser = homunculus.getParser('es6');1519 var node = parser.parse('import {} from "a"');1520 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,[JsNode.NAMEIMPORT,["{","}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1521 });1522 it('module import from 2', function() {1523 var parser = homunculus.getParser('es6');1524 var node = parser.parse('import {x} from "a"');1525 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,[JsNode.NAMEIMPORT,["{",JsNode.IMPORTSPEC,["x"],"}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1526 });1527 it('module import from 3', function() {1528 var parser = homunculus.getParser('es6');1529 var node = parser.parse('import x from "a"');1530 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,["x"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1531 });1532 it('module import from as', function() {1533 var parser = homunculus.getParser('es6');1534 var node = parser.parse('import x,{y as z,} from "a"');1535 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.IMPORTDECL,["import",JsNode.IMPORTCAULSE,["x",",",JsNode.NAMEIMPORT,["{",JsNode.IMPORTSPEC,["y","as",JsNode.BINDID,["z"]],",","}"]],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1536 });1537 it('module export *', function() {1538 var parser = homunculus.getParser('es6');1539 var node = parser.parse('export * from "a"');1540 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export","*",JsNode.FROMCAULSE,["from","\"a\""]]]]]);1541 });1542 it('module export from', function() {1543 var parser = homunculus.getParser('es6');1544 var node = parser.parse('export {x} from "a"');1545 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.EXPORTCAULSE,["{",JsNode.EXPORTSPEC,["x"],"}"],JsNode.FROMCAULSE,["from","\"a\""]]]]]);1546 });1547 it('module export error', function() {1548 var parser = homunculus.getParser('es6');1549 expect(function() {1550 parser.parse('export a');1551 }).to.throwError();1552 });1553 it('module var', function() {1554 var parser = homunculus.getParser('es6');1555 var node = parser.parse('export var a = 1');1556 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]]);1557 });1558 it('module decl', function() {1559 var parser = homunculus.getParser('es6');1560 var node = parser.parse('export function *a(){}');1561 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export",JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]);1562 });1563 it('module default', function() {1564 var parser = homunculus.getParser('es6');1565 var node = parser.parse('export default a+b');1566 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.MODULEBODY,[JsNode.EXPORTDECL,["export","default",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]]]]]);1567 });1568 it('module be an id', function() {1569 var parser = homunculus.getParser('es6');1570 var node = parser.parse('var module');1571 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["module"]]]]]]);1572 });1573 it('module be an object', function() {1574 var parser = homunculus.getParser('es6');1575 var node = parser.parse('module.exports');1576 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["module"],".","exports"]]]]]);1577 });1578 it('module error 1', function() {1579 var parser = homunculus.getParser('es6');1580 expect(function() {1581 parser.parse('module a');1582 }).to.throwError();1583 });1584 it('module error 2', function() {1585 var parser = homunculus.getParser('es6');1586 expect(function() {1587 parser.parse('module a from');1588 }).to.throwError();1589 });1590 it('module error 3', function() {1591 var parser = homunculus.getParser('es6');1592 expect(function() {1593 parser.parse('import');1594 }).to.throwError();1595 });1596 it('module error 4', function() {1597 var parser = homunculus.getParser('es6');1598 expect(function() {1599 parser.parse('import x');1600 }).to.throwError();1601 });1602 it('module error 5', function() {1603 var parser = homunculus.getParser('es6');1604 expect(function() {1605 parser.parse('import x from');1606 }).to.throwError();1607 });1608 it('module error 6', function() {1609 var parser = homunculus.getParser('es6');1610 expect(function() {1611 parser.parse('export');1612 }).to.throwError();1613 });1614 it('module error 7', function() {1615 var parser = homunculus.getParser('es6');1616 expect(function() {1617 parser.parse('export x');1618 }).to.throwError();1619 });1620 it('module error 8', function() {1621 var parser = homunculus.getParser('es6');1622 expect(function() {1623 parser.parse('export "a"');1624 }).to.throwError();1625 });1626 it('module error 9', function() {1627 var parser = homunculus.getParser('es6');1628 expect(function() {1629 parser.parse('export x from');1630 }).to.throwError();1631 });1632 it('module not in global env', function() {1633 var parser = homunculus.getParser('es6');1634 expect(function() {1635 parser.parse('function a() { export * from "xxx" }');1636 }).to.throwError();1637 });1638 it('export module import be property name', function() {1639 var parser = homunculus.getParser('es6');1640 var node = parser.parse('a.export = 1');1641 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","export"],"=",JsNode.PRMREXPR,["1"]]]]]]);1642 });1643 it('getter', function() {1644 var parser = homunculus.getParser('es6');1645 var node = parser.parse('var o = {get a(){}}');1646 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]]);1647 });1648 it('get be an property', function() {1649 var parser = homunculus.getParser('es6');1650 var node = parser.parse('var o = {get:1}');1651 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["get"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);1652 });1653 it('getter error 1', function() {1654 var parser = homunculus.getParser('es6');1655 expect(function() {1656 parser.parse('var o = {get a}');1657 }).to.throwError();1658 });1659 it('getter error 2', function() {1660 var parser = homunculus.getParser('es6');1661 expect(function() {1662 parser.parse('var o = {get a(}');1663 }).to.throwError();1664 });1665 it('getter error 3', function() {1666 var parser = homunculus.getParser('es6');1667 expect(function() {1668 parser.parse('var o = {get a()}');1669 }).to.throwError();1670 });1671 it('getter error 4', function() {1672 var parser = homunculus.getParser('es6');1673 expect(function() {1674 parser.parse('var o = {get 3}');1675 }).to.throwError();1676 });1677 it('setter', function() {1678 var parser = homunculus.getParser('es6');1679 var node = parser.parse('var o = {set a(b){}}');1680 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["set",JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]]);1681 });1682 it('set be an property', function() {1683 var parser = homunculus.getParser('es6');1684 var node = parser.parse('var o = {set:1}');1685 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["set"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);1686 });1687 it('setter error 1', function() {1688 var parser = homunculus.getParser('es6');1689 expect(function() {1690 parser.parse('var o = {set a}');1691 }).to.throwError();1692 });1693 it('setter error 2', function() {1694 var parser = homunculus.getParser('es6');1695 expect(function() {1696 parser.parse('var o = {set a(}');1697 }).to.throwError();1698 });1699 it('setter error 3', function() {1700 var parser = homunculus.getParser('es6');1701 expect(function() {1702 parser.parse('var o = {set a()}');1703 }).to.throwError();1704 });1705 it('setter error 4', function() {1706 var parser = homunculus.getParser('es6');1707 expect(function() {1708 parser.parse('var o = {set 3(){}}');1709 }).to.throwError();1710 });1711 });1712 describe('js lib exec test', function() {1713 it('jquery 1.11.0', function() {1714 var parser = homunculus.getParser('es6');1715 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.js'), { encoding: 'utf-8' });1716 var node = parser.parse(code);1717 var ignore = parser.ignore();1718 var str = jion(node, ignore);1719 expect(str).to.eql(code);1720 });1721 it('jquery 1.11.0 min', function() {1722 var parser = homunculus.getParser('es6');1723 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.min.js'), { encoding: 'utf-8' });1724 var node = parser.parse(code);1725 var ignore = parser.ignore();1726 var str = jion(node, ignore);1727 expect(str).to.eql(code);1728 });1729 it('backbone 1.1.0', function() {1730 var parser = homunculus.getParser('es6');1731 var code = fs.readFileSync(path.join(__dirname, './lib/backbone.js'), { encoding: 'utf-8' });1732 var node = parser.parse(code);1733 var ignore = parser.ignore();1734 var str = jion(node, ignore);1735 expect(str).to.eql(code);1736 });1737 it('handlebars', function() {1738 var parser = homunculus.getParser('es6');1739 var code = fs.readFileSync(path.join(__dirname, './lib/handlebars.js'), { encoding: 'utf-8' });1740 var node = parser.parse(code);1741 var ignore = parser.ignore();1742 var str = jion(node, ignore);1743 expect(str).to.eql(code);1744 });1745 it('bootstrap 3.0.0', function() {1746 var parser = homunculus.getParser('es6');1747 var code = fs.readFileSync(path.join(__dirname, './lib/bootstrap.js'), { encoding: 'utf-8' });1748 var node = parser.parse(code);1749 var ignore = parser.ignore();1750 var str = jion(node, ignore);1751 expect(str).to.eql(code);1752 });1753 it('expect 0.1.2', function() {1754 var parser = homunculus.getParser('es6');1755 var code = fs.readFileSync(path.join(__dirname, './lib/expect.js'), { encoding: 'utf-8' });1756 var node = parser.parse(code);1757 var ignore = parser.ignore();1758 var str = jion(node, ignore);1759 expect(str).to.eql(code);1760 });1761 it('html5shiv 3.6.1', function() {1762 var parser = homunculus.getParser('es6');1763 var code = fs.readFileSync(path.join(__dirname, './lib/html5shiv.js'), { encoding: 'utf-8' });1764 var node = parser.parse(code);1765 var ignore = parser.ignore();1766 var str = jion(node, ignore);1767 expect(str).to.eql(code);1768 });1769 it('formatter', function() {1770 var parser = homunculus.getParser('es6');1771 var code = fs.readFileSync(path.join(__dirname, './lib/formatter.js'), { encoding: 'utf-8' });1772 var node = parser.parse(code);1773 var ignore = parser.ignore();1774 var str = jion(node, ignore);1775 expect(str).to.eql(code);1776 });1777 });1778 describe('other test', function() {1779 it('node #parent,#prev,#next', function () {1780 var parser = homunculus.getParser('es6');1781 var node = parser.parse('var a, b;');1782 var varstmt = node.leaf(0).leaf(0);1783 var children = varstmt.leaves();1784 var a = children[0];1785 var b = children[1];1786 expect(node.parent()).to.be(null);1787 expect(a.parent()).to.be(varstmt);1788 expect(b.parent()).to.be(varstmt);1789 expect(a.prev()).to.be(null);1790 expect(a.next()).to.be(b);1791 expect(b.prev()).to.be(a);1792 });1793 it('node #leaf,#size,#leaves', function () {1794 var parser = homunculus.getParser('es6');1795 var node = parser.parse('var a');1796 var varstmt = node.leaf(0).leaf(0);1797 expect(varstmt.name()).to.be(JsNode.VARSTMT);1798 expect(varstmt.size()).to.be(3);1799 });1800 it('#ast should return as parse return', function () {1801 var parser = homunculus.getParser('es6');1802 var node = parser.parse('var a, b;');1803 expect(node).to.equal(parser.ast());1804 });1805 it('init class Parser(lexer) with a lexer', function () {1806 var lexer = homunculus.getLexer('es6');1807 var parser = new Parser(lexer);1808 var node = parser.parse('var a, b;');1809 expect(node).to.equal(parser.ast());1810 expect(function () {1811 parser.init();1812 }).to.not.throwError();1813 });1814 it('JsNode#getKey', function () {1815 expect(JsNode.getKey('script')).to.eql('SCRIPT');...

Full Screen

Full Screen

jsxparser.js

Source:jsxparser.js Github

copy

Full Screen

...56}57describe('jsxparser', function() {58 describe('simple test', function () {59 it('varstmt no assign', function() {60 var parser = homunculus.getParser('es6');61 var node = parser.parse('var a;');62 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],";"]]]]);63 });64 it('varstmt with assign', function() {65 var parser = homunculus.getParser('es6');66 var node = parser.parse('var a = 1;');67 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);68 });69 it('varstmt with multi', function() {70 var parser = homunculus.getParser('es6');71 var node = parser.parse('var a, b = 1;');72 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"]]]]);73 });74 it('destructuring array', function() {75 var parser = homunculus.getParser('es6');76 var node = parser.parse('var [a] = [1]');77 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]]]]]]);78 });79 it('destructuring with restparam', function() {80 var parser = homunculus.getParser('es6');81 var node = parser.parse('var [a, ...b] = [1, 2, 3]');82 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],"]"]]]]]]]]);83 });84 it('destructuring with default value', function() {85 var parser = homunculus.getParser('es6');86 var node = parser.parse('var [a = 1, [b] = [2]] = [, []]');87 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["2"],"]"]]]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]],"]"]]]]]]]]);88 });89 it('destructuring object', function() {90 var parser = homunculus.getParser('es6');91 var node = parser.parse('var {x, y = 1, "f": [z]} = {}');92 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["x"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],",",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"f\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["z"]],"]"]]],"}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);93 });94 it('destructuring object with keyword property', function() {95 var parser = homunculus.getParser('es6');96 var node = parser.parse('var {var, f,} = {}');97 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["var"]]],",",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["f"]]],",","}"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]]);98 });99 it('destructuring complex', function() {100 var parser = homunculus.getParser('es6');101 var node = parser.parse('var [x, {"a":[y=1,{z=2},...o]}] = []');102 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["x"]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"a\""]],":",JsNode.BINDELEM,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["y"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDELEM,[JsNode.OBJBINDPAT,["{",JsNode.BINDPROPT,[JsNode.SINGLENAME,[JsNode.BINDID,["z"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["2"]]]],"}"]],",",JsNode.BINDREST,["...",JsNode.BINDID,["o"]],"]"]]],"}"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]]]);103 });104 it('destructuring without assign should throw error', function() {105 var parser = homunculus.getParser('es6');106 expect(function() {107 parser.parse('var [a];');108 }).to.throwError();109 });110 it('destructuring array error 1', function() {111 var parser = homunculus.getParser('es6');112 expect(function() {113 parser.parse('var [');114 }).to.throwError();115 });116 it('destructuring array error 1', function() {117 var parser = homunculus.getParser('es6');118 expect(function() {119 parser.parse('var [a');120 }).to.throwError();121 });122 it('destructuring array error 1', function() {123 var parser = homunculus.getParser('es6');124 expect(function() {125 parser.parse('var [a,');126 }).to.throwError();127 });128 it('destructuring array error 2', function() {129 var parser = homunculus.getParser('es6');130 expect(function() {131 parser.parse('var [a,[b]=');132 }).to.throwError();133 });134 it('destructuring object error 1', function() {135 var parser = homunculus.getParser('es6');136 expect(function() {137 parser.parse('var {');138 }).to.throwError();139 });140 it('destructuring object error 2', function() {141 var parser = homunculus.getParser('es6');142 expect(function() {143 parser.parse('var {a');144 }).to.throwError();145 });146 it('destructuring object error 3', function() {147 var parser = homunculus.getParser('es6');148 expect(function() {149 parser.parse('var {!');150 }).to.throwError();151 });152 it('destructuring object error 4', function() {153 var parser = homunculus.getParser('es6');154 expect(function() {155 parser.parse('var {a ');156 }).to.throwError();157 });158 it('destructuring error: kw can not in array 1', function() {159 var parser = homunculus.getParser('es6');160 expect(function() {161 parser.parse('var [var] = [1]');162 }).to.throwError();163 });164 it('destructuring error: kw can not in array 2', function() {165 var parser = homunculus.getParser('es6');166 expect(function() {167 parser.parse('var [x, {"a":[var=1,{z=2},...o]}] = []');168 }).to.throwError();169 });170 it('letdecl 1', function() {171 var parser = homunculus.getParser('es6');172 var node = parser.parse('let a');173 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);174 });175 it('letdecl 2', function() {176 var parser = homunculus.getParser('es6');177 var node = parser.parse('let a, b = 1');178 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);179 });180 it('cstdecl 1', function() {181 var parser = homunculus.getParser('es6');182 var node = parser.parse('const a');183 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]]]]]]);184 });185 it('cstdecl 2', function() {186 var parser = homunculus.getParser('es6');187 var node = parser.parse('const a, b = 1');188 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LEXDECL,["const",JsNode.LEXBIND,[JsNode.BINDID,["a"]],",",JsNode.LEXBIND,[JsNode.BINDID,["b"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);189 });190 it('fndecl', function() {191 var parser = homunculus.getParser('es6');192 var node = parser.parse('function a() {}');193 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]);194 });195 it('fndecl with params', function() {196 var parser = homunculus.getParser('es6');197 var node = parser.parse('function a(b,c) {}');198 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"]]],")","{",JsNode.FNBODY,[],"}"]]]]);199 });200 it('fndecl bindelem', function() {201 var parser = homunculus.getParser('es6');202 var node = parser.parse('function a(b, c = 1, ...d){}');203 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],",",JsNode.BINDREST,["...",JsNode.BINDID,["d"]]],")","{",JsNode.FNBODY,[],"}"]]]]);204 });205 it('fndecl bindelem 2', function() {206 var parser = homunculus.getParser('es6');207 var node = parser.parse('function a(b, c = d*2){}');208 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.SINGLENAME,[JsNode.BINDID,["b"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["c"],JsNode.INITLZ,["=",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["d"],"*",JsNode.PRMREXPR,["2"]]]]],")","{",JsNode.FNBODY,[],"}"]]]]);209 });210 it('fndecl with fnbody', function() {211 var parser = homunculus.getParser('es6');212 var node = parser.parse('function a() {;}');213 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EMPTSTMT,[";"]],"}"]]]]);214 });215 it('fndecl rest', function() {216 var parser = homunculus.getParser('es6');217 var node = parser.parse('function a(...b){}');218 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.FNDECL,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[JsNode.BINDREST,["...",JsNode.BINDID,["b"]]],")","{",JsNode.FNBODY,[],"}"]]]]);219 });220 it('fndecl error 1', function() {221 var parser = homunculus.getParser('es6');222 expect(function() {223 parser.parse('function');224 }).to.throwError();225 });226 it('fndecl error 2', function() {227 var parser = homunculus.getParser('es6');228 expect(function() {229 parser.parse('function a');230 }).to.throwError();231 });232 it('fndecl error 3', function() {233 var parser = homunculus.getParser('es6');234 expect(function() {235 parser.parse('function a(');236 }).to.throwError();237 });238 it('fndecl error 4', function() {239 var parser = homunculus.getParser('es6');240 expect(function() {241 parser.parse('function a()');242 }).to.throwError();243 });244 it('fndecl error 5', function() {245 var parser = homunculus.getParser('es6');246 expect(function() {247 parser.parse('function a() {');248 }).to.throwError();249 });250 it('fnexpr 1', function() {251 var parser = homunculus.getParser('es6');252 var node = parser.parse('~function() {}()');253 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.FNEXPR,["function","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);254 });255 it('fnexpr 2', function() {256 var parser = homunculus.getParser('es6');257 var node = parser.parse('(function a() {})()');258 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.FNEXPR,["function",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);259 });260 it('fnexpr error 1', function() {261 var parser = homunculus.getParser('es6');262 expect(function() {263 parser.parse('(function');264 }).to.throwError();265 });266 it('fnexpr error 2', function() {267 var parser = homunculus.getParser('es6');268 expect(function() {269 parser.parse('(function(');270 }).to.throwError();271 });272 it('fnexpr error 3', function() {273 var parser = homunculus.getParser('es6');274 expect(function() {275 parser.parse('(function(a,');276 }).to.throwError();277 });278 it('fnexpr error 4', function() {279 var parser = homunculus.getParser('es6');280 expect(function() {281 parser.parse('(function(a,1');282 }).to.throwError();283 });284 it('fnparams error', function() {285 var parser = homunculus.getParser('es6');286 expect(function() {287 parser.parse('function a(b,){}');288 }).to.throwError();289 });290 it('args error', function() {291 var parser = homunculus.getParser('es6');292 expect(function() {293 parser.parse('a(b,)');294 }).to.throwError();295 });296 it('gendecl with yield', function() {297 var parser = homunculus.getParser('es6');298 var node = parser.parse('function * a(){yield}');299 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]);300 });301 it('gendecl with var stmt yield', function() {302 var parser = homunculus.getParser('es6');303 var node = parser.parse('function * a(){var a = yield 1}');304 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.YIELDEXPR,["yield",JsNode.PRMREXPR,["1"]]]]]],"}"]]]]);305 });306 it('yield can not in gencmph', function() {307 var parser = homunculus.getParser('es6');308 expect(function() {309 parser.parse('[for(yield of b)yield]');310 }).to.throwError();311 });312 it('yield can not in ungenerator', function() {313 var parser = homunculus.getParser('es6');314 expect(function() {315 parser.parse('function a(){yield}');316 }).to.throwError();317 });318 it('yield can in generator', function() {319 var parser = homunculus.getParser('es6');320 var node = parser.parse('function *a(){if(false)yield;do yield;while(false);for(;;)yield;}');321 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.GENDECL,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["false"],")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]],JsNode.ITERSTMT,["do",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"],"while","(",JsNode.PRMREXPR,["false"],")",";"],JsNode.ITERSTMT,["for","(",";",";",")",JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"],";"]]],"}"]]]]);322 });323 it('genmethod', function() {324 var parser = homunculus.getParser('es6');325 var node = parser.parse('class A{*method(){}}');326 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.GENMETHOD,["*",JsNode.PROPTNAME,[JsNode.LTRPROPT,["method"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]],"}"]]]]);327 });328 it('gendecl error 1', function() {329 var parser = homunculus.getParser('es6');330 expect(function() {331 parser.parse('function *');332 }).to.throwError();333 });334 it('gendecl error 2', function() {335 var parser = homunculus.getParser('es6');336 expect(function() {337 parser.parse('function * a');338 }).to.throwError();339 });340 it('gendecl error 3', function() {341 var parser = homunculus.getParser('es6');342 expect(function() {343 parser.parse('function * a(');344 }).to.throwError();345 });346 it('gendecl error 4', function() {347 var parser = homunculus.getParser('es6');348 expect(function() {349 parser.parse('function * a()');350 }).to.throwError();351 });352 it('gendecl error 5', function() {353 var parser = homunculus.getParser('es6');354 expect(function() {355 parser.parse('function * a(){');356 }).to.throwError();357 });358 it('gendecl error 6', function() {359 var parser = homunculus.getParser('es6');360 expect(function() {361 parser.parse('function *(){}');362 }).to.throwError();363 });364 it('yield expr error', function() {365 var parser = homunculus.getParser('es6');366 expect(function() {367 parser.parse('yield');368 }).to.throwError();369 });370 it('genexpr', function() {371 var parser = homunculus.getParser('es6');372 var node = parser.parse('!function * a(){}');373 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*",JsNode.BINDID,["a"],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]]]]]]]);374 });375 it('genexpr with yield', function() {376 var parser = homunculus.getParser('es6');377 var node = parser.parse('!function *(){yield}');378 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.GENEXPR,["function","*","(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.YIELDEXPR,["yield"]]],"}"]]]]]]]);379 });380 it('genexpr error 1', function() {381 var parser = homunculus.getParser('es6');382 expect(function() {383 parser.parse('!function *');384 }).to.throwError();385 });386 it('genexpr error 2', function() {387 var parser = homunculus.getParser('es6');388 expect(function() {389 parser.parse('!function * a');390 }).to.throwError();391 });392 it('genexpr error 3', function() {393 var parser = homunculus.getParser('es6');394 expect(function() {395 parser.parse('!function * a(');396 }).to.throwError();397 });398 it('genexpr error 4', function() {399 var parser = homunculus.getParser('es6');400 expect(function() {401 parser.parse('!function * a()');402 }).to.throwError();403 });404 it('genexpr error 5', function() {405 var parser = homunculus.getParser('es6');406 expect(function() {407 parser.parse('!function * a(){');408 }).to.throwError();409 });410 it('arrinit error', function() {411 var parser = homunculus.getParser('es6');412 expect(function() {413 parser.parse('[');414 }).to.throwError();415 });416 it('arrltr', function() {417 var parser = homunculus.getParser('es6');418 var node = parser.parse('[,,,2,3,]');419 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",",",",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],",","]"]]]]]]);420 });421 it('arrltr spread', function() {422 var parser = homunculus.getParser('es6');423 var node = parser.parse('[...a]');424 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],"]"]]]]]]);425 });426 it('arrltr multi spread', function() {427 var parser = homunculus.getParser('es6');428 var node = parser.parse('[...a,...b]');429 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.SPREAD,["...",JsNode.PRMREXPR,["a"]],",",JsNode.SPREAD,["...",JsNode.PRMREXPR,["b"]],"]"]]]]]]);430 });431 it('arrltr error', function() {432 var parser = homunculus.getParser('es6');433 expect(function() {434 parser.parse('[,,,2,3,');435 }).to.throwError();436 });437 it('arrcmph no if', function() {438 var parser = homunculus.getParser('es6');439 var node = parser.parse('[for(a of b)a]');440 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);441 });442 it('arrcmph with if', function() {443 var parser = homunculus.getParser('es6');444 var node = parser.parse('[for(a of b)if(a>1)a]');445 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],")"],JsNode.PRMREXPR,["a"]],"]"]]]]]]);446 });447 it('arrcmph recursion', function() {448 var parser = homunculus.getParser('es6');449 var node = parser.parse('[for(a of b)if(true)for(c of a)if(false)c]');450 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,["b"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["true"],")"],JsNode.CMPHFOR,["for","(",JsNode.BINDID,["c"],"of",JsNode.PRMREXPR,["a"],")"],JsNode.CMPHIF,["if","(",JsNode.PRMREXPR,["false"],")"],JsNode.PRMREXPR,["c"]],"]"]]]]]]);451 });452 it('arrcmph forbindpat', function() {453 var parser = homunculus.getParser('es6');454 var node = parser.parse('[for([a,b] of c)a+b]');455 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRCMPH,["[",JsNode.CMPH,[JsNode.CMPHFOR,["for","(",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],",",JsNode.SINGLENAME,[JsNode.BINDID,["b"]],"]"],"of",JsNode.PRMREXPR,["c"],")"],JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["b"]]],"]"]]]]]]);456 });457 it('arrcmph error 1', function() {458 var parser = homunculus.getParser('es6');459 expect(function() {460 parser.parse('[for');461 }).to.throwError();462 });463 it('arrcmph error 2', function() {464 var parser = homunculus.getParser('es6');465 expect(function() {466 parser.parse('[for(');467 }).to.throwError();468 });469 it('arrcmph error 3', function() {470 var parser = homunculus.getParser('es6');471 expect(function() {472 parser.parse('[for(a');473 }).to.throwError();474 });475 it('arrcmph error 4', function() {476 var parser = homunculus.getParser('es6');477 expect(function() {478 parser.parse('[for(a of');479 }).to.throwError();480 });481 it('arrcmph error 5', function() {482 var parser = homunculus.getParser('es6');483 expect(function() {484 parser.parse('[for(a of b');485 }).to.throwError();486 });487 it('arrcmph error 6', function() {488 var parser = homunculus.getParser('es6');489 expect(function() {490 parser.parse('[for(a of b)');491 }).to.throwError();492 });493 it('arrcmph error 7', function() {494 var parser = homunculus.getParser('es6');495 expect(function() {496 parser.parse('[for(a of b)if');497 }).to.throwError();498 });499 it('arrcmph error 8', function() {500 var parser = homunculus.getParser('es6');501 expect(function() {502 parser.parse('[for(a of b)if(');503 }).to.throwError();504 });505 it('arrcmph error 9', function() {506 var parser = homunculus.getParser('es6');507 expect(function() {508 parser.parse('[for(a of b)if(true');509 }).to.throwError();510 });511 it('arrcmph error 10', function() {512 var parser = homunculus.getParser('es6');513 expect(function() {514 parser.parse('[for(a of b)if(true)');515 }).to.throwError();516 });517 it('arrcmph error 11', function() {518 var parser = homunculus.getParser('es6');519 expect(function() {520 parser.parse('[for(a of b)if(true)a');521 }).to.throwError();522 });523 it('objlatr 1', function() {524 var parser = homunculus.getParser('es6');525 var node = parser.parse('({x,y}={"x":1,"y":2})');526 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],"}"]],"=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"x\""]],":",JsNode.PRMREXPR,["1"]],",",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["\"y\""]],":",JsNode.PRMREXPR,["2"]],"}"]]],")"]]]]]]);527 });528 it('objlatr 2', function() {529 var parser = homunculus.getParser('es6');530 var node = parser.parse('({x,y,[a]})');531 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",",JsNode.PROPTDEF,[JsNode.CMPTPROPT,["[",JsNode.PRMREXPR,["a"],"]"]],"}"]],")"]]]]]]);532 });533 it('objlatr 3', function() {534 var parser = homunculus.getParser('es6');535 var node = parser.parse('!{a(){}}');536 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);537 });538 it('objlatr 4', function() {539 var parser = homunculus.getParser('es6');540 var node = parser.parse('~{x,y,}');541 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["x"],",",JsNode.PROPTDEF,["y"],",","}"]]]]]]]);542 });543 it('keyword can be obj\'s property', function() {544 var parser = homunculus.getParser('es6');545 var node = parser.parse('var o = {var:1}');546 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["o"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]]);547 });548 it('keyword can not be label', function() {549 var parser = homunculus.getParser('es6');550 expect(function() {551 parser.parse('var:');552 }).to.throwError();553 });554 it('keyword after get/set', function() {555 var parser = homunculus.getParser('es6');556 var node = parser.parse('~{get var(){}}');557 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.METHOD,["get",JsNode.PROPTNAME,[JsNode.LTRPROPT,["var"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[],"}"]],"}"]]]]]]]);558 });559 it('newexpr 1', function() {560 var parser = homunculus.getParser('es6');561 var node = parser.parse('new A');562 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]]]]]]);563 });564 it('newexpr 2', function() {565 var parser = homunculus.getParser('es6');566 var node = parser.parse('new A()');567 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);568 });569 it('newexpr 3', function() {570 var parser = homunculus.getParser('es6');571 var node = parser.parse('new A().f');572 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"]]]]]);573 });574 it('newexpr 4', function() {575 var parser = homunculus.getParser('es6');576 var node = parser.parse('new A().f()');577 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);578 });579 it('newexpr 5', function() {580 var parser = homunculus.getParser('es6');581 var node = parser.parse('new new A().f()');582 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);583 });584 it('newexpr 6', function() {585 var parser = homunculus.getParser('es6');586 var node = parser.parse('new A()[1]');587 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);588 });589 it('newexpr error', function() {590 var parser = homunculus.getParser('es6');591 expect(function() {592 parser.parse('new');593 }).to.throwError();594 });595 it('super 1', function() {596 var parser = homunculus.getParser('es6');597 var node = parser.parse('new super');598 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super"]]]]]);599 });600 it('super 2', function() {601 var parser = homunculus.getParser('es6');602 var node = parser.parse('new super()');603 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new","super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);604 });605 it('super 3', function() {606 var parser = homunculus.getParser('es6');607 var node = parser.parse('new super.a');608 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"]]]]]]);609 });610 it('super 4', function() {611 var parser = homunculus.getParser('es6');612 var node = parser.parse('new super.a()');613 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);614 });615 it('super 5', function() {616 var parser = homunculus.getParser('es6');617 var node = parser.parse('new super.a().b');618 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,["super",".","a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"]]]]]);619 });620 it('super 6', function() {621 var parser = homunculus.getParser('es6');622 var node = parser.parse('super.a');623 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,["super",".","a"]]]]]);624 });625 it('super 7', function() {626 var parser = homunculus.getParser('es6');627 var node = parser.parse('super["a"]()');628 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,["super","[",JsNode.PRMREXPR,["\"a\""],"]"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);629 });630 it('super be an property', function() {631 var parser = homunculus.getParser('es6');632 var node = parser.parse('new a.super');633 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.NEWEXPR,["new",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","super"]]]]]]);634 });635 it('super error', function() {636 var parser = homunculus.getParser('es6');637 expect(function() {638 parser.parse('super super');639 }).to.throwError();640 });641 it('super in method', function() {642 var parser = homunculus.getParser('es6');643 expect(function() {644 parser.parse('class A{f(){super()}}');645 }).to.throwError();646 });647 it('super in constructor', function() {648 var parser = homunculus.getParser('es6');649 var node = parser.parse('class A{constructor(){super()}}');650 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.CLASSDECL,["class",JsNode.BINDID,["A"],"{",JsNode.CLASSBODY,[JsNode.CLASSELEM,[JsNode.METHOD,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["constructor"]],"(",JsNode.FMPARAMS,[],")","{",JsNode.FNBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,["super",JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]],"}"]]],"}"]]]]);651 });652 it('mmbexpr 1', function() {653 var parser = homunculus.getParser('es6');654 var node = parser.parse('a.b.c');655 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],".","c"]]]]]);656 });657 it('mmbexpr 2', function() {658 var parser = homunculus.getParser('es6');659 var node = parser.parse('a.b[c]');660 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"[",JsNode.PRMREXPR,["c"],"]"]]]]]);661 });662 it('mmbexpr 3', function() {663 var parser = homunculus.getParser('es6');664 var node = parser.parse('a.b');665 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"]]]]]);666 });667 it('mmbexpr 4', function() {668 var parser = homunculus.getParser('es6');669 var node = parser.parse('a[2]');670 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],"[",JsNode.PRMREXPR,["2"],"]"]]]]]);671 });672 it('mmbexpr error', function() {673 var parser = homunculus.getParser('es6');674 expect(function() {675 parser.parse('a.');676 }).to.throwError();677 });678 it('postfixexpr 1', function() {679 var parser = homunculus.getParser('es6');680 var node = parser.parse('a++ + b');681 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.PRMREXPR,["b"]]]]]]);682 });683 it('postfixexpr 2', function() {684 var parser = homunculus.getParser('es6');685 var node = parser.parse('a\nb++');686 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);687 });688 it('postfixexpr 3', function() {689 var parser = homunculus.getParser('es6');690 var node = parser.parse('a/*\n*/b++');691 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]],JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"++"]]]]]);692 });693 it('postfixexpr 4', function() {694 var parser = homunculus.getParser('es6');695 var node = parser.parse('a++');696 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"]]]]]);697 });698 it('postfixexpr error 1', function() {699 var parser = homunculus.getParser('es6');700 expect(function() {701 parser.parse('a++ ++');702 }).to.throwError();703 });704 it('postfixexpr error 2', function() {705 var parser = homunculus.getParser('es6');706 expect(function() {707 parser.parse('++');708 }).to.throwError();709 });710 it('prmrexpr 1', function() {711 var parser = homunculus.getParser('es6');712 var node = parser.parse('a');713 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);714 });715 it('prmrexpr 2', function() {716 var parser = homunculus.getParser('es6');717 var node = parser.parse('true');718 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["true"]]]]]);719 });720 it('prmrexpr 3', function() {721 var parser = homunculus.getParser('es6');722 var node = parser.parse('null');723 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["null"]]]]]);724 });725 it('prmrexpr 4', function() {726 var parser = homunculus.getParser('es6');727 var node = parser.parse('this');728 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["this"]]]]]);729 });730 it('prmrexpr 5', function() {731 var parser = homunculus.getParser('es6');732 var node = parser.parse('false');733 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["false"]]]]]);734 });735 it('prmrexpr 6', function() {736 var parser = homunculus.getParser('es6');737 var node = parser.parse('[]');738 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]]]]]);739 });740 it('prmrexpr 7', function() {741 var parser = homunculus.getParser('es6');742 var node = parser.parse('!{}');743 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]]]]]]);744 });745 it('prmrexpr error', function() {746 var parser = homunculus.getParser('es6');747 expect(function() {748 parser.parse('.');749 }).to.throwError();750 });751 it('callexpr 1', function() {752 var parser = homunculus.getParser('es6');753 var node = parser.parse('a()');754 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);755 });756 it('callexpr 2', function() {757 var parser = homunculus.getParser('es6');758 var node = parser.parse('a.b()');759 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);760 });761 it('callexpr 3', function() {762 var parser = homunculus.getParser('es6');763 var node = parser.parse('new A().f()');764 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);765 });766 it('callexpr 4', function() {767 var parser = homunculus.getParser('es6');768 var node = parser.parse('f()()');769 expect(tree(node)).to.eql(770 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);771 });772 it('callexpr 5', function() {773 var parser = homunculus.getParser('es6');774 var node = parser.parse('f().b[1]');775 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","b"],"[",JsNode.PRMREXPR,["1"],"]"]]]]]);776 });777 it('callexpr 6', function() {778 var parser = homunculus.getParser('es6');779 var node = parser.parse('a.b().c.d()');780 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],".","c"],".","d"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]);781 });782 it('callexpr error', function() {783 var parser = homunculus.getParser('es6');784 expect(function() {785 parser.parse('f(');786 }).to.throwError();787 });788 it('unaryexpr 1', function() {789 var parser = homunculus.getParser('es6');790 var node = parser.parse('typeof a');791 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["typeof",JsNode.PRMREXPR,["a"]]]]]]);792 });793 it('unaryexpr 2', function() {794 var parser = homunculus.getParser('es6');795 var node = parser.parse('!!0');796 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["!",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["0"]]]]]]]);797 });798 it('unaryexpr error 1', function() {799 var parser = homunculus.getParser('es6');800 expect(function() {801 parser.parse('!');802 }).to.throwError();803 });804 it('unaryexpr error 2', function() {805 var parser = homunculus.getParser('es6');806 expect(function() {807 parser.parse('++ +a');808 }).to.throwError();809 });810 it('mtplexpr 1', function() {811 var parser = homunculus.getParser('es6');812 var node = parser.parse('a * b');813 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.PRMREXPR,["a"],"*",JsNode.PRMREXPR,["b"]]]]]]);814 });815 it('mtplexpr 2', function() {816 var parser = homunculus.getParser('es6');817 var node = parser.parse('a() * b[0]');818 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["a"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]],"*",JsNode.MMBEXPR,[JsNode.PRMREXPR,["b"],"[",JsNode.PRMREXPR,["0"],"]"]]]]]]);819 });820 it('mtplexpr 3', function() {821 var parser = homunculus.getParser('es6');822 var node = parser.parse('!a * b--');823 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.MTPLEXPR,[JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["a"]],"*",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);824 });825 it('addexpr 1', function() {826 var parser = homunculus.getParser('es6');827 var node = parser.parse('a + b * 2 - c');828 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.MTPLEXPR,[JsNode.PRMREXPR,["b"],"*",JsNode.PRMREXPR,["2"]],"-",JsNode.PRMREXPR,["c"]]]]]]);829 });830 it('addexpr 2', function() {831 var parser = homunculus.getParser('es6');832 var node = parser.parse('~a + a++ + ++a');833 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ADDEXPR,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,["a"]],"+",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],"+",JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["a"]]]]]]]);834 });835 it('shiftexpr 1', function() {836 var parser = homunculus.getParser('es6');837 var node = parser.parse('a>>a+1');838 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["a"],">>",JsNode.ADDEXPR,[JsNode.PRMREXPR,["a"],"+",JsNode.PRMREXPR,["1"]]]]]]]);839 });840 it('shiftexpr 2', function() {841 var parser = homunculus.getParser('es6');842 var node = parser.parse('a*b>>>c/d<<--e');843 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);844 });845 it('reltexpr 1', function() {846 var parser = homunculus.getParser('es6');847 var node = parser.parse('a > b');848 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["b"]]]]]]);849 });850 it('reltexpr 2', function() {851 var parser = homunculus.getParser('es6');852 var node = parser.parse('a <= b+1');853 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<=",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["1"]]]]]]]);854 });855 it('reltexpr 3', function() {856 var parser = homunculus.getParser('es6');857 var node = parser.parse('a instanceof new A()');858 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"instanceof",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",JsNode.ARGLIST,[],")"]]]]]]]);859 });860 it('reltexpr error', function() {861 var parser = homunculus.getParser('es6');862 expect(function() {863 parser.parse('a <');864 }).to.throwError();865 });866 it('eqexpr 1', function() {867 var parser = homunculus.getParser('es6');868 var node = parser.parse('a == 3');869 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"==",JsNode.PRMREXPR,["3"]]]]]]);870 });871 it('eqexpr 2', function() {872 var parser = homunculus.getParser('es6');873 var node = parser.parse('a === b + 3');874 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"===",JsNode.ADDEXPR,[JsNode.PRMREXPR,["b"],"+",JsNode.PRMREXPR,["3"]]]]]]]);875 });876 it('eqexpr 3', function() {877 var parser = homunculus.getParser('es6');878 var node = parser.parse('a !== b >>> 4');879 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.EQEXPR,[JsNode.PRMREXPR,["a"],"!==",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["b"],">>>",JsNode.PRMREXPR,["4"]]]]]]]);880 });881 it('eqexpr error', function() {882 var parser = homunculus.getParser('es6');883 expect(function() {884 parser.parse('a ==');885 }).to.throwError();886 });887 it('bitandexpr', function() {888 var parser = homunculus.getParser('es6');889 var node = parser.parse('void a & --b');890 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITANDEXPR,[JsNode.UNARYEXPR,["void",JsNode.PRMREXPR,["a"]],"&",JsNode.UNARYEXPR,["--",JsNode.PRMREXPR,["b"]]]]]]]);891 });892 it('bitxorexpr', function() {893 var parser = homunculus.getParser('es6');894 var node = parser.parse('a>1 ^ b--');895 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITXOREXPR,[JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],">",JsNode.PRMREXPR,["1"]],"^",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["b"],"--"]]]]]]);896 });897 it('bitorexpr', function() {898 var parser = homunculus.getParser('es6');899 var node = parser.parse('++b | -a');900 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.BITOREXPR,[JsNode.UNARYEXPR,["++",JsNode.PRMREXPR,["b"]],"|",JsNode.UNARYEXPR,["-",JsNode.PRMREXPR,["a"]]]]]]]);901 });902 it('logandexpr', function() {903 var parser = homunculus.getParser('es6');904 var node = parser.parse('a.b && c >> 1');905 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGANDEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"&&",JsNode.SHIFTEXPR,[JsNode.PRMREXPR,["c"],">>",JsNode.PRMREXPR,["1"]]]]]]]);906 });907 it('logorexpr', function() {908 var parser = homunculus.getParser('es6');909 var node = parser.parse('a || b && c || d && f');910 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.LOGOREXPR,[JsNode.PRMREXPR,["a"],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["b"],"&&",JsNode.PRMREXPR,["c"]],"||",JsNode.LOGANDEXPR,[JsNode.PRMREXPR,["d"],"&&",JsNode.PRMREXPR,["f"]]]]]]]);911 });912 it('condexpr', function() {913 var parser = homunculus.getParser('es6');914 var node = parser.parse('a && b ? false || true : typeof null');915 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[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"]]]]]]]);916 });917 it('assignexpr 1', function() {918 var parser = homunculus.getParser('es6');919 var node = parser.parse('a = b = c');920 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["c"]]]]]]]);921 });922 it('assignexpr 2', function() {923 var parser = homunculus.getParser('es6');924 var node = parser.parse('a += b %= c');925 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["a"],"+=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"%=",JsNode.PRMREXPR,["c"]]]]]]]);926 });927 it('assignexpr error', function() {928 var parser = homunculus.getParser('es6');929 expect(function() {930 parser.parse('a + b = c');931 }).to.throwError();932 });933 it('expr 1', function() {934 var parser = homunculus.getParser('es6');935 var node = parser.parse('(1)');936 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["1"],")"]]]]]]);937 });938 it('expr 2', function() {939 var parser = homunculus.getParser('es6');940 var node = parser.parse('(a, !b, c+d)');941 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]]]);942 });943 it('expr 3', function() {944 var parser = homunculus.getParser('es6');945 var node = parser.parse('(a, ...b)');946 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.CPEAPL,["(",JsNode.PRMREXPR,["a"],",","...",JsNode.BINDID,["b"],")"]]]]]]);947 });948 it('expr error 1', function() {949 var parser = homunculus.getParser('es6');950 expect(function() {951 parser.parse('(a,');952 }).to.throwError();953 });954 it('expr error 2', function() {955 var parser = homunculus.getParser('es6');956 expect(function() {957 parser.parse('(a, b');958 }).to.throwError();959 });960 it('expr error 3', function() {961 var parser = homunculus.getParser('es6');962 expect(function() {963 parser.parse('(a...b)');964 }).to.throwError();965 });966 it('expr error 4', function() {967 var parser = homunculus.getParser('es6');968 expect(function() {969 parser.parse('(...a, b)');970 }).to.throwError();971 });972 it('returnstmt 1', function() {973 var parser = homunculus.getParser('es6');974 var node = parser.parse('return a');975 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]]]]]);976 });977 it('returnstmt 2', function() {978 var parser = homunculus.getParser('es6');979 var node = parser.parse('return\na');980 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);981 });982 it('returnstmt 3', function() {983 var parser = homunculus.getParser('es6');984 var node = parser.parse('return/*\n*/a');985 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"]]]]]);986 });987 it('returnstmt 4', function() {988 var parser = homunculus.getParser('es6');989 var node = parser.parse('return a\nreturn');990 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.RETSTMT,["return",JsNode.PRMREXPR,["a"]],JsNode.RETSTMT,["return"]]]]);991 });992 it('returnstmt 5', function() {993 var parser = homunculus.getParser('es6');994 var node = parser.parse('{return}');995 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.RETSTMT,["return"],"}"]]]]]);996 });997 it('labelstmt', function() {998 var parser = homunculus.getParser('es6');999 var node = parser.parse('label:;');1000 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.LABSTMT,["label",":",JsNode.EMPTSTMT,[";"]]]]]);1001 });1002 it('block', function() {1003 var parser = homunculus.getParser('es6');1004 var node = parser.parse('{}{}');1005 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]);1006 });1007 it('varstmt 1', function() {1008 var parser = homunculus.getParser('es6');1009 var node = parser.parse('var a, b;');1010 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"]],",",JsNode.VARDECL,[JsNode.BINDID,["b"]],";"]]]]);1011 });1012 it('varstmt 2', function() {1013 var parser = homunculus.getParser('es6');1014 var node = parser.parse('var a = 1');1015 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]]]]]);1016 });1017 it('varstmt 3', function() {1018 var parser = homunculus.getParser('es6');1019 var node = parser.parse('var a = b = 1');1020 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]]]]]]]);1021 });1022 it('varstmt 4', function() {1023 var parser = homunculus.getParser('es6');1024 var node = parser.parse('var a = [{}]');1025 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],"]"]]]]]]]]);1026 });1027 it('varstmt error 1', function() {1028 var parser = homunculus.getParser('es6');1029 expect(function() {1030 parser.parse('var')1031 }).to.throwError();1032 });1033 it('varstmt error 2', function() {1034 var parser = homunculus.getParser('es6');1035 expect(function() {1036 parser.parse('var a=');1037 }).to.throwError();1038 });1039 it('emptstmt', function() {1040 var parser = homunculus.getParser('es6');1041 var node = parser.parse(';{;}');1042 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.EMPTSTMT,[";"],JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.EMPTSTMT,[";"],"}"]]]]]);1043 });1044 it('ifstmt 1', function() {1045 var parser = homunculus.getParser('es6');1046 var node = parser.parse('if(true);');1047 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.EMPTSTMT,[";"]]]]]);1048 });1049 it('ifstmt 2', function() {1050 var parser = homunculus.getParser('es6');1051 var node = parser.parse('if(true){}else if(true){}else{}');1052 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"else",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]]);1053 });1054 it('ifstmt missing stmt', function() {1055 var parser = homunculus.getParser('es6');1056 expect(function() {1057 parser.parse('if(true)');1058 }).to.throwError();1059 });1060 it('whilestmt 1', function() {1061 var parser = homunculus.getParser('es6');1062 var node = parser.parse('while(false);');1063 expect(tree(node)).to.eql(1064 [JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.EMPTSTMT,[";"]]]]]);1065 });1066 it('whilestmt 2', function() {1067 var parser = homunculus.getParser('es6');1068 var node = parser.parse('while(false){}');1069 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1070 });1071 it('dowhilestmt 1', function() {1072 var parser = homunculus.getParser('es6');1073 var node = parser.parse('do;while(false)');1074 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.EMPTSTMT,[";"],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1075 });1076 it('dowhilestmt 2', function() {1077 var parser = homunculus.getParser('es6');1078 var node = parser.parse('do{}while(false)');1079 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["do",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]],"while","(",JsNode.PRMREXPR,["false"],")"]]]]);1080 });1081 it('forstmt 1', function() {1082 var parser = homunculus.getParser('es6');1083 var node = parser.parse('for(;;){}');1084 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",";",";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1085 });1086 it('forstmt 2', function() {1087 var parser = homunculus.getParser('es6');1088 var node = parser.parse('for(var a = 1; a < len; a++){}');1089 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]]],";",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<",JsNode.PRMREXPR,["len"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1090 });1091 it('forstmt 3', function() {1092 var parser = homunculus.getParser('es6');1093 var node = parser.parse('for(o in {});');1094 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,["o"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1095 });1096 it('forstmt 4', function() {1097 var parser = homunculus.getParser('es6');1098 var node = parser.parse('for(var k in {}){}');1099 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.BINDID,["k"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1100 });1101 it('forstmt 5', function() {1102 var parser = homunculus.getParser('es6');1103 var node = parser.parse('for(new A in [1,2]);');1104 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1105 });1106 it('forstmt 6', function() {1107 var parser = homunculus.getParser('es6');1108 var node = parser.parse('for(a.b in [1,2]);');1109 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1110 });1111 it('forstmt 7', function() {1112 var parser = homunculus.getParser('es6');1113 var node = parser.parse('for(new A of [1,2]);');1114 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1115 });1116 it('forstmt 8', function() {1117 var parser = homunculus.getParser('es6');1118 var node = parser.parse('for(a.b of [1,2]);');1119 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"of",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]]);1120 });1121 it('forstmt 9', function() {1122 var parser = homunculus.getParser('es6');1123 var node = parser.parse('for(let a in {});');1124 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1125 });1126 it('forstmt 10', function() {1127 var parser = homunculus.getParser('es6');1128 var node = parser.parse('for(var [a] of o){}');1129 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","var",JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1130 });1131 it('forstmt 11', function() {1132 var parser = homunculus.getParser('es6');1133 var node = parser.parse('for({a,b} of o){}');1134 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,["a"],",",JsNode.PROPTDEF,["b"],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1135 });1136 it('forstmt 12', function() {1137 var parser = homunculus.getParser('es6');1138 var node = parser.parse('for(let a of {});');1139 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(","let",JsNode.BINDID,["a"],"of",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]]);1140 });1141 it('forstmt 13', function() {1142 var parser = homunculus.getParser('es6');1143 var node = parser.parse('for(let i = 0; i < 2; i++){}');1144 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["i"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["0"]]],";"],JsNode.RELTEXPR,[JsNode.PRMREXPR,["i"],"<",JsNode.PRMREXPR,["2"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["i"],"++"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1145 });1146 it('forstmt 14', function() {1147 var parser = homunculus.getParser('es6');1148 var node = parser.parse('for(let [a] = [1];;){}');1149 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.ARRBINDPAT,["[",JsNode.SINGLENAME,[JsNode.BINDID,["a"]],"]"],JsNode.INITLZ,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],"]"]]]],";"],";",")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1150 });1151 it('forstmt 15', function() {1152 var parser = homunculus.getParser('es6');1153 var node = parser.parse('for(let a = 1;;);');1154 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.LEXDECL,["let",JsNode.LEXBIND,[JsNode.BINDID,["a"],JsNode.INITLZ,["=",JsNode.PRMREXPR,["1"]]],";"],";",")",JsNode.EMPTSTMT,[";"]]]]]);1155 });1156 it('forstmt 16', function() {1157 var parser = homunculus.getParser('es6');1158 var node = parser.parse('for({a:b=1} of o){}');1159 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTDEF,[JsNode.PROPTNAME,[JsNode.LTRPROPT,["a"]],":",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]],"}"]],"of",JsNode.PRMREXPR,["o"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{","}"]]]]]]);1160 });1161 it('forstmt missing expr', function() {1162 var parser = homunculus.getParser('es6');1163 expect(function() {1164 parser.parse('for(');1165 }).to.throwError();1166 });1167 it('forstmt leftexpr error 1', function() {1168 var parser = homunculus.getParser('js');1169 expect(function() {1170 parser.parse('for(a() in b);');1171 }).to.throwError();1172 });1173 it('forstmt leftexpr error 2', function() {1174 var parser = homunculus.getParser('js');1175 expect(function() {1176 parser.parse('for(a() of b);');1177 }).to.throwError();1178 });1179 it('forstmt let error', function() {1180 var parser = homunculus.getParser('js');1181 expect(function() {1182 parser.parse('for(let ;;);');1183 }).to.throwError();1184 });1185 it('forstmt missing ; 1', function() {1186 var parser = homunculus.getParser('es6');1187 expect(function() {1188 parser.parse('for(var a');1189 }).to.throwError();1190 });1191 it('forstmt missing ; 2', function() {1192 var parser = homunculus.getParser('es6');1193 expect(function() {1194 parser.parse('for(var a;');1195 }).to.throwError();1196 });1197 it('forstmt missing ; 3', function() {1198 var parser = homunculus.getParser('es6');1199 expect(function() {1200 parser.parse('for(var a;a > 10;');1201 }).to.throwError();1202 });1203 it('forstmt missing ; 4', function() {1204 var parser = homunculus.getParser('es6');1205 expect(function() {1206 parser.parse('for(a');1207 }).to.throwError();1208 });1209 it('forstmt missing ; 5', function() {1210 var parser = homunculus.getParser('es6');1211 expect(function() {1212 parser.parse('for(a;');1213 }).to.throwError();1214 });1215 it('forstmt missing ; 6', function() {1216 var parser = homunculus.getParser('es6');1217 expect(function() {1218 parser.parse('for(a;b');1219 }).to.throwError();1220 });1221 it('forstmt missing ; 7', function() {1222 var parser = homunculus.getParser('es6');1223 expect(function() {1224 parser.parse('for(a;b;');1225 }).to.throwError();1226 });1227 it('forstmt with in could not has multi varstmt', function() {1228 var parser = homunculus.getParser('es6');1229 expect(function() {1230 parser.parse('for(var a,b in {});');1231 }).to.throwError();1232 });1233 it('forstmt with in first', function() {1234 var parser = homunculus.getParser('es6');1235 expect(function() {1236 parser.parse('for(in {});');1237 }).to.throwError();1238 });1239 it('cntnstmt 1', function() {1240 var parser = homunculus.getParser('es6');1241 var node = parser.parse('while(false){continue;}');1242 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue",";"],"}"]]]]]]);1243 });1244 it('cntnstmt 2', function() {1245 var parser = homunculus.getParser('es6');1246 var node = parser.parse('while(false){continue a;}');1247 expect(tree(node)).to.eql([JsNode.SCRIPT,[JsNode.SCRIPTBODY,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCKSTMT,[JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue","a",";"],"}"]]]]]]);1248 });1249 it('cntnstmt 3', function() {1250 var parser = homunculus.getParser('es6');1251 var node = parser.parse('while(false){continue\na;}');1252 expect(tree(node)).to.eql([JsNode.SCRIPT,[J