fix(template-ref): fix string template refs inside slots

This commit is contained in:
Evan You
2020-02-25 18:29:51 -05:00
parent 8cb0b83088
commit 3eab143843
6 changed files with 110 additions and 7 deletions

View File

@@ -0,0 +1,49 @@
import { baseParse as parse } from '../../src/parse'
import { transform } from '../../src/transform'
import { transformRef } from '../../src/transforms/transformRef'
import { ElementNode, NodeTypes } from '../../src/ast'
function transformWithRef(template: string) {
const ast = parse(template)
transform(ast, {
nodeTransforms: [transformRef]
})
return ast.children[0] as ElementNode
}
describe('compiler: transform ref', () => {
const getExpected = (key: any) => ({
type: NodeTypes.DIRECTIVE,
name: 'bind',
arg: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: `ref`
},
exp: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`[_ctx, `, key, `]`]
}
})
test('static', () => {
const node = transformWithRef(`<div ref="test"/>`)
expect(node.props[0]).toMatchObject(
getExpected({
type: NodeTypes.SIMPLE_EXPRESSION,
content: `test`,
isStatic: true
})
)
})
test('dynamic', () => {
const node = transformWithRef(`<div :ref="test"/>`)
expect(node.props[0]).toMatchObject(
getExpected({
type: NodeTypes.SIMPLE_EXPRESSION,
content: `test`,
isStatic: false
})
)
})
})