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,[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

cssparser.js

Source:cssparser.js Github

copy

Full Screen

...59 var rule = require('../src/lexer/rule/CssRule')60 var KEYWORDS = rule.KEYWORDS;61 var VALUES = rule.VALUES;62 var COLORS = rule.COLORS;63 var parser = homunculus.getParser('css');64 it('kw', function() {65 KEYWORDS.forEach(function(k) {66 expect(parser.lexer.rule.keyWords().hasOwnProperty(k)).to.be.ok();67 });68 });69 it('value', function() {70 VALUES.forEach(function(k) {71 expect(parser.lexer.rule.values().hasOwnProperty(k)).to.be.ok();72 });73 });74 it('color', function() {75 COLORS.forEach(function(k) {76 expect(parser.lexer.rule.colors().hasOwnProperty(k)).to.be.ok();77 });78 });79 });80 describe('simple test', function() {81 it('@import string', function() {82 var parser = homunculus.getParser('css');83 var node = parser.parse('@import "a";');84 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IMPORT,["@import",CssNode.URL,["\"a\""],";"]]]);85 });86 it('@import ignore case', function() {87 var parser = homunculus.getParser('css');88 var node = parser.parse('@IMPORT "a";');89 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IMPORT,["@IMPORT",CssNode.URL,["\"a\""],";"]]]);90 });91 it('@import url(string)', function() {92 var parser = homunculus.getParser('css');93 var node = parser.parse('@import url("a");');94 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IMPORT,["@import",CssNode.URL,["url","(","\"a\"",")"],";"]]]);95 });96 it('@import url(string) no quote', function() {97 var parser = homunculus.getParser('css');98 var node = parser.parse('@import url(a);');99 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IMPORT,["@import",CssNode.URL,["url","(","a",")"],";"]]]);100 });101 it('@import with media', function() {102 var parser = homunculus.getParser('css');103 var node = parser.parse('@import "a" all;');104 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IMPORT,["@import",CssNode.URL,["\"a\""],CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["all"]]],";"]]]);105 });106 it('@import error', function() {107 var parser = homunculus.getParser('css');108 expect(function() {109 parser.parse('@import');110 }).to.throwError();111 });112 it('@import string no ; error', function() {113 var parser = homunculus.getParser('css');114 expect(function() {115 parser.parse('@import url(a)');116 }).to.throwError();117 });118 it('@import string with \' error', function() {119 var parser = homunculus.getParser('css');120 expect(function() {121 parser.parse('@import \'a\';');122 }).to.throwError();123 });124 it('@media query type', function() {125 var parser = homunculus.getParser('css');126 var node = parser.parse('@media all');127 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["all"]]]]]]);128 });129 it('@media query expr', function() {130 var parser = homunculus.getParser('css');131 var node = parser.parse('@media (width:100)');132 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.EXPR,["(",CssNode.KEY,["width"],":",CssNode.VALUE,["100"],")"]]]]]]);133 });134 it('@media query{}', function() {135 var parser = homunculus.getParser('css');136 var node = parser.parse('@media all{}');137 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["all"]]],CssNode.BLOCK,["{","}"]]]]);138 });139 it('@media query and', function() {140 var parser = homunculus.getParser('css');141 var node = parser.parse('@media not all and(width:800px)');142 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,["not",CssNode.MEDIATYPE,["all"],"and",CssNode.EXPR,["(",CssNode.KEY,["width"],":",CssNode.VALUE,["800","px"],")"]]]]]]);143 });144 it('@media multi query', function() {145 var parser = homunculus.getParser('css');146 var node = parser.parse('@media only screen and (-webkit-min-device-pixel-ratio: 2), screen and (min--moz-device-pixel-ratio: 2){}');147 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,["only",CssNode.MEDIATYPE,["screen"],"and",CssNode.EXPR,["(",CssNode.KEY,["-webkit-","min-device-pixel-ratio"],":",CssNode.VALUE,["2"],")"]],",",CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["screen"],"and",CssNode.EXPR,["(",CssNode.KEY,["min--moz-device-pixel-ratio"],":",CssNode.VALUE,["2"],")"]]],CssNode.BLOCK,["{","}"]]]]);148 });149 it('@media ignore unknow', function() {150 var parser = homunculus.getParser('css');151 var node = parser.parse('@media screen,3D{}');152 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["screen"]],",",CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["3","D"]]],CssNode.BLOCK,["{","}"]]]]);153 });154 it('@media multi and', function() {155 var parser = homunculus.getParser('css');156 var node = parser.parse('@media only screen and (min-width:120.063em) and (max-width:99999999em){}');157 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,["only",CssNode.MEDIATYPE,["screen"],"and",CssNode.EXPR,["(",CssNode.KEY,["min-width"],":",CssNode.VALUE,["120.063","em"],")"],"and",CssNode.EXPR,["(",CssNode.KEY,["max-width"],":",CssNode.VALUE,["99999999","em"],")"]]],CssNode.BLOCK,["{","}"]]]]);158 });159 it('@media hack 1', function() {160 var parser = homunculus.getParser('css');161 var node = parser.parse('@media screen\\9');162 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["screen","\\9"]]]]]]);163 });164 it('@media hack 2', function() {165 var parser = homunculus.getParser('css');166 var node = parser.parse('@media \\0screen\\,screen\\9');167 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["\\0","screen","\\,","screen","\\9"]]]]]]);168 });169 it('@media hack 3', function() {170 var parser = homunculus.getParser('css');171 var node = parser.parse('@media \\03D\\,3D\\9');172 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["\\0","3", "D","\\,","3", "D","\\9"]]]]]]);173 });174 it('@media error 1', function() {175 var parser = homunculus.getParser('css');176 expect(function() {177 parser.parse('@media');178 }).to.throwError();179 });180 it('@media error 2', function() {181 var parser = homunculus.getParser('css');182 expect(function() {183 parser.parse('@media(');184 }).to.throwError();185 });186 it('@media error 3', function() {187 var parser = homunculus.getParser('css');188 expect(function() {189 parser.parse('@media (notkeyword:1)');190 }).to.throwError();191 });192 it('@media error 4', function() {193 var parser = homunculus.getParser('css');194 expect(function() {195 parser.parse('@media only');196 }).to.throwError();197 });198 it('@charset string', function() {199 var parser = homunculus.getParser('css');200 var node = parser.parse('@charset "arail";');201 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.CHARSET,["@charset","\"arail\"",";"]]]);202 });203 it('@charset vars', function() {204 var parser = homunculus.getParser('css');205 var node = parser.parse('@charset $a;');206 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.CHARSET,["@charset","$a",";"]]]);207 });208 it('@charset error 1', function() {209 var parser = homunculus.getParser('css');210 expect(function() {211 parser.parse('@charset');212 }).to.throwError();213 });214 it('@charset error 2', function() {215 var parser = homunculus.getParser('css');216 expect(function() {217 parser.parse('@charset "arial"');218 }).to.throwError();219 });220 it('@font-face normal', function() {221 var parser = homunculus.getParser('css');222 var node = parser.parse('@font-face{font-family:YH;src:url(http://domain/fonts/MSYH.TTF)}');223 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["font-family"],":",CssNode.VALUE,["YH"],";"],CssNode.STYLE,[CssNode.KEY,["src"],":",CssNode.VALUE,[CssNode.URL,["url","(","http://domain/fonts/MSYH.TTF",")"]]],"}"]]]]);224 });225 it('@font-face with format', function() {226 var parser = homunculus.getParser('css');227 var node = parser.parse('@font-face{font-family:YH;src:url(xx),format("embedded-opentype")}');228 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["font-family"],":",CssNode.VALUE,["YH"],";"],CssNode.STYLE,[CssNode.KEY,["src"],":",CssNode.VALUE,[CssNode.URL,["url","(","xx",")"],",",CssNode.FORMAT,["format","(","\"embedded-opentype\"",")"]]],"}"]]]]);229 });230 it('@font-face format first', function() {231 var parser = homunculus.getParser('css');232 var node = parser.parse('@font-face{font-family:YH;src:format("embedded-opentype")}');233 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["font-family"],":",CssNode.VALUE,["YH"],";"],CssNode.STYLE,[CssNode.KEY,["src"],":",CssNode.VALUE,[CssNode.FORMAT,["format","(","\"embedded-opentype\"",")"]]],"}"]]]]);234 });235 it('@font-face mulit', function() {236 var parser = homunculus.getParser('css');237 var node = parser.parse('@font-face{font-family:YH;src:url(a),url(b)}');238 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["font-family"],":",CssNode.VALUE,["YH"],";"],CssNode.STYLE,[CssNode.KEY,["src"],":",CssNode.VALUE,[CssNode.URL,["url","(","a",")"],",",CssNode.URL,["url","(","b",")"]]],"}"]]]]);239 });240 it('@font-face only one var', function() {241 var parser = homunculus.getParser('css');242 var node = parser.parse('@font-face{$a}');243 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{","$a","}"]]]]);244 });245 it('@font-face only multi vars', function() {246 var parser = homunculus.getParser('css');247 var node = parser.parse('@font-face{$a:$b}');248 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{","$a",":",CssNode.VALUE,["$b"],"}"]]]]);249 });250 it('@font-face width fnc', function() {251 var parser = homunculus.getParser('css');252 var node = parser.parse('@font-face{$a()}');253 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.FNC,["$a",CssNode.CPARAMS,["(",")"]],"}"]]]]);254 });255 it('@font-face width styleset', function() {256 var parser = homunculus.getParser('css');257 var node = parser.parse('@font-face{margin:0}');258 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0"]],"}"]]]]);259 });260 it('@font-face error', function() {261 var parser = homunculus.getParser('css');262 expect(function() {263 parser.parse('@font-face');264 }).to.throwError();265 });266 it('@page normal', function() {267 var parser = homunculus.getParser('css');268 var node = parser.parse('@page thin:first{size:3in 8in}');269 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.PAGE,["@page","thin",":first",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["size"],":",CssNode.VALUE,["3","in","8","in"]],"}"]]]]);270 });271 it('@page without id', function() {272 var parser = homunculus.getParser('css');273 var node = parser.parse('@page :first{size:3in 8in}');274 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.PAGE,["@page",":first",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["size"],":",CssNode.VALUE,["3","in","8","in"]],"}"]]]]);275 });276 it('@page empty', function() {277 var parser = homunculus.getParser('css');278 var node = parser.parse('@page {}');279 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.PAGE,["@page",CssNode.BLOCK,["{","}"]]]]);280 });281 it('@page error 1', function() {282 var parser = homunculus.getParser('css');283 expect(function() {284 parser.parse('@page thin:first');285 }).to.throwError();286 });287 it('@keyframes normal', function() {288 var parser = homunculus.getParser('css');289 var node = parser.parse('@keyframes testanimations{}');290 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.KEYFRAMES,["@keyframes","testanimations",CssNode.BLOCK,["{","}"]]]]);291 });292 it('@keyframes from to', function() {293 var parser = homunculus.getParser('css');294 var node = parser.parse('@keyframes testanimations{from{transform:translate(0,0)}to{transform:translate(100,20)}}');295 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.KEYFRAMES,["@keyframes","testanimations",CssNode.BLOCK,["{",CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["from"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["transform"],":",CssNode.VALUE,[CssNode.TRANSLATE,["translate","(",CssNode.PARAM,["0"],",",CssNode.PARAM,["0"],")"]]],"}"]],CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["to"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["transform"],":",CssNode.VALUE,[CssNode.TRANSLATE,["translate","(",CssNode.PARAM,["100"],",",CssNode.PARAM,["20"],")"]]],"}"]],"}"]]]]);296 });297 it('@keyframes percent', function() {298 var parser = homunculus.getParser('css');299 var node = parser.parse('@keyframes testanimations{10%{width:0}}');300 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.KEYFRAMES,["@keyframes","testanimations",CssNode.BLOCK,["{",CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["10","%"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["0"]],"}"]],"}"]]]]);301 });302 it('@keyframes width var', function() {303 var parser = homunculus.getParser('css');304 var node = parser.parse('@keyframes bn$j{}');305 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.KEYFRAMES,["@keyframes","bn","$j",CssNode.BLOCK,["{","}"]]]]);306 });307 it('@keyframes error 1', function() {308 var parser = homunculus.getParser('css');309 expect(function() {310 parser.parse('@keyframes {}');311 }).to.throwError();312 });313 it('@keyframes error 2', function() {314 var parser = homunculus.getParser('css');315 expect(function() {316 parser.parse('@keyframes a');317 }).to.throwError();318 });319 it('@namespace normal', function() {320 var parser = homunculus.getParser('css');321 var node = parser.parse('@namespace a "url";');322 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.NAMESPACE,["@namespace","a","\"url\"",";"]]]);323 });324 it('@namespace without id', function() {325 var parser = homunculus.getParser('css');326 var node = parser.parse('@namespace "url";');327 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.NAMESPACE,["@namespace","\"url\"",";"]]]);328 });329 it('@namespace error 1', function() {330 var parser = homunculus.getParser('css');331 expect(function() {332 parser.parse('@namespace');333 }).to.throwError();334 });335 it('@namespace error 2', function() {336 var parser = homunculus.getParser('css');337 expect(function() {338 parser.parse('@keyframes {}');339 }).to.throwError();340 });341 it('@document normal', function() {342 var parser = homunculus.getParser('css');343 var node = parser.parse('@-moz-document url-prefix(){}');344 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@-moz-document",CssNode.URLPREFIX,["url-prefix","(",")"],CssNode.BLOCK,["{","}"]]]]);345 });346 it('@document string', function() {347 var parser = homunculus.getParser('css');348 var node = parser.parse('@document url-prefix("test"){}');349 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URLPREFIX,["url-prefix","(","\"test\"",")"],CssNode.BLOCK,["{","}"]]]]);350 });351 it('@document var', function() {352 var parser = homunculus.getParser('css');353 var node = parser.parse('@document url-prefix($a){}');354 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URLPREFIX,["url-prefix","(","$a",")"],CssNode.BLOCK,["{","}"]]]]);355 });356 it('@document multi', function() {357 var parser = homunculus.getParser('css');358 var node = parser.parse('@document url-prefix($a),url(){}');359 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URLPREFIX,["url-prefix","(","$a",")"],",",CssNode.URL,["url","(",")"],CssNode.BLOCK,["{","}"]]]]);360 });361 it('@document multi var', function() {362 var parser = homunculus.getParser('css');363 var node = parser.parse('@document url-prefix($a),url($b + 2),domain(aaa){}');364 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URLPREFIX,["url-prefix","(","$a",")"],",",CssNode.URL,["url","(",CssNode.ADDEXPR,["$b","+","2"],")"],",",CssNode.DOMAIN,["domain","(","aaa",")"],CssNode.BLOCK,["{","}"]]]]);365 });366 it('@document url()', function() {367 var parser = homunculus.getParser('css');368 var node = parser.parse('@document url(),url(){}');369 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URL,["url","(",")"],",",CssNode.URL,["url","(",")"],CssNode.BLOCK,["{","}"]]]]);370 });371 it('@document error 1', function() {372 var parser = homunculus.getParser('css');373 expect(function() {374 parser.parse('@-moz-document');375 }).to.throwError();376 });377 it('@document error 2', function() {378 var parser = homunculus.getParser('css');379 expect(function() {380 parser.parse('@-moz-document {}');381 }).to.throwError();382 });383 it('@document error 3', function() {384 var parser = homunculus.getParser('css');385 expect(function() {386 parser.parse('@-moz-document a{}');387 }).to.throwError();388 });389 it('@document error 4', function() {390 var parser = homunculus.getParser('css');391 expect(function() {392 parser.parse('@-moz-document a({}');393 }).to.throwError();394 });395 it('@document error 5', function() {396 var parser = homunculus.getParser('css');397 expect(function() {398 parser.parse('@document url(),xxx(){}');399 }).to.throwError();400 });401 it('@document error 6', function() {402 var parser = homunculus.getParser('css');403 expect(function() {404 parser.parse('@document url(),');405 }).to.throwError();406 });407 it('@viewport', function() {408 var parser = homunculus.getParser('css');409 var node = parser.parse('@viewport{width:0}');410 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VIEWPORT,["@viewport",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["0"]],"}"]]]]);411 });412 it('@counter-style', function() {413 var parser = homunculus.getParser('css');414 var node = parser.parse('@counter-style a{width:0}');415 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.CTSTYLE,["@counter-style","a",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["0"]],"}"]]]]);416 });417 it('@supports', function() {418 var parser = homunculus.getParser('css');419 var node = parser.parse('@supports not(transform-origin:2px){}');420 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.SUPPORTS,["@supports",CssNode.CNDT,["not",CssNode.CNDT,["(",CssNode.CNDT,[CssNode.STYLE,[CssNode.KEY,["transform-origin"],":",CssNode.VALUE,["2","px"]]],")"]],CssNode.BLOCK,["{","}"]]]]);421 });422 it('@keyframes in @supports', function() {423 var parser = homunculus.getParser('css');424 var node = parser.parse('@supports(animation-name:test){@keyframes a{}}');425 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.SUPPORTS,["@supports",CssNode.CNDT,["(",CssNode.CNDT,[CssNode.STYLE,[CssNode.KEY,["animation-name"],":",CssNode.VALUE,["test"]]],")"],CssNode.BLOCK,["{",CssNode.KEYFRAMES,["@keyframes","a",CssNode.BLOCK,["{","}"]],"}"]]]]);426 });427 it('@supports error', function() {428 var parser = homunculus.getParser('css');429 expect(function() {430 parser.parse('@supports not(');431 }).to.throwError();432 });433 it('$ is variable', function() {434 var parser = homunculus.getParser('css');435 var node = parser.parse('body{width:$a}');436 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["$a"]],"}"]]]]);437 });438 it('unknow @ is variable', function() {439 var parser = homunculus.getParser('css');440 var node = parser.parse('body{width:@a}');441 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["@a"]],"}"]]]]);442 });443 it('normal style', function() {444 var parser = homunculus.getParser('css');445 var node = parser.parse('body{width:0}');446 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,["0"]],"}"]]]]);447 });448 it('css3 variable', function() {449 var parser = homunculus.getParser('css');450 var node = parser.parse(':root{var-companyblue:#369;var-lighterblue:powderblue;}');451 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[":root"]],CssNode.BLOCK,["{",CssNode.VARSTMT,[CssNode.VARDECL,["var-companyblue",":",CssNode.VALUE,["#369"]],";"],CssNode.VARSTMT,[CssNode.VARDECL,["var-lighterblue",":",CssNode.VALUE,["powderblue"]],";"],"}"]]]]);452 });453 it('css3 var()', function() {454 var parser = homunculus.getParser('css');455 var node = parser.parse('h3{color:var(lighterblue);}');456 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["h3"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.VARS,["var","(","lighterblue",")"]],";"],"}"]]]]);457 });458 it('vardecl', function() {459 var parser = homunculus.getParser('css');460 var node = parser.parse('$a:1;@b=2;');461 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,["1"]],";"],CssNode.VARSTMT,[CssNode.VARDECL,["@b","=",CssNode.VALUE,["2"]],";"]]]);462 });463 it('vardecl a kw value', function() {464 var parser = homunculus.getParser('css');465 var node = parser.parse('$a:background;');466 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,["background"]],";"]]]);467 });468 it('vardecl a style', function() {469 var parser = homunculus.getParser('css');470 var node = parser.parse('$a:background:#FFF;');471 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,["#FFF"]]],";"]]]);472 });473 it('vardecl hack error', function() {474 var parser = homunculus.getParser('css');475 expect(function() {476 parser.parse('$a:*background;');477 }).to.throwError();478 });479 it('vardecl hack value', function() {480 var parser = homunculus.getParser('css');481 var node = parser.parse('$a:*background:url(xxx);');482 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.STYLE,[CssNode.KEY,["*","background"],":",CssNode.VALUE,[CssNode.URL,["url","(","xxx",")"]]]],";"]]]);483 });484 it('vardecl add', function() {485 var parser = homunculus.getParser('css');486 var node = parser.parse('$a:1+ 2;');487 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.ADDEXPR,["1","+","2"]]],";"]]]);488 });489 it('vardecl mtpl', function() {490 var parser = homunculus.getParser('css');491 var node = parser.parse('$a:1*2;');492 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.MTPLEXPR,["1","*","2"]]],";"]]]);493 });494 it('vardecl string add', function() {495 var parser = homunculus.getParser('css');496 var node = parser.parse('$a:margin:"1"+ 2;');497 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.ADDEXPR,["\"1\"","+","2"]]]],";"]]]);498 });499 it('vardecl string mtpl', function() {500 var parser = homunculus.getParser('css');501 var node = parser.parse('$a:margin:"1"*2;');502 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.MTPLEXPR,["\"1\"","*","2"]]]],";"]]]);503 });504 it('vardecl url()', function() {505 var parser = homunculus.getParser('css');506 var node = parser.parse('$a:url(xxx);');507 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.URL,["url","(","xxx",")"]]],";"]]]);508 });509 it('vardecl fn()', function() {510 var parser = homunculus.getParser('css');511 var node = parser.parse('$a:unknow();');512 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.BRACKET,["unknow","(",")"]]],";"]]]);513 });514 it('vardecl $fn()', function() {515 var parser = homunculus.getParser('css');516 var node = parser.parse('$a:$b();');517 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.FNC,["$b",CssNode.CPARAMS,["(",")"]]]],";"]]]);518 });519 it('vardecl in block', function() {520 var parser = homunculus.getParser('css');521 var node = parser.parse('.a{$a=1;$b:background:#FFF}');522 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,["1"]],";"],CssNode.VARSTMT,[CssNode.VARDECL,["$b",":",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,["#FFF"]]]],"}"]]]]);523 });524 it('vardecl multi', function() {525 var parser = homunculus.getParser('css');526 var node = parser.parse('$a=1,$b="2";');527 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,["1"]],",",CssNode.VARDECL,["$b","=",CssNode.VALUE,["\"2\""]],";"]]]);528 });529 it('vardecl error 1', function() {530 var parser = homunculus.getParser('css');531 expect(function() {532 parser.parse('$a');533 }).to.throwError();534 });535 it('vardecl error 2', function() {536 var parser = homunculus.getParser('css');537 expect(function() {538 parser.parse('$a:');539 }).to.throwError();540 });541 it('vardecl error 3', function() {542 var parser = homunculus.getParser('css');543 expect(function() {544 parser.parse('$a/');545 }).to.throwError();546 });547 it('vardecl error no ;', function() {548 var parser = homunculus.getParser('css');549 expect(function() {550 parser.parse('$a:1');551 }).to.throwError();552 });553 it('nesting {}', function() {554 var parser = homunculus.getParser('css');555 var node = parser.parse('h3{color:#000;h1{margin:0}}');556 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["h3"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,["#000"],";"],CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["h1"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0"]],"}"]],"}"]]]]);557 });558 it('multi selectors', function() {559 var parser = homunculus.getParser('css');560 var node = parser.parse('a,p{}');561 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"],",",CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{","}"]]]]);562 });563 it('multi values', function() {564 var parser = homunculus.getParser('css');565 var node = parser.parse('a{margin:0px 2px 3% auto}');566 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0","px","2","px","3","%","auto"]],"}"]]]]);567 });568 it('[pseudo]', function() {569 var parser = homunculus.getParser('css');570 var node = parser.parse('[hidden]{}');571 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["[","hidden","]"]],CssNode.BLOCK,["{","}"]]]]);572 });573 it('[pseudo] in block', function() {574 var parser = homunculus.getParser('css');575 var node = parser.parse('a{[hidden]{}}');576 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["[","hidden","]"]],CssNode.BLOCK,["{","}"]],"}"]]]]);577 });578 it('selector[pseudo]', function() {579 var parser = homunculus.getParser('css');580 var node = parser.parse('a[hidden]{}');581 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a","[","hidden","]"]],CssNode.BLOCK,["{","}"]]]]);582 });583 it('selector +', function() {584 var parser = homunculus.getParser('css');585 var node = parser.parse('a>b+c{}');586 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a",">","b","+","c"]],CssNode.BLOCK,["{","}"]]]]);587 });588 it('selector with hack', function() {589 var parser = homunculus.getParser('css');590 var node = parser.parse('_:-ms-fullscreen,:root input[type="date"],_:-ms-fullscreen{}');591 expect(tree(node)).to.eql([CssNode.SHEET,["_",CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[":-ms-fullscreen"],",",CssNode.SELECTOR,[":root","input","[","type","=","\"date\"","]"],",",CssNode.SELECTOR,["_",":-ms-fullscreen"]],CssNode.BLOCK,["{","}"]]]]);592 });593 it('selector both name and class', function() {594 var parser = homunculus.getParser('css');595 var node = parser.parse('a.a{filter:progid:DXImageTransform.Microsoft.gradient(enabled = false)}');596 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a",".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,["progid",":","DXImageTransform",".","Microsoft",".",CssNode.BRACKET,["gradient","(","enabled","=","false",")"]]],"}"]]]]);597 });598 it('pseudo first', function() {599 var parser = homunculus.getParser('css');600 var node = parser.parse(':hover{margin:0}');601 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[":hover"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0"]],"}"]]]]);602 });603 it('pseudo complex', function() {604 var parser = homunculus.getParser('css');605 var node = parser.parse('[disabled]:not(:first)[checked]:not([data="123"]){}');606 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["[","disabled","]",":not","(",":first",")","[","checked","]",":not","(","[","data","=","\"123\"","]",")"]],CssNode.BLOCK,["{","}"]]]]);607 });608 it('hack', function() {609 var parser = homunculus.getParser('css');610 var node = parser.parse('p{[;width:0;];}');611 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["[",";","width"],":",CssNode.VALUE,["0"],";","]",";"],"}"]]]]);612 });613 it('rgb', function() {614 var parser = homunculus.getParser('css');615 var node = parser.parse('p{color:rgb(0, 0, 255)}');616 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RGB,["rgb","(","0",",","0",",","255",")"]]],"}"]]]]);617 });618 it('rgba', function() {619 var parser = homunculus.getParser('css');620 var node = parser.parse('p{color:rgba(0, 0, 255, 0.5)}');621 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RGBA,["rgba","(","0",",","0",",","255",",","0.5",")"]]],"}"]]]]);622 });623 it('hsl', function() {624 var parser = homunculus.getParser('css');625 var node = parser.parse('p{color:hsl(0, 5%, 100%)}');626 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.HSL,["hsl","(","0",",","5","%",",","100","%",")"]]],"}"]]]]);627 });628 it('hsl zero', function() {629 var parser = homunculus.getParser('css');630 var node = parser.parse('p{color:hsl(0, 0, 100%)}');631 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.HSL,["hsl","(","0",",","0",",","100","%",")"]]],"}"]]]]);632 });633 it('hsl units error 1', function() {634 var parser = homunculus.getParser('css');635 expect(function() {636 parser.parse('p{color:hsl(0, 3, 100%)}')637 }).to.throwError();638 });639 it('hsl units error 2', function() {640 var parser = homunculus.getParser('css');641 expect(function() {642 parser.parse('p{color:hsl(0, 3%, 100deg)}')643 }).to.throwError();644 });645 it('hsla', function() {646 var parser = homunculus.getParser('css');647 var node = parser.parse('p{color:hsla(0, 5%, 100%, 0.2)}');648 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.HSLA,["hsla","(","0",",","5","%",",","100","%",",","0.2",")"]]],"}"]]]]);649 });650 it('max', function() {651 var parser = homunculus.getParser('css');652 var node = parser.parse('p{color:max(1 + 2, 100)}');653 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.MAX,["max","(",CssNode.PARAM,["1","+","2"],",",CssNode.PARAM,["100"],")"]]],"}"]]]]);654 });655 it('min', function() {656 var parser = homunculus.getParser('css');657 var node = parser.parse('p{color:min(1 + 2, 100)}');658 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.MIN,["min","(",CssNode.PARAM,["1","+","2"],",",CssNode.PARAM,["100"],")"]]],"}"]]]]);659 });660 it('linear-gradient 1', function() {661 var parser = homunculus.getParser('css');662 var node = parser.parse('p{background:linear-gradient(#fff,#333)}');663 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.LINEARGRADIENT,["linear-gradient","(",CssNode.COLORSTOP,["#fff"],",",CssNode.COLORSTOP,["#333"],")"]]],"}"]]]]);664 });665 it('linear-gradient 2', function() {666 var parser = homunculus.getParser('css');667 var node = parser.parse('p{background:linear-gradient(to right,#fff 10%,#333,red)}');668 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.LINEARGRADIENT,["linear-gradient","(",CssNode.POINT,["to","right"],",",CssNode.COLORSTOP,["#fff","10","%"],",",CssNode.COLORSTOP,["#333"],",",CssNode.COLORSTOP,["red"],")"]]],"}"]]]]);669 });670 it('linear-gradient 3', function() {671 var parser = homunculus.getParser('css');672 var node = parser.parse('p{background:linear-gradient(45deg,#fff 10%,transparent)}');673 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.LINEARGRADIENT,["linear-gradient","(",CssNode.POINT,["45","deg"],",",CssNode.COLORSTOP,["#fff","10","%"],",",CssNode.COLORSTOP,["transparent"],")"]]],"}"]]]]);674 });675 it('linear-gradient 4', function() {676 var parser = homunculus.getParser('css');677 var node = parser.parse('p{background:-moz-linear-gradient(left center,#000 20%,#f00 50%,#090 0)}');678 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,["-moz-",CssNode.LINEARGRADIENT,["linear-gradient","(",CssNode.POINT,["left","center"],",",CssNode.COLORSTOP,["#000","20","%"],",",CssNode.COLORSTOP,["#f00","50","%"],",",CssNode.COLORSTOP,["#090","0"],")"]]],"}"]]]]);679 });680 it('linear-gradient miss % error', function() {681 var parser = homunculus.getParser('css');682 expect(function() {683 parser.parse('p{color:radial-gradient(50, 10% 20%,rgb(0,0,0))}');684 }).to.throwError();685 });686 it('radial-gradient 1', function() {687 var parser = homunculus.getParser('css');688 var node = parser.parse('p{color:radial-gradient(circle,#f00,#ff0,#080)}');689 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RADIOGRADIENT,["radial-gradient","(","circle",",",CssNode.COLORSTOP,["#f00"],",",CssNode.COLORSTOP,["#ff0"],",",CssNode.COLORSTOP,["#080"],")"]]],"}"]]]]);690 });691 it('radial-gradient 2', function() {692 var parser = homunculus.getParser('css');693 var node = parser.parse('p{color:radial-gradient(50%, 10% 20%,#f00,#ff0,#080)}');694 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RADIOGRADIENT,["radial-gradient","(",CssNode.POS,[CssNode.LEN,["50","%"]],",",CssNode.LEN,["10","%"],CssNode.LEN,["20","%"],",",CssNode.COLORSTOP,["#f00"],",",CssNode.COLORSTOP,["#ff0"],",",CssNode.COLORSTOP,["#080"],")"]]],"}"]]]]);695 });696 it('radial-gradient 3', function() {697 var parser = homunculus.getParser('css');698 var node = parser.parse('p{color:radial-gradient(50%, 10% 20%,rgb(0,0,0),hsla(0, 5%, 100%, 0))}');699 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RADIOGRADIENT,["radial-gradient","(",CssNode.POS,[CssNode.LEN,["50","%"]],",",CssNode.LEN,["10","%"],CssNode.LEN,["20","%"],",",CssNode.COLORSTOP,[CssNode.RGB,["rgb","(","0",",","0",",","0",")"]],",",CssNode.COLORSTOP,[CssNode.HSLA,["hsla","(","0",",","5","%",",","100","%",",","0",")"]],")"]]],"}"]]]]);700 });701 it('radial-gradient 4', function() {702 var parser = homunculus.getParser('css');703 var node = parser.parse('p{color:radial-gradient(center,circle,#f00,#ff0,hsl(0, 5%, 100%));}');704 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,[CssNode.RADIOGRADIENT,["radial-gradient","(",CssNode.POS,["center"],",","circle",",",CssNode.COLORSTOP,["#f00"],",",CssNode.COLORSTOP,["#ff0"],",",CssNode.COLORSTOP,[CssNode.HSL,["hsl","(","0",",","5","%",",","100","%",")"]],")"]],";"],"}"]]]]);705 });706 it('radial-gradient 5', function() {707 var parser = homunculus.getParser('css');708 var node = parser.parse('p{color:-webkit-radial-gradient(left top,cover,#f00 20%,#ff0 50%,#080 0)}');709 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,["-webkit-",CssNode.RADIOGRADIENT,["radial-gradient","(",CssNode.POS,["left","top"],",","cover",",",CssNode.COLORSTOP,["#f00","20","%"],",",CssNode.COLORSTOP,["#ff0","50","%"],",",CssNode.COLORSTOP,["#080","0"],")"]]],"}"]]]]);710 });711 it(') error', function() {712 var parser = homunculus.getParser('css');713 expect(function() {714 parser.parse('p{color:)}');715 }).to.throwError();716 });717 it('multi fn()', function() {718 var parser = homunculus.getParser('css');719 var node = parser.parse('p{color:#f00 max(1) min(2) hsl(0, 5%, 100%) hsla(0, 5%, 100%, 0) calc(1 + 1) var(a) rgb(0,0,0) repeating-radial-gradient(circle,#f00,#ff0,#080)}');720 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,["#f00",CssNode.MAX,["max","(",CssNode.PARAM,["1"],")"],CssNode.MIN,["min","(",CssNode.PARAM,["2"],")"],CssNode.HSL,["hsl","(","0",",","5","%",",","100","%",")"],CssNode.HSLA,["hsla","(","0",",","5","%",",","100","%",",","0",")"],CssNode.CALC,["calc","(","1","+","1",")"],CssNode.VARS,["var","(","a",")"],CssNode.RGB,["rgb","(","0",",","0",",","0",")"],CssNode.RADIOGRADIENT,["repeating-radial-gradient","(","circle",",",CssNode.COLORSTOP,["#f00"],",",CssNode.COLORSTOP,["#ff0"],",",CssNode.COLORSTOP,["#080"],")"]]],"}"]]]]);721 });722 it('new kw', function() {723 var parser = homunculus.getParser('css');724 parser.lexer.rule.addKeyWord('xx');725 var node = parser.parse('p{xx:#fff}');726 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["xx"],":",CssNode.VALUE,['#fff']],"}"]]]]);727 });728 it('var can contain a styleset', function() {729 var parser = homunculus.getParser('css');730 parser.lexer.rule.addKeyWord('xx');731 var node = parser.parse('@a = color:#fff;');732 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["@a","=",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,["#fff"]]],";"]]]);733 });734 it('fn decl', function() {735 var parser = homunculus.getParser('css');736 var node = parser.parse('fn($a, $b){margin:$a;$b;$c()}');737 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FN,["fn",CssNode.PARAMS,["(","$a",",","$b",")"],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["$a"],";"],"$b",";",CssNode.FNC,["$c",CssNode.CPARAMS,["(",")"]],"}"]]]]);738 });739 it('fn call a value', function() {740 var parser = homunculus.getParser('css');741 var node = parser.parse('body{fn(#FFF)}');742 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,["#FFF"],")"]],"}"]]]]);743 });744 it('fn call multi value', function() {745 var parser = homunculus.getParser('css');746 var node = parser.parse('body{fn(#FFF, 3, id)}');747 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,["#FFF"],",",CssNode.VALUE,["3"],",",CssNode.VALUE,["id"],")"]],"}"]]]]);748 });749 it('fn call a kw value', function() {750 var parser = homunculus.getParser('css');751 var node = parser.parse('body{fn(background)}');752 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,["background"],")"]],"}"]]]]);753 });754 it('fn call complex', function() {755 var parser = homunculus.getParser('css');756 var node = parser.parse('body{fn(background:#FFF, margin, 3px, padding:0)}');757 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,["#FFF"]],",",CssNode.VALUE,["margin"],",",CssNode.VALUE,["3","px"],",",CssNode.STYLE,[CssNode.KEY,["padding"],":",CssNode.VALUE,["0"]],")"]],"}"]]]]);758 });759 it('fn call in value', function() {760 var parser = homunculus.getParser('css');761 var node = parser.parse('a{margin:$fn(1)}');762 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,["1"],")"]]]],"}"]]]]);763 });764 it('fn call in value multi value', function() {765 var parser = homunculus.getParser('css');766 var node = parser.parse('a{margin:$fn(1, #FFF)}');767 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,["1"],",",CssNode.VALUE,["#FFF"],")"]]]],"}"]]]]);768 });769 it('fn call in value a kw value', function() {770 var parser = homunculus.getParser('css');771 var node = parser.parse('a{margin:$fn(background)}');772 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,["background"],")"]]]],"}"]]]]);773 });774 it('fn call in value complex', function() {775 var parser = homunculus.getParser('css');776 var node = parser.parse('body{margin:$fn(background:#FFF,margin,3px,padding:0)}');777 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,["#FFF"]],",",CssNode.VALUE,["margin"],",",CssNode.VALUE,["3","px"],",",CssNode.STYLE,[CssNode.KEY,["padding"],":",CssNode.VALUE,["0"]],")"]]]],"}"]]]]);778 });779 it('fn call url()', function() {780 var parser = homunculus.getParser('css');781 var node = parser.parse('body{fn(background:url(xxx),margin)}');782 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.URL,["url","(","xxx",")"]]],",",CssNode.VALUE,["margin"],")"]],"}"]]]]);783 });784 it('not at first value fn call', function() {785 var parser = homunculus.getParser('css');786 var node = parser.parse('body{margin:1 $fn(#FFF)}');787 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["1",CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,["#FFF"],")"]]]],"}"]]]]);788 });789 it('fn add', function() {790 var parser = homunculus.getParser('css');791 var node = parser.parse('body{fn(1 + 2)}');792 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.ADDEXPR,["1","+","2"]],")"]],"}"]]]]);793 });794 it('fn add in value', function() {795 var parser = homunculus.getParser('css');796 var node = parser.parse('body{margin:$fn(1 + 2)}');797 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.ADDEXPR,["1","+","2"]],")"]]]],"}"]]]]);798 });799 it('fn string add', function() {800 var parser = homunculus.getParser('css');801 var node = parser.parse('body{fn("1" + 2)}');802 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.ADDEXPR,["\"1\"","+","2"]],")"]],"}"]]]]);803 });804 it('fn string add in value', function() {805 var parser = homunculus.getParser('css');806 var node = parser.parse('body{margin:$fn("1" + 2)}');807 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.ADDEXPR,["\"1\"","+","2"]],")"]]]],"}"]]]]);808 });809 it('fn mtpl', function() {810 var parser = homunculus.getParser('css');811 var node = parser.parse('body{fn(1 * 2)}');812 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.MTPLEXPR,["1","*","2"]],")"]],"}"]]]]);813 });814 it('fn string mtpl in value', function() {815 var parser = homunculus.getParser('css');816 var node = parser.parse('body{margin:$fn("1" * 2)}');817 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.MTPLEXPR,["\"1\"","*","2"]],")"]]]],"}"]]]]);818 });819 it('fn string mtpl', function() {820 var parser = homunculus.getParser('css');821 var node = parser.parse('body{fn("1" * 2)}');822 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.MTPLEXPR,["\"1\"","*","2"]],")"]],"}"]]]]);823 });824 it('fn mtpl in value', function() {825 var parser = homunculus.getParser('css');826 var node = parser.parse('body{margin:$fn(1 * 2)}');827 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.VALUE,[CssNode.MTPLEXPR,["1","*","2"]],")"]]]],"}"]]]]);828 });829 it('fn hack error', function() {830 var parser = homunculus.getParser('css');831 expect(function() {832 parser.parse('body{fn(*margin)}');833 }).to.throwError();834 });835 it('fn hack value', function() {836 var parser = homunculus.getParser('css');837 var node = parser.parse('body{fn(*margin:a)}');838 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["*","margin"],":",CssNode.VALUE,["a"]],")"]],"}"]]]]);839 });840 it('fn hack in value', function() {841 var parser = homunculus.getParser('css');842 var node = parser.parse('body{margin:$fn(*background:url(xxx))}');843 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["*","background"],":",CssNode.VALUE,[CssNode.URL,["url","(","xxx",")"]]],")"]]]],"}"]]]]);844 });845 it('fn arr', function() {846 var parser = homunculus.getParser('css');847 var node = parser.parse('div{$fn([1,2])}');848 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.ARRLTR,["[",CssNode.VALUE,["1"],",",CssNode.VALUE,["2"],"]"],")"]],"}"]]]]);849 });850 it('fn @dir', function() {851 var parser = homunculus.getParser('css');852 var node = parser.parse('div{$fn(@dir(""))}');853 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.DIR,["@dir",CssNode.CPARAMS,["(",CssNode.VALUE,["\"\""],")"]],")"]],"}"]]]]);854 });855 it('@extend', function() {856 var parser = homunculus.getParser('css');857 var node = parser.parse('body{@extend a}');858 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.EXTEND,["@extend",CssNode.SELECTORS,[CssNode.SELECTOR,["a"]]],"}"]]]]);859 });860 it('@extend multi', function() {861 var parser = homunculus.getParser('css');862 var node = parser.parse('body[type=text]{@extend .a, input[type=text]}');863 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body","[","type","=","text","]"]],CssNode.BLOCK,["{",CssNode.EXTEND,["@extend",CssNode.SELECTORS,[CssNode.SELECTOR,[".a"],",",CssNode.SELECTOR,["input","[","type","=","text","]"]]],"}"]]]]);864 });865 it('@extend error', function() {866 var parser = homunculus.getParser('css');867 expect(function() {868 parser.parse('body{@extend');869 }).to.throwError();870 });871 it('&', function() {872 var parser = homunculus.getParser('css');873 var node = parser.parse('body{&:hover{}}');874 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["&",":hover"]],CssNode.BLOCK,["{","}"]],"}"]]]]);875 });876 it('no value is error', function() {877 var parser = homunculus.getParser('css');878 expect(function() {879 parser.parse('body{width}');880 }).to.throwError();881 });882 it('$ no value is right', function() {883 var parser = homunculus.getParser('css');884 var node = parser.parse('body{$a}');885 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{","$a","}"]]]]);886 });887 it('counter', function() {888 var parser = homunculus.getParser('css');889 var node = parser.parse('body{content:counter(item)}');890 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.COUNTER,["counter","(",CssNode.PARAM,["item"],")"]]],"}"]]]]);891 });892 it('counter multi', function() {893 var parser = homunculus.getParser('css');894 var node = parser.parse('body{content:counter($a, 2)}');895 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.COUNTER,["counter","(",CssNode.PARAM,["$a"],",",CssNode.PARAM,["2"],")"]]],"}"]]]]);896 });897 it('attr', function() {898 var parser = homunculus.getParser('css');899 var node = parser.parse('body{content:attr(item)}');900 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.ATTR,["attr","(",CssNode.PARAM,["item"],")"]]],"}"]]]]);901 });902 it('attr multi', function() {903 var parser = homunculus.getParser('css');904 var node = parser.parse('body{content:attr($a, 2)}');905 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.ATTR,["attr","(",CssNode.PARAM,["$a"],",",CssNode.PARAM,["2"],")"]]],"}"]]]]);906 });907 it('toggle', function() {908 var parser = homunculus.getParser('css');909 var node = parser.parse('body{content:toggle(item)}');910 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.TOGGLE,["toggle","(",CssNode.PARAM,["item"],")"]]],"}"]]]]);911 });912 it('toggle multi', function() {913 var parser = homunculus.getParser('css');914 var node = parser.parse('body{content:toggle($a, 2)}');915 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.TOGGLE,["toggle","(",CssNode.PARAM,["$a"],",",CssNode.PARAM,["2"],")"]]],"}"]]]]);916 });917 it('calc', function() {918 var parser = homunculus.getParser('css');919 var node = parser.parse('body{width:calc(100 - 2)}');920 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,[CssNode.CALC,["calc","(","100","-","2",")"]]],"}"]]]]);921 });922 it('calc complex', function() {923 var parser = homunculus.getParser('css');924 var node = parser.parse('body{width:calc((100 - 2)*3)}');925 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["width"],":",CssNode.VALUE,[CssNode.CALC,["calc","(","(","100","-","2",")","*","3",")"]]],"}"]]]]);926 });927 it('calc error', function() {928 var parser = homunculus.getParser('css');929 expect(function() {930 parser.parse('a{margin:calc(1+})}');931 }).to.throwError();932 });933 it('filter()', function() {934 var parser = homunculus.getParser('css');935 var node = parser.parse('body{filter:alpha(opacity=50)}');936 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,[CssNode.FILTER,["alpha","(",CssNode.PARAM,["opacity","=","50"],")"]]],"}"]]]]);937 });938 it('filter single', function() {939 var parser = homunculus.getParser('css');940 var node = parser.parse('body{filter:alpha}');941 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,["alpha"]],"}"]]]]);942 });943 it('filter() multi', function() {944 var parser = homunculus.getParser('css');945 var node = parser.parse('body{filter:Glow(Color="#6699CC",Strength="5")}');946 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,[CssNode.FILTER,["Glow","(",CssNode.PARAM,["Color","=","\"#6699CC\""],",",CssNode.PARAM,["Strength","=","\"5\""],")"]]],"}"]]]]);947 });948 it('unknow bracket', function() {949 var parser = homunculus.getParser('css');950 var node = parser.parse('body{margin:unknow(xxx,xxx)}');951 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.BRACKET,["unknow","(","xxx",",","xxx",")"]]],"}"]]]]);952 });953 it('unknow bracket multi', function() {954 var parser = homunculus.getParser('css');955 var node = parser.parse('a{background-image: -webkit-gradient(linear, left top, right top, from(rgba(0, 0, 0, .5)), to(rgba(0, 0, 0, .0001)));}');956 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background-image"],":",CssNode.VALUE,["-webkit-",CssNode.BRACKET,["gradient","(","linear",",","left","top",",","right","top",",",CssNode.BRACKET,["from","(",CssNode.BRACKET,["rgba","(","0",",","0",",","0",",",".5",")"],")"],",",CssNode.BRACKET,["to","(",CssNode.BRACKET,["rgba","(","0",",","0",",","0",",",".0001",")"],")"],")"]],";"],"}"]]]]);957 });958 it('param error', function() {959 var parser = homunculus.getParser('css');960 expect(function() {961 parser.parse('a{margin:max(,)}');962 }).to.throwError();963 });964 it('omit @extend for compatible less', function() {965 var parser = homunculus.getParser('css');966 var node = parser.parse('.a{.b}');967 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.EXTEND,[CssNode.SELECTORS,[CssNode.SELECTOR,[".b"]]],"}"]]]]);968 });969 it('miss {', function() {970 var parser = homunculus.getParser('css');971 expect(function() {972 parser.parse('a}');973 }).to.throwError();974 });975 it('miss }', function() {976 var parser = homunculus.getParser('css');977 expect(function() {978 parser.parse('a{');979 }).to.throwError();980 });981 it('extra {', function() {982 var parser = homunculus.getParser('css');983 expect(function() {984 parser.parse('a{{}');985 }).to.throwError();986 });987 it('extra }', function() {988 var parser = homunculus.getParser('css');989 expect(function() {990 parser.parse('a}}');991 }).to.throwError();992 });993 it('+number, -number', function() {994 var parser = homunculus.getParser('css');995 var node = parser.parse('.a{margin:+2px -1px}');996 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["+2","px","-1","px"]],"}"]]]]);997 });998 it('value can contain +', function() {999 var parser = homunculus.getParser('css');1000 var node = parser.parse('a{unicode-range:U+1000-1212}');1001 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["unicode-range"],":",CssNode.VALUE,["U+1000-1212"]],"}"]]]]);1002 });1003 it('vardecl value contain +', function() {1004 var parser = homunculus.getParser('css');1005 var node = parser.parse('$a:unicode-range:U+1000-1212;');1006 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.STYLE,[CssNode.KEY,["unicode-range"],":",CssNode.VALUE,["U+1000-1212"]]],";"]]]);1007 });1008 it('vardecl contain +', function() {1009 var parser = homunculus.getParser('css');1010 var node = parser.parse('$a:U+1000-1212;');1011 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,["U+1000-1212"]],";"]]]);1012 });1013 it('~ in value', function() {1014 var parser = homunculus.getParser('css');1015 var node = parser.parse('p{margin:~"1,2"}');1016 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.UNBOX,["~","\"1,2\""]]],"}"]]]]);1017 });1018 it('~ out value', function() {1019 var parser = homunculus.getParser('css');1020 var node = parser.parse('p{~margin:1}');1021 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["~","margin"],":",CssNode.VALUE,["1"]],"}"]]]]);1022 });1023 it(';', function() {1024 var parser = homunculus.getParser('css');1025 var node = parser.parse('p{fn(1);;;margin:0}');1026 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["p"]],CssNode.BLOCK,["{",CssNode.FNC,["fn",CssNode.CPARAMS,["(",CssNode.VALUE,["1"],")"]],";",";",";",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0"]],"}"]]]]);1027 });1028 it('build-in fn can be value', function() {1029 var parser = homunculus.getParser('css');1030 var node = parser.parse('a{-webkit-transform:scale3d(.9,.9,.9) rotate3d(0,0,1,-3deg);animation-name: rotate;}');1031 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["-webkit-","transform"],":",CssNode.VALUE,[CssNode.SCALE3D,["scale3d","(",CssNode.PARAM,[".9"],",",CssNode.PARAM,[".9"],",",CssNode.PARAM,[".9"],")"],CssNode.ROTATE3D,["rotate3d","(",CssNode.PARAM,["0"],",",CssNode.PARAM,["0"],",",CssNode.PARAM,["1"],",",CssNode.PARAM,["-3","deg"],")"]],";"],CssNode.STYLE,[CssNode.KEY,["animation-name"],":",CssNode.VALUE,["rotate"],";"],"}"]]]]);1032 });1033 });1034 describe('operate', function() {1035 it('add in url()', function() {1036 var parser = homunculus.getParser('css');1037 var node = parser.parse('.a{background:url("a"+"b")}');1038 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.URL,["url","(",CssNode.ADDEXPR,["\"a\"","+","\"b\""],")"]]],"}"]]]]);1039 });1040 it('add in url() and first is $', function() {1041 var parser = homunculus.getParser('css');1042 var node = parser.parse('.a{background:url($a+"b")}');1043 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.URL,["url","(",CssNode.ADDEXPR,["$a","+","\"b\""],")"]]],"}"]]]]);1044 });1045 it('add with units', function() {1046 var parser = homunculus.getParser('css');1047 var node = parser.parse('.a{margin:2 + 3px + 2px}');1048 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.ADDEXPR,["2","+","3","px","+","2","px"]]],"}"]]]]);1049 });1050 it('mtpl in url()', function() {1051 var parser = homunculus.getParser('css');1052 var node = parser.parse('.a{background:url($a+$b*$c)}');1053 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["background"],":",CssNode.VALUE,[CssNode.URL,["url","(",CssNode.ADDEXPR,["$a","+",CssNode.MTPLEXPR,["$b","*","$c"]],")"]]],"}"]]]]);1054 });1055 it('mtpl with units', function() {1056 var parser = homunculus.getParser('css');1057 var node = parser.parse('.a{margin:2 * 3px * 2px}');1058 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,[".a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.MTPLEXPR,["2","*","3","px","*","2","px"]]],"}"]]]]);1059 });1060 it('as a style', function() {1061 var parser = homunculus.getParser('css');1062 var node = parser.parse('body{$a+$b}');1063 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.ADDEXPR,["$a","+","$b"],"}"]]]]);1064 });1065 it('as a key', function() {1066 var parser = homunculus.getParser('css');1067 var node = parser.parse('body{$a+$b:1}');1068 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.ADDEXPR,["$a","+","$b"],":",CssNode.VALUE,["1"],"}"]]]]);1069 });1070 it('in @font-face', function() {1071 var parser = homunculus.getParser('css');1072 var node = parser.parse('@font-face{$a:$b + 1}');1073 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FONTFACE,["@font-face",CssNode.BLOCK,["{","$a",":",CssNode.VALUE,[CssNode.ADDEXPR,["$b","+","1"]],"}"]]]]);1074 });1075 it('in @namespace', function() {1076 var parser = homunculus.getParser('css');1077 var node = parser.parse('@namespace $a*2;');1078 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.NAMESPACE,["@namespace",CssNode.MTPLEXPR,["$a","*","2"],";"]]]);1079 });1080 it('in @document', function() {1081 var parser = homunculus.getParser('css');1082 var node = parser.parse('@document url-prefix($a+$b){}');1083 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.DOC,["@document",CssNode.URLPREFIX,["url-prefix","(",CssNode.ADDEXPR,["$a","+","$b"],")"],CssNode.BLOCK,["{","}"]]]]);1084 });1085 it('in @media', function() {1086 var parser = homunculus.getParser('css');1087 var node = parser.parse('@media all and ($a){}');1088 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["all"],"and",CssNode.EXPR,["(",CssNode.KEY,["$a"],")"]]],CssNode.BLOCK,["{","}"]]]]);1089 });1090 it('in @media value', function() {1091 var parser = homunculus.getParser('css');1092 var node = parser.parse('@media all and ($a:$b){}');1093 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.MEDIA,["@media",CssNode.MEDIAQLIST,[CssNode.MEDIAQUERY,[CssNode.MEDIATYPE,["all"],"and",CssNode.EXPR,["(",CssNode.KEY,["$a"],":",CssNode.VALUE,["$b"],")"]]],CssNode.BLOCK,["{","}"]]]]);1094 });1095 it('counter', function() {1096 var parser = homunculus.getParser('css');1097 var node = parser.parse('body{content:counter($a + 2)}');1098 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["content"],":",CssNode.VALUE,[CssNode.COUNTER,["counter","(",CssNode.PARAM,[CssNode.ADDEXPR,["$a","+","2"]],")"]]],"}"]]]]);1099 });1100 it('alpha 1', function() {1101 var parser = homunculus.getParser('css');1102 var node = parser.parse('body{filter:alpha($a)}');1103 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,[CssNode.FILTER,["alpha","(",CssNode.PARAM,["$a"],")"]]],"}"]]]]);1104 });1105 it('alpha 2', function() {1106 var parser = homunculus.getParser('css');1107 var node = parser.parse('body{filter:alpha($a=$b + 2)}');1108 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["filter"],":",CssNode.VALUE,[CssNode.FILTER,["alpha","(",CssNode.PARAM,["$a","=",CssNode.ADDEXPR,["$b","+","2"]],")"]]],"}"]]]]);1109 });1110 it('()', function() {1111 var parser = homunculus.getParser('css');1112 var node = parser.parse('body{margin:0 (1 + 2)*3}');1113 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["0",CssNode.MTPLEXPR,[CssNode.PRMREXPR,["(",CssNode.ADDEXPR,["1","+","2"],")"],"*","3"]]],"}"]]]]);1114 });1115 it('in var', function() {1116 var parser = homunculus.getParser('css');1117 var node = parser.parse('$a: $b*($c + 2);');1118 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a",":",CssNode.VALUE,[CssNode.MTPLEXPR,["$b","*",CssNode.PRMREXPR,["(",CssNode.ADDEXPR,["$c","+","2"],")"]]]],";"]]]);1119 });1120 it('unit after ()', function() {1121 var parser = homunculus.getParser('css');1122 var node = parser.parse('a{padding:(1 + 2)px}');1123 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["padding"],":",CssNode.VALUE,[CssNode.PRMREXPR,["(",CssNode.ADDEXPR,["1","+","2"],")"],"px"]],"}"]]]]);1124 });1125 it('no blank between unit and ()', function() {1126 var parser = homunculus.getParser('css');1127 var node = parser.parse('body{margin:(1 + 2) px}');1128 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.PRMREXPR,["(",CssNode.ADDEXPR,["1","+","2"],")"],"px"]],"}"]]]]);1129 });1130 it('ignore in font', function() {1131 var parser = homunculus.getParser('css');1132 var node = parser.parse('body{font:0/0;font:bold 12px/3;}');1133 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["font"],":",CssNode.VALUE,["0","/","0"],";"],CssNode.STYLE,[CssNode.KEY,["font"],":",CssNode.VALUE,["bold","12","px","/","3"],";"],"}"]]]]);1134 });1135 it('ignore in border-image', function() {1136 var parser = homunculus.getParser('css');1137 var node = parser.parse('body{border-image: url(https://i.alipayobjects.com/i/localhost/png/201411/3qhQSLX7dl.png) 0 4/4px round;}');1138 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["body"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["border-image"],":",CssNode.VALUE,[CssNode.URL,["url","(","https://i.alipayobjects.com/i/localhost/png/201411/3qhQSLX7dl.png",")"],"0","4","/","4","px","round"],";"],"}"]]]]);1139 });1140 it('ignore in border-image', function() {1141 var parser = homunculus.getParser('css');1142 var node = parser.parse('a{-webkit-border-image: url(https://i.alipayobjects.com/i/localhost/png/201411/3qhQSLX7dl.png) 0 4/4px round;}');1143 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["a"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["-webkit-","border-image"],":",CssNode.VALUE,[CssNode.URL,["url","(","https://i.alipayobjects.com/i/localhost/png/201411/3qhQSLX7dl.png",")"],"0","4","/","4","px","round"],";"],"}"]]]]);1144 });1145 });1146 describe('@ifstmt', function() {1147 it('only @if', function() {1148 var parser = homunculus.getParser('css');1149 var node = parser.parse('@if($b){}');1150 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$b"],")",CssNode.BLOCK,["{","}"]]]]);1151 });1152 it('@elseif', function() {1153 var parser = homunculus.getParser('css');1154 var node = parser.parse('@if($b){}@elseif($a){}');1155 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$b"],")",CssNode.BLOCK,["{","}"],CssNode.IFSTMT,["@elseif","(",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{","}"]]]]]);1156 });1157 it('@else', function() {1158 var parser = homunculus.getParser('css');1159 var node = parser.parse('@if($b){}@else{}');1160 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$b"],")",CssNode.BLOCK,["{","}"],"@else",CssNode.BLOCK,["{","}"]]]]);1161 });1162 it('addexpr', function() {1163 var parser = homunculus.getParser('css');1164 var node = parser.parse('@if($b + 1){}');1165 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.ADDSTMT,[CssNode.PRMRSTMT,["$b"],"+",CssNode.PRMRSTMT,["1"]],")",CssNode.BLOCK,["{","}"]]]]);1166 });1167 it('within content', function() {1168 var parser = homunculus.getParser('css');1169 var node = parser.parse('@if($a){color:#FFF;div{margin:$a}}');1170 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["color"],":",CssNode.VALUE,["#FFF"],";"],CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,["$a"]],"}"]],"}"]]]]);1171 });1172 it('no @if error 1', function() {1173 var parser = homunculus.getParser('css');1174 expect(function() {1175 parser.parse('@else{}');1176 }).to.throwError();1177 });1178 it('no @if error 2', function() {1179 var parser = homunculus.getParser('css');1180 expect(function() {1181 parser.parse('@elseif($a){}');1182 }).to.throwError();1183 });1184 it('cross 1', function() {1185 var parser = homunculus.getParser('css');1186 var node = parser.parse('@if($a){@for(;$a>1;$a++){}}');1187 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{",CssNode.FORSTMT,["@for","(",";",CssNode.RELSTMT,[CssNode.PRMRSTMT,["$a"],">",CssNode.PRMRSTMT,["1"]],";",CssNode.POSTFIXSTMT,[CssNode.PRMRSTMT,["$a"],"++"],")",CssNode.BLOCK,["{","}"]],"}"]]]]);1188 });1189 it('cross 2', function() {1190 var parser = homunculus.getParser('css');1191 var node = parser.parse('@if($a){@if($b){}}');1192 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{",CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$b"],")",CssNode.BLOCK,["{","}"]],"}"]]]]);1193 });1194 });1195 describe('@forstmt', function() {1196 it('for(VARSTMT;EQSTMT;EQSTMT){}', function() {1197 var parser = homunculus.getParser('css');1198 var node = parser.parse('@for($a=1,$b="2";$a>$b;$a++){}');1199 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FORSTMT,["@for","(",CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,["1"]],",",CssNode.VARDECL,["$b","=",CssNode.VALUE,["\"2\""]],";"],CssNode.RELSTMT,[CssNode.PRMRSTMT,["$a"],">",CssNode.PRMRSTMT,["$b"]],";",CssNode.POSTFIXSTMT,[CssNode.PRMRSTMT,["$a"],"++"],")",CssNode.BLOCK,["{","}"]]]]);1200 });1201 it('for(;EQSTMT;EQSTMT){}', function() {1202 var parser = homunculus.getParser('css');1203 var node = parser.parse('@for(;$a!=$b;$a){}');1204 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FORSTMT,["@for","(",";",CssNode.EQSTMT,[CssNode.PRMRSTMT,["$a"],"!=",CssNode.PRMRSTMT,["$b"]],";",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{","}"]]]]);1205 });1206 it('for in', function() {1207 var parser = homunculus.getParser('css');1208 var node = parser.parse('@for($a in [1,2]){}');1209 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FORSTMT,["@for","(","$a","in",CssNode.ARRLTR,["[",CssNode.VALUE,["1"],",",CssNode.VALUE,["2"],"]"],")",CssNode.BLOCK,["{","}"]]]]);1210 });1211 it('for of', function() {1212 var parser = homunculus.getParser('css');1213 var node = parser.parse('@for($a of @dir("test")){}');1214 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FORSTMT,["@for","(","$a","of",CssNode.DIR,["@dir",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]],")",CssNode.BLOCK,["{","}"]]]]);1215 });1216 });1217 describe('eqstmt', function() {1218 it('eq', function() {1219 var parser = homunculus.getParser('css');1220 var node = parser.parse('@if($a==1){}');1221 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.EQSTMT,[CssNode.PRMRSTMT,["$a"],"==",CssNode.PRMRSTMT,["1"]],")",CssNode.BLOCK,["{","}"]]]]);1222 });1223 it('rel', function() {1224 var parser = homunculus.getParser('css');1225 var node = parser.parse('@if($a>1){}');1226 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.RELSTMT,[CssNode.PRMRSTMT,["$a"],">",CssNode.PRMRSTMT,["1"]],")",CssNode.BLOCK,["{","}"]]]]);1227 });1228 it('add/mtpl', function() {1229 var parser = homunculus.getParser('css');1230 var node = parser.parse('@if($a + $b * 2){}');1231 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.ADDSTMT,[CssNode.PRMRSTMT,["$a"],"+",CssNode.MTPLSTMT,[CssNode.PRMRSTMT,["$b"],"*",CssNode.PRMRSTMT,["2"]]],")",CssNode.BLOCK,["{","}"]]]]);1232 });1233 it('series add/mtpl', function() {1234 var parser = homunculus.getParser('css');1235 var node = parser.parse('@if($a + $b + $c){}@elseif($a * $b * $c){}');1236 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.ADDSTMT,[CssNode.PRMRSTMT,["$a"],"+",CssNode.PRMRSTMT,["$b"],CssNode.PRMRSTMT,["$a"],"+",CssNode.PRMRSTMT,["$c"]],")",CssNode.BLOCK,["{","}"],CssNode.IFSTMT,["@elseif","(",CssNode.MTPLSTMT,[CssNode.PRMRSTMT,["$a"],"*",CssNode.PRMRSTMT,["$b"],CssNode.PRMRSTMT,["$a"],"*",CssNode.PRMRSTMT,["$c"]],")",CssNode.BLOCK,["{","}"]]]]]);1237 });1238 it('postfix', function() {1239 var parser = homunculus.getParser('css');1240 var node = parser.parse('@if($a++){}');1241 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.POSTFIXSTMT,[CssNode.PRMRSTMT,["$a"],"++"],")",CssNode.BLOCK,["{","}"]]]]);1242 });1243 it('prmr', function() {1244 var parser = homunculus.getParser('css');1245 var node = parser.parse('@if($a){}');1246 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.PRMRSTMT,["$a"],")",CssNode.BLOCK,["{","}"]]]]);1247 });1248 it('()', function() {1249 var parser = homunculus.getParser('css');1250 var node = parser.parse('@if($a * ($b - 1)){}');1251 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.MTPLSTMT,[CssNode.PRMRSTMT,["$a"],"*",CssNode.PRMRSTMT,["(",CssNode.ADDSTMT,[CssNode.PRMRSTMT,["$b"],"-",CssNode.PRMRSTMT,["1"]],")"]],")",CssNode.BLOCK,["{","}"]]]]);1252 });1253 it('arrltr', function() {1254 var parser = homunculus.getParser('css');1255 var node = parser.parse('$a = [1,2];');1256 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.ARRLTR,["[",CssNode.VALUE,["1"],",",CssNode.VALUE,["2"],"]"]],";"]]]);1257 });1258 });1259 describe('global fn @', function() {1260 it('@dir', function() {1261 var parser = homunculus.getParser('css');1262 var node = parser.parse('$a = @dir("test");');1263 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.DIR,["@dir",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]]],";"]]]);1264 });1265 it('@dir in exprstmt', function() {1266 var parser = homunculus.getParser('css');1267 var node = parser.parse('@for($a of @dir()){}');1268 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.FORSTMT,["@for","(","$a","of",CssNode.DIR,["@dir",CssNode.CPARAMS,["(",")"]],")",CssNode.BLOCK,["{","}"]]]]);1269 });1270 it('@basename', function() {1271 var parser = homunculus.getParser('css');1272 var node = parser.parse('$a = @basename("test");');1273 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,[CssNode.BASENAME,["@basename",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]]]],";"]]]);1274 });1275 it('@basename in exprstmt', function() {1276 var parser = homunculus.getParser('css');1277 var node = parser.parse('@if(@basename("test") > "1"){}');1278 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.RELSTMT,[CssNode.BASENAME,["@basename",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]],">",CssNode.PRMRSTMT,["\"1\""]],")",CssNode.BLOCK,["{","}"]]]]);1279 });1280 it('@basename in value', function() {1281 var parser = homunculus.getParser('css');1282 var node = parser.parse('div{margin:@basename("")}');1283 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.BASENAME,["@basename",CssNode.CPARAMS,["(",CssNode.VALUE,["\"\""],")"]]]],"}"]]]]);1284 });1285 it('@extname', function() {1286 var parser = homunculus.getParser('css');1287 var node = parser.parse('$a = @extname("test");');1288 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,[CssNode.EXTNAME,["@extname",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]]]],";"]]]);1289 });1290 it('@extname in exprstmt', function() {1291 var parser = homunculus.getParser('css');1292 var node = parser.parse('@if(@extname("test") > "1"){}');1293 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.RELSTMT,[CssNode.EXTNAME,["@extname",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]],">",CssNode.PRMRSTMT,["\"1\""]],")",CssNode.BLOCK,["{","}"]]]]);1294 });1295 it('@extname in value', function() {1296 var parser = homunculus.getParser('css');1297 var node = parser.parse('div{margin:@extname("")}');1298 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.EXTNAME,["@extname",CssNode.CPARAMS,["(",CssNode.VALUE,["\"\""],")"]]]],"}"]]]]);1299 });1300 it('@width', function() {1301 var parser = homunculus.getParser('css');1302 var node = parser.parse('$a = @width("test");');1303 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,[CssNode.WIDTH,["@width",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]]]],";"]]]);1304 });1305 it('@width in exprstmt', function() {1306 var parser = homunculus.getParser('css');1307 var node = parser.parse('@if(@width("test") > 1){}');1308 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.RELSTMT,[CssNode.WIDTH,["@width",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]],">",CssNode.PRMRSTMT,["1"]],")",CssNode.BLOCK,["{","}"]]]]);1309 });1310 it('@width in value', function() {1311 var parser = homunculus.getParser('css');1312 var node = parser.parse('div{margin:@width("") + 1}');1313 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.ADDEXPR,[CssNode.WIDTH,["@width",CssNode.CPARAMS,["(",CssNode.VALUE,["\"\""],")"]],"+","1"]]],"}"]]]]);1314 });1315 it('@height', function() {1316 var parser = homunculus.getParser('css');1317 var node = parser.parse('$a = @height("test");');1318 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,[CssNode.HEIGHT,["@height",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]]]],";"]]]);1319 });1320 it('@height in exprstmt', function() {1321 var parser = homunculus.getParser('css');1322 var node = parser.parse('@if(@height("test") > 1){}');1323 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.IFSTMT,["@if","(",CssNode.RELSTMT,[CssNode.HEIGHT,["@height",CssNode.CPARAMS,["(",CssNode.VALUE,["\"test\""],")"]],">",CssNode.PRMRSTMT,["1"]],")",CssNode.BLOCK,["{","}"]]]]);1324 });1325 it('@height in value', function() {1326 var parser = homunculus.getParser('css');1327 var node = parser.parse('div{margin:@height("") + 1}');1328 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.ADDEXPR,[CssNode.HEIGHT,["@height",CssNode.CPARAMS,["(",CssNode.VALUE,["\"\""],")"]],"+","1"]]],"}"]]]]);1329 });1330 });1331 describe('unbox', function() {1332 it('vardecl', function() {1333 var parser = homunculus.getParser('css');1334 var node = parser.parse('$a = ~"123";');1335 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.VALUE,[CssNode.UNBOX,["~","\"123\""]]],";"]]]);1336 });1337 it('var as hack', function() {1338 var parser = homunculus.getParser('css');1339 var node = parser.parse('$a = ~margin:0;');1340 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.VARSTMT,[CssNode.VARDECL,["$a","=",CssNode.STYLE,[CssNode.KEY,["~","margin"],":",CssNode.VALUE,["0"]]],";"]]]);1341 });1342 it('fn call', function() {1343 var parser = homunculus.getParser('css');1344 var node = parser.parse('div{$fn(~"123")}');1345 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.UNBOX,["~","\"123\""],")"]],"}"]]]]);1346 });1347 it('fnc as hack', function() {1348 var parser = homunculus.getParser('css');1349 var node = parser.parse('div{$fn(~margin:0)}');1350 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.FNC,["$fn",CssNode.CPARAMS,["(",CssNode.STYLE,[CssNode.KEY,["~","margin"],":",CssNode.VALUE,["0"]],")"]],"}"]]]]);1351 });1352 it('in value', function() {1353 var parser = homunculus.getParser('css');1354 var node = parser.parse('div{margin:~"";padding:~$a}');1355 expect(tree(node)).to.eql([CssNode.SHEET,[CssNode.STYLESET,[CssNode.SELECTORS,[CssNode.SELECTOR,["div"]],CssNode.BLOCK,["{",CssNode.STYLE,[CssNode.KEY,["margin"],":",CssNode.VALUE,[CssNode.UNBOX,["~","\"\""]],";"],CssNode.STYLE,[CssNode.KEY,["padding"],":",CssNode.VALUE,[CssNode.UNBOX,["~","$a"]]],"}"]]]]);1356 });1357 it('only one unbxo in value', function() {1358 var parser = homunculus.getParser('css');1359 expect(function() {1360 parser.parse('div{margin:~""~""}');1361 }).to.throwError();1362 });1363 });1364 describe('lib test', function() {1365 it('bootstrap', function() {1366 var parser = homunculus.getParser('css');1367 var code = fs.readFileSync(path.join(__dirname, './lib/bootstrap.css'), { encoding: 'utf-8' });1368 var node = parser.parse(code);1369 var ignore = parser.ignore();1370 var str = jion(node, ignore);1371 expect(str).to.eql(code);1372 });1373 it('bootstrap-theme', function() {1374 var parser = homunculus.getParser('css');1375 var code = fs.readFileSync(path.join(__dirname, './lib/bootstrap-theme.css'), { encoding: 'utf-8' });1376 var node = parser.parse(code);1377 var ignore = parser.ignore();1378 var str = jion(node, ignore);1379 expect(str).to.eql(code);1380 });1381 it('normalize', function() {1382 var parser = homunculus.getParser('css');1383 var code = fs.readFileSync(path.join(__dirname, './lib/normalize.css'), { encoding: 'utf-8' });1384 var node = parser.parse(code);1385 var ignore = parser.ignore();1386 var str = jion(node, ignore);1387 expect(str).to.eql(code);1388 });1389 it('foundation', function() {1390 var parser = homunculus.getParser('css');1391 var code = fs.readFileSync(path.join(__dirname, './lib/foundation.css'), { encoding: 'utf-8' });1392 var node = parser.parse(code);1393 var ignore = parser.ignore();1394 var str = jion(node, ignore);1395 expect(str).to.eql(code);1396 });1397 it('animate', function() {1398 var parser = homunculus.getParser('css');1399 var code = fs.readFileSync(path.join(__dirname, './lib/animate.css'), { encoding: 'utf-8' });1400 var node = parser.parse(code);1401 var ignore = parser.ignore();1402 var str = jion(node, ignore);1403 expect(str).to.eql(code);1404 });1405 it('gumby', function() {1406 var parser = homunculus.getParser('css');1407 var code = fs.readFileSync(path.join(__dirname, './lib/gumby.css'), { encoding: 'utf-8' });1408 var node = parser.parse(code);1409 var ignore = parser.ignore();1410 var str = jion(node, ignore);1411 expect(str).to.eql(code);1412 });1413 it('pure', function() {1414 var parser = homunculus.getParser('css');1415 var code = fs.readFileSync(path.join(__dirname, './lib/pure.css'), { encoding: 'utf-8' });1416 var node = parser.parse(code);1417 var ignore = parser.ignore();1418 var str = jion(node, ignore);1419 expect(str).to.eql(code);1420 });1421 });1422 describe('other test', function() {1423 it('node #parent,#prev,#next', function() {1424 var parser = homunculus.getParser('css');1425 var node = parser.parse('a{}');1426 var styleset = node.first();1427 var children = styleset.leaves();1428 var a = children[0];1429 var b = children[1];1430 expect(node.parent()).to.be(null);1431 expect(a.parent()).to.be(styleset);1432 expect(b.parent()).to.be(styleset);1433 expect(a.prev()).to.be(null);1434 expect(a.next()).to.be(b);1435 expect(b.prev()).to.be(a);1436 });1437 it('node #leaf,#size,#leaves', function() {1438 var parser = homunculus.getParser('css');1439 var node = parser.parse('a{}');1440 var styleset = node.first();1441 expect(styleset.name()).to.be(CssNode.STYLESET);1442 expect(styleset.size()).to.be(2);1443 expect(styleset.leaves().length).to.be(2);1444 });1445 it('node #nid', function() {1446 var parser = homunculus.getParser('css');1447 var node = parser.parse('a{}');1448 expect(node.nid()).to.be.a('number');1449 });1450 it('#ast should return as parse return', function() {1451 var parser = homunculus.getParser('css');1452 var node = parser.parse('a{}');1453 expect(node).to.equal(parser.ast());1454 });1455 it('init class Parser(lexer) with a lexer', function() {1456 var lexer = homunculus.getLexer('css');1457 var parser = new Parser(lexer);1458 var node = parser.parse('a{}');1459 expect(node).to.equal(parser.ast());1460 expect(function() {1461 parser.init();1462 }).to.not.throwError();1463 });1464 it('CssNode#getKey', function() {1465 expect(CssNode.getKey('sheet')).to.eql('SHEET');...

Full Screen

Full Screen

jsparser.js

Source:jsparser.js Github

copy

Full Screen

...56}57describe('jsparser', function() {58 describe('simple test', function() {59 it('varstmt no assign', function() {60 var parser = homunculus.getParser('js');61 var node = parser.parse('var a;');62 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.VARSTMT, ['var', JsNode.VARDECL, ['a'], ';']]]);63 });64 it('varstmt with assign', function() {65 var parser = homunculus.getParser('js');66 var node = parser.parse('var a = 1;');67 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.VARSTMT, ['var', JsNode.VARDECL, ['a', JsNode.ASSIGN, ['=', JsNode.PRMREXPR, [1]]], ';']]]);68 });69 it('varstmt with multi', function() {70 var parser = homunculus.getParser('js');71 var node = parser.parse('var a, b = 1;');72 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.VARSTMT, ['var', JsNode.VARDECL, ['a'], ',', JsNode.VARDECL, ['b', JsNode.ASSIGN, ['=', JsNode.PRMREXPR, [1]]], ';']]]);73 });74 it('newexpr 1', function() {75 var parser = homunculus.getParser('js');76 var node = parser.parse('new A');77 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A']]]]]);78 });79 it('newexpr 2', function() {80 var parser = homunculus.getParser('js');81 var node = parser.parse('new A()');82 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']]]]]);83 });84 it('newexpr 3', function() {85 var parser = homunculus.getParser('js');86 var node = parser.parse('new A().f');87 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f']]]]);88 });89 it('newexpr 4', function() {90 var parser = homunculus.getParser('js');91 var node = parser.parse('new A().f()');92 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]);93 });94 it('newexpr 5', function() {95 var parser = homunculus.getParser('js');96 var node = parser.parse('new new A().f()');97 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.NEWEXPR, ['new', JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]);98 });99 it('newexpr 6', function() {100 var parser = homunculus.getParser('js');101 var node = parser.parse('new A()[1]');102 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"],JsNode.ARGS,["(",")"]],"[",JsNode.PRMREXPR,["1"],"]"]]]]);103 });104 it('newexpr error', function() {105 var parser = homunculus.getParser('js');106 expect(function() {107 parser.parse('new');108 }).to.throwError();109 });110 it('mmbexpr 1', function() {111 var parser = homunculus.getParser('js');112 var node = parser.parse('a.b.c');113 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],".","c"]]]]);114 });115 it('mmbexpr 2', function() {116 var parser = homunculus.getParser('js');117 var node = parser.parse('a.b[c]');118 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"[",JsNode.PRMREXPR,["c"],"]"]]]]);119 });120 it('mmbexpr 3', function() {121 var parser = homunculus.getParser('js');122 var node = parser.parse('a.b');123 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"]]]]);124 });125 it('mmbexpr 4', function() {126 var parser = homunculus.getParser('js');127 var node = parser.parse('a[2]');128 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '[', JsNode.PRMREXPR, ['2'], ']']]]]);129 });130 it('mmbexpr error', function() {131 var parser = homunculus.getParser('es6');132 expect(function() {133 parser.parse('a.');134 }).to.throwError();135 });136 it('returnstmt 1', function() {137 var parser = homunculus.getParser('js');138 var node = parser.parse('return a');139 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return', JsNode.PRMREXPR, ['a']]]]);140 });141 it('returnstmt 2', function() {142 var parser = homunculus.getParser('js');143 var node = parser.parse('return\na');144 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]);145 });146 it('returnstmt 3', function() {147 var parser = homunculus.getParser('js');148 var node = parser.parse('return/*\n*/a');149 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return'], JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]);150 });151 it('returnstmt 4', function() {152 var parser = homunculus.getParser('js');153 var node = parser.parse('return a\nreturn');154 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.RETSTMT, ['return', JsNode.PRMREXPR, ['a']], JsNode.RETSTMT, ['return']]]);155 });156 it('returnstmt 5', function() {157 var parser = homunculus.getParser('js');158 var node = parser.parse('{return}');159 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.BLOCK, ['{', JsNode.RETSTMT, ['return'], '}']]]);160 });161 it('postfixexpr 1', function() {162 var parser = homunculus.getParser('js');163 var node = parser.parse('a++ + b');164 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['a'], '++'], '+', JsNode.PRMREXPR, ['b']]]]]);165 });166 it('postfixexpr 2', function() {167 var parser = homunculus.getParser('js');168 var node = parser.parse('a\nb++');169 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']], JsNode.EXPRSTMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]);170 });171 it('postfixexpr 3', function() {172 var parser = homunculus.getParser('js');173 var node = parser.parse('a/*\n*/b++');174 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']], JsNode.EXPRSTMT, [JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '++']]]]);175 });176 it('postfixexpr 4', function() {177 var parser = homunculus.getParser('js');178 var node = parser.parse('a++');179 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"]]]]);180 });181 it('postfixexpr 5', function() {182 var parser = homunculus.getParser('js');183 var node = parser.parse('{a:a++\n}');184 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.BLOCK,["{",JsNode.LABSTMT,["a",":",JsNode.EXPRSTMT,[JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"]]],"}"]]]);185 });186 it('postfixexpr error 1', function() {187 var parser = homunculus.getParser('js');188 expect(function() {189 parser.parse('a++ ++');190 }).to.throwError();191 });192 it('postfixexpr error 2', function() {193 var parser = homunculus.getParser('js');194 expect(function() {195 parser.parse('++');196 }).to.throwError();197 });198 it('fndecl', function() {199 var parser = homunculus.getParser('js');200 var node = parser.parse('function a() {}');201 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.FNDECL, ['function', 'a', '(', ')', '{', JsNode.FNBODY, [], '}']]]);202 });203 it('fndecl with params', function() {204 var parser = homunculus.getParser('js');205 var node = parser.parse('function a(b,c) {}');206 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.FNDECL,["function","a","(",JsNode.FNPARAMS,["b",",","c"],")","{",JsNode.FNBODY,[],"}"]]]);207 });208 it('fndecl error 1', function() {209 var parser = homunculus.getParser('js');210 expect(function() {211 parser.parse('function a(');212 }).to.throwError();213 });214 it('fnexpr 1', function() {215 var parser = homunculus.getParser('js');216 var node = parser.parse('~function() {}()');217 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['~', JsNode.CALLEXPR, [JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], JsNode.ARGS, ['(', ')']]]]]]);218 });219 it('fnexpr 2', function() {220 var parser = homunculus.getParser('js');221 var node = parser.parse('(function() {})()');222 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['(', JsNode.FNEXPR, ['function', '(', ')', '{', JsNode.FNBODY, [], '}'], ')'], JsNode.ARGS, ['(', ')']]]]]);223 });224 it('fnexpr error 1', function() {225 var parser = homunculus.getParser('js');226 expect(function() {227 parser.parse('(function');228 }).to.throwError();229 });230 it('fnexpr error 2', function() {231 var parser = homunculus.getParser('js');232 expect(function() {233 parser.parse('(function(');234 }).to.throwError();235 });236 it('fnexpr error 3', function() {237 var parser = homunculus.getParser('js');238 expect(function() {239 parser.parse('(function(a,');240 }).to.throwError();241 });242 it('fnexpr error 4', function() {243 var parser = homunculus.getParser('js');244 expect(function() {245 parser.parse('(function(a,1');246 }).to.throwError();247 });248 it('fnparams error', function() {249 var parser = homunculus.getParser('js');250 expect(function() {251 parser.parse('function a(b,){}');252 }).to.throwError();253 });254 it('args error', function() {255 var parser = homunculus.getParser('js');256 expect(function() {257 parser.parse('a(b,)');258 }).to.throwError();259 });260 it('labelstmt', function() {261 var parser = homunculus.getParser('js');262 var node = parser.parse('label:;');263 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.LABSTMT, ['label', ':', JsNode.EMPTSTMT, [';']]]]);264 });265 it('prmrexpr 1', function() {266 var parser = homunculus.getParser('js');267 var node = parser.parse('a');268 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['a']]]]);269 });270 it('prmrexpr 2', function() {271 var parser = homunculus.getParser('js');272 var node = parser.parse('true');273 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['true']]]]);274 });275 it('prmrexpr 3', function() {276 var parser = homunculus.getParser('js');277 var node = parser.parse('null');278 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['null']]]]);279 });280 it('prmrexpr 4', function() {281 var parser = homunculus.getParser('js');282 var node = parser.parse('this');283 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['this']]]]);284 });285 it('prmrexpr 5', function() {286 var parser = homunculus.getParser('js');287 var node = parser.parse('false');288 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ['false']]]]);289 });290 it('prmrexpr 6', function() {291 var parser = homunculus.getParser('js');292 var node = parser.parse('[]');293 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, [JsNode.ARRLTR, ['[', ']']]]]]);294 });295 it('prmrexpr 7', function() {296 var parser = homunculus.getParser('js');297 var node = parser.parse('!{}');298 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, [JsNode.OBJLTR, ['{', '}']]]]]]);299 });300 it('prmrexpr error', function() {301 var parser = homunculus.getParser('js');302 expect(function() {303 parser.parse('.');304 }).to.throwError();305 });306 it('arrltr', function() {307 var parser = homunculus.getParser('js');308 var node = parser.parse('[,,,2,3,]');309 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,[JsNode.ARRLTR,["[",",",",",",",JsNode.PRMREXPR,["2"],",",JsNode.PRMREXPR,["3"],",","]"]]]]]);310 });311 it('arrltr error', function() {312 var parser = homunculus.getParser('js');313 expect(function() {314 parser.parse('[,,,2,3,');315 }).to.throwError();316 });317 it('objltr', function() {318 var parser = homunculus.getParser('js');319 var node = parser.parse('var o = {a: [], "b": 3, 5: {}}');320 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["a",":",JsNode.PRMREXPR,[JsNode.ARRLTR,["[","]"]]],",",JsNode.PROPTASSIGN,["\"b\"",":",JsNode.PRMREXPR,["3"]],",",JsNode.PROPTASSIGN,["5",":",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]]],"}"]]]]]]]);321 });322 it('keyword can be obj\'s property', function() {323 var parser = homunculus.getParser('js');324 var node = parser.parse('var o = {var:1}');325 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["var",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]);326 });327 it('keyword can not be label', function() {328 var parser = homunculus.getParser('js');329 expect(function() {330 parser.parse('var:');331 }).to.throwError();332 });333 it('keyword after get/set', function() {334 var parser = homunculus.getParser('js');335 var node = parser.parse('~{get var(){}}');336 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.UNARYEXPR,["~",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["get","var","(",")","{",JsNode.FNBODY,[],"}"],"}"]]]]]]);337 });338 it('objltr error', function() {339 var parser = homunculus.getParser('js');340 expect(function() {341 parser.parse('var o = {+');342 }).to.throwError();343 });344 it('getter', function() {345 var parser = homunculus.getParser('js');346 var node = parser.parse('var o = {get a(){}}');347 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["get","a","(",")","{",JsNode.FNBODY,[],"}"],"}"]]]]]]]);348 });349 it('get be an property', function() {350 var parser = homunculus.getParser('js');351 var node = parser.parse('var o = {get:1}');352 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["get",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]);353 });354 it('getter error 1', function() {355 var parser = homunculus.getParser('js');356 expect(function() {357 parser.parse('var o = {get a}');358 }).to.throwError();359 });360 it('getter error 2', function() {361 var parser = homunculus.getParser('js');362 expect(function() {363 parser.parse('var o = {get a(}');364 }).to.throwError();365 });366 it('getter error 3', function() {367 var parser = homunculus.getParser('js');368 expect(function() {369 parser.parse('var o = {get a()}');370 }).to.throwError();371 });372 it('getter error 4', function() {373 var parser = homunculus.getParser('js');374 expect(function() {375 parser.parse('var o = {get 3}');376 }).to.throwError();377 });378 it('getter error 5', function() {379 var parser = homunculus.getParser('js');380 expect(function() {381 parser.parse('var o = {get 3(){}}');382 }).to.throwError();383 });384 it('setter', function() {385 var parser = homunculus.getParser('js');386 var node = parser.parse('var o = {set a(b){}}');387 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["set","a","(","b",")","{",JsNode.FNBODY,[],"}"],"}"]]]]]]]);388 });389 it('set be an property', function() {390 var parser = homunculus.getParser('js');391 var node = parser.parse('var o = {set:1}');392 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["o",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.OBJLTR,["{",JsNode.PROPTASSIGN,["set",":",JsNode.PRMREXPR,["1"]],"}"]]]]]]]);393 });394 it('setter error 1', function() {395 var parser = homunculus.getParser('js');396 expect(function() {397 parser.parse('var o = {set a}');398 }).to.throwError();399 });400 it('setter error 2', function() {401 var parser = homunculus.getParser('js');402 expect(function() {403 parser.parse('var o = {set a(}');404 }).to.throwError();405 });406 it('setter error 3', function() {407 var parser = homunculus.getParser('js');408 expect(function() {409 parser.parse('var o = {set a()}');410 }).to.throwError();411 });412 it('setter error 4', function() {413 var parser = homunculus.getParser('js');414 expect(function() {415 parser.parse('var o = {set 4}');416 }).to.throwError();417 });418 it('setter error 5', function() {419 var parser = homunculus.getParser('js');420 expect(function() {421 parser.parse('var o = {set a(){}}');422 }).to.throwError();423 });424 it('callexpr 1', function() {425 var parser = homunculus.getParser('js');426 var node = parser.parse('a()');427 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']]]]]);428 });429 it('callexpr 2', function() {430 var parser = homunculus.getParser('js');431 var node = parser.parse('a.b()');432 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ['a'], '.', 'b'], JsNode.ARGS, ['(', ')']]]]]);433 });434 it('callexpr 3', function() {435 var parser = homunculus.getParser('js');436 var node = parser.parse('new A().f()');437 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CALLEXPR, [JsNode.MMBEXPR, [JsNode.NEWEXPR, ['new', JsNode.PRMREXPR, ['A'], JsNode.ARGS, ['(', ')']], '.', 'f'], JsNode.ARGS, ['(', ')']]]]]);438 });439 it('callexpr 4', function() {440 var parser = homunculus.getParser('js');441 var node = parser.parse('f()()');442 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",")"]],JsNode.ARGS,["(",")"]]]]]);443 });444 it('callexpr 5', function() {445 var parser = homunculus.getParser('js');446 var node = parser.parse('f().b[1]');447 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.PRMREXPR,["f"],JsNode.ARGS,["(",")"]],".","b"],"[",JsNode.PRMREXPR,["1"],"]"]]]]);448 });449 it('callexpr 6', function() {450 var parser = homunculus.getParser('js');451 var node = parser.parse('a.b().c.d()');452 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.MMBEXPR,[JsNode.CALLEXPR,[JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],JsNode.ARGS,["(",")"]],".","c"],".","d"],JsNode.ARGS,["(",")"]]]]]);453 });454 it('callexpr error', function() {455 var parser = homunculus.getParser('js');456 expect(function() {457 parser.parse('f(');458 }).to.throwError();459 });460 it('unaryexpr 1', function() {461 var parser = homunculus.getParser('js');462 var node = parser.parse('typeof a');463 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['typeof', JsNode.PRMREXPR, ['a']]]]]);464 });465 it('unaryexpr 2', function() {466 var parser = homunculus.getParser('js');467 var node = parser.parse('!!0');468 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.UNARYEXPR, ['!', JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['0']]]]]]);469 });470 it('unaryexpr error 1', function() {471 var parser = homunculus.getParser('js');472 expect(function() {473 parser.parse('!');474 }).to.throwError();475 });476 it('unaryexpr error 2', function() {477 var parser = homunculus.getParser('js');478 expect(function() {479 parser.parse('++ +a');480 }).to.throwError();481 });482 it('mtplexpr 1', function() {483 var parser = homunculus.getParser('js');484 var node = parser.parse('a * b');485 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ['a'], '*', JsNode.PRMREXPR, ['b']]]]]);486 });487 it('mtplexpr 2', function() {488 var parser = homunculus.getParser('js');489 var node = parser.parse('a() * b[0]');490 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.CALLEXPR, [JsNode.PRMREXPR, ['a'], JsNode.ARGS, ['(', ')']], '*', JsNode.MMBEXPR, [JsNode.PRMREXPR, ['b'], '[', JsNode.PRMREXPR, ['0'], ']']]]]]);491 });492 it('mtplexpr 3', function() {493 var parser = homunculus.getParser('js');494 var node = parser.parse('!a * b--');495 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.MTPLEXPR, [JsNode.UNARYEXPR, ['!', JsNode.PRMREXPR, ['a']], '*', JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ['b'], '--']]]]]);496 });497 it('addexpr 1', function() {498 var parser = homunculus.getParser('js');499 var node = parser.parse('a + b * 2 - c');500 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["b"], "*", JsNode.PRMREXPR, ["2"]], "-", JsNode.PRMREXPR, ["c"]]]]]);501 });502 it('addexpr 2', function() {503 var parser = homunculus.getParser('js');504 var node = parser.parse('~a + a++ + ++a');505 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ADDEXPR, [JsNode.UNARYEXPR, ["~", JsNode.PRMREXPR, ["a"]], "+", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["a"], "++"], "+", JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["a"]]]]]]);506 });507 it('shiftexpr 1', function() {508 var parser = homunculus.getParser('js');509 var node = parser.parse('a>>a+1');510 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["a"], ">>", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["a"], "+", JsNode.PRMREXPR, ["1"]]]]]]);511 });512 it('shiftexpr 2', function() {513 var parser = homunculus.getParser('js');514 var node = parser.parse('a*b>>>c/d<<--e');515 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.SHIFTEXPR, [JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["a"], "*", JsNode.PRMREXPR, ["b"]], ">>>", JsNode.MTPLEXPR, [JsNode.PRMREXPR, ["c"], "/", JsNode.PRMREXPR, ["d"]], "<<", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["e"]]]]]]);516 });517 it('reltexpr 1', function() {518 var parser = homunculus.getParser('js');519 var node = parser.parse('a > b');520 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["b"]]]]]);521 });522 it('reltexpr 2', function() {523 var parser = homunculus.getParser('js');524 var node = parser.parse('a <= b+1');525 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "<=", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["1"]]]]]]);526 });527 it('reltexpr 3', function() {528 var parser = homunculus.getParser('js');529 var node = parser.parse('a instanceof new A()');530 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], "instanceof", JsNode.NEWEXPR, ["new", JsNode.PRMREXPR, ["A"], JsNode.ARGS, ["(", ")"]]]]]]);531 });532 it('reltexpr error', function() {533 var parser = homunculus.getParser('js');534 expect(function() {535 parser.parse('a <');536 }).to.throwError();537 });538 it('eqexpr 1', function() {539 var parser = homunculus.getParser('js');540 var node = parser.parse('a == 3');541 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "==", JsNode.PRMREXPR, ["3"]]]]]);542 });543 it('eqexpr 2', function() {544 var parser = homunculus.getParser('js');545 var node = parser.parse('a === b + 3');546 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "===", JsNode.ADDEXPR, [JsNode.PRMREXPR, ["b"], "+", JsNode.PRMREXPR, ["3"]]]]]]);547 });548 it('eqexpr 3', function() {549 var parser = homunculus.getParser('js');550 var node = parser.parse('a !== b >>> 4');551 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.EQEXPR, [JsNode.PRMREXPR, ["a"], "!==", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["b"], ">>>", JsNode.PRMREXPR, ["4"]]]]]]);552 });553 it('eqexpr error', function() {554 var parser = homunculus.getParser('js');555 expect(function() {556 parser.parse('a ==');557 }).to.throwError();558 });559 it('bitandexpr', function() {560 var parser = homunculus.getParser('js');561 var node = parser.parse('void a & --b');562 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITANDEXPR, [JsNode.UNARYEXPR, ["void", JsNode.PRMREXPR, ["a"]], "&", JsNode.UNARYEXPR, ["--", JsNode.PRMREXPR, ["b"]]]]]]);563 });564 it('bitxorexpr', function() {565 var parser = homunculus.getParser('js');566 var node = parser.parse('a>1 ^ b--');567 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITXOREXPR, [JsNode.RELTEXPR, [JsNode.PRMREXPR, ["a"], ">", JsNode.PRMREXPR, ["1"]], "^", JsNode.POSTFIXEXPR, [JsNode.PRMREXPR, ["b"], "--"]]]]]);568 });569 it('bitorexpr', function() {570 var parser = homunculus.getParser('js');571 var node = parser.parse('++b | -a');572 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.BITOREXPR, [JsNode.UNARYEXPR, ["++", JsNode.PRMREXPR, ["b"]], "|", JsNode.UNARYEXPR, ["-", JsNode.PRMREXPR, ["a"]]]]]]);573 });574 it('logandexpr', function() {575 var parser = homunculus.getParser('js');576 var node = parser.parse('a.b && c >> 1');577 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.LOGANDEXPR, [JsNode.MMBEXPR, [JsNode.PRMREXPR, ["a"], ".", "b"], "&&", JsNode.SHIFTEXPR, [JsNode.PRMREXPR, ["c"], ">>", JsNode.PRMREXPR, ["1"]]]]]]);578 });579 it('logorexpr', function() {580 var parser = homunculus.getParser('js');581 var node = parser.parse('a || b && c || d && f');582 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["a"], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["b"], "&&", JsNode.PRMREXPR, ["c"]], "||", JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["d"], "&&", JsNode.PRMREXPR, ["f"]]]]]]);583 });584 it('condexpr', function() {585 var parser = homunculus.getParser('js');586 var node = parser.parse('a && b ? false || true : typeof null');587 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.CNDTEXPR, [JsNode.LOGANDEXPR, [JsNode.PRMREXPR, ["a"], "&&", JsNode.PRMREXPR, ["b"]], "?", JsNode.LOGOREXPR, [JsNode.PRMREXPR, ["false"], "||", JsNode.PRMREXPR, ["true"]], ":", JsNode.UNARYEXPR, ["typeof", JsNode.PRMREXPR, ["null"]]]]]]);588 });589 it('assignexpr 1', function() {590 var parser = homunculus.getParser('js');591 var node = parser.parse('a = b = c');592 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "=", JsNode.PRMREXPR, ["c"]]]]]]);593 });594 it('assignexpr 2', function() {595 var parser = homunculus.getParser('js');596 var node = parser.parse('a += b %= c');597 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["a"], "+=", JsNode.ASSIGNEXPR, [JsNode.PRMREXPR, ["b"], "%=", JsNode.PRMREXPR, ["c"]]]]]]);598 });599 it('assignexpr error', function() {600 var parser = homunculus.getParser('js');601 expect(function() {602 parser.parse('a + b = c');603 }).to.throwError();604 });605 it('expr 1', function() {606 var parser = homunculus.getParser('js');607 var node = parser.parse('(1)');608 expect(tree(node)).to.eql([JsNode.PROGRAM, [JsNode.EXPRSTMT, [JsNode.PRMREXPR, ["(", JsNode.PRMREXPR, ["1"], ")"]]]]);609 });610 it('expr 2', function() {611 var parser = homunculus.getParser('js');612 var node = parser.parse('(a, !b, c+d)');613 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EXPRSTMT,[JsNode.PRMREXPR,["(",JsNode.EXPR,[JsNode.PRMREXPR,["a"],",",JsNode.UNARYEXPR,["!",JsNode.PRMREXPR,["b"]],",",JsNode.ADDEXPR,[JsNode.PRMREXPR,["c"],"+",JsNode.PRMREXPR,["d"]]],")"]]]]);614 });615 it('expr error 1', function() {616 var parser = homunculus.getParser('js');617 expect(function() {618 parser.parse('(a,');619 }).to.throwError();620 });621 it('expr error 2', function() {622 var parser = homunculus.getParser('js');623 expect(function() {624 parser.parse('(a, b');625 }).to.throwError();626 });627 it('block', function() {628 var parser = homunculus.getParser('js');629 var node = parser.parse('{}{}');630 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.BLOCK,["{","}"],JsNode.BLOCK,["{","}"]]]);631 });632 it('varstmt 1', function() {633 var parser = homunculus.getParser('js');634 var node = parser.parse('var a, b;');635 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a"],",",JsNode.VARDECL,["b"],";"]]]);636 });637 it('varstmt 2', function() {638 var parser = homunculus.getParser('js');639 var node = parser.parse('var a = 1');640 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]]]]);641 });642 it('varstmt 3', function() {643 var parser = homunculus.getParser('js');644 var node = parser.parse('var a = b = 1');645 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.ASSIGNEXPR,[JsNode.PRMREXPR,["b"],"=",JsNode.PRMREXPR,["1"]]]]]]]);646 });647 it('varstmt 4', function() {648 var parser = homunculus.getParser('js');649 var node = parser.parse('var a = [{}]');650 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],"]"]]]]]]]);651 });652 it('varstmt error 1', function() {653 var parser = homunculus.getParser('js');654 expect(function() {655 parser.parse('var')656 }).to.throwError();657 });658 it('varstmt error 2', function() {659 var parser = homunculus.getParser('js');660 expect(function() {661 parser.parse('var a=');662 }).to.throwError();663 });664 it('emptstmt', function() {665 var parser = homunculus.getParser('js');666 var node = parser.parse(';{;}');667 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.EMPTSTMT,[";"],JsNode.BLOCK,["{",JsNode.EMPTSTMT,[";"],"}"]]]);668 });669 it('ifstmt 1', function() {670 var parser = homunculus.getParser('js');671 var node = parser.parse('if(true);');672 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.EMPTSTMT,[";"]]]]);673 });674 it('ifstmt 2', function() {675 var parser = homunculus.getParser('js');676 var node = parser.parse('if(true){}else if(true){}else{}');677 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCK,["{","}"],"else",JsNode.IFSTMT,["if","(",JsNode.PRMREXPR,["true"],")",JsNode.BLOCK,["{","}"],"else",JsNode.BLOCK,["{","}"]]]]]);678 });679 it('ifstmt missing stmt', function() {680 var parser = homunculus.getParser('js');681 expect(function() {682 parser.parse('if(true)');683 }).to.throwError();684 });685 it('whilestmt 1', function() {686 var parser = homunculus.getParser('js');687 var node = parser.parse('while(false);');688 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.EMPTSTMT,[";"]]]]);689 });690 it('whilestmt 2', function() {691 var parser = homunculus.getParser('js');692 var node = parser.parse('while(false){}');693 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{","}"]]]]);694 });695 it('dowhilestmt 1', function() {696 var parser = homunculus.getParser('js');697 var node = parser.parse('do;while(false)');698 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["do",JsNode.EMPTSTMT,[";"],"while","(",JsNode.PRMREXPR,["false"],")"]]]);699 });700 it('dowhilestmt 2', function() {701 var parser = homunculus.getParser('js');702 var node = parser.parse('do{}while(false)');703 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["do",JsNode.BLOCK,["{","}"],"while","(",JsNode.PRMREXPR,["false"],")"]]]);704 });705 it('forstmt 1', function() {706 var parser = homunculus.getParser('js');707 var node = parser.parse('for(;;){}');708 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",";",";",")",JsNode.BLOCK,["{","}"]]]]);709 });710 it('forstmt 2', function() {711 var parser = homunculus.getParser('js');712 var node = parser.parse('for(var a = 1; a < len; a++){}');713 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,["a",JsNode.ASSIGN,["=",JsNode.PRMREXPR,["1"]]]],";",JsNode.RELTEXPR,[JsNode.PRMREXPR,["a"],"<",JsNode.PRMREXPR,["len"]],";",JsNode.POSTFIXEXPR,[JsNode.PRMREXPR,["a"],"++"],")",JsNode.BLOCK,["{","}"]]]]);714 });715 it('forstmt 3', function() {716 var parser = homunculus.getParser('js');717 var node = parser.parse('for(o in {});');718 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.PRMREXPR,["o"],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.EMPTSTMT,[";"]]]]);719 });720 it('forstmt 4', function() {721 var parser = homunculus.getParser('js');722 var node = parser.parse('for(var k in {}){}');723 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.VARSTMT,["var",JsNode.VARDECL,["k"]],"in",JsNode.PRMREXPR,[JsNode.OBJLTR,["{","}"]],")",JsNode.BLOCK,["{","}"]]]]);724 });725 it('forstmt 5', function() {726 var parser = homunculus.getParser('js');727 var node = parser.parse('for(new A in [1,2]);');728 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.NEWEXPR,["new",JsNode.PRMREXPR,["A"]],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]);729 });730 it('forstmt 6', function() {731 var parser = homunculus.getParser('js');732 var node = parser.parse('for(a.b in [1,2]);');733 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["for","(",JsNode.MMBEXPR,[JsNode.PRMREXPR,["a"],".","b"],"in",JsNode.PRMREXPR,[JsNode.ARRLTR,["[",JsNode.PRMREXPR,["1"],",",JsNode.PRMREXPR,["2"],"]"]],")",JsNode.EMPTSTMT,[";"]]]]);734 });735 it('forstmt missing expr', function() {736 var parser = homunculus.getParser('js');737 expect(function() {738 parser.parse('for(');739 }).to.throwError();740 });741 it('forstmt leftexpr error', function() {742 var parser = homunculus.getParser('js');743 expect(function() {744 parser.parse('for(a() in b);');745 }).to.throwError();746 });747 it('forstmt missing ; 1', function() {748 var parser = homunculus.getParser('js');749 expect(function() {750 parser.parse('for(var a');751 }).to.throwError();752 });753 it('forstmt missing ; 2', function() {754 var parser = homunculus.getParser('js');755 expect(function() {756 parser.parse('for(var a;');757 }).to.throwError();758 });759 it('forstmt missing ; 3', function() {760 var parser = homunculus.getParser('js');761 expect(function() {762 parser.parse('for(var a;a > 10;');763 }).to.throwError();764 });765 it('forstmt missing ; 4', function() {766 var parser = homunculus.getParser('js');767 expect(function() {768 parser.parse('for(a');769 }).to.throwError();770 });771 it('forstmt missing ; 5', function() {772 var parser = homunculus.getParser('js');773 expect(function() {774 parser.parse('for(a;');775 }).to.throwError();776 });777 it('forstmt missing ; 6', function() {778 var parser = homunculus.getParser('js');779 expect(function() {780 parser.parse('for(a;b');781 }).to.throwError();782 });783 it('forstmt missing ; 7', function() {784 var parser = homunculus.getParser('js');785 expect(function() {786 parser.parse('for(a;b;');787 }).to.throwError();788 });789 it('forstmt with in could not has multi varstmt', function() {790 var parser = homunculus.getParser('js');791 expect(function() {792 parser.parse('for(var a,b in {});');793 }).to.throwError();794 });795 it('forstmt with in first', function() {796 var parser = homunculus.getParser('js');797 expect(function() {798 parser.parse('for(in {});');799 }).to.throwError();800 });801 it('cntnstmt 1', function() {802 var parser = homunculus.getParser('js');803 var node = parser.parse('while(false){continue;}');804 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue",";"],"}"]]]]);805 });806 it('cntnstmt 2', function() {807 var parser = homunculus.getParser('js');808 var node = parser.parse('while(false){continue a;}');809 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue","a",";"],"}"]]]]);810 });811 it('cntnstmt 3', function() {812 var parser = homunculus.getParser('js');813 var node = parser.parse('while(false){continue\na;}');814 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.CNTNSTMT,["continue"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]);815 });816 it('brkstmt 1', function() {817 var parser = homunculus.getParser('js');818 var node = parser.parse('while(false){break;}');819 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break",";"],"}"]]]]);820 });821 it('brkstmt 2', function() {822 var parser = homunculus.getParser('js');823 var node = parser.parse('while(false){break a;}');824 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break","a",";"],"}"]]]]);825 });826 it('brkstmt 3', function() {827 var parser = homunculus.getParser('js');828 var node = parser.parse('while(false){break\na;}');829 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.ITERSTMT,["while","(",JsNode.PRMREXPR,["false"],")",JsNode.BLOCK,["{",JsNode.BRKSTMT,["break"],JsNode.EXPRSTMT,[JsNode.PRMREXPR,["a"],";"],"}"]]]]);830 });831 it('withstmt', function() {832 var parser = homunculus.getParser('js');833 var node = parser.parse('with(a){}');834 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.WITHSTMT,["with","(",JsNode.PRMREXPR,["a"],")",JsNode.BLOCK,["{","}"]]]]);835 });836 it('withstmt error', function() {837 var parser = homunculus.getParser('es6');838 expect(function() {839 parser.parse('with(){}');840 }).to.throwError();841 });842 it('swchstmt', function() {843 var parser = homunculus.getParser('js');844 var node = parser.parse('switch(a){case 1:case 2:;break;default:;}');845 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.CASECLAUSE,["case",JsNode.PRMREXPR,["1"],":"],JsNode.CASECLAUSE,["case",JsNode.PRMREXPR,["2"],":",JsNode.EMPTSTMT,[";"],JsNode.BRKSTMT,["break",";"]],JsNode.DFTCLAUSE,["default",":",JsNode.EMPTSTMT,[";"]],"}"]]]]);846 });847 it('defaultstmt', function() {848 var parser = homunculus.getParser('js');849 var node = parser.parse('switch(a){default:case 1:break;}');850 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.SWCHSTMT,["switch","(",JsNode.PRMREXPR,["a"],")",JsNode.CASEBLOCK,["{",JsNode.DFTCLAUSE,["default",":","case",JsNode.PRMREXPR,["1"],":",JsNode.BRKSTMT,["break",";"]],"}"]]]]);851 });852 it('swchstmt error', function() {853 var parser = homunculus.getParser('js');854 expect(function() {855 parser.parse('switch(a){else:;}');856 }).to.throwError();857 });858 it('thrstmt', function() {859 var parser = homunculus.getParser('js');860 var node = parser.parse('throw e;');861 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.THRSTMT,["throw",JsNode.PRMREXPR,["e"],";"]]]);862 });863 it('thrstmt error', function() {864 var parser = homunculus.getParser('js');865 expect(function() {866 parser.parse('throw');867 }).to.throwError();868 });869 it('trystmt 1', function() {870 var parser = homunculus.getParser('js');871 var node = parser.parse('try{}catch(e){}finally{}');872 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.CACH,["catch","(","e",")",JsNode.BLOCK,["{","}"]],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]);873 });874 it('trystmt 2', function() {875 var parser = homunculus.getParser('js');876 var node = parser.parse('try{}finally{}');877 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.TRYSTMT,["try",JsNode.BLOCK,["{","}"],JsNode.FINL,["finally",JsNode.BLOCK,["{","}"]]]]]);878 });879 it('trystmt error 1', function() {880 var parser = homunculus.getParser('js');881 expect(function() {882 parser.parse('try');883 }).to.throwError();884 });885 it('trystmt error 2', function() {886 var parser = homunculus.getParser('js');887 expect(function() {888 parser.parse('try{');889 }).to.throwError();890 });891 it('trystmt error 3', function() {892 var parser = homunculus.getParser('js');893 expect(function() {894 parser.parse('try{}catch');895 }).to.throwError();896 });897 it('trystmt error 4', function() {898 var parser = homunculus.getParser('js');899 expect(function() {900 parser.parse('try{}catch{');901 }).to.throwError();902 });903 it('trystmt error 5', function() {904 var parser = homunculus.getParser('js');905 expect(function() {906 parser.parse('try{}catch(');907 }).to.throwError();908 });909 it('trystmt error 6', function() {910 var parser = homunculus.getParser('js');911 expect(function() {912 parser.parse('try{}catch()');913 }).to.throwError();914 });915 it('trystmt error 7', function() {916 var parser = homunculus.getParser('js');917 expect(function() {918 parser.parse('try{}catch(a,b)');919 }).to.throwError();920 });921 it('trystmt error 8', function() {922 var parser = homunculus.getParser('js');923 expect(function() {924 parser.parse('try{}catch(a){');925 }).to.throwError();926 });927 it('trystmt error 9', function() {928 var parser = homunculus.getParser('js');929 expect(function() {930 parser.parse('try{}finally');931 }).to.throwError();932 });933 it('debstmt', function() {934 var parser = homunculus.getParser('js');935 var node = parser.parse('debugger;');936 expect(tree(node)).to.eql([JsNode.PROGRAM,[JsNode.DEBSTMT,["debugger",";"]]]);937 });938 it('empty 1', function() {939 var parser = homunculus.getParser('js');940 var node = parser.parse('');941 expect(tree(node)).to.eql([JsNode.PROGRAM,[]]);942 });943 it('empty 2', function() {944 var parser = homunculus.getParser('js');945 var node = parser.parse();946 expect(tree(node)).to.eql([JsNode.PROGRAM,[]]);947 });948 });949 describe('js lib exec test', function() {950 it('jquery 1.11.0', function() {951 var parser = homunculus.getParser('js');952 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.js'), { encoding: 'utf-8' });953 var node = parser.parse(code);954 var ignore = parser.ignore();955 var str = jion(node, ignore);956 expect(str).to.eql(code);957 });958 it('jquery 1.11.0 min', function() {959 var parser = homunculus.getParser('js');960 var code = fs.readFileSync(path.join(__dirname, './lib/jquery-1.11.0.min.js'), { encoding: 'utf-8' });961 var node = parser.parse(code);962 var ignore = parser.ignore();963 var str = jion(node, ignore);964 expect(str).to.eql(code);965 });966 it('backbone 1.1.0', function() {967 var parser = homunculus.getParser('js');968 var code = fs.readFileSync(path.join(__dirname, './lib/backbone.js'), { encoding: 'utf-8' });969 var node = parser.parse(code);970 var ignore = parser.ignore();971 var str = jion(node, ignore);972 expect(str).to.eql(code);973 });974 it('handlebars', function() {975 var parser = homunculus.getParser('js');976 var code = fs.readFileSync(path.join(__dirname, './lib/handlebars.js'), { encoding: 'utf-8' });977 var node = parser.parse(code);978 var ignore = parser.ignore();979 var str = jion(node, ignore);980 expect(str).to.eql(code);981 });982 it('bootstrap 3.0.0', function() {983 var parser = homunculus.getParser('js');984 var code = fs.readFileSync(path.join(__dirname, './lib/bootstrap.js'), { encoding: 'utf-8' });985 var node = parser.parse(code);986 var ignore = parser.ignore();987 var str = jion(node, ignore);988 expect(str).to.eql(code);989 });990 it('expect 0.1.2', function() {991 var parser = homunculus.getParser('js');992 var code = fs.readFileSync(path.join(__dirname, './lib/expect.js'), { encoding: 'utf-8' });993 var node = parser.parse(code);994 var ignore = parser.ignore();995 var str = jion(node, ignore);996 expect(str).to.eql(code);997 });998 it('html5shiv 3.6.1', function() {999 var parser = homunculus.getParser('js');1000 var code = fs.readFileSync(path.join(__dirname, './lib/html5shiv.js'), { encoding: 'utf-8' });1001 var node = parser.parse(code);1002 var ignore = parser.ignore();1003 var str = jion(node, ignore);1004 expect(str).to.eql(code);1005 });1006 it('formatter', function() {1007 var parser = homunculus.getParser('js');1008 var code = fs.readFileSync(path.join(__dirname, './lib/formatter.js'), { encoding: 'utf-8' });1009 var node = parser.parse(code);1010 var ignore = parser.ignore();1011 var str = jion(node, ignore);1012 expect(str).to.eql(code);1013 });1014 });1015 describe('other test', function() {1016 it('node #parent,#prev,#next', function() {1017 var parser = homunculus.getParser('js');1018 var node = parser.parse('var a, b;');1019 var varstmt = node.leaves()[0];1020 var children = varstmt.leaves();1021 var a = children[0];1022 var b = children[1];1023 expect(node.parent()).to.be(null);1024 expect(a.parent()).to.be(varstmt);1025 expect(b.parent()).to.be(varstmt);1026 expect(a.prev()).to.be(null);1027 expect(a.next()).to.be(b);1028 expect(b.prev()).to.be(a);1029 });1030 it('node #leaf,#size,#leaves', function() {1031 var parser = homunculus.getParser('js');1032 var node = parser.parse('var a');1033 var varstmt = node.leaf(0);1034 expect(varstmt.name()).to.be(JsNode.VARSTMT);1035 expect(varstmt.size()).to.be(3);1036 expect(varstmt.leaves().length).to.be(3);1037 });1038 it('node #nid', function() {1039 var parser = homunculus.getParser('js');1040 var node = parser.parse('var a');1041 expect(node.nid()).to.be.a('number');1042 });1043 it('#ast should return as parse return', function() {1044 var parser = homunculus.getParser('js');1045 var node = parser.parse('var a, b;');1046 expect(node).to.equal(parser.ast());1047 });1048 it('init class Parser(lexer) with a lexer', function() {1049 var lexer = homunculus.getLexer('js');1050 var parser = new Parser(lexer);1051 var node = parser.parse('var a, b;');1052 expect(node).to.equal(parser.ast());1053 expect(function() {1054 parser.init();1055 }).to.not.throwError();1056 });1057 it('JsNode#getKey', function() {1058 expect(JsNode.getKey('program')).to.eql('PROGRAM');1059 expect(function() {1060 JsNode.getKey('');1061 }).to.throwError();1062 });1063 it('plainObject', function() {1064 var parser = homunculus.getParser('js');1065 parser.parse('var a');1066 expect(parser.ast(true)).to.eql(["PROGRAM",["VARSTMT",["var","VARDECL",["a"]]]]);1067 });1068 });...

Full Screen

Full Screen

markdown.js

Source:markdown.js Github

copy

Full Screen

...18 });19 it('returns a function when the config is empty', () => {20 let parser;21 setMarkdownConf({});22 parser = markdown.getParser();23 expect(parser).toBeFunction();24 });25 it('does not change text within inline tags', () => {26 const parser = markdown.getParser();27 expect(parser('{@link MyClass#_x} and {@link MyClass#_y}')).toBe(28 '<p>{@link MyClass#_x} and {@link MyClass#_y}</p>');29 });30 it('does not convert HTTP/HTTPS URLs to links', () => {31 const parser = markdown.getParser();32 expect(parser('Visit {@link http://usejsdoc.com}.'))33 .toBe('<p>Visit {@link http://usejsdoc.com}.</p>');34 expect(parser('Visit {@link https://google.com}.'))35 .toBe('<p>Visit {@link https://google.com}.</p>');36 });37 it('escapes the expected characters in code blocks', () => {38 const parser = markdown.getParser();39 const markdownText = '' +40 '```html\n' +41 '<p><a href="#">Sample \'HTML.\'</a></p>\n' +42 '```';43 const convertedText = '' +44 '<pre class="prettyprint source lang-html"><code>' +45 '&lt;p&gt;&lt;a href=&quot;#&quot;&gt;Sample \'HTML.\'&lt;/a&gt;&lt;/p&gt;\n' +46 '</code></pre>';47 expect(parser(markdownText)).toBe(convertedText);48 });49 it('hardwraps new lines when requested', () => {50 let parser;51 setMarkdownConf({hardwrap: true});52 parser = markdown.getParser();53 expect(parser('line one\nline two')).toBe(54 '<p>line one<br>\nline two</p>');55 });56 it('adds heading IDs when requested', () => {57 let parser;58 setMarkdownConf({idInHeadings: true});59 parser = markdown.getParser();60 expect(parser('# Hello')).toBe('<h1 id="hello">Hello</h1>');61 });62 it('does not pretty-print code blocks that start with "```plain"', () => {63 const parser = markdown.getParser();64 const markdownText = '```plain\nconsole.log("foo");\n```';65 const convertedText = '<pre class="source"><code>console.log(&quot;foo&quot;);\n' +66 '</code></pre>';67 expect(parser(markdownText)).toBe(convertedText);68 });69 describe('syntax highlighter', () => {70 it('supports a `highlight` function defined in the config file', () => {71 let parser;72 setMarkdownConf({73 highlight(code, language) {74 return `<pre><code>${code} highlighted as ${language}</code></pre>`;75 }76 });77 parser = markdown.getParser();78 expect(parser('```js\nhello\n```')).toBe(79 '<pre><code>hello\n highlighted as js</code></pre>'80 );81 });82 it('supports `highlight` as the path to a highlighter module', () => {83 let parser;84 setMarkdownConf({85 highlight: path.join(__dirname, '../../fixtures/markdown/highlighter')86 });87 parser = markdown.getParser();88 expect(parser('```js\nhello\n```')).toBe(89 '<pre><code>hello\n in this language: js</code></pre>'90 );91 });92 // TODO: Re-enable when `jsdoc.didLog()` is available outside of the JSDoc repo93 xit('logs an error if the `highlight` module cannot be found', () => {94 /*95 function getParser() {96 setMarkdownConf({97 highlight: path.join(__dirname, 'foo/bar/baz')98 });99 markdown.getParser();100 }101 expect(jsdoc.didLog(getParser, 'error')).toBeTrue();102 */103 });104 // TODO: Re-enable when `jsdoc.didLog()` is available outside of the JSDoc repo105 xit('logs an error if the `highlight` module does not assign a method to ' +106 '`exports.highlight`', () => {107 /*108 function getParser() {109 setMarkdownConf({110 highlight: path.join(__dirname, '../../fixtures/markdown/bad-highlighter')111 });112 markdown.getParser();113 }114 expect(jsdoc.didLog(getParser, 'error')).toBeTrue();115 */116 });117 });118 });...

Full Screen

Full Screen

tests.js

Source:tests.js Github

copy

Full Screen

1test('ID Test', function() {2 equal( $.tablesorter.getParser().id , 'opus-dates', 'ID correct' );3});4test('Type Test', function() {5 equal( $.tablesorter.getParser().type , 'text', 'Type correct' );6});7test('Match test', function() {8 ok( !$.tablesorter.getParser().is('test') , 'Not a date' );9 // our parser is only interested in the one date format10 // so we should reject anything else.11 ok( !$.tablesorter.getParser().is('2012-04-30') , 'Not a date' );12 ok( !$.tablesorter.getParser().is('') , 'Not a date' );13 ok( !$.tablesorter.getParser().is() , 'Not a date' );14 ok( $.tablesorter.getParser().is('20-Jan-2012') , 'A date' );15 ok( $.tablesorter.getParser().is('20-Jan-2012 00:00') , 'A date' );16 ok( $.tablesorter.getParser().is('20-Jun-2012 00:00') , 'A date' );17 ok( $.tablesorter.getParser().is('20-Mar-2012 00:00') , 'A date' );18 ok( $.tablesorter.getParser().is('20-Feb-2012 00:00') , 'A date' );19 ok( $.tablesorter.getParser().is('20-Apr-2012 00:00') , 'A date' );20 ok( $.tablesorter.getParser().is('20-Jul-2012 00:00') , 'A date' );21 ok( $.tablesorter.getParser().is('20-May-2012 00:00') , 'A date' );22 ok( $.tablesorter.getParser().is('20-Aug-2012 00:00') , 'A date' );23 ok( $.tablesorter.getParser().is('20-Sep-2012 00:00') , 'A date' );24 ok( $.tablesorter.getParser().is('20-Oct-2012 00:00') , 'A date' );25 ok( $.tablesorter.getParser().is('20-Nov-2012 00:00') , 'A date' );26 ok( $.tablesorter.getParser().is('01-Dec-2012 10:00') , 'A date' );27 ok( $.tablesorter.getParser().is('01-Dec-2012 10:00') , 'A date' );28 ok( $.tablesorter.getParser().is('01-Dec-2012 10:00') , 'A date' );29 ok( $.tablesorter.getParser().is('05-Nov-2012 14:50') , 'A date' );30 ok( $.tablesorter.getParser().is('05-Nov-2012 14:53') , 'A date' );31 ok( $.tablesorter.getParser().is("05-Nov-2012\t14:53") , 'A date' );32 ok( !$.tablesorter.getParser().is('View') , 'Not a date' );33 ok( !$.tablesorter.getParser().is('VMA000001') , 'Not a date' );34 ok( !$.tablesorter.getParser().is('Delivery') , 'Not a date' );35 ok( !$.tablesorter.getParser().is('Cardiff') , 'Not a date' );36 ok( !$.tablesorter.getParser().is('Dominic Mason') , 'Not a date' );37 ok( !$.tablesorter.getParser().is('View details') , 'Not a date' );38});39test('Format test', function() {40 equal( $.tablesorter.getParser().format('20-Jan-2012 00:00') , '2012-01-20 00:00', 'Reformatted date' );41 equal( $.tablesorter.getParser().format('20-Jun-2012 00:00'), '2012-06-20 00:00', 'Reformatted date');42 equal( $.tablesorter.getParser().format('20-Mar-2012 00:00'), '2012-03-20 00:00', 'Reformatted date');43 equal( $.tablesorter.getParser().format('20-Feb-2012 00:00'), '2012-02-20 00:00', 'Reformatted date');44 equal( $.tablesorter.getParser().format('20-Apr-2012 00:00'), '2012-04-20 00:00', 'Reformatted date');45 equal( $.tablesorter.getParser().format('20-Jul-2012 00:00'), '2012-07-20 00:00', 'Reformatted date');46 equal( $.tablesorter.getParser().format('20-May-2012 00:00'), '2012-05-20 00:00', 'Reformatted date');47 equal( $.tablesorter.getParser().format('20-Aug-2012 00:00'), '2012-08-20 00:00', 'Reformatted date');48 equal( $.tablesorter.getParser().format('20-Sep-2012 00:00'), '2012-09-20 00:00', 'Reformatted date');49 equal( $.tablesorter.getParser().format('20-Oct-2012 00:00'), '2012-10-20 00:00', 'Reformatted date');50 equal( $.tablesorter.getParser().format('20-Nov-2012 00:00'), '2012-11-20 00:00', 'Reformatted date');51 equal( $.tablesorter.getParser().format('01-Dec-2012 10:00'), '2012-12-01 10:00', 'Reformatted date');52 equal( $.tablesorter.getParser().format('01-Dec-2012'), '2012-12-01', 'Reformatted date');53 // check this just gets passed through unharmed rather than choking54 ok( $.tablesorter.getParser().format('Cash (30-Oct-2012) - Print '), 'No crash');55 ok( $.tablesorter.getParser().format('not a date'), 'No crash');...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

...19 const node = parse(code, optsA)20 const nodeA = normalizeNode(node, optsA)21 return nodeA22}23export const acorn = getParser(acornParser)24export const babel = getParser(babelParser)25export const babelEstree = getParser(babelEstreeParser)26export const espree = getParser(espreeParser)27export const esprima = getParser(esprimaParser)28export const meriyah = getParser(meriyahParser)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var appium = require('appium');3 withCapabilities({4 build();5driver.getParser().then(function(parser) {6 console.log(parser);7});8driver.quit();9var webdriver = require('selenium-webdriver');10var appium = require('appium');11 withCapabilities({12 build();13driver.getParser().then(function(parser) {14 console.log(parser);15});16driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";2import { assert } from "chai";3describe("sample scenario", () => {4 let driver: AppiumDriver;5 before(async () => {6 driver = await createDriver();7 });8 after(async () => {9 await driver.quit();10 });11 it("should find an element", async () => {12 const searchOptions: SearchOptions = {13 };14 const label = await driver.findElement(searchOptions);15 assert.equal(await label.text(), "hello world");16 });17});18import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";19import { assert } from "chai";20describe("sample scenario", () => {21 let driver: AppiumDriver;22 before(async () => {23 driver = await createDriver();24 });25 after(async () => {26 await driver.quit();27 });28 it("should find an element", async () => {29 const searchOptions: SearchOptions = driver.getParser().getSearchOptions("hello world");30 const label = await driver.findElement(searchOptions);31 assert.equal(await label.text(), "hello world");32 });33});34import { AppiumDriver, createDriver, SearchOptions, Direction } from "nativescript-dev-appium";35import { assert } from "chai";36describe("sample scenario", () => {37 let driver: AppiumDriver;38 before(async () => {39 driver = await createDriver();40 });41 after(async () => {42 await driver.quit();43 });44 it("should find an element",

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium').AppiumDriver;2var driver = new AppiumDriver();3var parser = driver.getParser();4var AppiumDriver = require('appium').AppiumDriver;5var driver = new AppiumDriver();6var parser = driver.getParser();7var AppiumDriver = require('appium').AppiumDriver;8var driver = new AppiumDriver();9var parser = driver.getParser();10var AppiumDriver = require('appium').AppiumDriver;11var driver = new AppiumDriver();12var parser = driver.getParser();13var AppiumDriver = require('appium').AppiumDriver;14var driver = new AppiumDriver();15var parser = driver.getParser();16var AppiumDriver = require('appium').AppiumDriver;17var driver = new AppiumDriver();18var parser = driver.getParser();19var AppiumDriver = require('appium').AppiumDriver;20var driver = new AppiumDriver();21var parser = driver.getParser();22var AppiumDriver = require('appium').AppiumDriver;23var driver = new AppiumDriver();24var parser = driver.getParser();25var AppiumDriver = require('appium').AppiumDriver;26var driver = new AppiumDriver();27var parser = driver.getParser();28var AppiumDriver = require('appium').AppiumDriver;29var driver = new AppiumDriver();30var parser = driver.getParser();31var AppiumDriver = require('appium').AppiumDriver;32var driver = new AppiumDriver();33var parser = driver.getParser();34var AppiumDriver = require('appium').AppiumDriver;35var driver = new AppiumDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1var appium = require('appium');2var parser = appium.getParser();3var args = parser.parseArgs();4console.log("args: " + args);5var Parser = require('appium/lib/parser');6var parser = new Parser();7var args = parser.parseArgs();8console.log("args: " + args);9{ [Error: Cannot find module 'appium/lib/parser']10code: 'MODULE_NOT_FOUND' }11Your name to display (optional):12Your name to display (optional):13var Parser = require('appium/lib/parser/parser');14var parser = new Parser();15var args = parser.parseArgs();16console.log("args: " + args);17Your name to display (optional):18Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1const AppiumDriver = require('appium-driver');2let parser = AppiumDriver.getParser();3let args = parser.parseArgs();4console.log(args);5const AppiumDriver = require('appium-driver');6let parser = AppiumDriver.getParser();7let args = parser.parseArgs();8console.log(args);9const AppiumDriver = require('appium-driver');10let parser = AppiumDriver.getParser();11let args = parser.parseArgs();12console.log(args);13const AppiumDriver = require('appium-driver');14let parser = AppiumDriver.getParser();15let args = parser.parseArgs();16console.log(args);17const AppiumDriver = require('appium-driver');18let parser = AppiumDriver.getParser();19let args = parser.parseArgs();20console.log(args);21const AppiumDriver = require('appium-driver');22let parser = AppiumDriver.getParser();23let args = parser.parseArgs();24console.log(args);25const AppiumDriver = require('appium-driver');26let parser = AppiumDriver.getParser();27let args = parser.parseArgs();28console.log(args);29const AppiumDriver = require('appium-driver');30let parser = AppiumDriver.getParser();31let args = parser.parseArgs();32console.log(args);33const AppiumDriver = require('appium-driver');34let parser = AppiumDriver.getParser();35let args = parser.parseArgs();36console.log(args);37const AppiumDriver = require('appium-driver');38let parser = AppiumDriver.getParser();39let args = parser.parseArgs();40console.log(args);

Full Screen

Using AI Code Generation

copy

Full Screen

1var parser = driver.getParser();2var parsed = parser.parse("test string");3var parser = driver.getParser();4var parsed = parser.parse("test string");5var parser = driver.getParser();6var parsed = parser.parse("test string");7var parser = driver.getParser();8var parsed = parser.parse("test string");9var parser = driver.getParser();10var parsed = parser.parse("test string");11var parser = driver.getParser();12var parsed = parser.parse("test string");13var parser = driver.getParser();14var parsed = parser.parse("test string");15var parser = driver.getParser();16var parsed = parser.parse("test string");17var parser = driver.getParser();18var parsed = parser.parse("test string");19var parser = driver.getParser();20var parsed = parser.parse("test string");21var parser = driver.getParser();22var parsed = parser.parse("test string");23var parser = driver.getParser();24var parsed = parser.parse("test string");

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium-android-driver');2var parser = AppiumDriver.getParser();3parser.parseArgs(['--app', 'path/to/my/app.apk']);4console.log(parser.argv.app);5var AppiumDriver = require('appium-android-driver');6var parser = AppiumDriver.getParser();7parser.parseArgs(['--app', 'path/to/my/app.apk']);8console.log(parser.argv.app);9var AppiumDriver = require('appium-android-driver');10var parser = AppiumDriver.getParser();11parser.parseArgs(['--app', 'path/to/my/app.apk']);12console.log(parser.argv.app);13var AppiumDriver = require('appium-android-driver');14var parser = AppiumDriver.getParser();15parser.parseArgs(['--app', 'path/to/my/app.apk']);16console.log(parser.argv.app);17var AppiumDriver = require('appium-android-driver');18var parser = AppiumDriver.getParser();19parser.parseArgs(['--app', 'path/to/my/app.apk']);20console.log(parser.argv.app);21var AppiumDriver = require('appium-android-driver');22var parser = AppiumDriver.getParser();23parser.parseArgs(['--app', 'path/to/my/app.apk']);24console.log(parser.argv.app);25var AppiumDriver = require('appium-android-driver');26var parser = AppiumDriver.getParser();27parser.parseArgs(['--app', 'path/to/my/app.apk']);28console.log(parser.argv.app);29var AppiumDriver = require('appium-android-driver');30var parser = AppiumDriver.getParser();31parser.parseArgs(['--app', 'path/to/my/app.apk']);32console.log(parser.argv.app);33var AppiumDriver = require('appium-android-driver');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful