Best JavaScript code snippet using playwright-internal
esprima.js
Source:esprima.js
...2331 var fdBody = genBlockStatement(0, null, null, fbExpressions);2332 var fd = genFunctionDeclaration(0, null, null, did, [], fdBody);2333 var returnStm = genReturnStatement(0, null, null, did);2334 var body = genBlockStatement(0, null, null, [fd, returnStm]);2335 var callee = genFunctionExpression(0, null, null, null, [], body);2336 var dinit = genCallExpression(0, null, null, callee, arguments);2337 var declarator = genVariableDeclarator(0, null, null, did, dinit);2338 // var declarations = [declarator];2339 // var rubbish = genVariableDeclaration(0, null, null, declarations);2340 // return rubbish;2341 return declarator;2342 }2343 2344 function genExpression(deep, choices, excludes) {2345 if(!choices) {2346 choices = ['Literal', 'Identifier', 'ArrayExpression', 'ObjectExpression', 'FunctionExpression', 'UnaryExpression', 'UpdateExpression', 'BinaryExpression', 'AssignmentExpression', 'LogicalExpression', 'MemberExpression', 'ConditionalExpression'];2347 }2348 var ccc = [];2349 for(var i = 0, len = choices.length; i < len; i++) {2350 if((!excludes || excludes.indexOf(choices[i]) < 0) && (deep < ComplexDeep || SimplestTypes.indexOf(choices[i]) >= 0)) {2351 ccc.push(choices[i]);2352 }2353 }2354 type = ccc[Math.floor(Math.random() * ccc.length)];2355 2356 var e;2357 switch(type) {2358 case 'ArrayExpression':2359 e = genArrayExpression(deep, choices, excludes);2360 break;2361 case 'ObjectExpression':2362 e = genObjectExpression(deep, choices, excludes);2363 break;2364 case 'FunctionExpression':2365 e = genFunctionExpression(deep, choices, excludes);2366 break;2367 case 'UnaryExpression':2368 e = genUnaryExpression(deep, choices, excludes);2369 break;2370 case 'UpdateExpression':2371 e = genUpdateExpression(deep, choices, excludes);2372 break;2373 case 'BinaryExpression':2374 e = genBinaryExpression(deep, choices, excludes);2375 break;2376 case 'AssignmentExpression':2377 e = genAssignmentExpression(deep, choices, excludes);2378 break;2379 case 'LogicalExpression':2380 e = genLogicalExpression(deep, choices, excludes);2381 break;2382 case 'MemberExpression':2383 e = genMemberExpression(deep, choices, excludes);2384 break;2385 case 'ConditionalExpression':2386 e = genConditionalExpression(deep, choices, excludes);2387 break;2388 case 'Identifier':2389 e = genIdentifier(deep, choices, excludes);2390 case 'Literal':2391 default:2392 e = genLiteral(deep, choices, excludes);2393 break;2394 }2395 return e;2396 }2397 2398 function genExpressions(deep, choices, excludes) {2399 list = [];2400 var ecnt = Math.ceil(Math.random() * 5);2401 for(var i = 0; i < ecnt; i++) {2402 var exp = genExpression(deep, choices, excludes);2403 list.push(exp);2404 }2405 return list;2406 }2407 2408 function genStatement(deep, choices, excludes) {2409 var type = 'ExpressionStatement';2410 if(deep < 3) {2411 if(!choices) {2412 choices = ['ExpressionStatement', 'BlockStatement', 'IfStatement', 'SwitchStatement', 'WhileStatement', 'ForStatement', 'ForInStatement'];2413 }2414 var ccc = [];2415 for(var i = 0, len = choices.length; i < len; i++) {2416 if(!excludes || excludes.indexOf(choices[i]) < 0) {2417 ccc.push(choices[i]);2418 }2419 }2420 var type = ccc[Math.floor(Math.random() * ccc.length)];2421 }2422 var e;2423 switch(type) {2424 case 'BlockStatement':2425 e = genBlockStatement(deep, choices, excludes);2426 break;2427 case 'IfStatement':2428 e = genIfStatement(deep, choices, excludes);2429 break;2430 case 'SwitchStatement':2431 e = genSwitchStatement(deep, choices, excludes);2432 break;2433 case 'WhileStatement':2434 e = genWhileStatement(deep, choices, excludes);2435 break;2436 case 'ForStatement':2437 e = genForStatement(deep, choices, excludes);2438 break;2439 case 'ForInStatement':2440 e = genForInStatement(deep, choices, excludes);2441 case 'ExpressionStatement':2442 default:2443 e = genExpressionStatement(deep, choices, excludes);2444 break;2445 }2446 return e;2447 }2448 2449 function genStatements(deep, choices, excludes) {2450 list = [];2451 var scnt = Math.ceil(Math.random() * 5);2452 for(var i = 0; i < scnt; i++) {2453 var stm = genStatement(deep, choices, excludes);2454 list.push(stm);2455 }2456 return list;2457 }2458 2459 function genPatterns(deep, choices, excludes) {2460 var patterns = [];2461 var pcnt = Math.ceil(Math.random() * 5);2462 for(var i = 0; i < pcnt; i++) {2463 var pid = genIdentifier(deep, choices, excludes);2464 patterns.push(pid);2465 }2466 return patterns;2467 }2468 2469 function genNode(deep, choices, excludes) {2470 return {};2471 }2472 function genIdentifier(deep, choices, excludes, name, nameClass) {2473 if(!name) {2474 name = (nameClass ? nameClass : '__rubbish') + (rubbishVarCnt++);2475 }2476 return {"type": "Identifier", "name": toUgly(name, true)};2477 }2478 function genLiteral(deep, choices, excludes, value) {2479 var raw;2480 if(!value) {2481 var rdn = Math.random();2482 if(rdn > 0.8) {2483 value = resFileNames[Math.floor(Math.random() * resFileNames.length)];2484 } else if(rdn > 0.6) {2485 value = true;2486 } else if(rdn > 0.5) {2487 value = true;2488 } else if(rdn > 0.4) {2489 value = false;2490 } else if(rdn > 0.2) {2491 value = Math.floor(rdn * 1000);2492 } else {2493 value = null;2494 }2495 }2496 if(value) {2497 if(typeof value === 'string') {2498 raw = '\'' + value + '\'';2499 } else if(typeof value === 'boolean') {2500 raw = value ? 'true' : 'false';2501 } else {2502 raw = value.toString();2503 }2504 } else {2505 raw = 'null';2506 }2507 return {"type": "Literal", "value": value, "raw": raw};2508 }2509 function genRegExpLiteral(deep, choices, excludes, pattern, flags) {2510 var ast = genLiteral(deep + 1, choices, excludes);2511 ast.regex = {"pattern": pattern, "flags": flags}2512 return ast;2513 }2514 function genProgram(deep, choices, excludes, body) {2515 return {"type": "Program", "body": body};2516 }2517 function genFunction(deep, choices, excludes, id, params, body) {2518 if(!id && Math.random() > 0.5){2519 id = genIdentifier(deep + 1, choices, excludes);2520 }2521 if(!params && Math.random() > 0.5) {2522 params = genPatterns(deep + 1, choices, excludes);2523 }2524 if(!body) {2525 body = genBlockStatement(deep + 1, choices, mergeArray(excludes, ["FunctionExpression"]));2526 }2527 return {"id": id, "params": params, "body": body};2528 }2529 function genExpressionStatement(deep, choices, excludes, expression) {2530 if(!expression) {2531 expression = genExpression(deep + 1, choices, excludes);2532 }2533 return {"type": "ExpressionStatement", "expression": expression};2534 }2535 function genDirective(deep, choices, excludes, expression, directive) {2536 return {"type": "ExpressionStatement", "expression": expression, "directive": directive};2537 }2538 function genBlockStatement(deep, choices, excludes, body) {2539 if(!body) {2540 body = genStatements(deep, choices, mergeArray(excludes, ["BlockStatement"]));2541 }2542 return {"type": "BlockStatement", "body": body};2543 }2544 function genFunctionBody(deep, choices, excludes) {2545 return genBlockStatement(deep, choices, excludes);2546 }2547 function genEmptyStatement(deep, choices, excludes) {2548 return {"type": "EmptyStatement"};2549 }2550 function genDebuggerStatement(deep, choices, excludes) {2551 return {"type": "DebuggerStatement"};2552 }2553 function genWithStatement(deep, choices, excludes, object, body) {2554 return {"type": "WithStatement", "object": object, "body": body};2555 }2556 function genReturnStatement(deep, choices, excludes, argument) {2557 if(!argument) {2558 argument = genExpression(deep + 1, ["Identifier", "MemberExpression"], excludes);2559 }2560 return {"type": "ReturnStatement", "argument": argument};2561 }2562 function genLabeledStatement(deep, choices, excludes, label, body) {2563 return {"type": "LabeledStatement", "label": label, "body": body};2564 }2565 function genBreakStatement(deep, choices, excludes, label) {2566 return {"type": "BreakStatement", "label": label};2567 }2568 function genContinueStatement(deep, choices, excludes) {2569 return {"type": "ContinueStatement", "label": label};2570 }2571 function genIfStatement(deep, choices, excludes, test, consequent, alternate) {2572 if(!test) {2573 test = genExpression(deep + 1, ["Identifier", "MemberExpression"], excludes);2574 }2575 if(!consequent) {2576 consequent = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2577 }2578 if(!alternate && Math.random() > 0.5) {2579 alternate = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2580 }2581 return {"type": "IfStatement", "test": test, "consequent": consequent, "alternate": alternate};2582 }2583 function genSwitchStatement(deep, choices, excludes, discriminant, cases) {2584 if(!discriminant) {2585 discriminant = genExpression(deep + 1, ["Identifier", "MemberExpression"], excludes);2586 }2587 if(!cases) {2588 cases = [];2589 var scCnt = Math.ceil(Math.random() * 5);2590 for(var i = 0; i < scCnt; i++) {2591 var sc = genSwitchCase(deep + 1, choices, excludes);2592 cases.push(sc);2593 }2594 }2595 return {"type": "SwitchStatement", "discriminant": discriminant, "cases": cases};2596 }2597 function genSwitchCase(deep, choices, excludes, test, consequent) {2598 if(!test && Math.random() > 0.5) {2599 test = genExpression(deep, ["Identifier"], excludes);2600 }2601 if(!consequent) {2602 consequent = genStatements(deep, choices, mergeArray(excludes, ["SwitchStatement"]));2603 }2604 return {"type": "SwitchCase", "test": test, "consequent": consequent};2605 }2606 function genThrowStatement(deep, choices, excludes, argument) {2607 return {"type": "ThrowStatement", "argument": argument};2608 }2609 function genTryStatement(deep, choices, excludes, block, handler, finalizer) {2610 return {"type": "TryStatement", "block": block, "handler": handler, "finalizer": finalizer};2611 }2612 function genCatchClause(deep, choices, excludes, param, body) {2613 return {"type": "CatchClause", "param": param, "body": body};2614 }2615 function genWhileStatement(deep, choices, excludes, test, body) {2616 if(!test) {2617 test = genExpression(deep + 1, ['Identifier', 'MemberExpression', 'UnaryExpression', 'BinaryExpression'], excludes);2618 }2619 if(!body) {2620 body = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2621 }2622 return {"type": "WhileStatement", "test": test, "body": body};2623 }2624 function genDoWhileStatement(deep, choices, excludes) {2625 if(!body) {2626 body = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2627 }2628 if(!test) {2629 test = genExpression(deep + 1, ['Identifier', 'MemberExpression', 'UnaryExpression', 'BinaryExpression'], excludes);2630 }2631 return {"type": "DoWhileStatement", "body": body, "test": test};2632 }2633 function genForStatement(deep, choices, excludes, init, test, update, body) {2634 if(!init && Math.random() > 0.5) {2635 init = genVariableDeclaration(deep + 1, choices, excludes);2636 }2637 if(!test && Math.random() > 0.5) {2638 test = genExpression(deep + 1, ["LogicalExpression"], excludes);2639 }2640 if(!update && Math.random() > 0.5) {2641 update = genExpression(deep + 1, ["UpdateExpression"], excludes);2642 }2643 if(!body) {2644 body = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2645 }2646 return {"type": "ForStatement", "init": init, "test": test, "update": update, "body": body};2647 }2648 function genForInStatement(deep, choices, excludes, left, right, body) {2649 if(!left) {2650 init = genVariableDeclaration(deep + 1, choices, excludes);2651 }2652 if(!right){2653 right = genExpression(deep + 1, ['Identifier', 'MemberExpression'], excludes);2654 }2655 if(!body) {2656 body = genStatement(deep + 1, ["ExpressionStatement", "BlockStatement"], excludes);2657 }2658 return {"type": "ForInStatement", "left": left, "right": right, "body": body};2659 }2660 function genFunctionDeclaration(deep, choices, excludes, id, params, body) {2661 var ast = genFunction(deep + 1, choices, excludes, id, params, body);2662 ast.type = "FunctionDeclaration";2663 return ast;2664 }2665 function genVariableDeclaration(deep, choices, excludes, declarations) {2666 if(!declarations) {2667 declarations = [];2668 var dcnt = Math.ceil(Math.random() * 5);2669 for(var i = 0; i < dcnt; i++) {2670 var d = genVariableDeclarator(deep, choices, excludes);2671 declarations.push(d);2672 }2673 }2674 return {"type": "VariableDeclaration", "declarations": declarations, "kind": "var"};2675 }2676 function genVariableDeclarator(deep, choices, excludes, id, init) {2677 if(!id) {2678 id = genIdentifier(deep + 1, choices, excludes);2679 }2680 if(undefined === init && Math.random() > 0.5) {2681 init = genExpression(deep + 1, choices, mergeArray(excludes, ['SequenceExpression']));2682 }2683 return {"type": "VariableDeclarator", "id": id, "init": init ? init : null};2684 }2685 function genThisExpression(deep, choices, excludes) {2686 return {"type": "ThisExpression"};2687 }2688 function genArrayExpression(deep, choices, excludes, elements) {2689 if(!elements && Math.random() > 0.5) {2690 elements = genSequenceExpression(deep + 1, choices, mergeArray(excludes, ['AssignmentExpression']));2691 }2692 return {"type": "ArrayExpression", "elements": elements};2693 }2694 function genObjectExpression(deep, choices, excludes, properties) {2695 if(!properties) {2696 properties = [];2697 var pcnt = Math.ceil(Math.random() * 5);2698 for(var i = 0; i < pcnt; i++) {2699 var ppt = genProperty(deep + 1, choices, excludes);2700 properties.push(ppt);2701 }2702 }2703 return {"type": "ObjectExpression", "properties": properties};2704 }2705 function genProperty(deep, choices, excludes, key, value, kind) {2706 if(!key){2707 key = genIdentifier(deep + 1, choices, excludes);2708 }2709 if(!value) {2710 value = genExpression(deep + 1, choices ? choices : ['Identifier', 'Literal', 'MemberExpression', 'AssignmentExpression'], excludes);2711 }2712 if(!kind) {2713 kind = 'init';2714 }2715 return {"type": "Property", "key": key, "value": value, "kind": kind};2716 }2717 function genFunctionExpression(deep, choices, excludes, id, params, body) {2718 var ast = genFunction(deep, choices, excludes, id, params, body); 2719 ast.type = "FunctionExpression";2720 return ast;2721 }2722 function genUnaryExpression(deep, choices, excludes, operator, prefix, argument) {2723 if(!operator) {2724 operator = genUnaryOperator(deep + 1, choices, excludes);2725 }2726 if(!argument) {2727 argument = genExpression(deep + 1, choices, mergeArray(excludes, ['UnaryExpression', 'AssignmentExpression', 'SequenceExpression']));2728 }2729 return {"type": "UnaryExpression", "operator": operator, "prefix": true, "argument": argument};2730 }2731 function genUnaryOperator(deep, choices, excludes) {...
compiler-dom.global.js
Source:compiler-dom.global.js
...1599 case 15 /* JS_ARRAY_EXPRESSION */:1600 genArrayExpression(node, context);1601 break;1602 case 16 /* JS_FUNCTION_EXPRESSION */:1603 genFunctionExpression(node, context);1604 break;1605 case 17 /* JS_SEQUENCE_EXPRESSION */:1606 genSequenceExpression(node, context);1607 break;1608 case 18 /* JS_CONDITIONAL_EXPRESSION */:1609 genConditionalExpression(node, context);1610 break;1611 /* istanbul ignore next */1612 default:1613 {1614 assert(false, `unhandled codegen node type: ${node.type}`);1615 // make sure we exhaust all possible types1616 const exhaustiveCheck = node;1617 return exhaustiveCheck;1618 }1619 }1620 }1621 function genText(node, context) {1622 context.push(JSON.stringify(node.content), node);1623 }1624 function genExpression(node, context) {1625 const { content, isStatic } = node;1626 context.push(isStatic ? JSON.stringify(content) : content, node);1627 }1628 function genInterpolation(node, context) {1629 const { push, helper } = context;1630 push(`${helper(TO_STRING)}(`);1631 genNode(node.content, context);1632 push(`)`);1633 }1634 function genCompoundExpression(node, context) {1635 for (let i = 0; i < node.children.length; i++) {1636 const child = node.children[i];1637 if (isString(child)) {1638 context.push(child);1639 }1640 else {1641 genNode(child, context);1642 }1643 }1644 }1645 function genExpressionAsPropertyKey(node, context) {1646 const { push } = context;1647 if (node.type === 8 /* COMPOUND_EXPRESSION */) {1648 push(`[`);1649 genCompoundExpression(node, context);1650 push(`]`);1651 }1652 else if (node.isStatic) {1653 // only quote keys if necessary1654 const text = isSimpleIdentifier(node.content)1655 ? node.content1656 : JSON.stringify(node.content);1657 push(text, node);1658 }1659 else {1660 push(`[${node.content}]`, node);1661 }1662 }1663 function genComment(node, context) {1664 {1665 const { push, helper } = context;1666 push(`${helper(CREATE_VNODE)}(${helper(COMMENT)}, 0, ${JSON.stringify(node.content)})`, node);1667 }1668 }1669 // JavaScript1670 function genCallExpression(node, context) {1671 const callee = isString(node.callee)1672 ? node.callee1673 : context.helper(node.callee);1674 context.push(callee + `(`, node, true);1675 genNodeList(node.arguments, context);1676 context.push(`)`);1677 }1678 function genObjectExpression(node, context) {1679 const { push, indent, deindent, newline, resetMapping } = context;1680 const { properties } = node;1681 if (!properties.length) {1682 push(`{}`, node);1683 return;1684 }1685 const multilines = properties.length > 1 ||1686 (1687 properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));1688 push(multilines ? `{` : `{ `);1689 multilines && indent();1690 for (let i = 0; i < properties.length; i++) {1691 const { key, value, loc } = properties[i];1692 resetMapping(loc); // reset source mapping for every property.1693 // key1694 genExpressionAsPropertyKey(key, context);1695 push(`: `);1696 // value1697 genNode(value, context);1698 if (i < properties.length - 1) {1699 // will only reach this if it's multilines1700 push(`,`);1701 newline();1702 }1703 }1704 multilines && deindent();1705 const lastChar = context.code[context.code.length - 1];1706 push(multilines || /[\])}]/.test(lastChar) ? `}` : ` }`);1707 }1708 function genArrayExpression(node, context) {1709 genNodeListAsArray(node.elements, context);1710 }1711 function genFunctionExpression(node, context) {1712 const { push, indent, deindent } = context;1713 const { params, returns, newline } = node;1714 push(`(`, node);1715 if (isArray(params)) {1716 genNodeList(params, context);1717 }1718 else if (params) {1719 genNode(params, context);1720 }1721 push(`) => `);1722 if (newline) {1723 push(`{`);1724 indent();1725 push(`return `);
...
compiler-dom.esm-browser.js
Source:compiler-dom.esm-browser.js
...1597 case 15 /* JS_ARRAY_EXPRESSION */:1598 genArrayExpression(node, context);1599 break;1600 case 16 /* JS_FUNCTION_EXPRESSION */:1601 genFunctionExpression(node, context);1602 break;1603 case 17 /* JS_SEQUENCE_EXPRESSION */:1604 genSequenceExpression(node, context);1605 break;1606 case 18 /* JS_CONDITIONAL_EXPRESSION */:1607 genConditionalExpression(node, context);1608 break;1609 /* istanbul ignore next */1610 default:1611 {1612 assert(false, `unhandled codegen node type: ${node.type}`);1613 // make sure we exhaust all possible types1614 const exhaustiveCheck = node;1615 return exhaustiveCheck;1616 }1617 }1618}1619function genText(node, context) {1620 context.push(JSON.stringify(node.content), node);1621}1622function genExpression(node, context) {1623 const { content, isStatic } = node;1624 context.push(isStatic ? JSON.stringify(content) : content, node);1625}1626function genInterpolation(node, context) {1627 const { push, helper } = context;1628 push(`${helper(TO_STRING)}(`);1629 genNode(node.content, context);1630 push(`)`);1631}1632function genCompoundExpression(node, context) {1633 for (let i = 0; i < node.children.length; i++) {1634 const child = node.children[i];1635 if (isString(child)) {1636 context.push(child);1637 }1638 else {1639 genNode(child, context);1640 }1641 }1642}1643function genExpressionAsPropertyKey(node, context) {1644 const { push } = context;1645 if (node.type === 8 /* COMPOUND_EXPRESSION */) {1646 push(`[`);1647 genCompoundExpression(node, context);1648 push(`]`);1649 }1650 else if (node.isStatic) {1651 // only quote keys if necessary1652 const text = isSimpleIdentifier(node.content)1653 ? node.content1654 : JSON.stringify(node.content);1655 push(text, node);1656 }1657 else {1658 push(`[${node.content}]`, node);1659 }1660}1661function genComment(node, context) {1662 {1663 const { push, helper } = context;1664 push(`${helper(CREATE_VNODE)}(${helper(COMMENT)}, 0, ${JSON.stringify(node.content)})`, node);1665 }1666}1667// JavaScript1668function genCallExpression(node, context) {1669 const callee = isString(node.callee)1670 ? node.callee1671 : context.helper(node.callee);1672 context.push(callee + `(`, node, true);1673 genNodeList(node.arguments, context);1674 context.push(`)`);1675}1676function genObjectExpression(node, context) {1677 const { push, indent, deindent, newline, resetMapping } = context;1678 const { properties } = node;1679 if (!properties.length) {1680 push(`{}`, node);1681 return;1682 }1683 const multilines = properties.length > 1 ||1684 (1685 properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));1686 push(multilines ? `{` : `{ `);1687 multilines && indent();1688 for (let i = 0; i < properties.length; i++) {1689 const { key, value, loc } = properties[i];1690 resetMapping(loc); // reset source mapping for every property.1691 // key1692 genExpressionAsPropertyKey(key, context);1693 push(`: `);1694 // value1695 genNode(value, context);1696 if (i < properties.length - 1) {1697 // will only reach this if it's multilines1698 push(`,`);1699 newline();1700 }1701 }1702 multilines && deindent();1703 const lastChar = context.code[context.code.length - 1];1704 push(multilines || /[\])}]/.test(lastChar) ? `}` : ` }`);1705}1706function genArrayExpression(node, context) {1707 genNodeListAsArray(node.elements, context);1708}1709function genFunctionExpression(node, context) {1710 const { push, indent, deindent } = context;1711 const { params, returns, newline } = node;1712 push(`(`, node);1713 if (isArray(params)) {1714 genNodeList(params, context);1715 }1716 else if (params) {1717 genNode(params, context);1718 }1719 push(`) => `);1720 if (newline) {1721 push(`{`);1722 indent();1723 push(`return `);
...
note-generate-code.js
Source:note-generate-code.js
...377 case 17 /* JS_ARRAY_EXPRESSION */:378 genArrayExpression(node, context);379 break;380 case 18 /* JS_FUNCTION_EXPRESSION */:381 genFunctionExpression(node, context);382 break;383 case 19 /* JS_CONDITIONAL_EXPRESSION */:384 genConditionalExpression(node, context);385 break;386 case 20 /* JS_CACHE_EXPRESSION */:387 genCacheExpression(node, context);388 break;389 // SSR only types390 case 21 /* JS_BLOCK_STATEMENT */:391 break;392 case 22 /* JS_TEMPLATE_LITERAL */:393 break;394 case 23 /* JS_IF_STATEMENT */:395 break;396 case 24 /* JS_ASSIGNMENT_EXPRESSION */:397 break;398 case 25 /* JS_SEQUENCE_EXPRESSION */:399 break;400 case 26 /* JS_RETURN_STATEMENT */:401 break;402 /* istanbul ignore next */403 case 10 /* IF_BRANCH */:404 // noop405 break;406 default:407 {408 assert(false, `unhandled codegen node type: ${node.type}`);409 // make sure we exhaust all possible types410 const exhaustiveCheck = node;411 return exhaustiveCheck;412 }413 }414 }415 function genText(node, context) {416 context.push(JSON.stringify(node.content), node);417 }418 function genExpression(node, context) {419 const { content, isStatic } = node;420 context.push(isStatic ? JSON.stringify(content) : content, node);421 }422 function genInterpolation(node, context) {423 const { push, helper, pure } = context;424 if (pure)425 push(PURE_ANNOTATION);426 push(`${helper(TO_DISPLAY_STRING)}(`);427 genNode(node.content, context);428 push(`)`);429 }430 function genCompoundExpression(node, context) {431 for (let i = 0; i < node.children.length; i++) {432 const child = node.children[i];433 if (isString(child)) {434 context.push(child);435 }436 else {437 genNode(child, context);438 }439 }440 }441 function genExpressionAsPropertyKey(node, context) {442 const { push } = context;443 if (node.type === 8 /* COMPOUND_EXPRESSION */) {444 push(`[`);445 genCompoundExpression(node, context);446 push(`]`);447 }448 else if (node.isStatic) {449 // only quote keys if necessary450 const text = isSimpleIdentifier(node.content)451 ? node.content452 : JSON.stringify(node.content);453 push(text, node);454 }455 else {456 push(`[${node.content}]`, node);457 }458 }459 function genComment(node, context) {460 {461 const { push, helper, pure } = context;462 if (pure) {463 push(PURE_ANNOTATION);464 }465 push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);466 }467 }468 function genVNodeCall(node, context) {469 const { push, helper, pure } = context;470 const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;471 if (directives) {472 push(helper(WITH_DIRECTIVES) + `(`);473 }474 if (isBlock) {475 push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);476 }477 if (pure) {478 push(PURE_ANNOTATION);479 }480 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);481 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);482 push(`)`);483 if (isBlock) {484 push(`)`);485 }486 if (directives) {487 push(`, `);488 genNode(directives, context);489 push(`)`);490 }491 }492 /**493 * Adds directives to a VNode.494 */495 function withDirectives(vnode, directives) {496 const internalInstance = currentRenderingInstance;497 if (internalInstance === null) {498 warn(`withDirectives can only be used inside render functions.`);499 return vnode;500 }501 const instance = internalInstance.proxy;502 const bindings = vnode.dirs || (vnode.dirs = []);503 for (let i = 0; i < directives.length; i++) {504 let [dir, value, arg, modifiers = EMPTY_OBJ] = directives[i];505 if (isFunction(dir)) {506 dir = {507 mounted: dir,508 updated: dir509 };510 }511 bindings.push({512 dir,513 instance,514 value,515 oldValue: void 0,516 arg,517 modifiers518 });519 }520 return vnode;521 }522 /**523 * Create a block root vnode. Takes the same exact arguments as `createVNode`.524 * A block root keeps track of dynamic nodes within the block in the525 * `dynamicChildren` array.526 *527 * @private528 */529 function createBlock(type, props, children, patchFlag, dynamicProps) {530 const vnode = createVNode(type, props, children, patchFlag, dynamicProps, true /* isBlock: prevent a block from tracking itself */);531 // save current block children on the block vnode532 vnode.dynamicChildren = currentBlock || EMPTY_ARR;533 // close block534 closeBlock();535 // a block is always going to be patched, so track it as a child of its536 // parent block537 if (shouldTrack$1 > 0 && currentBlock) {538 currentBlock.push(vnode);539 }540 return vnode;541 }542 const createVNodeWithArgsTransform = (...args) => {543 return _createVNode(...(vnodeArgsTransformer544 ? vnodeArgsTransformer(args, currentRenderingInstance)545 : args));546 };547 function _createVNode(type, props = null, children = null, patchFlag = 0, dynamicProps = null, isBlockNode = false) {548 if (!type || type === NULL_DYNAMIC_COMPONENT) {549 if ( !type) {550 warn(`Invalid vnode type when creating vnode: ${type}.`);551 }552 type = Comment;553 }554 if (isVNode(type)) {555 // createVNode receiving an existing vnode. This happens in cases like556 // <component :is="vnode"/>557 // #2078 make sure to merge refs during the clone instead of overwriting it558 const cloned = cloneVNode(type, props, true /* mergeRef: true */);559 if (children) {560 normalizeChildren(cloned, children);561 }562 return cloned;563 }564 // class component normalization.565 if (isClassComponent(type)) {566 type = type.__vccOpts;567 }568 // class & style normalization.569 if (props) {570 // for reactive or proxy objects, we need to clone it to enable mutation.571 if (isProxy(props) || InternalObjectKey in props) {572 props = extend({}, props);573 }574 let { class: klass, style } = props;575 if (klass && !isString(klass)) {576 props.class = normalizeClass(klass);577 }578 if (isObject(style)) {579 // reactive state objects need to be cloned since they are likely to be580 // mutated581 if (isProxy(style) && !isArray(style)) {582 style = extend({}, style);583 }584 props.style = normalizeStyle(style);585 }586 }587 // encode the vnode type information into a bitmap588 const shapeFlag = isString(type)589 ? 1 /* ELEMENT */590 : isSuspense(type)591 ? 128 /* SUSPENSE */592 : isTeleport(type)593 ? 64 /* TELEPORT */594 : isObject(type)595 ? 4 /* STATEFUL_COMPONENT */596 : isFunction(type)597 ? 2 /* FUNCTIONAL_COMPONENT */598 : 0;599 if ( shapeFlag & 4 /* STATEFUL_COMPONENT */ && isProxy(type)) {600 type = toRaw(type);601 warn(`Vue received a Component which was made a reactive object. This can ` +602 `lead to unnecessary performance overhead, and should be avoided by ` +603 `marking the component with \`markRaw\` or using \`shallowRef\` ` +604 `instead of \`ref\`.`, `\nComponent that was made reactive: `, type);605 }606 const vnode = {607 __v_isVNode: true,608 ["__v_skip" /* SKIP */]: true,609 type,610 props,611 key: props && normalizeKey(props),612 ref: props && normalizeRef(props),613 scopeId: currentScopeId,614 children: null,615 component: null,616 suspense: null,617 ssContent: null,618 ssFallback: null,619 dirs: null,620 transition: null,621 el: null,622 anchor: null,623 target: null,624 targetAnchor: null,625 staticCount: 0,626 shapeFlag,627 patchFlag,628 dynamicProps,629 dynamicChildren: null,630 appContext: null631 };632 // validate key633 if ( vnode.key !== vnode.key) {634 warn(`VNode created with invalid key (NaN). VNode type:`, vnode.type);635 }636 normalizeChildren(vnode, children);637 // normalize suspense children638 if ( shapeFlag & 128 /* SUSPENSE */) {639 const { content, fallback } = normalizeSuspenseChildren(vnode);640 vnode.ssContent = content;641 vnode.ssFallback = fallback;642 }643 if (shouldTrack$1 > 0 &&644 // avoid a block node from tracking itself645 !isBlockNode &&646 // has current parent block647 currentBlock &&648 // presence of a patch flag indicates this node needs patching on updates.649 // component nodes also should always be patched, because even if the650 // component doesn't need to update, it needs to persist the instance on to651 // the next vnode so that it can be properly unmounted later.652 (patchFlag > 0 || shapeFlag & 6 /* COMPONENT */) &&653 // the EVENTS flag is only for hydration and if it is the only flag, the654 // vnode should not be considered dynamic due to handler caching.655 patchFlag !== 32 /* HYDRATE_EVENTS */) {656 currentBlock.push(vnode);657 }658 return vnode;659 }660 function normalizeChildren(vnode, children) {661 let type = 0;662 const { shapeFlag } = vnode;663 if (children == null) {664 children = null;665 }666 else if (isArray(children)) {667 type = 16 /* ARRAY_CHILDREN */;668 }669 else if (typeof children === 'object') {670 if (shapeFlag & 1 /* ELEMENT */ || shapeFlag & 64 /* TELEPORT */) {671 // Normalize slot to plain children for plain element and Teleport672 const slot = children.default;673 if (slot) {674 // _c marker is added by withCtx() indicating this is a compiled slot675 slot._c && setCompiledSlotRendering(1);676 normalizeChildren(vnode, slot());677 slot._c && setCompiledSlotRendering(-1);678 }679 return;680 }681 else {682 type = 32 /* SLOTS_CHILDREN */;683 const slotFlag = children._;684 if (!slotFlag && !(InternalObjectKey in children)) {685 children._ctx = currentRenderingInstance;686 }687 else if (slotFlag === 3 /* FORWARDED */ && currentRenderingInstance) {688 // a child component receives forwarded slots from the parent.689 // its slot type is determined by its parent's slot type.690 if (currentRenderingInstance.vnode.patchFlag & 1024 /* DYNAMIC_SLOTS */) {691 children._ = 2 /* DYNAMIC */;692 vnode.patchFlag |= 1024 /* DYNAMIC_SLOTS */;693 }694 else {695 children._ = 1 /* STABLE */;696 }697 }698 }699 }700 else if (isFunction(children)) {701 children = { default: children, _ctx: currentRenderingInstance };702 type = 32 /* SLOTS_CHILDREN */;703 }704 else {705 children = String(children);706 // force teleport children to array so it can be moved around707 if (shapeFlag & 64 /* TELEPORT */) {708 type = 16 /* ARRAY_CHILDREN */;709 children = [createTextVNode(children)];710 }711 else {712 type = 8 /* TEXT_CHILDREN */;713 }714 }715 vnode.children = children;716 vnode.shapeFlag |= type;717 }718 function normalizeSuspenseChildren(vnode) {719 const { shapeFlag, children } = vnode;720 let content;721 let fallback;722 if (shapeFlag & 32 /* SLOTS_CHILDREN */) {723 content = normalizeSuspenseSlot(children.default);724 fallback = normalizeSuspenseSlot(children.fallback);725 }726 else {727 content = normalizeSuspenseSlot(children);728 fallback = normalizeVNode(null);729 }730 return {731 content,732 fallback733 };734 }735 function normalizeVNode(child) {736 if (child == null || typeof child === 'boolean') {737 // empty placeholder738 return createVNode(Comment);739 }740 else if (isArray(child)) {741 // fragment742 return createVNode(Fragment, null, child);743 }744 else if (typeof child === 'object') {745 // already vnode, this should be the most common since compiled templates746 // always produce all-vnode children arrays747 return child.el === null ? child : cloneVNode(child);748 }749 else {750 // strings and numbers751 return createVNode(Text, null, String(child));752 }753 }754 function normalizeSuspenseSlot(s) {755 if (isFunction(s)) {756 s = s();757 }758 if (isArray(s)) {759 const singleChild = filterSingleRoot(s);760 if ( !singleChild) {761 warn(`<Suspense> slots expect a single root node.`);762 }763 s = singleChild;764 }765 return normalizeVNode(s);766 }767 function filterSingleRoot(children) {768 const filtered = children.filter(child => {769 return !(isVNode(child) &&770 child.type === Comment &&771 child.children !== 'v-if');772 });773 return filtered.length === 1 && isVNode(filtered[0]) ? filtered[0] : null;774 }775 function genNodeList(nodes, context, multilines = false, comma = true) {776 const { push, newline } = context;777 for (let i = 0; i < nodes.length; i++) {778 const node = nodes[i];779 if (isString(node)) {780 push(node);781 }782 else if (isArray(node)) {783 genNodeListAsArray(node, context);784 }785 else {786 genNode(node, context);787 }788 if (i < nodes.length - 1) {789 if (multilines) {790 comma && push(',');791 newline();792 }793 else {794 comma && push(', ');795 }796 }797 }798 }799 function genNullableArgs(args) {800 let i = args.length;801 while (i--) {802 if (args[i] != null)803 break;804 }805 return args.slice(0, i + 1).map(arg => arg || `null`);806 }807 // JavaScript808 function genCallExpression(node, context) {809 const { push, helper, pure } = context;810 const callee = isString(node.callee) ? node.callee : helper(node.callee);811 if (pure) {812 push(PURE_ANNOTATION);813 }814 push(callee + `(`, node);815 genNodeList(node.arguments, context);816 push(`)`);817 }818 function genObjectExpression(node, context) {819 const { push, indent, deindent, newline } = context;820 const { properties } = node;821 if (!properties.length) {822 push(`{}`, node);823 return;824 }825 const multilines = properties.length > 1 ||826 (827 properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));828 push(multilines ? `{` : `{ `);829 multilines && indent();830 for (let i = 0; i < properties.length; i++) {831 const { key, value } = properties[i];832 // key833 genExpressionAsPropertyKey(key, context);834 push(`: `);835 // value836 genNode(value, context);837 if (i < properties.length - 1) {838 // will only reach this if it's multilines839 push(`,`);840 newline();841 }842 }843 multilines && deindent();844 push(multilines ? `}` : ` }`);845 }846 function genArrayExpression(node, context) {847 genNodeListAsArray(node.elements, context);848 }849 function genNodeListAsArray(nodes, context) {850 const multilines = nodes.length > 3 ||851 ( nodes.some(n => isArray(n) || !isText$1(n)));852 context.push(`[`);853 multilines && context.indent();854 genNodeList(nodes, context, multilines);855 multilines && context.deindent();856 context.push(`]`);857 }858 function genFunctionExpression(node, context) {859 const { push, indent, deindent, scopeId, mode } = context;860 const { params, returns, body, newline, isSlot } = node;861 if (isSlot) {862 push(`_${helperNameMap[WITH_CTX]}(`);863 }864 push(`(`, node);865 if (isArray(params)) {866 genNodeList(params, context);867 }868 else if (params) {869 genNode(params, context);870 }871 push(`) => `);872 if (newline || body) {...
genCode.js
Source:genCode.js
...305 case 17 /* JS_ARRAY_EXPRESSION */:306 genArrayExpression(node, context);307 break;308 case 18 /* JS_FUNCTION_EXPRESSION */:309 genFunctionExpression(node, context);310 break;311 case 19 /* JS_CONDITIONAL_EXPRESSION */:312 genConditionalExpression(node, context);313 break;314 case 20 /* JS_CACHE_EXPRESSION */:315 genCacheExpression(node, context);316 break;317 // SSR only types318 case 21 /* JS_BLOCK_STATEMENT */:319 break;320 case 22 /* JS_TEMPLATE_LITERAL */:321 break;322 case 23 /* JS_IF_STATEMENT */:323 break;324 case 24 /* JS_ASSIGNMENT_EXPRESSION */:325 break;326 case 25 /* JS_SEQUENCE_EXPRESSION */:327 break;328 case 26 /* JS_RETURN_STATEMENT */:329 break;330 /* istanbul ignore next */331 case 10 /* IF_BRANCH */:332 // noop333 break;334 default:335 if (process.env.NODE_ENV !== 'production') {336 assert(false, `unhandled codegen node type: ${node.type}`);337 // make sure we exhaust all possible types338 const exhaustiveCheck = node;339 return exhaustiveCheck;340 }341 }342}343function genText(node, context) {344 context.push(JSON.stringify(node.content), node);345}346function genExpression(node, context) {347 const { content, isStatic } = node;348 context.push(isStatic ? JSON.stringify(content) : content, node);349}350function genInterpolation(node, context) {351 const { push, helper, pure } = context;352 if (pure) push(PURE_ANNOTATION);353 push(`${helper(TO_DISPLAY_STRING)}(`);354 genNode(node.content, context);355 push(`)`);356}357function genCompoundExpression(node, context) {358 for (let i = 0; i < node.children.length; i++) {359 const child = node.children[i];360 if (isString(child)) {361 context.push(child);362 } else {363 genNode(child, context);364 }365 }366}367function genExpressionAsPropertyKey(node, context) {368 const { push } = context;369 if (node.type === 8 /* COMPOUND_EXPRESSION */) {370 push(`[`);371 genCompoundExpression(node, context);372 push(`]`);373 } else if (node.isStatic) {374 // only quote keys if necessary375 const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);376 push(text, node);377 } else {378 push(`[${node.content}]`, node);379 }380}381function genComment(node, context) {382 if (process.env.NODE_ENV !== 'production') {383 const { push, helper, pure } = context;384 if (pure) {385 push(PURE_ANNOTATION);386 }387 push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);388 }389}390function genVNodeCall(node, context) {391 const { push, helper, pure } = context;392 let { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking } = node;393 if (directives) {394 push(helper(WITH_DIRECTIVES) + `(`);395 }396 // å»é¤ä¼å397 isBlock = false;398 patchFlag = '-2 /* BAIL */';399 dynamicProps = null;400 //401 if (isBlock) {402 push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);403 }404 if (pure) {405 push(PURE_ANNOTATION);406 }407 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);408 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);409 push(`)`);410 if (isBlock) {411 push(`)`);412 }413 if (directives) {414 push(`, `);415 genNode(directives, context);416 push(`)`);417 }418}419function genNullableArgs(args) {420 let i = args.length;421 while (i--) {422 if (args[i] != null) break;423 }424 return args.slice(0, i + 1).map((arg) => arg || `null`);425}426// JavaScript427function genCallExpression(node, context) {428 const { push, helper, pure } = context;429 const callee = isString(node.callee) ? node.callee : helper(node.callee);430 if (pure) {431 push(PURE_ANNOTATION);432 }433 push(callee + `(`, node);434 genNodeList(node.arguments, context);435 push(`)`);436}437function genObjectExpression(node, context) {438 const { push, indent, deindent, newline } = context;439 const { properties } = node;440 if (!properties.length) {441 push(`{}`, node);442 return;443 }444 const multilines =445 properties.length > 1 ||446 (process.env.NODE_ENV !== 'production' && properties.some((p) => p.value.type !== 4 /* SIMPLE_EXPRESSION */));447 push(multilines ? `{` : `{ `);448 multilines && indent();449 for (let i = 0; i < properties.length; i++) {450 const { key, value } = properties[i];451 // key452 genExpressionAsPropertyKey(key, context);453 push(`: `);454 // value455 genNode(value, context);456 if (i < properties.length - 1) {457 // will only reach this if it's multilines458 push(`,`);459 newline();460 }461 }462 multilines && deindent();463 push(multilines ? `}` : ` }`);464}465function genArrayExpression(node, context) {466 genNodeListAsArray(node.elements, context);467}468function genFunctionExpression(node, context) {469 const { push, indent, deindent, scopeId, mode } = context;470 const { params, returns, body, newline, isSlot } = node;471 if (isSlot) {472 // wrap slot functions with owner context473 push(`_${helperNameMap[WITH_CTX]}(`);474 }475 push(`(`, node);476 if (isArray(params)) {477 genNodeList(params, context);478 } else if (params) {479 genNode(params, context);480 }481 push(`) => `);482 if (newline || body) {...
codegen.js
Source:codegen.js
...278 case 16:279 genArrayExpression(node, context);280 break;281 case 17:282 genFunctionExpression(node, context);283 break;284 case 18:285 genSequenceExpression(node, context);286 break;287 case 19:288 genConditionalExpression(node, context);289 break;290 case 20:291 genCacheExpression(node, context);292 break;293 default:294 if (true) {295 utils_1.assert(false, "unhandled codegen node type: " + node.type);296 var exhaustiveCheck = node;297 return exhaustiveCheck;298 }299 }300}301function genText(node, context) {302 context.push(JSON.stringify(node.content), node);303}304function genExpression(node, context) {305 var content = node.content, isStatic = node.isStatic;306 context.push(isStatic ? JSON.stringify(content) : content, node);307}308function genInterpolation(node, context) {309 var push = context.push, helper = context.helper;310 push(helper(runtimeHelpers_1.TO_STRING) + "(");311 genNode(node.content, context);312 push(")");313}314function genCompoundExpression(node, context) {315 for (var i = 0; i < node.children.length; i++) {316 var child = node.children[i];317 if (shared_1.isString(child)) {318 context.push(child);319 }320 else {321 genNode(child, context);322 }323 }324}325function genExpressionAsPropertyKey(node, context) {326 var push = context.push;327 if (node.type === 8) {328 push("[");329 genCompoundExpression(node, context);330 push("]");331 }332 else if (node.isStatic) {333 var text = utils_1.isSimpleIdentifier(node.content)334 ? node.content335 : JSON.stringify(node.content);336 push(text, node);337 }338 else {339 push("[" + node.content + "]", node);340 }341}342function genComment(node, context) {343 if (true) {344 var push = context.push, helper = context.helper;345 push(helper(runtimeHelpers_1.CREATE_COMMENT) + "(" + JSON.stringify(node.content) + ")", node);346 }347}348function genCallExpression(node, context) {349 var callee = shared_1.isString(node.callee)350 ? node.callee351 : context.helper(node.callee);352 context.push(callee + "(", node, true);353 genNodeList(node.arguments, context);354 context.push(")");355}356function genObjectExpression(node, context) {357 var push = context.push, indent = context.indent, deindent = context.deindent, newline = context.newline, resetMapping = context.resetMapping;358 var properties = node.properties;359 if (!properties.length) {360 push("{}", node);361 return;362 }363 var multilines = properties.length > 1 ||364 ((!true || true) &&365 properties.some(function (p) { return p.value.type !== 4; }));366 push(multilines ? "{" : "{ ");367 multilines && indent();368 for (var i = 0; i < properties.length; i++) {369 var _a = properties[i], key = _a.key, value = _a.value, loc = _a.loc;370 resetMapping(loc);371 genExpressionAsPropertyKey(key, context);372 push(": ");373 genNode(value, context);374 if (i < properties.length - 1) {375 push(",");376 newline();377 }378 }379 multilines && deindent();380 var lastChar = context.code[context.code.length - 1];381 push(multilines || /[\])}]/.test(lastChar) ? "}" : " }");382}383function genArrayExpression(node, context) {384 genNodeListAsArray(node.elements, context);385}386function genFunctionExpression(node, context) {387 var push = context.push, indent = context.indent, deindent = context.deindent;388 var params = node.params, returns = node.returns, newline = node.newline;389 push("(", node);390 if (shared_1.isArray(params)) {391 genNodeList(params, context);392 }393 else if (params) {394 genNode(params, context);395 }396 push(") => ");397 if (newline) {398 push("{");399 indent();400 push("return ");...
vnode.js
Source:vnode.js
...49 case 17 /* JS_ARRAY_EXPRESSION */:50 genArrayExpression(node, context)51 break52 case 18 /* JS_FUNCTION_EXPRESSION */:53 genFunctionExpression(node, context)54 break55 case 19 /* JS_CONDITIONAL_EXPRESSION */:56 genConditionalExpression(node, context)57 break58 case 20 /* JS_CACHE_EXPRESSION */:59 genCacheExpression(node, context)60 break61 // SSR only types62 case 21 /* JS_BLOCK_STATEMENT */:63 genNodeList(node.body, context, true, false)64 break65 case 22 /* JS_TEMPLATE_LITERAL */:66 genTemplateLiteral(node, context)67 break...
05-genNode.js
Source:05-genNode.js
...44 case NodeTypes.JS_ARRAY_EXPRESSION:45 genArrayExpression(node, context)46 break47 case NodeTypes.JS_FUNCTION_EXPRESSION:48 genFunctionExpression(node, context)49 break50 case NodeTypes.JS_CONDITIONAL_EXPRESSION:51 genConditionalExpression(node, context)52 break53 case NodeTypes.JS_CACHE_EXPRESSION:54 genCacheExpression(node, context)55 break56 case NodeTypes.JS_BLOCK_STATEMENT:57 genNodeList(node.body, context, true, false)58 break59 60 /* istanbul ignore next */61 case NodeTypes.IF_BRANCH:62 // noop...
Using AI Code Generation
1const { genFunctionExpression } = require('playwright/lib/client/functionCall.js');2const { Page } = require('playwright/lib/client/page.js');3const { ElementHandle } = require('playwright/lib/client/elementHandler.js');4const { JSHandle } = require('playwright/lib/client/jsHandle.js');5const page = new Page();6const elementHandle = new ElementHandle();7const expression = genFunctionExpression('function', 'function () {console.log("hello");}');8const functionExpression = expression.toString();9console.log(functionExpression);10const jsHandle = new JSHandle();11jsHandle.evaluate(functionExpression);12const { genObjectExpression } = require('playwright/lib/client/functionCall.js');13const { Page } = require('playwright/lib/client/page.js');14const { ElementHandle } = require('playwright/lib/client/elementHandler.js');15const { JSHandle } = require('playwright/lib/client/jsHandle.js');16const page = new Page();17const elementHandle = new ElementHandle();18const expression = genObjectExpression({ foo: 'bar' });19const objectExpression = expression.toString();20console.log(objectExpression);21const jsHandle = new JSHandle();22jsHandle.evaluate(objectExpression);
Using AI Code Generation
1const { genFunctionExpression } = require('@playwright/test/lib/utils/instrumentation');2const { Page } = require('@playwright/test/lib/server/page');3const { PageProxy } = require('@playwright/test/lib/server/pageProxy');4const { Frame } = require('@playwright/test/lib/server/frame');5const { FrameProxy } = require('@playwright/test/lib/server/frameProxy');6const { Worker } = require('@playwright/test/lib/server/worker');7const { WorkerProxy } = require('@playwright/test/lib/server/workerProxy');8const { BrowserContext } = require('@playwright/test/lib/server/browserContext');9const { BrowserContextProxy } = require('@playwright/test/lib/server/browserContextProxy');10const { Browser } = require('@playwright/test/lib/server/browser');11const { BrowserServer } = require('@playwright/test/lib/server/browserServer');12const { BrowserType } = require('@playwright/test/lib/server/browserType');13const { BrowserTypeProxy } = require('@playwright/test/lib/server/browserTypeProxy');14const { BrowserContextBase } = require('@playwright/test/lib/server/browserContextBase');15const { ChannelOwner } = require('@playwright/test/lib/server/channelOwner');16const { DispatcherConnection } = require('@playwright/test/lib/server/dispatcher');17const { Dispatcher } = require('@playwright/test/lib/server/dispatcher');18const { ConnectionTransport } = require('@playwright/test/lib/server/transport');19const { WebSocketTransport } = require('@playwright/test/lib/server/transport');20const { PipeTransport } = require('@playwright/test/lib/server/transport');21const { Playwright } = require('@playwright/test/lib/server/playwright');22const { PlaywrightDispatcher } = require('@playwright/test/lib/server/playwrightDispatcher');23const { BrowserTypeDispatcher } = require('@playwright/test/lib/server/browserTypeDispatcher');24const { BrowserContextDispatcher } = require('@playwright/test/lib/server/browserContextDispatcher');25const { BrowserDispatcher } = require('@playwright/test/lib/server/browserDispatcher');26const { BrowserServerDispatcher } = require('@playwright/test/lib/server/browserServerDispatcher');27const { PageDispatcher } = require('@playwright/test/lib/server/pageDispatcher');28const { FrameDispatcher } = require('@playwright/test/lib/server/frameDispatcher');29const { WorkerDispatcher } = require('@playwright/test/lib/server/workerDispatcher');30const { ConsoleMessageDispatcher } = require('@playwright/test/lib/server/consoleMessageDispatcher');31const { JS
Using AI Code Generation
1const { genFunctionExpression } = require('playwright/lib/utils/evaluators');2const { genFunctionExpression } = require('playwright/lib/utils/evaluators');3const { genFunctionExpression } = require('playwright/lib/utils/evaluators');4const { genFunctionExpression } = require('playwright/lib/utils/evaluators');5const { genFunctionExpression } = require('playwright/lib/utils/evaluators');6const { genFunctionExpression } = require('playwright/lib/utils/evaluators');7const { genFunctionExpression } = require('playwright/lib/utils/evaluators');8const { genFunctionExpression } = require('playwright/lib/utils/evaluators');9const { genFunctionExpression } = require('playwright/lib/utils/evaluators');10const { genFunctionExpression } = require('playwright/lib/utils/evaluators');11const { genFunctionExpression } = require('playwright/lib/utils/evaluators');12const { genFunctionExpression } = require('playwright/lib/utils/evaluators');13const { genFunctionExpression } = require('playwright/lib/utils/evaluators');14const { genFunctionExpression } = require('playwright/lib/utils/evaluators');15const { genFunctionExpression } = require('playwright-gen-function-expression');
Using AI Code Generation
1const { genFunctionExpression } = require('playwright-core/lib/utils/stackTrace');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const handle = await page.$('div');5 const expression = genFunctionExpression(handle, 'element => element.textContent');6 await page.evaluate(expression);7});
Using AI Code Generation
1const { genFunctionExpression } = require('playwright/lib/utils/selectorParser');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.click(genFunctionExpression('text=Hello World'));5});6test('My test', async ({ page }) => {7});8test('My test', async ({ page }) => {9});10test('My test', async ({ page }) => {11});12test('My test', async ({ page }) => {13});14test('My test', async ({ page }) => {
Using AI Code Generation
1const { genFunctionExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');2const code = genFunctionExpression('click', { button: 'right' });3console.log(code);4const { genFunctionExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');5const code = genFunctionExpression('click', { button: 'right' });6console.log(code);7const { genCallExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');8const code = genCallExpression('click', { button: 'right' });9console.log(code);10const { genCallExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');11const code = genCallExpression('click', { button: 'right' });12console.log(code);13const { genSequenceExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');14const code = genSequenceExpression('click', { button: 'right' });15console.log(code);16const { genSequenceExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');17const code = genSequenceExpression('click', { button: 'right' });18console.log(code);
Using AI Code Generation
1const playwright = require('playwright');2const { genFunctionExpression } = require('playwright/lib/internal/evaluators/Expression.js');3const { assert } = require('console');4const func = genFunctionExpression('return 42');5const result = func();6assert(result === 42);7const playwright = require('playwright');8const { genFunctionExpression } = require('playwright/lib/internal/evaluators/Expression.js');9(async () => {10 const browser = await playwright.chromium.launch();11 const page = await browser.newPage();12 const result = await page.evaluate(genFunctionExpression('return 42'));13 console.log(result);14 await browser.close();15})();
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.
Get 100 minutes of automation test minutes FREE!!