How to use genNodeListAsArray method in Playwright Internal

Best JavaScript code snippet using playwright-internal

compiler-core.cjs.js

Source:compiler-core.cjs.js Github

copy

Full Screen

...2141 n.type === 2 /* TEXT */ ||2142 n.type === 5 /* INTERPOLATION */ ||2143 n.type === 8 /* COMPOUND_EXPRESSION */);2144}2145function genNodeListAsArray(nodes, context) {2146 const multilines = nodes.length > 3 ||2147 ( nodes.some(n => isArray(n) || !isText$1(n)));2148 context.push(`[`);2149 multilines && context.indent();2150 genNodeList(nodes, context, multilines);2151 multilines && context.deindent();2152 context.push(`]`);2153}2154function genNodeList(nodes, context, multilines = false, comma = true) {2155 const { push, newline } = context;2156 for (let i = 0; i < nodes.length; i++) {2157 const node = nodes[i];2158 if (isString(node)) {2159 push(node);2160 }2161 else if (isArray(node)) {2162 genNodeListAsArray(node, context);2163 }2164 else {2165 genNode(node, context);2166 }2167 if (i < nodes.length - 1) {2168 if (multilines) {2169 comma && push(',');2170 newline();2171 }2172 else {2173 comma && push(', ');2174 }2175 }2176 }2177}2178function genNode(node, context) {2179 if (isString(node)) {2180 context.push(node);2181 return;2182 }2183 if (isSymbol(node)) {2184 context.push(context.helper(node));2185 return;2186 }2187 switch (node.type) {2188 case 1 /* ELEMENT */:2189 case 9 /* IF */:2190 case 11 /* FOR */:2191 2192 assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +2193 `Apply appropriate transforms first.`);2194 genNode(node.codegenNode, context);2195 break;2196 case 2 /* TEXT */:2197 genText(node, context);2198 break;2199 case 4 /* SIMPLE_EXPRESSION */:2200 genExpression(node, context);2201 break;2202 case 5 /* INTERPOLATION */:2203 genInterpolation(node, context);2204 break;2205 case 12 /* TEXT_CALL */:2206 genNode(node.codegenNode, context);2207 break;2208 case 8 /* COMPOUND_EXPRESSION */:2209 genCompoundExpression(node, context);2210 break;2211 case 3 /* COMMENT */:2212 genComment(node, context);2213 break;2214 case 13 /* VNODE_CALL */:2215 genVNodeCall(node, context);2216 break;2217 case 14 /* JS_CALL_EXPRESSION */:2218 genCallExpression(node, context);2219 break;2220 case 15 /* JS_OBJECT_EXPRESSION */:2221 genObjectExpression(node, context);2222 break;2223 case 17 /* JS_ARRAY_EXPRESSION */:2224 genArrayExpression(node, context);2225 break;2226 case 18 /* JS_FUNCTION_EXPRESSION */:2227 genFunctionExpression(node, context);2228 break;2229 case 19 /* JS_CONDITIONAL_EXPRESSION */:2230 genConditionalExpression(node, context);2231 break;2232 case 20 /* JS_CACHE_EXPRESSION */:2233 genCacheExpression(node, context);2234 break;2235 // SSR only types2236 case 21 /* JS_BLOCK_STATEMENT */:2237 genNodeList(node.body, context, true, false);2238 break;2239 case 22 /* JS_TEMPLATE_LITERAL */:2240 genTemplateLiteral(node, context);2241 break;2242 case 23 /* JS_IF_STATEMENT */:2243 genIfStatement(node, context);2244 break;2245 case 24 /* JS_ASSIGNMENT_EXPRESSION */:2246 genAssignmentExpression(node, context);2247 break;2248 case 25 /* JS_RETURN_STATEMENT */:2249 genReturnStatement(node, context);2250 break;2251 /* istanbul ignore next */2252 default:2253 {2254 assert(false, `unhandled codegen node type: ${node.type}`);2255 // make sure we exhaust all possible types2256 const exhaustiveCheck = node;2257 return exhaustiveCheck;2258 }2259 }2260}2261function genText(node, context) {2262 context.push(JSON.stringify(node.content), node);2263}2264function genExpression(node, context) {2265 const { content, isStatic } = node;2266 context.push(isStatic ? JSON.stringify(content) : content, node);2267}2268function genInterpolation(node, context) {2269 const { push, helper } = context;2270 push(`${helper(TO_DISPLAY_STRING)}(`);2271 genNode(node.content, context);2272 push(`)`);2273}2274function genCompoundExpression(node, context) {2275 for (let i = 0; i < node.children.length; i++) {2276 const child = node.children[i];2277 if (isString(child)) {2278 context.push(child);2279 }2280 else {2281 genNode(child, context);2282 }2283 }2284}2285function genExpressionAsPropertyKey(node, context) {2286 const { push } = context;2287 if (node.type === 8 /* COMPOUND_EXPRESSION */) {2288 push(`[`);2289 genCompoundExpression(node, context);2290 push(`]`);2291 }2292 else if (node.isStatic) {2293 // only quote keys if necessary2294 const text = isSimpleIdentifier(node.content)2295 ? node.content2296 : JSON.stringify(node.content);2297 push(text, node);2298 }2299 else {2300 push(`[${node.content}]`, node);2301 }2302}2303function genComment(node, context) {2304 {2305 const { push, helper } = context;2306 push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);2307 }2308}2309function genVNodeCall(node, context) {2310 const { push, helper } = context;2311 const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, isForBlock } = node;2312 if (directives) {2313 push(helper(WITH_DIRECTIVES) + `(`);2314 }2315 if (isBlock) {2316 push(`(${helper(OPEN_BLOCK)}(${isForBlock ? `true` : ``}), `);2317 }2318 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);2319 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);2320 push(`)`);2321 if (isBlock) {2322 push(`)`);2323 }2324 if (directives) {2325 push(`, `);2326 genNode(directives, context);2327 push(`)`);2328 }2329}2330function genNullableArgs(args) {2331 let i = args.length;2332 while (i--) {2333 if (args[i] != null)2334 break;2335 }2336 return args.slice(0, i + 1).map(arg => arg || `null`);2337}2338// JavaScript2339function genCallExpression(node, context) {2340 const callee = isString(node.callee)2341 ? node.callee2342 : context.helper(node.callee);2343 context.push(callee + `(`, node);2344 genNodeList(node.arguments, context);2345 context.push(`)`);2346}2347function genObjectExpression(node, context) {2348 const { push, indent, deindent, newline } = context;2349 const { properties } = node;2350 if (!properties.length) {2351 push(`{}`, node);2352 return;2353 }2354 const multilines = properties.length > 1 ||2355 (2356 properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));2357 push(multilines ? `{` : `{ `);2358 multilines && indent();2359 for (let i = 0; i < properties.length; i++) {2360 const { key, value } = properties[i];2361 // key2362 genExpressionAsPropertyKey(key, context);2363 push(`: `);2364 // value2365 genNode(value, context);2366 if (i < properties.length - 1) {2367 // will only reach this if it's multilines2368 push(`,`);2369 newline();2370 }2371 }2372 multilines && deindent();2373 push(multilines ? `}` : ` }`);2374}2375function genArrayExpression(node, context) {2376 genNodeListAsArray(node.elements, context);2377}2378function genFunctionExpression(node, context) {2379 const { push, indent, deindent, scopeId, mode } = context;2380 const { params, returns, body, newline, isSlot } = node;2381 // slot functions also need to push scopeId before rendering its content2382 const genScopeId = isSlot && scopeId != null && mode !== 'function';2383 if (genScopeId) {2384 push(`_withId(`);2385 }2386 push(`(`, node);2387 if (isArray(params)) {2388 genNodeList(params, context);2389 }2390 else if (params) {2391 genNode(params, context);2392 }2393 push(`) => `);2394 if (newline || body) {2395 push(`{`);2396 indent();2397 }2398 if (returns) {2399 if (newline) {2400 push(`return `);2401 }2402 if (isArray(returns)) {2403 genNodeListAsArray(returns, context);2404 }2405 else {2406 genNode(returns, context);2407 }2408 }2409 else if (body) {2410 genNode(body, context);2411 }2412 if (newline || body) {2413 deindent();2414 push(`}`);2415 }2416 if (genScopeId) {2417 push(`)`);2418 }2419}2420function genConditionalExpression(node, context) {2421 const { test, consequent, alternate, newline: needNewline } = node;2422 const { push, indent, deindent, newline } = context;2423 if (test.type === 4 /* SIMPLE_EXPRESSION */) {2424 const needsParens = !isSimpleIdentifier(test.content);2425 needsParens && push(`(`);2426 genExpression(test, context);2427 needsParens && push(`)`);2428 }2429 else {2430 push(`(`);2431 genNode(test, context);2432 push(`)`);2433 }2434 needNewline && indent();2435 context.indentLevel++;2436 needNewline || push(` `);2437 push(`? `);2438 genNode(consequent, context);2439 context.indentLevel--;2440 needNewline && newline();2441 needNewline || push(` `);2442 push(`: `);2443 const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;2444 if (!isNested) {2445 context.indentLevel++;2446 }2447 genNode(alternate, context);2448 if (!isNested) {2449 context.indentLevel--;2450 }2451 needNewline && deindent(true /* without newline */);2452}2453function genCacheExpression(node, context) {2454 const { push, helper, indent, deindent, newline } = context;2455 push(`_cache[${node.index}] || (`);2456 if (node.isVNode) {2457 indent();2458 push(`${helper(SET_BLOCK_TRACKING)}(-1),`);2459 newline();2460 }2461 push(`_cache[${node.index}] = `);2462 genNode(node.value, context);2463 if (node.isVNode) {2464 push(`,`);2465 newline();2466 push(`${helper(SET_BLOCK_TRACKING)}(1),`);2467 newline();2468 push(`_cache[${node.index}]`);2469 deindent();2470 }2471 push(`)`);2472}2473function genTemplateLiteral(node, context) {2474 const { push, indent, deindent } = context;2475 push('`');2476 const l = node.elements.length;2477 const multilines = l > 3;2478 for (let i = 0; i < l; i++) {2479 const e = node.elements[i];2480 if (isString(e)) {2481 push(e.replace(/`/g, '\\`'));2482 }2483 else {2484 push('${');2485 if (multilines)2486 indent();2487 genNode(e, context);2488 if (multilines)2489 deindent();2490 push('}');2491 }2492 }2493 push('`');2494}2495function genIfStatement(node, context) {2496 const { push, indent, deindent } = context;2497 const { test, consequent, alternate } = node;2498 push(`if (`);2499 genNode(test, context);2500 push(`) {`);2501 indent();2502 genNode(consequent, context);2503 deindent();2504 push(`}`);2505 if (alternate) {2506 push(` else `);2507 if (alternate.type === 23 /* JS_IF_STATEMENT */) {2508 genIfStatement(alternate, context);2509 }2510 else {2511 push(`{`);2512 indent();2513 genNode(alternate, context);2514 deindent();2515 push(`}`);2516 }2517 }2518}2519function genAssignmentExpression(node, context) {2520 genNode(node.left, context);2521 context.push(` = `);2522 genNode(node.right, context);2523}2524function genReturnStatement({ returns }, context) {2525 context.push(`return `);2526 if (isArray(returns)) {2527 genNodeListAsArray(returns, context);2528 }2529 else {2530 genNode(returns, context);2531 }2532}2533const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this');2534const transformExpression = (node, context) => {2535 if (node.type === 5 /* INTERPOLATION */) {2536 node.content = processExpression(node.content, context);2537 }2538 else if (node.type === 1 /* ELEMENT */) {2539 // handle directives on element2540 for (let i = 0; i < node.props.length; i++) {2541 const dir = node.props[i]; ...

Full Screen

Full Screen

compiler-core.cjs.prod.js

Source:compiler-core.cjs.prod.js Github

copy

Full Screen

...2128 n.type === 2 /* TEXT */ ||2129 n.type === 5 /* INTERPOLATION */ ||2130 n.type === 8 /* COMPOUND_EXPRESSION */);2131}2132function genNodeListAsArray(nodes, context) {2133 const multilines = nodes.length > 3 ||2134 ( nodes.some(n => isArray(n) || !isText$1(n)));2135 context.push(`[`);2136 multilines && context.indent();2137 genNodeList(nodes, context, multilines);2138 multilines && context.deindent();2139 context.push(`]`);2140}2141function genNodeList(nodes, context, multilines = false, comma = true) {2142 const { push, newline } = context;2143 for (let i = 0; i < nodes.length; i++) {2144 const node = nodes[i];2145 if (isString(node)) {2146 push(node);2147 }2148 else if (isArray(node)) {2149 genNodeListAsArray(node, context);2150 }2151 else {2152 genNode(node, context);2153 }2154 if (i < nodes.length - 1) {2155 if (multilines) {2156 comma && push(',');2157 newline();2158 }2159 else {2160 comma && push(', ');2161 }2162 }2163 }2164}2165function genNode(node, context) {2166 if (isString(node)) {2167 context.push(node);2168 return;2169 }2170 if (isSymbol(node)) {2171 context.push(context.helper(node));2172 return;2173 }2174 switch (node.type) {2175 case 1 /* ELEMENT */:2176 case 9 /* IF */:2177 case 11 /* FOR */:2178 genNode(node.codegenNode, context);2179 break;2180 case 2 /* TEXT */:2181 genText(node, context);2182 break;2183 case 4 /* SIMPLE_EXPRESSION */:2184 genExpression(node, context);2185 break;2186 case 5 /* INTERPOLATION */:2187 genInterpolation(node, context);2188 break;2189 case 12 /* TEXT_CALL */:2190 genNode(node.codegenNode, context);2191 break;2192 case 8 /* COMPOUND_EXPRESSION */:2193 genCompoundExpression(node, context);2194 break;2195 case 3 /* COMMENT */:2196 break;2197 case 13 /* VNODE_CALL */:2198 genVNodeCall(node, context);2199 break;2200 case 14 /* JS_CALL_EXPRESSION */:2201 genCallExpression(node, context);2202 break;2203 case 15 /* JS_OBJECT_EXPRESSION */:2204 genObjectExpression(node, context);2205 break;2206 case 17 /* JS_ARRAY_EXPRESSION */:2207 genArrayExpression(node, context);2208 break;2209 case 18 /* JS_FUNCTION_EXPRESSION */:2210 genFunctionExpression(node, context);2211 break;2212 case 19 /* JS_CONDITIONAL_EXPRESSION */:2213 genConditionalExpression(node, context);2214 break;2215 case 20 /* JS_CACHE_EXPRESSION */:2216 genCacheExpression(node, context);2217 break;2218 // SSR only types2219 case 21 /* JS_BLOCK_STATEMENT */:2220 genNodeList(node.body, context, true, false);2221 break;2222 case 22 /* JS_TEMPLATE_LITERAL */:2223 genTemplateLiteral(node, context);2224 break;2225 case 23 /* JS_IF_STATEMENT */:2226 genIfStatement(node, context);2227 break;2228 case 24 /* JS_ASSIGNMENT_EXPRESSION */:2229 genAssignmentExpression(node, context);2230 break;2231 case 25 /* JS_RETURN_STATEMENT */:2232 genReturnStatement(node, context);2233 break;2234 }2235}2236function genText(node, context) {2237 context.push(JSON.stringify(node.content), node);2238}2239function genExpression(node, context) {2240 const { content, isStatic } = node;2241 context.push(isStatic ? JSON.stringify(content) : content, node);2242}2243function genInterpolation(node, context) {2244 const { push, helper } = context;2245 push(`${helper(TO_DISPLAY_STRING)}(`);2246 genNode(node.content, context);2247 push(`)`);2248}2249function genCompoundExpression(node, context) {2250 for (let i = 0; i < node.children.length; i++) {2251 const child = node.children[i];2252 if (isString(child)) {2253 context.push(child);2254 }2255 else {2256 genNode(child, context);2257 }2258 }2259}2260function genExpressionAsPropertyKey(node, context) {2261 const { push } = context;2262 if (node.type === 8 /* COMPOUND_EXPRESSION */) {2263 push(`[`);2264 genCompoundExpression(node, context);2265 push(`]`);2266 }2267 else if (node.isStatic) {2268 // only quote keys if necessary2269 const text = isSimpleIdentifier(node.content)2270 ? node.content2271 : JSON.stringify(node.content);2272 push(text, node);2273 }2274 else {2275 push(`[${node.content}]`, node);2276 }2277}2278function genVNodeCall(node, context) {2279 const { push, helper } = context;2280 const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, isForBlock } = node;2281 if (directives) {2282 push(helper(WITH_DIRECTIVES) + `(`);2283 }2284 if (isBlock) {2285 push(`(${helper(OPEN_BLOCK)}(${isForBlock ? `true` : ``}), `);2286 }2287 push(helper(isBlock ? CREATE_BLOCK : CREATE_VNODE) + `(`, node);2288 genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);2289 push(`)`);2290 if (isBlock) {2291 push(`)`);2292 }2293 if (directives) {2294 push(`, `);2295 genNode(directives, context);2296 push(`)`);2297 }2298}2299function genNullableArgs(args) {2300 let i = args.length;2301 while (i--) {2302 if (args[i] != null)2303 break;2304 }2305 return args.slice(0, i + 1).map(arg => arg || `null`);2306}2307// JavaScript2308function genCallExpression(node, context) {2309 const callee = isString(node.callee)2310 ? node.callee2311 : context.helper(node.callee);2312 context.push(callee + `(`, node);2313 genNodeList(node.arguments, context);2314 context.push(`)`);2315}2316function genObjectExpression(node, context) {2317 const { push, indent, deindent, newline } = context;2318 const { properties } = node;2319 if (!properties.length) {2320 push(`{}`, node);2321 return;2322 }2323 const multilines = properties.length > 1 ||2324 (2325 properties.some(p => p.value.type !== 4 /* SIMPLE_EXPRESSION */));2326 push(multilines ? `{` : `{ `);2327 multilines && indent();2328 for (let i = 0; i < properties.length; i++) {2329 const { key, value } = properties[i];2330 // key2331 genExpressionAsPropertyKey(key, context);2332 push(`: `);2333 // value2334 genNode(value, context);2335 if (i < properties.length - 1) {2336 // will only reach this if it's multilines2337 push(`,`);2338 newline();2339 }2340 }2341 multilines && deindent();2342 push(multilines ? `}` : ` }`);2343}2344function genArrayExpression(node, context) {2345 genNodeListAsArray(node.elements, context);2346}2347function genFunctionExpression(node, context) {2348 const { push, indent, deindent, scopeId, mode } = context;2349 const { params, returns, body, newline, isSlot } = node;2350 // slot functions also need to push scopeId before rendering its content2351 const genScopeId = isSlot && scopeId != null && mode !== 'function';2352 if (genScopeId) {2353 push(`_withId(`);2354 }2355 push(`(`, node);2356 if (isArray(params)) {2357 genNodeList(params, context);2358 }2359 else if (params) {2360 genNode(params, context);2361 }2362 push(`) => `);2363 if (newline || body) {2364 push(`{`);2365 indent();2366 }2367 if (returns) {2368 if (newline) {2369 push(`return `);2370 }2371 if (isArray(returns)) {2372 genNodeListAsArray(returns, context);2373 }2374 else {2375 genNode(returns, context);2376 }2377 }2378 else if (body) {2379 genNode(body, context);2380 }2381 if (newline || body) {2382 deindent();2383 push(`}`);2384 }2385 if (genScopeId) {2386 push(`)`);2387 }2388}2389function genConditionalExpression(node, context) {2390 const { test, consequent, alternate, newline: needNewline } = node;2391 const { push, indent, deindent, newline } = context;2392 if (test.type === 4 /* SIMPLE_EXPRESSION */) {2393 const needsParens = !isSimpleIdentifier(test.content);2394 needsParens && push(`(`);2395 genExpression(test, context);2396 needsParens && push(`)`);2397 }2398 else {2399 push(`(`);2400 genNode(test, context);2401 push(`)`);2402 }2403 needNewline && indent();2404 context.indentLevel++;2405 needNewline || push(` `);2406 push(`? `);2407 genNode(consequent, context);2408 context.indentLevel--;2409 needNewline && newline();2410 needNewline || push(` `);2411 push(`: `);2412 const isNested = alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */;2413 if (!isNested) {2414 context.indentLevel++;2415 }2416 genNode(alternate, context);2417 if (!isNested) {2418 context.indentLevel--;2419 }2420 needNewline && deindent(true /* without newline */);2421}2422function genCacheExpression(node, context) {2423 const { push, helper, indent, deindent, newline } = context;2424 push(`_cache[${node.index}] || (`);2425 if (node.isVNode) {2426 indent();2427 push(`${helper(SET_BLOCK_TRACKING)}(-1),`);2428 newline();2429 }2430 push(`_cache[${node.index}] = `);2431 genNode(node.value, context);2432 if (node.isVNode) {2433 push(`,`);2434 newline();2435 push(`${helper(SET_BLOCK_TRACKING)}(1),`);2436 newline();2437 push(`_cache[${node.index}]`);2438 deindent();2439 }2440 push(`)`);2441}2442function genTemplateLiteral(node, context) {2443 const { push, indent, deindent } = context;2444 push('`');2445 const l = node.elements.length;2446 const multilines = l > 3;2447 for (let i = 0; i < l; i++) {2448 const e = node.elements[i];2449 if (isString(e)) {2450 push(e.replace(/`/g, '\\`'));2451 }2452 else {2453 push('${');2454 if (multilines)2455 indent();2456 genNode(e, context);2457 if (multilines)2458 deindent();2459 push('}');2460 }2461 }2462 push('`');2463}2464function genIfStatement(node, context) {2465 const { push, indent, deindent } = context;2466 const { test, consequent, alternate } = node;2467 push(`if (`);2468 genNode(test, context);2469 push(`) {`);2470 indent();2471 genNode(consequent, context);2472 deindent();2473 push(`}`);2474 if (alternate) {2475 push(` else `);2476 if (alternate.type === 23 /* JS_IF_STATEMENT */) {2477 genIfStatement(alternate, context);2478 }2479 else {2480 push(`{`);2481 indent();2482 genNode(alternate, context);2483 deindent();2484 push(`}`);2485 }2486 }2487}2488function genAssignmentExpression(node, context) {2489 genNode(node.left, context);2490 context.push(` = `);2491 genNode(node.right, context);2492}2493function genReturnStatement({ returns }, context) {2494 context.push(`return `);2495 if (isArray(returns)) {2496 genNodeListAsArray(returns, context);2497 }2498 else {2499 genNode(returns, context);2500 }2501}2502const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this');2503const transformExpression = (node, context) => {2504 if (node.type === 5 /* INTERPOLATION */) {2505 node.content = processExpression(node.content, context);2506 }2507 else if (node.type === 1 /* ELEMENT */) {2508 // handle directives on element2509 for (let i = 0; i < node.props.length; i++) {2510 const dir = node.props[i]; ...

Full Screen

Full Screen

compiler-dom.global.js

Source:compiler-dom.global.js Github

copy

Full Screen

...1523 n.type === 2 /* TEXT */ ||1524 n.type === 5 /* INTERPOLATION */ ||1525 n.type === 8 /* COMPOUND_EXPRESSION */);1526 }1527 function genNodeListAsArray(nodes, context) {1528 const multilines = nodes.length > 3 ||1529 ( nodes.some(n => isArray(n) || !isText(n)));1530 context.push(`[`);1531 multilines && context.indent();1532 genNodeList(nodes, context, multilines);1533 multilines && context.deindent();1534 context.push(`]`);1535 }1536 function genNodeList(nodes, context, multilines = false) {1537 const { push, newline } = context;1538 for (let i = 0; i < nodes.length; i++) {1539 const node = nodes[i];1540 if (isString(node)) {1541 push(node);1542 }1543 else if (isArray(node)) {1544 genNodeListAsArray(node, context);1545 }1546 else {1547 genNode(node, context);1548 }1549 if (i < nodes.length - 1) {1550 if (multilines) {1551 push(',');1552 newline();1553 }1554 else {1555 push(', ');1556 }1557 }1558 }1559 }1560 function genNode(node, context) {1561 if (isString(node)) {1562 context.push(node);1563 return;1564 }1565 if (isSymbol(node)) {1566 context.push(context.helper(node));1567 return;1568 }1569 switch (node.type) {1570 case 1 /* ELEMENT */:1571 case 9 /* IF */:1572 case 11 /* FOR */:1573 1574 assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +1575 `Apply appropriate transforms first.`);1576 genNode(node.codegenNode, context);1577 break;1578 case 2 /* TEXT */:1579 genText(node, context);1580 break;1581 case 4 /* SIMPLE_EXPRESSION */:1582 genExpression(node, context);1583 break;1584 case 5 /* INTERPOLATION */:1585 genInterpolation(node, context);1586 break;1587 case 8 /* COMPOUND_EXPRESSION */:1588 genCompoundExpression(node, context);1589 break;1590 case 3 /* COMMENT */:1591 genComment(node, context);1592 break;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.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 `);1726 }1727 if (isArray(returns)) {1728 genNodeListAsArray(returns, context);1729 }1730 else {1731 genNode(returns, context);1732 }1733 if (newline) {1734 deindent();1735 push(`}`);1736 }1737 }1738 function genConditionalExpression(node, context) {1739 const { test, consequent, alternate } = node;1740 const { push, indent, deindent, newline } = context;1741 if (test.type === 4 /* SIMPLE_EXPRESSION */) {1742 const needsParens = !isSimpleIdentifier(test.content); ...

Full Screen

Full Screen

compiler-dom.esm-browser.js

Source:compiler-dom.esm-browser.js Github

copy

Full Screen

...1521 n.type === 2 /* TEXT */ ||1522 n.type === 5 /* INTERPOLATION */ ||1523 n.type === 8 /* COMPOUND_EXPRESSION */);1524}1525function genNodeListAsArray(nodes, context) {1526 const multilines = nodes.length > 3 ||1527 ( nodes.some(n => isArray(n) || !isText(n)));1528 context.push(`[`);1529 multilines && context.indent();1530 genNodeList(nodes, context, multilines);1531 multilines && context.deindent();1532 context.push(`]`);1533}1534function genNodeList(nodes, context, multilines = false) {1535 const { push, newline } = context;1536 for (let i = 0; i < nodes.length; i++) {1537 const node = nodes[i];1538 if (isString(node)) {1539 push(node);1540 }1541 else if (isArray(node)) {1542 genNodeListAsArray(node, context);1543 }1544 else {1545 genNode(node, context);1546 }1547 if (i < nodes.length - 1) {1548 if (multilines) {1549 push(',');1550 newline();1551 }1552 else {1553 push(', ');1554 }1555 }1556 }1557}1558function genNode(node, context) {1559 if (isString(node)) {1560 context.push(node);1561 return;1562 }1563 if (isSymbol(node)) {1564 context.push(context.helper(node));1565 return;1566 }1567 switch (node.type) {1568 case 1 /* ELEMENT */:1569 case 9 /* IF */:1570 case 11 /* FOR */:1571 1572 assert(node.codegenNode != null, `Codegen node is missing for element/if/for node. ` +1573 `Apply appropriate transforms first.`);1574 genNode(node.codegenNode, context);1575 break;1576 case 2 /* TEXT */:1577 genText(node, context);1578 break;1579 case 4 /* SIMPLE_EXPRESSION */:1580 genExpression(node, context);1581 break;1582 case 5 /* INTERPOLATION */:1583 genInterpolation(node, context);1584 break;1585 case 8 /* COMPOUND_EXPRESSION */:1586 genCompoundExpression(node, context);1587 break;1588 case 3 /* COMMENT */:1589 genComment(node, context);1590 break;1591 case 12 /* JS_CALL_EXPRESSION */:1592 genCallExpression(node, context);1593 break;1594 case 13 /* JS_OBJECT_EXPRESSION */:1595 genObjectExpression(node, context);1596 break;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 `);1724 }1725 if (isArray(returns)) {1726 genNodeListAsArray(returns, context);1727 }1728 else {1729 genNode(returns, context);1730 }1731 if (newline) {1732 deindent();1733 push(`}`);1734 }1735}1736function genConditionalExpression(node, context) {1737 const { test, consequent, alternate } = node;1738 const { push, indent, deindent, newline } = context;1739 if (test.type === 4 /* SIMPLE_EXPRESSION */) {1740 const needsParens = !isSimpleIdentifier(test.content); ...

Full Screen

Full Screen

note-generate-code.js

Source:note-generate-code.js Github

copy

Full Screen

...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) {873 push(`{`);874 indent();875 }876 if (returns) {877 if (newline) {878 push(`return `);879 }880 if (isArray(returns)) {881 genNodeListAsArray(returns, context);882 }883 else {884 genNode(returns, context);885 }886 }887 else if (body) {888 genNode(body, context);889 }890 if (newline || body) {891 deindent();892 push(`}`);893 }894 if ( isSlot) {895 push(`)`);...

Full Screen

Full Screen

genCode.js

Source:genCode.js Github

copy

Full Screen

...224 n.type === 5 /* INTERPOLATION */ ||225 n.type === 8 /* COMPOUND_EXPRESSION */226 );227}228function genNodeListAsArray(nodes, context) {229 const multilines =230 nodes.length > 3 || (process.env.NODE_ENV !== 'production' && nodes.some((n) => isArray(n) || !isText$1(n)));231 context.push(`[`);232 multilines && context.indent();233 genNodeList(nodes, context, multilines);234 multilines && context.deindent();235 context.push(`]`);236}237function genNodeList(nodes, context, multilines = false, comma = true) {238 const { push, newline } = context;239 for (let i = 0; i < nodes.length; i++) {240 const node = nodes[i];241 if (isString(node)) {242 push(node);243 } else if (isArray(node)) {244 genNodeListAsArray(node, context);245 } else {246 genNode(node, context);247 }248 if (i < nodes.length - 1) {249 if (multilines) {250 comma && push(',');251 newline();252 } else {253 comma && push(', ');254 }255 }256 }257}258function genNode(node, context) {259 if (isString(node)) {260 context.push(node);261 return;262 }263 if (isSymbol(node)) {264 context.push(context.helper(node));265 return;266 }267 switch (node.type) {268 case 1 /* ELEMENT */:269 case 9 /* IF */:270 case 11 /* FOR */:271 process.env.NODE_ENV !== 'production' &&272 assert(273 node.codegenNode != null,274 `Codegen node is missing for element/if/for node. ` + `Apply appropriate transforms first.`275 );276 genNode(node.codegenNode, context);277 break;278 case 2 /* TEXT */:279 genText(node, context);280 break;281 case 4 /* SIMPLE_EXPRESSION */:282 genExpression(node, context);283 break;284 case 5 /* INTERPOLATION */:285 genInterpolation(node, context);286 break;287 case 12 /* TEXT_CALL */:288 genNode(node.codegenNode, context);289 break;290 case 8 /* COMPOUND_EXPRESSION */:291 genCompoundExpression(node, context);292 break;293 case 3 /* COMMENT */:294 genComment(node, context);295 break;296 case 13 /* VNODE_CALL */:297 genVNodeCall(node, context);298 break;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 // 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) {483 push(`{`);484 indent();485 }486 if (returns) {487 if (newline) {488 push(`return `);489 }490 if (isArray(returns)) {491 genNodeListAsArray(returns, context);492 } else {493 genNode(returns, context);494 }495 } else if (body) {496 genNode(body, context);497 }498 if (newline || body) {499 deindent();500 push(`}`);501 }502 if (isSlot) {503 push(`)`);504 }505}...

Full Screen

Full Screen

codegen.js

Source:codegen.js Github

copy

Full Screen

...198 n.type === 2 ||199 n.type === 5 ||200 n.type === 8);201}202function genNodeListAsArray(nodes, context) {203 var multilines = nodes.length > 3 ||204 ((!__BROWSER__ || true) && nodes.some(function (n) { return shared_1.isArray(n) || !isText(n); }));205 context.push("[");206 multilines && context.indent();207 genNodeList(nodes, context, multilines);208 multilines && context.deindent();209 context.push("]");210}211function genNodeList(nodes, context, multilines) {212 if (multilines === void 0) { multilines = false; }213 var push = context.push, newline = context.newline;214 for (var i = 0; i < nodes.length; i++) {215 var node = nodes[i];216 if (shared_1.isString(node)) {217 push(node);218 }219 else if (shared_1.isArray(node)) {220 genNodeListAsArray(node, context);221 }222 else {223 genNode(node, context);224 }225 if (i < nodes.length - 1) {226 if (multilines) {227 push(',');228 newline();229 }230 else {231 push(', ');232 }233 }234 }235}236function genNode(node, context) {237 if (shared_1.isString(node)) {238 context.push(node);239 return;240 }241 if (shared_1.isSymbol(node)) {242 context.push(context.helper(node));243 return;244 }245 switch (node.type) {246 case 1:247 case 9:248 case 11:249 true &&250 utils_1.assert(node.codegenNode != null, "Codegen node is missing for element/if/for node. " +251 "Apply appropriate transforms first.");252 genNode(node.codegenNode, context);253 break;254 case 2:255 genText(node, context);256 break;257 case 4:258 genExpression(node, context);259 break;260 case 5:261 genInterpolation(node, context);262 break;263 case 12:264 genNode(node.codegenNode, context);265 break;266 case 8:267 genCompoundExpression(node, context);268 break;269 case 3:270 genComment(node, context);271 break;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);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 ");401 }402 if (shared_1.isArray(returns)) {403 genNodeListAsArray(returns, context);404 }405 else {406 genNode(returns, context);407 }408 if (newline) {409 deindent();410 push("}");411 }412}413function genConditionalExpression(node, context) {414 var test = node.test, consequent = node.consequent, alternate = node.alternate;415 var push = context.push, indent = context.indent, deindent = context.deindent, newline = context.newline;416 if (test.type === 4) {417 var needsParens = !utils_1.isSimpleIdentifier(test.content);...

Full Screen

Full Screen

vnode.js

Source:vnode.js Github

copy

Full Screen

...118 if (shared.isString(node)) {119 push(node)120 }121 else if (shared.isArray(node)) {122 genNodeListAsArray(node, context)123 }124 else {125 genNode(node, context)126 }127 if (i < nodes.length - 1) {128 if (multilines) {129 comma && push(',')130 newline()131 }132 else {133 comma && push(', ')134 }135 }136 }137}138function genExpression(node, context) {139 const { content, isStatic } = node140 context.push(isStatic ? JSON.stringify(content) : content, node)141}142function genNodeListAsArray(nodes, context) {143 const multilines = nodes.length > 3 || nodes.some(n => isArray(n) || !isText$1(n))144 context.push(`[`)145 multilines && context.indent()146 genNodeList(nodes, context, multilines);147 multilines && context.deindent()148 context.push(`]`)149}150function genConditionalExpression(node, context) {151 const { test, consequent, alternate, newline: needNewline } = node152 const { push, indent, deindent, newline } = context153 // 生成条件表达式154 if (test.type === 4 /* SIMPLE_EXPRESSION */) {155 const needsParens = !isSimpleIdentifier(test.content)156 needsParens && push(`(`)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/client/helper');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const elementsArray = await genNodeListAsArray(elements);8 console.log(elementsArray);9 await browser.close();10})();11 ElementHandle {12 _context: BrowserContext {13 },14 _handle: JSHandle {15 }16 },17 ElementHandle {18 _context: BrowserContext {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const elements = await page.$$('a');8 const elementsArray = genNodeListAsArray(elements);9 console.log(elementsArray);10 await browser.close();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/client/helper');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const input = await page.$('input[name=q]');8 await input.type('playwright');9 const results = await page.$$('.b_algo');10 const resultText = await genNodeListAsArray(results, node => node.textContent);11 console.log(resultText);12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/server/dom');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const elements = await page.$$('text=Get Started');7 const array = await genNodeListAsArray(elements);8 console.log(array);9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require("playwright/lib/server/dom.js");2const { chromium } = require("playwright");3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const searchBox = await page.$("input[name='q']");8 const searchBoxValue = await searchBox.getAttribute("value");9 console.log(searchBoxValue);10 const searchBoxSiblings = await genNodeListAsArray(11 (el) => el.parentNode.children12 );13 console.log(searchBoxSiblings);14 await browser.close();15})();16 title="Search" value="google" class="gLFyf gsfi" jsaction="paste:puy29d;"

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');2const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');3const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');4const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');5const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');6const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');7const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');8const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');9const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');10const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');11const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');12const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');13const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');14const { genNodeListAsArray } = require('./node_modules/playwright/lib/server/dom.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright-core/lib/server/supplements/utils/selectorEvaluation');2const { chromium } = require('playwright-core');3const path = require('path');4(async () => {5 const browser = await chromium.launch({ headless: false });6 const page = await browser.newPage();7 await page.fill('input[name="q"]', 'playwright');8 await page.keyboard.press('Enter');9 await page.waitForNavigation();10 const links = await page.$$('a');11 const linkTexts = await genNodeListAsArray(links, n => n.innerText);12 console.log(linkTexts);13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/server/dom.js');2const nodeList = document.querySelectorAll('a');3const array = genNodeListAsArray(nodeList);4console.log(array);5const { genNodeListAsArray } = require('playwright/lib/server/dom.js');6const nodeList = document.querySelectorAll('a');7const array = genNodeListAsArray(nodeList);8console.log(array);9const { genNodeListAsArray } = require('playwright/lib/server/dom.js');10const nodeList = document.querySelectorAll('a');11const array = genNodeListAsArray(nodeList);12console.log(array);13const { genNodeListAsArray } = require('playwright/lib/server/dom.js');14const nodeList = document.querySelectorAll('a');15const array = genNodeListAsArray(nodeList);16console.log(array);17const { genNodeListAsArray } = require('playwright/lib/server/dom.js');18const nodeList = document.querySelectorAll('a');19const array = genNodeListAsArray(nodeList);20console.log(array);21const { genNodeListAsArray } = require('playwright/lib/server/dom.js');22const nodeList = document.querySelectorAll('a');23const array = genNodeListAsArray(nodeList);24console.log(array);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');2const nodeList = await genNodeListAsArray();3console.log(nodeList);4const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');5const nodeList = await genNodeListAsArray();6console.log(nodeList);7const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');8const nodeList = await genNodeListAsArray();9console.log(nodeList);10const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');11const nodeList = await genNodeListAsArray();12console.log(nodeList);13const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');14const nodeList = await genNodeListAsArray();15console.log(nodeList);16const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');17const nodeList = await genNodeListAsArray();18console.log(nodeList);19const { genNodeListAsArray } = require('playwright/lib/server/supplements/recorder/recorderSupplement');20const nodeList = await genNodeListAsArray();21console.log(nodeList);

Full Screen

Playwright tutorial

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

Chapters:

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

Run Playwright Internal automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful