Skip to content

Commit 0c7817c

Browse files
committed
fix(compiler-vapor): stringify number prop value
1 parent 4078206 commit 0c7817c

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ exports[`compile > dynamic root 1`] = `
171171
"import { createTextNode as _createTextNode } from 'vue/vapor';
172172
173173
export function render(_ctx) {
174-
const n0 = _createTextNode([1, 2])
174+
const n0 = _createTextNode(() => [1, 2])
175175
return n0
176176
}"
177177
`;
@@ -225,7 +225,7 @@ exports[`compile > static + dynamic root 1`] = `
225225
"import { createTextNode as _createTextNode } from 'vue/vapor';
226226
227227
export function render(_ctx) {
228-
const n0 = _createTextNode([1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B'])
228+
const n0 = _createTextNode(() => [1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B'])
229229
return n0
230230
}"
231231
`;

packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap

+12
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ export function render(_ctx) {
181181
}"
182182
`;
183183

184+
exports[`compiler v-bind > number value 1`] = `
185+
"import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor';
186+
187+
export function render(_ctx) {
188+
const _component_Comp = _resolveComponent("Comp")
189+
const n0 = _createComponent(_component_Comp, [
190+
{ depth: () => (0) }
191+
], null, true)
192+
return n0
193+
}"
194+
`;
195+
184196
exports[`compiler v-bind > should error if empty expression 1`] = `
185197
"import { setInheritAttrs as _setInheritAttrs, template as _template } from 'vue/vapor';
186198
const t0 = _template("<div arg></div>")

packages/compiler-vapor/__tests__/transforms/vBind.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,10 @@ describe('compiler v-bind', () => {
526526
expect(code).contains('renderEffect')
527527
expect(code).contains('_setAttr(n0, "foo-bar", _ctx.fooBar, true)')
528528
})
529+
530+
test('number value', () => {
531+
const { code } = compileWithVBind(`<Comp :depth="0" />`)
532+
expect(code).matchSnapshot()
533+
expect(code).contains('{ depth: () => (0) }')
534+
})
529535
})

packages/compiler-vapor/src/utils.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ export function getLiteralExpressionValue(
6161
exp: SimpleExpressionNode,
6262
): number | string | boolean | null {
6363
if (exp.ast) {
64-
if (
65-
['StringLiteral', 'NumericLiteral', 'BigIntLiteral'].includes(
66-
exp.ast.type,
67-
)
68-
) {
64+
if (exp.ast.type === 'StringLiteral') {
6965
return (exp.ast as StringLiteral | NumericLiteral | BigIntLiteral).value
7066
} else if (
7167
exp.ast.type === 'TemplateLiteral' &&

0 commit comments

Comments
 (0)