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