import { parse, NodeTypes, ElementNode, TextNode, ErrorCodes, ElementTypes, InterpolationNode } from '@vue/compiler-core' import { parserOptionsMinimal as parserOptions, DOMNamespaces } from '../src/parserOptionsMinimal' describe('DOM parser', () => { describe('Text', () => { test('textarea handles comments/elements as just text', () => { const ast = parse( '', parserOptions ) const element = ast.children[0] as ElementNode const text = element.children[0] as TextNode expect(text).toStrictEqual({ type: NodeTypes.TEXT, content: 'some
 tag should preserve raw whitespace', () => {
      const rawText = `  \na    b    \n   c`
      const ast = parse(`${rawText}`, parserOptions)
      expect((ast.children[0] as ElementNode).children[0]).toMatchObject({
        type: NodeTypes.TEXT,
        content: rawText
      })
    })
  })
  describe('Interpolation', () => {
    test('HTML entities in interpolation should be translated for backward compatibility.', () => {
      const ast = parse('{{ a < b }}', parserOptions)
      const element = ast.children[0] as ElementNode
      const interpolation = element.children[0] as InterpolationNode
      expect(interpolation).toStrictEqual({
        type: NodeTypes.INTERPOLATION,
        content: {
          type: NodeTypes.SIMPLE_EXPRESSION,
          content: `a < b`,
          isStatic: false,
          isConstant: false,
          loc: {
            start: { offset: 8, line: 1, column: 9 },
            end: { offset: 16, line: 1, column: 17 },
            source: 'a < b'
          }
        },
        loc: {
          start: { offset: 5, line: 1, column: 6 },
          end: { offset: 19, line: 1, column: 20 },
          source: '{{ a < b }}'
        }
      })
    })
  })
  describe('Element', () => {
    test('void element', () => {
      const ast = parse('![]() after', parserOptions)
      const element = ast.children[0] as ElementNode
      expect(element).toStrictEqual({
        type: NodeTypes.ELEMENT,
        ns: DOMNamespaces.HTML,
        tag: 'img',
        tagType: ElementTypes.ELEMENT,
        props: [],
        isSelfClosing: false,
        children: [],
        loc: {
          start: { offset: 0, line: 1, column: 1 },
          end: { offset: 5, line: 1, column: 6 },
          source: '
after', parserOptions)
      const element = ast.children[0] as ElementNode
      expect(element).toStrictEqual({
        type: NodeTypes.ELEMENT,
        ns: DOMNamespaces.HTML,
        tag: 'img',
        tagType: ElementTypes.ELEMENT,
        props: [],
        isSelfClosing: false,
        children: [],
        loc: {
          start: { offset: 0, line: 1, column: 1 },
          end: { offset: 5, line: 1, column: 6 },
          source: '![]() '
        },
        codegenNode: undefined
      })
    })
    test('native element', () => {
      const ast = parse('
'
        },
        codegenNode: undefined
      })
    })
    test('native element', () => {
      const ast = parse('