import { NO, makeMap, isArray } from '@vue/shared' import { ErrorCodes, createCompilerError, defaultOnError, CompilerError } from './errors' import { assert, advancePositionWithMutation, advancePositionWithClone } from './utils' import { Namespace, Namespaces, AttributeNode, CommentNode, DirectiveNode, ElementNode, ElementTypes, ExpressionNode, NodeTypes, Position, RootNode, SourceLocation, TextNode, TemplateChildNode, InterpolationNode } from './ast' import { extend } from '@vue/shared' // Portal and Fragment are native types, not components const isBuiltInComponent = /*#__PURE__*/ makeMap( `suspense,keep-alive,keepalive,transition`, true ) export interface ParserOptions { isVoidTag?: (tag: string) => boolean // e.g. img, br, hr isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex isPreTag?: (tag: string) => boolean // e.g.
 where whitespace is intact
  isCustomElement?: (tag: string) => boolean
  getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
  getTextMode?: (tag: string, ns: Namespace) => TextModes
  delimiters?: [string, string] // ['{{', '}}']

  // Map to HTML entities. E.g., `{ "amp;": "&" }`
  // The full set is https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references
  namedCharacterReferences?: { [name: string]: string | undefined }

  onError?: (error: CompilerError) => void
}

// `isNativeTag` is optional, others are required
type MergedParserOptions = Omit, 'isNativeTag'> &
  Pick

export const defaultParserOptions: MergedParserOptions = {
  delimiters: [`{{`, `}}`],
  getNamespace: () => Namespaces.HTML,
  getTextMode: () => TextModes.DATA,
  isVoidTag: NO,
  isPreTag: NO,
  isCustomElement: NO,
  namedCharacterReferences: {
    'gt;': '>',
    'lt;': '<',
    'amp;': '&',
    'apos;': "'",
    'quot;': '"'
  },
  onError: defaultOnError
}

export const enum TextModes {
  //          | Elements | Entities | End sign              | Inside of
  DATA, //    | ✔       | ✔       | End tags of ancestors |
  RCDATA, //  | ✘       | ✔       | End tag of the parent |