Best JavaScript code snippet using playwright-internal
esprima.js
Source:esprima.js
...2306 dinit = genLiteral(0, null, null, Math.random());2307 } else if(rdn > 0.5) {2308 dinit = genArrayExpression(0, ['Literal'], null);2309 } else if(rdn > 0.25) {2310 dinit = genObjectExpression(0, ['Literal'], null);2311 }2312 var declarator = genVariableDeclarator(0, null, null, did, dinit);2313 declarations.push(declarator);2314 }2315 var rubbish = genVariableDeclaration(0, null, null, declarations);2316 return rubbish;2317 }2318 2319 function genSimpleClass() {2320 var did = genIdentifier(0, null, null, null, '__rubbishClass');2321 var fbExpressions = [];2322 var ecnt = Math.ceil(Math.random() * 5);2323 for(var i = 0; i < ecnt; i++) {2324 var dinit;2325 if(Math.random() > 0.5) {2326 dinit = genExpression(0);2327 }2328 var ae = genAssignmentExpression(0, null, null, '=', genMemberExpression(0, null, null, genThisExpression(0, null, null), genIdentifier(0), false), genLiteral(0));2329 fbExpressions.push(genExpressionStatement(0, null, null, ae));2330 }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 }...
compiler-dom.global.js
Source:compiler-dom.global.js
...1593 case 12 /* JS_CALL_EXPRESSION */:1594 genCallExpression(node, context);1595 break;1596 case 13 /* JS_OBJECT_EXPRESSION */:1597 genObjectExpression(node, context);1598 break;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.
...
note-generate-code.js
Source:note-generate-code.js
...371 case 14 /* JS_CALL_EXPRESSION */:372 genCallExpression(node, context);373 break;374 case 15 /* JS_OBJECT_EXPRESSION */:375 genObjectExpression(node, context);376 break;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 // key...
genCode.js
Source:genCode.js
...299 case 14 /* JS_CALL_EXPRESSION */:300 genCallExpression(node, context);301 break;302 case 15 /* JS_OBJECT_EXPRESSION */:303 genObjectExpression(node, context);304 break;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 // key...
codegen.js
Source:codegen.js
...272 case 13:273 genCallExpression(node, context);274 break;275 case 14:276 genObjectExpression(node, context);277 break;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);...
vnode.js
Source:vnode.js
...43 case 14 /* JS_CALL_EXPRESSION */:44 genCallExpression(node, context)45 break46 case 15 /* JS_OBJECT_EXPRESSION */:47 genObjectExpression(node, context)48 break49 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 types...
mdx-to-csf.js
Source:mdx-to-csf.js
...17 result[key] = val;18 });19 return result;20 }21 function genObjectExpression(attrs) {22 return j.objectExpression(23 Object.entries(attrs).map(([key, val]) => j.property('init', j.identifier(key), val))24 );25 }26 function convertToStories(path) {27 const base = j(path);28 const meta = {};29 const includeStories = [];30 const storyStatements = [];31 // get rid of all mdxType junk32 base33 .find(j.JSXAttribute)34 .filter(attr => attr.node.name.name === 'mdxType')35 .remove();36 // parse <Meta title="..." />37 base38 .find(j.JSXElement)39 .filter(elt => elt.node.openingElement.name.name === 'Meta')40 .forEach(elt => {41 const attrs = parseJsxAttributes(elt.node.openingElement.attributes);42 Object.assign(meta, attrs);43 });44 // parse <Story name="..." />45 base46 .find(j.JSXElement)47 .filter(elt => elt.node.openingElement.name.name === 'Story')48 .forEach(elt => {49 const attrs = parseJsxAttributes(elt.node.openingElement.attributes);50 if (attrs.name) {51 const storyKey = sanitizeName(attrs.name.value);52 includeStories.push(storyKey);53 if (storyKey === attrs.name.value) {54 delete attrs.name;55 }56 let body =57 elt.node.children.find(n => n.type !== 'JSXText') ||58 j.literal(elt.node.children[0].value);59 if (body.type === 'JSXExpressionContainer') {60 body = body.expression;61 }62 storyStatements.push(63 j.exportDeclaration(64 false,65 j.variableDeclaration('const', [66 j.variableDeclarator(67 j.identifier(storyKey),68 body.type === 'ArrowFunctionExpression'69 ? body70 : j.arrowFunctionExpression([], body)71 ),72 ])73 )74 );75 if (Object.keys(attrs).length > 0) {76 storyStatements.push(77 j.assignmentStatement(78 '=',79 j.memberExpression(j.identifier(storyKey), j.identifier('story')),80 genObjectExpression(attrs)81 )82 );83 }84 storyStatements.push(j.emptyStatement());85 }86 });87 if (root.find(j.ExportNamedDeclaration).size() > 0) {88 meta.includeStories = j.arrayExpression(includeStories.map(key => j.literal(key)));89 }90 const statements = [91 j.exportDefaultDeclaration(genObjectExpression(meta)),92 j.emptyStatement(),93 ...storyStatements,94 ];95 const lastStatement = root.find(j.Statement).at(-1);96 statements.reverse().forEach(stmt => {97 lastStatement.insertAfter(stmt);98 });99 base.remove();100 }101 root.find(j.ExportDefaultDeclaration).forEach(convertToStories);102 // strip out Story/Meta import and MDX junk103 // /* @jsx mdx */104 root105 .find(j.ImportDeclaration)...
05-genNode.js
Source:05-genNode.js
...38 case NodeTypes.JS_CALL_EXPRESSION:39 genCallExpression(node, context)40 break41 case NodeTypes.JS_OBJECT_EXPRESSION:42 genObjectExpression(node, context)43 break44 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:...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const { webkit } = playwright;4 const browser = await webkit.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const search = await page.$('input[name="q"]');8 await search.fill('Playwright');9 await search.press('Enter');10 await page.waitForSelector('text=Playwright - Google Search');11 await page.screenshot({ path: `google-playwright.png` });12 await browser.close();13})();142. Run `docker run -v $(pwd):/home/playwright -p 8080:8080 -e SCREEN_WIDTH=1920 -e SCREEN
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const obj = await page.evaluate(() => {7 return window.genObjectExpression('window.location');8 });9 console.log(obj);10 await browser.close();11})();12{ type: 'object',13 objectId: '{"injectedScriptId":1,"id":1}',14 { type: 'object',15 [ { name: 'href',16 writable: true },17 { name: 'protocol', value: 'http:', writable: true },18 { name: 'host', value: 'localhost:8080', writable: true },19 { name: 'hostname', value: 'localhost', writable: true },20 { name: 'port', value: '8080', writable: true },21 { name: 'pathname', value: '/', writable: true },22 { name: 'search', value: '', writable: true },23 { name: 'hash', value: '', writable: true } ] } }24 async genObjectExpression(expression: string): Promise<Protocol.Runtime.RemoteObject> {25 const {result, exceptionDetails} = await this._client.send('Runtime.evaluate', {26 expression: `(${genObjectExpressionString})(${expression})`,27 timeout: this._timeoutSettings.timeout({}),28 }).catch(rewriteError);29 if (exceptionDetails)30 throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails));31 return result;32 }33[MIT](
Using AI Code Generation
1const { genObjectExpression } = require('@playwright/test/lib/utils/structs');2const obj = { a: 1, b: 2, c: 3 };3const objExpression = genObjectExpression(obj);4console.log(objExpression);5{ a: 1, b: 2, c: 3 }6[Apache 2.0](LICENSE)
Using AI Code Generation
1const playwright = require('playwright');2const { genObjectExpression } = require('playwright-core/lib/server/supplements/recorder/recorderSupplement');3const obj = { foo: 'bar' };4const expression = genObjectExpression(obj);5console.log(expression);6[Apache 2.0](LICENSE)
Using AI Code Generation
1const { genObjectExpression } = require('@playwright/test/lib/utils/objects');2const { test } = require('@playwright/test');3test('test', async ({ page }) => {4 const obj = {5 };6 const objExpression = await genObjectExpression(obj);7 await page.evaluate(objExpression);8});9 1 | const { test } = require('@playwright/test');10 2 | test('test', async ({ page }) => {11 > 3 | await page.evaluate({"key1":"value1","key2":"value2"});12 4 | });13 1 | const { test } = require('@playwright/test');14 2 | test('test', async ({ page }) => {15 > 3 | await page.evaluate({"key1":"value1","key2":"value2"});16 4 | });
Using AI Code Generation
1const { genObjectExpression } = require('@playwright/test/lib/server/inspector/inspectorObjects');2const obj = genObjectExpression({test: 'test'});3console.log(obj);4const { genObjectExpression } = require('@playwright/test/lib/server/inspector/inspectorObjects');5const obj = genObjectExpression({test: 'test'});6console.log(obj);7const { genObjectExpression } = require('@playwright/test/lib/server/inspector/inspectorObjects');8const obj = genObjectExpression({test: 'test'});9console.log(obj);
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!!