[57e58a3] | 1 | /**
|
---|
| 2 | * @vue/compiler-dom v3.5.13
|
---|
| 3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
| 4 | * @license MIT
|
---|
| 5 | **/
|
---|
| 6 | import { registerRuntimeHelpers, createSimpleExpression, createCompilerError, createObjectProperty, getConstantType, createCallExpression, TO_DISPLAY_STRING, transformModel as transformModel$1, findProp, hasDynamicKeyVBind, findDir, isStaticArgOf, transformOn as transformOn$1, isStaticExp, createCompoundExpression, checkCompatEnabled, noopDirectiveTransform, baseCompile, baseParse } from '@vue/compiler-core';
|
---|
| 7 | export * from '@vue/compiler-core';
|
---|
| 8 | import { isVoidTag, isHTMLTag, isSVGTag, isMathMLTag, parseStringStyle, capitalize, makeMap, extend } from '@vue/shared';
|
---|
| 9 |
|
---|
| 10 | const V_MODEL_RADIO = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelRadio` : ``);
|
---|
| 11 | const V_MODEL_CHECKBOX = Symbol(
|
---|
| 12 | !!(process.env.NODE_ENV !== "production") ? `vModelCheckbox` : ``
|
---|
| 13 | );
|
---|
| 14 | const V_MODEL_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelText` : ``);
|
---|
| 15 | const V_MODEL_SELECT = Symbol(
|
---|
| 16 | !!(process.env.NODE_ENV !== "production") ? `vModelSelect` : ``
|
---|
| 17 | );
|
---|
| 18 | const V_MODEL_DYNAMIC = Symbol(
|
---|
| 19 | !!(process.env.NODE_ENV !== "production") ? `vModelDynamic` : ``
|
---|
| 20 | );
|
---|
| 21 | const V_ON_WITH_MODIFIERS = Symbol(
|
---|
| 22 | !!(process.env.NODE_ENV !== "production") ? `vOnModifiersGuard` : ``
|
---|
| 23 | );
|
---|
| 24 | const V_ON_WITH_KEYS = Symbol(
|
---|
| 25 | !!(process.env.NODE_ENV !== "production") ? `vOnKeysGuard` : ``
|
---|
| 26 | );
|
---|
| 27 | const V_SHOW = Symbol(!!(process.env.NODE_ENV !== "production") ? `vShow` : ``);
|
---|
| 28 | const TRANSITION = Symbol(!!(process.env.NODE_ENV !== "production") ? `Transition` : ``);
|
---|
| 29 | const TRANSITION_GROUP = Symbol(
|
---|
| 30 | !!(process.env.NODE_ENV !== "production") ? `TransitionGroup` : ``
|
---|
| 31 | );
|
---|
| 32 | registerRuntimeHelpers({
|
---|
| 33 | [V_MODEL_RADIO]: `vModelRadio`,
|
---|
| 34 | [V_MODEL_CHECKBOX]: `vModelCheckbox`,
|
---|
| 35 | [V_MODEL_TEXT]: `vModelText`,
|
---|
| 36 | [V_MODEL_SELECT]: `vModelSelect`,
|
---|
| 37 | [V_MODEL_DYNAMIC]: `vModelDynamic`,
|
---|
| 38 | [V_ON_WITH_MODIFIERS]: `withModifiers`,
|
---|
| 39 | [V_ON_WITH_KEYS]: `withKeys`,
|
---|
| 40 | [V_SHOW]: `vShow`,
|
---|
| 41 | [TRANSITION]: `Transition`,
|
---|
| 42 | [TRANSITION_GROUP]: `TransitionGroup`
|
---|
| 43 | });
|
---|
| 44 |
|
---|
| 45 | let decoder;
|
---|
| 46 | function decodeHtmlBrowser(raw, asAttr = false) {
|
---|
| 47 | if (!decoder) {
|
---|
| 48 | decoder = document.createElement("div");
|
---|
| 49 | }
|
---|
| 50 | if (asAttr) {
|
---|
| 51 | decoder.innerHTML = `<div foo="${raw.replace(/"/g, """)}">`;
|
---|
| 52 | return decoder.children[0].getAttribute("foo");
|
---|
| 53 | } else {
|
---|
| 54 | decoder.innerHTML = raw;
|
---|
| 55 | return decoder.textContent;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | const parserOptions = {
|
---|
| 60 | parseMode: "html",
|
---|
| 61 | isVoidTag,
|
---|
| 62 | isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
|
---|
| 63 | isPreTag: (tag) => tag === "pre",
|
---|
| 64 | isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
|
---|
| 65 | decodeEntities: decodeHtmlBrowser ,
|
---|
| 66 | isBuiltInComponent: (tag) => {
|
---|
| 67 | if (tag === "Transition" || tag === "transition") {
|
---|
| 68 | return TRANSITION;
|
---|
| 69 | } else if (tag === "TransitionGroup" || tag === "transition-group") {
|
---|
| 70 | return TRANSITION_GROUP;
|
---|
| 71 | }
|
---|
| 72 | },
|
---|
| 73 | // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
|
---|
| 74 | getNamespace(tag, parent, rootNamespace) {
|
---|
| 75 | let ns = parent ? parent.ns : rootNamespace;
|
---|
| 76 | if (parent && ns === 2) {
|
---|
| 77 | if (parent.tag === "annotation-xml") {
|
---|
| 78 | if (tag === "svg") {
|
---|
| 79 | return 1;
|
---|
| 80 | }
|
---|
| 81 | if (parent.props.some(
|
---|
| 82 | (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
|
---|
| 83 | )) {
|
---|
| 84 | ns = 0;
|
---|
| 85 | }
|
---|
| 86 | } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
|
---|
| 87 | ns = 0;
|
---|
| 88 | }
|
---|
| 89 | } else if (parent && ns === 1) {
|
---|
| 90 | if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
|
---|
| 91 | ns = 0;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | if (ns === 0) {
|
---|
| 95 | if (tag === "svg") {
|
---|
| 96 | return 1;
|
---|
| 97 | }
|
---|
| 98 | if (tag === "math") {
|
---|
| 99 | return 2;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | return ns;
|
---|
| 103 | }
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | const transformStyle = (node) => {
|
---|
| 107 | if (node.type === 1) {
|
---|
| 108 | node.props.forEach((p, i) => {
|
---|
| 109 | if (p.type === 6 && p.name === "style" && p.value) {
|
---|
| 110 | node.props[i] = {
|
---|
| 111 | type: 7,
|
---|
| 112 | name: `bind`,
|
---|
| 113 | arg: createSimpleExpression(`style`, true, p.loc),
|
---|
| 114 | exp: parseInlineCSS(p.value.content, p.loc),
|
---|
| 115 | modifiers: [],
|
---|
| 116 | loc: p.loc
|
---|
| 117 | };
|
---|
| 118 | }
|
---|
| 119 | });
|
---|
| 120 | }
|
---|
| 121 | };
|
---|
| 122 | const parseInlineCSS = (cssText, loc) => {
|
---|
| 123 | const normalized = parseStringStyle(cssText);
|
---|
| 124 | return createSimpleExpression(
|
---|
| 125 | JSON.stringify(normalized),
|
---|
| 126 | false,
|
---|
| 127 | loc,
|
---|
| 128 | 3
|
---|
| 129 | );
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | function createDOMCompilerError(code, loc) {
|
---|
| 133 | return createCompilerError(
|
---|
| 134 | code,
|
---|
| 135 | loc,
|
---|
| 136 | !!(process.env.NODE_ENV !== "production") || false ? DOMErrorMessages : void 0
|
---|
| 137 | );
|
---|
| 138 | }
|
---|
| 139 | const DOMErrorCodes = {
|
---|
| 140 | "X_V_HTML_NO_EXPRESSION": 53,
|
---|
| 141 | "53": "X_V_HTML_NO_EXPRESSION",
|
---|
| 142 | "X_V_HTML_WITH_CHILDREN": 54,
|
---|
| 143 | "54": "X_V_HTML_WITH_CHILDREN",
|
---|
| 144 | "X_V_TEXT_NO_EXPRESSION": 55,
|
---|
| 145 | "55": "X_V_TEXT_NO_EXPRESSION",
|
---|
| 146 | "X_V_TEXT_WITH_CHILDREN": 56,
|
---|
| 147 | "56": "X_V_TEXT_WITH_CHILDREN",
|
---|
| 148 | "X_V_MODEL_ON_INVALID_ELEMENT": 57,
|
---|
| 149 | "57": "X_V_MODEL_ON_INVALID_ELEMENT",
|
---|
| 150 | "X_V_MODEL_ARG_ON_ELEMENT": 58,
|
---|
| 151 | "58": "X_V_MODEL_ARG_ON_ELEMENT",
|
---|
| 152 | "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
|
---|
| 153 | "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
|
---|
| 154 | "X_V_MODEL_UNNECESSARY_VALUE": 60,
|
---|
| 155 | "60": "X_V_MODEL_UNNECESSARY_VALUE",
|
---|
| 156 | "X_V_SHOW_NO_EXPRESSION": 61,
|
---|
| 157 | "61": "X_V_SHOW_NO_EXPRESSION",
|
---|
| 158 | "X_TRANSITION_INVALID_CHILDREN": 62,
|
---|
| 159 | "62": "X_TRANSITION_INVALID_CHILDREN",
|
---|
| 160 | "X_IGNORED_SIDE_EFFECT_TAG": 63,
|
---|
| 161 | "63": "X_IGNORED_SIDE_EFFECT_TAG",
|
---|
| 162 | "__EXTEND_POINT__": 64,
|
---|
| 163 | "64": "__EXTEND_POINT__"
|
---|
| 164 | };
|
---|
| 165 | const DOMErrorMessages = {
|
---|
| 166 | [53]: `v-html is missing expression.`,
|
---|
| 167 | [54]: `v-html will override element children.`,
|
---|
| 168 | [55]: `v-text is missing expression.`,
|
---|
| 169 | [56]: `v-text will override element children.`,
|
---|
| 170 | [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
---|
| 171 | [58]: `v-model argument is not supported on plain elements.`,
|
---|
| 172 | [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
|
---|
| 173 | [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
---|
| 174 | [61]: `v-show is missing expression.`,
|
---|
| 175 | [62]: `<Transition> expects exactly one child element or component.`,
|
---|
| 176 | [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 | const transformVHtml = (dir, node, context) => {
|
---|
| 180 | const { exp, loc } = dir;
|
---|
| 181 | if (!exp) {
|
---|
| 182 | context.onError(
|
---|
| 183 | createDOMCompilerError(53, loc)
|
---|
| 184 | );
|
---|
| 185 | }
|
---|
| 186 | if (node.children.length) {
|
---|
| 187 | context.onError(
|
---|
| 188 | createDOMCompilerError(54, loc)
|
---|
| 189 | );
|
---|
| 190 | node.children.length = 0;
|
---|
| 191 | }
|
---|
| 192 | return {
|
---|
| 193 | props: [
|
---|
| 194 | createObjectProperty(
|
---|
| 195 | createSimpleExpression(`innerHTML`, true, loc),
|
---|
| 196 | exp || createSimpleExpression("", true)
|
---|
| 197 | )
|
---|
| 198 | ]
|
---|
| 199 | };
|
---|
| 200 | };
|
---|
| 201 |
|
---|
| 202 | const transformVText = (dir, node, context) => {
|
---|
| 203 | const { exp, loc } = dir;
|
---|
| 204 | if (!exp) {
|
---|
| 205 | context.onError(
|
---|
| 206 | createDOMCompilerError(55, loc)
|
---|
| 207 | );
|
---|
| 208 | }
|
---|
| 209 | if (node.children.length) {
|
---|
| 210 | context.onError(
|
---|
| 211 | createDOMCompilerError(56, loc)
|
---|
| 212 | );
|
---|
| 213 | node.children.length = 0;
|
---|
| 214 | }
|
---|
| 215 | return {
|
---|
| 216 | props: [
|
---|
| 217 | createObjectProperty(
|
---|
| 218 | createSimpleExpression(`textContent`, true),
|
---|
| 219 | exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
|
---|
| 220 | context.helperString(TO_DISPLAY_STRING),
|
---|
| 221 | [exp],
|
---|
| 222 | loc
|
---|
| 223 | ) : createSimpleExpression("", true)
|
---|
| 224 | )
|
---|
| 225 | ]
|
---|
| 226 | };
|
---|
| 227 | };
|
---|
| 228 |
|
---|
| 229 | const transformModel = (dir, node, context) => {
|
---|
| 230 | const baseResult = transformModel$1(dir, node, context);
|
---|
| 231 | if (!baseResult.props.length || node.tagType === 1) {
|
---|
| 232 | return baseResult;
|
---|
| 233 | }
|
---|
| 234 | if (dir.arg) {
|
---|
| 235 | context.onError(
|
---|
| 236 | createDOMCompilerError(
|
---|
| 237 | 58,
|
---|
| 238 | dir.arg.loc
|
---|
| 239 | )
|
---|
| 240 | );
|
---|
| 241 | }
|
---|
| 242 | function checkDuplicatedValue() {
|
---|
| 243 | const value = findDir(node, "bind");
|
---|
| 244 | if (value && isStaticArgOf(value.arg, "value")) {
|
---|
| 245 | context.onError(
|
---|
| 246 | createDOMCompilerError(
|
---|
| 247 | 60,
|
---|
| 248 | value.loc
|
---|
| 249 | )
|
---|
| 250 | );
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | const { tag } = node;
|
---|
| 254 | const isCustomElement = context.isCustomElement(tag);
|
---|
| 255 | if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
|
---|
| 256 | let directiveToUse = V_MODEL_TEXT;
|
---|
| 257 | let isInvalidType = false;
|
---|
| 258 | if (tag === "input" || isCustomElement) {
|
---|
| 259 | const type = findProp(node, `type`);
|
---|
| 260 | if (type) {
|
---|
| 261 | if (type.type === 7) {
|
---|
| 262 | directiveToUse = V_MODEL_DYNAMIC;
|
---|
| 263 | } else if (type.value) {
|
---|
| 264 | switch (type.value.content) {
|
---|
| 265 | case "radio":
|
---|
| 266 | directiveToUse = V_MODEL_RADIO;
|
---|
| 267 | break;
|
---|
| 268 | case "checkbox":
|
---|
| 269 | directiveToUse = V_MODEL_CHECKBOX;
|
---|
| 270 | break;
|
---|
| 271 | case "file":
|
---|
| 272 | isInvalidType = true;
|
---|
| 273 | context.onError(
|
---|
| 274 | createDOMCompilerError(
|
---|
| 275 | 59,
|
---|
| 276 | dir.loc
|
---|
| 277 | )
|
---|
| 278 | );
|
---|
| 279 | break;
|
---|
| 280 | default:
|
---|
| 281 | !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
---|
| 282 | break;
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 | } else if (hasDynamicKeyVBind(node)) {
|
---|
| 286 | directiveToUse = V_MODEL_DYNAMIC;
|
---|
| 287 | } else {
|
---|
| 288 | !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
---|
| 289 | }
|
---|
| 290 | } else if (tag === "select") {
|
---|
| 291 | directiveToUse = V_MODEL_SELECT;
|
---|
| 292 | } else {
|
---|
| 293 | !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
|
---|
| 294 | }
|
---|
| 295 | if (!isInvalidType) {
|
---|
| 296 | baseResult.needRuntime = context.helper(directiveToUse);
|
---|
| 297 | }
|
---|
| 298 | } else {
|
---|
| 299 | context.onError(
|
---|
| 300 | createDOMCompilerError(
|
---|
| 301 | 57,
|
---|
| 302 | dir.loc
|
---|
| 303 | )
|
---|
| 304 | );
|
---|
| 305 | }
|
---|
| 306 | baseResult.props = baseResult.props.filter(
|
---|
| 307 | (p) => !(p.key.type === 4 && p.key.content === "modelValue")
|
---|
| 308 | );
|
---|
| 309 | return baseResult;
|
---|
| 310 | };
|
---|
| 311 |
|
---|
| 312 | const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
|
---|
| 313 | const isNonKeyModifier = /* @__PURE__ */ makeMap(
|
---|
| 314 | // event propagation management
|
---|
| 315 | `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
|
---|
| 316 | );
|
---|
| 317 | const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
|
---|
| 318 | const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
|
---|
| 319 | const resolveModifiers = (key, modifiers, context, loc) => {
|
---|
| 320 | const keyModifiers = [];
|
---|
| 321 | const nonKeyModifiers = [];
|
---|
| 322 | const eventOptionModifiers = [];
|
---|
| 323 | for (let i = 0; i < modifiers.length; i++) {
|
---|
| 324 | const modifier = modifiers[i].content;
|
---|
| 325 | if (modifier === "native" && checkCompatEnabled(
|
---|
| 326 | "COMPILER_V_ON_NATIVE",
|
---|
| 327 | context,
|
---|
| 328 | loc
|
---|
| 329 | )) {
|
---|
| 330 | eventOptionModifiers.push(modifier);
|
---|
| 331 | } else if (isEventOptionModifier(modifier)) {
|
---|
| 332 | eventOptionModifiers.push(modifier);
|
---|
| 333 | } else {
|
---|
| 334 | if (maybeKeyModifier(modifier)) {
|
---|
| 335 | if (isStaticExp(key)) {
|
---|
| 336 | if (isKeyboardEvent(key.content.toLowerCase())) {
|
---|
| 337 | keyModifiers.push(modifier);
|
---|
| 338 | } else {
|
---|
| 339 | nonKeyModifiers.push(modifier);
|
---|
| 340 | }
|
---|
| 341 | } else {
|
---|
| 342 | keyModifiers.push(modifier);
|
---|
| 343 | nonKeyModifiers.push(modifier);
|
---|
| 344 | }
|
---|
| 345 | } else {
|
---|
| 346 | if (isNonKeyModifier(modifier)) {
|
---|
| 347 | nonKeyModifiers.push(modifier);
|
---|
| 348 | } else {
|
---|
| 349 | keyModifiers.push(modifier);
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | return {
|
---|
| 355 | keyModifiers,
|
---|
| 356 | nonKeyModifiers,
|
---|
| 357 | eventOptionModifiers
|
---|
| 358 | };
|
---|
| 359 | };
|
---|
| 360 | const transformClick = (key, event) => {
|
---|
| 361 | const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
|
---|
| 362 | return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
|
---|
| 363 | `(`,
|
---|
| 364 | key,
|
---|
| 365 | `) === "onClick" ? "${event}" : (`,
|
---|
| 366 | key,
|
---|
| 367 | `)`
|
---|
| 368 | ]) : key;
|
---|
| 369 | };
|
---|
| 370 | const transformOn = (dir, node, context) => {
|
---|
| 371 | return transformOn$1(dir, node, context, (baseResult) => {
|
---|
| 372 | const { modifiers } = dir;
|
---|
| 373 | if (!modifiers.length) return baseResult;
|
---|
| 374 | let { key, value: handlerExp } = baseResult.props[0];
|
---|
| 375 | const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
---|
| 376 | if (nonKeyModifiers.includes("right")) {
|
---|
| 377 | key = transformClick(key, `onContextmenu`);
|
---|
| 378 | }
|
---|
| 379 | if (nonKeyModifiers.includes("middle")) {
|
---|
| 380 | key = transformClick(key, `onMouseup`);
|
---|
| 381 | }
|
---|
| 382 | if (nonKeyModifiers.length) {
|
---|
| 383 | handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
|
---|
| 384 | handlerExp,
|
---|
| 385 | JSON.stringify(nonKeyModifiers)
|
---|
| 386 | ]);
|
---|
| 387 | }
|
---|
| 388 | if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
|
---|
| 389 | (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
|
---|
| 390 | handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
|
---|
| 391 | handlerExp,
|
---|
| 392 | JSON.stringify(keyModifiers)
|
---|
| 393 | ]);
|
---|
| 394 | }
|
---|
| 395 | if (eventOptionModifiers.length) {
|
---|
| 396 | const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
|
---|
| 397 | key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
|
---|
| 398 | }
|
---|
| 399 | return {
|
---|
| 400 | props: [createObjectProperty(key, handlerExp)]
|
---|
| 401 | };
|
---|
| 402 | });
|
---|
| 403 | };
|
---|
| 404 |
|
---|
| 405 | const transformShow = (dir, node, context) => {
|
---|
| 406 | const { exp, loc } = dir;
|
---|
| 407 | if (!exp) {
|
---|
| 408 | context.onError(
|
---|
| 409 | createDOMCompilerError(61, loc)
|
---|
| 410 | );
|
---|
| 411 | }
|
---|
| 412 | return {
|
---|
| 413 | props: [],
|
---|
| 414 | needRuntime: context.helper(V_SHOW)
|
---|
| 415 | };
|
---|
| 416 | };
|
---|
| 417 |
|
---|
| 418 | const transformTransition = (node, context) => {
|
---|
| 419 | if (node.type === 1 && node.tagType === 1) {
|
---|
| 420 | const component = context.isBuiltInComponent(node.tag);
|
---|
| 421 | if (component === TRANSITION) {
|
---|
| 422 | return () => {
|
---|
| 423 | if (!node.children.length) {
|
---|
| 424 | return;
|
---|
| 425 | }
|
---|
| 426 | if (hasMultipleChildren(node)) {
|
---|
| 427 | context.onError(
|
---|
| 428 | createDOMCompilerError(
|
---|
| 429 | 62,
|
---|
| 430 | {
|
---|
| 431 | start: node.children[0].loc.start,
|
---|
| 432 | end: node.children[node.children.length - 1].loc.end,
|
---|
| 433 | source: ""
|
---|
| 434 | }
|
---|
| 435 | )
|
---|
| 436 | );
|
---|
| 437 | }
|
---|
| 438 | const child = node.children[0];
|
---|
| 439 | if (child.type === 1) {
|
---|
| 440 | for (const p of child.props) {
|
---|
| 441 | if (p.type === 7 && p.name === "show") {
|
---|
| 442 | node.props.push({
|
---|
| 443 | type: 6,
|
---|
| 444 | name: "persisted",
|
---|
| 445 | nameLoc: node.loc,
|
---|
| 446 | value: void 0,
|
---|
| 447 | loc: node.loc
|
---|
| 448 | });
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 | };
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | };
|
---|
| 456 | function hasMultipleChildren(node) {
|
---|
| 457 | const children = node.children = node.children.filter(
|
---|
| 458 | (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
|
---|
| 459 | );
|
---|
| 460 | const child = children[0];
|
---|
| 461 | return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
|
---|
| 462 | }
|
---|
| 463 |
|
---|
| 464 | const ignoreSideEffectTags = (node, context) => {
|
---|
| 465 | if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
|
---|
| 466 | !!(process.env.NODE_ENV !== "production") && context.onError(
|
---|
| 467 | createDOMCompilerError(
|
---|
| 468 | 63,
|
---|
| 469 | node.loc
|
---|
| 470 | )
|
---|
| 471 | );
|
---|
| 472 | context.removeNode();
|
---|
| 473 | }
|
---|
| 474 | };
|
---|
| 475 |
|
---|
| 476 | function isValidHTMLNesting(parent, child) {
|
---|
| 477 | if (parent in onlyValidChildren) {
|
---|
| 478 | return onlyValidChildren[parent].has(child);
|
---|
| 479 | }
|
---|
| 480 | if (child in onlyValidParents) {
|
---|
| 481 | return onlyValidParents[child].has(parent);
|
---|
| 482 | }
|
---|
| 483 | if (parent in knownInvalidChildren) {
|
---|
| 484 | if (knownInvalidChildren[parent].has(child)) return false;
|
---|
| 485 | }
|
---|
| 486 | if (child in knownInvalidParents) {
|
---|
| 487 | if (knownInvalidParents[child].has(parent)) return false;
|
---|
| 488 | }
|
---|
| 489 | return true;
|
---|
| 490 | }
|
---|
| 491 | const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
---|
| 492 | const emptySet = /* @__PURE__ */ new Set([]);
|
---|
| 493 | const onlyValidChildren = {
|
---|
| 494 | head: /* @__PURE__ */ new Set([
|
---|
| 495 | "base",
|
---|
| 496 | "basefront",
|
---|
| 497 | "bgsound",
|
---|
| 498 | "link",
|
---|
| 499 | "meta",
|
---|
| 500 | "title",
|
---|
| 501 | "noscript",
|
---|
| 502 | "noframes",
|
---|
| 503 | "style",
|
---|
| 504 | "script",
|
---|
| 505 | "template"
|
---|
| 506 | ]),
|
---|
| 507 | optgroup: /* @__PURE__ */ new Set(["option"]),
|
---|
| 508 | select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
|
---|
| 509 | // table
|
---|
| 510 | table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
|
---|
| 511 | tr: /* @__PURE__ */ new Set(["td", "th"]),
|
---|
| 512 | colgroup: /* @__PURE__ */ new Set(["col"]),
|
---|
| 513 | tbody: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 514 | thead: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 515 | tfoot: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 516 | // these elements can not have any children elements
|
---|
| 517 | script: emptySet,
|
---|
| 518 | iframe: emptySet,
|
---|
| 519 | option: emptySet,
|
---|
| 520 | textarea: emptySet,
|
---|
| 521 | style: emptySet,
|
---|
| 522 | title: emptySet
|
---|
| 523 | };
|
---|
| 524 | const onlyValidParents = {
|
---|
| 525 | // sections
|
---|
| 526 | html: emptySet,
|
---|
| 527 | body: /* @__PURE__ */ new Set(["html"]),
|
---|
| 528 | head: /* @__PURE__ */ new Set(["html"]),
|
---|
| 529 | // table
|
---|
| 530 | td: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 531 | colgroup: /* @__PURE__ */ new Set(["table"]),
|
---|
| 532 | caption: /* @__PURE__ */ new Set(["table"]),
|
---|
| 533 | tbody: /* @__PURE__ */ new Set(["table"]),
|
---|
| 534 | tfoot: /* @__PURE__ */ new Set(["table"]),
|
---|
| 535 | col: /* @__PURE__ */ new Set(["colgroup"]),
|
---|
| 536 | th: /* @__PURE__ */ new Set(["tr"]),
|
---|
| 537 | thead: /* @__PURE__ */ new Set(["table"]),
|
---|
| 538 | tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
|
---|
| 539 | // data list
|
---|
| 540 | dd: /* @__PURE__ */ new Set(["dl", "div"]),
|
---|
| 541 | dt: /* @__PURE__ */ new Set(["dl", "div"]),
|
---|
| 542 | // other
|
---|
| 543 | figcaption: /* @__PURE__ */ new Set(["figure"]),
|
---|
| 544 | // li: new Set(["ul", "ol"]),
|
---|
| 545 | summary: /* @__PURE__ */ new Set(["details"]),
|
---|
| 546 | area: /* @__PURE__ */ new Set(["map"])
|
---|
| 547 | };
|
---|
| 548 | const knownInvalidChildren = {
|
---|
| 549 | p: /* @__PURE__ */ new Set([
|
---|
| 550 | "address",
|
---|
| 551 | "article",
|
---|
| 552 | "aside",
|
---|
| 553 | "blockquote",
|
---|
| 554 | "center",
|
---|
| 555 | "details",
|
---|
| 556 | "dialog",
|
---|
| 557 | "dir",
|
---|
| 558 | "div",
|
---|
| 559 | "dl",
|
---|
| 560 | "fieldset",
|
---|
| 561 | "figure",
|
---|
| 562 | "footer",
|
---|
| 563 | "form",
|
---|
| 564 | "h1",
|
---|
| 565 | "h2",
|
---|
| 566 | "h3",
|
---|
| 567 | "h4",
|
---|
| 568 | "h5",
|
---|
| 569 | "h6",
|
---|
| 570 | "header",
|
---|
| 571 | "hgroup",
|
---|
| 572 | "hr",
|
---|
| 573 | "li",
|
---|
| 574 | "main",
|
---|
| 575 | "nav",
|
---|
| 576 | "menu",
|
---|
| 577 | "ol",
|
---|
| 578 | "p",
|
---|
| 579 | "pre",
|
---|
| 580 | "section",
|
---|
| 581 | "table",
|
---|
| 582 | "ul"
|
---|
| 583 | ]),
|
---|
| 584 | svg: /* @__PURE__ */ new Set([
|
---|
| 585 | "b",
|
---|
| 586 | "blockquote",
|
---|
| 587 | "br",
|
---|
| 588 | "code",
|
---|
| 589 | "dd",
|
---|
| 590 | "div",
|
---|
| 591 | "dl",
|
---|
| 592 | "dt",
|
---|
| 593 | "em",
|
---|
| 594 | "embed",
|
---|
| 595 | "h1",
|
---|
| 596 | "h2",
|
---|
| 597 | "h3",
|
---|
| 598 | "h4",
|
---|
| 599 | "h5",
|
---|
| 600 | "h6",
|
---|
| 601 | "hr",
|
---|
| 602 | "i",
|
---|
| 603 | "img",
|
---|
| 604 | "li",
|
---|
| 605 | "menu",
|
---|
| 606 | "meta",
|
---|
| 607 | "ol",
|
---|
| 608 | "p",
|
---|
| 609 | "pre",
|
---|
| 610 | "ruby",
|
---|
| 611 | "s",
|
---|
| 612 | "small",
|
---|
| 613 | "span",
|
---|
| 614 | "strong",
|
---|
| 615 | "sub",
|
---|
| 616 | "sup",
|
---|
| 617 | "table",
|
---|
| 618 | "u",
|
---|
| 619 | "ul",
|
---|
| 620 | "var"
|
---|
| 621 | ])
|
---|
| 622 | };
|
---|
| 623 | const knownInvalidParents = {
|
---|
| 624 | a: /* @__PURE__ */ new Set(["a"]),
|
---|
| 625 | button: /* @__PURE__ */ new Set(["button"]),
|
---|
| 626 | dd: /* @__PURE__ */ new Set(["dd", "dt"]),
|
---|
| 627 | dt: /* @__PURE__ */ new Set(["dd", "dt"]),
|
---|
| 628 | form: /* @__PURE__ */ new Set(["form"]),
|
---|
| 629 | li: /* @__PURE__ */ new Set(["li"]),
|
---|
| 630 | h1: headings,
|
---|
| 631 | h2: headings,
|
---|
| 632 | h3: headings,
|
---|
| 633 | h4: headings,
|
---|
| 634 | h5: headings,
|
---|
| 635 | h6: headings
|
---|
| 636 | };
|
---|
| 637 |
|
---|
| 638 | const validateHtmlNesting = (node, context) => {
|
---|
| 639 | if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
|
---|
| 640 | const error = new SyntaxError(
|
---|
| 641 | `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
|
---|
| 642 | );
|
---|
| 643 | error.loc = node.loc;
|
---|
| 644 | context.onWarn(error);
|
---|
| 645 | }
|
---|
| 646 | };
|
---|
| 647 |
|
---|
| 648 | const DOMNodeTransforms = [
|
---|
| 649 | transformStyle,
|
---|
| 650 | ...!!(process.env.NODE_ENV !== "production") ? [transformTransition, validateHtmlNesting] : []
|
---|
| 651 | ];
|
---|
| 652 | const DOMDirectiveTransforms = {
|
---|
| 653 | cloak: noopDirectiveTransform,
|
---|
| 654 | html: transformVHtml,
|
---|
| 655 | text: transformVText,
|
---|
| 656 | model: transformModel,
|
---|
| 657 | // override compiler-core
|
---|
| 658 | on: transformOn,
|
---|
| 659 | // override compiler-core
|
---|
| 660 | show: transformShow
|
---|
| 661 | };
|
---|
| 662 | function compile(src, options = {}) {
|
---|
| 663 | return baseCompile(
|
---|
| 664 | src,
|
---|
| 665 | extend({}, parserOptions, options, {
|
---|
| 666 | nodeTransforms: [
|
---|
| 667 | // ignore <script> and <tag>
|
---|
| 668 | // this is not put inside DOMNodeTransforms because that list is used
|
---|
| 669 | // by compiler-ssr to generate vnode fallback branches
|
---|
| 670 | ignoreSideEffectTags,
|
---|
| 671 | ...DOMNodeTransforms,
|
---|
| 672 | ...options.nodeTransforms || []
|
---|
| 673 | ],
|
---|
| 674 | directiveTransforms: extend(
|
---|
| 675 | {},
|
---|
| 676 | DOMDirectiveTransforms,
|
---|
| 677 | options.directiveTransforms || {}
|
---|
| 678 | ),
|
---|
| 679 | transformHoist: null
|
---|
| 680 | })
|
---|
| 681 | );
|
---|
| 682 | }
|
---|
| 683 | function parse(template, options = {}) {
|
---|
| 684 | return baseParse(template, extend({}, parserOptions, options));
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | export { DOMDirectiveTransforms, DOMErrorCodes, DOMErrorMessages, DOMNodeTransforms, TRANSITION, TRANSITION_GROUP, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, compile, createDOMCompilerError, parse, parserOptions, transformStyle };
|
---|