MCPcopy
hub / github.com/microsoft/playwright / processIf

Function processIf

tests/assets/reading-list/vue_3.1.5.js:12866–12946  ·  view source on GitHub ↗
(node, dir, context, processCodegen)

Source from the content-addressed store, hash-verified

12864 });
12865 // target-agnostic transform used for both Client and SSR
12866 function processIf(node, dir, context, processCodegen) {
12867 if (dir.name !== 'else' &&
12868 (!dir.exp || !dir.exp.content.trim())) {
12869 const loc = dir.exp ? dir.exp.loc : node.loc;
12870 context.onError(createCompilerError(27 /* X_V_IF_NO_EXPRESSION */, dir.loc));
12871 dir.exp = createSimpleExpression(`true`, false, loc);
12872 }
12873 if (dir.exp) {
12874 validateBrowserExpression(dir.exp, context);
12875 }
12876 if (dir.name === 'if') {
12877 const branch = createIfBranch(node, dir);
12878 const ifNode = {
12879 type: 9 /* IF */,
12880 loc: node.loc,
12881 branches: [branch]
12882 };
12883 context.replaceNode(ifNode);
12884 if (processCodegen) {
12885 return processCodegen(ifNode, branch, true);
12886 }
12887 }
12888 else {
12889 // locate the adjacent v-if
12890 const siblings = context.parent.children;
12891 const comments = [];
12892 let i = siblings.indexOf(node);
12893 while (i-- >= -1) {
12894 const sibling = siblings[i];
12895 if (sibling && sibling.type === 3 /* COMMENT */) {
12896 context.removeNode(sibling);
12897 comments.unshift(sibling);
12898 continue;
12899 }
12900 if (sibling &&
12901 sibling.type === 2 /* TEXT */ &&
12902 !sibling.content.trim().length) {
12903 context.removeNode(sibling);
12904 continue;
12905 }
12906 if (sibling && sibling.type === 9 /* IF */) {
12907 // move the node to the if node's branches
12908 context.removeNode();
12909 const branch = createIfBranch(node, dir);
12910 if (comments.length &&
12911 // #3619 ignore comments if the v-if is direct child of <transition>
12912 !(context.parent &&
12913 context.parent.type === 1 /* ELEMENT */ &&
12914 isBuiltInType(context.parent.tag, 'transition'))) {
12915 branch.children = [...comments, ...branch.children];
12916 }
12917 // check if user is forcing same key on different branches
12918 {
12919 const key = branch.userKey;
12920 if (key) {
12921 sibling.branches.forEach(({ userKey }) => {
12922 if (isSameKey(userKey, key)) {
12923 context.onError(createCompilerError(28 /* X_V_IF_SAME_KEY */, branch.userKey.loc));

Callers 1

vue_3.1.5.jsFile · 0.70

Calls 10

createCompilerErrorFunction · 0.85
createSimpleExpressionFunction · 0.85
createIfBranchFunction · 0.85
isBuiltInTypeFunction · 0.85
isSameKeyFunction · 0.85
traverseNodeFunction · 0.85
onExitFunction · 0.85
onErrorMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…