* Convert HTML string to AST.
(
template,
options
)
| 9584 | * Convert HTML string to AST. |
| 9585 | */ |
| 9586 | function parse ( |
| 9587 | template, |
| 9588 | options |
| 9589 | ) { |
| 9590 | warn$2 = options.warn || baseWarn; |
| 9591 | |
| 9592 | platformIsPreTag = options.isPreTag || no; |
| 9593 | platformMustUseProp = options.mustUseProp || no; |
| 9594 | platformGetTagNamespace = options.getTagNamespace || no; |
| 9595 | var isReservedTag = options.isReservedTag || no; |
| 9596 | maybeComponent = function (el) { return !!el.component || !isReservedTag(el.tag); }; |
| 9597 | |
| 9598 | transforms = pluckModuleFunction(options.modules, 'transformNode'); |
| 9599 | preTransforms = pluckModuleFunction(options.modules, 'preTransformNode'); |
| 9600 | postTransforms = pluckModuleFunction(options.modules, 'postTransformNode'); |
| 9601 | |
| 9602 | delimiters = options.delimiters; |
| 9603 | |
| 9604 | var stack = []; |
| 9605 | var preserveWhitespace = options.preserveWhitespace !== false; |
| 9606 | var whitespaceOption = options.whitespace; |
| 9607 | var root; |
| 9608 | var currentParent; |
| 9609 | var inVPre = false; |
| 9610 | var inPre = false; |
| 9611 | var warned = false; |
| 9612 | |
| 9613 | function warnOnce (msg, range) { |
| 9614 | if (!warned) { |
| 9615 | warned = true; |
| 9616 | warn$2(msg, range); |
| 9617 | } |
| 9618 | } |
| 9619 | |
| 9620 | function closeElement (element) { |
| 9621 | trimEndingWhitespace(element); |
| 9622 | if (!inVPre && !element.processed) { |
| 9623 | element = processElement(element, options); |
| 9624 | } |
| 9625 | // tree management |
| 9626 | if (!stack.length && element !== root) { |
| 9627 | // allow root elements with v-if, v-else-if and v-else |
| 9628 | if (root.if && (element.elseif || element.else)) { |
| 9629 | { |
| 9630 | checkRootConstraints(element); |
| 9631 | } |
| 9632 | addIfCondition(root, { |
| 9633 | exp: element.elseif, |
| 9634 | block: element |
| 9635 | }); |
| 9636 | } else { |
| 9637 | warnOnce( |
| 9638 | "Component template should contain exactly one root element. " + |
| 9639 | "If you are using v-if on multiple elements, " + |
| 9640 | "use v-else-if to chain them instead.", |
| 9641 | { start: element.start } |
| 9642 | ); |
| 9643 | } |
no test coverage detected