[57e58a3] | 1 | /**
|
---|
| 2 | * @vue/compiler-dom v3.5.13
|
---|
| 3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
| 4 | * @license MIT
|
---|
| 5 | **/
|
---|
| 6 | /*! #__NO_SIDE_EFFECTS__ */
|
---|
| 7 | // @__NO_SIDE_EFFECTS__
|
---|
| 8 | function makeMap(str) {
|
---|
| 9 | const map = /* @__PURE__ */ Object.create(null);
|
---|
| 10 | for (const key of str.split(",")) map[key] = 1;
|
---|
| 11 | return (val) => val in map;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | const EMPTY_OBJ = Object.freeze({}) ;
|
---|
| 15 | const NOOP = () => {
|
---|
| 16 | };
|
---|
| 17 | const NO = () => false;
|
---|
| 18 | const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && // uppercase letter
|
---|
| 19 | (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
|
---|
| 20 | const extend = Object.assign;
|
---|
| 21 | const isArray = Array.isArray;
|
---|
| 22 | const isString = (val) => typeof val === "string";
|
---|
| 23 | const isSymbol = (val) => typeof val === "symbol";
|
---|
| 24 | const isObject = (val) => val !== null && typeof val === "object";
|
---|
| 25 | const isReservedProp = /* @__PURE__ */ makeMap(
|
---|
| 26 | // the leading comma is intentional so empty string "" is also included
|
---|
| 27 | ",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"
|
---|
| 28 | );
|
---|
| 29 | const isBuiltInDirective = /* @__PURE__ */ makeMap(
|
---|
| 30 | "bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo"
|
---|
| 31 | );
|
---|
| 32 | const cacheStringFunction = (fn) => {
|
---|
| 33 | const cache = /* @__PURE__ */ Object.create(null);
|
---|
| 34 | return (str) => {
|
---|
| 35 | const hit = cache[str];
|
---|
| 36 | return hit || (cache[str] = fn(str));
|
---|
| 37 | };
|
---|
| 38 | };
|
---|
| 39 | const camelizeRE = /-(\w)/g;
|
---|
| 40 | const camelize = cacheStringFunction(
|
---|
| 41 | (str) => {
|
---|
| 42 | return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : "");
|
---|
| 43 | }
|
---|
| 44 | );
|
---|
| 45 | const capitalize = cacheStringFunction((str) => {
|
---|
| 46 | return str.charAt(0).toUpperCase() + str.slice(1);
|
---|
| 47 | });
|
---|
| 48 | const toHandlerKey = cacheStringFunction(
|
---|
| 49 | (str) => {
|
---|
| 50 | const s = str ? `on${capitalize(str)}` : ``;
|
---|
| 51 | return s;
|
---|
| 52 | }
|
---|
| 53 | );
|
---|
| 54 |
|
---|
| 55 | const PatchFlagNames = {
|
---|
| 56 | [1]: `TEXT`,
|
---|
| 57 | [2]: `CLASS`,
|
---|
| 58 | [4]: `STYLE`,
|
---|
| 59 | [8]: `PROPS`,
|
---|
| 60 | [16]: `FULL_PROPS`,
|
---|
| 61 | [32]: `NEED_HYDRATION`,
|
---|
| 62 | [64]: `STABLE_FRAGMENT`,
|
---|
| 63 | [128]: `KEYED_FRAGMENT`,
|
---|
| 64 | [256]: `UNKEYED_FRAGMENT`,
|
---|
| 65 | [512]: `NEED_PATCH`,
|
---|
| 66 | [1024]: `DYNAMIC_SLOTS`,
|
---|
| 67 | [2048]: `DEV_ROOT_FRAGMENT`,
|
---|
| 68 | [-1]: `HOISTED`,
|
---|
| 69 | [-2]: `BAIL`
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | const slotFlagsText = {
|
---|
| 73 | [1]: "STABLE",
|
---|
| 74 | [2]: "DYNAMIC",
|
---|
| 75 | [3]: "FORWARDED"
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | const range = 2;
|
---|
| 79 | function generateCodeFrame(source, start = 0, end = source.length) {
|
---|
| 80 | start = Math.max(0, Math.min(start, source.length));
|
---|
| 81 | end = Math.max(0, Math.min(end, source.length));
|
---|
| 82 | if (start > end) return "";
|
---|
| 83 | let lines = source.split(/(\r?\n)/);
|
---|
| 84 | const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
|
---|
| 85 | lines = lines.filter((_, idx) => idx % 2 === 0);
|
---|
| 86 | let count = 0;
|
---|
| 87 | const res = [];
|
---|
| 88 | for (let i = 0; i < lines.length; i++) {
|
---|
| 89 | count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
|
---|
| 90 | if (count >= start) {
|
---|
| 91 | for (let j = i - range; j <= i + range || end > count; j++) {
|
---|
| 92 | if (j < 0 || j >= lines.length) continue;
|
---|
| 93 | const line = j + 1;
|
---|
| 94 | res.push(
|
---|
| 95 | `${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
|
---|
| 96 | );
|
---|
| 97 | const lineLength = lines[j].length;
|
---|
| 98 | const newLineSeqLength = newlineSequences[j] && newlineSequences[j].length || 0;
|
---|
| 99 | if (j === i) {
|
---|
| 100 | const pad = start - (count - (lineLength + newLineSeqLength));
|
---|
| 101 | const length = Math.max(
|
---|
| 102 | 1,
|
---|
| 103 | end > count ? lineLength - pad : end - start
|
---|
| 104 | );
|
---|
| 105 | res.push(` | ` + " ".repeat(pad) + "^".repeat(length));
|
---|
| 106 | } else if (j > i) {
|
---|
| 107 | if (end > count) {
|
---|
| 108 | const length = Math.max(Math.min(end - count, lineLength), 1);
|
---|
| 109 | res.push(` | ` + "^".repeat(length));
|
---|
| 110 | }
|
---|
| 111 | count += lineLength + newLineSeqLength;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | break;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 | return res.join("\n");
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | const listDelimiterRE = /;(?![^(]*\))/g;
|
---|
| 121 | const propertyDelimiterRE = /:([^]+)/;
|
---|
| 122 | const styleCommentRE = /\/\*[^]*?\*\//g;
|
---|
| 123 | function parseStringStyle(cssText) {
|
---|
| 124 | const ret = {};
|
---|
| 125 | cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
---|
| 126 | if (item) {
|
---|
| 127 | const tmp = item.split(propertyDelimiterRE);
|
---|
| 128 | tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
---|
| 129 | }
|
---|
| 130 | });
|
---|
| 131 | return ret;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot";
|
---|
| 135 | const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
---|
| 136 | const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
|
---|
| 137 | const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
---|
| 138 | const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
|
---|
| 139 | const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
|
---|
| 140 | const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
|
---|
| 141 | const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
|
---|
| 142 |
|
---|
| 143 | const FRAGMENT = Symbol(`Fragment` );
|
---|
| 144 | const TELEPORT = Symbol(`Teleport` );
|
---|
| 145 | const SUSPENSE = Symbol(`Suspense` );
|
---|
| 146 | const KEEP_ALIVE = Symbol(`KeepAlive` );
|
---|
| 147 | const BASE_TRANSITION = Symbol(
|
---|
| 148 | `BaseTransition`
|
---|
| 149 | );
|
---|
| 150 | const OPEN_BLOCK = Symbol(`openBlock` );
|
---|
| 151 | const CREATE_BLOCK = Symbol(`createBlock` );
|
---|
| 152 | const CREATE_ELEMENT_BLOCK = Symbol(
|
---|
| 153 | `createElementBlock`
|
---|
| 154 | );
|
---|
| 155 | const CREATE_VNODE = Symbol(`createVNode` );
|
---|
| 156 | const CREATE_ELEMENT_VNODE = Symbol(
|
---|
| 157 | `createElementVNode`
|
---|
| 158 | );
|
---|
| 159 | const CREATE_COMMENT = Symbol(
|
---|
| 160 | `createCommentVNode`
|
---|
| 161 | );
|
---|
| 162 | const CREATE_TEXT = Symbol(
|
---|
| 163 | `createTextVNode`
|
---|
| 164 | );
|
---|
| 165 | const CREATE_STATIC = Symbol(
|
---|
| 166 | `createStaticVNode`
|
---|
| 167 | );
|
---|
| 168 | const RESOLVE_COMPONENT = Symbol(
|
---|
| 169 | `resolveComponent`
|
---|
| 170 | );
|
---|
| 171 | const RESOLVE_DYNAMIC_COMPONENT = Symbol(
|
---|
| 172 | `resolveDynamicComponent`
|
---|
| 173 | );
|
---|
| 174 | const RESOLVE_DIRECTIVE = Symbol(
|
---|
| 175 | `resolveDirective`
|
---|
| 176 | );
|
---|
| 177 | const RESOLVE_FILTER = Symbol(
|
---|
| 178 | `resolveFilter`
|
---|
| 179 | );
|
---|
| 180 | const WITH_DIRECTIVES = Symbol(
|
---|
| 181 | `withDirectives`
|
---|
| 182 | );
|
---|
| 183 | const RENDER_LIST = Symbol(`renderList` );
|
---|
| 184 | const RENDER_SLOT = Symbol(`renderSlot` );
|
---|
| 185 | const CREATE_SLOTS = Symbol(`createSlots` );
|
---|
| 186 | const TO_DISPLAY_STRING = Symbol(
|
---|
| 187 | `toDisplayString`
|
---|
| 188 | );
|
---|
| 189 | const MERGE_PROPS = Symbol(`mergeProps` );
|
---|
| 190 | const NORMALIZE_CLASS = Symbol(
|
---|
| 191 | `normalizeClass`
|
---|
| 192 | );
|
---|
| 193 | const NORMALIZE_STYLE = Symbol(
|
---|
| 194 | `normalizeStyle`
|
---|
| 195 | );
|
---|
| 196 | const NORMALIZE_PROPS = Symbol(
|
---|
| 197 | `normalizeProps`
|
---|
| 198 | );
|
---|
| 199 | const GUARD_REACTIVE_PROPS = Symbol(
|
---|
| 200 | `guardReactiveProps`
|
---|
| 201 | );
|
---|
| 202 | const TO_HANDLERS = Symbol(`toHandlers` );
|
---|
| 203 | const CAMELIZE = Symbol(`camelize` );
|
---|
| 204 | const CAPITALIZE = Symbol(`capitalize` );
|
---|
| 205 | const TO_HANDLER_KEY = Symbol(
|
---|
| 206 | `toHandlerKey`
|
---|
| 207 | );
|
---|
| 208 | const SET_BLOCK_TRACKING = Symbol(
|
---|
| 209 | `setBlockTracking`
|
---|
| 210 | );
|
---|
| 211 | const PUSH_SCOPE_ID = Symbol(`pushScopeId` );
|
---|
| 212 | const POP_SCOPE_ID = Symbol(`popScopeId` );
|
---|
| 213 | const WITH_CTX = Symbol(`withCtx` );
|
---|
| 214 | const UNREF = Symbol(`unref` );
|
---|
| 215 | const IS_REF = Symbol(`isRef` );
|
---|
| 216 | const WITH_MEMO = Symbol(`withMemo` );
|
---|
| 217 | const IS_MEMO_SAME = Symbol(`isMemoSame` );
|
---|
| 218 | const helperNameMap = {
|
---|
| 219 | [FRAGMENT]: `Fragment`,
|
---|
| 220 | [TELEPORT]: `Teleport`,
|
---|
| 221 | [SUSPENSE]: `Suspense`,
|
---|
| 222 | [KEEP_ALIVE]: `KeepAlive`,
|
---|
| 223 | [BASE_TRANSITION]: `BaseTransition`,
|
---|
| 224 | [OPEN_BLOCK]: `openBlock`,
|
---|
| 225 | [CREATE_BLOCK]: `createBlock`,
|
---|
| 226 | [CREATE_ELEMENT_BLOCK]: `createElementBlock`,
|
---|
| 227 | [CREATE_VNODE]: `createVNode`,
|
---|
| 228 | [CREATE_ELEMENT_VNODE]: `createElementVNode`,
|
---|
| 229 | [CREATE_COMMENT]: `createCommentVNode`,
|
---|
| 230 | [CREATE_TEXT]: `createTextVNode`,
|
---|
| 231 | [CREATE_STATIC]: `createStaticVNode`,
|
---|
| 232 | [RESOLVE_COMPONENT]: `resolveComponent`,
|
---|
| 233 | [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
---|
| 234 | [RESOLVE_DIRECTIVE]: `resolveDirective`,
|
---|
| 235 | [RESOLVE_FILTER]: `resolveFilter`,
|
---|
| 236 | [WITH_DIRECTIVES]: `withDirectives`,
|
---|
| 237 | [RENDER_LIST]: `renderList`,
|
---|
| 238 | [RENDER_SLOT]: `renderSlot`,
|
---|
| 239 | [CREATE_SLOTS]: `createSlots`,
|
---|
| 240 | [TO_DISPLAY_STRING]: `toDisplayString`,
|
---|
| 241 | [MERGE_PROPS]: `mergeProps`,
|
---|
| 242 | [NORMALIZE_CLASS]: `normalizeClass`,
|
---|
| 243 | [NORMALIZE_STYLE]: `normalizeStyle`,
|
---|
| 244 | [NORMALIZE_PROPS]: `normalizeProps`,
|
---|
| 245 | [GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
|
---|
| 246 | [TO_HANDLERS]: `toHandlers`,
|
---|
| 247 | [CAMELIZE]: `camelize`,
|
---|
| 248 | [CAPITALIZE]: `capitalize`,
|
---|
| 249 | [TO_HANDLER_KEY]: `toHandlerKey`,
|
---|
| 250 | [SET_BLOCK_TRACKING]: `setBlockTracking`,
|
---|
| 251 | [PUSH_SCOPE_ID]: `pushScopeId`,
|
---|
| 252 | [POP_SCOPE_ID]: `popScopeId`,
|
---|
| 253 | [WITH_CTX]: `withCtx`,
|
---|
| 254 | [UNREF]: `unref`,
|
---|
| 255 | [IS_REF]: `isRef`,
|
---|
| 256 | [WITH_MEMO]: `withMemo`,
|
---|
| 257 | [IS_MEMO_SAME]: `isMemoSame`
|
---|
| 258 | };
|
---|
| 259 | function registerRuntimeHelpers(helpers) {
|
---|
| 260 | Object.getOwnPropertySymbols(helpers).forEach((s) => {
|
---|
| 261 | helperNameMap[s] = helpers[s];
|
---|
| 262 | });
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | const Namespaces = {
|
---|
| 266 | "HTML": 0,
|
---|
| 267 | "0": "HTML",
|
---|
| 268 | "SVG": 1,
|
---|
| 269 | "1": "SVG",
|
---|
| 270 | "MATH_ML": 2,
|
---|
| 271 | "2": "MATH_ML"
|
---|
| 272 | };
|
---|
| 273 | const NodeTypes = {
|
---|
| 274 | "ROOT": 0,
|
---|
| 275 | "0": "ROOT",
|
---|
| 276 | "ELEMENT": 1,
|
---|
| 277 | "1": "ELEMENT",
|
---|
| 278 | "TEXT": 2,
|
---|
| 279 | "2": "TEXT",
|
---|
| 280 | "COMMENT": 3,
|
---|
| 281 | "3": "COMMENT",
|
---|
| 282 | "SIMPLE_EXPRESSION": 4,
|
---|
| 283 | "4": "SIMPLE_EXPRESSION",
|
---|
| 284 | "INTERPOLATION": 5,
|
---|
| 285 | "5": "INTERPOLATION",
|
---|
| 286 | "ATTRIBUTE": 6,
|
---|
| 287 | "6": "ATTRIBUTE",
|
---|
| 288 | "DIRECTIVE": 7,
|
---|
| 289 | "7": "DIRECTIVE",
|
---|
| 290 | "COMPOUND_EXPRESSION": 8,
|
---|
| 291 | "8": "COMPOUND_EXPRESSION",
|
---|
| 292 | "IF": 9,
|
---|
| 293 | "9": "IF",
|
---|
| 294 | "IF_BRANCH": 10,
|
---|
| 295 | "10": "IF_BRANCH",
|
---|
| 296 | "FOR": 11,
|
---|
| 297 | "11": "FOR",
|
---|
| 298 | "TEXT_CALL": 12,
|
---|
| 299 | "12": "TEXT_CALL",
|
---|
| 300 | "VNODE_CALL": 13,
|
---|
| 301 | "13": "VNODE_CALL",
|
---|
| 302 | "JS_CALL_EXPRESSION": 14,
|
---|
| 303 | "14": "JS_CALL_EXPRESSION",
|
---|
| 304 | "JS_OBJECT_EXPRESSION": 15,
|
---|
| 305 | "15": "JS_OBJECT_EXPRESSION",
|
---|
| 306 | "JS_PROPERTY": 16,
|
---|
| 307 | "16": "JS_PROPERTY",
|
---|
| 308 | "JS_ARRAY_EXPRESSION": 17,
|
---|
| 309 | "17": "JS_ARRAY_EXPRESSION",
|
---|
| 310 | "JS_FUNCTION_EXPRESSION": 18,
|
---|
| 311 | "18": "JS_FUNCTION_EXPRESSION",
|
---|
| 312 | "JS_CONDITIONAL_EXPRESSION": 19,
|
---|
| 313 | "19": "JS_CONDITIONAL_EXPRESSION",
|
---|
| 314 | "JS_CACHE_EXPRESSION": 20,
|
---|
| 315 | "20": "JS_CACHE_EXPRESSION",
|
---|
| 316 | "JS_BLOCK_STATEMENT": 21,
|
---|
| 317 | "21": "JS_BLOCK_STATEMENT",
|
---|
| 318 | "JS_TEMPLATE_LITERAL": 22,
|
---|
| 319 | "22": "JS_TEMPLATE_LITERAL",
|
---|
| 320 | "JS_IF_STATEMENT": 23,
|
---|
| 321 | "23": "JS_IF_STATEMENT",
|
---|
| 322 | "JS_ASSIGNMENT_EXPRESSION": 24,
|
---|
| 323 | "24": "JS_ASSIGNMENT_EXPRESSION",
|
---|
| 324 | "JS_SEQUENCE_EXPRESSION": 25,
|
---|
| 325 | "25": "JS_SEQUENCE_EXPRESSION",
|
---|
| 326 | "JS_RETURN_STATEMENT": 26,
|
---|
| 327 | "26": "JS_RETURN_STATEMENT"
|
---|
| 328 | };
|
---|
| 329 | const ElementTypes = {
|
---|
| 330 | "ELEMENT": 0,
|
---|
| 331 | "0": "ELEMENT",
|
---|
| 332 | "COMPONENT": 1,
|
---|
| 333 | "1": "COMPONENT",
|
---|
| 334 | "SLOT": 2,
|
---|
| 335 | "2": "SLOT",
|
---|
| 336 | "TEMPLATE": 3,
|
---|
| 337 | "3": "TEMPLATE"
|
---|
| 338 | };
|
---|
| 339 | const ConstantTypes = {
|
---|
| 340 | "NOT_CONSTANT": 0,
|
---|
| 341 | "0": "NOT_CONSTANT",
|
---|
| 342 | "CAN_SKIP_PATCH": 1,
|
---|
| 343 | "1": "CAN_SKIP_PATCH",
|
---|
| 344 | "CAN_CACHE": 2,
|
---|
| 345 | "2": "CAN_CACHE",
|
---|
| 346 | "CAN_STRINGIFY": 3,
|
---|
| 347 | "3": "CAN_STRINGIFY"
|
---|
| 348 | };
|
---|
| 349 | const locStub = {
|
---|
| 350 | start: { line: 1, column: 1, offset: 0 },
|
---|
| 351 | end: { line: 1, column: 1, offset: 0 },
|
---|
| 352 | source: ""
|
---|
| 353 | };
|
---|
| 354 | function createRoot(children, source = "") {
|
---|
| 355 | return {
|
---|
| 356 | type: 0,
|
---|
| 357 | source,
|
---|
| 358 | children,
|
---|
| 359 | helpers: /* @__PURE__ */ new Set(),
|
---|
| 360 | components: [],
|
---|
| 361 | directives: [],
|
---|
| 362 | hoists: [],
|
---|
| 363 | imports: [],
|
---|
| 364 | cached: [],
|
---|
| 365 | temps: 0,
|
---|
| 366 | codegenNode: void 0,
|
---|
| 367 | loc: locStub
|
---|
| 368 | };
|
---|
| 369 | }
|
---|
| 370 | function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
|
---|
| 371 | if (context) {
|
---|
| 372 | if (isBlock) {
|
---|
| 373 | context.helper(OPEN_BLOCK);
|
---|
| 374 | context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
|
---|
| 375 | } else {
|
---|
| 376 | context.helper(getVNodeHelper(context.inSSR, isComponent));
|
---|
| 377 | }
|
---|
| 378 | if (directives) {
|
---|
| 379 | context.helper(WITH_DIRECTIVES);
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
| 382 | return {
|
---|
| 383 | type: 13,
|
---|
| 384 | tag,
|
---|
| 385 | props,
|
---|
| 386 | children,
|
---|
| 387 | patchFlag,
|
---|
| 388 | dynamicProps,
|
---|
| 389 | directives,
|
---|
| 390 | isBlock,
|
---|
| 391 | disableTracking,
|
---|
| 392 | isComponent,
|
---|
| 393 | loc
|
---|
| 394 | };
|
---|
| 395 | }
|
---|
| 396 | function createArrayExpression(elements, loc = locStub) {
|
---|
| 397 | return {
|
---|
| 398 | type: 17,
|
---|
| 399 | loc,
|
---|
| 400 | elements
|
---|
| 401 | };
|
---|
| 402 | }
|
---|
| 403 | function createObjectExpression(properties, loc = locStub) {
|
---|
| 404 | return {
|
---|
| 405 | type: 15,
|
---|
| 406 | loc,
|
---|
| 407 | properties
|
---|
| 408 | };
|
---|
| 409 | }
|
---|
| 410 | function createObjectProperty(key, value) {
|
---|
| 411 | return {
|
---|
| 412 | type: 16,
|
---|
| 413 | loc: locStub,
|
---|
| 414 | key: isString(key) ? createSimpleExpression(key, true) : key,
|
---|
| 415 | value
|
---|
| 416 | };
|
---|
| 417 | }
|
---|
| 418 | function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
|
---|
| 419 | return {
|
---|
| 420 | type: 4,
|
---|
| 421 | loc,
|
---|
| 422 | content,
|
---|
| 423 | isStatic,
|
---|
| 424 | constType: isStatic ? 3 : constType
|
---|
| 425 | };
|
---|
| 426 | }
|
---|
| 427 | function createInterpolation(content, loc) {
|
---|
| 428 | return {
|
---|
| 429 | type: 5,
|
---|
| 430 | loc,
|
---|
| 431 | content: isString(content) ? createSimpleExpression(content, false, loc) : content
|
---|
| 432 | };
|
---|
| 433 | }
|
---|
| 434 | function createCompoundExpression(children, loc = locStub) {
|
---|
| 435 | return {
|
---|
| 436 | type: 8,
|
---|
| 437 | loc,
|
---|
| 438 | children
|
---|
| 439 | };
|
---|
| 440 | }
|
---|
| 441 | function createCallExpression(callee, args = [], loc = locStub) {
|
---|
| 442 | return {
|
---|
| 443 | type: 14,
|
---|
| 444 | loc,
|
---|
| 445 | callee,
|
---|
| 446 | arguments: args
|
---|
| 447 | };
|
---|
| 448 | }
|
---|
| 449 | function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
|
---|
| 450 | return {
|
---|
| 451 | type: 18,
|
---|
| 452 | params,
|
---|
| 453 | returns,
|
---|
| 454 | newline,
|
---|
| 455 | isSlot,
|
---|
| 456 | loc
|
---|
| 457 | };
|
---|
| 458 | }
|
---|
| 459 | function createConditionalExpression(test, consequent, alternate, newline = true) {
|
---|
| 460 | return {
|
---|
| 461 | type: 19,
|
---|
| 462 | test,
|
---|
| 463 | consequent,
|
---|
| 464 | alternate,
|
---|
| 465 | newline,
|
---|
| 466 | loc: locStub
|
---|
| 467 | };
|
---|
| 468 | }
|
---|
| 469 | function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
|
---|
| 470 | return {
|
---|
| 471 | type: 20,
|
---|
| 472 | index,
|
---|
| 473 | value,
|
---|
| 474 | needPauseTracking,
|
---|
| 475 | inVOnce,
|
---|
| 476 | needArraySpread: false,
|
---|
| 477 | loc: locStub
|
---|
| 478 | };
|
---|
| 479 | }
|
---|
| 480 | function createBlockStatement(body) {
|
---|
| 481 | return {
|
---|
| 482 | type: 21,
|
---|
| 483 | body,
|
---|
| 484 | loc: locStub
|
---|
| 485 | };
|
---|
| 486 | }
|
---|
| 487 | function createTemplateLiteral(elements) {
|
---|
| 488 | return {
|
---|
| 489 | type: 22,
|
---|
| 490 | elements,
|
---|
| 491 | loc: locStub
|
---|
| 492 | };
|
---|
| 493 | }
|
---|
| 494 | function createIfStatement(test, consequent, alternate) {
|
---|
| 495 | return {
|
---|
| 496 | type: 23,
|
---|
| 497 | test,
|
---|
| 498 | consequent,
|
---|
| 499 | alternate,
|
---|
| 500 | loc: locStub
|
---|
| 501 | };
|
---|
| 502 | }
|
---|
| 503 | function createAssignmentExpression(left, right) {
|
---|
| 504 | return {
|
---|
| 505 | type: 24,
|
---|
| 506 | left,
|
---|
| 507 | right,
|
---|
| 508 | loc: locStub
|
---|
| 509 | };
|
---|
| 510 | }
|
---|
| 511 | function createSequenceExpression(expressions) {
|
---|
| 512 | return {
|
---|
| 513 | type: 25,
|
---|
| 514 | expressions,
|
---|
| 515 | loc: locStub
|
---|
| 516 | };
|
---|
| 517 | }
|
---|
| 518 | function createReturnStatement(returns) {
|
---|
| 519 | return {
|
---|
| 520 | type: 26,
|
---|
| 521 | returns,
|
---|
| 522 | loc: locStub
|
---|
| 523 | };
|
---|
| 524 | }
|
---|
| 525 | function getVNodeHelper(ssr, isComponent) {
|
---|
| 526 | return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
---|
| 527 | }
|
---|
| 528 | function getVNodeBlockHelper(ssr, isComponent) {
|
---|
| 529 | return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
|
---|
| 530 | }
|
---|
| 531 | function convertToBlock(node, { helper, removeHelper, inSSR }) {
|
---|
| 532 | if (!node.isBlock) {
|
---|
| 533 | node.isBlock = true;
|
---|
| 534 | removeHelper(getVNodeHelper(inSSR, node.isComponent));
|
---|
| 535 | helper(OPEN_BLOCK);
|
---|
| 536 | helper(getVNodeBlockHelper(inSSR, node.isComponent));
|
---|
| 537 | }
|
---|
| 538 | }
|
---|
| 539 |
|
---|
| 540 | const defaultDelimitersOpen = new Uint8Array([123, 123]);
|
---|
| 541 | const defaultDelimitersClose = new Uint8Array([125, 125]);
|
---|
| 542 | function isTagStartChar(c) {
|
---|
| 543 | return c >= 97 && c <= 122 || c >= 65 && c <= 90;
|
---|
| 544 | }
|
---|
| 545 | function isWhitespace(c) {
|
---|
| 546 | return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
|
---|
| 547 | }
|
---|
| 548 | function isEndOfTagSection(c) {
|
---|
| 549 | return c === 47 || c === 62 || isWhitespace(c);
|
---|
| 550 | }
|
---|
| 551 | function toCharCodes(str) {
|
---|
| 552 | const ret = new Uint8Array(str.length);
|
---|
| 553 | for (let i = 0; i < str.length; i++) {
|
---|
| 554 | ret[i] = str.charCodeAt(i);
|
---|
| 555 | }
|
---|
| 556 | return ret;
|
---|
| 557 | }
|
---|
| 558 | const Sequences = {
|
---|
| 559 | Cdata: new Uint8Array([67, 68, 65, 84, 65, 91]),
|
---|
| 560 | // CDATA[
|
---|
| 561 | CdataEnd: new Uint8Array([93, 93, 62]),
|
---|
| 562 | // ]]>
|
---|
| 563 | CommentEnd: new Uint8Array([45, 45, 62]),
|
---|
| 564 | // `-->`
|
---|
| 565 | ScriptEnd: new Uint8Array([60, 47, 115, 99, 114, 105, 112, 116]),
|
---|
| 566 | // `<\/script`
|
---|
| 567 | StyleEnd: new Uint8Array([60, 47, 115, 116, 121, 108, 101]),
|
---|
| 568 | // `</style`
|
---|
| 569 | TitleEnd: new Uint8Array([60, 47, 116, 105, 116, 108, 101]),
|
---|
| 570 | // `</title`
|
---|
| 571 | TextareaEnd: new Uint8Array([
|
---|
| 572 | 60,
|
---|
| 573 | 47,
|
---|
| 574 | 116,
|
---|
| 575 | 101,
|
---|
| 576 | 120,
|
---|
| 577 | 116,
|
---|
| 578 | 97,
|
---|
| 579 | 114,
|
---|
| 580 | 101,
|
---|
| 581 | 97
|
---|
| 582 | ])
|
---|
| 583 | // `</textarea
|
---|
| 584 | };
|
---|
| 585 | class Tokenizer {
|
---|
| 586 | constructor(stack, cbs) {
|
---|
| 587 | this.stack = stack;
|
---|
| 588 | this.cbs = cbs;
|
---|
| 589 | /** The current state the tokenizer is in. */
|
---|
| 590 | this.state = 1;
|
---|
| 591 | /** The read buffer. */
|
---|
| 592 | this.buffer = "";
|
---|
| 593 | /** The beginning of the section that is currently being read. */
|
---|
| 594 | this.sectionStart = 0;
|
---|
| 595 | /** The index within the buffer that we are currently looking at. */
|
---|
| 596 | this.index = 0;
|
---|
| 597 | /** The start of the last entity. */
|
---|
| 598 | this.entityStart = 0;
|
---|
| 599 | /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
|
---|
| 600 | this.baseState = 1;
|
---|
| 601 | /** For special parsing behavior inside of script and style tags. */
|
---|
| 602 | this.inRCDATA = false;
|
---|
| 603 | /** For disabling RCDATA tags handling */
|
---|
| 604 | this.inXML = false;
|
---|
| 605 | /** For disabling interpolation parsing in v-pre */
|
---|
| 606 | this.inVPre = false;
|
---|
| 607 | /** Record newline positions for fast line / column calculation */
|
---|
| 608 | this.newlines = [];
|
---|
| 609 | this.mode = 0;
|
---|
| 610 | this.delimiterOpen = defaultDelimitersOpen;
|
---|
| 611 | this.delimiterClose = defaultDelimitersClose;
|
---|
| 612 | this.delimiterIndex = -1;
|
---|
| 613 | this.currentSequence = void 0;
|
---|
| 614 | this.sequenceIndex = 0;
|
---|
| 615 | }
|
---|
| 616 | get inSFCRoot() {
|
---|
| 617 | return this.mode === 2 && this.stack.length === 0;
|
---|
| 618 | }
|
---|
| 619 | reset() {
|
---|
| 620 | this.state = 1;
|
---|
| 621 | this.mode = 0;
|
---|
| 622 | this.buffer = "";
|
---|
| 623 | this.sectionStart = 0;
|
---|
| 624 | this.index = 0;
|
---|
| 625 | this.baseState = 1;
|
---|
| 626 | this.inRCDATA = false;
|
---|
| 627 | this.currentSequence = void 0;
|
---|
| 628 | this.newlines.length = 0;
|
---|
| 629 | this.delimiterOpen = defaultDelimitersOpen;
|
---|
| 630 | this.delimiterClose = defaultDelimitersClose;
|
---|
| 631 | }
|
---|
| 632 | /**
|
---|
| 633 | * Generate Position object with line / column information using recorded
|
---|
| 634 | * newline positions. We know the index is always going to be an already
|
---|
| 635 | * processed index, so all the newlines up to this index should have been
|
---|
| 636 | * recorded.
|
---|
| 637 | */
|
---|
| 638 | getPos(index) {
|
---|
| 639 | let line = 1;
|
---|
| 640 | let column = index + 1;
|
---|
| 641 | for (let i = this.newlines.length - 1; i >= 0; i--) {
|
---|
| 642 | const newlineIndex = this.newlines[i];
|
---|
| 643 | if (index > newlineIndex) {
|
---|
| 644 | line = i + 2;
|
---|
| 645 | column = index - newlineIndex;
|
---|
| 646 | break;
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 | return {
|
---|
| 650 | column,
|
---|
| 651 | line,
|
---|
| 652 | offset: index
|
---|
| 653 | };
|
---|
| 654 | }
|
---|
| 655 | peek() {
|
---|
| 656 | return this.buffer.charCodeAt(this.index + 1);
|
---|
| 657 | }
|
---|
| 658 | stateText(c) {
|
---|
| 659 | if (c === 60) {
|
---|
| 660 | if (this.index > this.sectionStart) {
|
---|
| 661 | this.cbs.ontext(this.sectionStart, this.index);
|
---|
| 662 | }
|
---|
| 663 | this.state = 5;
|
---|
| 664 | this.sectionStart = this.index;
|
---|
| 665 | } else if (!this.inVPre && c === this.delimiterOpen[0]) {
|
---|
| 666 | this.state = 2;
|
---|
| 667 | this.delimiterIndex = 0;
|
---|
| 668 | this.stateInterpolationOpen(c);
|
---|
| 669 | }
|
---|
| 670 | }
|
---|
| 671 | stateInterpolationOpen(c) {
|
---|
| 672 | if (c === this.delimiterOpen[this.delimiterIndex]) {
|
---|
| 673 | if (this.delimiterIndex === this.delimiterOpen.length - 1) {
|
---|
| 674 | const start = this.index + 1 - this.delimiterOpen.length;
|
---|
| 675 | if (start > this.sectionStart) {
|
---|
| 676 | this.cbs.ontext(this.sectionStart, start);
|
---|
| 677 | }
|
---|
| 678 | this.state = 3;
|
---|
| 679 | this.sectionStart = start;
|
---|
| 680 | } else {
|
---|
| 681 | this.delimiterIndex++;
|
---|
| 682 | }
|
---|
| 683 | } else if (this.inRCDATA) {
|
---|
| 684 | this.state = 32;
|
---|
| 685 | this.stateInRCDATA(c);
|
---|
| 686 | } else {
|
---|
| 687 | this.state = 1;
|
---|
| 688 | this.stateText(c);
|
---|
| 689 | }
|
---|
| 690 | }
|
---|
| 691 | stateInterpolation(c) {
|
---|
| 692 | if (c === this.delimiterClose[0]) {
|
---|
| 693 | this.state = 4;
|
---|
| 694 | this.delimiterIndex = 0;
|
---|
| 695 | this.stateInterpolationClose(c);
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 | stateInterpolationClose(c) {
|
---|
| 699 | if (c === this.delimiterClose[this.delimiterIndex]) {
|
---|
| 700 | if (this.delimiterIndex === this.delimiterClose.length - 1) {
|
---|
| 701 | this.cbs.oninterpolation(this.sectionStart, this.index + 1);
|
---|
| 702 | if (this.inRCDATA) {
|
---|
| 703 | this.state = 32;
|
---|
| 704 | } else {
|
---|
| 705 | this.state = 1;
|
---|
| 706 | }
|
---|
| 707 | this.sectionStart = this.index + 1;
|
---|
| 708 | } else {
|
---|
| 709 | this.delimiterIndex++;
|
---|
| 710 | }
|
---|
| 711 | } else {
|
---|
| 712 | this.state = 3;
|
---|
| 713 | this.stateInterpolation(c);
|
---|
| 714 | }
|
---|
| 715 | }
|
---|
| 716 | stateSpecialStartSequence(c) {
|
---|
| 717 | const isEnd = this.sequenceIndex === this.currentSequence.length;
|
---|
| 718 | const isMatch = isEnd ? (
|
---|
| 719 | // If we are at the end of the sequence, make sure the tag name has ended
|
---|
| 720 | isEndOfTagSection(c)
|
---|
| 721 | ) : (
|
---|
| 722 | // Otherwise, do a case-insensitive comparison
|
---|
| 723 | (c | 32) === this.currentSequence[this.sequenceIndex]
|
---|
| 724 | );
|
---|
| 725 | if (!isMatch) {
|
---|
| 726 | this.inRCDATA = false;
|
---|
| 727 | } else if (!isEnd) {
|
---|
| 728 | this.sequenceIndex++;
|
---|
| 729 | return;
|
---|
| 730 | }
|
---|
| 731 | this.sequenceIndex = 0;
|
---|
| 732 | this.state = 6;
|
---|
| 733 | this.stateInTagName(c);
|
---|
| 734 | }
|
---|
| 735 | /** Look for an end tag. For <title> and <textarea>, also decode entities. */
|
---|
| 736 | stateInRCDATA(c) {
|
---|
| 737 | if (this.sequenceIndex === this.currentSequence.length) {
|
---|
| 738 | if (c === 62 || isWhitespace(c)) {
|
---|
| 739 | const endOfText = this.index - this.currentSequence.length;
|
---|
| 740 | if (this.sectionStart < endOfText) {
|
---|
| 741 | const actualIndex = this.index;
|
---|
| 742 | this.index = endOfText;
|
---|
| 743 | this.cbs.ontext(this.sectionStart, endOfText);
|
---|
| 744 | this.index = actualIndex;
|
---|
| 745 | }
|
---|
| 746 | this.sectionStart = endOfText + 2;
|
---|
| 747 | this.stateInClosingTagName(c);
|
---|
| 748 | this.inRCDATA = false;
|
---|
| 749 | return;
|
---|
| 750 | }
|
---|
| 751 | this.sequenceIndex = 0;
|
---|
| 752 | }
|
---|
| 753 | if ((c | 32) === this.currentSequence[this.sequenceIndex]) {
|
---|
| 754 | this.sequenceIndex += 1;
|
---|
| 755 | } else if (this.sequenceIndex === 0) {
|
---|
| 756 | if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
|
---|
| 757 | if (!this.inVPre && c === this.delimiterOpen[0]) {
|
---|
| 758 | this.state = 2;
|
---|
| 759 | this.delimiterIndex = 0;
|
---|
| 760 | this.stateInterpolationOpen(c);
|
---|
| 761 | }
|
---|
| 762 | } else if (this.fastForwardTo(60)) {
|
---|
| 763 | this.sequenceIndex = 1;
|
---|
| 764 | }
|
---|
| 765 | } else {
|
---|
| 766 | this.sequenceIndex = Number(c === 60);
|
---|
| 767 | }
|
---|
| 768 | }
|
---|
| 769 | stateCDATASequence(c) {
|
---|
| 770 | if (c === Sequences.Cdata[this.sequenceIndex]) {
|
---|
| 771 | if (++this.sequenceIndex === Sequences.Cdata.length) {
|
---|
| 772 | this.state = 28;
|
---|
| 773 | this.currentSequence = Sequences.CdataEnd;
|
---|
| 774 | this.sequenceIndex = 0;
|
---|
| 775 | this.sectionStart = this.index + 1;
|
---|
| 776 | }
|
---|
| 777 | } else {
|
---|
| 778 | this.sequenceIndex = 0;
|
---|
| 779 | this.state = 23;
|
---|
| 780 | this.stateInDeclaration(c);
|
---|
| 781 | }
|
---|
| 782 | }
|
---|
| 783 | /**
|
---|
| 784 | * When we wait for one specific character, we can speed things up
|
---|
| 785 | * by skipping through the buffer until we find it.
|
---|
| 786 | *
|
---|
| 787 | * @returns Whether the character was found.
|
---|
| 788 | */
|
---|
| 789 | fastForwardTo(c) {
|
---|
| 790 | while (++this.index < this.buffer.length) {
|
---|
| 791 | const cc = this.buffer.charCodeAt(this.index);
|
---|
| 792 | if (cc === 10) {
|
---|
| 793 | this.newlines.push(this.index);
|
---|
| 794 | }
|
---|
| 795 | if (cc === c) {
|
---|
| 796 | return true;
|
---|
| 797 | }
|
---|
| 798 | }
|
---|
| 799 | this.index = this.buffer.length - 1;
|
---|
| 800 | return false;
|
---|
| 801 | }
|
---|
| 802 | /**
|
---|
| 803 | * Comments and CDATA end with `-->` and `]]>`.
|
---|
| 804 | *
|
---|
| 805 | * Their common qualities are:
|
---|
| 806 | * - Their end sequences have a distinct character they start with.
|
---|
| 807 | * - That character is then repeated, so we have to check multiple repeats.
|
---|
| 808 | * - All characters but the start character of the sequence can be skipped.
|
---|
| 809 | */
|
---|
| 810 | stateInCommentLike(c) {
|
---|
| 811 | if (c === this.currentSequence[this.sequenceIndex]) {
|
---|
| 812 | if (++this.sequenceIndex === this.currentSequence.length) {
|
---|
| 813 | if (this.currentSequence === Sequences.CdataEnd) {
|
---|
| 814 | this.cbs.oncdata(this.sectionStart, this.index - 2);
|
---|
| 815 | } else {
|
---|
| 816 | this.cbs.oncomment(this.sectionStart, this.index - 2);
|
---|
| 817 | }
|
---|
| 818 | this.sequenceIndex = 0;
|
---|
| 819 | this.sectionStart = this.index + 1;
|
---|
| 820 | this.state = 1;
|
---|
| 821 | }
|
---|
| 822 | } else if (this.sequenceIndex === 0) {
|
---|
| 823 | if (this.fastForwardTo(this.currentSequence[0])) {
|
---|
| 824 | this.sequenceIndex = 1;
|
---|
| 825 | }
|
---|
| 826 | } else if (c !== this.currentSequence[this.sequenceIndex - 1]) {
|
---|
| 827 | this.sequenceIndex = 0;
|
---|
| 828 | }
|
---|
| 829 | }
|
---|
| 830 | startSpecial(sequence, offset) {
|
---|
| 831 | this.enterRCDATA(sequence, offset);
|
---|
| 832 | this.state = 31;
|
---|
| 833 | }
|
---|
| 834 | enterRCDATA(sequence, offset) {
|
---|
| 835 | this.inRCDATA = true;
|
---|
| 836 | this.currentSequence = sequence;
|
---|
| 837 | this.sequenceIndex = offset;
|
---|
| 838 | }
|
---|
| 839 | stateBeforeTagName(c) {
|
---|
| 840 | if (c === 33) {
|
---|
| 841 | this.state = 22;
|
---|
| 842 | this.sectionStart = this.index + 1;
|
---|
| 843 | } else if (c === 63) {
|
---|
| 844 | this.state = 24;
|
---|
| 845 | this.sectionStart = this.index + 1;
|
---|
| 846 | } else if (isTagStartChar(c)) {
|
---|
| 847 | this.sectionStart = this.index;
|
---|
| 848 | if (this.mode === 0) {
|
---|
| 849 | this.state = 6;
|
---|
| 850 | } else if (this.inSFCRoot) {
|
---|
| 851 | this.state = 34;
|
---|
| 852 | } else if (!this.inXML) {
|
---|
| 853 | if (c === 116) {
|
---|
| 854 | this.state = 30;
|
---|
| 855 | } else {
|
---|
| 856 | this.state = c === 115 ? 29 : 6;
|
---|
| 857 | }
|
---|
| 858 | } else {
|
---|
| 859 | this.state = 6;
|
---|
| 860 | }
|
---|
| 861 | } else if (c === 47) {
|
---|
| 862 | this.state = 8;
|
---|
| 863 | } else {
|
---|
| 864 | this.state = 1;
|
---|
| 865 | this.stateText(c);
|
---|
| 866 | }
|
---|
| 867 | }
|
---|
| 868 | stateInTagName(c) {
|
---|
| 869 | if (isEndOfTagSection(c)) {
|
---|
| 870 | this.handleTagName(c);
|
---|
| 871 | }
|
---|
| 872 | }
|
---|
| 873 | stateInSFCRootTagName(c) {
|
---|
| 874 | if (isEndOfTagSection(c)) {
|
---|
| 875 | const tag = this.buffer.slice(this.sectionStart, this.index);
|
---|
| 876 | if (tag !== "template") {
|
---|
| 877 | this.enterRCDATA(toCharCodes(`</` + tag), 0);
|
---|
| 878 | }
|
---|
| 879 | this.handleTagName(c);
|
---|
| 880 | }
|
---|
| 881 | }
|
---|
| 882 | handleTagName(c) {
|
---|
| 883 | this.cbs.onopentagname(this.sectionStart, this.index);
|
---|
| 884 | this.sectionStart = -1;
|
---|
| 885 | this.state = 11;
|
---|
| 886 | this.stateBeforeAttrName(c);
|
---|
| 887 | }
|
---|
| 888 | stateBeforeClosingTagName(c) {
|
---|
| 889 | if (isWhitespace(c)) ; else if (c === 62) {
|
---|
| 890 | {
|
---|
| 891 | this.cbs.onerr(14, this.index);
|
---|
| 892 | }
|
---|
| 893 | this.state = 1;
|
---|
| 894 | this.sectionStart = this.index + 1;
|
---|
| 895 | } else {
|
---|
| 896 | this.state = isTagStartChar(c) ? 9 : 27;
|
---|
| 897 | this.sectionStart = this.index;
|
---|
| 898 | }
|
---|
| 899 | }
|
---|
| 900 | stateInClosingTagName(c) {
|
---|
| 901 | if (c === 62 || isWhitespace(c)) {
|
---|
| 902 | this.cbs.onclosetag(this.sectionStart, this.index);
|
---|
| 903 | this.sectionStart = -1;
|
---|
| 904 | this.state = 10;
|
---|
| 905 | this.stateAfterClosingTagName(c);
|
---|
| 906 | }
|
---|
| 907 | }
|
---|
| 908 | stateAfterClosingTagName(c) {
|
---|
| 909 | if (c === 62) {
|
---|
| 910 | this.state = 1;
|
---|
| 911 | this.sectionStart = this.index + 1;
|
---|
| 912 | }
|
---|
| 913 | }
|
---|
| 914 | stateBeforeAttrName(c) {
|
---|
| 915 | if (c === 62) {
|
---|
| 916 | this.cbs.onopentagend(this.index);
|
---|
| 917 | if (this.inRCDATA) {
|
---|
| 918 | this.state = 32;
|
---|
| 919 | } else {
|
---|
| 920 | this.state = 1;
|
---|
| 921 | }
|
---|
| 922 | this.sectionStart = this.index + 1;
|
---|
| 923 | } else if (c === 47) {
|
---|
| 924 | this.state = 7;
|
---|
| 925 | if (this.peek() !== 62) {
|
---|
| 926 | this.cbs.onerr(22, this.index);
|
---|
| 927 | }
|
---|
| 928 | } else if (c === 60 && this.peek() === 47) {
|
---|
| 929 | this.cbs.onopentagend(this.index);
|
---|
| 930 | this.state = 5;
|
---|
| 931 | this.sectionStart = this.index;
|
---|
| 932 | } else if (!isWhitespace(c)) {
|
---|
| 933 | if (c === 61) {
|
---|
| 934 | this.cbs.onerr(
|
---|
| 935 | 19,
|
---|
| 936 | this.index
|
---|
| 937 | );
|
---|
| 938 | }
|
---|
| 939 | this.handleAttrStart(c);
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
| 942 | handleAttrStart(c) {
|
---|
| 943 | if (c === 118 && this.peek() === 45) {
|
---|
| 944 | this.state = 13;
|
---|
| 945 | this.sectionStart = this.index;
|
---|
| 946 | } else if (c === 46 || c === 58 || c === 64 || c === 35) {
|
---|
| 947 | this.cbs.ondirname(this.index, this.index + 1);
|
---|
| 948 | this.state = 14;
|
---|
| 949 | this.sectionStart = this.index + 1;
|
---|
| 950 | } else {
|
---|
| 951 | this.state = 12;
|
---|
| 952 | this.sectionStart = this.index;
|
---|
| 953 | }
|
---|
| 954 | }
|
---|
| 955 | stateInSelfClosingTag(c) {
|
---|
| 956 | if (c === 62) {
|
---|
| 957 | this.cbs.onselfclosingtag(this.index);
|
---|
| 958 | this.state = 1;
|
---|
| 959 | this.sectionStart = this.index + 1;
|
---|
| 960 | this.inRCDATA = false;
|
---|
| 961 | } else if (!isWhitespace(c)) {
|
---|
| 962 | this.state = 11;
|
---|
| 963 | this.stateBeforeAttrName(c);
|
---|
| 964 | }
|
---|
| 965 | }
|
---|
| 966 | stateInAttrName(c) {
|
---|
| 967 | if (c === 61 || isEndOfTagSection(c)) {
|
---|
| 968 | this.cbs.onattribname(this.sectionStart, this.index);
|
---|
| 969 | this.handleAttrNameEnd(c);
|
---|
| 970 | } else if (c === 34 || c === 39 || c === 60) {
|
---|
| 971 | this.cbs.onerr(
|
---|
| 972 | 17,
|
---|
| 973 | this.index
|
---|
| 974 | );
|
---|
| 975 | }
|
---|
| 976 | }
|
---|
| 977 | stateInDirName(c) {
|
---|
| 978 | if (c === 61 || isEndOfTagSection(c)) {
|
---|
| 979 | this.cbs.ondirname(this.sectionStart, this.index);
|
---|
| 980 | this.handleAttrNameEnd(c);
|
---|
| 981 | } else if (c === 58) {
|
---|
| 982 | this.cbs.ondirname(this.sectionStart, this.index);
|
---|
| 983 | this.state = 14;
|
---|
| 984 | this.sectionStart = this.index + 1;
|
---|
| 985 | } else if (c === 46) {
|
---|
| 986 | this.cbs.ondirname(this.sectionStart, this.index);
|
---|
| 987 | this.state = 16;
|
---|
| 988 | this.sectionStart = this.index + 1;
|
---|
| 989 | }
|
---|
| 990 | }
|
---|
| 991 | stateInDirArg(c) {
|
---|
| 992 | if (c === 61 || isEndOfTagSection(c)) {
|
---|
| 993 | this.cbs.ondirarg(this.sectionStart, this.index);
|
---|
| 994 | this.handleAttrNameEnd(c);
|
---|
| 995 | } else if (c === 91) {
|
---|
| 996 | this.state = 15;
|
---|
| 997 | } else if (c === 46) {
|
---|
| 998 | this.cbs.ondirarg(this.sectionStart, this.index);
|
---|
| 999 | this.state = 16;
|
---|
| 1000 | this.sectionStart = this.index + 1;
|
---|
| 1001 | }
|
---|
| 1002 | }
|
---|
| 1003 | stateInDynamicDirArg(c) {
|
---|
| 1004 | if (c === 93) {
|
---|
| 1005 | this.state = 14;
|
---|
| 1006 | } else if (c === 61 || isEndOfTagSection(c)) {
|
---|
| 1007 | this.cbs.ondirarg(this.sectionStart, this.index + 1);
|
---|
| 1008 | this.handleAttrNameEnd(c);
|
---|
| 1009 | {
|
---|
| 1010 | this.cbs.onerr(
|
---|
| 1011 | 27,
|
---|
| 1012 | this.index
|
---|
| 1013 | );
|
---|
| 1014 | }
|
---|
| 1015 | }
|
---|
| 1016 | }
|
---|
| 1017 | stateInDirModifier(c) {
|
---|
| 1018 | if (c === 61 || isEndOfTagSection(c)) {
|
---|
| 1019 | this.cbs.ondirmodifier(this.sectionStart, this.index);
|
---|
| 1020 | this.handleAttrNameEnd(c);
|
---|
| 1021 | } else if (c === 46) {
|
---|
| 1022 | this.cbs.ondirmodifier(this.sectionStart, this.index);
|
---|
| 1023 | this.sectionStart = this.index + 1;
|
---|
| 1024 | }
|
---|
| 1025 | }
|
---|
| 1026 | handleAttrNameEnd(c) {
|
---|
| 1027 | this.sectionStart = this.index;
|
---|
| 1028 | this.state = 17;
|
---|
| 1029 | this.cbs.onattribnameend(this.index);
|
---|
| 1030 | this.stateAfterAttrName(c);
|
---|
| 1031 | }
|
---|
| 1032 | stateAfterAttrName(c) {
|
---|
| 1033 | if (c === 61) {
|
---|
| 1034 | this.state = 18;
|
---|
| 1035 | } else if (c === 47 || c === 62) {
|
---|
| 1036 | this.cbs.onattribend(0, this.sectionStart);
|
---|
| 1037 | this.sectionStart = -1;
|
---|
| 1038 | this.state = 11;
|
---|
| 1039 | this.stateBeforeAttrName(c);
|
---|
| 1040 | } else if (!isWhitespace(c)) {
|
---|
| 1041 | this.cbs.onattribend(0, this.sectionStart);
|
---|
| 1042 | this.handleAttrStart(c);
|
---|
| 1043 | }
|
---|
| 1044 | }
|
---|
| 1045 | stateBeforeAttrValue(c) {
|
---|
| 1046 | if (c === 34) {
|
---|
| 1047 | this.state = 19;
|
---|
| 1048 | this.sectionStart = this.index + 1;
|
---|
| 1049 | } else if (c === 39) {
|
---|
| 1050 | this.state = 20;
|
---|
| 1051 | this.sectionStart = this.index + 1;
|
---|
| 1052 | } else if (!isWhitespace(c)) {
|
---|
| 1053 | this.sectionStart = this.index;
|
---|
| 1054 | this.state = 21;
|
---|
| 1055 | this.stateInAttrValueNoQuotes(c);
|
---|
| 1056 | }
|
---|
| 1057 | }
|
---|
| 1058 | handleInAttrValue(c, quote) {
|
---|
| 1059 | if (c === quote || this.fastForwardTo(quote)) {
|
---|
| 1060 | this.cbs.onattribdata(this.sectionStart, this.index);
|
---|
| 1061 | this.sectionStart = -1;
|
---|
| 1062 | this.cbs.onattribend(
|
---|
| 1063 | quote === 34 ? 3 : 2,
|
---|
| 1064 | this.index + 1
|
---|
| 1065 | );
|
---|
| 1066 | this.state = 11;
|
---|
| 1067 | }
|
---|
| 1068 | }
|
---|
| 1069 | stateInAttrValueDoubleQuotes(c) {
|
---|
| 1070 | this.handleInAttrValue(c, 34);
|
---|
| 1071 | }
|
---|
| 1072 | stateInAttrValueSingleQuotes(c) {
|
---|
| 1073 | this.handleInAttrValue(c, 39);
|
---|
| 1074 | }
|
---|
| 1075 | stateInAttrValueNoQuotes(c) {
|
---|
| 1076 | if (isWhitespace(c) || c === 62) {
|
---|
| 1077 | this.cbs.onattribdata(this.sectionStart, this.index);
|
---|
| 1078 | this.sectionStart = -1;
|
---|
| 1079 | this.cbs.onattribend(1, this.index);
|
---|
| 1080 | this.state = 11;
|
---|
| 1081 | this.stateBeforeAttrName(c);
|
---|
| 1082 | } else if (c === 34 || c === 39 || c === 60 || c === 61 || c === 96) {
|
---|
| 1083 | this.cbs.onerr(
|
---|
| 1084 | 18,
|
---|
| 1085 | this.index
|
---|
| 1086 | );
|
---|
| 1087 | } else ;
|
---|
| 1088 | }
|
---|
| 1089 | stateBeforeDeclaration(c) {
|
---|
| 1090 | if (c === 91) {
|
---|
| 1091 | this.state = 26;
|
---|
| 1092 | this.sequenceIndex = 0;
|
---|
| 1093 | } else {
|
---|
| 1094 | this.state = c === 45 ? 25 : 23;
|
---|
| 1095 | }
|
---|
| 1096 | }
|
---|
| 1097 | stateInDeclaration(c) {
|
---|
| 1098 | if (c === 62 || this.fastForwardTo(62)) {
|
---|
| 1099 | this.state = 1;
|
---|
| 1100 | this.sectionStart = this.index + 1;
|
---|
| 1101 | }
|
---|
| 1102 | }
|
---|
| 1103 | stateInProcessingInstruction(c) {
|
---|
| 1104 | if (c === 62 || this.fastForwardTo(62)) {
|
---|
| 1105 | this.cbs.onprocessinginstruction(this.sectionStart, this.index);
|
---|
| 1106 | this.state = 1;
|
---|
| 1107 | this.sectionStart = this.index + 1;
|
---|
| 1108 | }
|
---|
| 1109 | }
|
---|
| 1110 | stateBeforeComment(c) {
|
---|
| 1111 | if (c === 45) {
|
---|
| 1112 | this.state = 28;
|
---|
| 1113 | this.currentSequence = Sequences.CommentEnd;
|
---|
| 1114 | this.sequenceIndex = 2;
|
---|
| 1115 | this.sectionStart = this.index + 1;
|
---|
| 1116 | } else {
|
---|
| 1117 | this.state = 23;
|
---|
| 1118 | }
|
---|
| 1119 | }
|
---|
| 1120 | stateInSpecialComment(c) {
|
---|
| 1121 | if (c === 62 || this.fastForwardTo(62)) {
|
---|
| 1122 | this.cbs.oncomment(this.sectionStart, this.index);
|
---|
| 1123 | this.state = 1;
|
---|
| 1124 | this.sectionStart = this.index + 1;
|
---|
| 1125 | }
|
---|
| 1126 | }
|
---|
| 1127 | stateBeforeSpecialS(c) {
|
---|
| 1128 | if (c === Sequences.ScriptEnd[3]) {
|
---|
| 1129 | this.startSpecial(Sequences.ScriptEnd, 4);
|
---|
| 1130 | } else if (c === Sequences.StyleEnd[3]) {
|
---|
| 1131 | this.startSpecial(Sequences.StyleEnd, 4);
|
---|
| 1132 | } else {
|
---|
| 1133 | this.state = 6;
|
---|
| 1134 | this.stateInTagName(c);
|
---|
| 1135 | }
|
---|
| 1136 | }
|
---|
| 1137 | stateBeforeSpecialT(c) {
|
---|
| 1138 | if (c === Sequences.TitleEnd[3]) {
|
---|
| 1139 | this.startSpecial(Sequences.TitleEnd, 4);
|
---|
| 1140 | } else if (c === Sequences.TextareaEnd[3]) {
|
---|
| 1141 | this.startSpecial(Sequences.TextareaEnd, 4);
|
---|
| 1142 | } else {
|
---|
| 1143 | this.state = 6;
|
---|
| 1144 | this.stateInTagName(c);
|
---|
| 1145 | }
|
---|
| 1146 | }
|
---|
| 1147 | startEntity() {
|
---|
| 1148 | }
|
---|
| 1149 | stateInEntity() {
|
---|
| 1150 | }
|
---|
| 1151 | /**
|
---|
| 1152 | * Iterates through the buffer, calling the function corresponding to the current state.
|
---|
| 1153 | *
|
---|
| 1154 | * States that are more likely to be hit are higher up, as a performance improvement.
|
---|
| 1155 | */
|
---|
| 1156 | parse(input) {
|
---|
| 1157 | this.buffer = input;
|
---|
| 1158 | while (this.index < this.buffer.length) {
|
---|
| 1159 | const c = this.buffer.charCodeAt(this.index);
|
---|
| 1160 | if (c === 10) {
|
---|
| 1161 | this.newlines.push(this.index);
|
---|
| 1162 | }
|
---|
| 1163 | switch (this.state) {
|
---|
| 1164 | case 1: {
|
---|
| 1165 | this.stateText(c);
|
---|
| 1166 | break;
|
---|
| 1167 | }
|
---|
| 1168 | case 2: {
|
---|
| 1169 | this.stateInterpolationOpen(c);
|
---|
| 1170 | break;
|
---|
| 1171 | }
|
---|
| 1172 | case 3: {
|
---|
| 1173 | this.stateInterpolation(c);
|
---|
| 1174 | break;
|
---|
| 1175 | }
|
---|
| 1176 | case 4: {
|
---|
| 1177 | this.stateInterpolationClose(c);
|
---|
| 1178 | break;
|
---|
| 1179 | }
|
---|
| 1180 | case 31: {
|
---|
| 1181 | this.stateSpecialStartSequence(c);
|
---|
| 1182 | break;
|
---|
| 1183 | }
|
---|
| 1184 | case 32: {
|
---|
| 1185 | this.stateInRCDATA(c);
|
---|
| 1186 | break;
|
---|
| 1187 | }
|
---|
| 1188 | case 26: {
|
---|
| 1189 | this.stateCDATASequence(c);
|
---|
| 1190 | break;
|
---|
| 1191 | }
|
---|
| 1192 | case 19: {
|
---|
| 1193 | this.stateInAttrValueDoubleQuotes(c);
|
---|
| 1194 | break;
|
---|
| 1195 | }
|
---|
| 1196 | case 12: {
|
---|
| 1197 | this.stateInAttrName(c);
|
---|
| 1198 | break;
|
---|
| 1199 | }
|
---|
| 1200 | case 13: {
|
---|
| 1201 | this.stateInDirName(c);
|
---|
| 1202 | break;
|
---|
| 1203 | }
|
---|
| 1204 | case 14: {
|
---|
| 1205 | this.stateInDirArg(c);
|
---|
| 1206 | break;
|
---|
| 1207 | }
|
---|
| 1208 | case 15: {
|
---|
| 1209 | this.stateInDynamicDirArg(c);
|
---|
| 1210 | break;
|
---|
| 1211 | }
|
---|
| 1212 | case 16: {
|
---|
| 1213 | this.stateInDirModifier(c);
|
---|
| 1214 | break;
|
---|
| 1215 | }
|
---|
| 1216 | case 28: {
|
---|
| 1217 | this.stateInCommentLike(c);
|
---|
| 1218 | break;
|
---|
| 1219 | }
|
---|
| 1220 | case 27: {
|
---|
| 1221 | this.stateInSpecialComment(c);
|
---|
| 1222 | break;
|
---|
| 1223 | }
|
---|
| 1224 | case 11: {
|
---|
| 1225 | this.stateBeforeAttrName(c);
|
---|
| 1226 | break;
|
---|
| 1227 | }
|
---|
| 1228 | case 6: {
|
---|
| 1229 | this.stateInTagName(c);
|
---|
| 1230 | break;
|
---|
| 1231 | }
|
---|
| 1232 | case 34: {
|
---|
| 1233 | this.stateInSFCRootTagName(c);
|
---|
| 1234 | break;
|
---|
| 1235 | }
|
---|
| 1236 | case 9: {
|
---|
| 1237 | this.stateInClosingTagName(c);
|
---|
| 1238 | break;
|
---|
| 1239 | }
|
---|
| 1240 | case 5: {
|
---|
| 1241 | this.stateBeforeTagName(c);
|
---|
| 1242 | break;
|
---|
| 1243 | }
|
---|
| 1244 | case 17: {
|
---|
| 1245 | this.stateAfterAttrName(c);
|
---|
| 1246 | break;
|
---|
| 1247 | }
|
---|
| 1248 | case 20: {
|
---|
| 1249 | this.stateInAttrValueSingleQuotes(c);
|
---|
| 1250 | break;
|
---|
| 1251 | }
|
---|
| 1252 | case 18: {
|
---|
| 1253 | this.stateBeforeAttrValue(c);
|
---|
| 1254 | break;
|
---|
| 1255 | }
|
---|
| 1256 | case 8: {
|
---|
| 1257 | this.stateBeforeClosingTagName(c);
|
---|
| 1258 | break;
|
---|
| 1259 | }
|
---|
| 1260 | case 10: {
|
---|
| 1261 | this.stateAfterClosingTagName(c);
|
---|
| 1262 | break;
|
---|
| 1263 | }
|
---|
| 1264 | case 29: {
|
---|
| 1265 | this.stateBeforeSpecialS(c);
|
---|
| 1266 | break;
|
---|
| 1267 | }
|
---|
| 1268 | case 30: {
|
---|
| 1269 | this.stateBeforeSpecialT(c);
|
---|
| 1270 | break;
|
---|
| 1271 | }
|
---|
| 1272 | case 21: {
|
---|
| 1273 | this.stateInAttrValueNoQuotes(c);
|
---|
| 1274 | break;
|
---|
| 1275 | }
|
---|
| 1276 | case 7: {
|
---|
| 1277 | this.stateInSelfClosingTag(c);
|
---|
| 1278 | break;
|
---|
| 1279 | }
|
---|
| 1280 | case 23: {
|
---|
| 1281 | this.stateInDeclaration(c);
|
---|
| 1282 | break;
|
---|
| 1283 | }
|
---|
| 1284 | case 22: {
|
---|
| 1285 | this.stateBeforeDeclaration(c);
|
---|
| 1286 | break;
|
---|
| 1287 | }
|
---|
| 1288 | case 25: {
|
---|
| 1289 | this.stateBeforeComment(c);
|
---|
| 1290 | break;
|
---|
| 1291 | }
|
---|
| 1292 | case 24: {
|
---|
| 1293 | this.stateInProcessingInstruction(c);
|
---|
| 1294 | break;
|
---|
| 1295 | }
|
---|
| 1296 | case 33: {
|
---|
| 1297 | this.stateInEntity();
|
---|
| 1298 | break;
|
---|
| 1299 | }
|
---|
| 1300 | }
|
---|
| 1301 | this.index++;
|
---|
| 1302 | }
|
---|
| 1303 | this.cleanup();
|
---|
| 1304 | this.finish();
|
---|
| 1305 | }
|
---|
| 1306 | /**
|
---|
| 1307 | * Remove data that has already been consumed from the buffer.
|
---|
| 1308 | */
|
---|
| 1309 | cleanup() {
|
---|
| 1310 | if (this.sectionStart !== this.index) {
|
---|
| 1311 | if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
|
---|
| 1312 | this.cbs.ontext(this.sectionStart, this.index);
|
---|
| 1313 | this.sectionStart = this.index;
|
---|
| 1314 | } else if (this.state === 19 || this.state === 20 || this.state === 21) {
|
---|
| 1315 | this.cbs.onattribdata(this.sectionStart, this.index);
|
---|
| 1316 | this.sectionStart = this.index;
|
---|
| 1317 | }
|
---|
| 1318 | }
|
---|
| 1319 | }
|
---|
| 1320 | finish() {
|
---|
| 1321 | this.handleTrailingData();
|
---|
| 1322 | this.cbs.onend();
|
---|
| 1323 | }
|
---|
| 1324 | /** Handle any trailing data. */
|
---|
| 1325 | handleTrailingData() {
|
---|
| 1326 | const endIndex = this.buffer.length;
|
---|
| 1327 | if (this.sectionStart >= endIndex) {
|
---|
| 1328 | return;
|
---|
| 1329 | }
|
---|
| 1330 | if (this.state === 28) {
|
---|
| 1331 | if (this.currentSequence === Sequences.CdataEnd) {
|
---|
| 1332 | this.cbs.oncdata(this.sectionStart, endIndex);
|
---|
| 1333 | } else {
|
---|
| 1334 | this.cbs.oncomment(this.sectionStart, endIndex);
|
---|
| 1335 | }
|
---|
| 1336 | } else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) ; else {
|
---|
| 1337 | this.cbs.ontext(this.sectionStart, endIndex);
|
---|
| 1338 | }
|
---|
| 1339 | }
|
---|
| 1340 | emitCodePoint(cp, consumed) {
|
---|
| 1341 | }
|
---|
| 1342 | }
|
---|
| 1343 |
|
---|
| 1344 | const CompilerDeprecationTypes = {
|
---|
| 1345 | "COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
|
---|
| 1346 | "COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
|
---|
| 1347 | "COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
|
---|
| 1348 | "COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
|
---|
| 1349 | "COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
---|
| 1350 | "COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
|
---|
| 1351 | "COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
|
---|
| 1352 | "COMPILER_FILTERS": "COMPILER_FILTERS"
|
---|
| 1353 | };
|
---|
| 1354 | const deprecationData = {
|
---|
| 1355 | ["COMPILER_IS_ON_ELEMENT"]: {
|
---|
| 1356 | message: `Platform-native elements with "is" prop will no longer be treated as components in Vue 3 unless the "is" value is explicitly prefixed with "vue:".`,
|
---|
| 1357 | link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
---|
| 1358 | },
|
---|
| 1359 | ["COMPILER_V_BIND_SYNC"]: {
|
---|
| 1360 | message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
|
---|
| 1361 | link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
---|
| 1362 | },
|
---|
| 1363 | ["COMPILER_V_BIND_OBJECT_ORDER"]: {
|
---|
| 1364 | message: `v-bind="obj" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.`,
|
---|
| 1365 | link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
---|
| 1366 | },
|
---|
| 1367 | ["COMPILER_V_ON_NATIVE"]: {
|
---|
| 1368 | message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
---|
| 1369 | link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
---|
| 1370 | },
|
---|
| 1371 | ["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
|
---|
| 1372 | message: `v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.`,
|
---|
| 1373 | link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
---|
| 1374 | },
|
---|
| 1375 | ["COMPILER_NATIVE_TEMPLATE"]: {
|
---|
| 1376 | message: `<template> with no special directives will render as a native template element instead of its inner content in Vue 3.`
|
---|
| 1377 | },
|
---|
| 1378 | ["COMPILER_INLINE_TEMPLATE"]: {
|
---|
| 1379 | message: `"inline-template" has been removed in Vue 3.`,
|
---|
| 1380 | link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
---|
| 1381 | },
|
---|
| 1382 | ["COMPILER_FILTERS"]: {
|
---|
| 1383 | message: `filters have been removed in Vue 3. The "|" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.`,
|
---|
| 1384 | link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
|
---|
| 1385 | }
|
---|
| 1386 | };
|
---|
| 1387 | function getCompatValue(key, { compatConfig }) {
|
---|
| 1388 | const value = compatConfig && compatConfig[key];
|
---|
| 1389 | if (key === "MODE") {
|
---|
| 1390 | return value || 3;
|
---|
| 1391 | } else {
|
---|
| 1392 | return value;
|
---|
| 1393 | }
|
---|
| 1394 | }
|
---|
| 1395 | function isCompatEnabled(key, context) {
|
---|
| 1396 | const mode = getCompatValue("MODE", context);
|
---|
| 1397 | const value = getCompatValue(key, context);
|
---|
| 1398 | return mode === 3 ? value === true : value !== false;
|
---|
| 1399 | }
|
---|
| 1400 | function checkCompatEnabled(key, context, loc, ...args) {
|
---|
| 1401 | const enabled = isCompatEnabled(key, context);
|
---|
| 1402 | if (enabled) {
|
---|
| 1403 | warnDeprecation(key, context, loc, ...args);
|
---|
| 1404 | }
|
---|
| 1405 | return enabled;
|
---|
| 1406 | }
|
---|
| 1407 | function warnDeprecation(key, context, loc, ...args) {
|
---|
| 1408 | const val = getCompatValue(key, context);
|
---|
| 1409 | if (val === "suppress-warning") {
|
---|
| 1410 | return;
|
---|
| 1411 | }
|
---|
| 1412 | const { message, link } = deprecationData[key];
|
---|
| 1413 | const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `
|
---|
| 1414 | Details: ${link}` : ``}`;
|
---|
| 1415 | const err = new SyntaxError(msg);
|
---|
| 1416 | err.code = key;
|
---|
| 1417 | if (loc) err.loc = loc;
|
---|
| 1418 | context.onWarn(err);
|
---|
| 1419 | }
|
---|
| 1420 |
|
---|
| 1421 | function defaultOnError(error) {
|
---|
| 1422 | throw error;
|
---|
| 1423 | }
|
---|
| 1424 | function defaultOnWarn(msg) {
|
---|
| 1425 | console.warn(`[Vue warn] ${msg.message}`);
|
---|
| 1426 | }
|
---|
| 1427 | function createCompilerError(code, loc, messages, additionalMessage) {
|
---|
| 1428 | const msg = (messages || errorMessages)[code] + (additionalMessage || ``) ;
|
---|
| 1429 | const error = new SyntaxError(String(msg));
|
---|
| 1430 | error.code = code;
|
---|
| 1431 | error.loc = loc;
|
---|
| 1432 | return error;
|
---|
| 1433 | }
|
---|
| 1434 | const ErrorCodes = {
|
---|
| 1435 | "ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
|
---|
| 1436 | "0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
|
---|
| 1437 | "CDATA_IN_HTML_CONTENT": 1,
|
---|
| 1438 | "1": "CDATA_IN_HTML_CONTENT",
|
---|
| 1439 | "DUPLICATE_ATTRIBUTE": 2,
|
---|
| 1440 | "2": "DUPLICATE_ATTRIBUTE",
|
---|
| 1441 | "END_TAG_WITH_ATTRIBUTES": 3,
|
---|
| 1442 | "3": "END_TAG_WITH_ATTRIBUTES",
|
---|
| 1443 | "END_TAG_WITH_TRAILING_SOLIDUS": 4,
|
---|
| 1444 | "4": "END_TAG_WITH_TRAILING_SOLIDUS",
|
---|
| 1445 | "EOF_BEFORE_TAG_NAME": 5,
|
---|
| 1446 | "5": "EOF_BEFORE_TAG_NAME",
|
---|
| 1447 | "EOF_IN_CDATA": 6,
|
---|
| 1448 | "6": "EOF_IN_CDATA",
|
---|
| 1449 | "EOF_IN_COMMENT": 7,
|
---|
| 1450 | "7": "EOF_IN_COMMENT",
|
---|
| 1451 | "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
|
---|
| 1452 | "8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
|
---|
| 1453 | "EOF_IN_TAG": 9,
|
---|
| 1454 | "9": "EOF_IN_TAG",
|
---|
| 1455 | "INCORRECTLY_CLOSED_COMMENT": 10,
|
---|
| 1456 | "10": "INCORRECTLY_CLOSED_COMMENT",
|
---|
| 1457 | "INCORRECTLY_OPENED_COMMENT": 11,
|
---|
| 1458 | "11": "INCORRECTLY_OPENED_COMMENT",
|
---|
| 1459 | "INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
|
---|
| 1460 | "12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
|
---|
| 1461 | "MISSING_ATTRIBUTE_VALUE": 13,
|
---|
| 1462 | "13": "MISSING_ATTRIBUTE_VALUE",
|
---|
| 1463 | "MISSING_END_TAG_NAME": 14,
|
---|
| 1464 | "14": "MISSING_END_TAG_NAME",
|
---|
| 1465 | "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
|
---|
| 1466 | "15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
|
---|
| 1467 | "NESTED_COMMENT": 16,
|
---|
| 1468 | "16": "NESTED_COMMENT",
|
---|
| 1469 | "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
|
---|
| 1470 | "17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
|
---|
| 1471 | "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
|
---|
| 1472 | "18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
|
---|
| 1473 | "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
|
---|
| 1474 | "19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
|
---|
| 1475 | "UNEXPECTED_NULL_CHARACTER": 20,
|
---|
| 1476 | "20": "UNEXPECTED_NULL_CHARACTER",
|
---|
| 1477 | "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
|
---|
| 1478 | "21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
|
---|
| 1479 | "UNEXPECTED_SOLIDUS_IN_TAG": 22,
|
---|
| 1480 | "22": "UNEXPECTED_SOLIDUS_IN_TAG",
|
---|
| 1481 | "X_INVALID_END_TAG": 23,
|
---|
| 1482 | "23": "X_INVALID_END_TAG",
|
---|
| 1483 | "X_MISSING_END_TAG": 24,
|
---|
| 1484 | "24": "X_MISSING_END_TAG",
|
---|
| 1485 | "X_MISSING_INTERPOLATION_END": 25,
|
---|
| 1486 | "25": "X_MISSING_INTERPOLATION_END",
|
---|
| 1487 | "X_MISSING_DIRECTIVE_NAME": 26,
|
---|
| 1488 | "26": "X_MISSING_DIRECTIVE_NAME",
|
---|
| 1489 | "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
|
---|
| 1490 | "27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
|
---|
| 1491 | "X_V_IF_NO_EXPRESSION": 28,
|
---|
| 1492 | "28": "X_V_IF_NO_EXPRESSION",
|
---|
| 1493 | "X_V_IF_SAME_KEY": 29,
|
---|
| 1494 | "29": "X_V_IF_SAME_KEY",
|
---|
| 1495 | "X_V_ELSE_NO_ADJACENT_IF": 30,
|
---|
| 1496 | "30": "X_V_ELSE_NO_ADJACENT_IF",
|
---|
| 1497 | "X_V_FOR_NO_EXPRESSION": 31,
|
---|
| 1498 | "31": "X_V_FOR_NO_EXPRESSION",
|
---|
| 1499 | "X_V_FOR_MALFORMED_EXPRESSION": 32,
|
---|
| 1500 | "32": "X_V_FOR_MALFORMED_EXPRESSION",
|
---|
| 1501 | "X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
|
---|
| 1502 | "33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
|
---|
| 1503 | "X_V_BIND_NO_EXPRESSION": 34,
|
---|
| 1504 | "34": "X_V_BIND_NO_EXPRESSION",
|
---|
| 1505 | "X_V_ON_NO_EXPRESSION": 35,
|
---|
| 1506 | "35": "X_V_ON_NO_EXPRESSION",
|
---|
| 1507 | "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
|
---|
| 1508 | "36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
|
---|
| 1509 | "X_V_SLOT_MIXED_SLOT_USAGE": 37,
|
---|
| 1510 | "37": "X_V_SLOT_MIXED_SLOT_USAGE",
|
---|
| 1511 | "X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
|
---|
| 1512 | "38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
|
---|
| 1513 | "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
|
---|
| 1514 | "39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
|
---|
| 1515 | "X_V_SLOT_MISPLACED": 40,
|
---|
| 1516 | "40": "X_V_SLOT_MISPLACED",
|
---|
| 1517 | "X_V_MODEL_NO_EXPRESSION": 41,
|
---|
| 1518 | "41": "X_V_MODEL_NO_EXPRESSION",
|
---|
| 1519 | "X_V_MODEL_MALFORMED_EXPRESSION": 42,
|
---|
| 1520 | "42": "X_V_MODEL_MALFORMED_EXPRESSION",
|
---|
| 1521 | "X_V_MODEL_ON_SCOPE_VARIABLE": 43,
|
---|
| 1522 | "43": "X_V_MODEL_ON_SCOPE_VARIABLE",
|
---|
| 1523 | "X_V_MODEL_ON_PROPS": 44,
|
---|
| 1524 | "44": "X_V_MODEL_ON_PROPS",
|
---|
| 1525 | "X_INVALID_EXPRESSION": 45,
|
---|
| 1526 | "45": "X_INVALID_EXPRESSION",
|
---|
| 1527 | "X_KEEP_ALIVE_INVALID_CHILDREN": 46,
|
---|
| 1528 | "46": "X_KEEP_ALIVE_INVALID_CHILDREN",
|
---|
| 1529 | "X_PREFIX_ID_NOT_SUPPORTED": 47,
|
---|
| 1530 | "47": "X_PREFIX_ID_NOT_SUPPORTED",
|
---|
| 1531 | "X_MODULE_MODE_NOT_SUPPORTED": 48,
|
---|
| 1532 | "48": "X_MODULE_MODE_NOT_SUPPORTED",
|
---|
| 1533 | "X_CACHE_HANDLER_NOT_SUPPORTED": 49,
|
---|
| 1534 | "49": "X_CACHE_HANDLER_NOT_SUPPORTED",
|
---|
| 1535 | "X_SCOPE_ID_NOT_SUPPORTED": 50,
|
---|
| 1536 | "50": "X_SCOPE_ID_NOT_SUPPORTED",
|
---|
| 1537 | "X_VNODE_HOOKS": 51,
|
---|
| 1538 | "51": "X_VNODE_HOOKS",
|
---|
| 1539 | "X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 52,
|
---|
| 1540 | "52": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
|
---|
| 1541 | "__EXTEND_POINT__": 53,
|
---|
| 1542 | "53": "__EXTEND_POINT__"
|
---|
| 1543 | };
|
---|
| 1544 | const errorMessages = {
|
---|
| 1545 | // parse errors
|
---|
| 1546 | [0]: "Illegal comment.",
|
---|
| 1547 | [1]: "CDATA section is allowed only in XML context.",
|
---|
| 1548 | [2]: "Duplicate attribute.",
|
---|
| 1549 | [3]: "End tag cannot have attributes.",
|
---|
| 1550 | [4]: "Illegal '/' in tags.",
|
---|
| 1551 | [5]: "Unexpected EOF in tag.",
|
---|
| 1552 | [6]: "Unexpected EOF in CDATA section.",
|
---|
| 1553 | [7]: "Unexpected EOF in comment.",
|
---|
| 1554 | [8]: "Unexpected EOF in script.",
|
---|
| 1555 | [9]: "Unexpected EOF in tag.",
|
---|
| 1556 | [10]: "Incorrectly closed comment.",
|
---|
| 1557 | [11]: "Incorrectly opened comment.",
|
---|
| 1558 | [12]: "Illegal tag name. Use '<' to print '<'.",
|
---|
| 1559 | [13]: "Attribute value was expected.",
|
---|
| 1560 | [14]: "End tag name was expected.",
|
---|
| 1561 | [15]: "Whitespace was expected.",
|
---|
| 1562 | [16]: "Unexpected '<!--' in comment.",
|
---|
| 1563 | [17]: `Attribute name cannot contain U+0022 ("), U+0027 ('), and U+003C (<).`,
|
---|
| 1564 | [18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
|
---|
| 1565 | [19]: "Attribute name cannot start with '='.",
|
---|
| 1566 | [21]: "'<?' is allowed only in XML context.",
|
---|
| 1567 | [20]: `Unexpected null character.`,
|
---|
| 1568 | [22]: "Illegal '/' in tags.",
|
---|
| 1569 | // Vue-specific parse errors
|
---|
| 1570 | [23]: "Invalid end tag.",
|
---|
| 1571 | [24]: "Element is missing end tag.",
|
---|
| 1572 | [25]: "Interpolation end sign was not found.",
|
---|
| 1573 | [27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
|
---|
| 1574 | [26]: "Legal directive name was expected.",
|
---|
| 1575 | // transform errors
|
---|
| 1576 | [28]: `v-if/v-else-if is missing expression.`,
|
---|
| 1577 | [29]: `v-if/else branches must use unique keys.`,
|
---|
| 1578 | [30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
---|
| 1579 | [31]: `v-for is missing expression.`,
|
---|
| 1580 | [32]: `v-for has invalid expression.`,
|
---|
| 1581 | [33]: `<template v-for> key should be placed on the <template> tag.`,
|
---|
| 1582 | [34]: `v-bind is missing expression.`,
|
---|
| 1583 | [52]: `v-bind with same-name shorthand only allows static argument.`,
|
---|
| 1584 | [35]: `v-on is missing expression.`,
|
---|
| 1585 | [36]: `Unexpected custom directive on <slot> outlet.`,
|
---|
| 1586 | [37]: `Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.`,
|
---|
| 1587 | [38]: `Duplicate slot names found. `,
|
---|
| 1588 | [39]: `Extraneous children found when component already has explicitly named default slot. These children will be ignored.`,
|
---|
| 1589 | [40]: `v-slot can only be used on components or <template> tags.`,
|
---|
| 1590 | [41]: `v-model is missing expression.`,
|
---|
| 1591 | [42]: `v-model value must be a valid JavaScript member expression.`,
|
---|
| 1592 | [43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
---|
| 1593 | [44]: `v-model cannot be used on a prop, because local prop bindings are not writable.
|
---|
| 1594 | Use a v-bind binding combined with a v-on listener that emits update:x event instead.`,
|
---|
| 1595 | [45]: `Error parsing JavaScript expression: `,
|
---|
| 1596 | [46]: `<KeepAlive> expects exactly one child component.`,
|
---|
| 1597 | [51]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
|
---|
| 1598 | // generic errors
|
---|
| 1599 | [47]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
---|
| 1600 | [48]: `ES module mode is not supported in this build of compiler.`,
|
---|
| 1601 | [49]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
---|
| 1602 | [50]: `"scopeId" option is only supported in module mode.`,
|
---|
| 1603 | // just to fulfill types
|
---|
| 1604 | [53]: ``
|
---|
| 1605 | };
|
---|
| 1606 |
|
---|
| 1607 | function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = /* @__PURE__ */ Object.create(null)) {
|
---|
| 1608 | {
|
---|
| 1609 | return;
|
---|
| 1610 | }
|
---|
| 1611 | }
|
---|
| 1612 | function isReferencedIdentifier(id, parent, parentStack) {
|
---|
| 1613 | {
|
---|
| 1614 | return false;
|
---|
| 1615 | }
|
---|
| 1616 | }
|
---|
| 1617 | function isInDestructureAssignment(parent, parentStack) {
|
---|
| 1618 | if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
---|
| 1619 | let i = parentStack.length;
|
---|
| 1620 | while (i--) {
|
---|
| 1621 | const p = parentStack[i];
|
---|
| 1622 | if (p.type === "AssignmentExpression") {
|
---|
| 1623 | return true;
|
---|
| 1624 | } else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) {
|
---|
| 1625 | break;
|
---|
| 1626 | }
|
---|
| 1627 | }
|
---|
| 1628 | }
|
---|
| 1629 | return false;
|
---|
| 1630 | }
|
---|
| 1631 | function isInNewExpression(parentStack) {
|
---|
| 1632 | let i = parentStack.length;
|
---|
| 1633 | while (i--) {
|
---|
| 1634 | const p = parentStack[i];
|
---|
| 1635 | if (p.type === "NewExpression") {
|
---|
| 1636 | return true;
|
---|
| 1637 | } else if (p.type !== "MemberExpression") {
|
---|
| 1638 | break;
|
---|
| 1639 | }
|
---|
| 1640 | }
|
---|
| 1641 | return false;
|
---|
| 1642 | }
|
---|
| 1643 | function walkFunctionParams(node, onIdent) {
|
---|
| 1644 | for (const p of node.params) {
|
---|
| 1645 | for (const id of extractIdentifiers(p)) {
|
---|
| 1646 | onIdent(id);
|
---|
| 1647 | }
|
---|
| 1648 | }
|
---|
| 1649 | }
|
---|
| 1650 | function walkBlockDeclarations(block, onIdent) {
|
---|
| 1651 | for (const stmt of block.body) {
|
---|
| 1652 | if (stmt.type === "VariableDeclaration") {
|
---|
| 1653 | if (stmt.declare) continue;
|
---|
| 1654 | for (const decl of stmt.declarations) {
|
---|
| 1655 | for (const id of extractIdentifiers(decl.id)) {
|
---|
| 1656 | onIdent(id);
|
---|
| 1657 | }
|
---|
| 1658 | }
|
---|
| 1659 | } else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
---|
| 1660 | if (stmt.declare || !stmt.id) continue;
|
---|
| 1661 | onIdent(stmt.id);
|
---|
| 1662 | } else if (isForStatement(stmt)) {
|
---|
| 1663 | walkForStatement(stmt, true, onIdent);
|
---|
| 1664 | }
|
---|
| 1665 | }
|
---|
| 1666 | }
|
---|
| 1667 | function isForStatement(stmt) {
|
---|
| 1668 | return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
|
---|
| 1669 | }
|
---|
| 1670 | function walkForStatement(stmt, isVar, onIdent) {
|
---|
| 1671 | const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
---|
| 1672 | if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) {
|
---|
| 1673 | for (const decl of variable.declarations) {
|
---|
| 1674 | for (const id of extractIdentifiers(decl.id)) {
|
---|
| 1675 | onIdent(id);
|
---|
| 1676 | }
|
---|
| 1677 | }
|
---|
| 1678 | }
|
---|
| 1679 | }
|
---|
| 1680 | function extractIdentifiers(param, nodes = []) {
|
---|
| 1681 | switch (param.type) {
|
---|
| 1682 | case "Identifier":
|
---|
| 1683 | nodes.push(param);
|
---|
| 1684 | break;
|
---|
| 1685 | case "MemberExpression":
|
---|
| 1686 | let object = param;
|
---|
| 1687 | while (object.type === "MemberExpression") {
|
---|
| 1688 | object = object.object;
|
---|
| 1689 | }
|
---|
| 1690 | nodes.push(object);
|
---|
| 1691 | break;
|
---|
| 1692 | case "ObjectPattern":
|
---|
| 1693 | for (const prop of param.properties) {
|
---|
| 1694 | if (prop.type === "RestElement") {
|
---|
| 1695 | extractIdentifiers(prop.argument, nodes);
|
---|
| 1696 | } else {
|
---|
| 1697 | extractIdentifiers(prop.value, nodes);
|
---|
| 1698 | }
|
---|
| 1699 | }
|
---|
| 1700 | break;
|
---|
| 1701 | case "ArrayPattern":
|
---|
| 1702 | param.elements.forEach((element) => {
|
---|
| 1703 | if (element) extractIdentifiers(element, nodes);
|
---|
| 1704 | });
|
---|
| 1705 | break;
|
---|
| 1706 | case "RestElement":
|
---|
| 1707 | extractIdentifiers(param.argument, nodes);
|
---|
| 1708 | break;
|
---|
| 1709 | case "AssignmentPattern":
|
---|
| 1710 | extractIdentifiers(param.left, nodes);
|
---|
| 1711 | break;
|
---|
| 1712 | }
|
---|
| 1713 | return nodes;
|
---|
| 1714 | }
|
---|
| 1715 | const isFunctionType = (node) => {
|
---|
| 1716 | return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
---|
| 1717 | };
|
---|
| 1718 | const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
---|
| 1719 | const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
---|
| 1720 | const TS_NODE_TYPES = [
|
---|
| 1721 | "TSAsExpression",
|
---|
| 1722 | // foo as number
|
---|
| 1723 | "TSTypeAssertion",
|
---|
| 1724 | // (<number>foo)
|
---|
| 1725 | "TSNonNullExpression",
|
---|
| 1726 | // foo!
|
---|
| 1727 | "TSInstantiationExpression",
|
---|
| 1728 | // foo<string>
|
---|
| 1729 | "TSSatisfiesExpression"
|
---|
| 1730 | // foo satisfies T
|
---|
| 1731 | ];
|
---|
| 1732 | function unwrapTSNode(node) {
|
---|
| 1733 | if (TS_NODE_TYPES.includes(node.type)) {
|
---|
| 1734 | return unwrapTSNode(node.expression);
|
---|
| 1735 | } else {
|
---|
| 1736 | return node;
|
---|
| 1737 | }
|
---|
| 1738 | }
|
---|
| 1739 |
|
---|
| 1740 | const isStaticExp = (p) => p.type === 4 && p.isStatic;
|
---|
| 1741 | function isCoreComponent(tag) {
|
---|
| 1742 | switch (tag) {
|
---|
| 1743 | case "Teleport":
|
---|
| 1744 | case "teleport":
|
---|
| 1745 | return TELEPORT;
|
---|
| 1746 | case "Suspense":
|
---|
| 1747 | case "suspense":
|
---|
| 1748 | return SUSPENSE;
|
---|
| 1749 | case "KeepAlive":
|
---|
| 1750 | case "keep-alive":
|
---|
| 1751 | return KEEP_ALIVE;
|
---|
| 1752 | case "BaseTransition":
|
---|
| 1753 | case "base-transition":
|
---|
| 1754 | return BASE_TRANSITION;
|
---|
| 1755 | }
|
---|
| 1756 | }
|
---|
| 1757 | const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
|
---|
| 1758 | const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
---|
| 1759 | const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
---|
| 1760 | const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
---|
| 1761 | const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
---|
| 1762 | const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
|
---|
| 1763 | const isMemberExpressionBrowser = (exp) => {
|
---|
| 1764 | const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
|
---|
| 1765 | let state = 0 /* inMemberExp */;
|
---|
| 1766 | let stateStack = [];
|
---|
| 1767 | let currentOpenBracketCount = 0;
|
---|
| 1768 | let currentOpenParensCount = 0;
|
---|
| 1769 | let currentStringType = null;
|
---|
| 1770 | for (let i = 0; i < path.length; i++) {
|
---|
| 1771 | const char = path.charAt(i);
|
---|
| 1772 | switch (state) {
|
---|
| 1773 | case 0 /* inMemberExp */:
|
---|
| 1774 | if (char === "[") {
|
---|
| 1775 | stateStack.push(state);
|
---|
| 1776 | state = 1 /* inBrackets */;
|
---|
| 1777 | currentOpenBracketCount++;
|
---|
| 1778 | } else if (char === "(") {
|
---|
| 1779 | stateStack.push(state);
|
---|
| 1780 | state = 2 /* inParens */;
|
---|
| 1781 | currentOpenParensCount++;
|
---|
| 1782 | } else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) {
|
---|
| 1783 | return false;
|
---|
| 1784 | }
|
---|
| 1785 | break;
|
---|
| 1786 | case 1 /* inBrackets */:
|
---|
| 1787 | if (char === `'` || char === `"` || char === "`") {
|
---|
| 1788 | stateStack.push(state);
|
---|
| 1789 | state = 3 /* inString */;
|
---|
| 1790 | currentStringType = char;
|
---|
| 1791 | } else if (char === `[`) {
|
---|
| 1792 | currentOpenBracketCount++;
|
---|
| 1793 | } else if (char === `]`) {
|
---|
| 1794 | if (!--currentOpenBracketCount) {
|
---|
| 1795 | state = stateStack.pop();
|
---|
| 1796 | }
|
---|
| 1797 | }
|
---|
| 1798 | break;
|
---|
| 1799 | case 2 /* inParens */:
|
---|
| 1800 | if (char === `'` || char === `"` || char === "`") {
|
---|
| 1801 | stateStack.push(state);
|
---|
| 1802 | state = 3 /* inString */;
|
---|
| 1803 | currentStringType = char;
|
---|
| 1804 | } else if (char === `(`) {
|
---|
| 1805 | currentOpenParensCount++;
|
---|
| 1806 | } else if (char === `)`) {
|
---|
| 1807 | if (i === path.length - 1) {
|
---|
| 1808 | return false;
|
---|
| 1809 | }
|
---|
| 1810 | if (!--currentOpenParensCount) {
|
---|
| 1811 | state = stateStack.pop();
|
---|
| 1812 | }
|
---|
| 1813 | }
|
---|
| 1814 | break;
|
---|
| 1815 | case 3 /* inString */:
|
---|
| 1816 | if (char === currentStringType) {
|
---|
| 1817 | state = stateStack.pop();
|
---|
| 1818 | currentStringType = null;
|
---|
| 1819 | }
|
---|
| 1820 | break;
|
---|
| 1821 | }
|
---|
| 1822 | }
|
---|
| 1823 | return !currentOpenBracketCount && !currentOpenParensCount;
|
---|
| 1824 | };
|
---|
| 1825 | const isMemberExpressionNode = NOOP ;
|
---|
| 1826 | const isMemberExpression = isMemberExpressionBrowser ;
|
---|
| 1827 | const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
---|
| 1828 | const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
|
---|
| 1829 | const isFnExpressionNode = NOOP ;
|
---|
| 1830 | const isFnExpression = isFnExpressionBrowser ;
|
---|
| 1831 | function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
|
---|
| 1832 | return advancePositionWithMutation(
|
---|
| 1833 | {
|
---|
| 1834 | offset: pos.offset,
|
---|
| 1835 | line: pos.line,
|
---|
| 1836 | column: pos.column
|
---|
| 1837 | },
|
---|
| 1838 | source,
|
---|
| 1839 | numberOfCharacters
|
---|
| 1840 | );
|
---|
| 1841 | }
|
---|
| 1842 | function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
|
---|
| 1843 | let linesCount = 0;
|
---|
| 1844 | let lastNewLinePos = -1;
|
---|
| 1845 | for (let i = 0; i < numberOfCharacters; i++) {
|
---|
| 1846 | if (source.charCodeAt(i) === 10) {
|
---|
| 1847 | linesCount++;
|
---|
| 1848 | lastNewLinePos = i;
|
---|
| 1849 | }
|
---|
| 1850 | }
|
---|
| 1851 | pos.offset += numberOfCharacters;
|
---|
| 1852 | pos.line += linesCount;
|
---|
| 1853 | pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
|
---|
| 1854 | return pos;
|
---|
| 1855 | }
|
---|
| 1856 | function assert(condition, msg) {
|
---|
| 1857 | if (!condition) {
|
---|
| 1858 | throw new Error(msg || `unexpected compiler condition`);
|
---|
| 1859 | }
|
---|
| 1860 | }
|
---|
| 1861 | function findDir(node, name, allowEmpty = false) {
|
---|
| 1862 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 1863 | const p = node.props[i];
|
---|
| 1864 | if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) {
|
---|
| 1865 | return p;
|
---|
| 1866 | }
|
---|
| 1867 | }
|
---|
| 1868 | }
|
---|
| 1869 | function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
---|
| 1870 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 1871 | const p = node.props[i];
|
---|
| 1872 | if (p.type === 6) {
|
---|
| 1873 | if (dynamicOnly) continue;
|
---|
| 1874 | if (p.name === name && (p.value || allowEmpty)) {
|
---|
| 1875 | return p;
|
---|
| 1876 | }
|
---|
| 1877 | } else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) {
|
---|
| 1878 | return p;
|
---|
| 1879 | }
|
---|
| 1880 | }
|
---|
| 1881 | }
|
---|
| 1882 | function isStaticArgOf(arg, name) {
|
---|
| 1883 | return !!(arg && isStaticExp(arg) && arg.content === name);
|
---|
| 1884 | }
|
---|
| 1885 | function hasDynamicKeyVBind(node) {
|
---|
| 1886 | return node.props.some(
|
---|
| 1887 | (p) => p.type === 7 && p.name === "bind" && (!p.arg || // v-bind="obj"
|
---|
| 1888 | p.arg.type !== 4 || // v-bind:[_ctx.foo]
|
---|
| 1889 | !p.arg.isStatic)
|
---|
| 1890 | // v-bind:[foo]
|
---|
| 1891 | );
|
---|
| 1892 | }
|
---|
| 1893 | function isText$1(node) {
|
---|
| 1894 | return node.type === 5 || node.type === 2;
|
---|
| 1895 | }
|
---|
| 1896 | function isVSlot(p) {
|
---|
| 1897 | return p.type === 7 && p.name === "slot";
|
---|
| 1898 | }
|
---|
| 1899 | function isTemplateNode(node) {
|
---|
| 1900 | return node.type === 1 && node.tagType === 3;
|
---|
| 1901 | }
|
---|
| 1902 | function isSlotOutlet(node) {
|
---|
| 1903 | return node.type === 1 && node.tagType === 2;
|
---|
| 1904 | }
|
---|
| 1905 | const propsHelperSet = /* @__PURE__ */ new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
---|
| 1906 | function getUnnormalizedProps(props, callPath = []) {
|
---|
| 1907 | if (props && !isString(props) && props.type === 14) {
|
---|
| 1908 | const callee = props.callee;
|
---|
| 1909 | if (!isString(callee) && propsHelperSet.has(callee)) {
|
---|
| 1910 | return getUnnormalizedProps(
|
---|
| 1911 | props.arguments[0],
|
---|
| 1912 | callPath.concat(props)
|
---|
| 1913 | );
|
---|
| 1914 | }
|
---|
| 1915 | }
|
---|
| 1916 | return [props, callPath];
|
---|
| 1917 | }
|
---|
| 1918 | function injectProp(node, prop, context) {
|
---|
| 1919 | let propsWithInjection;
|
---|
| 1920 | let props = node.type === 13 ? node.props : node.arguments[2];
|
---|
| 1921 | let callPath = [];
|
---|
| 1922 | let parentCall;
|
---|
| 1923 | if (props && !isString(props) && props.type === 14) {
|
---|
| 1924 | const ret = getUnnormalizedProps(props);
|
---|
| 1925 | props = ret[0];
|
---|
| 1926 | callPath = ret[1];
|
---|
| 1927 | parentCall = callPath[callPath.length - 1];
|
---|
| 1928 | }
|
---|
| 1929 | if (props == null || isString(props)) {
|
---|
| 1930 | propsWithInjection = createObjectExpression([prop]);
|
---|
| 1931 | } else if (props.type === 14) {
|
---|
| 1932 | const first = props.arguments[0];
|
---|
| 1933 | if (!isString(first) && first.type === 15) {
|
---|
| 1934 | if (!hasProp(prop, first)) {
|
---|
| 1935 | first.properties.unshift(prop);
|
---|
| 1936 | }
|
---|
| 1937 | } else {
|
---|
| 1938 | if (props.callee === TO_HANDLERS) {
|
---|
| 1939 | propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
|
---|
| 1940 | createObjectExpression([prop]),
|
---|
| 1941 | props
|
---|
| 1942 | ]);
|
---|
| 1943 | } else {
|
---|
| 1944 | props.arguments.unshift(createObjectExpression([prop]));
|
---|
| 1945 | }
|
---|
| 1946 | }
|
---|
| 1947 | !propsWithInjection && (propsWithInjection = props);
|
---|
| 1948 | } else if (props.type === 15) {
|
---|
| 1949 | if (!hasProp(prop, props)) {
|
---|
| 1950 | props.properties.unshift(prop);
|
---|
| 1951 | }
|
---|
| 1952 | propsWithInjection = props;
|
---|
| 1953 | } else {
|
---|
| 1954 | propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [
|
---|
| 1955 | createObjectExpression([prop]),
|
---|
| 1956 | props
|
---|
| 1957 | ]);
|
---|
| 1958 | if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) {
|
---|
| 1959 | parentCall = callPath[callPath.length - 2];
|
---|
| 1960 | }
|
---|
| 1961 | }
|
---|
| 1962 | if (node.type === 13) {
|
---|
| 1963 | if (parentCall) {
|
---|
| 1964 | parentCall.arguments[0] = propsWithInjection;
|
---|
| 1965 | } else {
|
---|
| 1966 | node.props = propsWithInjection;
|
---|
| 1967 | }
|
---|
| 1968 | } else {
|
---|
| 1969 | if (parentCall) {
|
---|
| 1970 | parentCall.arguments[0] = propsWithInjection;
|
---|
| 1971 | } else {
|
---|
| 1972 | node.arguments[2] = propsWithInjection;
|
---|
| 1973 | }
|
---|
| 1974 | }
|
---|
| 1975 | }
|
---|
| 1976 | function hasProp(prop, props) {
|
---|
| 1977 | let result = false;
|
---|
| 1978 | if (prop.key.type === 4) {
|
---|
| 1979 | const propKeyName = prop.key.content;
|
---|
| 1980 | result = props.properties.some(
|
---|
| 1981 | (p) => p.key.type === 4 && p.key.content === propKeyName
|
---|
| 1982 | );
|
---|
| 1983 | }
|
---|
| 1984 | return result;
|
---|
| 1985 | }
|
---|
| 1986 | function toValidAssetId(name, type) {
|
---|
| 1987 | return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
---|
| 1988 | return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
|
---|
| 1989 | })}`;
|
---|
| 1990 | }
|
---|
| 1991 | function hasScopeRef(node, ids) {
|
---|
| 1992 | if (!node || Object.keys(ids).length === 0) {
|
---|
| 1993 | return false;
|
---|
| 1994 | }
|
---|
| 1995 | switch (node.type) {
|
---|
| 1996 | case 1:
|
---|
| 1997 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 1998 | const p = node.props[i];
|
---|
| 1999 | if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) {
|
---|
| 2000 | return true;
|
---|
| 2001 | }
|
---|
| 2002 | }
|
---|
| 2003 | return node.children.some((c) => hasScopeRef(c, ids));
|
---|
| 2004 | case 11:
|
---|
| 2005 | if (hasScopeRef(node.source, ids)) {
|
---|
| 2006 | return true;
|
---|
| 2007 | }
|
---|
| 2008 | return node.children.some((c) => hasScopeRef(c, ids));
|
---|
| 2009 | case 9:
|
---|
| 2010 | return node.branches.some((b) => hasScopeRef(b, ids));
|
---|
| 2011 | case 10:
|
---|
| 2012 | if (hasScopeRef(node.condition, ids)) {
|
---|
| 2013 | return true;
|
---|
| 2014 | }
|
---|
| 2015 | return node.children.some((c) => hasScopeRef(c, ids));
|
---|
| 2016 | case 4:
|
---|
| 2017 | return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
|
---|
| 2018 | case 8:
|
---|
| 2019 | return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
|
---|
| 2020 | case 5:
|
---|
| 2021 | case 12:
|
---|
| 2022 | return hasScopeRef(node.content, ids);
|
---|
| 2023 | case 2:
|
---|
| 2024 | case 3:
|
---|
| 2025 | case 20:
|
---|
| 2026 | return false;
|
---|
| 2027 | default:
|
---|
| 2028 | return false;
|
---|
| 2029 | }
|
---|
| 2030 | }
|
---|
| 2031 | function getMemoedVNodeCall(node) {
|
---|
| 2032 | if (node.type === 14 && node.callee === WITH_MEMO) {
|
---|
| 2033 | return node.arguments[1].returns;
|
---|
| 2034 | } else {
|
---|
| 2035 | return node;
|
---|
| 2036 | }
|
---|
| 2037 | }
|
---|
| 2038 | const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
|
---|
| 2039 |
|
---|
| 2040 | const defaultParserOptions = {
|
---|
| 2041 | parseMode: "base",
|
---|
| 2042 | ns: 0,
|
---|
| 2043 | delimiters: [`{{`, `}}`],
|
---|
| 2044 | getNamespace: () => 0,
|
---|
| 2045 | isVoidTag: NO,
|
---|
| 2046 | isPreTag: NO,
|
---|
| 2047 | isIgnoreNewlineTag: NO,
|
---|
| 2048 | isCustomElement: NO,
|
---|
| 2049 | onError: defaultOnError,
|
---|
| 2050 | onWarn: defaultOnWarn,
|
---|
| 2051 | comments: true,
|
---|
| 2052 | prefixIdentifiers: false
|
---|
| 2053 | };
|
---|
| 2054 | let currentOptions = defaultParserOptions;
|
---|
| 2055 | let currentRoot = null;
|
---|
| 2056 | let currentInput = "";
|
---|
| 2057 | let currentOpenTag = null;
|
---|
| 2058 | let currentProp = null;
|
---|
| 2059 | let currentAttrValue = "";
|
---|
| 2060 | let currentAttrStartIndex = -1;
|
---|
| 2061 | let currentAttrEndIndex = -1;
|
---|
| 2062 | let inPre = 0;
|
---|
| 2063 | let inVPre = false;
|
---|
| 2064 | let currentVPreBoundary = null;
|
---|
| 2065 | const stack = [];
|
---|
| 2066 | const tokenizer = new Tokenizer(stack, {
|
---|
| 2067 | onerr: emitError,
|
---|
| 2068 | ontext(start, end) {
|
---|
| 2069 | onText(getSlice(start, end), start, end);
|
---|
| 2070 | },
|
---|
| 2071 | ontextentity(char, start, end) {
|
---|
| 2072 | onText(char, start, end);
|
---|
| 2073 | },
|
---|
| 2074 | oninterpolation(start, end) {
|
---|
| 2075 | if (inVPre) {
|
---|
| 2076 | return onText(getSlice(start, end), start, end);
|
---|
| 2077 | }
|
---|
| 2078 | let innerStart = start + tokenizer.delimiterOpen.length;
|
---|
| 2079 | let innerEnd = end - tokenizer.delimiterClose.length;
|
---|
| 2080 | while (isWhitespace(currentInput.charCodeAt(innerStart))) {
|
---|
| 2081 | innerStart++;
|
---|
| 2082 | }
|
---|
| 2083 | while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) {
|
---|
| 2084 | innerEnd--;
|
---|
| 2085 | }
|
---|
| 2086 | let exp = getSlice(innerStart, innerEnd);
|
---|
| 2087 | if (exp.includes("&")) {
|
---|
| 2088 | {
|
---|
| 2089 | exp = currentOptions.decodeEntities(exp, false);
|
---|
| 2090 | }
|
---|
| 2091 | }
|
---|
| 2092 | addNode({
|
---|
| 2093 | type: 5,
|
---|
| 2094 | content: createExp(exp, false, getLoc(innerStart, innerEnd)),
|
---|
| 2095 | loc: getLoc(start, end)
|
---|
| 2096 | });
|
---|
| 2097 | },
|
---|
| 2098 | onopentagname(start, end) {
|
---|
| 2099 | const name = getSlice(start, end);
|
---|
| 2100 | currentOpenTag = {
|
---|
| 2101 | type: 1,
|
---|
| 2102 | tag: name,
|
---|
| 2103 | ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
|
---|
| 2104 | tagType: 0,
|
---|
| 2105 | // will be refined on tag close
|
---|
| 2106 | props: [],
|
---|
| 2107 | children: [],
|
---|
| 2108 | loc: getLoc(start - 1, end),
|
---|
| 2109 | codegenNode: void 0
|
---|
| 2110 | };
|
---|
| 2111 | },
|
---|
| 2112 | onopentagend(end) {
|
---|
| 2113 | endOpenTag(end);
|
---|
| 2114 | },
|
---|
| 2115 | onclosetag(start, end) {
|
---|
| 2116 | const name = getSlice(start, end);
|
---|
| 2117 | if (!currentOptions.isVoidTag(name)) {
|
---|
| 2118 | let found = false;
|
---|
| 2119 | for (let i = 0; i < stack.length; i++) {
|
---|
| 2120 | const e = stack[i];
|
---|
| 2121 | if (e.tag.toLowerCase() === name.toLowerCase()) {
|
---|
| 2122 | found = true;
|
---|
| 2123 | if (i > 0) {
|
---|
| 2124 | emitError(24, stack[0].loc.start.offset);
|
---|
| 2125 | }
|
---|
| 2126 | for (let j = 0; j <= i; j++) {
|
---|
| 2127 | const el = stack.shift();
|
---|
| 2128 | onCloseTag(el, end, j < i);
|
---|
| 2129 | }
|
---|
| 2130 | break;
|
---|
| 2131 | }
|
---|
| 2132 | }
|
---|
| 2133 | if (!found) {
|
---|
| 2134 | emitError(23, backTrack(start, 60));
|
---|
| 2135 | }
|
---|
| 2136 | }
|
---|
| 2137 | },
|
---|
| 2138 | onselfclosingtag(end) {
|
---|
| 2139 | const name = currentOpenTag.tag;
|
---|
| 2140 | currentOpenTag.isSelfClosing = true;
|
---|
| 2141 | endOpenTag(end);
|
---|
| 2142 | if (stack[0] && stack[0].tag === name) {
|
---|
| 2143 | onCloseTag(stack.shift(), end);
|
---|
| 2144 | }
|
---|
| 2145 | },
|
---|
| 2146 | onattribname(start, end) {
|
---|
| 2147 | currentProp = {
|
---|
| 2148 | type: 6,
|
---|
| 2149 | name: getSlice(start, end),
|
---|
| 2150 | nameLoc: getLoc(start, end),
|
---|
| 2151 | value: void 0,
|
---|
| 2152 | loc: getLoc(start)
|
---|
| 2153 | };
|
---|
| 2154 | },
|
---|
| 2155 | ondirname(start, end) {
|
---|
| 2156 | const raw = getSlice(start, end);
|
---|
| 2157 | const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
|
---|
| 2158 | if (!inVPre && name === "") {
|
---|
| 2159 | emitError(26, start);
|
---|
| 2160 | }
|
---|
| 2161 | if (inVPre || name === "") {
|
---|
| 2162 | currentProp = {
|
---|
| 2163 | type: 6,
|
---|
| 2164 | name: raw,
|
---|
| 2165 | nameLoc: getLoc(start, end),
|
---|
| 2166 | value: void 0,
|
---|
| 2167 | loc: getLoc(start)
|
---|
| 2168 | };
|
---|
| 2169 | } else {
|
---|
| 2170 | currentProp = {
|
---|
| 2171 | type: 7,
|
---|
| 2172 | name,
|
---|
| 2173 | rawName: raw,
|
---|
| 2174 | exp: void 0,
|
---|
| 2175 | arg: void 0,
|
---|
| 2176 | modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
|
---|
| 2177 | loc: getLoc(start)
|
---|
| 2178 | };
|
---|
| 2179 | if (name === "pre") {
|
---|
| 2180 | inVPre = tokenizer.inVPre = true;
|
---|
| 2181 | currentVPreBoundary = currentOpenTag;
|
---|
| 2182 | const props = currentOpenTag.props;
|
---|
| 2183 | for (let i = 0; i < props.length; i++) {
|
---|
| 2184 | if (props[i].type === 7) {
|
---|
| 2185 | props[i] = dirToAttr(props[i]);
|
---|
| 2186 | }
|
---|
| 2187 | }
|
---|
| 2188 | }
|
---|
| 2189 | }
|
---|
| 2190 | },
|
---|
| 2191 | ondirarg(start, end) {
|
---|
| 2192 | if (start === end) return;
|
---|
| 2193 | const arg = getSlice(start, end);
|
---|
| 2194 | if (inVPre) {
|
---|
| 2195 | currentProp.name += arg;
|
---|
| 2196 | setLocEnd(currentProp.nameLoc, end);
|
---|
| 2197 | } else {
|
---|
| 2198 | const isStatic = arg[0] !== `[`;
|
---|
| 2199 | currentProp.arg = createExp(
|
---|
| 2200 | isStatic ? arg : arg.slice(1, -1),
|
---|
| 2201 | isStatic,
|
---|
| 2202 | getLoc(start, end),
|
---|
| 2203 | isStatic ? 3 : 0
|
---|
| 2204 | );
|
---|
| 2205 | }
|
---|
| 2206 | },
|
---|
| 2207 | ondirmodifier(start, end) {
|
---|
| 2208 | const mod = getSlice(start, end);
|
---|
| 2209 | if (inVPre) {
|
---|
| 2210 | currentProp.name += "." + mod;
|
---|
| 2211 | setLocEnd(currentProp.nameLoc, end);
|
---|
| 2212 | } else if (currentProp.name === "slot") {
|
---|
| 2213 | const arg = currentProp.arg;
|
---|
| 2214 | if (arg) {
|
---|
| 2215 | arg.content += "." + mod;
|
---|
| 2216 | setLocEnd(arg.loc, end);
|
---|
| 2217 | }
|
---|
| 2218 | } else {
|
---|
| 2219 | const exp = createSimpleExpression(mod, true, getLoc(start, end));
|
---|
| 2220 | currentProp.modifiers.push(exp);
|
---|
| 2221 | }
|
---|
| 2222 | },
|
---|
| 2223 | onattribdata(start, end) {
|
---|
| 2224 | currentAttrValue += getSlice(start, end);
|
---|
| 2225 | if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
---|
| 2226 | currentAttrEndIndex = end;
|
---|
| 2227 | },
|
---|
| 2228 | onattribentity(char, start, end) {
|
---|
| 2229 | currentAttrValue += char;
|
---|
| 2230 | if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
---|
| 2231 | currentAttrEndIndex = end;
|
---|
| 2232 | },
|
---|
| 2233 | onattribnameend(end) {
|
---|
| 2234 | const start = currentProp.loc.start.offset;
|
---|
| 2235 | const name = getSlice(start, end);
|
---|
| 2236 | if (currentProp.type === 7) {
|
---|
| 2237 | currentProp.rawName = name;
|
---|
| 2238 | }
|
---|
| 2239 | if (currentOpenTag.props.some(
|
---|
| 2240 | (p) => (p.type === 7 ? p.rawName : p.name) === name
|
---|
| 2241 | )) {
|
---|
| 2242 | emitError(2, start);
|
---|
| 2243 | }
|
---|
| 2244 | },
|
---|
| 2245 | onattribend(quote, end) {
|
---|
| 2246 | if (currentOpenTag && currentProp) {
|
---|
| 2247 | setLocEnd(currentProp.loc, end);
|
---|
| 2248 | if (quote !== 0) {
|
---|
| 2249 | if (currentAttrValue.includes("&")) {
|
---|
| 2250 | currentAttrValue = currentOptions.decodeEntities(
|
---|
| 2251 | currentAttrValue,
|
---|
| 2252 | true
|
---|
| 2253 | );
|
---|
| 2254 | }
|
---|
| 2255 | if (currentProp.type === 6) {
|
---|
| 2256 | if (currentProp.name === "class") {
|
---|
| 2257 | currentAttrValue = condense(currentAttrValue).trim();
|
---|
| 2258 | }
|
---|
| 2259 | if (quote === 1 && !currentAttrValue) {
|
---|
| 2260 | emitError(13, end);
|
---|
| 2261 | }
|
---|
| 2262 | currentProp.value = {
|
---|
| 2263 | type: 2,
|
---|
| 2264 | content: currentAttrValue,
|
---|
| 2265 | loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
|
---|
| 2266 | };
|
---|
| 2267 | if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") {
|
---|
| 2268 | tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
|
---|
| 2269 | }
|
---|
| 2270 | } else {
|
---|
| 2271 | let expParseMode = 0 /* Normal */;
|
---|
| 2272 | currentProp.exp = createExp(
|
---|
| 2273 | currentAttrValue,
|
---|
| 2274 | false,
|
---|
| 2275 | getLoc(currentAttrStartIndex, currentAttrEndIndex),
|
---|
| 2276 | 0,
|
---|
| 2277 | expParseMode
|
---|
| 2278 | );
|
---|
| 2279 | if (currentProp.name === "for") {
|
---|
| 2280 | currentProp.forParseResult = parseForExpression(currentProp.exp);
|
---|
| 2281 | }
|
---|
| 2282 | let syncIndex = -1;
|
---|
| 2283 | if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex(
|
---|
| 2284 | (mod) => mod.content === "sync"
|
---|
| 2285 | )) > -1 && checkCompatEnabled(
|
---|
| 2286 | "COMPILER_V_BIND_SYNC",
|
---|
| 2287 | currentOptions,
|
---|
| 2288 | currentProp.loc,
|
---|
| 2289 | currentProp.rawName
|
---|
| 2290 | )) {
|
---|
| 2291 | currentProp.name = "model";
|
---|
| 2292 | currentProp.modifiers.splice(syncIndex, 1);
|
---|
| 2293 | }
|
---|
| 2294 | }
|
---|
| 2295 | }
|
---|
| 2296 | if (currentProp.type !== 7 || currentProp.name !== "pre") {
|
---|
| 2297 | currentOpenTag.props.push(currentProp);
|
---|
| 2298 | }
|
---|
| 2299 | }
|
---|
| 2300 | currentAttrValue = "";
|
---|
| 2301 | currentAttrStartIndex = currentAttrEndIndex = -1;
|
---|
| 2302 | },
|
---|
| 2303 | oncomment(start, end) {
|
---|
| 2304 | if (currentOptions.comments) {
|
---|
| 2305 | addNode({
|
---|
| 2306 | type: 3,
|
---|
| 2307 | content: getSlice(start, end),
|
---|
| 2308 | loc: getLoc(start - 4, end + 3)
|
---|
| 2309 | });
|
---|
| 2310 | }
|
---|
| 2311 | },
|
---|
| 2312 | onend() {
|
---|
| 2313 | const end = currentInput.length;
|
---|
| 2314 | if (tokenizer.state !== 1) {
|
---|
| 2315 | switch (tokenizer.state) {
|
---|
| 2316 | case 5:
|
---|
| 2317 | case 8:
|
---|
| 2318 | emitError(5, end);
|
---|
| 2319 | break;
|
---|
| 2320 | case 3:
|
---|
| 2321 | case 4:
|
---|
| 2322 | emitError(
|
---|
| 2323 | 25,
|
---|
| 2324 | tokenizer.sectionStart
|
---|
| 2325 | );
|
---|
| 2326 | break;
|
---|
| 2327 | case 28:
|
---|
| 2328 | if (tokenizer.currentSequence === Sequences.CdataEnd) {
|
---|
| 2329 | emitError(6, end);
|
---|
| 2330 | } else {
|
---|
| 2331 | emitError(7, end);
|
---|
| 2332 | }
|
---|
| 2333 | break;
|
---|
| 2334 | case 6:
|
---|
| 2335 | case 7:
|
---|
| 2336 | case 9:
|
---|
| 2337 | case 11:
|
---|
| 2338 | case 12:
|
---|
| 2339 | case 13:
|
---|
| 2340 | case 14:
|
---|
| 2341 | case 15:
|
---|
| 2342 | case 16:
|
---|
| 2343 | case 17:
|
---|
| 2344 | case 18:
|
---|
| 2345 | case 19:
|
---|
| 2346 | // "
|
---|
| 2347 | case 20:
|
---|
| 2348 | // '
|
---|
| 2349 | case 21:
|
---|
| 2350 | emitError(9, end);
|
---|
| 2351 | break;
|
---|
| 2352 | }
|
---|
| 2353 | }
|
---|
| 2354 | for (let index = 0; index < stack.length; index++) {
|
---|
| 2355 | onCloseTag(stack[index], end - 1);
|
---|
| 2356 | emitError(24, stack[index].loc.start.offset);
|
---|
| 2357 | }
|
---|
| 2358 | },
|
---|
| 2359 | oncdata(start, end) {
|
---|
| 2360 | if (stack[0].ns !== 0) {
|
---|
| 2361 | onText(getSlice(start, end), start, end);
|
---|
| 2362 | } else {
|
---|
| 2363 | emitError(1, start - 9);
|
---|
| 2364 | }
|
---|
| 2365 | },
|
---|
| 2366 | onprocessinginstruction(start) {
|
---|
| 2367 | if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
|
---|
| 2368 | emitError(
|
---|
| 2369 | 21,
|
---|
| 2370 | start - 1
|
---|
| 2371 | );
|
---|
| 2372 | }
|
---|
| 2373 | }
|
---|
| 2374 | });
|
---|
| 2375 | const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
---|
| 2376 | const stripParensRE = /^\(|\)$/g;
|
---|
| 2377 | function parseForExpression(input) {
|
---|
| 2378 | const loc = input.loc;
|
---|
| 2379 | const exp = input.content;
|
---|
| 2380 | const inMatch = exp.match(forAliasRE);
|
---|
| 2381 | if (!inMatch) return;
|
---|
| 2382 | const [, LHS, RHS] = inMatch;
|
---|
| 2383 | const createAliasExpression = (content, offset, asParam = false) => {
|
---|
| 2384 | const start = loc.start.offset + offset;
|
---|
| 2385 | const end = start + content.length;
|
---|
| 2386 | return createExp(
|
---|
| 2387 | content,
|
---|
| 2388 | false,
|
---|
| 2389 | getLoc(start, end),
|
---|
| 2390 | 0,
|
---|
| 2391 | asParam ? 1 /* Params */ : 0 /* Normal */
|
---|
| 2392 | );
|
---|
| 2393 | };
|
---|
| 2394 | const result = {
|
---|
| 2395 | source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
|
---|
| 2396 | value: void 0,
|
---|
| 2397 | key: void 0,
|
---|
| 2398 | index: void 0,
|
---|
| 2399 | finalized: false
|
---|
| 2400 | };
|
---|
| 2401 | let valueContent = LHS.trim().replace(stripParensRE, "").trim();
|
---|
| 2402 | const trimmedOffset = LHS.indexOf(valueContent);
|
---|
| 2403 | const iteratorMatch = valueContent.match(forIteratorRE);
|
---|
| 2404 | if (iteratorMatch) {
|
---|
| 2405 | valueContent = valueContent.replace(forIteratorRE, "").trim();
|
---|
| 2406 | const keyContent = iteratorMatch[1].trim();
|
---|
| 2407 | let keyOffset;
|
---|
| 2408 | if (keyContent) {
|
---|
| 2409 | keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
|
---|
| 2410 | result.key = createAliasExpression(keyContent, keyOffset, true);
|
---|
| 2411 | }
|
---|
| 2412 | if (iteratorMatch[2]) {
|
---|
| 2413 | const indexContent = iteratorMatch[2].trim();
|
---|
| 2414 | if (indexContent) {
|
---|
| 2415 | result.index = createAliasExpression(
|
---|
| 2416 | indexContent,
|
---|
| 2417 | exp.indexOf(
|
---|
| 2418 | indexContent,
|
---|
| 2419 | result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length
|
---|
| 2420 | ),
|
---|
| 2421 | true
|
---|
| 2422 | );
|
---|
| 2423 | }
|
---|
| 2424 | }
|
---|
| 2425 | }
|
---|
| 2426 | if (valueContent) {
|
---|
| 2427 | result.value = createAliasExpression(valueContent, trimmedOffset, true);
|
---|
| 2428 | }
|
---|
| 2429 | return result;
|
---|
| 2430 | }
|
---|
| 2431 | function getSlice(start, end) {
|
---|
| 2432 | return currentInput.slice(start, end);
|
---|
| 2433 | }
|
---|
| 2434 | function endOpenTag(end) {
|
---|
| 2435 | if (tokenizer.inSFCRoot) {
|
---|
| 2436 | currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
|
---|
| 2437 | }
|
---|
| 2438 | addNode(currentOpenTag);
|
---|
| 2439 | const { tag, ns } = currentOpenTag;
|
---|
| 2440 | if (ns === 0 && currentOptions.isPreTag(tag)) {
|
---|
| 2441 | inPre++;
|
---|
| 2442 | }
|
---|
| 2443 | if (currentOptions.isVoidTag(tag)) {
|
---|
| 2444 | onCloseTag(currentOpenTag, end);
|
---|
| 2445 | } else {
|
---|
| 2446 | stack.unshift(currentOpenTag);
|
---|
| 2447 | if (ns === 1 || ns === 2) {
|
---|
| 2448 | tokenizer.inXML = true;
|
---|
| 2449 | }
|
---|
| 2450 | }
|
---|
| 2451 | currentOpenTag = null;
|
---|
| 2452 | }
|
---|
| 2453 | function onText(content, start, end) {
|
---|
| 2454 | {
|
---|
| 2455 | const tag = stack[0] && stack[0].tag;
|
---|
| 2456 | if (tag !== "script" && tag !== "style" && content.includes("&")) {
|
---|
| 2457 | content = currentOptions.decodeEntities(content, false);
|
---|
| 2458 | }
|
---|
| 2459 | }
|
---|
| 2460 | const parent = stack[0] || currentRoot;
|
---|
| 2461 | const lastNode = parent.children[parent.children.length - 1];
|
---|
| 2462 | if (lastNode && lastNode.type === 2) {
|
---|
| 2463 | lastNode.content += content;
|
---|
| 2464 | setLocEnd(lastNode.loc, end);
|
---|
| 2465 | } else {
|
---|
| 2466 | parent.children.push({
|
---|
| 2467 | type: 2,
|
---|
| 2468 | content,
|
---|
| 2469 | loc: getLoc(start, end)
|
---|
| 2470 | });
|
---|
| 2471 | }
|
---|
| 2472 | }
|
---|
| 2473 | function onCloseTag(el, end, isImplied = false) {
|
---|
| 2474 | if (isImplied) {
|
---|
| 2475 | setLocEnd(el.loc, backTrack(end, 60));
|
---|
| 2476 | } else {
|
---|
| 2477 | setLocEnd(el.loc, lookAhead(end, 62) + 1);
|
---|
| 2478 | }
|
---|
| 2479 | if (tokenizer.inSFCRoot) {
|
---|
| 2480 | if (el.children.length) {
|
---|
| 2481 | el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
|
---|
| 2482 | } else {
|
---|
| 2483 | el.innerLoc.end = extend({}, el.innerLoc.start);
|
---|
| 2484 | }
|
---|
| 2485 | el.innerLoc.source = getSlice(
|
---|
| 2486 | el.innerLoc.start.offset,
|
---|
| 2487 | el.innerLoc.end.offset
|
---|
| 2488 | );
|
---|
| 2489 | }
|
---|
| 2490 | const { tag, ns, children } = el;
|
---|
| 2491 | if (!inVPre) {
|
---|
| 2492 | if (tag === "slot") {
|
---|
| 2493 | el.tagType = 2;
|
---|
| 2494 | } else if (isFragmentTemplate(el)) {
|
---|
| 2495 | el.tagType = 3;
|
---|
| 2496 | } else if (isComponent(el)) {
|
---|
| 2497 | el.tagType = 1;
|
---|
| 2498 | }
|
---|
| 2499 | }
|
---|
| 2500 | if (!tokenizer.inRCDATA) {
|
---|
| 2501 | el.children = condenseWhitespace(children);
|
---|
| 2502 | }
|
---|
| 2503 | if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
|
---|
| 2504 | const first = children[0];
|
---|
| 2505 | if (first && first.type === 2) {
|
---|
| 2506 | first.content = first.content.replace(/^\r?\n/, "");
|
---|
| 2507 | }
|
---|
| 2508 | }
|
---|
| 2509 | if (ns === 0 && currentOptions.isPreTag(tag)) {
|
---|
| 2510 | inPre--;
|
---|
| 2511 | }
|
---|
| 2512 | if (currentVPreBoundary === el) {
|
---|
| 2513 | inVPre = tokenizer.inVPre = false;
|
---|
| 2514 | currentVPreBoundary = null;
|
---|
| 2515 | }
|
---|
| 2516 | if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) {
|
---|
| 2517 | tokenizer.inXML = false;
|
---|
| 2518 | }
|
---|
| 2519 | {
|
---|
| 2520 | const props = el.props;
|
---|
| 2521 | if (isCompatEnabled(
|
---|
| 2522 | "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
---|
| 2523 | currentOptions
|
---|
| 2524 | )) {
|
---|
| 2525 | let hasIf = false;
|
---|
| 2526 | let hasFor = false;
|
---|
| 2527 | for (let i = 0; i < props.length; i++) {
|
---|
| 2528 | const p = props[i];
|
---|
| 2529 | if (p.type === 7) {
|
---|
| 2530 | if (p.name === "if") {
|
---|
| 2531 | hasIf = true;
|
---|
| 2532 | } else if (p.name === "for") {
|
---|
| 2533 | hasFor = true;
|
---|
| 2534 | }
|
---|
| 2535 | }
|
---|
| 2536 | if (hasIf && hasFor) {
|
---|
| 2537 | warnDeprecation(
|
---|
| 2538 | "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
---|
| 2539 | currentOptions,
|
---|
| 2540 | el.loc
|
---|
| 2541 | );
|
---|
| 2542 | break;
|
---|
| 2543 | }
|
---|
| 2544 | }
|
---|
| 2545 | }
|
---|
| 2546 | if (!tokenizer.inSFCRoot && isCompatEnabled(
|
---|
| 2547 | "COMPILER_NATIVE_TEMPLATE",
|
---|
| 2548 | currentOptions
|
---|
| 2549 | ) && el.tag === "template" && !isFragmentTemplate(el)) {
|
---|
| 2550 | warnDeprecation(
|
---|
| 2551 | "COMPILER_NATIVE_TEMPLATE",
|
---|
| 2552 | currentOptions,
|
---|
| 2553 | el.loc
|
---|
| 2554 | );
|
---|
| 2555 | const parent = stack[0] || currentRoot;
|
---|
| 2556 | const index = parent.children.indexOf(el);
|
---|
| 2557 | parent.children.splice(index, 1, ...el.children);
|
---|
| 2558 | }
|
---|
| 2559 | const inlineTemplateProp = props.find(
|
---|
| 2560 | (p) => p.type === 6 && p.name === "inline-template"
|
---|
| 2561 | );
|
---|
| 2562 | if (inlineTemplateProp && checkCompatEnabled(
|
---|
| 2563 | "COMPILER_INLINE_TEMPLATE",
|
---|
| 2564 | currentOptions,
|
---|
| 2565 | inlineTemplateProp.loc
|
---|
| 2566 | ) && el.children.length) {
|
---|
| 2567 | inlineTemplateProp.value = {
|
---|
| 2568 | type: 2,
|
---|
| 2569 | content: getSlice(
|
---|
| 2570 | el.children[0].loc.start.offset,
|
---|
| 2571 | el.children[el.children.length - 1].loc.end.offset
|
---|
| 2572 | ),
|
---|
| 2573 | loc: inlineTemplateProp.loc
|
---|
| 2574 | };
|
---|
| 2575 | }
|
---|
| 2576 | }
|
---|
| 2577 | }
|
---|
| 2578 | function lookAhead(index, c) {
|
---|
| 2579 | let i = index;
|
---|
| 2580 | while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
|
---|
| 2581 | return i;
|
---|
| 2582 | }
|
---|
| 2583 | function backTrack(index, c) {
|
---|
| 2584 | let i = index;
|
---|
| 2585 | while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
|
---|
| 2586 | return i;
|
---|
| 2587 | }
|
---|
| 2588 | const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
|
---|
| 2589 | function isFragmentTemplate({ tag, props }) {
|
---|
| 2590 | if (tag === "template") {
|
---|
| 2591 | for (let i = 0; i < props.length; i++) {
|
---|
| 2592 | if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) {
|
---|
| 2593 | return true;
|
---|
| 2594 | }
|
---|
| 2595 | }
|
---|
| 2596 | }
|
---|
| 2597 | return false;
|
---|
| 2598 | }
|
---|
| 2599 | function isComponent({ tag, props }) {
|
---|
| 2600 | if (currentOptions.isCustomElement(tag)) {
|
---|
| 2601 | return false;
|
---|
| 2602 | }
|
---|
| 2603 | if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
|
---|
| 2604 | return true;
|
---|
| 2605 | }
|
---|
| 2606 | for (let i = 0; i < props.length; i++) {
|
---|
| 2607 | const p = props[i];
|
---|
| 2608 | if (p.type === 6) {
|
---|
| 2609 | if (p.name === "is" && p.value) {
|
---|
| 2610 | if (p.value.content.startsWith("vue:")) {
|
---|
| 2611 | return true;
|
---|
| 2612 | } else if (checkCompatEnabled(
|
---|
| 2613 | "COMPILER_IS_ON_ELEMENT",
|
---|
| 2614 | currentOptions,
|
---|
| 2615 | p.loc
|
---|
| 2616 | )) {
|
---|
| 2617 | return true;
|
---|
| 2618 | }
|
---|
| 2619 | }
|
---|
| 2620 | } else if (// :is on plain element - only treat as component in compat mode
|
---|
| 2621 | p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled(
|
---|
| 2622 | "COMPILER_IS_ON_ELEMENT",
|
---|
| 2623 | currentOptions,
|
---|
| 2624 | p.loc
|
---|
| 2625 | )) {
|
---|
| 2626 | return true;
|
---|
| 2627 | }
|
---|
| 2628 | }
|
---|
| 2629 | return false;
|
---|
| 2630 | }
|
---|
| 2631 | function isUpperCase(c) {
|
---|
| 2632 | return c > 64 && c < 91;
|
---|
| 2633 | }
|
---|
| 2634 | const windowsNewlineRE = /\r\n/g;
|
---|
| 2635 | function condenseWhitespace(nodes, tag) {
|
---|
| 2636 | const shouldCondense = currentOptions.whitespace !== "preserve";
|
---|
| 2637 | let removedWhitespace = false;
|
---|
| 2638 | for (let i = 0; i < nodes.length; i++) {
|
---|
| 2639 | const node = nodes[i];
|
---|
| 2640 | if (node.type === 2) {
|
---|
| 2641 | if (!inPre) {
|
---|
| 2642 | if (isAllWhitespace(node.content)) {
|
---|
| 2643 | const prev = nodes[i - 1] && nodes[i - 1].type;
|
---|
| 2644 | const next = nodes[i + 1] && nodes[i + 1].type;
|
---|
| 2645 | if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
|
---|
| 2646 | removedWhitespace = true;
|
---|
| 2647 | nodes[i] = null;
|
---|
| 2648 | } else {
|
---|
| 2649 | node.content = " ";
|
---|
| 2650 | }
|
---|
| 2651 | } else if (shouldCondense) {
|
---|
| 2652 | node.content = condense(node.content);
|
---|
| 2653 | }
|
---|
| 2654 | } else {
|
---|
| 2655 | node.content = node.content.replace(windowsNewlineRE, "\n");
|
---|
| 2656 | }
|
---|
| 2657 | }
|
---|
| 2658 | }
|
---|
| 2659 | return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
---|
| 2660 | }
|
---|
| 2661 | function isAllWhitespace(str) {
|
---|
| 2662 | for (let i = 0; i < str.length; i++) {
|
---|
| 2663 | if (!isWhitespace(str.charCodeAt(i))) {
|
---|
| 2664 | return false;
|
---|
| 2665 | }
|
---|
| 2666 | }
|
---|
| 2667 | return true;
|
---|
| 2668 | }
|
---|
| 2669 | function hasNewlineChar(str) {
|
---|
| 2670 | for (let i = 0; i < str.length; i++) {
|
---|
| 2671 | const c = str.charCodeAt(i);
|
---|
| 2672 | if (c === 10 || c === 13) {
|
---|
| 2673 | return true;
|
---|
| 2674 | }
|
---|
| 2675 | }
|
---|
| 2676 | return false;
|
---|
| 2677 | }
|
---|
| 2678 | function condense(str) {
|
---|
| 2679 | let ret = "";
|
---|
| 2680 | let prevCharIsWhitespace = false;
|
---|
| 2681 | for (let i = 0; i < str.length; i++) {
|
---|
| 2682 | if (isWhitespace(str.charCodeAt(i))) {
|
---|
| 2683 | if (!prevCharIsWhitespace) {
|
---|
| 2684 | ret += " ";
|
---|
| 2685 | prevCharIsWhitespace = true;
|
---|
| 2686 | }
|
---|
| 2687 | } else {
|
---|
| 2688 | ret += str[i];
|
---|
| 2689 | prevCharIsWhitespace = false;
|
---|
| 2690 | }
|
---|
| 2691 | }
|
---|
| 2692 | return ret;
|
---|
| 2693 | }
|
---|
| 2694 | function addNode(node) {
|
---|
| 2695 | (stack[0] || currentRoot).children.push(node);
|
---|
| 2696 | }
|
---|
| 2697 | function getLoc(start, end) {
|
---|
| 2698 | return {
|
---|
| 2699 | start: tokenizer.getPos(start),
|
---|
| 2700 | // @ts-expect-error allow late attachment
|
---|
| 2701 | end: end == null ? end : tokenizer.getPos(end),
|
---|
| 2702 | // @ts-expect-error allow late attachment
|
---|
| 2703 | source: end == null ? end : getSlice(start, end)
|
---|
| 2704 | };
|
---|
| 2705 | }
|
---|
| 2706 | function cloneLoc(loc) {
|
---|
| 2707 | return getLoc(loc.start.offset, loc.end.offset);
|
---|
| 2708 | }
|
---|
| 2709 | function setLocEnd(loc, end) {
|
---|
| 2710 | loc.end = tokenizer.getPos(end);
|
---|
| 2711 | loc.source = getSlice(loc.start.offset, end);
|
---|
| 2712 | }
|
---|
| 2713 | function dirToAttr(dir) {
|
---|
| 2714 | const attr = {
|
---|
| 2715 | type: 6,
|
---|
| 2716 | name: dir.rawName,
|
---|
| 2717 | nameLoc: getLoc(
|
---|
| 2718 | dir.loc.start.offset,
|
---|
| 2719 | dir.loc.start.offset + dir.rawName.length
|
---|
| 2720 | ),
|
---|
| 2721 | value: void 0,
|
---|
| 2722 | loc: dir.loc
|
---|
| 2723 | };
|
---|
| 2724 | if (dir.exp) {
|
---|
| 2725 | const loc = dir.exp.loc;
|
---|
| 2726 | if (loc.end.offset < dir.loc.end.offset) {
|
---|
| 2727 | loc.start.offset--;
|
---|
| 2728 | loc.start.column--;
|
---|
| 2729 | loc.end.offset++;
|
---|
| 2730 | loc.end.column++;
|
---|
| 2731 | }
|
---|
| 2732 | attr.value = {
|
---|
| 2733 | type: 2,
|
---|
| 2734 | content: dir.exp.content,
|
---|
| 2735 | loc
|
---|
| 2736 | };
|
---|
| 2737 | }
|
---|
| 2738 | return attr;
|
---|
| 2739 | }
|
---|
| 2740 | function createExp(content, isStatic = false, loc, constType = 0, parseMode = 0 /* Normal */) {
|
---|
| 2741 | const exp = createSimpleExpression(content, isStatic, loc, constType);
|
---|
| 2742 | return exp;
|
---|
| 2743 | }
|
---|
| 2744 | function emitError(code, index, message) {
|
---|
| 2745 | currentOptions.onError(
|
---|
| 2746 | createCompilerError(code, getLoc(index, index), void 0, message)
|
---|
| 2747 | );
|
---|
| 2748 | }
|
---|
| 2749 | function reset() {
|
---|
| 2750 | tokenizer.reset();
|
---|
| 2751 | currentOpenTag = null;
|
---|
| 2752 | currentProp = null;
|
---|
| 2753 | currentAttrValue = "";
|
---|
| 2754 | currentAttrStartIndex = -1;
|
---|
| 2755 | currentAttrEndIndex = -1;
|
---|
| 2756 | stack.length = 0;
|
---|
| 2757 | }
|
---|
| 2758 | function baseParse(input, options) {
|
---|
| 2759 | reset();
|
---|
| 2760 | currentInput = input;
|
---|
| 2761 | currentOptions = extend({}, defaultParserOptions);
|
---|
| 2762 | if (options) {
|
---|
| 2763 | let key;
|
---|
| 2764 | for (key in options) {
|
---|
| 2765 | if (options[key] != null) {
|
---|
| 2766 | currentOptions[key] = options[key];
|
---|
| 2767 | }
|
---|
| 2768 | }
|
---|
| 2769 | }
|
---|
| 2770 | {
|
---|
| 2771 | if (!currentOptions.decodeEntities) {
|
---|
| 2772 | throw new Error(
|
---|
| 2773 | `[@vue/compiler-core] decodeEntities option is required in browser builds.`
|
---|
| 2774 | );
|
---|
| 2775 | }
|
---|
| 2776 | }
|
---|
| 2777 | tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
|
---|
| 2778 | tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
|
---|
| 2779 | const delimiters = options && options.delimiters;
|
---|
| 2780 | if (delimiters) {
|
---|
| 2781 | tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
|
---|
| 2782 | tokenizer.delimiterClose = toCharCodes(delimiters[1]);
|
---|
| 2783 | }
|
---|
| 2784 | const root = currentRoot = createRoot([], input);
|
---|
| 2785 | tokenizer.parse(currentInput);
|
---|
| 2786 | root.loc = getLoc(0, input.length);
|
---|
| 2787 | root.children = condenseWhitespace(root.children);
|
---|
| 2788 | currentRoot = null;
|
---|
| 2789 | return root;
|
---|
| 2790 | }
|
---|
| 2791 |
|
---|
| 2792 | function cacheStatic(root, context) {
|
---|
| 2793 | walk(
|
---|
| 2794 | root,
|
---|
| 2795 | void 0,
|
---|
| 2796 | context,
|
---|
| 2797 | // Root node is unfortunately non-hoistable due to potential parent
|
---|
| 2798 | // fallthrough attributes.
|
---|
| 2799 | isSingleElementRoot(root, root.children[0])
|
---|
| 2800 | );
|
---|
| 2801 | }
|
---|
| 2802 | function isSingleElementRoot(root, child) {
|
---|
| 2803 | const { children } = root;
|
---|
| 2804 | return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
|
---|
| 2805 | }
|
---|
| 2806 | function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
---|
| 2807 | const { children } = node;
|
---|
| 2808 | const toCache = [];
|
---|
| 2809 | for (let i = 0; i < children.length; i++) {
|
---|
| 2810 | const child = children[i];
|
---|
| 2811 | if (child.type === 1 && child.tagType === 0) {
|
---|
| 2812 | const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
---|
| 2813 | if (constantType > 0) {
|
---|
| 2814 | if (constantType >= 2) {
|
---|
| 2815 | child.codegenNode.patchFlag = -1;
|
---|
| 2816 | toCache.push(child);
|
---|
| 2817 | continue;
|
---|
| 2818 | }
|
---|
| 2819 | } else {
|
---|
| 2820 | const codegenNode = child.codegenNode;
|
---|
| 2821 | if (codegenNode.type === 13) {
|
---|
| 2822 | const flag = codegenNode.patchFlag;
|
---|
| 2823 | if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
---|
| 2824 | const props = getNodeProps(child);
|
---|
| 2825 | if (props) {
|
---|
| 2826 | codegenNode.props = context.hoist(props);
|
---|
| 2827 | }
|
---|
| 2828 | }
|
---|
| 2829 | if (codegenNode.dynamicProps) {
|
---|
| 2830 | codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
|
---|
| 2831 | }
|
---|
| 2832 | }
|
---|
| 2833 | }
|
---|
| 2834 | } else if (child.type === 12) {
|
---|
| 2835 | const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
---|
| 2836 | if (constantType >= 2) {
|
---|
| 2837 | toCache.push(child);
|
---|
| 2838 | continue;
|
---|
| 2839 | }
|
---|
| 2840 | }
|
---|
| 2841 | if (child.type === 1) {
|
---|
| 2842 | const isComponent = child.tagType === 1;
|
---|
| 2843 | if (isComponent) {
|
---|
| 2844 | context.scopes.vSlot++;
|
---|
| 2845 | }
|
---|
| 2846 | walk(child, node, context, false, inFor);
|
---|
| 2847 | if (isComponent) {
|
---|
| 2848 | context.scopes.vSlot--;
|
---|
| 2849 | }
|
---|
| 2850 | } else if (child.type === 11) {
|
---|
| 2851 | walk(child, node, context, child.children.length === 1, true);
|
---|
| 2852 | } else if (child.type === 9) {
|
---|
| 2853 | for (let i2 = 0; i2 < child.branches.length; i2++) {
|
---|
| 2854 | walk(
|
---|
| 2855 | child.branches[i2],
|
---|
| 2856 | node,
|
---|
| 2857 | context,
|
---|
| 2858 | child.branches[i2].children.length === 1,
|
---|
| 2859 | inFor
|
---|
| 2860 | );
|
---|
| 2861 | }
|
---|
| 2862 | }
|
---|
| 2863 | }
|
---|
| 2864 | let cachedAsArray = false;
|
---|
| 2865 | if (toCache.length === children.length && node.type === 1) {
|
---|
| 2866 | if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
|
---|
| 2867 | node.codegenNode.children = getCacheExpression(
|
---|
| 2868 | createArrayExpression(node.codegenNode.children)
|
---|
| 2869 | );
|
---|
| 2870 | cachedAsArray = true;
|
---|
| 2871 | } else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
---|
| 2872 | const slot = getSlotNode(node.codegenNode, "default");
|
---|
| 2873 | if (slot) {
|
---|
| 2874 | slot.returns = getCacheExpression(
|
---|
| 2875 | createArrayExpression(slot.returns)
|
---|
| 2876 | );
|
---|
| 2877 | cachedAsArray = true;
|
---|
| 2878 | }
|
---|
| 2879 | } else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
|
---|
| 2880 | const slotName = findDir(node, "slot", true);
|
---|
| 2881 | const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
|
---|
| 2882 | if (slot) {
|
---|
| 2883 | slot.returns = getCacheExpression(
|
---|
| 2884 | createArrayExpression(slot.returns)
|
---|
| 2885 | );
|
---|
| 2886 | cachedAsArray = true;
|
---|
| 2887 | }
|
---|
| 2888 | }
|
---|
| 2889 | }
|
---|
| 2890 | if (!cachedAsArray) {
|
---|
| 2891 | for (const child of toCache) {
|
---|
| 2892 | child.codegenNode = context.cache(child.codegenNode);
|
---|
| 2893 | }
|
---|
| 2894 | }
|
---|
| 2895 | function getCacheExpression(value) {
|
---|
| 2896 | const exp = context.cache(value);
|
---|
| 2897 | if (inFor && context.hmr) {
|
---|
| 2898 | exp.needArraySpread = true;
|
---|
| 2899 | }
|
---|
| 2900 | return exp;
|
---|
| 2901 | }
|
---|
| 2902 | function getSlotNode(node2, name) {
|
---|
| 2903 | if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
|
---|
| 2904 | const slot = node2.children.properties.find(
|
---|
| 2905 | (p) => p.key === name || p.key.content === name
|
---|
| 2906 | );
|
---|
| 2907 | return slot && slot.value;
|
---|
| 2908 | }
|
---|
| 2909 | }
|
---|
| 2910 | if (toCache.length && context.transformHoist) {
|
---|
| 2911 | context.transformHoist(children, context, node);
|
---|
| 2912 | }
|
---|
| 2913 | }
|
---|
| 2914 | function getConstantType(node, context) {
|
---|
| 2915 | const { constantCache } = context;
|
---|
| 2916 | switch (node.type) {
|
---|
| 2917 | case 1:
|
---|
| 2918 | if (node.tagType !== 0) {
|
---|
| 2919 | return 0;
|
---|
| 2920 | }
|
---|
| 2921 | const cached = constantCache.get(node);
|
---|
| 2922 | if (cached !== void 0) {
|
---|
| 2923 | return cached;
|
---|
| 2924 | }
|
---|
| 2925 | const codegenNode = node.codegenNode;
|
---|
| 2926 | if (codegenNode.type !== 13) {
|
---|
| 2927 | return 0;
|
---|
| 2928 | }
|
---|
| 2929 | if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
|
---|
| 2930 | return 0;
|
---|
| 2931 | }
|
---|
| 2932 | if (codegenNode.patchFlag === void 0) {
|
---|
| 2933 | let returnType2 = 3;
|
---|
| 2934 | const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
---|
| 2935 | if (generatedPropsType === 0) {
|
---|
| 2936 | constantCache.set(node, 0);
|
---|
| 2937 | return 0;
|
---|
| 2938 | }
|
---|
| 2939 | if (generatedPropsType < returnType2) {
|
---|
| 2940 | returnType2 = generatedPropsType;
|
---|
| 2941 | }
|
---|
| 2942 | for (let i = 0; i < node.children.length; i++) {
|
---|
| 2943 | const childType = getConstantType(node.children[i], context);
|
---|
| 2944 | if (childType === 0) {
|
---|
| 2945 | constantCache.set(node, 0);
|
---|
| 2946 | return 0;
|
---|
| 2947 | }
|
---|
| 2948 | if (childType < returnType2) {
|
---|
| 2949 | returnType2 = childType;
|
---|
| 2950 | }
|
---|
| 2951 | }
|
---|
| 2952 | if (returnType2 > 1) {
|
---|
| 2953 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 2954 | const p = node.props[i];
|
---|
| 2955 | if (p.type === 7 && p.name === "bind" && p.exp) {
|
---|
| 2956 | const expType = getConstantType(p.exp, context);
|
---|
| 2957 | if (expType === 0) {
|
---|
| 2958 | constantCache.set(node, 0);
|
---|
| 2959 | return 0;
|
---|
| 2960 | }
|
---|
| 2961 | if (expType < returnType2) {
|
---|
| 2962 | returnType2 = expType;
|
---|
| 2963 | }
|
---|
| 2964 | }
|
---|
| 2965 | }
|
---|
| 2966 | }
|
---|
| 2967 | if (codegenNode.isBlock) {
|
---|
| 2968 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 2969 | const p = node.props[i];
|
---|
| 2970 | if (p.type === 7) {
|
---|
| 2971 | constantCache.set(node, 0);
|
---|
| 2972 | return 0;
|
---|
| 2973 | }
|
---|
| 2974 | }
|
---|
| 2975 | context.removeHelper(OPEN_BLOCK);
|
---|
| 2976 | context.removeHelper(
|
---|
| 2977 | getVNodeBlockHelper(context.inSSR, codegenNode.isComponent)
|
---|
| 2978 | );
|
---|
| 2979 | codegenNode.isBlock = false;
|
---|
| 2980 | context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
|
---|
| 2981 | }
|
---|
| 2982 | constantCache.set(node, returnType2);
|
---|
| 2983 | return returnType2;
|
---|
| 2984 | } else {
|
---|
| 2985 | constantCache.set(node, 0);
|
---|
| 2986 | return 0;
|
---|
| 2987 | }
|
---|
| 2988 | case 2:
|
---|
| 2989 | case 3:
|
---|
| 2990 | return 3;
|
---|
| 2991 | case 9:
|
---|
| 2992 | case 11:
|
---|
| 2993 | case 10:
|
---|
| 2994 | return 0;
|
---|
| 2995 | case 5:
|
---|
| 2996 | case 12:
|
---|
| 2997 | return getConstantType(node.content, context);
|
---|
| 2998 | case 4:
|
---|
| 2999 | return node.constType;
|
---|
| 3000 | case 8:
|
---|
| 3001 | let returnType = 3;
|
---|
| 3002 | for (let i = 0; i < node.children.length; i++) {
|
---|
| 3003 | const child = node.children[i];
|
---|
| 3004 | if (isString(child) || isSymbol(child)) {
|
---|
| 3005 | continue;
|
---|
| 3006 | }
|
---|
| 3007 | const childType = getConstantType(child, context);
|
---|
| 3008 | if (childType === 0) {
|
---|
| 3009 | return 0;
|
---|
| 3010 | } else if (childType < returnType) {
|
---|
| 3011 | returnType = childType;
|
---|
| 3012 | }
|
---|
| 3013 | }
|
---|
| 3014 | return returnType;
|
---|
| 3015 | case 20:
|
---|
| 3016 | return 2;
|
---|
| 3017 | default:
|
---|
| 3018 | return 0;
|
---|
| 3019 | }
|
---|
| 3020 | }
|
---|
| 3021 | const allowHoistedHelperSet = /* @__PURE__ */ new Set([
|
---|
| 3022 | NORMALIZE_CLASS,
|
---|
| 3023 | NORMALIZE_STYLE,
|
---|
| 3024 | NORMALIZE_PROPS,
|
---|
| 3025 | GUARD_REACTIVE_PROPS
|
---|
| 3026 | ]);
|
---|
| 3027 | function getConstantTypeOfHelperCall(value, context) {
|
---|
| 3028 | if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
|
---|
| 3029 | const arg = value.arguments[0];
|
---|
| 3030 | if (arg.type === 4) {
|
---|
| 3031 | return getConstantType(arg, context);
|
---|
| 3032 | } else if (arg.type === 14) {
|
---|
| 3033 | return getConstantTypeOfHelperCall(arg, context);
|
---|
| 3034 | }
|
---|
| 3035 | }
|
---|
| 3036 | return 0;
|
---|
| 3037 | }
|
---|
| 3038 | function getGeneratedPropsConstantType(node, context) {
|
---|
| 3039 | let returnType = 3;
|
---|
| 3040 | const props = getNodeProps(node);
|
---|
| 3041 | if (props && props.type === 15) {
|
---|
| 3042 | const { properties } = props;
|
---|
| 3043 | for (let i = 0; i < properties.length; i++) {
|
---|
| 3044 | const { key, value } = properties[i];
|
---|
| 3045 | const keyType = getConstantType(key, context);
|
---|
| 3046 | if (keyType === 0) {
|
---|
| 3047 | return keyType;
|
---|
| 3048 | }
|
---|
| 3049 | if (keyType < returnType) {
|
---|
| 3050 | returnType = keyType;
|
---|
| 3051 | }
|
---|
| 3052 | let valueType;
|
---|
| 3053 | if (value.type === 4) {
|
---|
| 3054 | valueType = getConstantType(value, context);
|
---|
| 3055 | } else if (value.type === 14) {
|
---|
| 3056 | valueType = getConstantTypeOfHelperCall(value, context);
|
---|
| 3057 | } else {
|
---|
| 3058 | valueType = 0;
|
---|
| 3059 | }
|
---|
| 3060 | if (valueType === 0) {
|
---|
| 3061 | return valueType;
|
---|
| 3062 | }
|
---|
| 3063 | if (valueType < returnType) {
|
---|
| 3064 | returnType = valueType;
|
---|
| 3065 | }
|
---|
| 3066 | }
|
---|
| 3067 | }
|
---|
| 3068 | return returnType;
|
---|
| 3069 | }
|
---|
| 3070 | function getNodeProps(node) {
|
---|
| 3071 | const codegenNode = node.codegenNode;
|
---|
| 3072 | if (codegenNode.type === 13) {
|
---|
| 3073 | return codegenNode.props;
|
---|
| 3074 | }
|
---|
| 3075 | }
|
---|
| 3076 |
|
---|
| 3077 | function createTransformContext(root, {
|
---|
| 3078 | filename = "",
|
---|
| 3079 | prefixIdentifiers = false,
|
---|
| 3080 | hoistStatic = false,
|
---|
| 3081 | hmr = false,
|
---|
| 3082 | cacheHandlers = false,
|
---|
| 3083 | nodeTransforms = [],
|
---|
| 3084 | directiveTransforms = {},
|
---|
| 3085 | transformHoist = null,
|
---|
| 3086 | isBuiltInComponent = NOOP,
|
---|
| 3087 | isCustomElement = NOOP,
|
---|
| 3088 | expressionPlugins = [],
|
---|
| 3089 | scopeId = null,
|
---|
| 3090 | slotted = true,
|
---|
| 3091 | ssr = false,
|
---|
| 3092 | inSSR = false,
|
---|
| 3093 | ssrCssVars = ``,
|
---|
| 3094 | bindingMetadata = EMPTY_OBJ,
|
---|
| 3095 | inline = false,
|
---|
| 3096 | isTS = false,
|
---|
| 3097 | onError = defaultOnError,
|
---|
| 3098 | onWarn = defaultOnWarn,
|
---|
| 3099 | compatConfig
|
---|
| 3100 | }) {
|
---|
| 3101 | const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
---|
| 3102 | const context = {
|
---|
| 3103 | // options
|
---|
| 3104 | filename,
|
---|
| 3105 | selfName: nameMatch && capitalize(camelize(nameMatch[1])),
|
---|
| 3106 | prefixIdentifiers,
|
---|
| 3107 | hoistStatic,
|
---|
| 3108 | hmr,
|
---|
| 3109 | cacheHandlers,
|
---|
| 3110 | nodeTransforms,
|
---|
| 3111 | directiveTransforms,
|
---|
| 3112 | transformHoist,
|
---|
| 3113 | isBuiltInComponent,
|
---|
| 3114 | isCustomElement,
|
---|
| 3115 | expressionPlugins,
|
---|
| 3116 | scopeId,
|
---|
| 3117 | slotted,
|
---|
| 3118 | ssr,
|
---|
| 3119 | inSSR,
|
---|
| 3120 | ssrCssVars,
|
---|
| 3121 | bindingMetadata,
|
---|
| 3122 | inline,
|
---|
| 3123 | isTS,
|
---|
| 3124 | onError,
|
---|
| 3125 | onWarn,
|
---|
| 3126 | compatConfig,
|
---|
| 3127 | // state
|
---|
| 3128 | root,
|
---|
| 3129 | helpers: /* @__PURE__ */ new Map(),
|
---|
| 3130 | components: /* @__PURE__ */ new Set(),
|
---|
| 3131 | directives: /* @__PURE__ */ new Set(),
|
---|
| 3132 | hoists: [],
|
---|
| 3133 | imports: [],
|
---|
| 3134 | cached: [],
|
---|
| 3135 | constantCache: /* @__PURE__ */ new WeakMap(),
|
---|
| 3136 | temps: 0,
|
---|
| 3137 | identifiers: /* @__PURE__ */ Object.create(null),
|
---|
| 3138 | scopes: {
|
---|
| 3139 | vFor: 0,
|
---|
| 3140 | vSlot: 0,
|
---|
| 3141 | vPre: 0,
|
---|
| 3142 | vOnce: 0
|
---|
| 3143 | },
|
---|
| 3144 | parent: null,
|
---|
| 3145 | grandParent: null,
|
---|
| 3146 | currentNode: root,
|
---|
| 3147 | childIndex: 0,
|
---|
| 3148 | inVOnce: false,
|
---|
| 3149 | // methods
|
---|
| 3150 | helper(name) {
|
---|
| 3151 | const count = context.helpers.get(name) || 0;
|
---|
| 3152 | context.helpers.set(name, count + 1);
|
---|
| 3153 | return name;
|
---|
| 3154 | },
|
---|
| 3155 | removeHelper(name) {
|
---|
| 3156 | const count = context.helpers.get(name);
|
---|
| 3157 | if (count) {
|
---|
| 3158 | const currentCount = count - 1;
|
---|
| 3159 | if (!currentCount) {
|
---|
| 3160 | context.helpers.delete(name);
|
---|
| 3161 | } else {
|
---|
| 3162 | context.helpers.set(name, currentCount);
|
---|
| 3163 | }
|
---|
| 3164 | }
|
---|
| 3165 | },
|
---|
| 3166 | helperString(name) {
|
---|
| 3167 | return `_${helperNameMap[context.helper(name)]}`;
|
---|
| 3168 | },
|
---|
| 3169 | replaceNode(node) {
|
---|
| 3170 | {
|
---|
| 3171 | if (!context.currentNode) {
|
---|
| 3172 | throw new Error(`Node being replaced is already removed.`);
|
---|
| 3173 | }
|
---|
| 3174 | if (!context.parent) {
|
---|
| 3175 | throw new Error(`Cannot replace root node.`);
|
---|
| 3176 | }
|
---|
| 3177 | }
|
---|
| 3178 | context.parent.children[context.childIndex] = context.currentNode = node;
|
---|
| 3179 | },
|
---|
| 3180 | removeNode(node) {
|
---|
| 3181 | if (!context.parent) {
|
---|
| 3182 | throw new Error(`Cannot remove root node.`);
|
---|
| 3183 | }
|
---|
| 3184 | const list = context.parent.children;
|
---|
| 3185 | const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
|
---|
| 3186 | if (removalIndex < 0) {
|
---|
| 3187 | throw new Error(`node being removed is not a child of current parent`);
|
---|
| 3188 | }
|
---|
| 3189 | if (!node || node === context.currentNode) {
|
---|
| 3190 | context.currentNode = null;
|
---|
| 3191 | context.onNodeRemoved();
|
---|
| 3192 | } else {
|
---|
| 3193 | if (context.childIndex > removalIndex) {
|
---|
| 3194 | context.childIndex--;
|
---|
| 3195 | context.onNodeRemoved();
|
---|
| 3196 | }
|
---|
| 3197 | }
|
---|
| 3198 | context.parent.children.splice(removalIndex, 1);
|
---|
| 3199 | },
|
---|
| 3200 | onNodeRemoved: NOOP,
|
---|
| 3201 | addIdentifiers(exp) {
|
---|
| 3202 | },
|
---|
| 3203 | removeIdentifiers(exp) {
|
---|
| 3204 | },
|
---|
| 3205 | hoist(exp) {
|
---|
| 3206 | if (isString(exp)) exp = createSimpleExpression(exp);
|
---|
| 3207 | context.hoists.push(exp);
|
---|
| 3208 | const identifier = createSimpleExpression(
|
---|
| 3209 | `_hoisted_${context.hoists.length}`,
|
---|
| 3210 | false,
|
---|
| 3211 | exp.loc,
|
---|
| 3212 | 2
|
---|
| 3213 | );
|
---|
| 3214 | identifier.hoisted = exp;
|
---|
| 3215 | return identifier;
|
---|
| 3216 | },
|
---|
| 3217 | cache(exp, isVNode = false, inVOnce = false) {
|
---|
| 3218 | const cacheExp = createCacheExpression(
|
---|
| 3219 | context.cached.length,
|
---|
| 3220 | exp,
|
---|
| 3221 | isVNode,
|
---|
| 3222 | inVOnce
|
---|
| 3223 | );
|
---|
| 3224 | context.cached.push(cacheExp);
|
---|
| 3225 | return cacheExp;
|
---|
| 3226 | }
|
---|
| 3227 | };
|
---|
| 3228 | {
|
---|
| 3229 | context.filters = /* @__PURE__ */ new Set();
|
---|
| 3230 | }
|
---|
| 3231 | return context;
|
---|
| 3232 | }
|
---|
| 3233 | function transform(root, options) {
|
---|
| 3234 | const context = createTransformContext(root, options);
|
---|
| 3235 | traverseNode(root, context);
|
---|
| 3236 | if (options.hoistStatic) {
|
---|
| 3237 | cacheStatic(root, context);
|
---|
| 3238 | }
|
---|
| 3239 | if (!options.ssr) {
|
---|
| 3240 | createRootCodegen(root, context);
|
---|
| 3241 | }
|
---|
| 3242 | root.helpers = /* @__PURE__ */ new Set([...context.helpers.keys()]);
|
---|
| 3243 | root.components = [...context.components];
|
---|
| 3244 | root.directives = [...context.directives];
|
---|
| 3245 | root.imports = context.imports;
|
---|
| 3246 | root.hoists = context.hoists;
|
---|
| 3247 | root.temps = context.temps;
|
---|
| 3248 | root.cached = context.cached;
|
---|
| 3249 | root.transformed = true;
|
---|
| 3250 | {
|
---|
| 3251 | root.filters = [...context.filters];
|
---|
| 3252 | }
|
---|
| 3253 | }
|
---|
| 3254 | function createRootCodegen(root, context) {
|
---|
| 3255 | const { helper } = context;
|
---|
| 3256 | const { children } = root;
|
---|
| 3257 | if (children.length === 1) {
|
---|
| 3258 | const child = children[0];
|
---|
| 3259 | if (isSingleElementRoot(root, child) && child.codegenNode) {
|
---|
| 3260 | const codegenNode = child.codegenNode;
|
---|
| 3261 | if (codegenNode.type === 13) {
|
---|
| 3262 | convertToBlock(codegenNode, context);
|
---|
| 3263 | }
|
---|
| 3264 | root.codegenNode = codegenNode;
|
---|
| 3265 | } else {
|
---|
| 3266 | root.codegenNode = child;
|
---|
| 3267 | }
|
---|
| 3268 | } else if (children.length > 1) {
|
---|
| 3269 | let patchFlag = 64;
|
---|
| 3270 | if (children.filter((c) => c.type !== 3).length === 1) {
|
---|
| 3271 | patchFlag |= 2048;
|
---|
| 3272 | }
|
---|
| 3273 | root.codegenNode = createVNodeCall(
|
---|
| 3274 | context,
|
---|
| 3275 | helper(FRAGMENT),
|
---|
| 3276 | void 0,
|
---|
| 3277 | root.children,
|
---|
| 3278 | patchFlag,
|
---|
| 3279 | void 0,
|
---|
| 3280 | void 0,
|
---|
| 3281 | true,
|
---|
| 3282 | void 0,
|
---|
| 3283 | false
|
---|
| 3284 | );
|
---|
| 3285 | } else ;
|
---|
| 3286 | }
|
---|
| 3287 | function traverseChildren(parent, context) {
|
---|
| 3288 | let i = 0;
|
---|
| 3289 | const nodeRemoved = () => {
|
---|
| 3290 | i--;
|
---|
| 3291 | };
|
---|
| 3292 | for (; i < parent.children.length; i++) {
|
---|
| 3293 | const child = parent.children[i];
|
---|
| 3294 | if (isString(child)) continue;
|
---|
| 3295 | context.grandParent = context.parent;
|
---|
| 3296 | context.parent = parent;
|
---|
| 3297 | context.childIndex = i;
|
---|
| 3298 | context.onNodeRemoved = nodeRemoved;
|
---|
| 3299 | traverseNode(child, context);
|
---|
| 3300 | }
|
---|
| 3301 | }
|
---|
| 3302 | function traverseNode(node, context) {
|
---|
| 3303 | context.currentNode = node;
|
---|
| 3304 | const { nodeTransforms } = context;
|
---|
| 3305 | const exitFns = [];
|
---|
| 3306 | for (let i2 = 0; i2 < nodeTransforms.length; i2++) {
|
---|
| 3307 | const onExit = nodeTransforms[i2](node, context);
|
---|
| 3308 | if (onExit) {
|
---|
| 3309 | if (isArray(onExit)) {
|
---|
| 3310 | exitFns.push(...onExit);
|
---|
| 3311 | } else {
|
---|
| 3312 | exitFns.push(onExit);
|
---|
| 3313 | }
|
---|
| 3314 | }
|
---|
| 3315 | if (!context.currentNode) {
|
---|
| 3316 | return;
|
---|
| 3317 | } else {
|
---|
| 3318 | node = context.currentNode;
|
---|
| 3319 | }
|
---|
| 3320 | }
|
---|
| 3321 | switch (node.type) {
|
---|
| 3322 | case 3:
|
---|
| 3323 | if (!context.ssr) {
|
---|
| 3324 | context.helper(CREATE_COMMENT);
|
---|
| 3325 | }
|
---|
| 3326 | break;
|
---|
| 3327 | case 5:
|
---|
| 3328 | if (!context.ssr) {
|
---|
| 3329 | context.helper(TO_DISPLAY_STRING);
|
---|
| 3330 | }
|
---|
| 3331 | break;
|
---|
| 3332 | // for container types, further traverse downwards
|
---|
| 3333 | case 9:
|
---|
| 3334 | for (let i2 = 0; i2 < node.branches.length; i2++) {
|
---|
| 3335 | traverseNode(node.branches[i2], context);
|
---|
| 3336 | }
|
---|
| 3337 | break;
|
---|
| 3338 | case 10:
|
---|
| 3339 | case 11:
|
---|
| 3340 | case 1:
|
---|
| 3341 | case 0:
|
---|
| 3342 | traverseChildren(node, context);
|
---|
| 3343 | break;
|
---|
| 3344 | }
|
---|
| 3345 | context.currentNode = node;
|
---|
| 3346 | let i = exitFns.length;
|
---|
| 3347 | while (i--) {
|
---|
| 3348 | exitFns[i]();
|
---|
| 3349 | }
|
---|
| 3350 | }
|
---|
| 3351 | function createStructuralDirectiveTransform(name, fn) {
|
---|
| 3352 | const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
|
---|
| 3353 | return (node, context) => {
|
---|
| 3354 | if (node.type === 1) {
|
---|
| 3355 | const { props } = node;
|
---|
| 3356 | if (node.tagType === 3 && props.some(isVSlot)) {
|
---|
| 3357 | return;
|
---|
| 3358 | }
|
---|
| 3359 | const exitFns = [];
|
---|
| 3360 | for (let i = 0; i < props.length; i++) {
|
---|
| 3361 | const prop = props[i];
|
---|
| 3362 | if (prop.type === 7 && matches(prop.name)) {
|
---|
| 3363 | props.splice(i, 1);
|
---|
| 3364 | i--;
|
---|
| 3365 | const onExit = fn(node, prop, context);
|
---|
| 3366 | if (onExit) exitFns.push(onExit);
|
---|
| 3367 | }
|
---|
| 3368 | }
|
---|
| 3369 | return exitFns;
|
---|
| 3370 | }
|
---|
| 3371 | };
|
---|
| 3372 | }
|
---|
| 3373 |
|
---|
| 3374 | const PURE_ANNOTATION = `/*@__PURE__*/`;
|
---|
| 3375 | const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
---|
| 3376 | function createCodegenContext(ast, {
|
---|
| 3377 | mode = "function",
|
---|
| 3378 | prefixIdentifiers = mode === "module",
|
---|
| 3379 | sourceMap = false,
|
---|
| 3380 | filename = `template.vue.html`,
|
---|
| 3381 | scopeId = null,
|
---|
| 3382 | optimizeImports = false,
|
---|
| 3383 | runtimeGlobalName = `Vue`,
|
---|
| 3384 | runtimeModuleName = `vue`,
|
---|
| 3385 | ssrRuntimeModuleName = "vue/server-renderer",
|
---|
| 3386 | ssr = false,
|
---|
| 3387 | isTS = false,
|
---|
| 3388 | inSSR = false
|
---|
| 3389 | }) {
|
---|
| 3390 | const context = {
|
---|
| 3391 | mode,
|
---|
| 3392 | prefixIdentifiers,
|
---|
| 3393 | sourceMap,
|
---|
| 3394 | filename,
|
---|
| 3395 | scopeId,
|
---|
| 3396 | optimizeImports,
|
---|
| 3397 | runtimeGlobalName,
|
---|
| 3398 | runtimeModuleName,
|
---|
| 3399 | ssrRuntimeModuleName,
|
---|
| 3400 | ssr,
|
---|
| 3401 | isTS,
|
---|
| 3402 | inSSR,
|
---|
| 3403 | source: ast.source,
|
---|
| 3404 | code: ``,
|
---|
| 3405 | column: 1,
|
---|
| 3406 | line: 1,
|
---|
| 3407 | offset: 0,
|
---|
| 3408 | indentLevel: 0,
|
---|
| 3409 | pure: false,
|
---|
| 3410 | map: void 0,
|
---|
| 3411 | helper(key) {
|
---|
| 3412 | return `_${helperNameMap[key]}`;
|
---|
| 3413 | },
|
---|
| 3414 | push(code, newlineIndex = -2 /* None */, node) {
|
---|
| 3415 | context.code += code;
|
---|
| 3416 | },
|
---|
| 3417 | indent() {
|
---|
| 3418 | newline(++context.indentLevel);
|
---|
| 3419 | },
|
---|
| 3420 | deindent(withoutNewLine = false) {
|
---|
| 3421 | if (withoutNewLine) {
|
---|
| 3422 | --context.indentLevel;
|
---|
| 3423 | } else {
|
---|
| 3424 | newline(--context.indentLevel);
|
---|
| 3425 | }
|
---|
| 3426 | },
|
---|
| 3427 | newline() {
|
---|
| 3428 | newline(context.indentLevel);
|
---|
| 3429 | }
|
---|
| 3430 | };
|
---|
| 3431 | function newline(n) {
|
---|
| 3432 | context.push("\n" + ` `.repeat(n), 0 /* Start */);
|
---|
| 3433 | }
|
---|
| 3434 | return context;
|
---|
| 3435 | }
|
---|
| 3436 | function generate(ast, options = {}) {
|
---|
| 3437 | const context = createCodegenContext(ast, options);
|
---|
| 3438 | if (options.onContextCreated) options.onContextCreated(context);
|
---|
| 3439 | const {
|
---|
| 3440 | mode,
|
---|
| 3441 | push,
|
---|
| 3442 | prefixIdentifiers,
|
---|
| 3443 | indent,
|
---|
| 3444 | deindent,
|
---|
| 3445 | newline,
|
---|
| 3446 | scopeId,
|
---|
| 3447 | ssr
|
---|
| 3448 | } = context;
|
---|
| 3449 | const helpers = Array.from(ast.helpers);
|
---|
| 3450 | const hasHelpers = helpers.length > 0;
|
---|
| 3451 | const useWithBlock = !prefixIdentifiers && mode !== "module";
|
---|
| 3452 | const preambleContext = context;
|
---|
| 3453 | {
|
---|
| 3454 | genFunctionPreamble(ast, preambleContext);
|
---|
| 3455 | }
|
---|
| 3456 | const functionName = ssr ? `ssrRender` : `render`;
|
---|
| 3457 | const args = ssr ? ["_ctx", "_push", "_parent", "_attrs"] : ["_ctx", "_cache"];
|
---|
| 3458 | const signature = args.join(", ");
|
---|
| 3459 | {
|
---|
| 3460 | push(`function ${functionName}(${signature}) {`);
|
---|
| 3461 | }
|
---|
| 3462 | indent();
|
---|
| 3463 | if (useWithBlock) {
|
---|
| 3464 | push(`with (_ctx) {`);
|
---|
| 3465 | indent();
|
---|
| 3466 | if (hasHelpers) {
|
---|
| 3467 | push(
|
---|
| 3468 | `const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
|
---|
| 3469 | `,
|
---|
| 3470 | -1 /* End */
|
---|
| 3471 | );
|
---|
| 3472 | newline();
|
---|
| 3473 | }
|
---|
| 3474 | }
|
---|
| 3475 | if (ast.components.length) {
|
---|
| 3476 | genAssets(ast.components, "component", context);
|
---|
| 3477 | if (ast.directives.length || ast.temps > 0) {
|
---|
| 3478 | newline();
|
---|
| 3479 | }
|
---|
| 3480 | }
|
---|
| 3481 | if (ast.directives.length) {
|
---|
| 3482 | genAssets(ast.directives, "directive", context);
|
---|
| 3483 | if (ast.temps > 0) {
|
---|
| 3484 | newline();
|
---|
| 3485 | }
|
---|
| 3486 | }
|
---|
| 3487 | if (ast.filters && ast.filters.length) {
|
---|
| 3488 | newline();
|
---|
| 3489 | genAssets(ast.filters, "filter", context);
|
---|
| 3490 | newline();
|
---|
| 3491 | }
|
---|
| 3492 | if (ast.temps > 0) {
|
---|
| 3493 | push(`let `);
|
---|
| 3494 | for (let i = 0; i < ast.temps; i++) {
|
---|
| 3495 | push(`${i > 0 ? `, ` : ``}_temp${i}`);
|
---|
| 3496 | }
|
---|
| 3497 | }
|
---|
| 3498 | if (ast.components.length || ast.directives.length || ast.temps) {
|
---|
| 3499 | push(`
|
---|
| 3500 | `, 0 /* Start */);
|
---|
| 3501 | newline();
|
---|
| 3502 | }
|
---|
| 3503 | if (!ssr) {
|
---|
| 3504 | push(`return `);
|
---|
| 3505 | }
|
---|
| 3506 | if (ast.codegenNode) {
|
---|
| 3507 | genNode(ast.codegenNode, context);
|
---|
| 3508 | } else {
|
---|
| 3509 | push(`null`);
|
---|
| 3510 | }
|
---|
| 3511 | if (useWithBlock) {
|
---|
| 3512 | deindent();
|
---|
| 3513 | push(`}`);
|
---|
| 3514 | }
|
---|
| 3515 | deindent();
|
---|
| 3516 | push(`}`);
|
---|
| 3517 | return {
|
---|
| 3518 | ast,
|
---|
| 3519 | code: context.code,
|
---|
| 3520 | preamble: ``,
|
---|
| 3521 | map: context.map ? context.map.toJSON() : void 0
|
---|
| 3522 | };
|
---|
| 3523 | }
|
---|
| 3524 | function genFunctionPreamble(ast, context) {
|
---|
| 3525 | const {
|
---|
| 3526 | ssr,
|
---|
| 3527 | prefixIdentifiers,
|
---|
| 3528 | push,
|
---|
| 3529 | newline,
|
---|
| 3530 | runtimeModuleName,
|
---|
| 3531 | runtimeGlobalName,
|
---|
| 3532 | ssrRuntimeModuleName
|
---|
| 3533 | } = context;
|
---|
| 3534 | const VueBinding = runtimeGlobalName;
|
---|
| 3535 | const helpers = Array.from(ast.helpers);
|
---|
| 3536 | if (helpers.length > 0) {
|
---|
| 3537 | {
|
---|
| 3538 | push(`const _Vue = ${VueBinding}
|
---|
| 3539 | `, -1 /* End */);
|
---|
| 3540 | if (ast.hoists.length) {
|
---|
| 3541 | const staticHelpers = [
|
---|
| 3542 | CREATE_VNODE,
|
---|
| 3543 | CREATE_ELEMENT_VNODE,
|
---|
| 3544 | CREATE_COMMENT,
|
---|
| 3545 | CREATE_TEXT,
|
---|
| 3546 | CREATE_STATIC
|
---|
| 3547 | ].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
|
---|
| 3548 | push(`const { ${staticHelpers} } = _Vue
|
---|
| 3549 | `, -1 /* End */);
|
---|
| 3550 | }
|
---|
| 3551 | }
|
---|
| 3552 | }
|
---|
| 3553 | genHoists(ast.hoists, context);
|
---|
| 3554 | newline();
|
---|
| 3555 | push(`return `);
|
---|
| 3556 | }
|
---|
| 3557 | function genAssets(assets, type, { helper, push, newline, isTS }) {
|
---|
| 3558 | const resolver = helper(
|
---|
| 3559 | type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE
|
---|
| 3560 | );
|
---|
| 3561 | for (let i = 0; i < assets.length; i++) {
|
---|
| 3562 | let id = assets[i];
|
---|
| 3563 | const maybeSelfReference = id.endsWith("__self");
|
---|
| 3564 | if (maybeSelfReference) {
|
---|
| 3565 | id = id.slice(0, -6);
|
---|
| 3566 | }
|
---|
| 3567 | push(
|
---|
| 3568 | `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`
|
---|
| 3569 | );
|
---|
| 3570 | if (i < assets.length - 1) {
|
---|
| 3571 | newline();
|
---|
| 3572 | }
|
---|
| 3573 | }
|
---|
| 3574 | }
|
---|
| 3575 | function genHoists(hoists, context) {
|
---|
| 3576 | if (!hoists.length) {
|
---|
| 3577 | return;
|
---|
| 3578 | }
|
---|
| 3579 | context.pure = true;
|
---|
| 3580 | const { push, newline } = context;
|
---|
| 3581 | newline();
|
---|
| 3582 | for (let i = 0; i < hoists.length; i++) {
|
---|
| 3583 | const exp = hoists[i];
|
---|
| 3584 | if (exp) {
|
---|
| 3585 | push(`const _hoisted_${i + 1} = `);
|
---|
| 3586 | genNode(exp, context);
|
---|
| 3587 | newline();
|
---|
| 3588 | }
|
---|
| 3589 | }
|
---|
| 3590 | context.pure = false;
|
---|
| 3591 | }
|
---|
| 3592 | function isText(n) {
|
---|
| 3593 | return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
|
---|
| 3594 | }
|
---|
| 3595 | function genNodeListAsArray(nodes, context) {
|
---|
| 3596 | const multilines = nodes.length > 3 || nodes.some((n) => isArray(n) || !isText(n));
|
---|
| 3597 | context.push(`[`);
|
---|
| 3598 | multilines && context.indent();
|
---|
| 3599 | genNodeList(nodes, context, multilines);
|
---|
| 3600 | multilines && context.deindent();
|
---|
| 3601 | context.push(`]`);
|
---|
| 3602 | }
|
---|
| 3603 | function genNodeList(nodes, context, multilines = false, comma = true) {
|
---|
| 3604 | const { push, newline } = context;
|
---|
| 3605 | for (let i = 0; i < nodes.length; i++) {
|
---|
| 3606 | const node = nodes[i];
|
---|
| 3607 | if (isString(node)) {
|
---|
| 3608 | push(node, -3 /* Unknown */);
|
---|
| 3609 | } else if (isArray(node)) {
|
---|
| 3610 | genNodeListAsArray(node, context);
|
---|
| 3611 | } else {
|
---|
| 3612 | genNode(node, context);
|
---|
| 3613 | }
|
---|
| 3614 | if (i < nodes.length - 1) {
|
---|
| 3615 | if (multilines) {
|
---|
| 3616 | comma && push(",");
|
---|
| 3617 | newline();
|
---|
| 3618 | } else {
|
---|
| 3619 | comma && push(", ");
|
---|
| 3620 | }
|
---|
| 3621 | }
|
---|
| 3622 | }
|
---|
| 3623 | }
|
---|
| 3624 | function genNode(node, context) {
|
---|
| 3625 | if (isString(node)) {
|
---|
| 3626 | context.push(node, -3 /* Unknown */);
|
---|
| 3627 | return;
|
---|
| 3628 | }
|
---|
| 3629 | if (isSymbol(node)) {
|
---|
| 3630 | context.push(context.helper(node));
|
---|
| 3631 | return;
|
---|
| 3632 | }
|
---|
| 3633 | switch (node.type) {
|
---|
| 3634 | case 1:
|
---|
| 3635 | case 9:
|
---|
| 3636 | case 11:
|
---|
| 3637 | assert(
|
---|
| 3638 | node.codegenNode != null,
|
---|
| 3639 | `Codegen node is missing for element/if/for node. Apply appropriate transforms first.`
|
---|
| 3640 | );
|
---|
| 3641 | genNode(node.codegenNode, context);
|
---|
| 3642 | break;
|
---|
| 3643 | case 2:
|
---|
| 3644 | genText(node, context);
|
---|
| 3645 | break;
|
---|
| 3646 | case 4:
|
---|
| 3647 | genExpression(node, context);
|
---|
| 3648 | break;
|
---|
| 3649 | case 5:
|
---|
| 3650 | genInterpolation(node, context);
|
---|
| 3651 | break;
|
---|
| 3652 | case 12:
|
---|
| 3653 | genNode(node.codegenNode, context);
|
---|
| 3654 | break;
|
---|
| 3655 | case 8:
|
---|
| 3656 | genCompoundExpression(node, context);
|
---|
| 3657 | break;
|
---|
| 3658 | case 3:
|
---|
| 3659 | genComment(node, context);
|
---|
| 3660 | break;
|
---|
| 3661 | case 13:
|
---|
| 3662 | genVNodeCall(node, context);
|
---|
| 3663 | break;
|
---|
| 3664 | case 14:
|
---|
| 3665 | genCallExpression(node, context);
|
---|
| 3666 | break;
|
---|
| 3667 | case 15:
|
---|
| 3668 | genObjectExpression(node, context);
|
---|
| 3669 | break;
|
---|
| 3670 | case 17:
|
---|
| 3671 | genArrayExpression(node, context);
|
---|
| 3672 | break;
|
---|
| 3673 | case 18:
|
---|
| 3674 | genFunctionExpression(node, context);
|
---|
| 3675 | break;
|
---|
| 3676 | case 19:
|
---|
| 3677 | genConditionalExpression(node, context);
|
---|
| 3678 | break;
|
---|
| 3679 | case 20:
|
---|
| 3680 | genCacheExpression(node, context);
|
---|
| 3681 | break;
|
---|
| 3682 | case 21:
|
---|
| 3683 | genNodeList(node.body, context, true, false);
|
---|
| 3684 | break;
|
---|
| 3685 | // SSR only types
|
---|
| 3686 | case 22:
|
---|
| 3687 | break;
|
---|
| 3688 | case 23:
|
---|
| 3689 | break;
|
---|
| 3690 | case 24:
|
---|
| 3691 | break;
|
---|
| 3692 | case 25:
|
---|
| 3693 | break;
|
---|
| 3694 | case 26:
|
---|
| 3695 | break;
|
---|
| 3696 | /* v8 ignore start */
|
---|
| 3697 | case 10:
|
---|
| 3698 | break;
|
---|
| 3699 | default:
|
---|
| 3700 | {
|
---|
| 3701 | assert(false, `unhandled codegen node type: ${node.type}`);
|
---|
| 3702 | const exhaustiveCheck = node;
|
---|
| 3703 | return exhaustiveCheck;
|
---|
| 3704 | }
|
---|
| 3705 | }
|
---|
| 3706 | }
|
---|
| 3707 | function genText(node, context) {
|
---|
| 3708 | context.push(JSON.stringify(node.content), -3 /* Unknown */, node);
|
---|
| 3709 | }
|
---|
| 3710 | function genExpression(node, context) {
|
---|
| 3711 | const { content, isStatic } = node;
|
---|
| 3712 | context.push(
|
---|
| 3713 | isStatic ? JSON.stringify(content) : content,
|
---|
| 3714 | -3 /* Unknown */,
|
---|
| 3715 | node
|
---|
| 3716 | );
|
---|
| 3717 | }
|
---|
| 3718 | function genInterpolation(node, context) {
|
---|
| 3719 | const { push, helper, pure } = context;
|
---|
| 3720 | if (pure) push(PURE_ANNOTATION);
|
---|
| 3721 | push(`${helper(TO_DISPLAY_STRING)}(`);
|
---|
| 3722 | genNode(node.content, context);
|
---|
| 3723 | push(`)`);
|
---|
| 3724 | }
|
---|
| 3725 | function genCompoundExpression(node, context) {
|
---|
| 3726 | for (let i = 0; i < node.children.length; i++) {
|
---|
| 3727 | const child = node.children[i];
|
---|
| 3728 | if (isString(child)) {
|
---|
| 3729 | context.push(child, -3 /* Unknown */);
|
---|
| 3730 | } else {
|
---|
| 3731 | genNode(child, context);
|
---|
| 3732 | }
|
---|
| 3733 | }
|
---|
| 3734 | }
|
---|
| 3735 | function genExpressionAsPropertyKey(node, context) {
|
---|
| 3736 | const { push } = context;
|
---|
| 3737 | if (node.type === 8) {
|
---|
| 3738 | push(`[`);
|
---|
| 3739 | genCompoundExpression(node, context);
|
---|
| 3740 | push(`]`);
|
---|
| 3741 | } else if (node.isStatic) {
|
---|
| 3742 | const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
|
---|
| 3743 | push(text, -2 /* None */, node);
|
---|
| 3744 | } else {
|
---|
| 3745 | push(`[${node.content}]`, -3 /* Unknown */, node);
|
---|
| 3746 | }
|
---|
| 3747 | }
|
---|
| 3748 | function genComment(node, context) {
|
---|
| 3749 | const { push, helper, pure } = context;
|
---|
| 3750 | if (pure) {
|
---|
| 3751 | push(PURE_ANNOTATION);
|
---|
| 3752 | }
|
---|
| 3753 | push(
|
---|
| 3754 | `${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
|
---|
| 3755 | -3 /* Unknown */,
|
---|
| 3756 | node
|
---|
| 3757 | );
|
---|
| 3758 | }
|
---|
| 3759 | function genVNodeCall(node, context) {
|
---|
| 3760 | const { push, helper, pure } = context;
|
---|
| 3761 | const {
|
---|
| 3762 | tag,
|
---|
| 3763 | props,
|
---|
| 3764 | children,
|
---|
| 3765 | patchFlag,
|
---|
| 3766 | dynamicProps,
|
---|
| 3767 | directives,
|
---|
| 3768 | isBlock,
|
---|
| 3769 | disableTracking,
|
---|
| 3770 | isComponent
|
---|
| 3771 | } = node;
|
---|
| 3772 | let patchFlagString;
|
---|
| 3773 | if (patchFlag) {
|
---|
| 3774 | {
|
---|
| 3775 | if (patchFlag < 0) {
|
---|
| 3776 | patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
---|
| 3777 | } else {
|
---|
| 3778 | const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
|
---|
| 3779 | patchFlagString = patchFlag + ` /* ${flagNames} */`;
|
---|
| 3780 | }
|
---|
| 3781 | }
|
---|
| 3782 | }
|
---|
| 3783 | if (directives) {
|
---|
| 3784 | push(helper(WITH_DIRECTIVES) + `(`);
|
---|
| 3785 | }
|
---|
| 3786 | if (isBlock) {
|
---|
| 3787 | push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
|
---|
| 3788 | }
|
---|
| 3789 | if (pure) {
|
---|
| 3790 | push(PURE_ANNOTATION);
|
---|
| 3791 | }
|
---|
| 3792 | const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
---|
| 3793 | push(helper(callHelper) + `(`, -2 /* None */, node);
|
---|
| 3794 | genNodeList(
|
---|
| 3795 | genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
|
---|
| 3796 | context
|
---|
| 3797 | );
|
---|
| 3798 | push(`)`);
|
---|
| 3799 | if (isBlock) {
|
---|
| 3800 | push(`)`);
|
---|
| 3801 | }
|
---|
| 3802 | if (directives) {
|
---|
| 3803 | push(`, `);
|
---|
| 3804 | genNode(directives, context);
|
---|
| 3805 | push(`)`);
|
---|
| 3806 | }
|
---|
| 3807 | }
|
---|
| 3808 | function genNullableArgs(args) {
|
---|
| 3809 | let i = args.length;
|
---|
| 3810 | while (i--) {
|
---|
| 3811 | if (args[i] != null) break;
|
---|
| 3812 | }
|
---|
| 3813 | return args.slice(0, i + 1).map((arg) => arg || `null`);
|
---|
| 3814 | }
|
---|
| 3815 | function genCallExpression(node, context) {
|
---|
| 3816 | const { push, helper, pure } = context;
|
---|
| 3817 | const callee = isString(node.callee) ? node.callee : helper(node.callee);
|
---|
| 3818 | if (pure) {
|
---|
| 3819 | push(PURE_ANNOTATION);
|
---|
| 3820 | }
|
---|
| 3821 | push(callee + `(`, -2 /* None */, node);
|
---|
| 3822 | genNodeList(node.arguments, context);
|
---|
| 3823 | push(`)`);
|
---|
| 3824 | }
|
---|
| 3825 | function genObjectExpression(node, context) {
|
---|
| 3826 | const { push, indent, deindent, newline } = context;
|
---|
| 3827 | const { properties } = node;
|
---|
| 3828 | if (!properties.length) {
|
---|
| 3829 | push(`{}`, -2 /* None */, node);
|
---|
| 3830 | return;
|
---|
| 3831 | }
|
---|
| 3832 | const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
|
---|
| 3833 | push(multilines ? `{` : `{ `);
|
---|
| 3834 | multilines && indent();
|
---|
| 3835 | for (let i = 0; i < properties.length; i++) {
|
---|
| 3836 | const { key, value } = properties[i];
|
---|
| 3837 | genExpressionAsPropertyKey(key, context);
|
---|
| 3838 | push(`: `);
|
---|
| 3839 | genNode(value, context);
|
---|
| 3840 | if (i < properties.length - 1) {
|
---|
| 3841 | push(`,`);
|
---|
| 3842 | newline();
|
---|
| 3843 | }
|
---|
| 3844 | }
|
---|
| 3845 | multilines && deindent();
|
---|
| 3846 | push(multilines ? `}` : ` }`);
|
---|
| 3847 | }
|
---|
| 3848 | function genArrayExpression(node, context) {
|
---|
| 3849 | genNodeListAsArray(node.elements, context);
|
---|
| 3850 | }
|
---|
| 3851 | function genFunctionExpression(node, context) {
|
---|
| 3852 | const { push, indent, deindent } = context;
|
---|
| 3853 | const { params, returns, body, newline, isSlot } = node;
|
---|
| 3854 | if (isSlot) {
|
---|
| 3855 | push(`_${helperNameMap[WITH_CTX]}(`);
|
---|
| 3856 | }
|
---|
| 3857 | push(`(`, -2 /* None */, node);
|
---|
| 3858 | if (isArray(params)) {
|
---|
| 3859 | genNodeList(params, context);
|
---|
| 3860 | } else if (params) {
|
---|
| 3861 | genNode(params, context);
|
---|
| 3862 | }
|
---|
| 3863 | push(`) => `);
|
---|
| 3864 | if (newline || body) {
|
---|
| 3865 | push(`{`);
|
---|
| 3866 | indent();
|
---|
| 3867 | }
|
---|
| 3868 | if (returns) {
|
---|
| 3869 | if (newline) {
|
---|
| 3870 | push(`return `);
|
---|
| 3871 | }
|
---|
| 3872 | if (isArray(returns)) {
|
---|
| 3873 | genNodeListAsArray(returns, context);
|
---|
| 3874 | } else {
|
---|
| 3875 | genNode(returns, context);
|
---|
| 3876 | }
|
---|
| 3877 | } else if (body) {
|
---|
| 3878 | genNode(body, context);
|
---|
| 3879 | }
|
---|
| 3880 | if (newline || body) {
|
---|
| 3881 | deindent();
|
---|
| 3882 | push(`}`);
|
---|
| 3883 | }
|
---|
| 3884 | if (isSlot) {
|
---|
| 3885 | if (node.isNonScopedSlot) {
|
---|
| 3886 | push(`, undefined, true`);
|
---|
| 3887 | }
|
---|
| 3888 | push(`)`);
|
---|
| 3889 | }
|
---|
| 3890 | }
|
---|
| 3891 | function genConditionalExpression(node, context) {
|
---|
| 3892 | const { test, consequent, alternate, newline: needNewline } = node;
|
---|
| 3893 | const { push, indent, deindent, newline } = context;
|
---|
| 3894 | if (test.type === 4) {
|
---|
| 3895 | const needsParens = !isSimpleIdentifier(test.content);
|
---|
| 3896 | needsParens && push(`(`);
|
---|
| 3897 | genExpression(test, context);
|
---|
| 3898 | needsParens && push(`)`);
|
---|
| 3899 | } else {
|
---|
| 3900 | push(`(`);
|
---|
| 3901 | genNode(test, context);
|
---|
| 3902 | push(`)`);
|
---|
| 3903 | }
|
---|
| 3904 | needNewline && indent();
|
---|
| 3905 | context.indentLevel++;
|
---|
| 3906 | needNewline || push(` `);
|
---|
| 3907 | push(`? `);
|
---|
| 3908 | genNode(consequent, context);
|
---|
| 3909 | context.indentLevel--;
|
---|
| 3910 | needNewline && newline();
|
---|
| 3911 | needNewline || push(` `);
|
---|
| 3912 | push(`: `);
|
---|
| 3913 | const isNested = alternate.type === 19;
|
---|
| 3914 | if (!isNested) {
|
---|
| 3915 | context.indentLevel++;
|
---|
| 3916 | }
|
---|
| 3917 | genNode(alternate, context);
|
---|
| 3918 | if (!isNested) {
|
---|
| 3919 | context.indentLevel--;
|
---|
| 3920 | }
|
---|
| 3921 | needNewline && deindent(
|
---|
| 3922 | true
|
---|
| 3923 | /* without newline */
|
---|
| 3924 | );
|
---|
| 3925 | }
|
---|
| 3926 | function genCacheExpression(node, context) {
|
---|
| 3927 | const { push, helper, indent, deindent, newline } = context;
|
---|
| 3928 | const { needPauseTracking, needArraySpread } = node;
|
---|
| 3929 | if (needArraySpread) {
|
---|
| 3930 | push(`[...(`);
|
---|
| 3931 | }
|
---|
| 3932 | push(`_cache[${node.index}] || (`);
|
---|
| 3933 | if (needPauseTracking) {
|
---|
| 3934 | indent();
|
---|
| 3935 | push(`${helper(SET_BLOCK_TRACKING)}(-1`);
|
---|
| 3936 | if (node.inVOnce) push(`, true`);
|
---|
| 3937 | push(`),`);
|
---|
| 3938 | newline();
|
---|
| 3939 | push(`(`);
|
---|
| 3940 | }
|
---|
| 3941 | push(`_cache[${node.index}] = `);
|
---|
| 3942 | genNode(node.value, context);
|
---|
| 3943 | if (needPauseTracking) {
|
---|
| 3944 | push(`).cacheIndex = ${node.index},`);
|
---|
| 3945 | newline();
|
---|
| 3946 | push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
---|
| 3947 | newline();
|
---|
| 3948 | push(`_cache[${node.index}]`);
|
---|
| 3949 | deindent();
|
---|
| 3950 | }
|
---|
| 3951 | push(`)`);
|
---|
| 3952 | if (needArraySpread) {
|
---|
| 3953 | push(`)]`);
|
---|
| 3954 | }
|
---|
| 3955 | }
|
---|
| 3956 |
|
---|
| 3957 | const prohibitedKeywordRE = new RegExp(
|
---|
| 3958 | "\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b"
|
---|
| 3959 | );
|
---|
| 3960 | const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
|
---|
| 3961 | function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
|
---|
| 3962 | const exp = node.content;
|
---|
| 3963 | if (!exp.trim()) {
|
---|
| 3964 | return;
|
---|
| 3965 | }
|
---|
| 3966 | try {
|
---|
| 3967 | new Function(
|
---|
| 3968 | asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`
|
---|
| 3969 | );
|
---|
| 3970 | } catch (e) {
|
---|
| 3971 | let message = e.message;
|
---|
| 3972 | const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
|
---|
| 3973 | if (keywordMatch) {
|
---|
| 3974 | message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
---|
| 3975 | }
|
---|
| 3976 | context.onError(
|
---|
| 3977 | createCompilerError(
|
---|
| 3978 | 45,
|
---|
| 3979 | node.loc,
|
---|
| 3980 | void 0,
|
---|
| 3981 | message
|
---|
| 3982 | )
|
---|
| 3983 | );
|
---|
| 3984 | }
|
---|
| 3985 | }
|
---|
| 3986 |
|
---|
| 3987 | const transformExpression = (node, context) => {
|
---|
| 3988 | if (node.type === 5) {
|
---|
| 3989 | node.content = processExpression(
|
---|
| 3990 | node.content,
|
---|
| 3991 | context
|
---|
| 3992 | );
|
---|
| 3993 | } else if (node.type === 1) {
|
---|
| 3994 | const memo = findDir(node, "memo");
|
---|
| 3995 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 3996 | const dir = node.props[i];
|
---|
| 3997 | if (dir.type === 7 && dir.name !== "for") {
|
---|
| 3998 | const exp = dir.exp;
|
---|
| 3999 | const arg = dir.arg;
|
---|
| 4000 | if (exp && exp.type === 4 && !(dir.name === "on" && arg) && // key has been processed in transformFor(vMemo + vFor)
|
---|
| 4001 | !(memo && arg && arg.type === 4 && arg.content === "key")) {
|
---|
| 4002 | dir.exp = processExpression(
|
---|
| 4003 | exp,
|
---|
| 4004 | context,
|
---|
| 4005 | // slot args must be processed as function params
|
---|
| 4006 | dir.name === "slot"
|
---|
| 4007 | );
|
---|
| 4008 | }
|
---|
| 4009 | if (arg && arg.type === 4 && !arg.isStatic) {
|
---|
| 4010 | dir.arg = processExpression(arg, context);
|
---|
| 4011 | }
|
---|
| 4012 | }
|
---|
| 4013 | }
|
---|
| 4014 | }
|
---|
| 4015 | };
|
---|
| 4016 | function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
---|
| 4017 | {
|
---|
| 4018 | {
|
---|
| 4019 | validateBrowserExpression(node, context, asParams, asRawStatements);
|
---|
| 4020 | }
|
---|
| 4021 | return node;
|
---|
| 4022 | }
|
---|
| 4023 | }
|
---|
| 4024 | function stringifyExpression(exp) {
|
---|
| 4025 | if (isString(exp)) {
|
---|
| 4026 | return exp;
|
---|
| 4027 | } else if (exp.type === 4) {
|
---|
| 4028 | return exp.content;
|
---|
| 4029 | } else {
|
---|
| 4030 | return exp.children.map(stringifyExpression).join("");
|
---|
| 4031 | }
|
---|
| 4032 | }
|
---|
| 4033 |
|
---|
| 4034 | const transformIf = createStructuralDirectiveTransform(
|
---|
| 4035 | /^(if|else|else-if)$/,
|
---|
| 4036 | (node, dir, context) => {
|
---|
| 4037 | return processIf(node, dir, context, (ifNode, branch, isRoot) => {
|
---|
| 4038 | const siblings = context.parent.children;
|
---|
| 4039 | let i = siblings.indexOf(ifNode);
|
---|
| 4040 | let key = 0;
|
---|
| 4041 | while (i-- >= 0) {
|
---|
| 4042 | const sibling = siblings[i];
|
---|
| 4043 | if (sibling && sibling.type === 9) {
|
---|
| 4044 | key += sibling.branches.length;
|
---|
| 4045 | }
|
---|
| 4046 | }
|
---|
| 4047 | return () => {
|
---|
| 4048 | if (isRoot) {
|
---|
| 4049 | ifNode.codegenNode = createCodegenNodeForBranch(
|
---|
| 4050 | branch,
|
---|
| 4051 | key,
|
---|
| 4052 | context
|
---|
| 4053 | );
|
---|
| 4054 | } else {
|
---|
| 4055 | const parentCondition = getParentCondition(ifNode.codegenNode);
|
---|
| 4056 | parentCondition.alternate = createCodegenNodeForBranch(
|
---|
| 4057 | branch,
|
---|
| 4058 | key + ifNode.branches.length - 1,
|
---|
| 4059 | context
|
---|
| 4060 | );
|
---|
| 4061 | }
|
---|
| 4062 | };
|
---|
| 4063 | });
|
---|
| 4064 | }
|
---|
| 4065 | );
|
---|
| 4066 | function processIf(node, dir, context, processCodegen) {
|
---|
| 4067 | if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
---|
| 4068 | const loc = dir.exp ? dir.exp.loc : node.loc;
|
---|
| 4069 | context.onError(
|
---|
| 4070 | createCompilerError(28, dir.loc)
|
---|
| 4071 | );
|
---|
| 4072 | dir.exp = createSimpleExpression(`true`, false, loc);
|
---|
| 4073 | }
|
---|
| 4074 | if (dir.exp) {
|
---|
| 4075 | validateBrowserExpression(dir.exp, context);
|
---|
| 4076 | }
|
---|
| 4077 | if (dir.name === "if") {
|
---|
| 4078 | const branch = createIfBranch(node, dir);
|
---|
| 4079 | const ifNode = {
|
---|
| 4080 | type: 9,
|
---|
| 4081 | loc: cloneLoc(node.loc),
|
---|
| 4082 | branches: [branch]
|
---|
| 4083 | };
|
---|
| 4084 | context.replaceNode(ifNode);
|
---|
| 4085 | if (processCodegen) {
|
---|
| 4086 | return processCodegen(ifNode, branch, true);
|
---|
| 4087 | }
|
---|
| 4088 | } else {
|
---|
| 4089 | const siblings = context.parent.children;
|
---|
| 4090 | const comments = [];
|
---|
| 4091 | let i = siblings.indexOf(node);
|
---|
| 4092 | while (i-- >= -1) {
|
---|
| 4093 | const sibling = siblings[i];
|
---|
| 4094 | if (sibling && sibling.type === 3) {
|
---|
| 4095 | context.removeNode(sibling);
|
---|
| 4096 | comments.unshift(sibling);
|
---|
| 4097 | continue;
|
---|
| 4098 | }
|
---|
| 4099 | if (sibling && sibling.type === 2 && !sibling.content.trim().length) {
|
---|
| 4100 | context.removeNode(sibling);
|
---|
| 4101 | continue;
|
---|
| 4102 | }
|
---|
| 4103 | if (sibling && sibling.type === 9) {
|
---|
| 4104 | if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
|
---|
| 4105 | context.onError(
|
---|
| 4106 | createCompilerError(30, node.loc)
|
---|
| 4107 | );
|
---|
| 4108 | }
|
---|
| 4109 | context.removeNode();
|
---|
| 4110 | const branch = createIfBranch(node, dir);
|
---|
| 4111 | if (comments.length && // #3619 ignore comments if the v-if is direct child of <transition>
|
---|
| 4112 | !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) {
|
---|
| 4113 | branch.children = [...comments, ...branch.children];
|
---|
| 4114 | }
|
---|
| 4115 | {
|
---|
| 4116 | const key = branch.userKey;
|
---|
| 4117 | if (key) {
|
---|
| 4118 | sibling.branches.forEach(({ userKey }) => {
|
---|
| 4119 | if (isSameKey(userKey, key)) {
|
---|
| 4120 | context.onError(
|
---|
| 4121 | createCompilerError(
|
---|
| 4122 | 29,
|
---|
| 4123 | branch.userKey.loc
|
---|
| 4124 | )
|
---|
| 4125 | );
|
---|
| 4126 | }
|
---|
| 4127 | });
|
---|
| 4128 | }
|
---|
| 4129 | }
|
---|
| 4130 | sibling.branches.push(branch);
|
---|
| 4131 | const onExit = processCodegen && processCodegen(sibling, branch, false);
|
---|
| 4132 | traverseNode(branch, context);
|
---|
| 4133 | if (onExit) onExit();
|
---|
| 4134 | context.currentNode = null;
|
---|
| 4135 | } else {
|
---|
| 4136 | context.onError(
|
---|
| 4137 | createCompilerError(30, node.loc)
|
---|
| 4138 | );
|
---|
| 4139 | }
|
---|
| 4140 | break;
|
---|
| 4141 | }
|
---|
| 4142 | }
|
---|
| 4143 | }
|
---|
| 4144 | function createIfBranch(node, dir) {
|
---|
| 4145 | const isTemplateIf = node.tagType === 3;
|
---|
| 4146 | return {
|
---|
| 4147 | type: 10,
|
---|
| 4148 | loc: node.loc,
|
---|
| 4149 | condition: dir.name === "else" ? void 0 : dir.exp,
|
---|
| 4150 | children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
|
---|
| 4151 | userKey: findProp(node, `key`),
|
---|
| 4152 | isTemplateIf
|
---|
| 4153 | };
|
---|
| 4154 | }
|
---|
| 4155 | function createCodegenNodeForBranch(branch, keyIndex, context) {
|
---|
| 4156 | if (branch.condition) {
|
---|
| 4157 | return createConditionalExpression(
|
---|
| 4158 | branch.condition,
|
---|
| 4159 | createChildrenCodegenNode(branch, keyIndex, context),
|
---|
| 4160 | // make sure to pass in asBlock: true so that the comment node call
|
---|
| 4161 | // closes the current block.
|
---|
| 4162 | createCallExpression(context.helper(CREATE_COMMENT), [
|
---|
| 4163 | '"v-if"' ,
|
---|
| 4164 | "true"
|
---|
| 4165 | ])
|
---|
| 4166 | );
|
---|
| 4167 | } else {
|
---|
| 4168 | return createChildrenCodegenNode(branch, keyIndex, context);
|
---|
| 4169 | }
|
---|
| 4170 | }
|
---|
| 4171 | function createChildrenCodegenNode(branch, keyIndex, context) {
|
---|
| 4172 | const { helper } = context;
|
---|
| 4173 | const keyProperty = createObjectProperty(
|
---|
| 4174 | `key`,
|
---|
| 4175 | createSimpleExpression(
|
---|
| 4176 | `${keyIndex}`,
|
---|
| 4177 | false,
|
---|
| 4178 | locStub,
|
---|
| 4179 | 2
|
---|
| 4180 | )
|
---|
| 4181 | );
|
---|
| 4182 | const { children } = branch;
|
---|
| 4183 | const firstChild = children[0];
|
---|
| 4184 | const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1;
|
---|
| 4185 | if (needFragmentWrapper) {
|
---|
| 4186 | if (children.length === 1 && firstChild.type === 11) {
|
---|
| 4187 | const vnodeCall = firstChild.codegenNode;
|
---|
| 4188 | injectProp(vnodeCall, keyProperty, context);
|
---|
| 4189 | return vnodeCall;
|
---|
| 4190 | } else {
|
---|
| 4191 | let patchFlag = 64;
|
---|
| 4192 | if (!branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) {
|
---|
| 4193 | patchFlag |= 2048;
|
---|
| 4194 | }
|
---|
| 4195 | return createVNodeCall(
|
---|
| 4196 | context,
|
---|
| 4197 | helper(FRAGMENT),
|
---|
| 4198 | createObjectExpression([keyProperty]),
|
---|
| 4199 | children,
|
---|
| 4200 | patchFlag,
|
---|
| 4201 | void 0,
|
---|
| 4202 | void 0,
|
---|
| 4203 | true,
|
---|
| 4204 | false,
|
---|
| 4205 | false,
|
---|
| 4206 | branch.loc
|
---|
| 4207 | );
|
---|
| 4208 | }
|
---|
| 4209 | } else {
|
---|
| 4210 | const ret = firstChild.codegenNode;
|
---|
| 4211 | const vnodeCall = getMemoedVNodeCall(ret);
|
---|
| 4212 | if (vnodeCall.type === 13) {
|
---|
| 4213 | convertToBlock(vnodeCall, context);
|
---|
| 4214 | }
|
---|
| 4215 | injectProp(vnodeCall, keyProperty, context);
|
---|
| 4216 | return ret;
|
---|
| 4217 | }
|
---|
| 4218 | }
|
---|
| 4219 | function isSameKey(a, b) {
|
---|
| 4220 | if (!a || a.type !== b.type) {
|
---|
| 4221 | return false;
|
---|
| 4222 | }
|
---|
| 4223 | if (a.type === 6) {
|
---|
| 4224 | if (a.value.content !== b.value.content) {
|
---|
| 4225 | return false;
|
---|
| 4226 | }
|
---|
| 4227 | } else {
|
---|
| 4228 | const exp = a.exp;
|
---|
| 4229 | const branchExp = b.exp;
|
---|
| 4230 | if (exp.type !== branchExp.type) {
|
---|
| 4231 | return false;
|
---|
| 4232 | }
|
---|
| 4233 | if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) {
|
---|
| 4234 | return false;
|
---|
| 4235 | }
|
---|
| 4236 | }
|
---|
| 4237 | return true;
|
---|
| 4238 | }
|
---|
| 4239 | function getParentCondition(node) {
|
---|
| 4240 | while (true) {
|
---|
| 4241 | if (node.type === 19) {
|
---|
| 4242 | if (node.alternate.type === 19) {
|
---|
| 4243 | node = node.alternate;
|
---|
| 4244 | } else {
|
---|
| 4245 | return node;
|
---|
| 4246 | }
|
---|
| 4247 | } else if (node.type === 20) {
|
---|
| 4248 | node = node.value;
|
---|
| 4249 | }
|
---|
| 4250 | }
|
---|
| 4251 | }
|
---|
| 4252 |
|
---|
| 4253 | const transformBind = (dir, _node, context) => {
|
---|
| 4254 | const { modifiers, loc } = dir;
|
---|
| 4255 | const arg = dir.arg;
|
---|
| 4256 | let { exp } = dir;
|
---|
| 4257 | if (exp && exp.type === 4 && !exp.content.trim()) {
|
---|
| 4258 | {
|
---|
| 4259 | exp = void 0;
|
---|
| 4260 | }
|
---|
| 4261 | }
|
---|
| 4262 | if (!exp) {
|
---|
| 4263 | if (arg.type !== 4 || !arg.isStatic) {
|
---|
| 4264 | context.onError(
|
---|
| 4265 | createCompilerError(
|
---|
| 4266 | 52,
|
---|
| 4267 | arg.loc
|
---|
| 4268 | )
|
---|
| 4269 | );
|
---|
| 4270 | return {
|
---|
| 4271 | props: [
|
---|
| 4272 | createObjectProperty(arg, createSimpleExpression("", true, loc))
|
---|
| 4273 | ]
|
---|
| 4274 | };
|
---|
| 4275 | }
|
---|
| 4276 | transformBindShorthand(dir);
|
---|
| 4277 | exp = dir.exp;
|
---|
| 4278 | }
|
---|
| 4279 | if (arg.type !== 4) {
|
---|
| 4280 | arg.children.unshift(`(`);
|
---|
| 4281 | arg.children.push(`) || ""`);
|
---|
| 4282 | } else if (!arg.isStatic) {
|
---|
| 4283 | arg.content = `${arg.content} || ""`;
|
---|
| 4284 | }
|
---|
| 4285 | if (modifiers.some((mod) => mod.content === "camel")) {
|
---|
| 4286 | if (arg.type === 4) {
|
---|
| 4287 | if (arg.isStatic) {
|
---|
| 4288 | arg.content = camelize(arg.content);
|
---|
| 4289 | } else {
|
---|
| 4290 | arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
---|
| 4291 | }
|
---|
| 4292 | } else {
|
---|
| 4293 | arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
---|
| 4294 | arg.children.push(`)`);
|
---|
| 4295 | }
|
---|
| 4296 | }
|
---|
| 4297 | if (!context.inSSR) {
|
---|
| 4298 | if (modifiers.some((mod) => mod.content === "prop")) {
|
---|
| 4299 | injectPrefix(arg, ".");
|
---|
| 4300 | }
|
---|
| 4301 | if (modifiers.some((mod) => mod.content === "attr")) {
|
---|
| 4302 | injectPrefix(arg, "^");
|
---|
| 4303 | }
|
---|
| 4304 | }
|
---|
| 4305 | return {
|
---|
| 4306 | props: [createObjectProperty(arg, exp)]
|
---|
| 4307 | };
|
---|
| 4308 | };
|
---|
| 4309 | const transformBindShorthand = (dir, context) => {
|
---|
| 4310 | const arg = dir.arg;
|
---|
| 4311 | const propName = camelize(arg.content);
|
---|
| 4312 | dir.exp = createSimpleExpression(propName, false, arg.loc);
|
---|
| 4313 | };
|
---|
| 4314 | const injectPrefix = (arg, prefix) => {
|
---|
| 4315 | if (arg.type === 4) {
|
---|
| 4316 | if (arg.isStatic) {
|
---|
| 4317 | arg.content = prefix + arg.content;
|
---|
| 4318 | } else {
|
---|
| 4319 | arg.content = `\`${prefix}\${${arg.content}}\``;
|
---|
| 4320 | }
|
---|
| 4321 | } else {
|
---|
| 4322 | arg.children.unshift(`'${prefix}' + (`);
|
---|
| 4323 | arg.children.push(`)`);
|
---|
| 4324 | }
|
---|
| 4325 | };
|
---|
| 4326 |
|
---|
| 4327 | const transformFor = createStructuralDirectiveTransform(
|
---|
| 4328 | "for",
|
---|
| 4329 | (node, dir, context) => {
|
---|
| 4330 | const { helper, removeHelper } = context;
|
---|
| 4331 | return processFor(node, dir, context, (forNode) => {
|
---|
| 4332 | const renderExp = createCallExpression(helper(RENDER_LIST), [
|
---|
| 4333 | forNode.source
|
---|
| 4334 | ]);
|
---|
| 4335 | const isTemplate = isTemplateNode(node);
|
---|
| 4336 | const memo = findDir(node, "memo");
|
---|
| 4337 | const keyProp = findProp(node, `key`, false, true);
|
---|
| 4338 | const isDirKey = keyProp && keyProp.type === 7;
|
---|
| 4339 | if (isDirKey && !keyProp.exp) {
|
---|
| 4340 | transformBindShorthand(keyProp);
|
---|
| 4341 | }
|
---|
| 4342 | let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
---|
| 4343 | const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
|
---|
| 4344 | const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
---|
| 4345 | const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
---|
| 4346 | forNode.codegenNode = createVNodeCall(
|
---|
| 4347 | context,
|
---|
| 4348 | helper(FRAGMENT),
|
---|
| 4349 | void 0,
|
---|
| 4350 | renderExp,
|
---|
| 4351 | fragmentFlag,
|
---|
| 4352 | void 0,
|
---|
| 4353 | void 0,
|
---|
| 4354 | true,
|
---|
| 4355 | !isStableFragment,
|
---|
| 4356 | false,
|
---|
| 4357 | node.loc
|
---|
| 4358 | );
|
---|
| 4359 | return () => {
|
---|
| 4360 | let childBlock;
|
---|
| 4361 | const { children } = forNode;
|
---|
| 4362 | if (isTemplate) {
|
---|
| 4363 | node.children.some((c) => {
|
---|
| 4364 | if (c.type === 1) {
|
---|
| 4365 | const key = findProp(c, "key");
|
---|
| 4366 | if (key) {
|
---|
| 4367 | context.onError(
|
---|
| 4368 | createCompilerError(
|
---|
| 4369 | 33,
|
---|
| 4370 | key.loc
|
---|
| 4371 | )
|
---|
| 4372 | );
|
---|
| 4373 | return true;
|
---|
| 4374 | }
|
---|
| 4375 | }
|
---|
| 4376 | });
|
---|
| 4377 | }
|
---|
| 4378 | const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
|
---|
| 4379 | const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
|
---|
| 4380 | if (slotOutlet) {
|
---|
| 4381 | childBlock = slotOutlet.codegenNode;
|
---|
| 4382 | if (isTemplate && keyProperty) {
|
---|
| 4383 | injectProp(childBlock, keyProperty, context);
|
---|
| 4384 | }
|
---|
| 4385 | } else if (needFragmentWrapper) {
|
---|
| 4386 | childBlock = createVNodeCall(
|
---|
| 4387 | context,
|
---|
| 4388 | helper(FRAGMENT),
|
---|
| 4389 | keyProperty ? createObjectExpression([keyProperty]) : void 0,
|
---|
| 4390 | node.children,
|
---|
| 4391 | 64,
|
---|
| 4392 | void 0,
|
---|
| 4393 | void 0,
|
---|
| 4394 | true,
|
---|
| 4395 | void 0,
|
---|
| 4396 | false
|
---|
| 4397 | );
|
---|
| 4398 | } else {
|
---|
| 4399 | childBlock = children[0].codegenNode;
|
---|
| 4400 | if (isTemplate && keyProperty) {
|
---|
| 4401 | injectProp(childBlock, keyProperty, context);
|
---|
| 4402 | }
|
---|
| 4403 | if (childBlock.isBlock !== !isStableFragment) {
|
---|
| 4404 | if (childBlock.isBlock) {
|
---|
| 4405 | removeHelper(OPEN_BLOCK);
|
---|
| 4406 | removeHelper(
|
---|
| 4407 | getVNodeBlockHelper(context.inSSR, childBlock.isComponent)
|
---|
| 4408 | );
|
---|
| 4409 | } else {
|
---|
| 4410 | removeHelper(
|
---|
| 4411 | getVNodeHelper(context.inSSR, childBlock.isComponent)
|
---|
| 4412 | );
|
---|
| 4413 | }
|
---|
| 4414 | }
|
---|
| 4415 | childBlock.isBlock = !isStableFragment;
|
---|
| 4416 | if (childBlock.isBlock) {
|
---|
| 4417 | helper(OPEN_BLOCK);
|
---|
| 4418 | helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
|
---|
| 4419 | } else {
|
---|
| 4420 | helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
|
---|
| 4421 | }
|
---|
| 4422 | }
|
---|
| 4423 | if (memo) {
|
---|
| 4424 | const loop = createFunctionExpression(
|
---|
| 4425 | createForLoopParams(forNode.parseResult, [
|
---|
| 4426 | createSimpleExpression(`_cached`)
|
---|
| 4427 | ])
|
---|
| 4428 | );
|
---|
| 4429 | loop.body = createBlockStatement([
|
---|
| 4430 | createCompoundExpression([`const _memo = (`, memo.exp, `)`]),
|
---|
| 4431 | createCompoundExpression([
|
---|
| 4432 | `if (_cached`,
|
---|
| 4433 | ...keyExp ? [` && _cached.key === `, keyExp] : [],
|
---|
| 4434 | ` && ${context.helperString(
|
---|
| 4435 | IS_MEMO_SAME
|
---|
| 4436 | )}(_cached, _memo)) return _cached`
|
---|
| 4437 | ]),
|
---|
| 4438 | createCompoundExpression([`const _item = `, childBlock]),
|
---|
| 4439 | createSimpleExpression(`_item.memo = _memo`),
|
---|
| 4440 | createSimpleExpression(`return _item`)
|
---|
| 4441 | ]);
|
---|
| 4442 | renderExp.arguments.push(
|
---|
| 4443 | loop,
|
---|
| 4444 | createSimpleExpression(`_cache`),
|
---|
| 4445 | createSimpleExpression(String(context.cached.length))
|
---|
| 4446 | );
|
---|
| 4447 | context.cached.push(null);
|
---|
| 4448 | } else {
|
---|
| 4449 | renderExp.arguments.push(
|
---|
| 4450 | createFunctionExpression(
|
---|
| 4451 | createForLoopParams(forNode.parseResult),
|
---|
| 4452 | childBlock,
|
---|
| 4453 | true
|
---|
| 4454 | )
|
---|
| 4455 | );
|
---|
| 4456 | }
|
---|
| 4457 | };
|
---|
| 4458 | });
|
---|
| 4459 | }
|
---|
| 4460 | );
|
---|
| 4461 | function processFor(node, dir, context, processCodegen) {
|
---|
| 4462 | if (!dir.exp) {
|
---|
| 4463 | context.onError(
|
---|
| 4464 | createCompilerError(31, dir.loc)
|
---|
| 4465 | );
|
---|
| 4466 | return;
|
---|
| 4467 | }
|
---|
| 4468 | const parseResult = dir.forParseResult;
|
---|
| 4469 | if (!parseResult) {
|
---|
| 4470 | context.onError(
|
---|
| 4471 | createCompilerError(32, dir.loc)
|
---|
| 4472 | );
|
---|
| 4473 | return;
|
---|
| 4474 | }
|
---|
| 4475 | finalizeForParseResult(parseResult, context);
|
---|
| 4476 | const { addIdentifiers, removeIdentifiers, scopes } = context;
|
---|
| 4477 | const { source, value, key, index } = parseResult;
|
---|
| 4478 | const forNode = {
|
---|
| 4479 | type: 11,
|
---|
| 4480 | loc: dir.loc,
|
---|
| 4481 | source,
|
---|
| 4482 | valueAlias: value,
|
---|
| 4483 | keyAlias: key,
|
---|
| 4484 | objectIndexAlias: index,
|
---|
| 4485 | parseResult,
|
---|
| 4486 | children: isTemplateNode(node) ? node.children : [node]
|
---|
| 4487 | };
|
---|
| 4488 | context.replaceNode(forNode);
|
---|
| 4489 | scopes.vFor++;
|
---|
| 4490 | const onExit = processCodegen && processCodegen(forNode);
|
---|
| 4491 | return () => {
|
---|
| 4492 | scopes.vFor--;
|
---|
| 4493 | if (onExit) onExit();
|
---|
| 4494 | };
|
---|
| 4495 | }
|
---|
| 4496 | function finalizeForParseResult(result, context) {
|
---|
| 4497 | if (result.finalized) return;
|
---|
| 4498 | {
|
---|
| 4499 | validateBrowserExpression(result.source, context);
|
---|
| 4500 | if (result.key) {
|
---|
| 4501 | validateBrowserExpression(
|
---|
| 4502 | result.key,
|
---|
| 4503 | context,
|
---|
| 4504 | true
|
---|
| 4505 | );
|
---|
| 4506 | }
|
---|
| 4507 | if (result.index) {
|
---|
| 4508 | validateBrowserExpression(
|
---|
| 4509 | result.index,
|
---|
| 4510 | context,
|
---|
| 4511 | true
|
---|
| 4512 | );
|
---|
| 4513 | }
|
---|
| 4514 | if (result.value) {
|
---|
| 4515 | validateBrowserExpression(
|
---|
| 4516 | result.value,
|
---|
| 4517 | context,
|
---|
| 4518 | true
|
---|
| 4519 | );
|
---|
| 4520 | }
|
---|
| 4521 | }
|
---|
| 4522 | result.finalized = true;
|
---|
| 4523 | }
|
---|
| 4524 | function createForLoopParams({ value, key, index }, memoArgs = []) {
|
---|
| 4525 | return createParamsList([value, key, index, ...memoArgs]);
|
---|
| 4526 | }
|
---|
| 4527 | function createParamsList(args) {
|
---|
| 4528 | let i = args.length;
|
---|
| 4529 | while (i--) {
|
---|
| 4530 | if (args[i]) break;
|
---|
| 4531 | }
|
---|
| 4532 | return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
|
---|
| 4533 | }
|
---|
| 4534 |
|
---|
| 4535 | const defaultFallback = createSimpleExpression(`undefined`, false);
|
---|
| 4536 | const trackSlotScopes = (node, context) => {
|
---|
| 4537 | if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
|
---|
| 4538 | const vSlot = findDir(node, "slot");
|
---|
| 4539 | if (vSlot) {
|
---|
| 4540 | vSlot.exp;
|
---|
| 4541 | context.scopes.vSlot++;
|
---|
| 4542 | return () => {
|
---|
| 4543 | context.scopes.vSlot--;
|
---|
| 4544 | };
|
---|
| 4545 | }
|
---|
| 4546 | }
|
---|
| 4547 | };
|
---|
| 4548 | const trackVForSlotScopes = (node, context) => {
|
---|
| 4549 | let vFor;
|
---|
| 4550 | if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
|
---|
| 4551 | const result = vFor.forParseResult;
|
---|
| 4552 | if (result) {
|
---|
| 4553 | finalizeForParseResult(result, context);
|
---|
| 4554 | const { value, key, index } = result;
|
---|
| 4555 | const { addIdentifiers, removeIdentifiers } = context;
|
---|
| 4556 | value && addIdentifiers(value);
|
---|
| 4557 | key && addIdentifiers(key);
|
---|
| 4558 | index && addIdentifiers(index);
|
---|
| 4559 | return () => {
|
---|
| 4560 | value && removeIdentifiers(value);
|
---|
| 4561 | key && removeIdentifiers(key);
|
---|
| 4562 | index && removeIdentifiers(index);
|
---|
| 4563 | };
|
---|
| 4564 | }
|
---|
| 4565 | }
|
---|
| 4566 | };
|
---|
| 4567 | const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(
|
---|
| 4568 | props,
|
---|
| 4569 | children,
|
---|
| 4570 | false,
|
---|
| 4571 | true,
|
---|
| 4572 | children.length ? children[0].loc : loc
|
---|
| 4573 | );
|
---|
| 4574 | function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
---|
| 4575 | context.helper(WITH_CTX);
|
---|
| 4576 | const { children, loc } = node;
|
---|
| 4577 | const slotsProperties = [];
|
---|
| 4578 | const dynamicSlots = [];
|
---|
| 4579 | let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
|
---|
| 4580 | const onComponentSlot = findDir(node, "slot", true);
|
---|
| 4581 | if (onComponentSlot) {
|
---|
| 4582 | const { arg, exp } = onComponentSlot;
|
---|
| 4583 | if (arg && !isStaticExp(arg)) {
|
---|
| 4584 | hasDynamicSlots = true;
|
---|
| 4585 | }
|
---|
| 4586 | slotsProperties.push(
|
---|
| 4587 | createObjectProperty(
|
---|
| 4588 | arg || createSimpleExpression("default", true),
|
---|
| 4589 | buildSlotFn(exp, void 0, children, loc)
|
---|
| 4590 | )
|
---|
| 4591 | );
|
---|
| 4592 | }
|
---|
| 4593 | let hasTemplateSlots = false;
|
---|
| 4594 | let hasNamedDefaultSlot = false;
|
---|
| 4595 | const implicitDefaultChildren = [];
|
---|
| 4596 | const seenSlotNames = /* @__PURE__ */ new Set();
|
---|
| 4597 | let conditionalBranchIndex = 0;
|
---|
| 4598 | for (let i = 0; i < children.length; i++) {
|
---|
| 4599 | const slotElement = children[i];
|
---|
| 4600 | let slotDir;
|
---|
| 4601 | if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
|
---|
| 4602 | if (slotElement.type !== 3) {
|
---|
| 4603 | implicitDefaultChildren.push(slotElement);
|
---|
| 4604 | }
|
---|
| 4605 | continue;
|
---|
| 4606 | }
|
---|
| 4607 | if (onComponentSlot) {
|
---|
| 4608 | context.onError(
|
---|
| 4609 | createCompilerError(37, slotDir.loc)
|
---|
| 4610 | );
|
---|
| 4611 | break;
|
---|
| 4612 | }
|
---|
| 4613 | hasTemplateSlots = true;
|
---|
| 4614 | const { children: slotChildren, loc: slotLoc } = slotElement;
|
---|
| 4615 | const {
|
---|
| 4616 | arg: slotName = createSimpleExpression(`default`, true),
|
---|
| 4617 | exp: slotProps,
|
---|
| 4618 | loc: dirLoc
|
---|
| 4619 | } = slotDir;
|
---|
| 4620 | let staticSlotName;
|
---|
| 4621 | if (isStaticExp(slotName)) {
|
---|
| 4622 | staticSlotName = slotName ? slotName.content : `default`;
|
---|
| 4623 | } else {
|
---|
| 4624 | hasDynamicSlots = true;
|
---|
| 4625 | }
|
---|
| 4626 | const vFor = findDir(slotElement, "for");
|
---|
| 4627 | const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
|
---|
| 4628 | let vIf;
|
---|
| 4629 | let vElse;
|
---|
| 4630 | if (vIf = findDir(slotElement, "if")) {
|
---|
| 4631 | hasDynamicSlots = true;
|
---|
| 4632 | dynamicSlots.push(
|
---|
| 4633 | createConditionalExpression(
|
---|
| 4634 | vIf.exp,
|
---|
| 4635 | buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++),
|
---|
| 4636 | defaultFallback
|
---|
| 4637 | )
|
---|
| 4638 | );
|
---|
| 4639 | } else if (vElse = findDir(
|
---|
| 4640 | slotElement,
|
---|
| 4641 | /^else(-if)?$/,
|
---|
| 4642 | true
|
---|
| 4643 | /* allowEmpty */
|
---|
| 4644 | )) {
|
---|
| 4645 | let j = i;
|
---|
| 4646 | let prev;
|
---|
| 4647 | while (j--) {
|
---|
| 4648 | prev = children[j];
|
---|
| 4649 | if (prev.type !== 3) {
|
---|
| 4650 | break;
|
---|
| 4651 | }
|
---|
| 4652 | }
|
---|
| 4653 | if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
|
---|
| 4654 | let conditional = dynamicSlots[dynamicSlots.length - 1];
|
---|
| 4655 | while (conditional.alternate.type === 19) {
|
---|
| 4656 | conditional = conditional.alternate;
|
---|
| 4657 | }
|
---|
| 4658 | conditional.alternate = vElse.exp ? createConditionalExpression(
|
---|
| 4659 | vElse.exp,
|
---|
| 4660 | buildDynamicSlot(
|
---|
| 4661 | slotName,
|
---|
| 4662 | slotFunction,
|
---|
| 4663 | conditionalBranchIndex++
|
---|
| 4664 | ),
|
---|
| 4665 | defaultFallback
|
---|
| 4666 | ) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
---|
| 4667 | } else {
|
---|
| 4668 | context.onError(
|
---|
| 4669 | createCompilerError(30, vElse.loc)
|
---|
| 4670 | );
|
---|
| 4671 | }
|
---|
| 4672 | } else if (vFor) {
|
---|
| 4673 | hasDynamicSlots = true;
|
---|
| 4674 | const parseResult = vFor.forParseResult;
|
---|
| 4675 | if (parseResult) {
|
---|
| 4676 | finalizeForParseResult(parseResult, context);
|
---|
| 4677 | dynamicSlots.push(
|
---|
| 4678 | createCallExpression(context.helper(RENDER_LIST), [
|
---|
| 4679 | parseResult.source,
|
---|
| 4680 | createFunctionExpression(
|
---|
| 4681 | createForLoopParams(parseResult),
|
---|
| 4682 | buildDynamicSlot(slotName, slotFunction),
|
---|
| 4683 | true
|
---|
| 4684 | )
|
---|
| 4685 | ])
|
---|
| 4686 | );
|
---|
| 4687 | } else {
|
---|
| 4688 | context.onError(
|
---|
| 4689 | createCompilerError(
|
---|
| 4690 | 32,
|
---|
| 4691 | vFor.loc
|
---|
| 4692 | )
|
---|
| 4693 | );
|
---|
| 4694 | }
|
---|
| 4695 | } else {
|
---|
| 4696 | if (staticSlotName) {
|
---|
| 4697 | if (seenSlotNames.has(staticSlotName)) {
|
---|
| 4698 | context.onError(
|
---|
| 4699 | createCompilerError(
|
---|
| 4700 | 38,
|
---|
| 4701 | dirLoc
|
---|
| 4702 | )
|
---|
| 4703 | );
|
---|
| 4704 | continue;
|
---|
| 4705 | }
|
---|
| 4706 | seenSlotNames.add(staticSlotName);
|
---|
| 4707 | if (staticSlotName === "default") {
|
---|
| 4708 | hasNamedDefaultSlot = true;
|
---|
| 4709 | }
|
---|
| 4710 | }
|
---|
| 4711 | slotsProperties.push(createObjectProperty(slotName, slotFunction));
|
---|
| 4712 | }
|
---|
| 4713 | }
|
---|
| 4714 | if (!onComponentSlot) {
|
---|
| 4715 | const buildDefaultSlotProperty = (props, children2) => {
|
---|
| 4716 | const fn = buildSlotFn(props, void 0, children2, loc);
|
---|
| 4717 | if (context.compatConfig) {
|
---|
| 4718 | fn.isNonScopedSlot = true;
|
---|
| 4719 | }
|
---|
| 4720 | return createObjectProperty(`default`, fn);
|
---|
| 4721 | };
|
---|
| 4722 | if (!hasTemplateSlots) {
|
---|
| 4723 | slotsProperties.push(buildDefaultSlotProperty(void 0, children));
|
---|
| 4724 | } else if (implicitDefaultChildren.length && // #3766
|
---|
| 4725 | // with whitespace: 'preserve', whitespaces between slots will end up in
|
---|
| 4726 | // implicitDefaultChildren. Ignore if all implicit children are whitespaces.
|
---|
| 4727 | implicitDefaultChildren.some((node2) => isNonWhitespaceContent(node2))) {
|
---|
| 4728 | if (hasNamedDefaultSlot) {
|
---|
| 4729 | context.onError(
|
---|
| 4730 | createCompilerError(
|
---|
| 4731 | 39,
|
---|
| 4732 | implicitDefaultChildren[0].loc
|
---|
| 4733 | )
|
---|
| 4734 | );
|
---|
| 4735 | } else {
|
---|
| 4736 | slotsProperties.push(
|
---|
| 4737 | buildDefaultSlotProperty(void 0, implicitDefaultChildren)
|
---|
| 4738 | );
|
---|
| 4739 | }
|
---|
| 4740 | }
|
---|
| 4741 | }
|
---|
| 4742 | const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
|
---|
| 4743 | let slots = createObjectExpression(
|
---|
| 4744 | slotsProperties.concat(
|
---|
| 4745 | createObjectProperty(
|
---|
| 4746 | `_`,
|
---|
| 4747 | // 2 = compiled but dynamic = can skip normalization, but must run diff
|
---|
| 4748 | // 1 = compiled and static = can skip normalization AND diff as optimized
|
---|
| 4749 | createSimpleExpression(
|
---|
| 4750 | slotFlag + (` /* ${slotFlagsText[slotFlag]} */` ),
|
---|
| 4751 | false
|
---|
| 4752 | )
|
---|
| 4753 | )
|
---|
| 4754 | ),
|
---|
| 4755 | loc
|
---|
| 4756 | );
|
---|
| 4757 | if (dynamicSlots.length) {
|
---|
| 4758 | slots = createCallExpression(context.helper(CREATE_SLOTS), [
|
---|
| 4759 | slots,
|
---|
| 4760 | createArrayExpression(dynamicSlots)
|
---|
| 4761 | ]);
|
---|
| 4762 | }
|
---|
| 4763 | return {
|
---|
| 4764 | slots,
|
---|
| 4765 | hasDynamicSlots
|
---|
| 4766 | };
|
---|
| 4767 | }
|
---|
| 4768 | function buildDynamicSlot(name, fn, index) {
|
---|
| 4769 | const props = [
|
---|
| 4770 | createObjectProperty(`name`, name),
|
---|
| 4771 | createObjectProperty(`fn`, fn)
|
---|
| 4772 | ];
|
---|
| 4773 | if (index != null) {
|
---|
| 4774 | props.push(
|
---|
| 4775 | createObjectProperty(`key`, createSimpleExpression(String(index), true))
|
---|
| 4776 | );
|
---|
| 4777 | }
|
---|
| 4778 | return createObjectExpression(props);
|
---|
| 4779 | }
|
---|
| 4780 | function hasForwardedSlots(children) {
|
---|
| 4781 | for (let i = 0; i < children.length; i++) {
|
---|
| 4782 | const child = children[i];
|
---|
| 4783 | switch (child.type) {
|
---|
| 4784 | case 1:
|
---|
| 4785 | if (child.tagType === 2 || hasForwardedSlots(child.children)) {
|
---|
| 4786 | return true;
|
---|
| 4787 | }
|
---|
| 4788 | break;
|
---|
| 4789 | case 9:
|
---|
| 4790 | if (hasForwardedSlots(child.branches)) return true;
|
---|
| 4791 | break;
|
---|
| 4792 | case 10:
|
---|
| 4793 | case 11:
|
---|
| 4794 | if (hasForwardedSlots(child.children)) return true;
|
---|
| 4795 | break;
|
---|
| 4796 | }
|
---|
| 4797 | }
|
---|
| 4798 | return false;
|
---|
| 4799 | }
|
---|
| 4800 | function isNonWhitespaceContent(node) {
|
---|
| 4801 | if (node.type !== 2 && node.type !== 12)
|
---|
| 4802 | return true;
|
---|
| 4803 | return node.type === 2 ? !!node.content.trim() : isNonWhitespaceContent(node.content);
|
---|
| 4804 | }
|
---|
| 4805 |
|
---|
| 4806 | const directiveImportMap = /* @__PURE__ */ new WeakMap();
|
---|
| 4807 | const transformElement = (node, context) => {
|
---|
| 4808 | return function postTransformElement() {
|
---|
| 4809 | node = context.currentNode;
|
---|
| 4810 | if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) {
|
---|
| 4811 | return;
|
---|
| 4812 | }
|
---|
| 4813 | const { tag, props } = node;
|
---|
| 4814 | const isComponent = node.tagType === 1;
|
---|
| 4815 | let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
|
---|
| 4816 | const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
---|
| 4817 | let vnodeProps;
|
---|
| 4818 | let vnodeChildren;
|
---|
| 4819 | let patchFlag = 0;
|
---|
| 4820 | let vnodeDynamicProps;
|
---|
| 4821 | let dynamicPropNames;
|
---|
| 4822 | let vnodeDirectives;
|
---|
| 4823 | let shouldUseBlock = (
|
---|
| 4824 | // dynamic component may resolve to plain elements
|
---|
| 4825 | isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && // <svg> and <foreignObject> must be forced into blocks so that block
|
---|
| 4826 | // updates inside get proper isSVG flag at runtime. (#639, #643)
|
---|
| 4827 | // This is technically web-specific, but splitting the logic out of core
|
---|
| 4828 | // leads to too much unnecessary complexity.
|
---|
| 4829 | (tag === "svg" || tag === "foreignObject" || tag === "math")
|
---|
| 4830 | );
|
---|
| 4831 | if (props.length > 0) {
|
---|
| 4832 | const propsBuildResult = buildProps(
|
---|
| 4833 | node,
|
---|
| 4834 | context,
|
---|
| 4835 | void 0,
|
---|
| 4836 | isComponent,
|
---|
| 4837 | isDynamicComponent
|
---|
| 4838 | );
|
---|
| 4839 | vnodeProps = propsBuildResult.props;
|
---|
| 4840 | patchFlag = propsBuildResult.patchFlag;
|
---|
| 4841 | dynamicPropNames = propsBuildResult.dynamicPropNames;
|
---|
| 4842 | const directives = propsBuildResult.directives;
|
---|
| 4843 | vnodeDirectives = directives && directives.length ? createArrayExpression(
|
---|
| 4844 | directives.map((dir) => buildDirectiveArgs(dir, context))
|
---|
| 4845 | ) : void 0;
|
---|
| 4846 | if (propsBuildResult.shouldUseBlock) {
|
---|
| 4847 | shouldUseBlock = true;
|
---|
| 4848 | }
|
---|
| 4849 | }
|
---|
| 4850 | if (node.children.length > 0) {
|
---|
| 4851 | if (vnodeTag === KEEP_ALIVE) {
|
---|
| 4852 | shouldUseBlock = true;
|
---|
| 4853 | patchFlag |= 1024;
|
---|
| 4854 | if (node.children.length > 1) {
|
---|
| 4855 | context.onError(
|
---|
| 4856 | createCompilerError(46, {
|
---|
| 4857 | start: node.children[0].loc.start,
|
---|
| 4858 | end: node.children[node.children.length - 1].loc.end,
|
---|
| 4859 | source: ""
|
---|
| 4860 | })
|
---|
| 4861 | );
|
---|
| 4862 | }
|
---|
| 4863 | }
|
---|
| 4864 | const shouldBuildAsSlots = isComponent && // Teleport is not a real component and has dedicated runtime handling
|
---|
| 4865 | vnodeTag !== TELEPORT && // explained above.
|
---|
| 4866 | vnodeTag !== KEEP_ALIVE;
|
---|
| 4867 | if (shouldBuildAsSlots) {
|
---|
| 4868 | const { slots, hasDynamicSlots } = buildSlots(node, context);
|
---|
| 4869 | vnodeChildren = slots;
|
---|
| 4870 | if (hasDynamicSlots) {
|
---|
| 4871 | patchFlag |= 1024;
|
---|
| 4872 | }
|
---|
| 4873 | } else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
---|
| 4874 | const child = node.children[0];
|
---|
| 4875 | const type = child.type;
|
---|
| 4876 | const hasDynamicTextChild = type === 5 || type === 8;
|
---|
| 4877 | if (hasDynamicTextChild && getConstantType(child, context) === 0) {
|
---|
| 4878 | patchFlag |= 1;
|
---|
| 4879 | }
|
---|
| 4880 | if (hasDynamicTextChild || type === 2) {
|
---|
| 4881 | vnodeChildren = child;
|
---|
| 4882 | } else {
|
---|
| 4883 | vnodeChildren = node.children;
|
---|
| 4884 | }
|
---|
| 4885 | } else {
|
---|
| 4886 | vnodeChildren = node.children;
|
---|
| 4887 | }
|
---|
| 4888 | }
|
---|
| 4889 | if (dynamicPropNames && dynamicPropNames.length) {
|
---|
| 4890 | vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
---|
| 4891 | }
|
---|
| 4892 | node.codegenNode = createVNodeCall(
|
---|
| 4893 | context,
|
---|
| 4894 | vnodeTag,
|
---|
| 4895 | vnodeProps,
|
---|
| 4896 | vnodeChildren,
|
---|
| 4897 | patchFlag === 0 ? void 0 : patchFlag,
|
---|
| 4898 | vnodeDynamicProps,
|
---|
| 4899 | vnodeDirectives,
|
---|
| 4900 | !!shouldUseBlock,
|
---|
| 4901 | false,
|
---|
| 4902 | isComponent,
|
---|
| 4903 | node.loc
|
---|
| 4904 | );
|
---|
| 4905 | };
|
---|
| 4906 | };
|
---|
| 4907 | function resolveComponentType(node, context, ssr = false) {
|
---|
| 4908 | let { tag } = node;
|
---|
| 4909 | const isExplicitDynamic = isComponentTag(tag);
|
---|
| 4910 | const isProp = findProp(
|
---|
| 4911 | node,
|
---|
| 4912 | "is",
|
---|
| 4913 | false,
|
---|
| 4914 | true
|
---|
| 4915 | /* allow empty */
|
---|
| 4916 | );
|
---|
| 4917 | if (isProp) {
|
---|
| 4918 | if (isExplicitDynamic || isCompatEnabled(
|
---|
| 4919 | "COMPILER_IS_ON_ELEMENT",
|
---|
| 4920 | context
|
---|
| 4921 | )) {
|
---|
| 4922 | let exp;
|
---|
| 4923 | if (isProp.type === 6) {
|
---|
| 4924 | exp = isProp.value && createSimpleExpression(isProp.value.content, true);
|
---|
| 4925 | } else {
|
---|
| 4926 | exp = isProp.exp;
|
---|
| 4927 | if (!exp) {
|
---|
| 4928 | exp = createSimpleExpression(`is`, false, isProp.arg.loc);
|
---|
| 4929 | }
|
---|
| 4930 | }
|
---|
| 4931 | if (exp) {
|
---|
| 4932 | return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [
|
---|
| 4933 | exp
|
---|
| 4934 | ]);
|
---|
| 4935 | }
|
---|
| 4936 | } else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) {
|
---|
| 4937 | tag = isProp.value.content.slice(4);
|
---|
| 4938 | }
|
---|
| 4939 | }
|
---|
| 4940 | const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
---|
| 4941 | if (builtIn) {
|
---|
| 4942 | if (!ssr) context.helper(builtIn);
|
---|
| 4943 | return builtIn;
|
---|
| 4944 | }
|
---|
| 4945 | context.helper(RESOLVE_COMPONENT);
|
---|
| 4946 | context.components.add(tag);
|
---|
| 4947 | return toValidAssetId(tag, `component`);
|
---|
| 4948 | }
|
---|
| 4949 | function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
|
---|
| 4950 | const { tag, loc: elementLoc, children } = node;
|
---|
| 4951 | let properties = [];
|
---|
| 4952 | const mergeArgs = [];
|
---|
| 4953 | const runtimeDirectives = [];
|
---|
| 4954 | const hasChildren = children.length > 0;
|
---|
| 4955 | let shouldUseBlock = false;
|
---|
| 4956 | let patchFlag = 0;
|
---|
| 4957 | let hasRef = false;
|
---|
| 4958 | let hasClassBinding = false;
|
---|
| 4959 | let hasStyleBinding = false;
|
---|
| 4960 | let hasHydrationEventBinding = false;
|
---|
| 4961 | let hasDynamicKeys = false;
|
---|
| 4962 | let hasVnodeHook = false;
|
---|
| 4963 | const dynamicPropNames = [];
|
---|
| 4964 | const pushMergeArg = (arg) => {
|
---|
| 4965 | if (properties.length) {
|
---|
| 4966 | mergeArgs.push(
|
---|
| 4967 | createObjectExpression(dedupeProperties(properties), elementLoc)
|
---|
| 4968 | );
|
---|
| 4969 | properties = [];
|
---|
| 4970 | }
|
---|
| 4971 | if (arg) mergeArgs.push(arg);
|
---|
| 4972 | };
|
---|
| 4973 | const pushRefVForMarker = () => {
|
---|
| 4974 | if (context.scopes.vFor > 0) {
|
---|
| 4975 | properties.push(
|
---|
| 4976 | createObjectProperty(
|
---|
| 4977 | createSimpleExpression("ref_for", true),
|
---|
| 4978 | createSimpleExpression("true")
|
---|
| 4979 | )
|
---|
| 4980 | );
|
---|
| 4981 | }
|
---|
| 4982 | };
|
---|
| 4983 | const analyzePatchFlag = ({ key, value }) => {
|
---|
| 4984 | if (isStaticExp(key)) {
|
---|
| 4985 | const name = key.content;
|
---|
| 4986 | const isEventHandler = isOn(name);
|
---|
| 4987 | if (isEventHandler && (!isComponent || isDynamicComponent) && // omit the flag for click handlers because hydration gives click
|
---|
| 4988 | // dedicated fast path.
|
---|
| 4989 | name.toLowerCase() !== "onclick" && // omit v-model handlers
|
---|
| 4990 | name !== "onUpdate:modelValue" && // omit onVnodeXXX hooks
|
---|
| 4991 | !isReservedProp(name)) {
|
---|
| 4992 | hasHydrationEventBinding = true;
|
---|
| 4993 | }
|
---|
| 4994 | if (isEventHandler && isReservedProp(name)) {
|
---|
| 4995 | hasVnodeHook = true;
|
---|
| 4996 | }
|
---|
| 4997 | if (isEventHandler && value.type === 14) {
|
---|
| 4998 | value = value.arguments[0];
|
---|
| 4999 | }
|
---|
| 5000 | if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) {
|
---|
| 5001 | return;
|
---|
| 5002 | }
|
---|
| 5003 | if (name === "ref") {
|
---|
| 5004 | hasRef = true;
|
---|
| 5005 | } else if (name === "class") {
|
---|
| 5006 | hasClassBinding = true;
|
---|
| 5007 | } else if (name === "style") {
|
---|
| 5008 | hasStyleBinding = true;
|
---|
| 5009 | } else if (name !== "key" && !dynamicPropNames.includes(name)) {
|
---|
| 5010 | dynamicPropNames.push(name);
|
---|
| 5011 | }
|
---|
| 5012 | if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) {
|
---|
| 5013 | dynamicPropNames.push(name);
|
---|
| 5014 | }
|
---|
| 5015 | } else {
|
---|
| 5016 | hasDynamicKeys = true;
|
---|
| 5017 | }
|
---|
| 5018 | };
|
---|
| 5019 | for (let i = 0; i < props.length; i++) {
|
---|
| 5020 | const prop = props[i];
|
---|
| 5021 | if (prop.type === 6) {
|
---|
| 5022 | const { loc, name, nameLoc, value } = prop;
|
---|
| 5023 | let isStatic = true;
|
---|
| 5024 | if (name === "ref") {
|
---|
| 5025 | hasRef = true;
|
---|
| 5026 | pushRefVForMarker();
|
---|
| 5027 | }
|
---|
| 5028 | if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled(
|
---|
| 5029 | "COMPILER_IS_ON_ELEMENT",
|
---|
| 5030 | context
|
---|
| 5031 | ))) {
|
---|
| 5032 | continue;
|
---|
| 5033 | }
|
---|
| 5034 | properties.push(
|
---|
| 5035 | createObjectProperty(
|
---|
| 5036 | createSimpleExpression(name, true, nameLoc),
|
---|
| 5037 | createSimpleExpression(
|
---|
| 5038 | value ? value.content : "",
|
---|
| 5039 | isStatic,
|
---|
| 5040 | value ? value.loc : loc
|
---|
| 5041 | )
|
---|
| 5042 | )
|
---|
| 5043 | );
|
---|
| 5044 | } else {
|
---|
| 5045 | const { name, arg, exp, loc, modifiers } = prop;
|
---|
| 5046 | const isVBind = name === "bind";
|
---|
| 5047 | const isVOn = name === "on";
|
---|
| 5048 | if (name === "slot") {
|
---|
| 5049 | if (!isComponent) {
|
---|
| 5050 | context.onError(
|
---|
| 5051 | createCompilerError(40, loc)
|
---|
| 5052 | );
|
---|
| 5053 | }
|
---|
| 5054 | continue;
|
---|
| 5055 | }
|
---|
| 5056 | if (name === "once" || name === "memo") {
|
---|
| 5057 | continue;
|
---|
| 5058 | }
|
---|
| 5059 | if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled(
|
---|
| 5060 | "COMPILER_IS_ON_ELEMENT",
|
---|
| 5061 | context
|
---|
| 5062 | ))) {
|
---|
| 5063 | continue;
|
---|
| 5064 | }
|
---|
| 5065 | if (isVOn && ssr) {
|
---|
| 5066 | continue;
|
---|
| 5067 | }
|
---|
| 5068 | if (
|
---|
| 5069 | // #938: elements with dynamic keys should be forced into blocks
|
---|
| 5070 | isVBind && isStaticArgOf(arg, "key") || // inline before-update hooks need to force block so that it is invoked
|
---|
| 5071 | // before children
|
---|
| 5072 | isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")
|
---|
| 5073 | ) {
|
---|
| 5074 | shouldUseBlock = true;
|
---|
| 5075 | }
|
---|
| 5076 | if (isVBind && isStaticArgOf(arg, "ref")) {
|
---|
| 5077 | pushRefVForMarker();
|
---|
| 5078 | }
|
---|
| 5079 | if (!arg && (isVBind || isVOn)) {
|
---|
| 5080 | hasDynamicKeys = true;
|
---|
| 5081 | if (exp) {
|
---|
| 5082 | if (isVBind) {
|
---|
| 5083 | pushRefVForMarker();
|
---|
| 5084 | pushMergeArg();
|
---|
| 5085 | {
|
---|
| 5086 | {
|
---|
| 5087 | const hasOverridableKeys = mergeArgs.some((arg2) => {
|
---|
| 5088 | if (arg2.type === 15) {
|
---|
| 5089 | return arg2.properties.some(({ key }) => {
|
---|
| 5090 | if (key.type !== 4 || !key.isStatic) {
|
---|
| 5091 | return true;
|
---|
| 5092 | }
|
---|
| 5093 | return key.content !== "class" && key.content !== "style" && !isOn(key.content);
|
---|
| 5094 | });
|
---|
| 5095 | } else {
|
---|
| 5096 | return true;
|
---|
| 5097 | }
|
---|
| 5098 | });
|
---|
| 5099 | if (hasOverridableKeys) {
|
---|
| 5100 | checkCompatEnabled(
|
---|
| 5101 | "COMPILER_V_BIND_OBJECT_ORDER",
|
---|
| 5102 | context,
|
---|
| 5103 | loc
|
---|
| 5104 | );
|
---|
| 5105 | }
|
---|
| 5106 | }
|
---|
| 5107 | if (isCompatEnabled(
|
---|
| 5108 | "COMPILER_V_BIND_OBJECT_ORDER",
|
---|
| 5109 | context
|
---|
| 5110 | )) {
|
---|
| 5111 | mergeArgs.unshift(exp);
|
---|
| 5112 | continue;
|
---|
| 5113 | }
|
---|
| 5114 | }
|
---|
| 5115 | mergeArgs.push(exp);
|
---|
| 5116 | } else {
|
---|
| 5117 | pushMergeArg({
|
---|
| 5118 | type: 14,
|
---|
| 5119 | loc,
|
---|
| 5120 | callee: context.helper(TO_HANDLERS),
|
---|
| 5121 | arguments: isComponent ? [exp] : [exp, `true`]
|
---|
| 5122 | });
|
---|
| 5123 | }
|
---|
| 5124 | } else {
|
---|
| 5125 | context.onError(
|
---|
| 5126 | createCompilerError(
|
---|
| 5127 | isVBind ? 34 : 35,
|
---|
| 5128 | loc
|
---|
| 5129 | )
|
---|
| 5130 | );
|
---|
| 5131 | }
|
---|
| 5132 | continue;
|
---|
| 5133 | }
|
---|
| 5134 | if (isVBind && modifiers.some((mod) => mod.content === "prop")) {
|
---|
| 5135 | patchFlag |= 32;
|
---|
| 5136 | }
|
---|
| 5137 | const directiveTransform = context.directiveTransforms[name];
|
---|
| 5138 | if (directiveTransform) {
|
---|
| 5139 | const { props: props2, needRuntime } = directiveTransform(prop, node, context);
|
---|
| 5140 | !ssr && props2.forEach(analyzePatchFlag);
|
---|
| 5141 | if (isVOn && arg && !isStaticExp(arg)) {
|
---|
| 5142 | pushMergeArg(createObjectExpression(props2, elementLoc));
|
---|
| 5143 | } else {
|
---|
| 5144 | properties.push(...props2);
|
---|
| 5145 | }
|
---|
| 5146 | if (needRuntime) {
|
---|
| 5147 | runtimeDirectives.push(prop);
|
---|
| 5148 | if (isSymbol(needRuntime)) {
|
---|
| 5149 | directiveImportMap.set(prop, needRuntime);
|
---|
| 5150 | }
|
---|
| 5151 | }
|
---|
| 5152 | } else if (!isBuiltInDirective(name)) {
|
---|
| 5153 | runtimeDirectives.push(prop);
|
---|
| 5154 | if (hasChildren) {
|
---|
| 5155 | shouldUseBlock = true;
|
---|
| 5156 | }
|
---|
| 5157 | }
|
---|
| 5158 | }
|
---|
| 5159 | }
|
---|
| 5160 | let propsExpression = void 0;
|
---|
| 5161 | if (mergeArgs.length) {
|
---|
| 5162 | pushMergeArg();
|
---|
| 5163 | if (mergeArgs.length > 1) {
|
---|
| 5164 | propsExpression = createCallExpression(
|
---|
| 5165 | context.helper(MERGE_PROPS),
|
---|
| 5166 | mergeArgs,
|
---|
| 5167 | elementLoc
|
---|
| 5168 | );
|
---|
| 5169 | } else {
|
---|
| 5170 | propsExpression = mergeArgs[0];
|
---|
| 5171 | }
|
---|
| 5172 | } else if (properties.length) {
|
---|
| 5173 | propsExpression = createObjectExpression(
|
---|
| 5174 | dedupeProperties(properties),
|
---|
| 5175 | elementLoc
|
---|
| 5176 | );
|
---|
| 5177 | }
|
---|
| 5178 | if (hasDynamicKeys) {
|
---|
| 5179 | patchFlag |= 16;
|
---|
| 5180 | } else {
|
---|
| 5181 | if (hasClassBinding && !isComponent) {
|
---|
| 5182 | patchFlag |= 2;
|
---|
| 5183 | }
|
---|
| 5184 | if (hasStyleBinding && !isComponent) {
|
---|
| 5185 | patchFlag |= 4;
|
---|
| 5186 | }
|
---|
| 5187 | if (dynamicPropNames.length) {
|
---|
| 5188 | patchFlag |= 8;
|
---|
| 5189 | }
|
---|
| 5190 | if (hasHydrationEventBinding) {
|
---|
| 5191 | patchFlag |= 32;
|
---|
| 5192 | }
|
---|
| 5193 | }
|
---|
| 5194 | if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) {
|
---|
| 5195 | patchFlag |= 512;
|
---|
| 5196 | }
|
---|
| 5197 | if (!context.inSSR && propsExpression) {
|
---|
| 5198 | switch (propsExpression.type) {
|
---|
| 5199 | case 15:
|
---|
| 5200 | let classKeyIndex = -1;
|
---|
| 5201 | let styleKeyIndex = -1;
|
---|
| 5202 | let hasDynamicKey = false;
|
---|
| 5203 | for (let i = 0; i < propsExpression.properties.length; i++) {
|
---|
| 5204 | const key = propsExpression.properties[i].key;
|
---|
| 5205 | if (isStaticExp(key)) {
|
---|
| 5206 | if (key.content === "class") {
|
---|
| 5207 | classKeyIndex = i;
|
---|
| 5208 | } else if (key.content === "style") {
|
---|
| 5209 | styleKeyIndex = i;
|
---|
| 5210 | }
|
---|
| 5211 | } else if (!key.isHandlerKey) {
|
---|
| 5212 | hasDynamicKey = true;
|
---|
| 5213 | }
|
---|
| 5214 | }
|
---|
| 5215 | const classProp = propsExpression.properties[classKeyIndex];
|
---|
| 5216 | const styleProp = propsExpression.properties[styleKeyIndex];
|
---|
| 5217 | if (!hasDynamicKey) {
|
---|
| 5218 | if (classProp && !isStaticExp(classProp.value)) {
|
---|
| 5219 | classProp.value = createCallExpression(
|
---|
| 5220 | context.helper(NORMALIZE_CLASS),
|
---|
| 5221 | [classProp.value]
|
---|
| 5222 | );
|
---|
| 5223 | }
|
---|
| 5224 | if (styleProp && // the static style is compiled into an object,
|
---|
| 5225 | // so use `hasStyleBinding` to ensure that it is a dynamic style binding
|
---|
| 5226 | (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || // v-bind:style and style both exist,
|
---|
| 5227 | // v-bind:style with static literal object
|
---|
| 5228 | styleProp.value.type === 17)) {
|
---|
| 5229 | styleProp.value = createCallExpression(
|
---|
| 5230 | context.helper(NORMALIZE_STYLE),
|
---|
| 5231 | [styleProp.value]
|
---|
| 5232 | );
|
---|
| 5233 | }
|
---|
| 5234 | } else {
|
---|
| 5235 | propsExpression = createCallExpression(
|
---|
| 5236 | context.helper(NORMALIZE_PROPS),
|
---|
| 5237 | [propsExpression]
|
---|
| 5238 | );
|
---|
| 5239 | }
|
---|
| 5240 | break;
|
---|
| 5241 | case 14:
|
---|
| 5242 | break;
|
---|
| 5243 | default:
|
---|
| 5244 | propsExpression = createCallExpression(
|
---|
| 5245 | context.helper(NORMALIZE_PROPS),
|
---|
| 5246 | [
|
---|
| 5247 | createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [
|
---|
| 5248 | propsExpression
|
---|
| 5249 | ])
|
---|
| 5250 | ]
|
---|
| 5251 | );
|
---|
| 5252 | break;
|
---|
| 5253 | }
|
---|
| 5254 | }
|
---|
| 5255 | return {
|
---|
| 5256 | props: propsExpression,
|
---|
| 5257 | directives: runtimeDirectives,
|
---|
| 5258 | patchFlag,
|
---|
| 5259 | dynamicPropNames,
|
---|
| 5260 | shouldUseBlock
|
---|
| 5261 | };
|
---|
| 5262 | }
|
---|
| 5263 | function dedupeProperties(properties) {
|
---|
| 5264 | const knownProps = /* @__PURE__ */ new Map();
|
---|
| 5265 | const deduped = [];
|
---|
| 5266 | for (let i = 0; i < properties.length; i++) {
|
---|
| 5267 | const prop = properties[i];
|
---|
| 5268 | if (prop.key.type === 8 || !prop.key.isStatic) {
|
---|
| 5269 | deduped.push(prop);
|
---|
| 5270 | continue;
|
---|
| 5271 | }
|
---|
| 5272 | const name = prop.key.content;
|
---|
| 5273 | const existing = knownProps.get(name);
|
---|
| 5274 | if (existing) {
|
---|
| 5275 | if (name === "style" || name === "class" || isOn(name)) {
|
---|
| 5276 | mergeAsArray(existing, prop);
|
---|
| 5277 | }
|
---|
| 5278 | } else {
|
---|
| 5279 | knownProps.set(name, prop);
|
---|
| 5280 | deduped.push(prop);
|
---|
| 5281 | }
|
---|
| 5282 | }
|
---|
| 5283 | return deduped;
|
---|
| 5284 | }
|
---|
| 5285 | function mergeAsArray(existing, incoming) {
|
---|
| 5286 | if (existing.value.type === 17) {
|
---|
| 5287 | existing.value.elements.push(incoming.value);
|
---|
| 5288 | } else {
|
---|
| 5289 | existing.value = createArrayExpression(
|
---|
| 5290 | [existing.value, incoming.value],
|
---|
| 5291 | existing.loc
|
---|
| 5292 | );
|
---|
| 5293 | }
|
---|
| 5294 | }
|
---|
| 5295 | function buildDirectiveArgs(dir, context) {
|
---|
| 5296 | const dirArgs = [];
|
---|
| 5297 | const runtime = directiveImportMap.get(dir);
|
---|
| 5298 | if (runtime) {
|
---|
| 5299 | dirArgs.push(context.helperString(runtime));
|
---|
| 5300 | } else {
|
---|
| 5301 | {
|
---|
| 5302 | context.helper(RESOLVE_DIRECTIVE);
|
---|
| 5303 | context.directives.add(dir.name);
|
---|
| 5304 | dirArgs.push(toValidAssetId(dir.name, `directive`));
|
---|
| 5305 | }
|
---|
| 5306 | }
|
---|
| 5307 | const { loc } = dir;
|
---|
| 5308 | if (dir.exp) dirArgs.push(dir.exp);
|
---|
| 5309 | if (dir.arg) {
|
---|
| 5310 | if (!dir.exp) {
|
---|
| 5311 | dirArgs.push(`void 0`);
|
---|
| 5312 | }
|
---|
| 5313 | dirArgs.push(dir.arg);
|
---|
| 5314 | }
|
---|
| 5315 | if (Object.keys(dir.modifiers).length) {
|
---|
| 5316 | if (!dir.arg) {
|
---|
| 5317 | if (!dir.exp) {
|
---|
| 5318 | dirArgs.push(`void 0`);
|
---|
| 5319 | }
|
---|
| 5320 | dirArgs.push(`void 0`);
|
---|
| 5321 | }
|
---|
| 5322 | const trueExpression = createSimpleExpression(`true`, false, loc);
|
---|
| 5323 | dirArgs.push(
|
---|
| 5324 | createObjectExpression(
|
---|
| 5325 | dir.modifiers.map(
|
---|
| 5326 | (modifier) => createObjectProperty(modifier, trueExpression)
|
---|
| 5327 | ),
|
---|
| 5328 | loc
|
---|
| 5329 | )
|
---|
| 5330 | );
|
---|
| 5331 | }
|
---|
| 5332 | return createArrayExpression(dirArgs, dir.loc);
|
---|
| 5333 | }
|
---|
| 5334 | function stringifyDynamicPropNames(props) {
|
---|
| 5335 | let propsNamesString = `[`;
|
---|
| 5336 | for (let i = 0, l = props.length; i < l; i++) {
|
---|
| 5337 | propsNamesString += JSON.stringify(props[i]);
|
---|
| 5338 | if (i < l - 1) propsNamesString += ", ";
|
---|
| 5339 | }
|
---|
| 5340 | return propsNamesString + `]`;
|
---|
| 5341 | }
|
---|
| 5342 | function isComponentTag(tag) {
|
---|
| 5343 | return tag === "component" || tag === "Component";
|
---|
| 5344 | }
|
---|
| 5345 |
|
---|
| 5346 | const transformSlotOutlet = (node, context) => {
|
---|
| 5347 | if (isSlotOutlet(node)) {
|
---|
| 5348 | const { children, loc } = node;
|
---|
| 5349 | const { slotName, slotProps } = processSlotOutlet(node, context);
|
---|
| 5350 | const slotArgs = [
|
---|
| 5351 | context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
|
---|
| 5352 | slotName,
|
---|
| 5353 | "{}",
|
---|
| 5354 | "undefined",
|
---|
| 5355 | "true"
|
---|
| 5356 | ];
|
---|
| 5357 | let expectedLen = 2;
|
---|
| 5358 | if (slotProps) {
|
---|
| 5359 | slotArgs[2] = slotProps;
|
---|
| 5360 | expectedLen = 3;
|
---|
| 5361 | }
|
---|
| 5362 | if (children.length) {
|
---|
| 5363 | slotArgs[3] = createFunctionExpression([], children, false, false, loc);
|
---|
| 5364 | expectedLen = 4;
|
---|
| 5365 | }
|
---|
| 5366 | if (context.scopeId && !context.slotted) {
|
---|
| 5367 | expectedLen = 5;
|
---|
| 5368 | }
|
---|
| 5369 | slotArgs.splice(expectedLen);
|
---|
| 5370 | node.codegenNode = createCallExpression(
|
---|
| 5371 | context.helper(RENDER_SLOT),
|
---|
| 5372 | slotArgs,
|
---|
| 5373 | loc
|
---|
| 5374 | );
|
---|
| 5375 | }
|
---|
| 5376 | };
|
---|
| 5377 | function processSlotOutlet(node, context) {
|
---|
| 5378 | let slotName = `"default"`;
|
---|
| 5379 | let slotProps = void 0;
|
---|
| 5380 | const nonNameProps = [];
|
---|
| 5381 | for (let i = 0; i < node.props.length; i++) {
|
---|
| 5382 | const p = node.props[i];
|
---|
| 5383 | if (p.type === 6) {
|
---|
| 5384 | if (p.value) {
|
---|
| 5385 | if (p.name === "name") {
|
---|
| 5386 | slotName = JSON.stringify(p.value.content);
|
---|
| 5387 | } else {
|
---|
| 5388 | p.name = camelize(p.name);
|
---|
| 5389 | nonNameProps.push(p);
|
---|
| 5390 | }
|
---|
| 5391 | }
|
---|
| 5392 | } else {
|
---|
| 5393 | if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
|
---|
| 5394 | if (p.exp) {
|
---|
| 5395 | slotName = p.exp;
|
---|
| 5396 | } else if (p.arg && p.arg.type === 4) {
|
---|
| 5397 | const name = camelize(p.arg.content);
|
---|
| 5398 | slotName = p.exp = createSimpleExpression(name, false, p.arg.loc);
|
---|
| 5399 | }
|
---|
| 5400 | } else {
|
---|
| 5401 | if (p.name === "bind" && p.arg && isStaticExp(p.arg)) {
|
---|
| 5402 | p.arg.content = camelize(p.arg.content);
|
---|
| 5403 | }
|
---|
| 5404 | nonNameProps.push(p);
|
---|
| 5405 | }
|
---|
| 5406 | }
|
---|
| 5407 | }
|
---|
| 5408 | if (nonNameProps.length > 0) {
|
---|
| 5409 | const { props, directives } = buildProps(
|
---|
| 5410 | node,
|
---|
| 5411 | context,
|
---|
| 5412 | nonNameProps,
|
---|
| 5413 | false,
|
---|
| 5414 | false
|
---|
| 5415 | );
|
---|
| 5416 | slotProps = props;
|
---|
| 5417 | if (directives.length) {
|
---|
| 5418 | context.onError(
|
---|
| 5419 | createCompilerError(
|
---|
| 5420 | 36,
|
---|
| 5421 | directives[0].loc
|
---|
| 5422 | )
|
---|
| 5423 | );
|
---|
| 5424 | }
|
---|
| 5425 | }
|
---|
| 5426 | return {
|
---|
| 5427 | slotName,
|
---|
| 5428 | slotProps
|
---|
| 5429 | };
|
---|
| 5430 | }
|
---|
| 5431 |
|
---|
| 5432 | const transformOn$1 = (dir, node, context, augmentor) => {
|
---|
| 5433 | const { loc, modifiers, arg } = dir;
|
---|
| 5434 | if (!dir.exp && !modifiers.length) {
|
---|
| 5435 | context.onError(createCompilerError(35, loc));
|
---|
| 5436 | }
|
---|
| 5437 | let eventName;
|
---|
| 5438 | if (arg.type === 4) {
|
---|
| 5439 | if (arg.isStatic) {
|
---|
| 5440 | let rawName = arg.content;
|
---|
| 5441 | if (rawName.startsWith("vnode")) {
|
---|
| 5442 | context.onError(createCompilerError(51, arg.loc));
|
---|
| 5443 | }
|
---|
| 5444 | if (rawName.startsWith("vue:")) {
|
---|
| 5445 | rawName = `vnode-${rawName.slice(4)}`;
|
---|
| 5446 | }
|
---|
| 5447 | const eventString = node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? (
|
---|
| 5448 | // for non-element and vnode lifecycle event listeners, auto convert
|
---|
| 5449 | // it to camelCase. See issue #2249
|
---|
| 5450 | toHandlerKey(camelize(rawName))
|
---|
| 5451 | ) : (
|
---|
| 5452 | // preserve case for plain element listeners that have uppercase
|
---|
| 5453 | // letters, as these may be custom elements' custom events
|
---|
| 5454 | `on:${rawName}`
|
---|
| 5455 | );
|
---|
| 5456 | eventName = createSimpleExpression(eventString, true, arg.loc);
|
---|
| 5457 | } else {
|
---|
| 5458 | eventName = createCompoundExpression([
|
---|
| 5459 | `${context.helperString(TO_HANDLER_KEY)}(`,
|
---|
| 5460 | arg,
|
---|
| 5461 | `)`
|
---|
| 5462 | ]);
|
---|
| 5463 | }
|
---|
| 5464 | } else {
|
---|
| 5465 | eventName = arg;
|
---|
| 5466 | eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
|
---|
| 5467 | eventName.children.push(`)`);
|
---|
| 5468 | }
|
---|
| 5469 | let exp = dir.exp;
|
---|
| 5470 | if (exp && !exp.content.trim()) {
|
---|
| 5471 | exp = void 0;
|
---|
| 5472 | }
|
---|
| 5473 | let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
|
---|
| 5474 | if (exp) {
|
---|
| 5475 | const isMemberExp = isMemberExpression(exp);
|
---|
| 5476 | const isInlineStatement = !(isMemberExp || isFnExpression(exp));
|
---|
| 5477 | const hasMultipleStatements = exp.content.includes(`;`);
|
---|
| 5478 | {
|
---|
| 5479 | validateBrowserExpression(
|
---|
| 5480 | exp,
|
---|
| 5481 | context,
|
---|
| 5482 | false,
|
---|
| 5483 | hasMultipleStatements
|
---|
| 5484 | );
|
---|
| 5485 | }
|
---|
| 5486 | if (isInlineStatement || shouldCache && isMemberExp) {
|
---|
| 5487 | exp = createCompoundExpression([
|
---|
| 5488 | `${isInlineStatement ? `$event` : `${``}(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
|
---|
| 5489 | exp,
|
---|
| 5490 | hasMultipleStatements ? `}` : `)`
|
---|
| 5491 | ]);
|
---|
| 5492 | }
|
---|
| 5493 | }
|
---|
| 5494 | let ret = {
|
---|
| 5495 | props: [
|
---|
| 5496 | createObjectProperty(
|
---|
| 5497 | eventName,
|
---|
| 5498 | exp || createSimpleExpression(`() => {}`, false, loc)
|
---|
| 5499 | )
|
---|
| 5500 | ]
|
---|
| 5501 | };
|
---|
| 5502 | if (augmentor) {
|
---|
| 5503 | ret = augmentor(ret);
|
---|
| 5504 | }
|
---|
| 5505 | if (shouldCache) {
|
---|
| 5506 | ret.props[0].value = context.cache(ret.props[0].value);
|
---|
| 5507 | }
|
---|
| 5508 | ret.props.forEach((p) => p.key.isHandlerKey = true);
|
---|
| 5509 | return ret;
|
---|
| 5510 | };
|
---|
| 5511 |
|
---|
| 5512 | const transformText = (node, context) => {
|
---|
| 5513 | if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
---|
| 5514 | return () => {
|
---|
| 5515 | const children = node.children;
|
---|
| 5516 | let currentContainer = void 0;
|
---|
| 5517 | let hasText = false;
|
---|
| 5518 | for (let i = 0; i < children.length; i++) {
|
---|
| 5519 | const child = children[i];
|
---|
| 5520 | if (isText$1(child)) {
|
---|
| 5521 | hasText = true;
|
---|
| 5522 | for (let j = i + 1; j < children.length; j++) {
|
---|
| 5523 | const next = children[j];
|
---|
| 5524 | if (isText$1(next)) {
|
---|
| 5525 | if (!currentContainer) {
|
---|
| 5526 | currentContainer = children[i] = createCompoundExpression(
|
---|
| 5527 | [child],
|
---|
| 5528 | child.loc
|
---|
| 5529 | );
|
---|
| 5530 | }
|
---|
| 5531 | currentContainer.children.push(` + `, next);
|
---|
| 5532 | children.splice(j, 1);
|
---|
| 5533 | j--;
|
---|
| 5534 | } else {
|
---|
| 5535 | currentContainer = void 0;
|
---|
| 5536 | break;
|
---|
| 5537 | }
|
---|
| 5538 | }
|
---|
| 5539 | }
|
---|
| 5540 | }
|
---|
| 5541 | if (!hasText || // if this is a plain element with a single text child, leave it
|
---|
| 5542 | // as-is since the runtime has dedicated fast path for this by directly
|
---|
| 5543 | // setting textContent of the element.
|
---|
| 5544 | // for component root it's always normalized anyway.
|
---|
| 5545 | children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && // #3756
|
---|
| 5546 | // custom directives can potentially add DOM elements arbitrarily,
|
---|
| 5547 | // we need to avoid setting textContent of the element at runtime
|
---|
| 5548 | // to avoid accidentally overwriting the DOM elements added
|
---|
| 5549 | // by the user through custom directives.
|
---|
| 5550 | !node.props.find(
|
---|
| 5551 | (p) => p.type === 7 && !context.directiveTransforms[p.name]
|
---|
| 5552 | ) && // in compat mode, <template> tags with no special directives
|
---|
| 5553 | // will be rendered as a fragment so its children must be
|
---|
| 5554 | // converted into vnodes.
|
---|
| 5555 | !(node.tag === "template"))) {
|
---|
| 5556 | return;
|
---|
| 5557 | }
|
---|
| 5558 | for (let i = 0; i < children.length; i++) {
|
---|
| 5559 | const child = children[i];
|
---|
| 5560 | if (isText$1(child) || child.type === 8) {
|
---|
| 5561 | const callArgs = [];
|
---|
| 5562 | if (child.type !== 2 || child.content !== " ") {
|
---|
| 5563 | callArgs.push(child);
|
---|
| 5564 | }
|
---|
| 5565 | if (!context.ssr && getConstantType(child, context) === 0) {
|
---|
| 5566 | callArgs.push(
|
---|
| 5567 | 1 + (` /* ${PatchFlagNames[1]} */` )
|
---|
| 5568 | );
|
---|
| 5569 | }
|
---|
| 5570 | children[i] = {
|
---|
| 5571 | type: 12,
|
---|
| 5572 | content: child,
|
---|
| 5573 | loc: child.loc,
|
---|
| 5574 | codegenNode: createCallExpression(
|
---|
| 5575 | context.helper(CREATE_TEXT),
|
---|
| 5576 | callArgs
|
---|
| 5577 | )
|
---|
| 5578 | };
|
---|
| 5579 | }
|
---|
| 5580 | }
|
---|
| 5581 | };
|
---|
| 5582 | }
|
---|
| 5583 | };
|
---|
| 5584 |
|
---|
| 5585 | const seen$1 = /* @__PURE__ */ new WeakSet();
|
---|
| 5586 | const transformOnce = (node, context) => {
|
---|
| 5587 | if (node.type === 1 && findDir(node, "once", true)) {
|
---|
| 5588 | if (seen$1.has(node) || context.inVOnce || context.inSSR) {
|
---|
| 5589 | return;
|
---|
| 5590 | }
|
---|
| 5591 | seen$1.add(node);
|
---|
| 5592 | context.inVOnce = true;
|
---|
| 5593 | context.helper(SET_BLOCK_TRACKING);
|
---|
| 5594 | return () => {
|
---|
| 5595 | context.inVOnce = false;
|
---|
| 5596 | const cur = context.currentNode;
|
---|
| 5597 | if (cur.codegenNode) {
|
---|
| 5598 | cur.codegenNode = context.cache(
|
---|
| 5599 | cur.codegenNode,
|
---|
| 5600 | true,
|
---|
| 5601 | true
|
---|
| 5602 | );
|
---|
| 5603 | }
|
---|
| 5604 | };
|
---|
| 5605 | }
|
---|
| 5606 | };
|
---|
| 5607 |
|
---|
| 5608 | const transformModel$1 = (dir, node, context) => {
|
---|
| 5609 | const { exp, arg } = dir;
|
---|
| 5610 | if (!exp) {
|
---|
| 5611 | context.onError(
|
---|
| 5612 | createCompilerError(41, dir.loc)
|
---|
| 5613 | );
|
---|
| 5614 | return createTransformProps();
|
---|
| 5615 | }
|
---|
| 5616 | const rawExp = exp.loc.source.trim();
|
---|
| 5617 | const expString = exp.type === 4 ? exp.content : rawExp;
|
---|
| 5618 | const bindingType = context.bindingMetadata[rawExp];
|
---|
| 5619 | if (bindingType === "props" || bindingType === "props-aliased") {
|
---|
| 5620 | context.onError(createCompilerError(44, exp.loc));
|
---|
| 5621 | return createTransformProps();
|
---|
| 5622 | }
|
---|
| 5623 | const maybeRef = false;
|
---|
| 5624 | if (!expString.trim() || !isMemberExpression(exp) && !maybeRef) {
|
---|
| 5625 | context.onError(
|
---|
| 5626 | createCompilerError(42, exp.loc)
|
---|
| 5627 | );
|
---|
| 5628 | return createTransformProps();
|
---|
| 5629 | }
|
---|
| 5630 | const propName = arg ? arg : createSimpleExpression("modelValue", true);
|
---|
| 5631 | const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(['"onUpdate:" + ', arg]) : `onUpdate:modelValue`;
|
---|
| 5632 | let assignmentExp;
|
---|
| 5633 | const eventArg = context.isTS ? `($event: any)` : `$event`;
|
---|
| 5634 | {
|
---|
| 5635 | assignmentExp = createCompoundExpression([
|
---|
| 5636 | `${eventArg} => ((`,
|
---|
| 5637 | exp,
|
---|
| 5638 | `) = $event)`
|
---|
| 5639 | ]);
|
---|
| 5640 | }
|
---|
| 5641 | const props = [
|
---|
| 5642 | // modelValue: foo
|
---|
| 5643 | createObjectProperty(propName, dir.exp),
|
---|
| 5644 | // "onUpdate:modelValue": $event => (foo = $event)
|
---|
| 5645 | createObjectProperty(eventName, assignmentExp)
|
---|
| 5646 | ];
|
---|
| 5647 | if (dir.modifiers.length && node.tagType === 1) {
|
---|
| 5648 | const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
|
---|
| 5649 | const modifiersKey = arg ? isStaticExp(arg) ? `${arg.content}Modifiers` : createCompoundExpression([arg, ' + "Modifiers"']) : `modelModifiers`;
|
---|
| 5650 | props.push(
|
---|
| 5651 | createObjectProperty(
|
---|
| 5652 | modifiersKey,
|
---|
| 5653 | createSimpleExpression(
|
---|
| 5654 | `{ ${modifiers} }`,
|
---|
| 5655 | false,
|
---|
| 5656 | dir.loc,
|
---|
| 5657 | 2
|
---|
| 5658 | )
|
---|
| 5659 | )
|
---|
| 5660 | );
|
---|
| 5661 | }
|
---|
| 5662 | return createTransformProps(props);
|
---|
| 5663 | };
|
---|
| 5664 | function createTransformProps(props = []) {
|
---|
| 5665 | return { props };
|
---|
| 5666 | }
|
---|
| 5667 |
|
---|
| 5668 | const validDivisionCharRE = /[\w).+\-_$\]]/;
|
---|
| 5669 | const transformFilter = (node, context) => {
|
---|
| 5670 | if (!isCompatEnabled("COMPILER_FILTERS", context)) {
|
---|
| 5671 | return;
|
---|
| 5672 | }
|
---|
| 5673 | if (node.type === 5) {
|
---|
| 5674 | rewriteFilter(node.content, context);
|
---|
| 5675 | } else if (node.type === 1) {
|
---|
| 5676 | node.props.forEach((prop) => {
|
---|
| 5677 | if (prop.type === 7 && prop.name !== "for" && prop.exp) {
|
---|
| 5678 | rewriteFilter(prop.exp, context);
|
---|
| 5679 | }
|
---|
| 5680 | });
|
---|
| 5681 | }
|
---|
| 5682 | };
|
---|
| 5683 | function rewriteFilter(node, context) {
|
---|
| 5684 | if (node.type === 4) {
|
---|
| 5685 | parseFilter(node, context);
|
---|
| 5686 | } else {
|
---|
| 5687 | for (let i = 0; i < node.children.length; i++) {
|
---|
| 5688 | const child = node.children[i];
|
---|
| 5689 | if (typeof child !== "object") continue;
|
---|
| 5690 | if (child.type === 4) {
|
---|
| 5691 | parseFilter(child, context);
|
---|
| 5692 | } else if (child.type === 8) {
|
---|
| 5693 | rewriteFilter(node, context);
|
---|
| 5694 | } else if (child.type === 5) {
|
---|
| 5695 | rewriteFilter(child.content, context);
|
---|
| 5696 | }
|
---|
| 5697 | }
|
---|
| 5698 | }
|
---|
| 5699 | }
|
---|
| 5700 | function parseFilter(node, context) {
|
---|
| 5701 | const exp = node.content;
|
---|
| 5702 | let inSingle = false;
|
---|
| 5703 | let inDouble = false;
|
---|
| 5704 | let inTemplateString = false;
|
---|
| 5705 | let inRegex = false;
|
---|
| 5706 | let curly = 0;
|
---|
| 5707 | let square = 0;
|
---|
| 5708 | let paren = 0;
|
---|
| 5709 | let lastFilterIndex = 0;
|
---|
| 5710 | let c, prev, i, expression, filters = [];
|
---|
| 5711 | for (i = 0; i < exp.length; i++) {
|
---|
| 5712 | prev = c;
|
---|
| 5713 | c = exp.charCodeAt(i);
|
---|
| 5714 | if (inSingle) {
|
---|
| 5715 | if (c === 39 && prev !== 92) inSingle = false;
|
---|
| 5716 | } else if (inDouble) {
|
---|
| 5717 | if (c === 34 && prev !== 92) inDouble = false;
|
---|
| 5718 | } else if (inTemplateString) {
|
---|
| 5719 | if (c === 96 && prev !== 92) inTemplateString = false;
|
---|
| 5720 | } else if (inRegex) {
|
---|
| 5721 | if (c === 47 && prev !== 92) inRegex = false;
|
---|
| 5722 | } else if (c === 124 && // pipe
|
---|
| 5723 | exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
---|
| 5724 | if (expression === void 0) {
|
---|
| 5725 | lastFilterIndex = i + 1;
|
---|
| 5726 | expression = exp.slice(0, i).trim();
|
---|
| 5727 | } else {
|
---|
| 5728 | pushFilter();
|
---|
| 5729 | }
|
---|
| 5730 | } else {
|
---|
| 5731 | switch (c) {
|
---|
| 5732 | case 34:
|
---|
| 5733 | inDouble = true;
|
---|
| 5734 | break;
|
---|
| 5735 | // "
|
---|
| 5736 | case 39:
|
---|
| 5737 | inSingle = true;
|
---|
| 5738 | break;
|
---|
| 5739 | // '
|
---|
| 5740 | case 96:
|
---|
| 5741 | inTemplateString = true;
|
---|
| 5742 | break;
|
---|
| 5743 | // `
|
---|
| 5744 | case 40:
|
---|
| 5745 | paren++;
|
---|
| 5746 | break;
|
---|
| 5747 | // (
|
---|
| 5748 | case 41:
|
---|
| 5749 | paren--;
|
---|
| 5750 | break;
|
---|
| 5751 | // )
|
---|
| 5752 | case 91:
|
---|
| 5753 | square++;
|
---|
| 5754 | break;
|
---|
| 5755 | // [
|
---|
| 5756 | case 93:
|
---|
| 5757 | square--;
|
---|
| 5758 | break;
|
---|
| 5759 | // ]
|
---|
| 5760 | case 123:
|
---|
| 5761 | curly++;
|
---|
| 5762 | break;
|
---|
| 5763 | // {
|
---|
| 5764 | case 125:
|
---|
| 5765 | curly--;
|
---|
| 5766 | break;
|
---|
| 5767 | }
|
---|
| 5768 | if (c === 47) {
|
---|
| 5769 | let j = i - 1;
|
---|
| 5770 | let p;
|
---|
| 5771 | for (; j >= 0; j--) {
|
---|
| 5772 | p = exp.charAt(j);
|
---|
| 5773 | if (p !== " ") break;
|
---|
| 5774 | }
|
---|
| 5775 | if (!p || !validDivisionCharRE.test(p)) {
|
---|
| 5776 | inRegex = true;
|
---|
| 5777 | }
|
---|
| 5778 | }
|
---|
| 5779 | }
|
---|
| 5780 | }
|
---|
| 5781 | if (expression === void 0) {
|
---|
| 5782 | expression = exp.slice(0, i).trim();
|
---|
| 5783 | } else if (lastFilterIndex !== 0) {
|
---|
| 5784 | pushFilter();
|
---|
| 5785 | }
|
---|
| 5786 | function pushFilter() {
|
---|
| 5787 | filters.push(exp.slice(lastFilterIndex, i).trim());
|
---|
| 5788 | lastFilterIndex = i + 1;
|
---|
| 5789 | }
|
---|
| 5790 | if (filters.length) {
|
---|
| 5791 | warnDeprecation(
|
---|
| 5792 | "COMPILER_FILTERS",
|
---|
| 5793 | context,
|
---|
| 5794 | node.loc
|
---|
| 5795 | );
|
---|
| 5796 | for (i = 0; i < filters.length; i++) {
|
---|
| 5797 | expression = wrapFilter(expression, filters[i], context);
|
---|
| 5798 | }
|
---|
| 5799 | node.content = expression;
|
---|
| 5800 | node.ast = void 0;
|
---|
| 5801 | }
|
---|
| 5802 | }
|
---|
| 5803 | function wrapFilter(exp, filter, context) {
|
---|
| 5804 | context.helper(RESOLVE_FILTER);
|
---|
| 5805 | const i = filter.indexOf("(");
|
---|
| 5806 | if (i < 0) {
|
---|
| 5807 | context.filters.add(filter);
|
---|
| 5808 | return `${toValidAssetId(filter, "filter")}(${exp})`;
|
---|
| 5809 | } else {
|
---|
| 5810 | const name = filter.slice(0, i);
|
---|
| 5811 | const args = filter.slice(i + 1);
|
---|
| 5812 | context.filters.add(name);
|
---|
| 5813 | return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
|
---|
| 5814 | }
|
---|
| 5815 | }
|
---|
| 5816 |
|
---|
| 5817 | const seen = /* @__PURE__ */ new WeakSet();
|
---|
| 5818 | const transformMemo = (node, context) => {
|
---|
| 5819 | if (node.type === 1) {
|
---|
| 5820 | const dir = findDir(node, "memo");
|
---|
| 5821 | if (!dir || seen.has(node)) {
|
---|
| 5822 | return;
|
---|
| 5823 | }
|
---|
| 5824 | seen.add(node);
|
---|
| 5825 | return () => {
|
---|
| 5826 | const codegenNode = node.codegenNode || context.currentNode.codegenNode;
|
---|
| 5827 | if (codegenNode && codegenNode.type === 13) {
|
---|
| 5828 | if (node.tagType !== 1) {
|
---|
| 5829 | convertToBlock(codegenNode, context);
|
---|
| 5830 | }
|
---|
| 5831 | node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
---|
| 5832 | dir.exp,
|
---|
| 5833 | createFunctionExpression(void 0, codegenNode),
|
---|
| 5834 | `_cache`,
|
---|
| 5835 | String(context.cached.length)
|
---|
| 5836 | ]);
|
---|
| 5837 | context.cached.push(null);
|
---|
| 5838 | }
|
---|
| 5839 | };
|
---|
| 5840 | }
|
---|
| 5841 | };
|
---|
| 5842 |
|
---|
| 5843 | function getBaseTransformPreset(prefixIdentifiers) {
|
---|
| 5844 | return [
|
---|
| 5845 | [
|
---|
| 5846 | transformOnce,
|
---|
| 5847 | transformIf,
|
---|
| 5848 | transformMemo,
|
---|
| 5849 | transformFor,
|
---|
| 5850 | ...[transformFilter] ,
|
---|
| 5851 | ...[transformExpression] ,
|
---|
| 5852 | transformSlotOutlet,
|
---|
| 5853 | transformElement,
|
---|
| 5854 | trackSlotScopes,
|
---|
| 5855 | transformText
|
---|
| 5856 | ],
|
---|
| 5857 | {
|
---|
| 5858 | on: transformOn$1,
|
---|
| 5859 | bind: transformBind,
|
---|
| 5860 | model: transformModel$1
|
---|
| 5861 | }
|
---|
| 5862 | ];
|
---|
| 5863 | }
|
---|
| 5864 | function baseCompile(source, options = {}) {
|
---|
| 5865 | const onError = options.onError || defaultOnError;
|
---|
| 5866 | const isModuleMode = options.mode === "module";
|
---|
| 5867 | {
|
---|
| 5868 | if (options.prefixIdentifiers === true) {
|
---|
| 5869 | onError(createCompilerError(47));
|
---|
| 5870 | } else if (isModuleMode) {
|
---|
| 5871 | onError(createCompilerError(48));
|
---|
| 5872 | }
|
---|
| 5873 | }
|
---|
| 5874 | const prefixIdentifiers = false;
|
---|
| 5875 | if (options.cacheHandlers) {
|
---|
| 5876 | onError(createCompilerError(49));
|
---|
| 5877 | }
|
---|
| 5878 | if (options.scopeId && !isModuleMode) {
|
---|
| 5879 | onError(createCompilerError(50));
|
---|
| 5880 | }
|
---|
| 5881 | const resolvedOptions = extend({}, options, {
|
---|
| 5882 | prefixIdentifiers
|
---|
| 5883 | });
|
---|
| 5884 | const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
|
---|
| 5885 | const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
---|
| 5886 | transform(
|
---|
| 5887 | ast,
|
---|
| 5888 | extend({}, resolvedOptions, {
|
---|
| 5889 | nodeTransforms: [
|
---|
| 5890 | ...nodeTransforms,
|
---|
| 5891 | ...options.nodeTransforms || []
|
---|
| 5892 | // user transforms
|
---|
| 5893 | ],
|
---|
| 5894 | directiveTransforms: extend(
|
---|
| 5895 | {},
|
---|
| 5896 | directiveTransforms,
|
---|
| 5897 | options.directiveTransforms || {}
|
---|
| 5898 | // user transforms
|
---|
| 5899 | )
|
---|
| 5900 | })
|
---|
| 5901 | );
|
---|
| 5902 | return generate(ast, resolvedOptions);
|
---|
| 5903 | }
|
---|
| 5904 |
|
---|
| 5905 | const BindingTypes = {
|
---|
| 5906 | "DATA": "data",
|
---|
| 5907 | "PROPS": "props",
|
---|
| 5908 | "PROPS_ALIASED": "props-aliased",
|
---|
| 5909 | "SETUP_LET": "setup-let",
|
---|
| 5910 | "SETUP_CONST": "setup-const",
|
---|
| 5911 | "SETUP_REACTIVE_CONST": "setup-reactive-const",
|
---|
| 5912 | "SETUP_MAYBE_REF": "setup-maybe-ref",
|
---|
| 5913 | "SETUP_REF": "setup-ref",
|
---|
| 5914 | "OPTIONS": "options",
|
---|
| 5915 | "LITERAL_CONST": "literal-const"
|
---|
| 5916 | };
|
---|
| 5917 |
|
---|
| 5918 | const noopDirectiveTransform = () => ({ props: [] });
|
---|
| 5919 |
|
---|
| 5920 | const V_MODEL_RADIO = Symbol(`vModelRadio` );
|
---|
| 5921 | const V_MODEL_CHECKBOX = Symbol(
|
---|
| 5922 | `vModelCheckbox`
|
---|
| 5923 | );
|
---|
| 5924 | const V_MODEL_TEXT = Symbol(`vModelText` );
|
---|
| 5925 | const V_MODEL_SELECT = Symbol(
|
---|
| 5926 | `vModelSelect`
|
---|
| 5927 | );
|
---|
| 5928 | const V_MODEL_DYNAMIC = Symbol(
|
---|
| 5929 | `vModelDynamic`
|
---|
| 5930 | );
|
---|
| 5931 | const V_ON_WITH_MODIFIERS = Symbol(
|
---|
| 5932 | `vOnModifiersGuard`
|
---|
| 5933 | );
|
---|
| 5934 | const V_ON_WITH_KEYS = Symbol(
|
---|
| 5935 | `vOnKeysGuard`
|
---|
| 5936 | );
|
---|
| 5937 | const V_SHOW = Symbol(`vShow` );
|
---|
| 5938 | const TRANSITION = Symbol(`Transition` );
|
---|
| 5939 | const TRANSITION_GROUP = Symbol(
|
---|
| 5940 | `TransitionGroup`
|
---|
| 5941 | );
|
---|
| 5942 | registerRuntimeHelpers({
|
---|
| 5943 | [V_MODEL_RADIO]: `vModelRadio`,
|
---|
| 5944 | [V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
---|
| 5945 | [V_MODEL_TEXT]: `vModelText`,
|
---|
| 5946 | [V_MODEL_SELECT]: `vModelSelect`,
|
---|
| 5947 | [V_MODEL_DYNAMIC]: `vModelDynamic`,
|
---|
| 5948 | [V_ON_WITH_MODIFIERS]: `withModifiers`,
|
---|
| 5949 | [V_ON_WITH_KEYS]: `withKeys`,
|
---|
| 5950 | [V_SHOW]: `vShow`,
|
---|
| 5951 | [TRANSITION]: `Transition`,
|
---|
| 5952 | [TRANSITION_GROUP]: `TransitionGroup`
|
---|
| 5953 | });
|
---|
| 5954 |
|
---|
| 5955 | let decoder;
|
---|
| 5956 | function decodeHtmlBrowser(raw, asAttr = false) {
|
---|
| 5957 | if (!decoder) {
|
---|
| 5958 | decoder = document.createElement("div");
|
---|
| 5959 | }
|
---|
| 5960 | if (asAttr) {
|
---|
| 5961 | decoder.innerHTML = `<div foo="${raw.replace(/"/g, """)}">`;
|
---|
| 5962 | return decoder.children[0].getAttribute("foo");
|
---|
| 5963 | } else {
|
---|
| 5964 | decoder.innerHTML = raw;
|
---|
| 5965 | return decoder.textContent;
|
---|
| 5966 | }
|
---|
| 5967 | }
|
---|
| 5968 |
|
---|
| 5969 | const parserOptions = {
|
---|
| 5970 | parseMode: "html",
|
---|
| 5971 | isVoidTag,
|
---|
| 5972 | isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
---|
| 5973 | isPreTag: (tag) => tag === "pre",
|
---|
| 5974 | isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
|
---|
| 5975 | decodeEntities: decodeHtmlBrowser ,
|
---|
| 5976 | isBuiltInComponent: (tag) => {
|
---|
| 5977 | if (tag === "Transition" || tag === "transition") {
|
---|
| 5978 | return TRANSITION;
|
---|
| 5979 | } else if (tag === "TransitionGroup" || tag === "transition-group") {
|
---|
| 5980 | return TRANSITION_GROUP;
|
---|
| 5981 | }
|
---|
| 5982 | },
|
---|
| 5983 | // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
---|
| 5984 | getNamespace(tag, parent, rootNamespace) {
|
---|
| 5985 | let ns = parent ? parent.ns : rootNamespace;
|
---|
| 5986 | if (parent && ns === 2) {
|
---|
| 5987 | if (parent.tag === "annotation-xml") {
|
---|
| 5988 | if (tag === "svg") {
|
---|
| 5989 | return 1;
|
---|
| 5990 | }
|
---|
| 5991 | if (parent.props.some(
|
---|
| 5992 | (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
---|
| 5993 | )) {
|
---|
| 5994 | ns = 0;
|
---|
| 5995 | }
|
---|
| 5996 | } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
---|
| 5997 | ns = 0;
|
---|
| 5998 | }
|
---|
| 5999 | } else if (parent && ns === 1) {
|
---|
| 6000 | if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
---|
| 6001 | ns = 0;
|
---|
| 6002 | }
|
---|
| 6003 | }
|
---|
| 6004 | if (ns === 0) {
|
---|
| 6005 | if (tag === "svg") {
|
---|
| 6006 | return 1;
|
---|
| 6007 | }
|
---|
| 6008 | if (tag === "math") {
|
---|
| 6009 | return 2;
|
---|
| 6010 | }
|
---|
| 6011 | }
|
---|
| 6012 | return ns;
|
---|
| 6013 | }
|
---|
| 6014 | };
|
---|
| 6015 |
|
---|
| 6016 | const transformStyle = (node) => {
|
---|
| 6017 | if (node.type === 1) {
|
---|
| 6018 | node.props.forEach((p, i) => {
|
---|
| 6019 | if (p.type === 6 && p.name === "style" && p.value) {
|
---|
| 6020 | node.props[i] = {
|
---|
| 6021 | type: 7,
|
---|
| 6022 | name: `bind`,
|
---|
| 6023 | arg: createSimpleExpression(`style`, true, p.loc),
|
---|
| 6024 | exp: parseInlineCSS(p.value.content, p.loc),
|
---|
| 6025 | modifiers: [],
|
---|
| 6026 | loc: p.loc
|
---|
| 6027 | };
|
---|
| 6028 | }
|
---|
| 6029 | });
|
---|
| 6030 | }
|
---|
| 6031 | };
|
---|
| 6032 | const parseInlineCSS = (cssText, loc) => {
|
---|
| 6033 | const normalized = parseStringStyle(cssText);
|
---|
| 6034 | return createSimpleExpression(
|
---|
| 6035 | JSON.stringify(normalized),
|
---|
| 6036 | false,
|
---|
| 6037 | loc,
|
---|
| 6038 | 3
|
---|
| 6039 | );
|
---|
| 6040 | };
|
---|
| 6041 |
|
---|
| 6042 | function createDOMCompilerError(code, loc) {
|
---|
| 6043 | return createCompilerError(
|
---|
| 6044 | code,
|
---|
| 6045 | loc,
|
---|
| 6046 | DOMErrorMessages
|
---|
| 6047 | );
|
---|
| 6048 | }
|
---|
| 6049 | const DOMErrorCodes = {
|
---|
| 6050 | "X_V_HTML_NO_EXPRESSION": 53,
|
---|
| 6051 | "53": "X_V_HTML_NO_EXPRESSION",
|
---|
| 6052 | "X_V_HTML_WITH_CHILDREN": 54,
|
---|
| 6053 | "54": "X_V_HTML_WITH_CHILDREN",
|
---|
| 6054 | "X_V_TEXT_NO_EXPRESSION": 55,
|
---|
| 6055 | "55": "X_V_TEXT_NO_EXPRESSION",
|
---|
| 6056 | "X_V_TEXT_WITH_CHILDREN": 56,
|
---|
| 6057 | "56": "X_V_TEXT_WITH_CHILDREN",
|
---|
| 6058 | "X_V_MODEL_ON_INVALID_ELEMENT": 57,
|
---|
| 6059 | "57": "X_V_MODEL_ON_INVALID_ELEMENT",
|
---|
| 6060 | "X_V_MODEL_ARG_ON_ELEMENT": 58,
|
---|
| 6061 | "58": "X_V_MODEL_ARG_ON_ELEMENT",
|
---|
| 6062 | "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
|
---|
| 6063 | "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
|
---|
| 6064 | "X_V_MODEL_UNNECESSARY_VALUE": 60,
|
---|
| 6065 | "60": "X_V_MODEL_UNNECESSARY_VALUE",
|
---|
| 6066 | "X_V_SHOW_NO_EXPRESSION": 61,
|
---|
| 6067 | "61": "X_V_SHOW_NO_EXPRESSION",
|
---|
| 6068 | "X_TRANSITION_INVALID_CHILDREN": 62,
|
---|
| 6069 | "62": "X_TRANSITION_INVALID_CHILDREN",
|
---|
| 6070 | "X_IGNORED_SIDE_EFFECT_TAG": 63,
|
---|
| 6071 | "63": "X_IGNORED_SIDE_EFFECT_TAG",
|
---|
| 6072 | "__EXTEND_POINT__": 64,
|
---|
| 6073 | "64": "__EXTEND_POINT__"
|
---|
| 6074 | };
|
---|
| 6075 | const DOMErrorMessages = {
|
---|
| 6076 | [53]: `v-html is missing expression.`,
|
---|
| 6077 | [54]: `v-html will override element children.`,
|
---|
| 6078 | [55]: `v-text is missing expression.`,
|
---|
| 6079 | [56]: `v-text will override element children.`,
|
---|
| 6080 | [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
---|
| 6081 | [58]: `v-model argument is not supported on plain elements.`,
|
---|
| 6082 | [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
---|
| 6083 | [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
---|
| 6084 | [61]: `v-show is missing expression.`,
|
---|
| 6085 | [62]: `<Transition> expects exactly one child element or component.`,
|
---|
| 6086 | [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
---|
| 6087 | };
|
---|
| 6088 |
|
---|
| 6089 | const transformVHtml = (dir, node, context) => {
|
---|
| 6090 | const { exp, loc } = dir;
|
---|
| 6091 | if (!exp) {
|
---|
| 6092 | context.onError(
|
---|
| 6093 | createDOMCompilerError(53, loc)
|
---|
| 6094 | );
|
---|
| 6095 | }
|
---|
| 6096 | if (node.children.length) {
|
---|
| 6097 | context.onError(
|
---|
| 6098 | createDOMCompilerError(54, loc)
|
---|
| 6099 | );
|
---|
| 6100 | node.children.length = 0;
|
---|
| 6101 | }
|
---|
| 6102 | return {
|
---|
| 6103 | props: [
|
---|
| 6104 | createObjectProperty(
|
---|
| 6105 | createSimpleExpression(`innerHTML`, true, loc),
|
---|
| 6106 | exp || createSimpleExpression("", true)
|
---|
| 6107 | )
|
---|
| 6108 | ]
|
---|
| 6109 | };
|
---|
| 6110 | };
|
---|
| 6111 |
|
---|
| 6112 | const transformVText = (dir, node, context) => {
|
---|
| 6113 | const { exp, loc } = dir;
|
---|
| 6114 | if (!exp) {
|
---|
| 6115 | context.onError(
|
---|
| 6116 | createDOMCompilerError(55, loc)
|
---|
| 6117 | );
|
---|
| 6118 | }
|
---|
| 6119 | if (node.children.length) {
|
---|
| 6120 | context.onError(
|
---|
| 6121 | createDOMCompilerError(56, loc)
|
---|
| 6122 | );
|
---|
| 6123 | node.children.length = 0;
|
---|
| 6124 | }
|
---|
| 6125 | return {
|
---|
| 6126 | props: [
|
---|
| 6127 | createObjectProperty(
|
---|
| 6128 | createSimpleExpression(`textContent`, true),
|
---|
| 6129 | exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
|
---|
| 6130 | context.helperString(TO_DISPLAY_STRING),
|
---|
| 6131 | [exp],
|
---|
| 6132 | loc
|
---|
| 6133 | ) : createSimpleExpression("", true)
|
---|
| 6134 | )
|
---|
| 6135 | ]
|
---|
| 6136 | };
|
---|
| 6137 | };
|
---|
| 6138 |
|
---|
| 6139 | const transformModel = (dir, node, context) => {
|
---|
| 6140 | const baseResult = transformModel$1(dir, node, context);
|
---|
| 6141 | if (!baseResult.props.length || node.tagType === 1) {
|
---|
| 6142 | return baseResult;
|
---|
| 6143 | }
|
---|
| 6144 | if (dir.arg) {
|
---|
| 6145 | context.onError(
|
---|
| 6146 | createDOMCompilerError(
|
---|
| 6147 | 58,
|
---|
| 6148 | dir.arg.loc
|
---|
| 6149 | )
|
---|
| 6150 | );
|
---|
| 6151 | }
|
---|
| 6152 | function checkDuplicatedValue() {
|
---|
| 6153 | const value = findDir(node, "bind");
|
---|
| 6154 | if (value && isStaticArgOf(value.arg, "value")) {
|
---|
| 6155 | context.onError(
|
---|
| 6156 | createDOMCompilerError(
|
---|
| 6157 | 60,
|
---|
| 6158 | value.loc
|
---|
| 6159 | )
|
---|
| 6160 | );
|
---|
| 6161 | }
|
---|
| 6162 | }
|
---|
| 6163 | const { tag } = node;
|
---|
| 6164 | const isCustomElement = context.isCustomElement(tag);
|
---|
| 6165 | if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
---|
| 6166 | let directiveToUse = V_MODEL_TEXT;
|
---|
| 6167 | let isInvalidType = false;
|
---|
| 6168 | if (tag === "input" || isCustomElement) {
|
---|
| 6169 | const type = findProp(node, `type`);
|
---|
| 6170 | if (type) {
|
---|
| 6171 | if (type.type === 7) {
|
---|
| 6172 | directiveToUse = V_MODEL_DYNAMIC;
|
---|
| 6173 | } else if (type.value) {
|
---|
| 6174 | switch (type.value.content) {
|
---|
| 6175 | case "radio":
|
---|
| 6176 | directiveToUse = V_MODEL_RADIO;
|
---|
| 6177 | break;
|
---|
| 6178 | case "checkbox":
|
---|
| 6179 | directiveToUse = V_MODEL_CHECKBOX;
|
---|
| 6180 | break;
|
---|
| 6181 | case "file":
|
---|
| 6182 | isInvalidType = true;
|
---|
| 6183 | context.onError(
|
---|
| 6184 | createDOMCompilerError(
|
---|
| 6185 | 59,
|
---|
| 6186 | dir.loc
|
---|
| 6187 | )
|
---|
| 6188 | );
|
---|
| 6189 | break;
|
---|
| 6190 | default:
|
---|
| 6191 | checkDuplicatedValue();
|
---|
| 6192 | break;
|
---|
| 6193 | }
|
---|
| 6194 | }
|
---|
| 6195 | } else if (hasDynamicKeyVBind(node)) {
|
---|
| 6196 | directiveToUse = V_MODEL_DYNAMIC;
|
---|
| 6197 | } else {
|
---|
| 6198 | checkDuplicatedValue();
|
---|
| 6199 | }
|
---|
| 6200 | } else if (tag === "select") {
|
---|
| 6201 | directiveToUse = V_MODEL_SELECT;
|
---|
| 6202 | } else {
|
---|
| 6203 | checkDuplicatedValue();
|
---|
| 6204 | }
|
---|
| 6205 | if (!isInvalidType) {
|
---|
| 6206 | baseResult.needRuntime = context.helper(directiveToUse);
|
---|
| 6207 | }
|
---|
| 6208 | } else {
|
---|
| 6209 | context.onError(
|
---|
| 6210 | createDOMCompilerError(
|
---|
| 6211 | 57,
|
---|
| 6212 | dir.loc
|
---|
| 6213 | )
|
---|
| 6214 | );
|
---|
| 6215 | }
|
---|
| 6216 | baseResult.props = baseResult.props.filter(
|
---|
| 6217 | (p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
---|
| 6218 | );
|
---|
| 6219 | return baseResult;
|
---|
| 6220 | };
|
---|
| 6221 |
|
---|
| 6222 | const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
|
---|
| 6223 | const isNonKeyModifier = /* @__PURE__ */ makeMap(
|
---|
| 6224 | // event propagation management
|
---|
| 6225 | `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
---|
| 6226 | );
|
---|
| 6227 | const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
|
---|
| 6228 | const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
|
---|
| 6229 | const resolveModifiers = (key, modifiers, context, loc) => {
|
---|
| 6230 | const keyModifiers = [];
|
---|
| 6231 | const nonKeyModifiers = [];
|
---|
| 6232 | const eventOptionModifiers = [];
|
---|
| 6233 | for (let i = 0; i < modifiers.length; i++) {
|
---|
| 6234 | const modifier = modifiers[i].content;
|
---|
| 6235 | if (modifier === "native" && checkCompatEnabled(
|
---|
| 6236 | "COMPILER_V_ON_NATIVE",
|
---|
| 6237 | context,
|
---|
| 6238 | loc
|
---|
| 6239 | )) {
|
---|
| 6240 | eventOptionModifiers.push(modifier);
|
---|
| 6241 | } else if (isEventOptionModifier(modifier)) {
|
---|
| 6242 | eventOptionModifiers.push(modifier);
|
---|
| 6243 | } else {
|
---|
| 6244 | if (maybeKeyModifier(modifier)) {
|
---|
| 6245 | if (isStaticExp(key)) {
|
---|
| 6246 | if (isKeyboardEvent(key.content.toLowerCase())) {
|
---|
| 6247 | keyModifiers.push(modifier);
|
---|
| 6248 | } else {
|
---|
| 6249 | nonKeyModifiers.push(modifier);
|
---|
| 6250 | }
|
---|
| 6251 | } else {
|
---|
| 6252 | keyModifiers.push(modifier);
|
---|
| 6253 | nonKeyModifiers.push(modifier);
|
---|
| 6254 | }
|
---|
| 6255 | } else {
|
---|
| 6256 | if (isNonKeyModifier(modifier)) {
|
---|
| 6257 | nonKeyModifiers.push(modifier);
|
---|
| 6258 | } else {
|
---|
| 6259 | keyModifiers.push(modifier);
|
---|
| 6260 | }
|
---|
| 6261 | }
|
---|
| 6262 | }
|
---|
| 6263 | }
|
---|
| 6264 | return {
|
---|
| 6265 | keyModifiers,
|
---|
| 6266 | nonKeyModifiers,
|
---|
| 6267 | eventOptionModifiers
|
---|
| 6268 | };
|
---|
| 6269 | };
|
---|
| 6270 | const transformClick = (key, event) => {
|
---|
| 6271 | const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
---|
| 6272 | return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
|
---|
| 6273 | `(`,
|
---|
| 6274 | key,
|
---|
| 6275 | `) === "onClick" ? "${event}" : (`,
|
---|
| 6276 | key,
|
---|
| 6277 | `)`
|
---|
| 6278 | ]) : key;
|
---|
| 6279 | };
|
---|
| 6280 | const transformOn = (dir, node, context) => {
|
---|
| 6281 | return transformOn$1(dir, node, context, (baseResult) => {
|
---|
| 6282 | const { modifiers } = dir;
|
---|
| 6283 | if (!modifiers.length) return baseResult;
|
---|
| 6284 | let { key, value: handlerExp } = baseResult.props[0];
|
---|
| 6285 | const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
---|
| 6286 | if (nonKeyModifiers.includes("right")) {
|
---|
| 6287 | key = transformClick(key, `onContextmenu`);
|
---|
| 6288 | }
|
---|
| 6289 | if (nonKeyModifiers.includes("middle")) {
|
---|
| 6290 | key = transformClick(key, `onMouseup`);
|
---|
| 6291 | }
|
---|
| 6292 | if (nonKeyModifiers.length) {
|
---|
| 6293 | handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
---|
| 6294 | handlerExp,
|
---|
| 6295 | JSON.stringify(nonKeyModifiers)
|
---|
| 6296 | ]);
|
---|
| 6297 | }
|
---|
| 6298 | if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
|
---|
| 6299 | (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
|
---|
| 6300 | handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
---|
| 6301 | handlerExp,
|
---|
| 6302 | JSON.stringify(keyModifiers)
|
---|
| 6303 | ]);
|
---|
| 6304 | }
|
---|
| 6305 | if (eventOptionModifiers.length) {
|
---|
| 6306 | const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
|
---|
| 6307 | key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
---|
| 6308 | }
|
---|
| 6309 | return {
|
---|
| 6310 | props: [createObjectProperty(key, handlerExp)]
|
---|
| 6311 | };
|
---|
| 6312 | });
|
---|
| 6313 | };
|
---|
| 6314 |
|
---|
| 6315 | const transformShow = (dir, node, context) => {
|
---|
| 6316 | const { exp, loc } = dir;
|
---|
| 6317 | if (!exp) {
|
---|
| 6318 | context.onError(
|
---|
| 6319 | createDOMCompilerError(61, loc)
|
---|
| 6320 | );
|
---|
| 6321 | }
|
---|
| 6322 | return {
|
---|
| 6323 | props: [],
|
---|
| 6324 | needRuntime: context.helper(V_SHOW)
|
---|
| 6325 | };
|
---|
| 6326 | };
|
---|
| 6327 |
|
---|
| 6328 | const transformTransition = (node, context) => {
|
---|
| 6329 | if (node.type === 1 && node.tagType === 1) {
|
---|
| 6330 | const component = context.isBuiltInComponent(node.tag);
|
---|
| 6331 | if (component === TRANSITION) {
|
---|
| 6332 | return () => {
|
---|
| 6333 | if (!node.children.length) {
|
---|
| 6334 | return;
|
---|
| 6335 | }
|
---|
| 6336 | if (hasMultipleChildren(node)) {
|
---|
| 6337 | context.onError(
|
---|
| 6338 | createDOMCompilerError(
|
---|
| 6339 | 62,
|
---|
| 6340 | {
|
---|
| 6341 | start: node.children[0].loc.start,
|
---|
| 6342 | end: node.children[node.children.length - 1].loc.end,
|
---|
| 6343 | source: ""
|
---|
| 6344 | }
|
---|
| 6345 | )
|
---|
| 6346 | );
|
---|
| 6347 | }
|
---|
| 6348 | const child = node.children[0];
|
---|
| 6349 | if (child.type === 1) {
|
---|
| 6350 | for (const p of child.props) {
|
---|
| 6351 | if (p.type === 7 && p.name === "show") {
|
---|
| 6352 | node.props.push({
|
---|
| 6353 | type: 6,
|
---|
| 6354 | name: "persisted",
|
---|
| 6355 | nameLoc: node.loc,
|
---|
| 6356 | value: void 0,
|
---|
| 6357 | loc: node.loc
|
---|
| 6358 | });
|
---|
| 6359 | }
|
---|
| 6360 | }
|
---|
| 6361 | }
|
---|
| 6362 | };
|
---|
| 6363 | }
|
---|
| 6364 | }
|
---|
| 6365 | };
|
---|
| 6366 | function hasMultipleChildren(node) {
|
---|
| 6367 | const children = node.children = node.children.filter(
|
---|
| 6368 | (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
|
---|
| 6369 | );
|
---|
| 6370 | const child = children[0];
|
---|
| 6371 | return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
|
---|
| 6372 | }
|
---|
| 6373 |
|
---|
| 6374 | const ignoreSideEffectTags = (node, context) => {
|
---|
| 6375 | if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
---|
| 6376 | context.onError(
|
---|
| 6377 | createDOMCompilerError(
|
---|
| 6378 | 63,
|
---|
| 6379 | node.loc
|
---|
| 6380 | )
|
---|
| 6381 | );
|
---|
| 6382 | context.removeNode();
|
---|
| 6383 | }
|
---|
| 6384 | };
|
---|
| 6385 |
|
---|
| 6386 | function isValidHTMLNesting(parent, child) {
|
---|
| 6387 | if (parent in onlyValidChildren) {
|
---|
| 6388 | return onlyValidChildren[parent].has(child);
|
---|
| 6389 | }
|
---|
| 6390 | if (child in onlyValidParents) {
|
---|
| 6391 | return onlyValidParents[child].has(parent);
|
---|
| 6392 | }
|
---|
| 6393 | if (parent in knownInvalidChildren) {
|
---|
| 6394 | if (knownInvalidChildren[parent].has(child)) return false;
|
---|
| 6395 | }
|
---|
| 6396 | if (child in knownInvalidParents) {
|
---|
| 6397 | if (knownInvalidParents[child].has(parent)) return false;
|
---|
| 6398 | }
|
---|
| 6399 | return true;
|
---|
| 6400 | }
|
---|
| 6401 | const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
---|
| 6402 | const emptySet = /* @__PURE__ */ new Set([]);
|
---|
| 6403 | const onlyValidChildren = {
|
---|
| 6404 | head: /* @__PURE__ */ new Set([
|
---|
| 6405 | "base",
|
---|
| 6406 | "basefront",
|
---|
| 6407 | "bgsound",
|
---|
| 6408 | "link",
|
---|
| 6409 | "meta",
|
---|
| 6410 | "title",
|
---|
| 6411 | "noscript",
|
---|
| 6412 | "noframes",
|
---|
| 6413 | "style",
|
---|
| 6414 | "script",
|
---|
| 6415 | "template"
|
---|
| 6416 | ]),
|
---|
| 6417 | optgroup: /* @__PURE__ */ new Set(["option"]),
|
---|
| 6418 | select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
|
---|
| 6419 | // table
|
---|
| 6420 | table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
|
---|
| 6421 | tr: /* @__PURE__ */ new Set(["td", "th"]),
|
---|
| 6422 | colgroup: /* @__PURE__ */ new Set(["col"]),
|
---|
| 6423 | tbody: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 6424 | thead: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 6425 | tfoot: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 6426 | // these elements can not have any children elements
|
---|
| 6427 | script: emptySet,
|
---|
| 6428 | iframe: emptySet,
|
---|
| 6429 | option: emptySet,
|
---|
| 6430 | textarea: emptySet,
|
---|
| 6431 | style: emptySet,
|
---|
| 6432 | title: emptySet
|
---|
| 6433 | };
|
---|
| 6434 | const onlyValidParents = {
|
---|
| 6435 | // sections
|
---|
| 6436 | html: emptySet,
|
---|
| 6437 | body: /* @__PURE__ */ new Set(["html"]),
|
---|
| 6438 | head: /* @__PURE__ */ new Set(["html"]),
|
---|
| 6439 | // table
|
---|
| 6440 | td: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 6441 | colgroup: /* @__PURE__ */ new Set(["table"]),
|
---|
| 6442 | caption: /* @__PURE__ */ new Set(["table"]),
|
---|
| 6443 | tbody: /* @__PURE__ */ new Set(["table"]),
|
---|
| 6444 | tfoot: /* @__PURE__ */ new Set(["table"]),
|
---|
| 6445 | col: /* @__PURE__ */ new Set(["colgroup"]),
|
---|
| 6446 | th: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 6447 | thead: /* @__PURE__ */ new Set(["table"]),
|
---|
| 6448 | tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
|
---|
| 6449 | // data list
|
---|
| 6450 | dd: /* @__PURE__ */ new Set(["dl", "div"]),
|
---|
| 6451 | dt: /* @__PURE__ */ new Set(["dl", "div"]),
|
---|
| 6452 | // other
|
---|
| 6453 | figcaption: /* @__PURE__ */ new Set(["figure"]),
|
---|
| 6454 | // li: new Set(["ul", "ol"]),
|
---|
| 6455 | summary: /* @__PURE__ */ new Set(["details"]),
|
---|
| 6456 | area: /* @__PURE__ */ new Set(["map"])
|
---|
| 6457 | };
|
---|
| 6458 | const knownInvalidChildren = {
|
---|
| 6459 | p: /* @__PURE__ */ new Set([
|
---|
| 6460 | "address",
|
---|
| 6461 | "article",
|
---|
| 6462 | "aside",
|
---|
| 6463 | "blockquote",
|
---|
| 6464 | "center",
|
---|
| 6465 | "details",
|
---|
| 6466 | "dialog",
|
---|
| 6467 | "dir",
|
---|
| 6468 | "div",
|
---|
| 6469 | "dl",
|
---|
| 6470 | "fieldset",
|
---|
| 6471 | "figure",
|
---|
| 6472 | "footer",
|
---|
| 6473 | "form",
|
---|
| 6474 | "h1",
|
---|
| 6475 | "h2",
|
---|
| 6476 | "h3",
|
---|
| 6477 | "h4",
|
---|
| 6478 | "h5",
|
---|
| 6479 | "h6",
|
---|
| 6480 | "header",
|
---|
| 6481 | "hgroup",
|
---|
| 6482 | "hr",
|
---|
| 6483 | "li",
|
---|
| 6484 | "main",
|
---|
| 6485 | "nav",
|
---|
| 6486 | "menu",
|
---|
| 6487 | "ol",
|
---|
| 6488 | "p",
|
---|
| 6489 | "pre",
|
---|
| 6490 | "section",
|
---|
| 6491 | "table",
|
---|
| 6492 | "ul"
|
---|
| 6493 | ]),
|
---|
| 6494 | svg: /* @__PURE__ */ new Set([
|
---|
| 6495 | "b",
|
---|
| 6496 | "blockquote",
|
---|
| 6497 | "br",
|
---|
| 6498 | "code",
|
---|
| 6499 | "dd",
|
---|
| 6500 | "div",
|
---|
| 6501 | "dl",
|
---|
| 6502 | "dt",
|
---|
| 6503 | "em",
|
---|
| 6504 | "embed",
|
---|
| 6505 | "h1",
|
---|
| 6506 | "h2",
|
---|
| 6507 | "h3",
|
---|
| 6508 | "h4",
|
---|
| 6509 | "h5",
|
---|
| 6510 | "h6",
|
---|
| 6511 | "hr",
|
---|
| 6512 | "i",
|
---|
| 6513 | "img",
|
---|
| 6514 | "li",
|
---|
| 6515 | "menu",
|
---|
| 6516 | "meta",
|
---|
| 6517 | "ol",
|
---|
| 6518 | "p",
|
---|
| 6519 | "pre",
|
---|
| 6520 | "ruby",
|
---|
| 6521 | "s",
|
---|
| 6522 | "small",
|
---|
| 6523 | "span",
|
---|
| 6524 | "strong",
|
---|
| 6525 | "sub",
|
---|
| 6526 | "sup",
|
---|
| 6527 | "table",
|
---|
| 6528 | "u",
|
---|
| 6529 | "ul",
|
---|
| 6530 | "var"
|
---|
| 6531 | ])
|
---|
| 6532 | };
|
---|
| 6533 | const knownInvalidParents = {
|
---|
| 6534 | a: /* @__PURE__ */ new Set(["a"]),
|
---|
| 6535 | button: /* @__PURE__ */ new Set(["button"]),
|
---|
| 6536 | dd: /* @__PURE__ */ new Set(["dd", "dt"]),
|
---|
| 6537 | dt: /* @__PURE__ */ new Set(["dd", "dt"]),
|
---|
| 6538 | form: /* @__PURE__ */ new Set(["form"]),
|
---|
| 6539 | li: /* @__PURE__ */ new Set(["li"]),
|
---|
| 6540 | h1: headings,
|
---|
| 6541 | h2: headings,
|
---|
| 6542 | h3: headings,
|
---|
| 6543 | h4: headings,
|
---|
| 6544 | h5: headings,
|
---|
| 6545 | h6: headings
|
---|
| 6546 | };
|
---|
| 6547 |
|
---|
| 6548 | const validateHtmlNesting = (node, context) => {
|
---|
| 6549 | if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
|
---|
| 6550 | const error = new SyntaxError(
|
---|
| 6551 | `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
|
---|
| 6552 | );
|
---|
| 6553 | error.loc = node.loc;
|
---|
| 6554 | context.onWarn(error);
|
---|
| 6555 | }
|
---|
| 6556 | };
|
---|
| 6557 |
|
---|
| 6558 | const DOMNodeTransforms = [
|
---|
| 6559 | transformStyle,
|
---|
| 6560 | ...[transformTransition, validateHtmlNesting]
|
---|
| 6561 | ];
|
---|
| 6562 | const DOMDirectiveTransforms = {
|
---|
| 6563 | cloak: noopDirectiveTransform,
|
---|
| 6564 | html: transformVHtml,
|
---|
| 6565 | text: transformVText,
|
---|
| 6566 | model: transformModel,
|
---|
| 6567 | // override compiler-core
|
---|
| 6568 | on: transformOn,
|
---|
| 6569 | // override compiler-core
|
---|
| 6570 | show: transformShow
|
---|
| 6571 | };
|
---|
| 6572 | function compile(src, options = {}) {
|
---|
| 6573 | return baseCompile(
|
---|
| 6574 | src,
|
---|
| 6575 | extend({}, parserOptions, options, {
|
---|
| 6576 | nodeTransforms: [
|
---|
| 6577 | // ignore <script> and <tag>
|
---|
| 6578 | // this is not put inside DOMNodeTransforms because that list is used
|
---|
| 6579 | // by compiler-ssr to generate vnode fallback branches
|
---|
| 6580 | ignoreSideEffectTags,
|
---|
| 6581 | ...DOMNodeTransforms,
|
---|
| 6582 | ...options.nodeTransforms || []
|
---|
| 6583 | ],
|
---|
| 6584 | directiveTransforms: extend(
|
---|
| 6585 | {},
|
---|
| 6586 | DOMDirectiveTransforms,
|
---|
| 6587 | options.directiveTransforms || {}
|
---|
| 6588 | ),
|
---|
| 6589 | transformHoist: null
|
---|
| 6590 | })
|
---|
| 6591 | );
|
---|
| 6592 | }
|
---|
| 6593 | function parse(template, options = {}) {
|
---|
| 6594 | return baseParse(template, extend({}, parserOptions, options));
|
---|
| 6595 | }
|
---|
| 6596 |
|
---|
| 6597 | export { BASE_TRANSITION, BindingTypes, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, CompilerDeprecationTypes, ConstantTypes, DOMDirectiveTransforms, DOMErrorCodes, DOMErrorMessages, DOMNodeTransforms, ElementTypes, ErrorCodes, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, Namespaces, NodeTypes, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TRANSITION, TRANSITION_GROUP, TS_NODE_TYPES, UNREF, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, compile, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createDOMCompilerError, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, errorMessages, extractIdentifiers, findDir, findProp, forAliasRE, generate, generateCodeFrame, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, helperNameMap, injectProp, isCoreComponent, isFnExpression, isFnExpressionBrowser, isFnExpressionNode, isFunctionType, isInDestructureAssignment, isInNewExpression, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText$1 as isText, isVSlot, locStub, noopDirectiveTransform, parse, parserOptions, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel$1 as transformModel, transformOn$1 as transformOn, transformStyle, traverseNode, unwrapTSNode, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
|
---|