How to use processExpression method in Playwright Internal

Best JavaScript code snippet using playwright-internal

analyzer.js

Source:analyzer.js Github

copy

Full Screen

...198 }199 }200 throw new Error('control-flow: Label not found: ' + label);201 }202 function processExpression(node) {203 switch (node.type) {204 case 'ThisExpression':205 ops.push('ThisExpression');206 for (var i = 0; i < vars.length; ++i) {207 if (vars[i].id === 'this') {208 vars[i].nodes.push(node);209 break;210 }211 }212 return new VariableId('this', node);213 case 'MemberExpression':214 ops.push('MemberExpression');215 var o = processExpression(node.object);216 var r = temporary(node);217 var p = processExpression(node.property);218 return clone(r);219 case 'Identifier':220 ops.push('Identifier');221 return lookupIdentifier(node.name, node);222 case 'Literal':223 ops.push('Literal');224 return new Literal(node.value, node);225 case 'FunctionExpression': //为function单独分出一个块,terminater是jump226 var term1 = new JumpTerminator(0, node);227 splitBlock(term1);228 term1.next = cblock.id;229 ops.push('FunctionExpression');230 var r = temporary(node);231 pendingClosures.push({232 id: r,233 parentblockid: cblock.id,234 parentclosure: name,235 closure: node,236 environment: makeEnv({237 root: false,238 }),239 });240 var functerm = new JumpTerminator(0, node);241 splitBlock(functerm);242 functerm.next = cblock.id;243 return clone(r);244 case 'ArrowFunctionExpression':245 var term1 = new JumpTerminator(0, node);246 splitBlock(term1);247 term1.next = cblock.id;248 ops.push('ArrowFunctionExpression');249 var r = temporary(node);250 pendingClosures.push({251 id: r,252 parentblockid: cblock.id,253 parentclosure: name,254 closure: node,255 environment: makeEnv({256 root: false,257 }),258 });259 var functerm = new JumpTerminator(0, node);260 splitBlock(functerm);261 functerm.next = cblock.id;262 return clone(r);263 case 'SequenceExpression':264 ops.push('SequenceExpression');265 var r;266 for (var i = 0; i < node.expressions.length; ++i) {267 r = processExpression(node.expressions[i]);268 }269 return r;270 case 'UnaryExpression':271 ops.push('UnaryExpression');272 var r = temporary(node);273 var arg = processExpression(node.argument);274 return clone(r);275 case 'BinaryExpression':276 ops.push('BinaryExpression');277 var r = temporary(node);278 var a = processExpression(node.left);279 var b = processExpression(node.right);280 return clone(r);281 case 'AssignmentExpression':282 ops.push('AssignmentExpression');283 var a = processExpression(node.right);284 var tok = node.operator;285 var tmp = temporary(node);286 var b = processExpression(node.left);287 return clone(tmp);288 case 'UpdateExpression':289 ops.push('UpdateExpression');290 var tok;291 if (node.operator === '++') {292 tok = '+';293 } else if (node.operator === '--') {294 tok = '-';295 }296 var r = temporary(node);297 var v = processExpression(node.argument);298 if (node.prefix) {299 return clone(r);300 } else {301 return clone(v);302 }303 case 'LogicalExpression':304 ops.push('LogicalExpression');305 var tmp = temporary(node);306 var r = processExpression(node.left);307 var s = new IfTerminator(clone(r), 0, 0, node);308 var x = blocks.length;309 splitBlock(s);310 var l = processExpression(node.right);311 var y = blocks.length;312 var t = new JumpTerminator(y, node);313 splitBlock(t);314 if (node.operator === '||') {315 s.consequent = y;316 s.alternate = x;317 } else if (node.operator === '&&') {318 s.consequent = x;319 s.alternate = y;320 } else {321 throw new Error(322 'control-flow: Unrecognized logical operator'323 );324 }325 return clone(tmp);326 case 'ConditionalExpression':327 ops.push('ConditionalExpression');328 var r = temporary(node);329 var test = processExpression(node.test);330 var term1 = new IfTerminator(test, 0, 0, node);331 splitBlock(term1);332 term1.consequent = cblock.id;333 var t = processExpression(node.consequent);334 var term2 = new JumpTerminator(0, node);335 splitBlock(term2);336 term1.alternate = cblock.id;337 var f = processExpression(node.alternate);338 var term3 = new JumpTerminator(0, node);339 splitBlock(term3);340 term2.next = cblock.id;341 term3.next = cblock.id;342 return clone(r);343 case 'CallExpression':344 ops.push('CallExpression');345 var f = processExpression(node.callee);346 var args = new Array(node.arguments.length);347 for (var i = 0; i < node.arguments.length; ++i) {348 args[i] = processExpression(node.arguments[i]);349 }350 var r = temporary(node);351 return clone(r);352 case 'NewExpression':353 ops.push('NewExpression');354 var args = new Array(node.arguments.length);355 for (var i = 0; i < node.arguments.length; ++i) {356 args[i] = processExpression(node.arguments[i]);357 }358 var r = temporary(node);359 var ctor = processExpression(node.callee);360 return clone(r);361 case 'ArrayExpression':362 ops.push('ArrayExpression');363 var arr = temporary(node);364 for (var i = 0; i < node.elements.length; ++i) {365 var val;366 if (node.elements[i]) {367 val = processExpression(node.elements[i]);368 } else {369 ops.push('Literal');370 val = new Literal(undefined, node);371 }372 }373 return clone(arr);374 case 'SpreadElement':375 ops.push('SpreadElement');376 var tmp = processExpression(node.argument);377 return clone(tmp);378 case 'ObjectExpression':379 ops.push('ObjectExpression');380 var obj = temporary(node);381 for (var i = 0; i < node.properties.length; ++i) {382 ops.push('Property');383 var prop = node.properties[i];384 var p = processExpression(prop.key);385 var value = processExpression(prop.value);386 }387 return clone(obj);388 case 'TemplateLiteral':389 var obj = temporary(node);390 ops.push('TemplateLiteral');391 for (var i = 0; i < node.expressions.length; ++i) {392 var p = processExpression(node.expressions[i]);393 }394 return clone(obj);395 396 case 'ClassExpression':397 var obj = temporary(node);398 ops.push('ClassExpression');399 ops.push('ClassBody');400 var term1 = new JumpTerminator(0, node);401 splitBlock(term1);402 term1.next = cblock.id;403 for (let i = 0; i < node.body.body.length; i++) {404 let method = node.body.body[i];405 ops.push('MethodDefinition');406 pendingClosures.push({407 id: temporary(method),408 parentblockid: cblock.id,409 parentclosure: name,410 closure: method,411 environment: makeEnv({412 root: false,413 }),414 });415 var functerm = new JumpTerminator(0, node);416 splitBlock(functerm);417 functerm.next = cblock.id;418 }419 return clone(obj);420 421 case 'Super':422 var obj = temporary(node);423 ops.push('Super');424 return clone(obj);425 case 'ArrayPattern':426 var obj = temporary(node);427 ops.push('ArrayPattern');428 for (let i = 0; i < node.elements.length; i++) {429 let element = node.elements[i];430 processExpression(element);431 }432 return clone(obj);433 434 case 'ObjectPattern':435 ops.push('ObjectPattern');436 var obj = temporary(node);437 for (var i = 0; i < node.properties.length; ++i) {438 ops.push('Property');439 var prop = node.properties[i];440 var p = processExpression(prop.key);441 var value = processExpression(prop.value);442 }443 return clone(obj);444 case 'AwaitExpression':445 var obj = temporary(node);446 ops.push('AwaitExpression');447 processExpression(node.argument);448 return clone(obj);449 default:450 throw new Error(451 'control-flow: Unrecognized expression type: ' +452 node.type453 );454 }455 }456 function processStatement(stmt) {457 switch (stmt.type) {458 case 'EmptyStatement':459 ops.push('EmptyStatement');460 break;461 case 'BlockStatement':462 ops.push('BlockStatement');463 for (var i = 0; i < stmt.body.length; ++i) {464 processStatement(stmt.body[i]);465 }466 break;467 case 'ExpressionStatement':468 ops.push('ExpressionStatement');469 var r = processExpression(stmt.expression);470 //Check if we should enable strict mode471 if (472 isFirst &&473 r.type === 'Literal' &&474 r.value === 'use strict'475 ) {476 strictMode = env.strict = true;477 }478 break;479 case 'IfStatement':480 ops.push('IfStatement');481 var test = processExpression(stmt.test);482 if ((stmt.consequent && stmt.consequent.type != 'BlockStatement' ) || (stmt.consequent.type == 'BlockStatement' && stmt.consequent.body.length)) {483 var term = new IfTerminator(test, 0, 0, stmt);484 splitBlock(term);485 var next = cblock.id;486 term.consequent = processBlock(487 stmt.consequent,488 makeEnv({489 next: next,490 })491 );492 if (stmt.alternate) {493 term.alternate = processBlock(494 stmt.alternate,495 makeEnv({496 next: next,497 })498 );499 } else {500 term.alternate = next;501 }502 }503 break;504 case 'LabeledStatement':505 var jmp = new JumpTerminator(0,stmt);506 splitBlock(jmp);507 ops.push('LabeledStatement');508 jmp = processBlock(stmt.body, makeEnv({509 next: cblock.id,510 breakBlock: cblock.id,511 continueBlock: cblock.id + 1,512 label: stmt.label.name513 }));514 break;515 case 'BreakStatement':516 ops.push('BreakStatement');517 if (stmt.label) {518 var e = lookupLabel(stmt.label.name);519 splitBlock(new JumpTerminator(e.breakBlock, stmt));520 } else {521 splitBlock(new JumpTerminator(env.breakBlock, stmt));522 }523 break;524 case 'ContinueStatement':525 ops.push('ContinueStatement');526 if (stmt.label) {527 var e = lookupLabel(stmt.label.name);528 if (e.isSwitch) {529 throw new Error(530 "control-flow: Can't continue from switch statement"531 );532 }533 splitBlock(new JumpTerminator(e.continueBlock, stmt));534 } else {535 splitBlock(new JumpTerminator(env.continueBlock, stmt));536 }537 break;538 case 'WithStatement':539 ops.push('WithStatement');540 var obj = processExpression(stmt.object);541 var body = processStatement(stmt.body);542 break;543 case 'SwitchStatement':544 ops.push('SwitchStatement');545 var discr = processExpression(stmt.discriminant);546 var jmpToSwitchHead = new JumpTerminator(0, stmt);547 splitBlock(jmpToSwitchHead);548 var jmpToSwitchBreak = new JumpTerminator(0, stmt);549 var breakBlockId = blocks.length - 1;550 splitBlock(jmpToSwitchBreak);551 jmpToSwitchHead.next = cblock.id;552 for (var i = 0; i < stmt.cases.length; ++i) {553 var c = stmt.cases[i];554 if (c.test) {555 ops.push('SwitchCase');556 //处理case语句557 var r = processExpression(c.test);558 if (c.consequent.length) {559 var casejmp = new IfTerminator(clone(r), 0, 0, c);560 splitBlock(casejmp);561 casejmp.consequent = processBlock(562 c.consequent,563 makeEnv({564 next: cblock.id,565 breakBlock: breakBlockId,566 isSwitch: true,567 })568 );569 casejmp.alternate = cblock.id;570 }571 } else {572 //处理default语句573 if (c.consequent.length) {574 var casejmp = new JumpTerminator(0, c);575 splitBlock(casejmp);576 casejmp.next = processBlock(577 c.consequent,578 makeEnv({579 next: cblock.id,580 breakBlock: breakBlockId,581 isSwitch: true,582 })583 )584 blocks[casejmp.next].body.splice(0,0,'SwitchCase');585 }else{586 ops.push('SwitchCase');587 }588 }589 }590 jmpToSwitchBreak.next = cblock.id;591 break;592 case 'ReturnStatement':593 ops.push('ReturnStatement');594 if(stmt.argument){595 processExpression(stmt.argument);596 }597 splitBlock(new JumpTerminator(exit, stmt));598 break;599 case 'ThrowStatement':600 ops.push('ThrowStatement');601 processExpression(stmt.argument)602 splitBlock(new JumpTerminator(env.catch, stmt));603 break;604 case 'TryStatement':605 ops.push('TryStatement');606 var jmpToStart = new JumpTerminator(0, stmt);607 splitBlock(jmpToStart);608 //Generate finally block609 var next = cblock.id;610 var finallyBlock;611 if (stmt.finalizer) {612 finallyBlock = processBlock(613 stmt.finalizer,614 makeEnv({615 next: next,616 })617 );618 } else {619 finallyBlock = next;620 }621 //Get handler622 var handler = stmt.handler;623 if (!handler && stmt.handlers && stmt.handlers.length > 0) {624 handler = stmt.handlers[0];625 }626 //Generate catch block627 var catchBlock;628 var exception = temporary(stmt);629 if (handler) {630 catchBlock = processBlock(631 handler,632 makeEnv({633 next: finallyBlock,634 catchVar: [handler.param.name, exception.id],635 })636 );637 }638 //Generate main try block639 var tryBlock = processBlock(640 stmt.block,641 makeEnv({642 next: finallyBlock,643 exception: exception.id,644 catch: catchBlock || null,645 })646 );647 //Fix up links648 jmpToStart.next = tryBlock;649 break;650 651 case 'CatchClause':652 ops.push('CatchClause');653 processExpression(stmt.param);654 processStatement(stmt.body);655 break;656 case 'WhileStatement':657 ops.push('WhileStatement');658 var jmp = new JumpTerminator(0, stmt);659 splitBlock(jmp);660 var loopStart = cblock.id;661 jmp.next = loopStart;662 var test = processExpression(stmt.test);663 var ifHead = new IfTerminator(test, 0, 0, stmt);664 splitBlock(ifHead);665 var loopExit = cblock.id;666 var loopBody = processBlock(667 stmt.body,668 makeEnv({669 next: loopStart,670 continueBlock: loopStart,671 breakBlock: loopExit,672 })673 );674 ifHead.consequent = loopBody;675 ifHead.alternate = loopExit;676 break;677 case 'DoWhileStatement':678 ops.push('DoWhileStatement');679 var jmpStart = new JumpTerminator(0, stmt);680 splitBlock(jmpStart);681 var loopStart = cblock.id;682 var test = processExpression(stmt.test);683 var ifHead = new IfTerminator(test, 0, 0, node);684 splitBlock(ifHead);685 var loopExit = cblock.id;686 var loopBody = processBlock(687 stmt.body,688 makeEnv({689 next: loopStart,690 continueBlock: loopStart,691 breakBlock: loopExit,692 })693 );694 jmpStart.next = loopBody;695 ifHead.consequent = loopBody;696 ifHead.alternate = loopExit;697 break;698 case 'ForStatement':699 ops.push('ForStatement');700 //Create initialization block701 if (stmt.init) {702 if (stmt.init.type === 'VariableDeclaration') {703 processStatement(stmt.init);704 } else {705 processExpression(stmt.init);706 }707 }708 var jmpStart = new JumpTerminator(0, next);709 splitBlock(jmpStart);710 //Create test block711 var loopTest = cblock.id;712 var test;713 if (stmt.test) {714 test = processExpression(stmt.test);715 var ifTest = new IfTerminator(test, 0, 0, stmt.test || stmt);716 splitBlock(ifTest);717 } else {718 var jmp = new JumpTerminator(0, stmt.test || stmt);719 splitBlock(jmp);720 }721 //Create update block722 var loopUpdate = cblock.id;723 if (stmt.update) {724 processExpression(stmt.update);725 }726 var jmpUpdate = new JumpTerminator(727 loopTest,728 stmt.update || stmt729 );730 splitBlock(jmpUpdate);731 //Create exit node732 var loopExit = cblock.id;733 //Link nodes734 jmpStart.next = loopTest;735 if (stmt.test) {736 ifTest.alternate = loopExit;737 ifTest.consequent = processBlock(738 stmt.body,739 makeEnv({740 next: loopUpdate,741 continueBlock: loopUpdate,742 breakBlock: loopExit,743 })744 );745 } else {746 jmp.next = processBlock(747 stmt.body,748 makeEnv({749 next: loopUpdate,750 continueBlock: loopUpdate,751 breakBlock: loopExit,752 })753 );754 }755 756 break;757 case 'ForInStatement':758 ops.push('ForInStatement');759 var rightObj = processExpression(stmt.right);760 var jmp = new JumpTerminator(blocks.length, stmt);761 splitBlock(jmp)762 if (stmt.left.type == 'VariableDeclaration'){763 var leftObj = processStatement(stmt.left);764 }else{765 var leftObj = processExpression(stmt.left);766 }767 var loopStart = cblock.id;768 var ift = new IfTerminator(leftObj, 0, blocks.length, stmt);769 splitBlock(ift);770 var loopExit = cblock.id;771 var loopBody = processBlock(772 stmt.body,773 makeEnv({774 next: loopStart,775 breakBlock: loopExit,776 continueBlock: loopStart,777 })778 );779 ift.consequent = loopBody;780 break;781 case 'ForOfStatement':782 ops.push('ForOfStatement');783 var rightObj = processExpression(stmt.right);784 var jmp = new JumpTerminator(blocks.length, stmt);785 splitBlock(jmp)786 if (stmt.left.type == 'VariableDeclaration'){787 var leftObj = processStatement(stmt.left);788 }else{789 var leftObj = processExpression(stmt.left);790 }791 var loopStart = cblock.id;792 var ift = new IfTerminator(leftObj, 0, blocks.length, stmt);793 splitBlock(ift);794 var loopExit = cblock.id;795 var loopBody = processBlock(796 stmt.body,797 makeEnv({798 next: loopStart,799 breakBlock: loopExit,800 continueBlock: loopStart,801 })802 );803 ift.consequent = loopBody;804 break;805 case 'VariableDeclaration':806 ops.push('VariableDeclaration');807 for (var i = 0; i < stmt.declarations.length; ++i) {808 ops.push('VariableDeclarator');809 processExpression(stmt.declarations[i].id)810 if (stmt.declarations[i].init) {811 processExpression(stmt.declarations[i].init);812 }813 }814 break;815 case 'FunctionDeclaration':816 var term1 = new JumpTerminator(0, stmt);817 splitBlock(term1);818 term1.next = cblock.id;819 ops.push('FunctionDeclaration');820 var tmp = temporary(stmt);821 pendingClosures.push({822 id: tmp,823 parentblockid: cblock.id,824 parentclosure: name,825 closure: stmt,...

Full Screen

Full Screen

useAnalysis.js

Source:useAnalysis.js Github

copy

Full Screen

...89 // var a = {x: function() {a=1}}90 // should process init first, then lhs91 // process sequence should identical to Fuzzil IR92 if (stmt.declarations[i].init!==null) {93 processExpression(stmt.declarations[i].init, symtab);94 }95 processPattern(stmt.declarations[i].id, symtab, letScope, true);96 }97 break;98 case 'BlockStatement':99 if (stmt.declaredVars===undefined) {100 initSymtabDeclaredVars(symtab, stmt);101 // we only track out of let scope use before def. Mark every function102 // inside let scope as inScope so that we don't track same let scope103 // use before def.104 for (const [func] of stmt.funcInBlock) {105 setSymtab(symtab, func, 'declared', 'inScope');106 }107 for (let i=0; i<stmt.body.length; i++) {108 processStmt(stmt.body[i], symtab, stmt);109 }110 for (const [func] of stmt.funcInBlock) {111 setSymtab(symtab, func, 'declared', 'outScope');112 }113 cleanSymtabDeclaredVars(symtab, stmt);114 break;115 } else {116 // called from function declaration, father node have already init117 // symtab and processed the arguments;118 for (const [func] of stmt.funcInBlock) {119 setSymtab(symtab, func, 'declared', 'inScope');120 }121 for (let i=0; i<stmt.body.length; i++) {122 processStmt(stmt.body[i], symtab, stmt);123 }124 break;125 }126 case 'FunctionDeclaration':127 // func declaration has to be handled in blockStatment.128 // duplicated function declaration means use not def129 // {130 // function a() { }131 // function a() { 1; }132 // }133 // but FunctionDeclaration use may never cause134 // out of scope use before def.135 initSymtabDeclaredVars(symtab, stmt.body);136 for (let i=0; i<stmt.params.length; i++) {137 processPattern(stmt.params[i], symtab, stmt.body, true);138 }139 processStmt(stmt.body, symtab, stmt.body);140 cleanSymtabDeclaredVars(symtab, stmt.body);141 break;142 case 'EmptyStatement':143 break;144 case 'ExpressionStatement':145 processExpression(stmt.expression, symtab);146 break;147 case 'ReturnStatement':148 if (stmt.argument!==null) {149 processExpression(stmt.argument, symtab);150 }151 break;152 case 'DebuggerStatement':153 break;154 case 'WithStatement':155 exitProgram(stmt.type);156 break;157 case 'LabeledStatement':158 processStmt(stmt.body, symtab, letScope);159 break;160 case 'BreakStatement':161 break;162 case 'ContinueStatement':163 break;164 case 'IfStatement':165 processExpression(stmt.test, symtab);166 processStmt(stmt.consequent, symtab, letScope);167 if (stmt.alternate!==null) {168 processStmt(stmt.alternate, symtab, letScope);169 }170 break;171 case 'SwitchStatement':172 processExpression(stmt.discriminant, symtab);173 for (let i=0; i<stmt.cases.length; i++) {174 if (stmt.cases[i].test!==null) {175 processExpression(stmt.cases[i].test, symtab);176 }177 for (let j=0; j<stmt.cases[i].consequent.length; j++) {178 processStmt(stmt.cases[i].consequent[j], symtab, letScope);179 }180 }181 break;182 case 'ThrowStatement':183 processExpression(stmt.argument, symtab);184 break;185 case 'TryStatement':186 processStmt(stmt.block, symtab, stmt.block);187 if (stmt.handler!==null) {188 initSymtabDeclaredVars(symtab, stmt.handler.body);189 if (stmt.handler.param!==null) {190 processPattern(stmt.handler.param, symtab, stmt.handler.body, true);191 }192 processStmt(stmt.handler.body, symtab, stmt.handler.body);193 cleanSymtabDeclaredVars(symtab, stmt.handler.body);194 }195 if (stmt.finalizer!==null) {196 processStmt(stmt.finalizer, symtab, letScope);197 }198 return;199 case 'WhileStatement':200 processExpression(stmt.test, symtab);201 processStmt(stmt.body, symtab, letScope);202 return;203 case 'DoWhileStatement':204 processStmt(stmt.body, symtab, letScope);205 processExpression(stmt.test, symtab);206 return;207 case 'ForStatement':208 // forstatment declaration is a seperate lex scope209 // only let loopvar will be on this Scope.210 // they do not have chance to outScope access211 initSymtabDeclaredVars(symtab, stmt);212 if (stmt.init===null) {213 } else if (stmt.init.type=='VariableDeclaration') {214 processStmt(stmt.init, symtab, stmt);215 } else {216 processExpression(stmt.init, symtab);217 }218 if (stmt.test!==null) {219 processExpression(stmt.test, symtab);220 }221 if (stmt.update!==null) {222 processExpression(stmt.update, symtab);223 }224 processStmt(stmt.body, symtab, stmt);225 cleanSymtabDeclaredVars(symtab, stmt);226 break;227 case 'ForInStatement':228 case 'ForOfStatement':229 initSymtabDeclaredVars(symtab, stmt);230 if (stmt.left.type=='VariableDeclaration') {231 processStmt(stmt.left, symtab, stmt);232 } else {233 processPattern(stmt.left, symtab, null, false);234 }235 processExpression(stmt.right, symtab);236 processStmt(stmt.body, symtab, stmt);237 cleanSymtabDeclaredVars(symtab, stmt);238 break;239 case 'ClassDeclaration':240 processPattern(stmt.id, symtab, letScope, true);241 if (stmt.superClass!==null) {242 processExpression(stmt.superClass, symtab);243 }244 processClassBody(stmt.body, symtab);245 break;246 case 'ImportDeclaration':247 case 'ExportNamedDeclaration':248 case 'ExportDefaultDeclaration':249 case 'ExportAllDeclaration':250 exitProgram(stmt.type);251 default:252 throw new Error();253 }254 return;255}256/**257 * @param {Node} expression258 * @param {Map[]} symtab259 * @return {undefined}260 */261function processExpression(expression, symtab) {262 switch (expression.type) {263 case 'Identifier':264 processPattern(expression, symtab, null, false);265 break;266 case 'Literal':267 break;268 case 'ThisExpression':269 break;270 case 'ArrayExpression':271 for (let i=0; i<expression.elements.length; i++) {272 if (expression.elements[i]===null) {273 continue;274 } else if (expression.elements[i].type=='SpreadElement') {275 processExpression(expression.elements[i].argument, symtab);276 } else {277 processExpression(expression.elements[i], symtab);278 }279 }280 break;281 case 'ObjectExpression':282 for (let i=0; i<expression.properties.length; i++) {283 if (expression.properties[i].type=='Property') {284 processExpression(expression.properties[i].key, symtab);285 processExpression(expression.properties[i].value, symtab);286 } else {287 processExpression(expression.properties[i].argument, symtab);288 }289 }290 break;291 case 'FunctionExpression':292 initSymtabDeclaredVars(symtab, expression);293 if (expression.id!==null) {294 setSymtab(symtab, expression.id, 'declared', 'inScope');295 }296 initSymtabDeclaredVars(symtab, expression.body);297 for (let i=0; i<expression.params.length; i++) {298 processPattern(expression.params[i], symtab, expression.body, true);299 }300 processStmt(expression.body, symtab, expression.body);301 cleanSymtabDeclaredVars(symtab, expression.body);302 cleanSymtabDeclaredVars(symtab, expression);303 break;304 case 'ArrowFunctionExpression':305 // arrow function may have varsOnscope306 // (a)=>return a;307 if (expression.expression===false) {308 initSymtabDeclaredVars(symtab, expression.body);309 for (let i=0; i<expression.params.length; i++) {310 processPattern(expression.params[i], symtab);311 }312 processStmt(expression.body, symtab, expression.body);313 cleanSymtabDeclaredVars(symtab, expression.body);314 } else {315 initSymtabDeclaredVars(symtab, expression);316 for (let i=0; i<expression.params.length; i++) {317 processPattern(expression.params[i], symtab, expression, true);318 }319 processExpression(expression.body, symtab);320 cleanSymtabDeclaredVars(symtab, expression);321 }322 break;323 case 'TaggedTemplateExpression':324 processExpression(expression.tag, symtab);325 for (let i=0; i<expression.quasi.expressions.length; i++) {326 processExpression(expression.quasi.expressions[i], symtab);327 }328 break;329 case 'TemplateLiteral':330 for (let i=0; i<expression.expressions.length; i++) {331 processExpression(expression.expressions[i], symtab);332 }333 break;334 case 'ChainExpression':335 processExpression(expression.expression, symtab);336 break;337 case 'ImportExpression':338 exitProgram(expression.type);339 break;340 case 'UnaryExpression':341 processExpression(expression.argument, symtab);342 break;343 case 'BinaryExpression':344 processExpression(expression.left, symtab);345 processExpression(expression.right, symtab);346 break;347 case 'AssignmentExpression':348 processPattern(expression.left, symtab, null, false);349 processExpression(expression.right, symtab);350 break;351 case 'LogicalExpression':352 processExpression(expression.left, symtab);353 processExpression(expression.right, symtab);354 break;355 case 'MemberExpression':356 if (expression.object.type!='Super') {357 processExpression(expression.object, symtab);358 }359 if (expression.computed==true) {360 processExpression(expression.property, symtab);361 }362 break;363 case 'ConditionalExpression':364 processExpression(expression.test, symtab);365 processExpression(expression.alternate, symtab);366 processExpression(expression.consequent, symtab);367 break;368 case 'CallExpression':369 if (expression.callee.type!='Super') {370 processExpression(expression.callee, symtab);371 }372 for (let i=0; i<expression.arguments.length; i++) {373 if (expression.arguments[i].type=='SpreadExpression') {374 processExpression(expression.arguments[i].argument, symtab);375 } else {376 processExpression(expression.arguments[i], symtab);377 }378 }379 break;380 case 'NewExpression':381 processExpression(expression.callee, symtab);382 for (let i=0; i<expression.arguments.length; i++) {383 if (expression.arguments[i].type=='SpreadExpression') {384 processExpression(expression.arguments[i].argument, symtab);385 } else {386 processExpression(expression.arguments[i], symtab);387 }388 }389 break;390 case 'SequenceExpression':391 for (let i=0; i<expression.expressions.length; i++) {392 processExpression(expression.expressions[i], symtab);393 }394 break;395 case 'YieldExpression':396 if (expression.argument!==null) {397 processExpression(expression.argument, symtab);398 }399 break;400 case 'AwaitExpression':401 processExpression(expression.argument, symtab);402 break;403 case 'MetaProperty':404 break;405 case 'UpdateExpression':406 processExpression(expression.argument, symtab);407 break;408 case 'SpreadElement':409 processExpression(expression.argument, symtab);410 break;411 case 'ClassExpression':412 initSymtabDeclaredVars(symtab, expression);413 if (expression.id!==null) {414 processPattern(expression.id, symtab, expression, true);415 }416 if (expression.superClass!==null) {417 processExpression(expression.superClass, symtab);418 }419 processClassBody(expression.body, symtab);420 cleanSymtabDeclaredVars(symtab, expression);421 break;422 default:423 throw new Error();424 }425 return;426}427/**428 * @param {Node[]} classbody429 * @param {Map[]} symtab430 * @param {Node}letScope431 * @return {undefined}432 */433function processClassBody(classbody, symtab) {434 for (let i=0; i<classbody.length; i++) {435 if (classbody[i].type=='MethodDefinition') {436 if (classbody[i].key.type!='PrivateIdentifier') {437 exitProgram('class private identifer');438 }439 processExpression(classbody[i].key, symtab);440 processExpression(classbody[i].value, symtab);441 } else {442 exitProgram('Class Property definition');443 }444 }445}446/**447 * @param {Node} pattern448 * @param {Map[]} symtab449 * @param {Node} letScope450 * @param {Boolean} declare451 * @return {undefined}452 * declare=true means declare; false means use453 * if declare false, then letScope is meaningless454 */455function processPattern(pattern, symtab, letScope, declare) {456 switch (pattern.type) {457 case 'Identifier':458 if (!inSymtab(symtab, pattern.name)) {459 break;460 }461 switch (getSymtab(symtab, pattern.name, 'declared')) {462 case undefined:463 if (declare===true) {464 setSymtab(symtab, pattern.name, 'declared', 'inScope');465 letScope.declaredVars.push(pattern.name);466 } else {467 setLoadUndefined(symtab, pattern.name);468 }469 break;470 case 'inScope':471 break;472 case 'outScope':473 setLoadUndefined(symtab, pattern.name);474 break;475 default:476 throw new Error();477 }478 break;479 case 'MemberExpression':480 if (pattern.object.type!='Super') {481 processExpression(pattern.object, symtab);482 }483 if (pattern.computed==true) {484 processExpression(pattern.property, symtab);485 }486 break;487 case 'ObjectPattern':488 for (let i=0; i<pattern.properties.length; i++) {489 switch (pattern.properties[i].type) {490 case 'Property':491 processExpression(pattern.properties[i].key, symtab);492 processPattern(pattern.properties[i].value,493 symtab, letScope, declare);494 break;495 case 'RestElement':496 processPattern(pattern.properties[i].argument,497 symtab, letScope, declare);498 break;499 default:500 throw new Error();501 }502 }503 break;504 case 'ArrayPattern':505 for (let i=0; i<pattern.elements.length; i++) {506 if (pattern.elements[i]===null) continue;507 processPattern(pattern.elements[i], symtab, letScope, declare);508 }509 break;510 case 'RestElement':511 processPattern(pattern.argument, symtab, letScope, declare);512 break;513 case 'AssignmentPattern':514 processPattern(pattern.left, symtab, letScope, declare);515 processExpression(pattern.right, symtab);516 break;517 default:518 throw new Error();519 }520 return;521}522/**523 * @param {Map[]} symtab524 * @param {Node} scope525 * @return {undefined}526 */527function initSymtabDeclaredVars(symtab, scope) {528 symtab.push(scope.varsOnScope);529 scope.declaredVars=[];...

Full Screen

Full Screen

funcDeclSort.js

Source:funcDeclSort.js Github

copy

Full Screen

...46 case 'VariableDeclaration':47 for (let i=0; i<stmt.declarations.length; i++) {48 processPattern(stmt.declarations[i].id, symtab, callStack, false);49 if (stmt.declarations[i].init!==null) {50 processExpression(stmt.declarations[i].init, symtab, callStack);51 }52 }53 break;54 case 'BlockStatement':55 if (stmt.varsOnScope!=symtab[symtab.length-1]) {56 symtab.push(stmt.varsOnScope);57 for (let i=0; i<stmt.body.length; i++) {58 processStmt(stmt.body[i], symtab, callStack);59 }60 sortFuncDecl(stmt, symtab);61 symtab.pop();62 break;63 } else {64 // called from Function declaration/ function exp, etc.65 for (let i=0; i<stmt.body.length; i++) {66 processStmt(stmt.body[i], symtab, callStack);67 }68 sortFuncDecl(stmt, symtab);69 break;70 }71 case 'FunctionDeclaration':72 // be careful about the order: function name symbol is in outer scope;73 // should first find correct func name symbol, then push the inner symtab74 callStack.push(75 [getSymtab(symtab, stmt.id.name, 'declaredIn'), stmt.id.name]);76 symtab.push(stmt.body.varsOnScope);77 for (let i=0; i<stmt.params.length; i++) {78 processPattern(stmt.params[i], symtab, callStack, false);79 }80 processStmt(stmt.body, symtab, callStack);81 callStack.pop();82 symtab.pop();83 break;84 case 'EmptyStatement':85 break;86 case 'ExpressionStatement':87 processExpression(stmt.expression, symtab, callStack);88 break;89 case 'ClassDeclaration':90 processPattern(stmt.id, symtab, callStack, false);91 if (stmt.superClass!==null) {92 processExpression(stmt.superClass, symtab, callStack);93 }94 processClassBody(stmt.body, symtab, callStack);95 break;96 case 'ReturnStatement':97 if (stmt.argument!==null) {98 processExpression(stmt.argument, symtab, callStack);99 }100 break;101 case 'DebuggerStatement':102 break;103 case 'WithStatement':104 exitProgram(stmt.type);105 break;106 case 'LabeledStatement':107 processStmt(stmt.body, symtab, callStack);108 break;109 case 'BreakStatement':110 break;111 case 'ContinueStatement':112 break;113 case 'IfStatement':114 processExpression(stmt.test, symtab, callStack);115 processStmt(stmt.consequent, symtab, callStack);116 if (stmt.alternate!==null) {117 processStmt(stmt.alternate, symtab, callStack);118 }119 break;120 case 'SwitchStatement':121 processExpression(stmt.discriminant, symtab, callStack);122 for (let i=0; i<stmt.cases.length; i++) {123 if (stmt.cases[i].test!==null) {124 processExpression(stmt.cases[i].test, symtab, callStack);125 }126 for (let j=0; j<stmt.cases[i].consequent.length; j++) {127 processStmt(stmt.cases[i].consequent[j], symtab, callStack);128 }129 }130 break;131 case 'ThrowStatement':132 processExpression(stmt.argument, symtab, callStack);133 break;134 case 'TryStatement':135 processStmt(stmt.block, symtab, callStack);136 if (stmt.handler!==null) {137 symtab.push(stmt.handler.body.varsOnScope);138 if (stmt.handler.param!==null) {139 processPattern(stmt.handler.param, symtab, callStack, false);140 }141 processStmt(stmt.handler.body, symtab, callStack);142 symtab.pop();143 }144 if (stmt.finalizer!==null) {145 processStmt(stmt.finalizer, symtab, callStack);146 }147 return;148 case 'WhileStatement':149 processExpression(stmt.test, symtab, callStack);150 processStmt(stmt.body, symtab, callStack);151 return;152 case 'DoWhileStatement':153 processStmt(stmt.body, symtab, callStack);154 processExpression(stmt.test, symtab, callStack);155 return;156 case 'ForStatement':157 symtab.push(stmt.varsOnScope);158 if (stmt.init===null) {159 } else if (stmt.init.type=='VariableDeclaration') {160 processStmt(stmt.init, symtab, callStack);161 } else {162 processExpression(stmt.init, symtab, callStack);163 }164 if (stmt.test!==null) {165 processExpression(stmt.test, symtab, callStack);166 }167 if (stmt.update!==null) {168 processExpression(stmt.update, symtab, callStack);169 }170 processStmt(stmt.body, symtab, callStack);171 symtab.pop();172 break;173 case 'ForInStatement':174 case 'ForOfStatement':175 symtab.push(stmt.varsOnScope);176 if (stmt.left.type=='VariableDeclaration') {177 processStmt(stmt.left, symtab, callStack);178 } else {179 processPattern(stmt.left, symtab, callStack, true);180 }181 processExpression(stmt.right, symtab, callStack);182 processStmt(stmt.body, symtab, callStack);183 symtab.pop();184 break;185 // technically, import declaration is not a stmt186 case 'ImportDeclaration':187 case 'ExportNamedDeclaration':188 case 'ExportDefaultDeclaration':189 case 'ExportAllDeclaration':190 exitProgram(stmt.type);191 default:192 throw new Error();193 }194 return;195}196/**197 * @param {Node} expression198 * @param {Map[]} symtab199 * @param {[]} callStack200 * @return {undefined}201 */202function processExpression(expression, symtab, callStack) {203 switch (expression.type) {204 case 'Identifier':205 processPattern(expression, symtab, callStack, true);206 break;207 case 'Literal':208 break;209 case 'ThisExpression':210 break;211 case 'ArrayExpression':212 for (let i=0; i<expression.elements.length; i++) {213 if (expression.elements[i]===null) {214 continue;215 } else if (expression.elements[i].type=='SpreadElement') {216 processExpression(expression.elements[i].argument, symtab, callStack);217 } else {218 processExpression(expression.elements[i], symtab, callStack);219 }220 }221 break;222 case 'ObjectExpression':223 for (let i=0; i<expression.properties.length; i++) {224 if (expression.properties[i].type=='Property') {225 processExpression(expression.properties[i].key, symtab, callStack);226 processExpression(expression.properties[i].value, symtab, callStack);227 } else {228 processExpression(expression.properties[i].argument,229 symtab, callStack);230 }231 }232 break;233 case 'FunctionExpression':234 symtab.push(expression.varsOnScope);235 symtab.push(expression.body.varsOnScope);236 for (let i=0; i<expression.params.length; i++) {237 processPattern(expression.params[i], symtab, callStack, false);238 }239 processStmt(expression.body, symtab, callStack);240 symtab.pop();241 symtab.pop();242 break;243 case 'ArrowFunctionExpression':244 if (expression.expression===false) {245 symtab.push(expression.body.varsOnScope);246 for (let i=0; i<expression.params.length; i++) {247 processPattern(expression.params[i], symtab, callStack, false);248 }249 if (expression.id!==null) {250 throw new Error();251 }252 processStmt(expression.body, symtab, callStack);253 symtab.pop();254 } else {255 symtab.push(expression.varsOnScope);256 for (let i=0; i<expression.params.length; i++) {257 processPattern(expression.params[i], symtab, callStack, false);258 }259 if (expression.id!==null) {260 throw new Error();261 }262 processExpression(expression.body, symtab, callStack);263 symtab.pop();264 }265 break;266 case 'ClassExpression':267 symtab.push(expression.varsOnScope);268 if (expression.superClass!==null) {269 processExpression(expression.superClass, symtab, callStack);270 }271 processClassBody(expression.body);272 symtab.pop();273 break;274 case 'TaggedTemplateExpression':275 processExpression(expression.tag, symtab, callStack);276 for (let i=0; i<expression.quasi.expressions.length; i++) {277 processExpression(expression.quasi.expressions[i], symtab, callStack);278 }279 break;280 case 'TemplateLiteral':281 for (let i=0; i<expression.expressions.length; i++) {282 processExpression(expression.expressions[i], symtab, callStack);283 }284 break;285 case 'ChainExpression':286 processExpression(expression.expression, symtab, callStack);287 break;288 case 'ImportExpression':289 exitProgram(expression.type);290 break;291 case 'UnaryExpression':292 processExpression(expression.argument, symtab, callStack);293 break;294 case 'BinaryExpression':295 processExpression(expression.left, symtab, callStack);296 processExpression(expression.right, symtab, callStack);297 break;298 case 'AssignmentExpression':299 processPattern(expression.left, symtab, callStack, true);300 processExpression(expression.right, symtab, callStack);301 break;302 case 'LogicalExpression':303 processExpression(expression.left, symtab, callStack);304 processExpression(expression.right, symtab, callStack);305 break;306 case 'MemberExpression':307 if (expression.object.type!='Super') {308 processExpression(expression.object, symtab, callStack);309 }310 if (expression.computed==true) {311 processExpression(expression.property, symtab, callStack);312 }313 break;314 case 'ConditionalExpression':315 processExpression(expression.test, symtab, callStack);316 processExpression(expression.alternate, symtab, callStack);317 processExpression(expression.consequent, symtab, callStack);318 break;319 case 'CallExpression':320 if (expression.callee.type!='Super') {321 processExpression(expression.callee, symtab, callStack);322 }323 for (let i=0; i<expression.arguments.length; i++) {324 if (expression.arguments[i].type=='SpreadExpression') {325 processExpression(expression.arguments[i].argument,326 symtab, callStack);327 } else {328 processExpression(expression.arguments[i], symtab, callStack);329 }330 }331 break;332 case 'NewExpression':333 processExpression(expression.callee, symtab, callStack);334 for (let i=0; i<expression.arguments.length; i++) {335 if (expression.arguments[i].type=='SpreadExpression') {336 processExpression(expression.arguments[i].argument,337 symtab, callStack);338 } else {339 processExpression(expression.arguments[i], symtab, callStack);340 }341 }342 break;343 case 'SequenceExpression':344 for (let i=0; i<expression.expressions.length; i++) {345 processExpression(expression.expressions[i], symtab, callStack);346 }347 break;348 case 'YieldExpression':349 if (expression.argument!==null) {350 processExpression(expression.argument, symtab, callStack);351 }352 break;353 case 'AwaitExpression':354 processExpression(expression.argument, symtab, callStack);355 break;356 case 'MetaProperty':357 break;358 case 'UpdateExpression':359 processExpression(expression.argument, symtab, callStack);360 break;361 case 'SpreadElement':362 processExpression(expression.argument, symtab, callStack);363 break;364 default:365 throw new Error();366 }367 return;368}369/**370 * @param {Node[]} classbody371 * @param {Map[]} symtab372 * @param {Node}letScope373 * @return {undefined}374 */375function processClassBody(classbody, symtab) {376 for (let i=0; i<classbody.length; i++) {377 if (classbody[i].type=='MethodDefinition') {378 if (classbody[i].key.type!='PrivateIdentifier') {379 exitProgram('class private identifer');380 }381 processExpression(classbody[i].key, symtab, callStack);382 processExpression(classbody[i].value, symtab, callStack);383 } else {384 exitProgram('Class Property definition');385 }386 }387}388/**389 * @param {Node} symtab390 * @param {string} variable391 * @param {string} key392 * @return {String|Map}393 */394function getSymtab(symtab, variable, key) {395 for (let i=symtab.length-1; i>=0; i--) {396 if (symtab[i].has(variable)) {397 if (key==undefined) {398 return symtab[i].get(variable);399 } else {400 return symtab[i].get(variable).get(key);401 }402 }403 }404}405/**406 * @param {Node} pattern407 * @param {Node} symtab408 * @param {[String]} callStack409 * @param {Boolean} use410 * @return {undefined}411 */412function processPattern(pattern, symtab, callStack, use) {413 switch (pattern.type) {414 case 'Identifier':415 calleeProperties=getSymtab(symtab, pattern.name);416 if (calleeProperties!==undefined&&417 calleeProperties.get('type')=='func'&&use) {418 for (const [callerScope, callerName] of callStack) {419 if (callerScope==calleeProperties.get('declaredIn')) {420 callerScope.get(callerName).push(pattern.name);421 }422 }423 }424 break;425 case 'MemberExpression':426 if (pattern.object.type!='Super') {427 processExpression(pattern.object, symtab, callStack);428 }429 if (pattern.computed==true) {430 processExpression(pattern.property, symtab, callStack);431 }432 break;433 case 'ObjectPattern':434 for (let i=0; i<pattern.properties.length; i++) {435 switch (pattern.properties[i].type) {436 case 'Property':437 processExpression(pattern.properties[i].key, symtab, callStack);438 processPattern(pattern.properties[i].value, symtab, callStack, use);439 break;440 case 'RestElement':441 processPattern(pattern.properties[i].argument,442 symtab, callStack, use);443 break;444 default:445 throw new Error();446 }447 }448 break;449 case 'ArrayPattern':450 for (let i=0; i<pattern.elements.length; i++) {451 if (pattern.elements[i]===null) continue;452 processPattern(pattern.elements[i], symtab, callStack, use);453 }454 break;455 case 'RestElement':456 processPattern(pattern.argument, symtab, callStack, use);457 break;458 case 'AssignmentPattern':459 processPattern(pattern.left, symtab, callStack, use);460 processExpression(pattern.right, symtab, callStack);461 break;462 default:463 throw new Error();464 }465 return;466}467/**468 * @param {Node} node469 * @param {Map[]} symtab470 * @return {undefined}471 */472function sortFuncDecl(node, symtab) {473 const toAddLoadUndefined=[];474 const visited=[];...

Full Screen

Full Screen

identifierAnalysis.js

Source:identifierAnalysis.js Github

copy

Full Screen

...27 switch (stmt.type) {28 case 'VariableDeclaration':29 for (let i=0; i<stmt.declarations.length; i++) {30 if (stmt.declarations[i].init!==null) {31 processExpression(stmt.declarations[i].init, []);32 }33 processPattern(stmt.declarations[i].id);34 }35 break;36 case 'BlockStatement':37 for (let i=0; i<stmt.body.length; i++) {38 processStmt(stmt.body[i]);39 }40 break;41 case 'FunctionDeclaration':42 for (let i=0; i<stmt.params.length; i++) {43 processPattern(stmt.params[i]);44 }45 processStmt(stmt.body);46 break;47 case 'EmptyStatement':48 break;49 case 'ExpressionStatement':50 processExpression(stmt.expression, []);51 break;52 case 'ReturnStatement':53 if (stmt.argument!==null) {54 processExpression(stmt.argument, []);55 }56 break;57 case 'DebuggerStatement':58 break;59 case 'WithStatement':60 exitProgram(stmt.type);61 break;62 case 'LabeledStatement':63 processStmt(stmt.body);64 break;65 case 'BreakStatement':66 break;67 case 'ContinueStatement':68 break;69 case 'IfStatement':70 processExpression(stmt.test, []);71 processStmt(stmt.consequent);72 if (stmt.alternate!==null) {73 processStmt(stmt.alternate);74 }75 break;76 case 'SwitchStatement':77 processExpression(stmt.discriminant, []);78 for (let i=0; i<stmt.cases.length; i++) {79 if (stmt.cases[i].test!==null) {80 processExpression(stmt.cases[i].test, []);81 }82 for (let j=0; j<stmt.cases[i].consequent.length; j++) {83 processStmt(stmt.cases[i].consequent[j]);84 }85 }86 break;87 case 'ThrowStatement':88 processExpression(stmt.argument, []);89 break;90 case 'TryStatement':91 processStmt(stmt.block);92 if (stmt.handler!==null) {93 if (stmt.handler.param!==null) {94 processPattern(stmt.handler.param);95 }96 processStmt(stmt.handler.body);97 }98 if (stmt.finalizer!==null) {99 processStmt(stmt.finalizer);100 }101 return;102 case 'WhileStatement':103 processExpression(stmt.test, []);104 processStmt(stmt.body);105 return;106 case 'DoWhileStatement':107 processStmt(stmt.body);108 processExpression(stmt.test, []);109 return;110 case 'ForStatement':111 if (stmt.init===null) {112 } else if (stmt.init.type=='VariableDeclaration') {113 processStmt(stmt.init);114 } else {115 processExpression(stmt.init, []);116 }117 if (stmt.test!==null) {118 processExpression(stmt.test, []);119 }120 if (stmt.update!==null) {121 processExpression(stmt.update, []);122 }123 processStmt(stmt.body);124 break;125 case 'ForInStatement':126 case 'ForOfStatement':127 if (stmt.left.type=='VariableDeclaration') {128 processStmt(stmt.left);129 } else {130 processPattern(stmt.left);131 }132 processExpression(stmt.right, []);133 processStmt(stmt.body);134 break;135 case 'ClassDeclaration':136 processPattern(stmt.id);137 if (stmt.superClass!==null) {138 processExpression(stmt.superClass, []);139 }140 processClassBody(stmt.body);141 break;142 case 'ImportDeclaration':143 case 'ExportNamedDeclaration':144 case 'ExportDefaultDeclaration':145 case 'ExportAllDeclaration':146 exitProgram(stmt.type);147 default:148 throw new Error();149 }150 return;151}152/**153 * @param {Node} expression154 * @param {[]} identifierTab155 * identifierTab: [[IdentifierNode,...],...]156 * if there is something that may change the value of identifier in a expression157 * like a+func() ; mark previous identifier as dup158 * @return {undefined}159 */160function processExpression(expression, identifierTab) {161 switch (expression.type) {162 case 'Identifier':163 if (identifierTab.length==0) {164 break;165 }166 identifierTab[identifierTab.length-1].push(expression);167 break;168 case 'Literal':169 break;170 case 'ThisExpression':171 break;172 case 'ArrayExpression':173 identifierTab.push([]);174 for (let i=0; i<expression.elements.length; i++) {175 if (expression.elements[i]===null) {176 continue;177 } else if (expression.elements[i].type=='SpreadElement') {178 processExpression(expression.elements[i].argument, identifierTab);179 } else {180 processExpression(expression.elements[i], identifierTab);181 }182 }183 identifierTab.pop();184 break;185 case 'ObjectExpression':186 identifierTab.push([]);187 for (let i=0; i<expression.properties.length; i++) {188 if (expression.properties[i].type=='Property') {189 processExpression(expression.properties[i].key, identifierTab);190 processExpression(expression.properties[i].value, identifierTab);191 } else {192 processExpression(expression.properties[i].argument, identifierTab);193 }194 }195 identifierTab.pop();196 break;197 case 'FunctionExpression':198 identifierTab.push([]);199 for (let i=0; i<expression.params.length; i++) {200 processPattern(expression.params[i]);201 }202 processStmt(expression.body);203 identifierTab.pop();204 break;205 case 'ArrowFunctionExpression':206 identifierTab.push([]);207 for (let i=0; i<expression.params.length; i++) {208 processPattern(expression.params[i]);209 }210 if (expression.expression===false) {211 processStmt(expression.body);212 } else {213 processExpression(expression.body, []);214 }215 identifierTab.pop();216 break;217 case 'CallExpression':218 identifierTab.push([]);219 if (expression.callee.type!='Super') {220 processExpression(expression.callee, identifierTab);221 }222 for (let i=0; i<expression.arguments.length; i++) {223 if (expression.arguments[i].type=='SpreadExpression') {224 processExpression(expression.arguments[i].argument, identifierTab);225 } else {226 processExpression(expression.arguments[i], identifierTab);227 }228 }229 identifierTab.pop();230 dupEverything(identifierTab);231 break;232 case 'TaggedTemplateExpression':233 identifierTab.push([]);234 processExpression(expression.tag, identifierTab);235 for (let i=0; i<expression.quasi.expressions.length; i++) {236 processExpression(expression.quasi.expressions[i], identifierTab);237 }238 identifierTab.pop();239 dupEverything(identifierTab);240 break;241 case 'TemplateLiteral':242 identifierTab.push([]);243 for (let i=0; i<expression.expressions.length; i++) {244 processExpression(expression.expressions[i], identifierTab);245 }246 identifierTab.pop();247 break;248 case 'ChainExpression':249 identifierTab.push([]);250 processExpression(expression.expression, identifierTab);251 identifierTab.pop();252 break;253 case 'ImportExpression':254 exitProgram(expression.type);255 break;256 case 'UnaryExpression':257 identifierTab.push([]);258 processExpression(expression.argument, identifierTab);259 identifierTab.pop();260 if (expression.operator=='-'||expression.operator=='+'||261 expression.operator=='~'||expression.operator=='delete') {262 // this will call valueOf of a object263 // delete can be trap by proxy264 dupEverything(identifierTab);265 }266 break;267 case 'BinaryExpression':268 identifierTab.push([]);269 processExpression(expression.left, identifierTab);270 processExpression(expression.right, identifierTab);271 identifierTab.pop();272 if (expression.operator!='==='||expression.operator=='!=='||273 expression.operator=='instanceof') {274 // others will call toString or valueof275 dupEverything(identifierTab);276 }277 break;278 case 'AssignmentExpression':279 if (expression.operator=='=') {280 identifierTab.push([]);281 processPattern(expression.left);282 processExpression(expression.right, identifierTab);283 identifierTab.pop();284 // x * (x=1)285 // actually only need to dup the lhs of the assignExpression286 // currently we dup everything.287 // Will change that in the future.288 dupEverything(identifierTab);289 break;290 } else {291 identifierTab.push([]);292 processExpression(expression.left, identifierTab);293 processExpression(expression.right, identifierTab);294 identifierTab.pop();295 // a += ++a296 dupEverything(identifierTab);297 }298 break;299 case 'LogicalExpression':300 identifierTab.push([]);301 processExpression(expression.left, identifierTab);302 processExpression(expression.right, identifierTab);303 identifierTab.pop();304 break;305 case 'MemberExpression':306 identifierTab.push([]);307 if (expression.object.type!='Super') {308 processExpression(expression.object, identifierTab);309 }310 if (expression.computed==true) {311 processExpression(expression.property, identifierTab);312 }313 identifierTab.pop();314 dupEverything(identifierTab);315 // getter can be a function call316 break;317 case 'ConditionalExpression':318 identifierTab.push([]);319 processExpression(expression.test, identifierTab);320 processExpression(expression.alternate, identifierTab);321 processExpression(expression.consequent, identifierTab);322 identifierTab.pop();323 break;324 case 'NewExpression':325 identifierTab.push([]);326 processExpression(expression.callee, identifierTab);327 for (let i=0; i<expression.arguments.length; i++) {328 if (expression.arguments[i].type=='SpreadExpression') {329 processExpression(expression.arguments[i].argument, identifierTab);330 } else {331 processExpression(expression.arguments[i], identifierTab);332 }333 }334 identifierTab.pop();335 dupEverything(identifierTab);336 break;337 case 'SequenceExpression':338 identifierTab.push([]);339 for (let i=0; i<expression.expressions.length; i++) {340 processExpression(expression.expressions[i], identifierTab);341 }342 identifierTab.pop();343 break;344 case 'YieldExpression':345 identifierTab.push([]);346 if (expression.argument!==null) {347 processExpression(expression.argument, identifierTab);348 }349 identifierTab.pop();350 break;351 case 'AwaitExpression':352 identifierTab.push([]);353 processExpression(expression.argument, identifierTab);354 identifierTab.pop();355 break;356 case 'MetaProperty':357 break;358 case 'UpdateExpression':359 identifierTab.push([]);360 processExpression(expression.argument, identifierTab);361 identifierTab.pop();362 dupEverything(identifierTab);363 break;364 case 'SpreadElement':365 identifierTab.push([]);366 processExpression(expression.argument, identifierTab);367 identifierTab.pop();368 break;369 case 'ClassExpression':370 identifierTab.push([]);371 if (expression.id!==null) {372 processPattern(expression.id);373 }374 if (expression.superClass!==null) {375 processExpression(expression.superClass, identifierTab);376 }377 processClassBody(expression.body);378 identifierTab.pop();379 break;380 default:381 throw new Error();382 }383 return;384}385/**386 * @param {[]} identifierTab387 * @return {undefined}388 */389function dupEverything(identifierTab) {390 for (const tab of identifierTab) {391 for (const node of tab) {392 node.dup=true;393 }394 }395}396/**397 * @param {Node[]} classbody398 * @return {undefined}399 */400function processClassBody(classbody) {401 for (let i=0; i<classbody.length; i++) {402 if (classbody[i].type=='MethodDefinition') {403 if (classbody[i].key.type!='PrivateIdentifier') {404 exitProgram('class private identifer');405 }406 processExpression(classbody[i].key, []);407 processExpression(classbody[i].value, []);408 } else {409 exitProgram('Class Property definition');410 }411 }412}413/**414 * @param {Node} pattern415 * @return {undefined}416 */417function processPattern(pattern) {418 switch (pattern.type) {419 case 'Identifier':420 break;421 case 'MemberExpression':422 if (pattern.object.type!='Super') {423 processExpression(pattern.object, []);424 }425 if (pattern.computed==true) {426 processExpression(pattern.property, []);427 }428 break;429 case 'ObjectPattern':430 for (let i=0; i<pattern.properties.length; i++) {431 switch (pattern.properties[i].type) {432 case 'Property':433 processExpression(pattern.properties[i].key, []);434 processPattern(pattern.properties[i].value);435 break;436 case 'RestElement':437 processPattern(pattern.properties[i].argument);438 break;439 default:440 throw new Error();441 }442 }443 break;444 case 'ArrayPattern':445 for (let i=0; i<pattern.elements.length; i++) {446 if (pattern.elements[i]===null) continue;447 processPattern(pattern.elements[i]);448 }449 break;450 case 'RestElement':451 processPattern(pattern.argument);452 break;453 case 'AssignmentPattern':454 processPattern(pattern.left);455 processExpression(pattern.right, []);456 break;457 default:458 throw new Error();459 }460 return;461}462/**463 * @param {string} type464 * @return {undefined}465 */466function exitProgram(type) {467 console.log('Not Supported: '+type);468 process.exit(139);469}

Full Screen

Full Screen

class-compiler.js

Source:class-compiler.js Github

copy

Full Screen

...156 return block;157}158function processAssignmentExpression(assignment, options) {159 const expression = assignment.expression;160 expression.left = processExpression(expression.left, options);161 expression.right = processExpression(expression.right, options);162 return assignment;163}164function processUpdateExpression(element, options) {165 element.expression.argument = processExpression(166 element.expression.argument,167 options168 );169 return element;170}171function processReturnStatement(returnStatement, options) {172 returnStatement.argument = processExpression(173 returnStatement.argument,174 options175 );176 return returnStatement;177}178function getTopOfMemberExpression(memberExpression) {179 if (n.MemberExpression.check(memberExpression.object)) {180 return [181 ...getTopOfMemberExpression(memberExpression.object),182 memberExpression,183 ];184 } else {185 return [memberExpression];186 }187}188function processCallExpression(callExpression, options) {189 if (n.MemberExpression.check(callExpression.expression.callee)) {190 const [member] = getTopOfMemberExpression(callExpression.expression.callee);191 if (192 n.ThisExpression.check(member.object) &&193 !options.classMethods.includes(member.property.name)194 ) {195 if (member.property.name === 'template') {196 member.property.name = 'template.current';197 } else if (198 member.property.name === 'addEventListener' ||199 member.property.name === 'removeEventListener' ||200 member.property.name === 'dispatchEvent'201 ) {202 callExpression.expression.callee = b.identifier(203 'this.template.current.' + member.property.name204 );205 } else {206 callExpression.expression.callee = processExpression(207 callExpression.expression.callee,208 options209 );210 }211 }212 const lifeCycleMap = {213 renderedCallback: 'componentDidUpdate',214 connectedCallback: 'componentDidMount',215 errorCallback: 'componentDidCatch',216 disconnectedCallback: 'componentWillUnmount',217 };218 if (lifeCycleMap.hasOwnProperty(member.property.name)) {219 member.property.name = lifeCycleMap[member.property.name];220 }221 }222 callExpression.expression.arguments = callExpression.expression.arguments.map(223 (arg) => processExpression(arg, options)224 );225 return callExpression;226}227function processVariableDeclaration(element, options) {228 for (let i = 0; i < element.declarations.length; i++) {229 const declaration = element.declarations[i];230 element.declarations[i] = processExpression(231 element.declarations[i],232 options233 );234 if (n.VariableDeclarator.check(declaration)) {235 element.declarations[i] = b.variableDeclarator(236 declaration.id,237 processExpression(declaration.init, options)238 );239 }240 }241 return element;242}243function processExpression(expression, options) {244 if (n.MemberExpression.check(expression)) {245 let [top, next, ...rest] = getTopOfMemberExpression(expression);246 if (top.property.name === 'template') {247 if (next.property.name !== 'host') {248 // only add member if it is not "host"249 rest = [next, ...rest];250 }251 return b.identifier(252 `this.template.current.${rest.map((e) => e.property.name).join('.')}`253 );254 } else if (n.ThisExpression.check(expression.object)) {255 return b.identifier(`this.__s.${expression.property.name}`);256 } else if (n.MemberExpression.check(expression.object)) {257 expression.object = processExpression(expression.object, options);258 return expression;259 }260 }261 if (n.CallExpression.check(expression)) {262 return processCallExpression({ expression }, options).expression;263 }264 if (n.UpdateExpression.check(expression)) {265 expression.argument = processExpression(expression.argument, options);266 return expression;267 }268 if (n.BinaryExpression.check(expression)) {269 expression.left = processExpression(expression.left, options);270 expression.right = processExpression(expression.right, options);271 return expression;272 }273 if (n.ConditionalExpression.check(expression)) {274 expression.test = processExpression(expression.test, options);275 expression.consequent = processExpression(expression.consequent, options);276 expression.alternate = processExpression(expression.alternate, options);277 }278 if (n.ObjectExpression.check(expression)) {279 expression.properties.forEach((property) => {280 property.key = processExpression(property.key);281 property.value = processExpression(property.value);282 });283 }284 return expression;285}286function processForLoop(element, options) {287 element.test = processExpression(element.test, options);288 element.init = processVariableDeclaration(element.init, options);289 element.update = processExpression(element.update, options);290 element.body = n.BlockStatement.check(element.body)291 ? processBlock(element.body, options)292 : processExpression(element.body, options);293 return element;294}295function processForOfLoop(element, options) {296 element.left = processVariableDeclaration(element.left, options);297 element.right = processExpression(element.right, options);298 element.body = n.BlockStatement.check(element.body)299 ? processBlock(element.body, options)300 : processExpression(element.body, options);301 return element;302}303function processIfStatement(element, options) {304 element.test = processExpression(element.test, options);305 element.consequent = n.BlockStatement.check(element.consequent)306 ? processBlock(element.consequent, options)307 : processExpression(element.consequent, options);308 if (element.alternate) {309 element.alternate = n.BlockStatement.check(element.alternate)310 ? processBlock(element.alternate, options)311 : processExpression(element.alternate, options);312 }313 return element;314}315function processElement(element, options) {316 if (n.ExpressionStatement.check(element)) {317 if (n.AssignmentExpression.check(element.expression)) {318 return processAssignmentExpression(element, options);319 }320 if (n.UpdateExpression.check(element.expression)) {321 return processUpdateExpression(element, options);322 }323 if (n.CallExpression.check(element.expression)) {324 return processCallExpression(element, options);325 }...

Full Screen

Full Screen

compiler.js

Source:compiler.js Github

copy

Full Screen

...23 for (let variable of assignment.variables) {24 if (scope[variable.value]) {25 throw new CompileError(`Variable '${variable.value}' is already defined`)26 }27 const regex = processExpression(assignment.value, variable, tree, scope, counter);28 if (regex === '') {29 throw new CompileError(`Variable '${variable.value}' has no value`)30 }31 if (variable.visible) {32 scope[variable.value] = `(?<${variable.value}_${counter.value++}>${regex})`33 } else {34 scope[variable.value] = `(?:${regex})`35 }36 }37 }38 return scope39}40function processExpression(expression, variable, tree, scope, counter, regex = '') {41 if (Array.isArray(expression)) {42 for (let expr of expression) {43 regex = processExpression(expr, variable, tree, scope, counter, regex)44 }45 return regex46 }47 if (expression.type === 'expression') {48 regex = processExpression(expression.value, variable, tree, scope, counter, regex)49 return regex50 }51 if (expression.type === 'string') {52 regex = `${regex}${escapeRegExp(expression.value)}`53 } else if (expression.type === 'regex') {54 try {55 new RegExp(expression.value)56 } catch (err) {57 throw new CompileError(err.message)58 }59 regex = `${regex}${expression.value}`60 } else if (expression.type === 'variable') {61 const assignment = tree.find(assignment => assignment.variables.find(variable => variable.value === expression.value))62 if (!assignment) {63 throw new CompileError(`Variable '${expression.value}' is not defined`)64 }65 const v = assignment.variables.find(variable => variable.value === expression.value)66 if (!v) {67 throw new CompileError(`Variable '${expression.value}' is not defined`)68 }69 if (v.visible) {70 regex = `${regex}(?<${expression.value}_${counter.value++}>${processExpression(assignment.value, v, tree, scope, counter)})`71 } else {72 regex = `${regex}(?:${processExpression(assignment.value, v, tree, scope, counter)})`73 }74 } else if (expression.type === 'dot') {75 regex = `${regex}(?:${expression.value.map(e => processExpression(e, variable, tree, scope, counter)).join('\\s*\\b')})`76 } else if (expression.type === 'semicolon') {77 regex = `${regex}(?:${expression.value.map(e => processExpression(e, variable, tree, scope, counter)).join('|')})`78 } else if (expression.type === 'comma') {79 regex = `${regex}(?:(?:${expression.value.map(e => processExpression(e, variable, tree, scope, counter)).join('|')})\\s*\\b)+`80 } else if (expression.type === 'label') {81 regex = `${regex}(?<${expression.label}_${counter.value++}>${processExpression(expression.value, variable, tree, scope, counter)})`82 } else if (expression.type === 'questionmark') {83 regex = `${regex}(?:${processExpression(expression.value, variable, tree, scope, counter)}){0,1}`84 }85 return regex86}87const reRegExpChar = /[\\^$.*+?()[\]{}|]/g88const reHasRegExpChar = RegExp(reRegExpChar.source)89function escapeRegExp(string) {90 return (string && reHasRegExpChar.test(string)) ? string.replace(reRegExpChar, '\\$&') : (string || '')91}...

Full Screen

Full Screen

processor.js

Source:processor.js Github

copy

Full Screen

...5const functionRE = /^\s*([\w.]+)\(/;6const conditionRE = /([\s\S]+(?= if )) if ([\s\S]+(?= else )|[\s\S]+)(?: else ([\s\S]+))?/;7module.exports = {8 variable(el) {9 processExpression(el.text, el);10 if (functionRE.test(el.text)) {11 el.method = RegExp.$1;12 }13 },14 // a hook for custom comment processor15 comment(el) {16 el.text = '';17 },18 // a hook for custom text processor19 text() {},20 for(el) {21 if (!forTagRE.test(el.text)) {22 utils.throw('parse error, for expression invalid', el);23 }24 el.value = RegExp.$1;25 el.index = RegExp.$2;26 processExpression(RegExp.$3, el);27 },28 if(el) {29 if (!el.text) {30 utils.throw('parse error, if condition invalid', el);31 }32 processExpression(el.text, el);33 },34 else(el) {35 const ifEl = getIfEl(el);36 ifEl.elseBlock = el;37 },38 elseif(el) {39 if (!el.text) {40 utils.throw('parse error, elseif condition invalid', el);41 }42 if (el.parent && el.parent.else) {43 utils.throw('parse error, else behind elseif', el);44 }45 const ifEl = getIfEl(el);46 ifEl.elseifBlock = ifEl.elseifBlock || [];47 ifEl.elseifBlock.push(el);48 processExpression(el.text, el);49 },50 elif(el) {51 this.elseif(el);52 },53 set(el) {54 if (!el.text) {55 utils.throw('parse error, set expression invalid', el);56 }57 const index = el.text.indexOf('=');58 el.key = el.text.slice(0, index).trim();59 el.isUnary = true;60 processExpression(el.text.slice(index + 1), el);61 },62 raw() {},63 filter(el) {64 if (!el.text) {65 return utils.throw('parse error, filter function not found', el);66 }67 processExpression(`_$o._$r | ${el.text}`, el);68 },69 import(el) {70 if (!el.text) {71 return utils.throw('parse error, import url not found', el);72 }73 const expArr = el.text.split(' as ');74 processExpression(expArr[0], el);75 el.item = expArr[1] && expArr[1].trim();76 el.isUnary = true;77 },78 macro(el) {79 if (!el.text) {80 return utils.throw('parse error, macro name was needed', el);81 }82 el.isAlone = true;83 const result = parser.parseMacroExpr(el.text);84 el._ast.macro.set(result.methodName, el);85 el.genRender = result.genRender;86 },87 extends(el) {88 if (!el.text) {89 utils.throw('parse error, extends url invalid', el);90 }91 el.isUnary = el.isAlone = true;92 processExpression(el.text, el);93 el._ast.extends = el;94 },95 block(el) {96 if (!el.text) {97 utils.throw('parse error, block name invalid', el);98 }99 el.name = el.text;100 el._ast.blocks = el._ast.blocks || new Map();101 el._ast.blocks.set(el.name, el);102 },103 include(el) {104 if (!el.text) {105 utils.throw('parse error, include url invalid', el);106 }107 el.isUnary = true;108 try {109 el.attrFunc = parser.parseAttr(el.text, '_url');110 } catch (e) {111 utils.throw(e.message, el);112 }113 },114 custom(el, extra) {115 el.isCustom = true;116 el.render = extra.render;117 el.isUnary = extra.unary;118 if (el.text && !extra.noAttr) {119 try {120 el.attrFunc = parser.parseAttr(el.text, extra.attrName);121 } catch (e) {122 utils.throw(e.message, el);123 }124 }125 },126};127function getIfEl(el) {128 const ifEl = el.parent ? (el.parent.ifBlock || el.parent) : null;129 if (!ifEl) {130 utils.throw('parse error, if block not found', el);131 }132 el.ifBlock = el.parent = ifEl;133 el.isAlone = true;134 return ifEl;135}136function processExpression(expr, el) {137 if (expr.indexOf(' if ') >= 0) {138 expr = expr.replace(139 conditionRE,140 (all, res, cond, res2) => `${cond}?${res}:${res2 || '""'}`141 );142 }143 try {144 Object.assign(el, parser.parseCommonExpr(expr));145 } catch (e) {146 utils.throw(e.message, el);147 }...

Full Screen

Full Screen

SymbolTable.js

Source:SymbolTable.js Github

copy

Full Screen

...20 }21 process(statements) {22 for (let statement of statements) {23 if (statement instanceof Assignment) {24 this.variables[statement.variable.name] = this.processExpression(statement.expression);25 if (statement.expression instanceof Literal) {26 this.symbols[statement.variable.name] = statement.expression.value;27 this.size++;28 }29 }30 }31 this.main = this.variables.main;32 if (!this.main) {33 throw new Error('No main variable declaration found');34 }35 }36 processExpression(expr) {37 // Process children38 for (let key in expr) {39 if (expr[key] instanceof Node) {40 expr[key] = this.processExpression(expr[key]);41 }42 }43 // Replace variable references with their values44 if (expr instanceof Variable) {45 let value = this.variables[expr.name];46 if (value == null)47 throw new Error(`Undeclared indentifier ${expr.name}`);48 expr = this.processExpression(value.copy());49 }50 return expr;51 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { processExpression } = require('@playwright/test/lib/server/frames');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const element = await page.$('text=Get started');5 const handle = await element.asElement();6 const result = await processExpression('this.textContent', handle, false);7 console.log(result.value);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { processExpression } = require('playwright/lib/server/injected/injectedScript');2const { processExpression } = require('playwright/lib/server/injected/injectedScript');3const { processExpression } = require('playwright/lib/server/injected/injectedScript');4const { processExpression } = require('playwright/lib/server/injected/injectedScript');5const { processExpression } = require('playwright/lib/server/injected/injectedScript');6const { processExpression } = require('playwright/lib/server/injected/injectedScript');7const { processExpression } = require('playwright/lib/server/injected/injectedScript');8const { processExpression } = require('playwright/lib/server/injected/injectedScript');9const { processExpression } = require('playwright/lib/server/injected/injectedScript');10const { processExpression } = require('playwright/lib/server/injected/injectedScript');11const { processExpression } = require('playwright/lib/server/injected/injectedScript');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { processExpression } = require('playwright/lib/utils/selectorParser');2const { processExpression } = require('playwright/lib/utils/selectorParser');3const selector = processExpression('css=div > button:has-text("Click me")');4console.log(selector);5#### `selector.find(selector)`6#### `selector.nth(index)`7#### `selector.withText(text)`8#### `selector.withValue(value)`9#### `selector.filter(filterFunction)`10#### `selector.count()`11#### `selector.textContent()`12#### `selector.getAttribute(name)`13#### `selector.isVisible()`14#### `selector.isDisabled()`15#### `selector.isChecked()`16#### `selector.press(key[, options])`17#### `selector.fill(value)`18#### `selector.check(options)`19#### `selector.uncheck(options)`20#### `selector.selectOption(value[, options])`21#### `selector.dblclick(options)`22#### `selector.click(options)`

Full Screen

Using AI Code Generation

copy

Full Screen

1const { processExpression } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const expression = processExpression('click', { selector: 'text="Click me"' });3console.log(expression);4{5 target: { selector: 'text="Click me"' },6}

Full Screen

Using AI Code Generation

copy

Full Screen

1const processExpression = require('playwright/lib/server/frames').processExpression;2(async () => {3 const result = await processExpression('document.querySelector("#foo")', false, false);4 console.log(result);5})();6{7 objectId: '{"injectedScriptId":1,"id":1}',8 preview: {9 { name: 'id', type: 'string', value: 'foo' },10 { name: 'innerHTML', type: 'string', value: 'Hello world' },11 { name: 'outerHTML', type: 'string', value: '<div id="foo">Hello world</div>' }12 }13}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Internal } = require('playwright/lib/server/internal');2const internal = new Internal();3const expression = 'document.querySelector("body").innerText';4const isFunction = false;5const arg = undefined;6const returnByValue = false;7const timeout = 3000;8const world = {page: page};9const result = await internal.processExpression(expression, isFunction, arg, returnByValue, timeout, world);10console.log(result);11const { Internal } = require('playwright/lib/server/internal');12const internal = new Internal();13const expression = 'document.querySelector("body").innerText';14const isFunction = false;15const arg = undefined;16const returnByValue = false;17const timeout = 3000;18const world = {page: page};19const result = await internal.processExpression(expression, isFunction, arg, returnByValue, timeout, world);20console.log(result);21const { Internal } = require('playwright/lib/server/internal');22const internal = new Internal();23const expression = 'document.querySelector("body").innerText';24const isFunction = false;25const arg = undefined;26const returnByValue = false;27const timeout = 3000;28const world = {page: page};29const result = await internal.processExpression(expression, isFunction, arg, returnByValue, timeout, world);30console.log(result);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { processExpression } = require('playwright/lib/server/injected/injectedScript');2const result = processExpression('1 + 1');3const { processExpression } = require('playwright/lib/server/injected/injectedScript');4const result = processExpression('1 + 1');5### processExpression(expression, options?)6const { processExpression } = require('playwright/lib/server/injected/injectedScript');7const result = processExpression('1 + 1');

Full Screen

Using AI Code Generation

copy

Full Screen

1const {processExpression} = require('playwright/lib/server/frames');2const {parse} = require('playwright/lib/server/common/selectorParser');3const selector = parse('text=hello');4const result = processExpression(selector, document, false);5console.log(result);6[MIT](LICENSE)

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal 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