|
|
@@ -377,10 +377,12 @@ describe('compiler: parse', () => {
|
|
|
|
|
|
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)
|
|
|
})
|
|
|
@@ -636,6 +638,40 @@ describe('compiler: parse', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ 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
|
|
|
@@ -1679,6 +1715,14 @@ foo
|
|
|
})
|
|
|
|
|
|
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'),
|
|
|
@@ -1746,6 +1790,27 @@ foo
|
|
|
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', () => {
|
|
|
@@ -2222,6 +2287,15 @@ foo
|
|
|
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: [
|
|
|
@@ -2391,6 +2465,15 @@ foo
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
+ {
|
|
|
+ code: '<template><!--a<!--b<!----></template>',
|
|
|
+ errors: [
|
|
|
+ {
|
|
|
+ type: ErrorCodes.NESTED_COMMENT,
|
|
|
+ loc: { offset: 15, line: 1, column: 16 }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
{
|
|
|
code: '<template><!--a<!--></template>',
|
|
|
errors: []
|