Best JavaScript code snippet using playwright-internal
compiler-core.esm-bundler.js
Source:compiler-core.esm-bundler.js
...1239 // node may contain dynamic children, but its props may be eligible for1240 // hoisting.1241 const codegenNode = child.codegenNode;1242 if (codegenNode.type === 13 /* VNODE_CALL */) {1243 const flag = getPatchFlag(codegenNode);1244 if ((!flag ||1245 flag === 512 /* NEED_PATCH */ ||1246 flag === 1 /* TEXT */) &&1247 !hasDynamicKeyOrRef(child) &&1248 !hasCachedProps()) {1249 const props = getNodeProps(child);1250 if (props) {1251 codegenNode.props = context.hoist(props);1252 }1253 }1254 }1255 }1256 }1257 if (child.type === 1 /* ELEMENT */) {1258 walk(child.children, context, resultCache);1259 }1260 else if (child.type === 11 /* FOR */) {1261 // Do not hoist v-for single child because it has to be a block1262 walk(child.children, context, resultCache, child.children.length === 1);1263 }1264 else if (child.type === 9 /* IF */) {1265 for (let i = 0; i < child.branches.length; i++) {1266 const branchChildren = child.branches[i].children;1267 // Do not hoist v-if single child because it has to be a block1268 walk(branchChildren, context, resultCache, branchChildren.length === 1);1269 }1270 }1271 else if (child.type === 12 /* TEXT_CALL */ &&1272 isStaticNode(child.content, resultCache)) {1273 child.codegenNode = context.hoist(child.codegenNode);1274 }1275 }1276}1277function isStaticNode(node, resultCache = new Map()) {1278 switch (node.type) {1279 case 1 /* ELEMENT */:1280 if (node.tagType !== 0 /* ELEMENT */) {1281 return false;1282 }1283 const cached = resultCache.get(node);1284 if (cached !== undefined) {1285 return cached;1286 }1287 const codegenNode = node.codegenNode;1288 if (codegenNode.type !== 13 /* VNODE_CALL */) {1289 return false;1290 }1291 const flag = getPatchFlag(codegenNode);1292 if (!flag && !hasDynamicKeyOrRef(node) && !hasCachedProps()) {1293 // element self is static. check its children.1294 for (let i = 0; i < node.children.length; i++) {1295 if (!isStaticNode(node.children[i], resultCache)) {1296 resultCache.set(node, false);1297 return false;1298 }1299 }1300 // only svg/foreignObject could be block here, however if they are static1301 // then they don't need to be blocks since there will be no nested1302 // updates.1303 if (codegenNode.isBlock) {1304 codegenNode.isBlock = false;1305 }1306 resultCache.set(node, true);1307 return true;1308 }1309 else {1310 resultCache.set(node, false);1311 return false;1312 }1313 case 2 /* TEXT */:1314 case 3 /* COMMENT */:1315 return true;1316 case 9 /* IF */:1317 case 11 /* FOR */:1318 case 10 /* IF_BRANCH */:1319 return false;1320 case 5 /* INTERPOLATION */:1321 case 12 /* TEXT_CALL */:1322 return isStaticNode(node.content, resultCache);1323 case 4 /* SIMPLE_EXPRESSION */:1324 return node.isConstant;1325 case 8 /* COMPOUND_EXPRESSION */:1326 return node.children.every(child => {1327 return (isString(child) || isSymbol(child) || isStaticNode(child, resultCache));1328 });1329 default:1330 if ((process.env.NODE_ENV !== 'production')) ;1331 return false;1332 }1333}1334function hasDynamicKeyOrRef(node) {1335 return !!(findProp(node, 'key', true) || findProp(node, 'ref', true));1336}1337function hasCachedProps(node) {1338 {1339 return false;1340 }1341}1342function getNodeProps(node) {1343 const codegenNode = node.codegenNode;1344 if (codegenNode.type === 13 /* VNODE_CALL */) {1345 return codegenNode.props;1346 }1347}1348function getPatchFlag(node) {1349 const flag = node.patchFlag;1350 return flag ? parseInt(flag, 10) : undefined;1351}1352function createTransformContext(root, { prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, expressionPlugins = [], scopeId = null, ssr = false, onError = defaultOnError }) {1353 const context = {1354 // options1355 prefixIdentifiers,1356 hoistStatic,1357 cacheHandlers,1358 nodeTransforms,1359 directiveTransforms,1360 transformHoist,1361 isBuiltInComponent,1362 expressionPlugins,
...
compiler-core.cjs.js
Source:compiler-core.cjs.js
...1102 }1103 else {1104 // node may contain dynamic children, but its props may be eligible for1105 // hoisting.1106 const flag = getPatchFlag(child);1107 if (!flag ||1108 flag === 32 /* NEED_PATCH */ ||1109 flag === 1 /* TEXT */) {1110 let codegenNode = child.codegenNode;1111 if (codegenNode.callee === APPLY_DIRECTIVES) {1112 codegenNode = codegenNode.arguments[0];1113 }1114 const props = codegenNode.arguments[1];1115 if (props && props !== `null`) {1116 codegenNode.arguments[1] = context.hoist(props);1117 }1118 }1119 }1120 }1121 if (child.type === 1 /* ELEMENT */) {1122 walk(child.children, context, resultCache);1123 }1124 else if (child.type === 11 /* FOR */) {1125 // Do not hoist v-for single child because it has to be a block1126 walk(child.children, context, resultCache, child.children.length === 1);1127 }1128 else if (child.type === 9 /* IF */) {1129 for (let i = 0; i < child.branches.length; i++) {1130 const branchChildren = child.branches[i].children;1131 // Do not hoist v-if single child because it has to be a block1132 walk(branchChildren, context, resultCache, branchChildren.length === 1);1133 }1134 }1135 }1136}1137function getPatchFlag(node) {1138 let codegenNode = node.codegenNode;1139 if (codegenNode.callee === APPLY_DIRECTIVES) {1140 codegenNode = codegenNode.arguments[0];1141 }1142 const flag = codegenNode.arguments[3];1143 return flag ? parseInt(flag, 10) : undefined;1144}1145function isStaticNode(node, resultCache) {1146 switch (node.type) {1147 case 1 /* ELEMENT */:1148 if (node.tagType !== 0 /* ELEMENT */) {1149 return false;1150 }1151 if (resultCache.has(node)) {1152 return resultCache.get(node);1153 }1154 const flag = getPatchFlag(node);1155 if (!flag) {1156 // element self is static. check its children.1157 for (let i = 0; i < node.children.length; i++) {1158 if (!isStaticNode(node.children[i], resultCache)) {1159 resultCache.set(node, false);1160 return false;1161 }1162 }1163 resultCache.set(node, true);1164 return true;1165 }1166 else {1167 return false;1168 }
...
compiler-core.cjs.prod.js
Source:compiler-core.cjs.prod.js
...1073 }1074 else {1075 // node may contain dynamic children, but its props may be eligible for1076 // hoisting.1077 const flag = getPatchFlag(child);1078 if (!flag ||1079 flag === 32 /* NEED_PATCH */ ||1080 flag === 1 /* TEXT */) {1081 let codegenNode = child.codegenNode;1082 if (codegenNode.callee === APPLY_DIRECTIVES) {1083 codegenNode = codegenNode.arguments[0];1084 }1085 const props = codegenNode.arguments[1];1086 if (props && props !== `null`) {1087 codegenNode.arguments[1] = context.hoist(props);1088 }1089 }1090 }1091 }1092 if (child.type === 1 /* ELEMENT */) {1093 walk(child.children, context, resultCache);1094 }1095 else if (child.type === 11 /* FOR */) {1096 // Do not hoist v-for single child because it has to be a block1097 walk(child.children, context, resultCache, child.children.length === 1);1098 }1099 else if (child.type === 9 /* IF */) {1100 for (let i = 0; i < child.branches.length; i++) {1101 const branchChildren = child.branches[i].children;1102 // Do not hoist v-if single child because it has to be a block1103 walk(branchChildren, context, resultCache, branchChildren.length === 1);1104 }1105 }1106 }1107}1108function getPatchFlag(node) {1109 let codegenNode = node.codegenNode;1110 if (codegenNode.callee === APPLY_DIRECTIVES) {1111 codegenNode = codegenNode.arguments[0];1112 }1113 const flag = codegenNode.arguments[3];1114 return flag ? parseInt(flag, 10) : undefined;1115}1116function isStaticNode(node, resultCache) {1117 switch (node.type) {1118 case 1 /* ELEMENT */:1119 if (node.tagType !== 0 /* ELEMENT */) {1120 return false;1121 }1122 if (resultCache.has(node)) {1123 return resultCache.get(node);1124 }1125 const flag = getPatchFlag(node);1126 if (!flag) {1127 // element self is static. check its children.1128 for (let i = 0; i < node.children.length; i++) {1129 if (!isStaticNode(node.children[i], resultCache)) {1130 resultCache.set(node, false);1131 return false;1132 }1133 }1134 resultCache.set(node, true);1135 return true;1136 }1137 else {1138 return false;1139 }
...
compiler-dom.global.js
Source:compiler-dom.global.js
...1076 }1077 else {1078 // node may contain dynamic children, but its props may be eligible for1079 // hoisting.1080 const flag = getPatchFlag(child);1081 if (!flag ||1082 flag === 32 /* NEED_PATCH */ ||1083 flag === 1 /* TEXT */) {1084 let codegenNode = child.codegenNode;1085 if (codegenNode.callee === APPLY_DIRECTIVES) {1086 codegenNode = codegenNode.arguments[0];1087 }1088 const props = codegenNode.arguments[1];1089 if (props && props !== `null`) {1090 codegenNode.arguments[1] = context.hoist(props);1091 }1092 }1093 }1094 }1095 if (child.type === 1 /* ELEMENT */) {1096 walk(child.children, context, resultCache);1097 }1098 else if (child.type === 11 /* FOR */) {1099 // Do not hoist v-for single child because it has to be a block1100 walk(child.children, context, resultCache, child.children.length === 1);1101 }1102 else if (child.type === 9 /* IF */) {1103 for (let i = 0; i < child.branches.length; i++) {1104 const branchChildren = child.branches[i].children;1105 // Do not hoist v-if single child because it has to be a block1106 walk(branchChildren, context, resultCache, branchChildren.length === 1);1107 }1108 }1109 }1110 }1111 function getPatchFlag(node) {1112 let codegenNode = node.codegenNode;1113 if (codegenNode.callee === APPLY_DIRECTIVES) {1114 codegenNode = codegenNode.arguments[0];1115 }1116 const flag = codegenNode.arguments[3];1117 return flag ? parseInt(flag, 10) : undefined;1118 }1119 function isStaticNode(node, resultCache) {1120 switch (node.type) {1121 case 1 /* ELEMENT */:1122 if (node.tagType !== 0 /* ELEMENT */) {1123 return false;1124 }1125 if (resultCache.has(node)) {1126 return resultCache.get(node);1127 }1128 const flag = getPatchFlag(node);1129 if (!flag) {1130 // element self is static. check its children.1131 for (let i = 0; i < node.children.length; i++) {1132 if (!isStaticNode(node.children[i], resultCache)) {1133 resultCache.set(node, false);1134 return false;1135 }1136 }1137 resultCache.set(node, true);1138 return true;1139 }1140 else {1141 return false;1142 }
...
compiler-dom.esm-browser.js
Source:compiler-dom.esm-browser.js
...1074 }1075 else {1076 // node may contain dynamic children, but its props may be eligible for1077 // hoisting.1078 const flag = getPatchFlag(child);1079 if (!flag ||1080 flag === 32 /* NEED_PATCH */ ||1081 flag === 1 /* TEXT */) {1082 let codegenNode = child.codegenNode;1083 if (codegenNode.callee === APPLY_DIRECTIVES) {1084 codegenNode = codegenNode.arguments[0];1085 }1086 const props = codegenNode.arguments[1];1087 if (props && props !== `null`) {1088 codegenNode.arguments[1] = context.hoist(props);1089 }1090 }1091 }1092 }1093 if (child.type === 1 /* ELEMENT */) {1094 walk(child.children, context, resultCache);1095 }1096 else if (child.type === 11 /* FOR */) {1097 // Do not hoist v-for single child because it has to be a block1098 walk(child.children, context, resultCache, child.children.length === 1);1099 }1100 else if (child.type === 9 /* IF */) {1101 for (let i = 0; i < child.branches.length; i++) {1102 const branchChildren = child.branches[i].children;1103 // Do not hoist v-if single child because it has to be a block1104 walk(branchChildren, context, resultCache, branchChildren.length === 1);1105 }1106 }1107 }1108}1109function getPatchFlag(node) {1110 let codegenNode = node.codegenNode;1111 if (codegenNode.callee === APPLY_DIRECTIVES) {1112 codegenNode = codegenNode.arguments[0];1113 }1114 const flag = codegenNode.arguments[3];1115 return flag ? parseInt(flag, 10) : undefined;1116}1117function isStaticNode(node, resultCache) {1118 switch (node.type) {1119 case 1 /* ELEMENT */:1120 if (node.tagType !== 0 /* ELEMENT */) {1121 return false;1122 }1123 if (resultCache.has(node)) {1124 return resultCache.get(node);1125 }1126 const flag = getPatchFlag(node);1127 if (!flag) {1128 // element self is static. check its children.1129 for (let i = 0; i < node.children.length; i++) {1130 if (!isStaticNode(node.children[i], resultCache)) {1131 resultCache.set(node, false);1132 return false;1133 }1134 }1135 resultCache.set(node, true);1136 return true;1137 }1138 else {1139 return false;1140 }
...
note-ast-transform.js
Source:note-ast-transform.js
...735 const codegenNode = node.codegenNode;736 if (codegenNode.type !== 13 /* VNODE_CALL */) {737 return 0 /* NOT_STATIC */;738 }739 const flag = getPatchFlag(codegenNode);740 if (!flag && !hasNonHoistableProps(node)) {741 // element self is static. check its children.742 let returnType = 1 /* FULL_STATIC */;743 for (let i = 0; i < node.children.length; i++) {744 const childType = getStaticType(node.children[i], resultCache);745 if (childType === 0 /* NOT_STATIC */) {746 resultCache.set(node, 0 /* NOT_STATIC */);747 return 0 /* NOT_STATIC */;748 }749 else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {750 returnType = 2 /* HAS_RUNTIME_CONSTANT */;751 }752 }753 // check if any of the props contain runtime constants754 if (returnType !== 2 /* HAS_RUNTIME_CONSTANT */) {755 for (let i = 0; i < node.props.length; i++) {756 const p = node.props[i];757 if (p.type === 7 /* DIRECTIVE */ &&758 p.name === 'bind' &&759 p.exp &&760 (p.exp.type === 8 /* COMPOUND_EXPRESSION */ ||761 p.exp.isRuntimeConstant)) {762 returnType = 2 /* HAS_RUNTIME_CONSTANT */;763 }764 }765 }766 // only svg/foreignObject could be block here, however if they are767 // stati then they don't need to be blocks since there will be no768 // nested updates.769 if (codegenNode.isBlock) {770 codegenNode.isBlock = false;771 }772 resultCache.set(node, returnType);773 return returnType;774 }775 else {776 resultCache.set(node, 0 /* NOT_STATIC */);777 return 0 /* NOT_STATIC */;778 }779 case 2 /* TEXT */:780 case 3 /* COMMENT */:781 return 1 /* FULL_STATIC */;782 case 9 /* IF */:783 case 11 /* FOR */:784 case 10 /* IF_BRANCH */:785 return 0 /* NOT_STATIC */;786 case 5 /* INTERPOLATION */:787 case 12 /* TEXT_CALL */:788 return getStaticType(node.content, resultCache);789 case 4 /* SIMPLE_EXPRESSION */:790 return node.isConstant791 ? node.isRuntimeConstant792 ? 2 /* HAS_RUNTIME_CONSTANT */793 : 1 /* FULL_STATIC */794 : 0 /* NOT_STATIC */;795 case 8 /* COMPOUND_EXPRESSION */:796 let returnType = 1 /* FULL_STATIC */;797 for (let i = 0; i < node.children.length; i++) {798 const child = node.children[i];799 if (isString(child) || isSymbol(child)) {800 continue;801 }802 const childType = getStaticType(child, resultCache);803 if (childType === 0 /* NOT_STATIC */) {804 return 0 /* NOT_STATIC */;805 }806 else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {807 returnType = 2 /* HAS_RUNTIME_CONSTANT */;808 }809 }810 return returnType;811 default:812 return 0 /* NOT_STATIC */;813 }814 }815 const transformElement = (node, context) => {816 if (!(node.type === 1 /* ELEMENT */ &&817 (node.tagType === 0 /* ELEMENT */ ||818 node.tagType === 1 /* COMPONENT */))) {819 return;820 }821 // perform the work on exit, after all child expressions have been822 // processed and merged.823 return function postTransformElement() {824 const { tag, props } = node;825 const isComponent = node.tagType === 1 /* COMPONENT */;826 // The goal of the transform is to create a codegenNode implementing the827 // VNodeCall interface.828 const vnodeTag = isComponent829 ? resolveComponentType(node, context)830 : `"${tag}"`;831 const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;832 let vnodeProps;833 let vnodeChildren;834 let vnodePatchFlag;835 let patchFlag = 0;836 let vnodeDynamicProps;837 let dynamicPropNames;838 let vnodeDirectives;839 let shouldUseBlock = 840 // dynamic component may resolve to plain elements841 isDynamicComponent ||842 vnodeTag === TELEPORT ||843 vnodeTag === SUSPENSE ||844 (!isComponent &&845 // <svg> and <foreignObject> must be forced into blocks so that block846 // updates inside get proper isSVG flag at runtime. (#639, #643)847 // This is technically web-specific, but splitting the logic out of core848 // leads to too much unnecessary complexity.849 (tag === 'svg' ||850 tag === 'foreignObject' ||851 // #938: elements with dynamic keys should be forced into blocks852 findProp(node, 'key', true)));853 // props854 if (props.length > 0) {855 const propsBuildResult = buildProps(node, context);856 vnodeProps = propsBuildResult.props;857 patchFlag = propsBuildResult.patchFlag;858 dynamicPropNames = propsBuildResult.dynamicPropNames;859 const directives = propsBuildResult.directives;860 vnodeDirectives =861 directives && directives.length862 ? createArrayExpression(directives.map(dir => buildDirectiveArgs(dir, context)))863 : undefined;864 }865 // children866 if (node.children.length > 0) {867 if (vnodeTag === KEEP_ALIVE) {868 // Although a built-in component, we compile KeepAlive with raw children869 // instead of slot functions so that it can be used inside Transition870 // or other Transition-wrapping HOCs.871 // To ensure correct updates with block optimizations, we need to:872 // 1. Force keep-alive into a block. This avoids its children being873 // collected by a parent block.874 shouldUseBlock = true;875 // 2. Force keep-alive to always be updated, since it uses raw children.876 patchFlag |= 1024 /* DYNAMIC_SLOTS */;877 if ( node.children.length > 1) {878 context.onError(createCompilerError(44 /* X_KEEP_ALIVE_INVALID_CHILDREN */, {879 start: node.children[0].loc.start,880 end: node.children[node.children.length - 1].loc.end,881 source: ''882 }));883 }884 }885 const shouldBuildAsSlots = isComponent &&886 // Teleport is not a real component and has dedicated runtime handling887 vnodeTag !== TELEPORT &&888 // explained above.889 vnodeTag !== KEEP_ALIVE;890 if (shouldBuildAsSlots) {891 const { slots, hasDynamicSlots } = buildSlots(node, context);892 vnodeChildren = slots;893 if (hasDynamicSlots) {894 patchFlag |= 1024 /* DYNAMIC_SLOTS */;895 }896 }897 else if (node.children.length === 1 && vnodeTag !== TELEPORT) {898 const child = node.children[0];899 const type = child.type;900 // check for dynamic text children901 const hasDynamicTextChild = type === 5 /* INTERPOLATION */ ||902 type === 8 /* COMPOUND_EXPRESSION */;903 if (hasDynamicTextChild && !getStaticType(child)) {904 patchFlag |= 1 /* TEXT */;905 }906 // pass directly if the only child is a text node907 // (plain / interpolation / expression)908 if (hasDynamicTextChild || type === 2 /* TEXT */) {909 vnodeChildren = child;910 }911 else {912 vnodeChildren = node.children;913 }914 }915 else {916 vnodeChildren = node.children;917 }918 }919 // patchFlag & dynamicPropNames920 if (patchFlag !== 0) {921 {922 if (patchFlag < 0) {923 // special flags (negative and mutually exclusive)924 vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;925 }926 else {927 // bitwise flags928 const flagNames = Object.keys(PatchFlagNames)929 .map(Number)930 .filter(n => n > 0 && patchFlag & n)931 .map(n => PatchFlagNames[n])932 .join(`, `);933 vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;934 }935 }936 if (dynamicPropNames && dynamicPropNames.length) {937 vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);938 }939 }940 // function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, loc = locStub) 941 node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, vnodePatchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false /* disableTracking */, node.loc);942 };943 };944 function stringifyDynamicPropNames(props) {945 let propsNamesString = `[`;946 for (let i = 0, l = props.length; i < l; i++) {947 propsNamesString += JSON.stringify(props[i]);948 if (i < l - 1)949 propsNamesString += ', ';950 }951 return propsNamesString + `]`;952 }953 /**954 * Even for a node with no patch flag, it is possible for it to contain955 * non-hoistable expressions that refers to scope variables, e.g. compiler956 * injected keys or cached event handlers. Therefore we need to always check the957 * codegenNode's props to be sure.958 */959 function hasNonHoistableProps(node) {960 const props = getNodeProps(node);961 if (props && props.type === 15 /* JS_OBJECT_EXPRESSION */) {962 const { properties } = props;963 for (let i = 0; i < properties.length; i++) {964 const { key, value } = properties[i];965 if (key.type !== 4 /* SIMPLE_EXPRESSION */ ||966 !key.isStatic ||967 (value.type !== 4 /* SIMPLE_EXPRESSION */ ||968 (!value.isStatic && !value.isConstant))) {969 return true;970 }971 }972 }973 return false;974 }975 const vModelSelect = {976 created(el, binding, vnode) {977 addEventListener(el, 'change', () => {978 const selectedVal = Array.prototype.filter979 .call(el.options, (o) => o.selected)980 .map(getValue);981 el._assign(el.multiple ? selectedVal : selectedVal[0]);982 });983 el._assign = getModelAssigner(vnode);984 },985 // set value in mounted & updated because <select> relies on its children986 // <option>s.987 mounted(el, { value }) {988 setSelected(el, value);989 },990 beforeUpdate(el, _binding, vnode) {991 el._assign = getModelAssigner(vnode);992 },993 updated(el, { value }) {994 setSelected(el, value);995 }996 };997 /**998 * 999 * node.type:0 ROOT 1 ELEMENT 2 TEXT 3 COMMENT 4 SIMPLE_EXPRESSION 5 INTERPOLATION 8 COMPOUND_EXPRESSION 9 IF 10 IF_BRANCH IF 11 FOR 12 TEXT_CALL1000 * 1001 * static type 0 NOT_STATIC 1 FULL_STATIC 2 HAS_RUNTIME_CONSTANT1002 * tagtype: 0 element 1 template 2 slot1003 * 1004 * codegennode.patchFlag -2 BAIL -1 HOISTED 1 TEXT 2 CLASS 4 STYLE 8 PROPS 16 FULL_PROPS 32 HYDRATE_EVENTS 64 STABLE_FRAGMENT 128 KEYED_FRAGMENT 256 UNKEYED_FRAGMENT 512 NEED_PATCH 1024 DYNAMIC_SLOTS1005 * 1006 */1007 function getStaticType(node, resultCache = new Map()) { // 0 NOT_STATIC 1 FULL_STATIC 2 HAS_RUNTIME_CONSTANT1008 switch (node.type) {1009 case 1 /* ELEMENT */:1010 if (node.tagType !== 0 /* ELEMENT */) {1011 return 0 /* NOT_STATIC */;1012 }1013 const cached = resultCache.get(node);1014 if (cached !== undefined) {1015 return cached;1016 }1017 const codegenNode = node.codegenNode;1018 if (codegenNode.type !== 13 /* VNODE_CALL */) {1019 return 0 /* NOT_STATIC */;1020 }1021 const flag = getPatchFlag(codegenNode);1022 if (!flag && !hasNonHoistableProps(node)) {1023 // element self is static. check its children.1024 let returnType = 1 /* FULL_STATIC */;1025 for (let i = 0; i < node.children.length; i++) {1026 const childType = getStaticType(node.children[i], resultCache);1027 if (childType === 0 /* NOT_STATIC */) {1028 resultCache.set(node, 0 /* NOT_STATIC */);1029 return 0 /* NOT_STATIC */;1030 }1031 else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {1032 returnType = 2 /* HAS_RUNTIME_CONSTANT */;1033 }1034 }1035 // check if any of the props contain runtime constants1036 if (returnType !== 2 /* HAS_RUNTIME_CONSTANT */) {1037 for (let i = 0; i < node.props.length; i++) {1038 const p = node.props[i];1039 if (p.type === 7 /* DIRECTIVE */ &&1040 p.name === 'bind' &&1041 p.exp &&1042 (p.exp.type === 8 /* COMPOUND_EXPRESSION */ ||1043 p.exp.isRuntimeConstant)) {1044 returnType = 2 /* HAS_RUNTIME_CONSTANT */;1045 }1046 }1047 }1048 // only svg/foreignObject could be block here, however if they are1049 // stati then they don't need to be blocks since there will be no1050 // nested updates.1051 if (codegenNode.isBlock) {1052 codegenNode.isBlock = false;1053 }1054 resultCache.set(node, returnType);1055 return returnType;1056 }1057 else {1058 resultCache.set(node, 0 /* NOT_STATIC */);1059 return 0 /* NOT_STATIC */;1060 }1061 case 2 /* TEXT */:1062 case 3 /* COMMENT */:1063 return 1 /* FULL_STATIC */;1064 case 9 /* IF */:1065 case 11 /* FOR */:1066 case 10 /* IF_BRANCH */:1067 return 0 /* NOT_STATIC */;1068 case 5 /* INTERPOLATION */:1069 case 12 /* TEXT_CALL */:1070 return getStaticType(node.content, resultCache);1071 case 4 /* SIMPLE_EXPRESSION */:1072 return node.isConstant1073 ? node.isRuntimeConstant1074 ? 2 /* HAS_RUNTIME_CONSTANT */1075 : 1 /* FULL_STATIC */1076 : 0 /* NOT_STATIC */;1077 case 8 /* COMPOUND_EXPRESSION */:1078 let returnType = 1 /* FULL_STATIC */;1079 for (let i = 0; i < node.children.length; i++) {1080 const child = node.children[i];1081 if (isString(child) || isSymbol(child)) {1082 continue;1083 }1084 const childType = getStaticType(child, resultCache);1085 if (childType === 0 /* NOT_STATIC */) {1086 return 0 /* NOT_STATIC */;1087 }1088 else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {1089 returnType = 2 /* HAS_RUNTIME_CONSTANT */;1090 }1091 }1092 return returnType;1093 default:1094 return 0 /* NOT_STATIC */;1095 }1096 }1097 /**1098 * context.scopes1099 * scopes: {1100 vFor: 0,1101 vSlot: 0,1102 vPre: 0,1103 vOnce: 01104 },1105 */1106 function isCoreComponent(tag) {1107 if (isBuiltInType(tag, 'Teleport')) {1108 return TELEPORT;1109 }1110 else if (isBuiltInType(tag, 'Suspense')) {1111 return SUSPENSE;1112 }1113 else if (isBuiltInType(tag, 'KeepAlive')) {1114 return KEEP_ALIVE;1115 }1116 else if (isBuiltInType(tag, 'BaseTransition')) {1117 return BASE_TRANSITION;1118 }1119 }1120 const buildClientSlotFn = (props, children, loc) => {1121 createFunctionExpression(props, children, false /* newline */, true /* isSlot */, children.length ? children[0].loc : loc);1122 }1123 function createFunctionExpression(params, returns = undefined, newline = false, isSlot = false, loc = locStub) {1124 return {1125 type: 18 /* JS_FUNCTION_EXPRESSION */,1126 params,1127 returns,1128 newline,1129 isSlot,1130 loc1131 };1132 }1133 function buildDynamicSlot(name, fn) {1134 return createObjectExpression([1135 createObjectProperty(`name`, name),1136 createObjectProperty(`fn`, fn)1137 ]);1138 }1139 function createConditionalExpression(test, consequent, alternate, newline = true) {1140 return {1141 type: 19 /* JS_CONDITIONAL_EXPRESSION */,1142 test,1143 consequent,1144 alternate,1145 newline,1146 loc: locStub1147 };1148 }1149 function createForLoopParams({ value, key, index }) {1150 const params = [];1151 if (value) {1152 params.push(value);1153 }1154 if (key) {1155 if (!value) {1156 params.push(createSimpleExpression(`_`, false));1157 }1158 params.push(key);1159 }1160 if (index) {1161 if (!key) {1162 if (!value) {1163 params.push(createSimpleExpression(`_`, false));1164 }1165 params.push(createSimpleExpression(`__`, false));1166 }1167 params.push(index);1168 }1169 return params;1170 }1171 // Instead of being a DirectiveTransform, v-slot processing is called during1172 // transformElement to build the slots object for a component.1173 function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {1174 context.helper(WITH_CTX);1175 const { children, loc } = node;1176 const slotsProperties = [];1177 const dynamicSlots = [];1178 const buildDefaultSlotProperty = (props, children) => createObjectProperty(`default`, buildSlotFn(props, children, loc));1179 // If the slot is inside a v-for or another v-slot, force it to be dynamic1180 // since it likely uses a scope variable.1181 1182 let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;1183 // 1. Check for slot with slotProps on component itself.1184 // <Comp v-slot="{ prop }"/>1185 const onComponentSlot = findDir(node, 'slot', true);1186 if (onComponentSlot) {1187 const { arg, exp } = onComponentSlot;1188 if (arg && !isStaticExp(arg)) {1189 hasDynamicSlots = true;1190 }1191 slotsProperties.push(createObjectProperty(arg || createSimpleExpression('default', true), buildSlotFn(exp, children, loc)));1192 }1193 // 2. Iterate through children and check for template slots1194 // <template v-slot:foo="{ prop }">1195 let hasTemplateSlots = false;1196 let hasNamedDefaultSlot = false;1197 const implicitDefaultChildren = [];1198 const seenSlotNames = new Set();1199 for (let i = 0; i < children.length; i++) {1200 const slotElement = children[i];1201 let slotDir;1202 if (!isTemplateNode(slotElement) ||1203 !(slotDir = findDir(slotElement, 'slot', true))) {1204 // not a <template v-slot>, skip.1205 if (slotElement.type !== 3 /* COMMENT */) {1206 implicitDefaultChildren.push(slotElement);1207 }1208 continue;1209 }1210 if (onComponentSlot) {1211 // already has on-component slot - this is incorrect usage.1212 context.onError(createCompilerError(36 /* X_V_SLOT_MIXED_SLOT_USAGE */, slotDir.loc));1213 break;1214 }1215 hasTemplateSlots = true;1216 const { children: slotChildren, loc: slotLoc } = slotElement;1217 const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;1218 // check if name is dynamic.1219 let staticSlotName;1220 if (isStaticExp(slotName)) {1221 staticSlotName = slotName ? slotName.content : `default`;1222 }1223 else {1224 hasDynamicSlots = true;1225 }1226 const slotFunction = buildSlotFn(slotProps, slotChildren, slotLoc);1227 // check if this slot is conditional (v-if/v-for)1228 let vIf;1229 let vElse;1230 let vFor;1231 if ((vIf = findDir(slotElement, 'if'))) {1232 hasDynamicSlots = true;1233 dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback));1234 }1235 else if ((vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))) {1236 // find adjacent v-if1237 let j = i;1238 let prev;1239 while (j--) {1240 prev = children[j];1241 if (prev.type !== 3 /* COMMENT */) {1242 break;1243 }1244 }1245 if (prev && isTemplateNode(prev) && findDir(prev, 'if')) {1246 // remove node1247 children.splice(i, 1);1248 i--;1249 // attach this slot to previous conditional1250 let conditional = dynamicSlots[dynamicSlots.length - 1];1251 while (conditional.alternate.type === 19 /* JS_CONDITIONAL_EXPRESSION */) {1252 conditional = conditional.alternate;1253 }1254 conditional.alternate = vElse.exp1255 ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction), defaultFallback)1256 : buildDynamicSlot(slotName, slotFunction);1257 }1258 else {1259 context.onError(createCompilerError(29 /* X_V_ELSE_NO_ADJACENT_IF */, vElse.loc));1260 }1261 }1262 else if ((vFor = findDir(slotElement, 'for'))) {1263 hasDynamicSlots = true;1264 const parseResult = vFor.parseResult ||1265 parseForExpression(vFor.exp, context);1266 if (parseResult) {1267 // Render the dynamic slots as an array and add it to the createSlot()1268 // args. The runtime knows how to handle it appropriately.1269 dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [1270 parseResult.source,1271 createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true /* force newline */)1272 ]));1273 }1274 else {1275 context.onError(createCompilerError(31 /* X_V_FOR_MALFORMED_EXPRESSION */, vFor.loc));1276 }1277 }1278 else {1279 // check duplicate static names1280 if (staticSlotName) {1281 if (seenSlotNames.has(staticSlotName)) {1282 context.onError(createCompilerError(37 /* X_V_SLOT_DUPLICATE_SLOT_NAMES */, dirLoc));1283 continue;1284 }1285 seenSlotNames.add(staticSlotName);1286 if (staticSlotName === 'default') {1287 hasNamedDefaultSlot = true;1288 }1289 }1290 slotsProperties.push(createObjectProperty(slotName, slotFunction));1291 }1292 }1293 if (!onComponentSlot) {1294 if (!hasTemplateSlots) {1295 // implicit default slot (on component)1296 slotsProperties.push(buildDefaultSlotProperty(undefined, children));1297 }1298 else if (implicitDefaultChildren.length) {1299 // implicit default slot (mixed with named slots)1300 if (hasNamedDefaultSlot) {1301 context.onError(createCompilerError(38 /* X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */, implicitDefaultChildren[0].loc));1302 }1303 else {1304 slotsProperties.push(buildDefaultSlotProperty(undefined, implicitDefaultChildren));1305 }1306 }1307 }1308 const slotFlag = hasDynamicSlots1309 ? 2 /* DYNAMIC */1310 : hasForwardedSlots(node.children)1311 ? 3 /* FORWARDED */1312 : 1 /* STABLE */;1313 let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`, 1314 // 2 = compiled but dynamic = can skip normalization, but must run diff1315 // 1 = compiled and static = can skip normalization AND diff as optimized1316 createSimpleExpression('' + slotFlag, false))), loc);1317 if (dynamicSlots.length) {1318 slots = createCallExpression(context.helper(CREATE_SLOTS), [1319 slots,1320 createArrayExpression(dynamicSlots)1321 ]);1322 }1323 return {1324 slots,1325 hasDynamicSlots1326 };1327 }1328 const trackSlotScopes = (node, context) => {1329 if (node.type === 1 /* ELEMENT */ &&1330 (node.tagType === 1 /* COMPONENT */ ||1331 node.tagType === 3 /* TEMPLATE */)) {1332 // We are only checking non-empty v-slot here1333 // since we only care about slots that introduce scope variables.1334 const vSlot = findDir(node, 'slot');1335 if (vSlot) {1336 const slotProps = vSlot.exp;1337 context.scopes.vSlot++;1338 return () => {1339 context.scopes.vSlot--;1340 };1341 }1342 }1343 };1344 // Merge adjacent text nodes and expressions into a single expression1345 // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.1346 const transformText = (node, context) => {1347 if (node.type === 0 /* ROOT */ ||1348 node.type === 1 /* ELEMENT */ ||1349 node.type === 11 /* FOR */ ||1350 node.type === 10 /* IF_BRANCH */) {1351 // perform the transform on node exit so that all expressions have already1352 // been processed.1353 return () => {1354 const children = node.children;1355 let currentContainer = undefined;1356 let hasText = false;1357 for (let i = 0; i < children.length; i++) {1358 const child = children[i];1359 if (isText(child)) {1360 hasText = true;1361 for (let j = i + 1; j < children.length; j++) {1362 const next = children[j];1363 if (isText(next)) {1364 if (!currentContainer) {1365 currentContainer = children[i] = {1366 type: 8 /* COMPOUND_EXPRESSION */,1367 loc: child.loc,1368 children: [child]1369 };1370 }1371 // merge adjacent text node into current1372 currentContainer.children.push(` + `, next);1373 children.splice(j, 1);1374 j--;1375 }1376 else {1377 currentContainer = undefined;1378 break;1379 }1380 }1381 }1382 }1383 if (!hasText ||1384 // if this is a plain element with a single text child, leave it1385 // as-is since the runtime has dedicated fast path for this by directly1386 // setting textContent of the element.1387 // for component root it's always normalized anyway.1388 (children.length === 1 &&1389 (node.type === 0 /* ROOT */ ||1390 (node.type === 1 /* ELEMENT */ &&1391 node.tagType === 0 /* ELEMENT */)))) {1392 return;1393 }1394 // pre-convert text nodes into createTextVNode(text) calls to avoid1395 // runtime normalization.1396 for (let i = 0; i < children.length; i++) {1397 const child = children[i];1398 if (isText(child) || child.type === 8 /* COMPOUND_EXPRESSION */) {1399 const callArgs = [];1400 // createTextVNode defaults to single whitespace, so if it is a1401 // single space the code could be an empty call to save bytes.1402 if (child.type !== 2 /* TEXT */ || child.content !== ' ') {1403 callArgs.push(child);1404 }1405 // mark dynamic text with flag so it gets patched inside a block1406 if (!context.ssr && child.type !== 2 /* TEXT */) {1407 callArgs.push(`${1 /* TEXT */} /* ${PatchFlagNames[1 /* TEXT */]} */`);1408 }1409 children[i] = {1410 type: 12 /* TEXT_CALL */,1411 content: child,1412 loc: child.loc,1413 codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)1414 };1415 }1416 }1417 };1418 }1419 };1420 // 2.2 directiveTransforms1421 const transformOn = (dir, node, context, augmentor) => {1422 const { loc, modifiers, arg } = dir;1423 if (!dir.exp && !modifiers.length) {1424 context.onError(createCompilerError(34 /* X_V_ON_NO_EXPRESSION */, loc));1425 }1426 let eventName;1427 if (arg.type === 4 /* SIMPLE_EXPRESSION */) {1428 if (arg.isStatic) {1429 const rawName = arg.content;1430 // for @vnode-xxx event listeners, auto convert it to camelCase1431 const normalizedName = rawName.startsWith(`vnode`)1432 ? capitalize(camelize(rawName))1433 : capitalize(rawName);1434 eventName = createSimpleExpression(`on${normalizedName}`, true, arg.loc);1435 }1436 else {1437 eventName = createCompoundExpression([1438 `"on" + ${context.helperString(CAPITALIZE)}(`,1439 arg,1440 `)`1441 ]);1442 }1443 }1444 else {1445 // already a compound expression.1446 eventName = arg;1447 eventName.children.unshift(`"on" + ${context.helperString(CAPITALIZE)}(`);1448 eventName.children.push(`)`);1449 }1450 // handler processing1451 let exp = dir.exp;1452 if (exp && !exp.content.trim()) {1453 exp = undefined;1454 }1455 let isCacheable = context.cacheHandlers && !exp;1456 if (exp) {1457 const isMemberExp = isMemberExpression(exp.content);1458 const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));1459 const hasMultipleStatements = exp.content.includes(`;`);1460 {1461 validateBrowserExpression(exp, context, false, hasMultipleStatements);1462 }1463 if (isInlineStatement || (isCacheable && isMemberExp)) {1464 // wrap inline statement in a function expression1465 exp = createCompoundExpression([1466 `${isInlineStatement ? `$event` : `(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,1467 exp,1468 hasMultipleStatements ? `}` : `)`1469 ]);1470 }1471 }1472 let ret = {1473 props: [1474 createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))1475 ]1476 };1477 // apply extended compiler augmentor1478 if (augmentor) {1479 ret = augmentor(ret);1480 }1481 if (isCacheable) {1482 // cache handlers so that it's always the same handler being passed down.1483 // this avoids unnecessary re-renders when users use inline handlers on1484 // components.1485 ret.props[0].value = context.cache(ret.props[0].value);1486 }1487 return ret;1488 };1489 // v-bind without arg is handled directly in ./transformElements.ts due to it affecting1490 // codegen for the entire props object. This transform here is only for v-bind1491 // *with* args.1492 const transformBind = (dir, node, context) => {1493 const { exp, modifiers, loc } = dir;1494 const arg = dir.arg;1495 // .prop is no longer necessary due to new patch behavior1496 // .sync is replaced by v-model:arg1497 if (modifiers.includes('camel')) {1498 if (arg.type === 4 /* SIMPLE_EXPRESSION */) {1499 if (arg.isStatic) {1500 arg.content = camelize(arg.content);1501 }1502 else {1503 arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;1504 }1505 }1506 else {1507 arg.children.unshift(`${context.helperString(CAMELIZE)}(`);1508 arg.children.push(`)`);1509 }1510 }1511 if (!exp ||1512 (exp.type === 4 /* SIMPLE_EXPRESSION */ && !exp.content.trim())) {1513 context.onError(createCompilerError(33 /* X_V_BIND_NO_EXPRESSION */, loc));1514 return {1515 props: [createObjectProperty(arg, createSimpleExpression('', true, loc))]1516 };1517 }1518 return {1519 props: [createObjectProperty(arg, exp)]1520 };1521 };1522 const transformModel = (dir, node, context) => {1523 const { exp, arg } = dir;1524 if (!exp) {1525 context.onError(createCompilerError(40 /* X_V_MODEL_NO_EXPRESSION */, dir.loc));1526 return createTransformProps();1527 }1528 const expString = exp.type === 4 /* SIMPLE_EXPRESSION */ ? exp.content : exp.loc.source;1529 if (!isMemberExpression(expString)) {1530 context.onError(createCompilerError(41 /* X_V_MODEL_MALFORMED_EXPRESSION */, exp.loc));1531 return createTransformProps();1532 }1533 const propName = arg ? arg : createSimpleExpression('modelValue', true);1534 const eventName = arg1535 ? isStaticExp(arg)1536 ? `onUpdate:${arg.content}`1537 : createCompoundExpression(['"onUpdate:" + ', arg])1538 : `onUpdate:modelValue`;1539 const props = [1540 // modelValue: foo1541 createObjectProperty(propName, dir.exp),1542 // "onUpdate:modelValue": $event => (foo = $event)1543 createObjectProperty(eventName, createCompoundExpression([`$event => (`, exp, ` = $event)`]))1544 ];1545 // modelModifiers: { foo: true, "bar-baz": true }1546 if (dir.modifiers.length && node.tagType === 1 /* COMPONENT */) {1547 const modifiers = dir.modifiers1548 .map(m => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`)1549 .join(`, `);1550 const modifiersKey = arg1551 ? isStaticExp(arg)1552 ? `${arg.content}Modifiers`1553 : createCompoundExpression([arg, ' + "Modifiers"'])1554 : `modelModifiers`;1555 props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, true)));1556 }1557 return createTransformProps(props);1558 };1559/**1560 * 3 转æ¢1561 * transform(ast, extend({}, options, {1562 prefixIdentifiers,1563 nodeTransforms: [1564 ...nodeTransforms,1565 ...(options.nodeTransforms || []) // user transforms1566 ],1567 directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {} // user transforms1568 )1569 }));1570 */1571function transform(root, options) {1572 const context = createTransformContext(root, options);1573 traverseNode(root, context);1574 if (options.hoistStatic) {1575 hoistStatic(root, context);1576 }1577 if (!options.ssr) {1578 createRootCodegen(root, context);1579 }1580 // finalize meta information1581 root.helpers = [...context.helpers];1582 root.components = [...context.components];1583 root.directives = [...context.directives];1584 root.imports = [...context.imports];1585 root.hoists = context.hoists;1586 root.temps = context.temps;1587 root.cached = context.cached;1588}1589 // 3.1 createTransformContext(root, options);1590 function createTransformContext(root, { prefixIdentifiers = false, hoistStatic = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, expressionPlugins = [], scopeId = null, ssr = false, ssrCssVars = ``, bindingMetadata = {}, onError = defaultOnError }) {1591 const context = {1592 // options1593 prefixIdentifiers,1594 hoistStatic,1595 cacheHandlers,1596 nodeTransforms,1597 directiveTransforms,1598 transformHoist,1599 isBuiltInComponent,1600 isCustomElement,1601 expressionPlugins,1602 scopeId,1603 ssr,1604 ssrCssVars,1605 bindingMetadata,1606 onError,1607 // state1608 root,1609 helpers: new Set(),1610 components: new Set(),1611 directives: new Set(),1612 hoists: [],1613 imports: new Set(),1614 temps: 0,1615 cached: 0,1616 identifiers: Object.create(null),1617 scopes: {1618 vFor: 0,1619 vSlot: 0,1620 vPre: 0,1621 vOnce: 01622 },1623 parent: null,1624 currentNode: root,1625 childIndex: 0,1626 // methods1627 helper(name) {1628 context.helpers.add(name);1629 return name;1630 },1631 helperString(name) {1632 return `_${helperNameMap[context.helper(name)]}`;1633 },1634 replaceNode(node) {1635 /* istanbul ignore if */1636 {1637 if (!context.currentNode) {1638 throw new Error(`Node being replaced is already removed.`);1639 }1640 if (!context.parent) {1641 throw new Error(`Cannot replace root node.`);1642 }1643 }1644 context.parent.children[context.childIndex] = context.currentNode = node;1645 },1646 removeNode(node) {1647 if ( !context.parent) {1648 throw new Error(`Cannot remove root node.`);1649 }1650 const list = context.parent.children;1651 const removalIndex = node1652 ? list.indexOf(node)1653 : context.currentNode1654 ? context.childIndex1655 : -1;1656 /* istanbul ignore if */1657 if ( removalIndex < 0) {1658 throw new Error(`node being removed is not a child of current parent`);1659 }1660 if (!node || node === context.currentNode) {1661 // current node removed1662 context.currentNode = null;1663 context.onNodeRemoved();1664 }1665 else {1666 // sibling node removed1667 if (context.childIndex > removalIndex) {1668 context.childIndex--;1669 context.onNodeRemoved();1670 }1671 }1672 context.parent.children.splice(removalIndex, 1);1673 },1674 onNodeRemoved: () => { },1675 addIdentifiers(exp) {1676 },1677 removeIdentifiers(exp) {1678 },1679 hoist(exp) {1680 context.hoists.push(exp);1681 const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, true);1682 identifier.hoisted = exp;1683 return identifier;1684 },1685 cache(exp, isVNode = false) {1686 return createCacheExpression(++context.cached, exp, isVNode);1687 }1688 };1689 return context;1690 }1691 // 3.2 traverseNode(node, context)1692 function traverseNode(node, context) {1693 context.currentNode = node;1694 // apply transform plugins1695 const { nodeTransforms } = context;1696 const exitFns = [];1697 for (let i = 0; i < nodeTransforms.length; i++) {1698 const onExit = nodeTransforms[i](node, context);1699 if (onExit) {1700 if (isArray(onExit)) {1701 exitFns.push(...onExit);1702 }1703 else {1704 exitFns.push(onExit);1705 }1706 }1707 if (!context.currentNode) {1708 // node was removed1709 return;1710 }1711 else {1712 // node may have been replaced1713 node = context.currentNode;1714 }1715 }1716 switch (node.type) {1717 case 3 /* COMMENT */:1718 if (!context.ssr) {1719 // inject import for the Comment symbol, which is needed for creating1720 // comment nodes with `createVNode`1721 context.helper(CREATE_COMMENT);1722 }1723 break;1724 case 5 /* INTERPOLATION */:1725 // no need to traverse, but we need to inject toString helper1726 if (!context.ssr) {1727 context.helper(TO_DISPLAY_STRING);1728 }1729 break;1730 // for container types, further traverse downwards1731 case 9 /* IF */:1732 for (let i = 0; i < node.branches.length; i++) {1733 traverseNode(node.branches[i], context);1734 }1735 break;1736 case 10 /* IF_BRANCH */:1737 case 11 /* FOR */:1738 case 1 /* ELEMENT */:1739 case 0 /* ROOT */:1740 traverseChildren(node, context);1741 break;1742 }1743 // exit transforms1744 context.currentNode = node;1745 let i = exitFns.length;1746 while (i--) {1747 exitFns[i]();1748 }1749 }1750 function hoistStatic(root, context) {1751 walk(root, context, new Map(), 1752 // Root node is unfortunately non-hoistable due to potential parent1753 // fallthrough attributes.1754 isSingleElementRoot(root, root.children[0]));1755 }1756 /**1757 * context.hoists: []1758 */1759 function hoist(exp) {1760 context.hoists.push(exp);1761 const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, true);1762 identifier.hoisted = exp;1763 return identifier;1764 }1765 function isSingleElementRoot(root, child) {1766 const { children } = root;1767 return (children.length === 1 &&1768 child.type === 1 /* ELEMENT */ &&1769 !isSlotOutlet(child));1770 }1771 function walk(node, context, resultCache, doNotHoistNode = false) {1772 let hasHoistedNode = false;1773 // Some transforms, e.g. transformAssetUrls from @vue/compiler-sfc, replaces1774 // static bindings with expressions. These expressions are guaranteed to be1775 // constant so they are still eligible for hoisting, but they are only1776 // available at runtime and therefore cannot be evaluated ahead of time.1777 // This is only a concern for pre-stringification (via transformHoist by1778 // @vue/compiler-dom), but doing it here allows us to perform only one full1779 // walk of the AST and allow `stringifyStatic` to stop walking as soon as its1780 // stringficiation threshold is met.1781 let hasRuntimeConstant = false;1782 const { children } = node;1783 for (let i = 0; i < children.length; i++) {1784 const child = children[i];1785 // only plain elements & text calls are eligible for hoisting.1786 if (child.type === 1 /* ELEMENT */ &&1787 child.tagType === 0 /* ELEMENT */) {1788 let staticType;1789 if (!doNotHoistNode &&1790 (staticType = getStaticType(child, resultCache)) > 0) {1791 if (staticType === 2 /* HAS_RUNTIME_CONSTANT */) {1792 hasRuntimeConstant = true;1793 }1794 child.codegenNode.patchFlag =1795 -1 /* HOISTED */ + ( ` /* HOISTED */` );1796 child.codegenNode = context.hoist(child.codegenNode);1797 hasHoistedNode = true;1798 continue;1799 }1800 else {1801 // node may contain dynamic children, but its props may be eligible for1802 // hoisting.1803 const codegenNode = child.codegenNode;1804 if (codegenNode.type === 13 /* VNODE_CALL */) {1805 const flag = getPatchFlag(codegenNode);1806 if ((!flag ||1807 flag === 512 /* NEED_PATCH */ ||1808 flag === 1 /* TEXT */) &&1809 !hasNonHoistableProps(child)) {1810 const props = getNodeProps(child);1811 if (props) {1812 codegenNode.props = context.hoist(props);1813 }1814 }1815 }1816 }1817 }1818 else if (child.type === 12 /* TEXT_CALL */) {1819 const staticType = getStaticType(child.content, resultCache);...
simpleExpression.js
Source:simpleExpression.js
...20 const codegenNode = node.codegenNode;21 if (codegenNode.type !== 13 /* VNODE_CALL */) {22 return 0 /* NOT_STATIC */;23 }24 const flag = getPatchFlag(codegenNode);25 if (!flag && !hasNonHoistableProps(node)) {26 // element self is static. check its children.27 let returnType = 1 /* FULL_STATIC */;28 for (let i = 0; i < node.children.length; i++) {29 const childType = getStaticType(node.children[i], resultCache);30 if (childType === 0 /* NOT_STATIC */) {31 resultCache.set(node, 0 /* NOT_STATIC */);32 return 0 /* NOT_STATIC */;33 }34 else if (childType === 2 /* HAS_RUNTIME_CONSTANT */) {35 returnType = 2 /* HAS_RUNTIME_CONSTANT */;36 }37 }38 // check if any of the props contain runtime constants...
hoistStatic.js
Source:hoistStatic.js
...26 }27 else {28 var codegenNode = child.codegenNode;29 if (codegenNode.type === 13) {30 var flag = getPatchFlag(codegenNode);31 if ((!flag ||32 flag === shared_1.PatchFlags.NEED_PATCH ||33 flag === shared_1.PatchFlags.TEXT) &&34 !hasDynamicKeyOrRef(child) &&35 !hasCachedProps(child)) {36 var props = getNodeProps(child);37 if (props && props !== "null") {38 getVNodeCall(codegenNode).arguments[1] = context.hoist(props);39 }40 }41 }42 }43 }44 if (child.type === 1) {45 walk(child.children, context, resultCache);46 }47 else if (child.type === 11) {48 walk(child.children, context, resultCache, child.children.length === 1);49 }50 else if (child.type === 9) {51 for (var i_1 = 0; i_1 < child.branches.length; i_1++) {52 var branchChildren = child.branches[i_1].children;53 walk(branchChildren, context, resultCache, branchChildren.length === 1);54 }55 }56 }57}58function isStaticNode(node, resultCache) {59 if (resultCache === void 0) { resultCache = new Map(); }60 switch (node.type) {61 case 1:62 if (node.tagType !== 0) {63 return false;64 }65 var cached = resultCache.get(node);66 if (cached !== undefined) {67 return cached;68 }69 var codegenNode = node.codegenNode;70 if (codegenNode.type !== 13) {71 return false;72 }73 var flag = getPatchFlag(codegenNode);74 if (!flag && !hasDynamicKeyOrRef(node) && !hasCachedProps(node)) {75 for (var i = 0; i < node.children.length; i++) {76 if (!isStaticNode(node.children[i], resultCache)) {77 resultCache.set(node, false);78 return false;79 }80 }81 resultCache.set(node, true);82 return true;83 }84 else {85 resultCache.set(node, false);86 return false;87 }88 case 2:89 case 3:90 return true;91 case 9:92 case 11:93 return false;94 case 5:95 case 12:96 return isStaticNode(node.content, resultCache);97 case 4:98 return node.isConstant;99 case 8:100 return node.children.every(function (child) {101 return (shared_1.isString(child) || shared_1.isSymbol(child) || isStaticNode(child, resultCache));102 });103 default:104 if (__DEV__) {105 var exhaustiveCheck = node;106 exhaustiveCheck;107 }108 return false;109 }110}111exports.isStaticNode = isStaticNode;112function hasDynamicKeyOrRef(node) {113 return !!(utils_1.findProp(node, 'key', true) || utils_1.findProp(node, 'ref', true));114}115function hasCachedProps(node) {116 if (__BROWSER__) {117 return false;118 }119 var props = getNodeProps(node);120 if (props &&121 props !== 'null' &&122 props.type === 14) {123 var properties = props.properties;124 for (var i = 0; i < properties.length; i++) {125 if (properties[i].value.type === 20) {126 return true;127 }128 }129 }130 return false;131}132function getNodeProps(node) {133 var codegenNode = node.codegenNode;134 if (codegenNode.type === 13) {135 return getVNodeArgAt(codegenNode, 1);136 }137}138function getVNodeArgAt(node, index) {139 return getVNodeCall(node).arguments[index];140}141function getVNodeCall(node) {142 return node.callee === runtimeHelpers_1.WITH_DIRECTIVES ? node.arguments[0] : node;143}144function getPatchFlag(node) {145 var flag = getVNodeArgAt(node, 3);146 return flag ? parseInt(flag, 10) : undefined;...
Using AI Code Generation
1const { getPatchFlag } = require('playwright/lib/client/patchTypes');2const { getPatchFlag } = require('playwright/lib/client/patchTypes');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 const client = await page.context().newCDPSession(page);9 await client.send('DOM.enable');10 await client.send('CSS.enable');11 const patchFlag = await getPatchFlag(page, 'input');12 console.log(patchFlag);13 await browser.close();14})();15### getPatchFlag(page: Page, selector: string): Promise<number>16[MIT](./LICENSE)
Using AI Code Generation
1const { getPatchFlag } = require('playwright/lib/server/supplements/recorder/recorderApp');2const { test } = require('playwright');3(async () => {4 const browser = await test.launch();5 const page = await browser.newPage();6 await page.click('[aria-label="Search"]');7 await page.fill('[aria-label="Search"]', 'Hello');8 console.log(getPatchFlag('fill', 'aria-label="Search"', 'Hello'));9 await browser.close();10})();
Using AI Code Generation
1const { getPatchFlag } = require('playwright-core/lib/server/common/patchRegistry');2const { patchTypes } = require('playwright-core/lib/server/common/patchTypes');3console.log(getPatchFlag(patchTypes.CHROMIUM));4const { getPatchFlag } = require('playwright-core/lib/server/common/patchRegistry');5const { patchTypes } = require('playwright-core/lib/server/common/patchTypes');6console.log(getPatchFlag(patchTypes.CHROMIUM));7const { getPatchFlag } = require('playwright-core/lib/server/common/patchRegistry');8const { patchTypes } = require('playwright-core/lib/server/common/patchTypes');9console.log(getPatchFlag(patchTypes.CHROMIUM));
Using AI Code Generation
1const { getPatchFlag } = require('playwright');2const patchFlag = getPatchFlag('aria-label');3console.log(patchFlag);4const patchFlag = getPatchFlag('aria-label');5console.log(patchFlag);6const patchFlag = getPatchFlag('aria-label');7console.log(patchFlag);8const patchFlag = getPatchFlag('aria-label');9console.log(patchFlag);10const patchFlag = getPatchFlag('aria-label');11console.log(patchFlag);12const patchFlag = getPatchFlag('aria-label');13console.log(patchFlag);14const patchFlag = getPatchFlag('aria-label');15console.log(patchFlag);16const patchFlag = getPatchFlag('aria-label');17console.log(patchFlag);18const patchFlag = getPatchFlag('aria-label');19console.log(patchFlag);20const patchFlag = getPatchFlag('aria-label');21console.log(patchFlag);22const patchFlag = getPatchFlag('aria-label');23console.log(patchFlag);
Using AI Code Generation
1const { getPatchFlag } = require('./node_modules/playwright/lib/server/domPatch.js');2console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid' } }));3console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass' } }));4console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red' } }));5console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' } }));6console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo'] }));7console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo', 'bar'] }));8console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo', 'bar', 'baz'] }));9console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo', 'bar', 'baz', 'qux'] }));10console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo', 'bar', 'baz', 'qux', 'quux'] }));11console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid', class: 'myclass', style: 'color:red', 'data-foo': 'bar' }, children: ['foo', 'bar', 'baz', 'qux', 'quux', 'quuz'] }));12console.log(getPatchFlag({ name: 'div', attrs: { id: 'myid
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!