}
`;
+exports[`compiler: parse Errors EOF_IN_TAG <div></div 1`] = `
+Object {
+ "cached": 0,
+ "children": Array [
+ Object {
+ "children": Array [],
+ "codegenNode": undefined,
+ "isSelfClosing": false,
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ "offset": 10,
+ },
+ "source": "<div></div",
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ "offset": 0,
+ },
+ },
+ "ns": 0,
+ "props": Array [],
+ "tag": "div",
+ "tagType": 0,
+ "type": 1,
+ },
+ ],
+ "codegenNode": undefined,
+ "components": Array [],
+ "directives": Array [],
+ "helpers": Array [],
+ "hoists": Array [],
+ "imports": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 11,
+ "line": 1,
+ "offset": 10,
+ },
+ "source": "<div></div",
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ "offset": 0,
+ },
+ },
+ "temps": 0,
+ "type": 0,
+}
+`;
+
exports[`compiler: parse Errors EOF_IN_TAG <template><div 1`] = `
Object {
"cached": 0,
}
`;
+exports[`compiler: parse Errors NESTED_COMMENT <template><!--a<!--b<!----></template> 1`] = `
+Object {
+ "cached": 0,
+ "children": Array [
+ Object {
+ "children": Array [
+ Object {
+ "content": "a<!--b<!--",
+ "loc": Object {
+ "end": Object {
+ "column": 28,
+ "line": 1,
+ "offset": 27,
+ },
+ "source": "<!--a<!--b<!---->",
+ "start": Object {
+ "column": 11,
+ "line": 1,
+ "offset": 10,
+ },
+ },
+ "type": 3,
+ },
+ ],
+ "codegenNode": undefined,
+ "isSelfClosing": false,
+ "loc": Object {
+ "end": Object {
+ "column": 39,
+ "line": 1,
+ "offset": 38,
+ },
+ "source": "<template><!--a<!--b<!----></template>",
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ "offset": 0,
+ },
+ },
+ "ns": 0,
+ "props": Array [],
+ "tag": "template",
+ "tagType": 0,
+ "type": 1,
+ },
+ ],
+ "codegenNode": undefined,
+ "components": Array [],
+ "directives": Array [],
+ "helpers": Array [],
+ "hoists": Array [],
+ "imports": Array [],
+ "loc": Object {
+ "end": Object {
+ "column": 39,
+ "line": 1,
+ "offset": 38,
+ },
+ "source": "<template><!--a<!--b<!----></template>",
+ "start": Object {
+ "column": 1,
+ "line": 1,
+ "offset": 0,
+ },
+ },
+ "temps": 0,
+ "type": 0,
+}
+`;
+
exports[`compiler: parse Errors NESTED_COMMENT <template><!--a<!--b<!--c--></template> 1`] = `
Object {
"cached": 0,
test('comments option', () => {
__DEV__ = false
- const astNoComment = baseParse('<!--abc-->')
+ const astDefaultComment = baseParse('<!--abc-->')
+ const astNoComment = baseParse('<!--abc-->', { comments: false })
const astWithComments = baseParse('<!--abc-->', { comments: true })
__DEV__ = true
+ expect(astDefaultComment.children).toHaveLength(0)
expect(astNoComment.children).toHaveLength(0)
expect(astWithComments.children).toHaveLength(1)
})
})
})
+ test('built-in component', () => {
+ const ast = baseParse('<div></div><comp></comp>', {
+ isBuiltInComponent: tag => (tag === 'comp' ? Symbol() : void 0)
+ })
+
+ expect(ast.children[0]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'div',
+ tagType: ElementTypes.ELEMENT
+ })
+
+ expect(ast.children[1]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'comp',
+ tagType: ElementTypes.COMPONENT
+ })
+ })
+
+ test('slot element', () => {
+ const ast = baseParse('<slot></slot><Comp></Comp>')
+
+ expect(ast.children[0]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'slot',
+ tagType: ElementTypes.SLOT
+ })
+
+ expect(ast.children[1]).toMatchObject({
+ type: NodeTypes.ELEMENT,
+ tag: 'Comp',
+ tagType: ElementTypes.COMPONENT
+ })
+ })
+
test('attribute with no value', () => {
const ast = baseParse('<div id></div>')
const element = ast.children[0] as ElementNode
})
describe('decodeEntities option', () => {
+ test('use default map', () => {
+ const ast: any = baseParse('><&'"&foo;')
+
+ expect(ast.children.length).toBe(1)
+ expect(ast.children[0].type).toBe(NodeTypes.TEXT)
+ expect(ast.children[0].content).toBe('><&\'"&foo;')
+ })
+
test('use the given map', () => {
const ast: any = baseParse('&∪︀', {
decodeEntities: text => text.replace('∪︀', '\u222A\uFE00'),
const ast = baseParse(` foo \n bar baz `)
expect((ast.children[0] as TextNode).content).toBe(` foo bar baz `)
})
+
+ it('should remove leading newline character immediately following the pre element start tag', () => {
+ const ast = baseParse(`<pre>\n foo bar </pre>`, {
+ isPreTag: tag => tag === 'pre'
+ })
+ expect(ast.children).toHaveLength(1)
+ const preElement = ast.children[0] as ElementNode
+ expect(preElement.children).toHaveLength(1)
+ expect((preElement.children[0] as TextNode).content).toBe(` foo bar `)
+ })
+
+ it('should NOT remove leading newline character immediately following child-tag of pre element', () => {
+ const ast = baseParse(`<pre><span></span>\n foo bar </pre>`, {
+ isPreTag: tag => tag === 'pre'
+ })
+ const preElement = ast.children[0] as ElementNode
+ expect(preElement.children).toHaveLength(2)
+ expect((preElement.children[1] as TextNode).content).toBe(
+ `\n foo bar `
+ )
+ })
})
describe('Errors', () => {
loc: { offset: 0, line: 1, column: 1 }
}
]
+ },
+ {
+ code: '<div></div',
+ errors: [
+ {
+ type: ErrorCodes.EOF_IN_TAG,
+ loc: { offset: 10, line: 1, column: 11 }
+ }
+ ]
}
],
INCORRECTLY_CLOSED_COMMENT: [
}
]
},
+ {
+ code: '<template><!--a<!--b<!----></template>',
+ errors: [
+ {
+ type: ErrorCodes.NESTED_COMMENT,
+ loc: { offset: 15, line: 1, column: 16 }
+ }
+ ]
+ },
{
code: '<template><!--a<!--></template>',
errors: []