How to use isVSlot method in Playwright Internal

Best JavaScript code snippet using playwright-internal

compiler-dom.global.js

Source:compiler-dom.global.js Github

copy

Full Screen

...379 createCallExpression(context.helper(OPEN_BLOCK)),380 blockExp381 ]);382 }383 function isVSlot(p) {384 return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';385 }386 function isTemplateNode(node) {387 return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);388 }389 function isSlotOutlet(node) {390 return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;391 }392 function injectProp(node, prop, context) {393 let propsWithInjection;394 const props = node.callee === RENDER_SLOT ? node.arguments[2] : node.arguments[1];395 if (props == null || isString(props)) {396 propsWithInjection = createObjectExpression([prop]);397 }...

Full Screen

Full Screen

compiler-core.cjs.js

Source:compiler-core.cjs.js Github

copy

Full Screen

...383 createCallExpression(context.helper(OPEN_BLOCK)),384 blockExp385 ]);386}387function isVSlot(p) {388 return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';389}390function isTemplateNode(node) {391 return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);392}393function isSlotOutlet(node) {394 return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;395}396function injectProp(node, prop, context) {397 let propsWithInjection;398 const props = node.callee === RENDER_SLOT ? node.arguments[2] : node.arguments[1];399 if (props == null || isString(props)) {400 propsWithInjection = createObjectExpression([prop]);401 }...

Full Screen

Full Screen

compiler-core.cjs.prod.js

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

copy

Full Screen

...379 createCallExpression(context.helper(OPEN_BLOCK)),380 blockExp381 ]);382}383function isVSlot(p) {384 return p.type === 7 /* DIRECTIVE */ && p.name === 'slot';385}386function isTemplateNode(node) {387 return (node.type === 1 /* ELEMENT */ && node.tagType === 3 /* TEMPLATE */);388}389function isSlotOutlet(node) {390 return node.type === 1 /* ELEMENT */ && node.tagType === 2 /* SLOT */;391}392function injectProp(node, prop, context) {393 let propsWithInjection;394 const props = node.callee === RENDER_SLOT ? node.arguments[2] : node.arguments[1];395 if (props == null || isString(props)) {396 propsWithInjection = createObjectExpression([prop]);397 }...

Full Screen

Full Screen

transformElement.js

Source:transformElement.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3var ast_1 = require("../ast");4var shared_1 = require("@vue/shared");5var errors_1 = require("../errors");6var runtimeHelpers_1 = require("../runtimeHelpers");7var utils_1 = require("../utils");8var vSlot_1 = require("./vSlot");9var hoistStatic_1 = require("./hoistStatic");10var directiveImportMap = new WeakMap();11exports.transformElement = function (node, context) {12 if (node.type !== 1 ||13 node.tagType === 2 ||14 (node.tagType === 3 && node.props.some(utils_1.isVSlot))) {15 return;16 }17 return function () {18 var isComponent = node.tagType === 1;19 var hasProps = node.props.length > 0;20 var patchFlag = 0;21 var runtimeDirectives;22 var dynamicPropNames;23 var dynamicComponent;24 var isProp = utils_1.findProp(node, 'is');25 if (node.tag === 'component') {26 if (isProp) {27 if (isProp.type === 6) {28 var tag = isProp.value && isProp.value.content;29 if (tag) {30 context.helper(runtimeHelpers_1.RESOLVE_COMPONENT);31 context.components.add(tag);32 dynamicComponent = utils_1.toValidAssetId(tag, "component");33 }34 }35 else if (isProp.exp) {36 dynamicComponent = ast_1.createCallExpression(context.helper(runtimeHelpers_1.RESOLVE_DYNAMIC_COMPONENT), [isProp.exp]);37 }38 }39 }40 if (isComponent && !dynamicComponent) {41 context.helper(runtimeHelpers_1.RESOLVE_COMPONENT);42 context.components.add(node.tag);43 }44 var args = [45 dynamicComponent46 ? dynamicComponent47 : isComponent48 ? utils_1.toValidAssetId(node.tag, "component")49 : node.tagType === 450 ? context.helper(runtimeHelpers_1.PORTAL)51 : node.tagType === 552 ? context.helper(runtimeHelpers_1.SUSPENSE)53 : "\"" + node.tag + "\""54 ];55 if (hasProps) {56 var propsBuildResult = buildProps(node, context, node.props.filter(function (p) { return p !== isProp; }));57 patchFlag = propsBuildResult.patchFlag;58 dynamicPropNames = propsBuildResult.dynamicPropNames;59 runtimeDirectives = propsBuildResult.directives;60 if (!propsBuildResult.props) {61 hasProps = false;62 }63 else {64 args.push(propsBuildResult.props);65 }66 }67 var hasChildren = node.children.length > 0;68 if (hasChildren) {69 if (!hasProps) {70 args.push("null");71 }72 if (isComponent || node.tagType === 5) {73 var _a = vSlot_1.buildSlots(node, context), slots = _a.slots, hasDynamicSlots = _a.hasDynamicSlots;74 args.push(slots);75 if (hasDynamicSlots) {76 patchFlag |= shared_1.PatchFlags.DYNAMIC_SLOTS;77 }78 }79 else if (node.children.length === 1) {80 var child = node.children[0];81 var type = child.type;82 var hasDynamicTextChild = type === 5 ||83 type === 8;84 if (hasDynamicTextChild && !hoistStatic_1.isStaticNode(child)) {85 patchFlag |= shared_1.PatchFlags.TEXT;86 }87 if (hasDynamicTextChild || type === 2) {88 args.push(child);89 }90 else {91 args.push(node.children);92 }93 }94 else {95 args.push(node.children);96 }97 }98 if (patchFlag !== 0) {99 if (!hasChildren) {100 if (!hasProps) {101 args.push("null");102 }103 args.push("null");104 }105 if (__DEV__) {106 var flagNames = Object.keys(shared_1.PatchFlagNames)107 .map(Number)108 .filter(function (n) { return n > 0 && patchFlag & n; })109 .map(function (n) { return shared_1.PatchFlagNames[n]; })110 .join(", ");111 args.push(patchFlag + (" /* " + flagNames + " */"));112 }113 else {114 args.push(patchFlag + '');115 }116 if (dynamicPropNames && dynamicPropNames.length) {117 args.push("[" + dynamicPropNames.map(function (n) { return JSON.stringify(n); }).join(", ") + "]");118 }119 }120 var loc = node.loc;121 var vnode = ast_1.createCallExpression(context.helper(runtimeHelpers_1.CREATE_VNODE), args, loc);122 if (runtimeDirectives && runtimeDirectives.length) {123 node.codegenNode = ast_1.createCallExpression(context.helper(runtimeHelpers_1.WITH_DIRECTIVES), [124 vnode,125 ast_1.createArrayExpression(runtimeDirectives.map(function (dir) { return buildDirectiveArgs(dir, context); }), loc)126 ], loc);127 }128 else {129 node.codegenNode = vnode;130 }131 };132};133function buildProps(node, context, props) {134 if (props === void 0) { props = node.props; }135 var elementLoc = node.loc;136 var isComponent = node.tagType === 1;137 var properties = [];138 var mergeArgs = [];139 var runtimeDirectives = [];140 var patchFlag = 0;141 var hasRef = false;142 var hasClassBinding = false;143 var hasStyleBinding = false;144 var hasDynamicKeys = false;145 var dynamicPropNames = [];146 var analyzePatchFlag = function (_a) {147 var key = _a.key, value = _a.value;148 if (key.type === 4 && key.isStatic) {149 if (value.type === 20 ||150 ((value.type === 4 ||151 value.type === 8) &&152 hoistStatic_1.isStaticNode(value))) {153 return;154 }155 var name_1 = key.content;156 if (name_1 === 'ref') {157 hasRef = true;158 }159 else if (name_1 === 'class') {160 hasClassBinding = true;161 }162 else if (name_1 === 'style') {163 hasStyleBinding = true;164 }165 else if (name_1 !== 'key') {166 dynamicPropNames.push(name_1);167 }168 }169 else {170 hasDynamicKeys = true;171 }172 };173 for (var i = 0; i < props.length; i++) {174 var prop = props[i];175 if (prop.type === 6) {176 var loc = prop.loc, name_2 = prop.name, value = prop.value;177 if (name_2 === 'ref') {178 hasRef = true;179 }180 properties.push(ast_1.createObjectProperty(ast_1.createSimpleExpression(name_2, true, utils_1.getInnerRange(loc, 0, name_2.length)), ast_1.createSimpleExpression(value ? value.content : '', true, value ? value.loc : loc)));181 }182 else {183 var name_3 = prop.name, arg = prop.arg, exp = prop.exp, loc = prop.loc;184 if (name_3 === 'slot') {185 if (!isComponent) {186 context.onError(errors_1.createCompilerError(46, loc));187 }188 continue;189 }190 if (name_3 === 'once') {191 continue;192 }193 var isBind = name_3 === 'bind';194 var isOn = name_3 === 'on';195 if (!arg && (isBind || isOn)) {196 hasDynamicKeys = true;197 if (exp) {198 if (properties.length) {199 mergeArgs.push(ast_1.createObjectExpression(dedupeProperties(properties), elementLoc));200 properties = [];201 }202 if (isBind) {203 mergeArgs.push(exp);204 }205 else {206 mergeArgs.push({207 type: 13,208 loc: loc,209 callee: context.helper(runtimeHelpers_1.TO_HANDLERS),210 arguments: [exp]211 });212 }213 }214 else {215 context.onError(errors_1.createCompilerError(isBind216 ? 39217 : 40, loc));218 }219 continue;220 }221 var directiveTransform = context.directiveTransforms[name_3];222 if (directiveTransform) {223 var _a = directiveTransform(prop, node, context), props_1 = _a.props, needRuntime = _a.needRuntime;224 props_1.forEach(analyzePatchFlag);225 properties.push.apply(properties, props_1);226 if (needRuntime) {227 runtimeDirectives.push(prop);228 if (shared_1.isSymbol(needRuntime)) {229 directiveImportMap.set(prop, needRuntime);230 }231 }232 }233 else {234 runtimeDirectives.push(prop);235 }236 }237 }238 var propsExpression = undefined;239 if (mergeArgs.length) {240 if (properties.length) {241 mergeArgs.push(ast_1.createObjectExpression(dedupeProperties(properties), elementLoc));242 }243 if (mergeArgs.length > 1) {244 propsExpression = ast_1.createCallExpression(context.helper(runtimeHelpers_1.MERGE_PROPS), mergeArgs, elementLoc);245 }246 else {247 propsExpression = mergeArgs[0];248 }249 }250 else if (properties.length) {251 propsExpression = ast_1.createObjectExpression(dedupeProperties(properties), elementLoc);252 }253 if (hasDynamicKeys) {254 patchFlag |= shared_1.PatchFlags.FULL_PROPS;255 }256 else {257 if (hasClassBinding) {258 patchFlag |= shared_1.PatchFlags.CLASS;259 }260 if (hasStyleBinding) {261 patchFlag |= shared_1.PatchFlags.STYLE;262 }263 if (dynamicPropNames.length) {264 patchFlag |= shared_1.PatchFlags.PROPS;265 }266 }267 if (patchFlag === 0 && (hasRef || runtimeDirectives.length > 0)) {268 patchFlag |= shared_1.PatchFlags.NEED_PATCH;269 }270 return {271 props: propsExpression,272 directives: runtimeDirectives,273 patchFlag: patchFlag,274 dynamicPropNames: dynamicPropNames275 };276}277exports.buildProps = buildProps;278function dedupeProperties(properties) {279 var knownProps = {};280 var deduped = [];281 for (var i = 0; i < properties.length; i++) {282 var prop = properties[i];283 if (prop.key.type === 8 || !prop.key.isStatic) {284 deduped.push(prop);285 continue;286 }287 var name_4 = prop.key.content;288 var existing = knownProps[name_4];289 if (existing) {290 if (name_4 === 'style' ||291 name_4 === 'class' ||292 name_4.startsWith('on') ||293 name_4.startsWith('vnode')) {294 mergeAsArray(existing, prop);295 }296 }297 else {298 knownProps[name_4] = prop;299 deduped.push(prop);300 }301 }302 return deduped;303}304function mergeAsArray(existing, incoming) {305 if (existing.value.type === 16) {306 existing.value.elements.push(incoming.value);307 }308 else {309 existing.value = ast_1.createArrayExpression([existing.value, incoming.value], existing.loc);310 }311}312function buildDirectiveArgs(dir, context) {313 var dirArgs = [];314 var runtime = directiveImportMap.get(dir);315 if (runtime) {316 context.helper(runtime);317 dirArgs.push(context.helperString(runtime));318 }319 else {320 context.helper(runtimeHelpers_1.RESOLVE_DIRECTIVE);321 context.directives.add(dir.name);322 dirArgs.push(utils_1.toValidAssetId(dir.name, "directive"));323 }324 var loc = dir.loc;325 if (dir.exp)326 dirArgs.push(dir.exp);327 if (dir.arg) {328 if (!dir.exp) {329 dirArgs.push("void 0");330 }331 dirArgs.push(dir.arg);332 }333 if (Object.keys(dir.modifiers).length) {334 if (!dir.arg) {335 if (!dir.exp) {336 dirArgs.push("void 0");337 }338 dirArgs.push("void 0");339 }340 dirArgs.push(ast_1.createObjectExpression(dir.modifiers.map(function (modifier) {341 return ast_1.createObjectProperty(modifier, ast_1.createSimpleExpression("true", false, loc));342 }), loc));343 }344 return ast_1.createArrayExpression(dirArgs, dir.loc);...

Full Screen

Full Screen

parse3.js

Source:parse3.js Github

copy

Full Screen

1const transformText = (node, context) => {2 if (node.type === 0 /* ROOT */ ||3 node.type === 1 /* ELEMENT */ ||4 node.type === 11 /* FOR */ ||5 node.type === 10 /* IF_BRANCH */) {6 // 在节点退出时执行转换,保证所有表达式都已经被处理7 return () => {8 const children = node.children9 let currentContainer = undefined10 let hasText = false11 // 将相邻文本节点合并12 for (let i = 0; i < children.length; i++) {13 const child = children[i]14 if (isText(child)) {15 hasText = true16 for (let j = i + 1; j < children.length; j++) {17 const next = children[j]18 if (isText(next)) {19 if (!currentContainer) {20 // 创建复合表达式节点21 currentContainer = children[i] = {22 type: 8 /* COMPOUND_EXPRESSION */,23 loc: child.loc,24 children: [child]25 }26 }27 currentContainer.children.push(` + `, next)28 children.splice(j, 1)29 j--30 }31 else {32 currentContainer = undefined33 break34 }35 }36 }37 }38 if (!hasText ||39 // 如果是一个带有单个文本子元素的纯元素节点,什么都不需要转换,因为这种情况在运行时可以直接设置元素的 textContent 来更新文本。40 (children.length === 1 &&41 (node.type === 0 /* ROOT */ ||42 (node.type === 1 /* ELEMENT */ &&43 node.tagType === 0 /* ELEMENT */)))) {44 return45 }46 // 为子文本节点创建一个调用函数表达式的代码生成节点47 for (let i = 0; i < children.length; i++) {48 const child = children[i]49 if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {50 const callArgs = []51 // 为 createTextVNode 添加执行参数52 if (child.type !== 2 /* TEXT */ || child.content !== ' ') {53 callArgs.push(child)54 }55 // 标记动态文本56 if (!context.ssr && child.type !== 2 /* TEXT */) {57 callArgs.push(`${1 /* TEXT */} /* ${PatchFlagNames[1 /* TEXT */]} */`)58 }59 children[i] = {60 type: 12 /* TEXT_CALL */,61 content: child,62 loc: child.loc,63 codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)64 }65 }66 }67 }68 }69}70function createCallExpression(callee, args = [], loc = locStub) {71 return {72 type: 14 /* JS_CALL_EXPRESSION */,73 loc,74 callee,75 arguments: args76 }77}78// v-if 节点转换函数的实现79const transformIf = createStructuralDirectiveTransform(/^(if|else|else-if)$/, (node, dir, context) => {80 return processIf(node, dir, context, (ifNode, branch, isRoot) => {81 return () => {82 // 退出回调函数,当所有子节点转换完成执行83 }84 })85})86function createStructuralDirectiveTransform(name, fn) {87 const matches = isString(name)88 ? (n) => n === name89 : (n) => name.test(n)90 return (node, context) => {91 // 只处理元素节点92 if (node.type === 1 /* ELEMENT */) {93 const { props } = node94 // 结构化指令的转换与插槽无关,插槽相关处理逻辑在 vSlot.ts 中95 if (node.tagType === 3 /* TEMPLATE */ && props.some(isVSlot)) {96 return97 }98 const exitFns = []99 for (let i = 0; i < props.length; i++) {100 const prop = props[i]101 if (prop.type === 7 /* DIRECTIVE */ && matches(prop.name)) {102 // 删除结构指令以避免无限递归103 props.splice(i, 1)104 i--105 const onExit = fn(node, prop, context)106 if (onExit)107 exitFns.push(onExit)108 }109 }110 return exitFns111 }112 }113}114function processIf(node, dir, context, processCodegen) {115 if (dir.name === 'if') {116 // 创建分支节点117 const branch = createIfBranch(node, dir)118 // 创建 IF 节点,替换当前节点119 const ifNode = {120 type: 9 /* IF */,121 loc: node.loc,122 branches: [branch]123 }124 context.replaceNode(ifNode)125 if (processCodegen) {126 return processCodegen(ifNode, branch, true)127 }128 }129 else {130 // 处理 v-if 相邻节点,比如 v-else-if 和 v-else131 const siblings = context.parent.children132 let i = siblings.indexOf(node)133 while (i-- >= -1) {134 const sibling = siblings[i]135 if (sibling && sibling.type === 9 /* IF */) {136 // 把节点移动到 IF 节点的 branches 中137 context.removeNode()138 const branch = createIfBranch(node, dir)139 sibling.branches.push(branch)140 const onExit = processCodegen && processCodegen(sibling, branch, false)141 // 因为分支已被删除,所以它的子节点需要在这里遍历142 traverseNode(branch, context)143 // 执行退出函数144 if (onExit)145 onExit()146 // 恢复 currentNode 为 null,因为它已经被移除147 context.currentNode = null148 }149 else {150 context.onError(createCompilerError(28 /* X_V_ELSE_NO_ADJACENT_IF */, node.loc))151 }152 break153 }154 }155}156function createIfBranch(node, dir) {157 return {158 type: 10 /* IF_BRANCH */,159 loc: node.loc,160 condition: dir.name === 'else' ? undefined : dir.exp,161 children: node.tagType === 3 /* TEMPLATE */ ? node.children : [node]162 }163}164function createChildrenCodegenNode(branch, index, context) {165 const { helper } = context166 // 根据 index 创建 key 属性167 const keyProperty = createObjectProperty(`key`, createSimpleExpression(index + '', false))168 const { children } = branch169 const firstChild = children[0]170 const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* ELEMENT */171 if (needFragmentWrapper) {172 if (children.length === 1 && firstChild.type === 11 /* FOR */) {173 const vnodeCall = firstChild.codegenNode174 injectProp(vnodeCall, keyProperty, context)175 return vnodeCall176 }177 else {178 return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, `${64 /* STABLE_FRAGMENT */} /* ${PatchFlagNames[64 /* STABLE_FRAGMENT */]} */`, undefined, undefined, true, false, branch.loc)179 }180 } 181 else {182 const vnodeCall = firstChild183 .codegenNode;184 // 把 createVNode 改变为 createBlock185 if (vnodeCall.type === 13 /* VNODE_CALL */ &&186 // 组件节点的 children 会被视为插槽,不需要添加 block187 (firstChild.tagType !== 1 /* COMPONENT */ ||188 vnodeCall.tag === TELEPORT)) {189 vnodeCall.isBlock = true190 // 创建 block 的辅助代码191 helper(OPEN_BLOCK)192 helper(CREATE_BLOCK)193 }194 // 给 branch 注入 key 属性195 injectProp(vnodeCall, keyProperty, context)196 return vnodeCall197 }...

Full Screen

Full Screen

transform.js

Source:transform.js Github

copy

Full Screen

1import { NOOP } from "../util.js";2import { defaultOnError } from "./error.js";3import { __DEV__, isVSlot } from "./utils.js";4import {5 NodeTypes,6 ElementTypes,7 createSimpleExpression,8 createCacheExpression,9} from "./ast.js";10import { isSingleElementRoot, hoistStatic } from "./transforms/hoistStatic.js";11import {12 TO_DISPLAY_STRING,13 FRAGMENT,14 helperNameMap,15 CREATE_BLOCK,16 CREATE_COMMENT,17 OPEN_BLOCK,18} from "./runtimeHelpers.js";19export function createTransformContext(20 root,21 {22 prefixIdentifiers = false,23 hoistStatic = false,24 cacheHandlers = false,25 nodeTransforms = [],26 directiveTransforms = {},27 transformHoist = null,28 isBuiltInComponent = NOOP,29 expressionPlugins = [],30 scopeId = null,31 ssr = false,32 onError = defaultOnError,33 }34) {35 const context = {36 // options37 prefixIdentifiers,38 hoistStatic,39 cacheHandlers,40 nodeTransforms,41 directiveTransforms,42 transformHoist,43 isBuiltInComponent,44 expressionPlugins,45 scopeId,46 ssr,47 onError,48 // state49 root,50 helpers: new Set(),51 components: new Set(),52 directives: new Set(),53 hoists: [],54 imports: new Set(),55 temps: 0,56 cached: 0,57 identifiers: {},58 scopes: {59 vFor: 0,60 vSlot: 0,61 vPre: 0,62 vOnce: 0,63 },64 parent: null,65 currentNode: root,66 childIndex: 0,67 // methods68 helper(name) {69 context.helpers.add(name);70 return name;71 },72 helperString(name) {73 return `_${helperNameMap[context.helper(name)]}`;74 },75 replaceNode(node) {76 // parent, childIndex 来自 traverseChildren 里面的赋值77 context.parent.children[context.childIndex] = context.currentNode = node;78 },79 removeNode(node) {80 if (__DEV__ && !context.parent) {81 throw new Error(`Cannot, remove root node.`);82 }83 const list = context.parent.children;84 // 先从节点孩子中找,然后取当前节点85 const removalIndex = node86 ? list.indexOf(node)87 : context.currentNode88 ? context.childIndex89 : -1;90 if (__DEV__ && removalIndex < 0) {91 throw new Error(`node being removed is not a child of current parent`);92 }93 if (!node || node === context.currentNode) {94 // 删除的是当前 traverseNode 递归中正遍历的节点95 context.currentNode = null;96 context.onNodeRemoved();97 } else {98 // 删除当前节点前面的兄弟节点99 if (context.childIndex > removalIndex) {100 context.childIndex--;101 context.onNodeRemoved();102 }103 }104 // 执行删除105 context.parent.children.splice(removalIndex, 1);106 },107 onNodeRemoved: () => {},108 addIdentifiers(exp) {},109 removeIdentifiers(exp) {},110 hoist(exp) {111 context.hoists.push(exp);112 const identifier = createSimpleExpression(113 `_hoisted_${context.hoists.length}`,114 false,115 exp.loc,116 true117 );118 identifier.hoisted = exp;119 return identifier;120 },121 cache(exp, isVNode = false) {122 return createCacheExpression(++context.cached, exp, isVNode);123 },124 };125 function addId(id) {}126 function removeId(id) {}127 return context;128}129export function traverseNode(node, context) {130 context.currentNode = node;131 const { nodeTransforms } = context;132 const exitFns = [];133 for (let i = 0; i < nodeTransforms.length; i++) {134 // 调用诸如 transformText 的函数135 const onExit = nodeTransforms[i](node, context);136 if (onExit) {137 const fns = Array.isArray(onExit) ? onExit : [onExit];138 exitFns.push(...fns);139 }140 if (!context.currentNode) {141 // 可能被移除了142 return;143 } else {144 // 节点可能被替换过,重新建立引用145 node = context.currentNode;146 }147 }148 switch (node.type) {149 // ... 省略150 case NodeTypes.INTERPOLATION:151 if (!context.ssr) {152 // 这个函数来自上下文处理中的 helper(name)153 context.helper(TO_DISPLAY_STRING);154 }155 break;156 case NodeTypes.IF:157 for (let i = 0; i < node.branches.length; i++) {158 traverseNode(node.branches[i], context);159 }160 break;161 case NodeTypes.IF_BRANCH:162 case NodeTypes.ELEMENT:163 case NodeTypes.ROOT:164 traverseChildren(node, context);165 break;166 }167 context.currentNode = node;168 let i = exitFns.length;169 // 执行所有转换170 while (i--) {171 exitFns[i]();172 }173}174export function transform(root, options) {175 const context = createTransformContext(root, options);176 traverseNode(root, context);177 console.log(root, "000");178 if (options.hoistStatic) {179 hoistStatic(root, context);180 }181 if (!options.ssr) {182 createRootCodegen(root, context);183 }184 // ... ssr 处理185 // root 属性合并,初始化186 root.helpers = [...context.helpers];187 root.components = [...context.components];188 root.directives = [...context.directives];189 root.imports = [...context.imports];190 root.hoists = context.hoists;191 root.temps = context.temps;192 root.cached = context.cached;193}194function createRootCodegen(root, context) {195 const { helper } = context;196 const { children } = root;197 const child = children[0];198 if (children.length === 1) {199 // 只有一个孩子节点200 // 且孩子节点是一个元素 element 类型,将它放在一个代码块钟返回201 // 如: { code }202 if (isSingleElementRoot(root, child) && child.codegenNode) {203 const codegenNode = child.codegenNode;204 if (codegenNode.type === NodeTypes.VNODE_CALL) {205 codegenNode.isBlock = true;206 helper(OPEN_BLOCK);207 helper(CREATE_BLOCK);208 }209 root.codegenNode = codegenNode;210 } else {211 root.codegenNode = child;212 }213 } else if (children.length > 1) {214 } else {215 // 没有孩子节点, codegen 返回 null,看到没216 // 01 simple text 返回 null 问题找到根源了217 }218}219export function traverseChildren(parent, context) {220 let i = 0;221 const nodeRemoved = () => {222 i--;223 };224 for (; i < parent.children.length; i++) {225 const child = parent.children[i];226 // 过略掉字符串,只处理 ast child227 if (typeof child === "string") continue;228 context.parent = parent;229 context.childIndex = i;230 context.onNodeRemoved = nodeRemoved;231 traverseNode(child, context);232 }233}234export function createStructuralDirectiveTransform(name, fn) {235 const matches =236 typeof name === "string" ? (n) => n === name : (n) => name.test(n);237 return (node, context) => {238 if (node.type === NodeTypes.ELEMENT) {239 const { props } = node;240 // 忽略 v-slot,它在 vSlot.ts 中处理241 if (node.tagType === ElementTypes.TEMPLATE && props.some(isVSlot)) {242 return;243 }244 // 开始收集 v-if 指令的 transform 函数245 const exitFns = [];246 for (let i = 0; i < props.length; i++) {247 const prop = props[i];248 if (prop.type === NodeTypes.DIRECTIVE && matches(prop.name)) {249 // 删除原节点中的指令属性250 props.splice(i, 1);251 i--;252 const onExit = fn(node, prop, context);253 if (onExit) exitFns.push(onExit);254 }255 }256 return exitFns;257 }258 };...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...128 blockExp129 ]);130}131exports.createBlockExpression = createBlockExpression;132function isVSlot(p) {133 return p.type === 7 && p.name === 'slot';134}135exports.isVSlot = isVSlot;136function isTemplateNode(node) {137 return (node.type === 1 && node.tagType === 3);138}139exports.isTemplateNode = isTemplateNode;140function isSlotOutlet(node) {141 return node.type === 1 && node.tagType === 2;142}143exports.isSlotOutlet = isSlotOutlet;144function injectProp(node, prop, context) {145 var propsWithInjection;146 var props = node.callee === runtimeHelpers_1.RENDER_SLOT ? node.arguments[2] : node.arguments[1];...

Full Screen

Full Screen

vSlot.js

Source:vSlot.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3var ast_1 = require("../ast");4var errors_1 = require("../errors");5var utils_1 = require("../utils");6var runtimeHelpers_1 = require("../runtimeHelpers");7var vFor_1 = require("./vFor");8var isStaticExp = function (p) {9 return p.type === 4 && p.isStatic;10};11var defaultFallback = ast_1.createSimpleExpression("undefined", false);12exports.trackSlotScopes = function (node, context) {13 if (node.type === 1 &&14 (node.tagType === 1 ||15 node.tagType === 3)) {16 var vSlot = utils_1.findDir(node, 'slot');17 if (vSlot) {18 var slotProps_1 = vSlot.exp;19 if (!__BROWSER__ && context.prefixIdentifiers) {20 slotProps_1 && context.addIdentifiers(slotProps_1);21 }22 context.scopes.vSlot++;23 return function () {24 if (!__BROWSER__ && context.prefixIdentifiers) {25 slotProps_1 && context.removeIdentifiers(slotProps_1);26 }27 context.scopes.vSlot--;28 };29 }30 }31};32exports.trackVForSlotScopes = function (node, context) {33 var vFor;34 if (utils_1.isTemplateNode(node) &&35 node.props.some(utils_1.isVSlot) &&36 (vFor = utils_1.findDir(node, 'for'))) {37 var result = (vFor.parseResult = vFor_1.parseForExpression(vFor.exp, context));38 if (result) {39 var value_1 = result.value, key_1 = result.key, index_1 = result.index;40 var addIdentifiers = context.addIdentifiers, removeIdentifiers_1 = context.removeIdentifiers;41 value_1 && addIdentifiers(value_1);42 key_1 && addIdentifiers(key_1);43 index_1 && addIdentifiers(index_1);44 return function () {45 value_1 && removeIdentifiers_1(value_1);46 key_1 && removeIdentifiers_1(key_1);47 index_1 && removeIdentifiers_1(index_1);48 };49 }50 }51};52function buildSlots(node, context) {53 var children = node.children, loc = node.loc;54 var slotsProperties = [];55 var dynamicSlots = [];56 var hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;57 if (!__BROWSER__ && context.prefixIdentifiers) {58 hasDynamicSlots = utils_1.hasScopeRef(node, context.identifiers);59 }60 var explicitDefaultSlot = utils_1.findDir(node, 'slot', true);61 if (explicitDefaultSlot) {62 var arg = explicitDefaultSlot.arg, exp = explicitDefaultSlot.exp, loc_1 = explicitDefaultSlot.loc;63 if (arg) {64 context.onError(errors_1.createCompilerError(42, loc_1));65 }66 slotsProperties.push(buildDefaultSlot(exp, children, loc_1));67 }68 var hasTemplateSlots = false;69 var extraneousChild = undefined;70 var seenSlotNames = new Set();71 for (var i = 0; i < children.length; i++) {72 var slotElement = children[i];73 var slotDir = void 0;74 if (!utils_1.isTemplateNode(slotElement) ||75 !(slotDir = utils_1.findDir(slotElement, 'slot', true))) {76 if (slotElement.type !== 3 && !extraneousChild) {77 extraneousChild = slotElement;78 }79 continue;80 }81 if (explicitDefaultSlot) {82 context.onError(errors_1.createCompilerError(43, slotDir.loc));83 break;84 }85 hasTemplateSlots = true;86 var slotChildren = slotElement.children, slotLoc = slotElement.loc;87 var _a = slotDir.arg, slotName = _a === void 0 ? ast_1.createSimpleExpression("default", true) : _a, slotProps = slotDir.exp, dirLoc = slotDir.loc;88 var staticSlotName = void 0;89 if (isStaticExp(slotName)) {90 staticSlotName = slotName ? slotName.content : "default";91 }92 else {93 hasDynamicSlots = true;94 }95 var slotFunction = ast_1.createFunctionExpression(slotProps, slotChildren, false, slotChildren.length ? slotChildren[0].loc : slotLoc);96 var vIf = void 0;97 var vElse = void 0;98 var vFor = void 0;99 if ((vIf = utils_1.findDir(slotElement, 'if'))) {100 hasDynamicSlots = true;101 dynamicSlots.push(ast_1.createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));102 }103 else if ((vElse = utils_1.findDir(slotElement, /^else(-if)?$/, true))) {104 var j = i;105 var prev = void 0;106 while (j--) {107 prev = children[j];108 if (prev.type !== 3) {109 break;110 }111 }112 if (prev && utils_1.isTemplateNode(prev) && utils_1.findDir(prev, 'if')) {113 children.splice(i, 1);114 i--;115 __DEV__ && utils_1.assert(dynamicSlots.length > 0);116 var conditional = dynamicSlots[dynamicSlots.length - 1];117 while (conditional.alternate.type === 19) {118 conditional = conditional.alternate;119 }120 conditional.alternate = vElse.exp121 ? ast_1.createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)122 : buildDynamicSlot(slotName, slotFunction);123 }124 else {125 context.onError(errors_1.createCompilerError(36, vElse.loc));126 }127 }128 else if ((vFor = utils_1.findDir(slotElement, 'for'))) {129 hasDynamicSlots = true;130 var parseResult = vFor.parseResult ||131 vFor_1.parseForExpression(vFor.exp, context);132 if (parseResult) {133 dynamicSlots.push(ast_1.createCallExpression(context.helper(runtimeHelpers_1.RENDER_LIST), [134 parseResult.source,135 ast_1.createFunctionExpression(vFor_1.createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true)136 ]));137 }138 else {139 context.onError(errors_1.createCompilerError(38, vFor.loc));140 }141 }142 else {143 if (staticSlotName) {144 if (seenSlotNames.has(staticSlotName)) {145 context.onError(errors_1.createCompilerError(44, dirLoc));146 continue;147 }148 seenSlotNames.add(staticSlotName);149 }150 slotsProperties.push(ast_1.createObjectProperty(slotName, slotFunction));151 }152 }153 if (hasTemplateSlots && extraneousChild) {154 context.onError(errors_1.createCompilerError(45, extraneousChild.loc));155 }156 if (!explicitDefaultSlot && !hasTemplateSlots) {157 slotsProperties.push(buildDefaultSlot(undefined, children, loc));158 }159 var slots = ast_1.createObjectExpression(slotsProperties.concat(ast_1.createObjectProperty("_compiled", ast_1.createSimpleExpression("true", false))), loc);160 if (dynamicSlots.length) {161 slots = ast_1.createCallExpression(context.helper(runtimeHelpers_1.CREATE_SLOTS), [162 slots,163 ast_1.createArrayExpression(dynamicSlots)164 ]);165 }166 return {167 slots: slots,168 hasDynamicSlots: hasDynamicSlots169 };170}171exports.buildSlots = buildSlots;172function buildDefaultSlot(slotProps, children, loc) {173 return ast_1.createObjectProperty("default", ast_1.createFunctionExpression(slotProps, children, false, children.length ? children[0].loc : loc));174}175function buildDynamicSlot(name, fn) {176 return ast_1.createObjectExpression([177 ast_1.createObjectProperty("name", name),178 ast_1.createObjectProperty("fn", fn)179 ]);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/utils/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 await page.click('text=Get started');8 const element = await page.waitForSelector('text=Start typing');9 console.log(isVSlot(element));10 await browser.close();11})();12const { isVSlot } = require('playwright/lib/utils/dom.js');13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.click('text=Get started');19 const element = await page.waitForSelector('text=Start typing');20 if (isVSlot(element)) {21 const parentElement = element.parentElement;22 console.log(parentElement);23 }24 await browser.close();25})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/client/selectorEngine');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await browser.close();7})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/server/frames');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 element = await page.$('input[name="q"]');8 console.log(isVSlot(element));9 await browser.close();10})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/client/slot.js');2const { Page } = require('playwright/lib/client/page.js');3const { ElementHandle } = require('playwright/lib/client/elementHandle.js');4const { Frame } = require('playwright/lib/client/frame.js');5const { isVSlot } = require('playwright/lib/client/slot.js');6const { Page } = require('playwright/lib/client/page.js');7const { ElementHandle } = require('playwright/lib/client/elementHandle.js');8const { Frame } = require('playwright/lib/client/frame.js');9const { isVSlot } = require('playwright/lib/client/slot.js');10const { Page } = require('playwright/lib/client/page.js');11const { ElementHandle } = require('playwright/lib/client/elementHandle.js');12const { Frame } = require('playwright/lib/client/frame.js');13const { isVSlot } = require('playwright/lib/client/slot.js');14const { Page } = require('playwright/lib/client/page.js');15const { ElementHandle } = require('playwright/lib/client/elementHandle.js');16const { Frame } = require('playwright/lib/client/frame.js');17const { isVSlot } = require('playwright/lib/client/slot.js');18const { Page } = require('playwright/lib/client/page.js');19const { ElementHandle } = require('playwright/lib/client/elementHandle.js');20const { Frame } = require('playwright/lib/client/frame.js');21const { isVSlot } = require('playwright/lib/client/slot.js');22const { Page } = require('playwright/lib/client/page.js');23const { ElementHandle } = require('playwright/lib/client/elementHandle.js');24const { Frame } = require('playwright/lib/client/frame.js');25const { isVSlot } = require('playwright/lib/client/slot.js');26const { Page } = require('playwright/lib/client/page.js');27const { ElementHandle } = require('playwright

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/server/supplements/virtualSlots/virtualSlots');2const { parse } = require('playwright/lib/server/supplements/virtualSlots/parser');3const html = `<div> <input type="checkbox" checked /> </div>`;4const parsed = parse(html);5const vslot = parsed.children[0];6console.log(isVSlot(vslot));7const { chromium } = require('playwright');8const { isVSlot } = require('playwright/lib/server/supplements/virtualSlots/virtualSlots');9const { parse } = require('playwright/lib/server/supplements/virtualSlots/parser');10(async () => {11 const browser = await chromium.launch();12 const context = await browser.newContext();13 const page = await context.newPage();14 const checkbox = await page.$('input[type="checkbox"]');15 const vNode = await checkbox.evaluateHandle((el) => el.getInternal());16 const isSlot = isVSlot(vNode);17 console.log(isSlot);18 await browser.close();19})();20 at ExecutionContext._evaluateInternal (/home/username/node_modules/playwright/lib/server/frames.js:1242:19)21 at processTicksAndRejections (internal/process/task_queues.js:93:5)22 at async ExecutionContext.evaluate (/home/username/node_modules/playwright/lib/server/frames.js:1225:16)23 at async Object.<anonymous> (/home/username/test.js:15:27)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Internal } = require('playwright');2const vSlot = Internal.isVSlot('v-slot:default');3console.log(vSlot);4const { Internal } = require('playwright');5const vSlot = Internal.isVSlot('v-slot:default');6console.log(vSlot);7const { Internal } = require('playwright');8const vSlot = Internal.isVSlot('v-slot:default');9console.log(vSlot);10const { Internal } = require('playwright');11const vSlot = Internal.isVSlot('v-slot:default');12console.log(vSlot);13const { Internal } = require('playwright');14const vSlot = Internal.isVSlot('v-slot:default');15console.log(vSlot);16const { Internal } = require('playwright');17const vSlot = Internal.isVSlot('v-slot:default');18console.log(vSlot);19const { Internal } = require('playwright');20const vSlot = Internal.isVSlot('v-slot:default');21console.log(vSlot);22const { Internal } = require('playwright');23const vSlot = Internal.isVSlot('v-slot:default');24console.log(vSlot);25const { Internal } = require('playwright');26const vSlot = Internal.isVSlot('v-slot:default');27console.log(vSlot);28const { Internal } = require('playwright');29const vSlot = Internal.isVSlot('v-slot:default');30console.log(vSlot);31const { Internal } = require('playwright');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { isVSlot } = require('playwright/lib/server/common/selectorParser');2const selector = 'text=Hello World';3console.log(isVSlot(selector));4const { isVSlot } = require('playwright/lib/server/common/selectorParser');5const selector = 'text=Hello World';6console.log(isVSlot(selector));7const { isVSlot } = require('playwright/lib/server/common/selectorParser');8const selector = 'text=Hello World';9console.log(isVSlot(selector));10const { isVSlot } = require('playwright/lib/server/common/selectorParser');11const selector = 'text=Hello World';12console.log(isVSlot(selector));13const { isVSlot } = require('playwright/lib/server/common/selectorParser');14const selector = 'text=Hello World';15console.log(isVSlot(selector));16const { isVSlot } = require('playwright/lib/server/common/selectorParser');17const selector = 'text=Hello World';18console.log(isVSlot(selector));19const { isVSlot } = require('playwright/lib/server/common/selectorParser');20const selector = 'text=Hello World';21console.log(isVSlot(selector));22const { isVSlot } = require('playwright/lib/server/common/selectorParser');23const selector = 'text=Hello World';24console.log(isVSlot(selector));25const { isVSlot } = require('playwright/lib/server/common/selectorParser');26const selector = 'text=Hello World';27console.log(isVSlot(selector));28const { isVSlot } = require('playwright/lib/server/common/selectorParser');29const selector = 'text=Hello World';30console.log(isVSlot(selector));

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