fix(compiler-dom): properly stringify class/style bindings when hoisting static strings
This commit is contained in:
@@ -77,8 +77,8 @@ describe('stringify static html', () => {
|
||||
|
||||
test('serliazing constant bindings', () => {
|
||||
const { ast } = compileWithStringify(
|
||||
`<div><div>${repeat(
|
||||
`<span :class="'foo' + 'bar'">{{ 1 }} + {{ false }}</span>`,
|
||||
`<div><div :style="{ color: 'red' }">${repeat(
|
||||
`<span :class="[{ foo: true }, { bar: true }]">{{ 1 }} + {{ false }}</span>`,
|
||||
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
|
||||
)}</div></div>`
|
||||
)
|
||||
@@ -89,8 +89,8 @@ describe('stringify static html', () => {
|
||||
callee: CREATE_STATIC,
|
||||
arguments: [
|
||||
JSON.stringify(
|
||||
`<div>${repeat(
|
||||
`<span class="foobar">1 + false</span>`,
|
||||
`<div style="color:red;">${repeat(
|
||||
`<span class="foo bar">1 + false</span>`,
|
||||
StringifyThresholds.ELEMENT_WITH_BINDING_COUNT
|
||||
)}</div>`
|
||||
)
|
||||
|
||||
@@ -26,17 +26,8 @@ function transformWithStyleTransform(
|
||||
}
|
||||
|
||||
describe('compiler: style transform', () => {
|
||||
test('should transform into directive node and hoist value', () => {
|
||||
const { root, node } = transformWithStyleTransform(
|
||||
`<div style="color: red"/>`
|
||||
)
|
||||
expect(root.hoists).toMatchObject([
|
||||
{
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: `{"color":"red"}`,
|
||||
isStatic: false
|
||||
}
|
||||
])
|
||||
test('should transform into directive node', () => {
|
||||
const { node } = transformWithStyleTransform(`<div style="color: red"/>`)
|
||||
expect(node.props[0]).toMatchObject({
|
||||
type: NodeTypes.DIRECTIVE,
|
||||
name: `bind`,
|
||||
@@ -47,7 +38,7 @@ describe('compiler: style transform', () => {
|
||||
},
|
||||
exp: {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: `_hoisted_1`,
|
||||
content: `{"color":"red"}`,
|
||||
isStatic: false
|
||||
}
|
||||
})
|
||||
@@ -71,7 +62,7 @@ describe('compiler: style transform', () => {
|
||||
},
|
||||
value: {
|
||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||
content: `_hoisted_1`,
|
||||
content: `{"color":"red"}`,
|
||||
isStatic: false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user