Skip to content

Commit

Permalink
fix(compiler-vapor): stringify number prop value
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Nov 15, 2024
1 parent 4078206 commit 0c7817c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports[`compile > dynamic root 1`] = `
"import { createTextNode as _createTextNode } from 'vue/vapor';
export function render(_ctx) {
const n0 = _createTextNode([1, 2])
const n0 = _createTextNode(() => [1, 2])
return n0
}"
`;
Expand Down Expand Up @@ -225,7 +225,7 @@ exports[`compile > static + dynamic root 1`] = `
"import { createTextNode as _createTextNode } from 'vue/vapor';
export function render(_ctx) {
const n0 = _createTextNode([1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B'])
const n0 = _createTextNode(() => [1, 2, "3", 4, 5, "6", 7, 8, "9", 'A', 'B'])
return n0
}"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ export function render(_ctx) {
}"
`;

exports[`compiler v-bind > number value 1`] = `
"import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor';
export function render(_ctx) {
const _component_Comp = _resolveComponent("Comp")
const n0 = _createComponent(_component_Comp, [
{ depth: () => (0) }
], null, true)
return n0
}"
`;

exports[`compiler v-bind > should error if empty expression 1`] = `
"import { setInheritAttrs as _setInheritAttrs, template as _template } from 'vue/vapor';
const t0 = _template("<div arg></div>")
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler-vapor/__tests__/transforms/vBind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,10 @@ describe('compiler v-bind', () => {
expect(code).contains('renderEffect')
expect(code).contains('_setAttr(n0, "foo-bar", _ctx.fooBar, true)')
})

test('number value', () => {
const { code } = compileWithVBind(`<Comp :depth="0" />`)
expect(code).matchSnapshot()
expect(code).contains('{ depth: () => (0) }')
})
})
6 changes: 1 addition & 5 deletions packages/compiler-vapor/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ export function getLiteralExpressionValue(
exp: SimpleExpressionNode,
): number | string | boolean | null {
if (exp.ast) {
if (
['StringLiteral', 'NumericLiteral', 'BigIntLiteral'].includes(
exp.ast.type,
)
) {
if (exp.ast.type === 'StringLiteral') {
return (exp.ast as StringLiteral | NumericLiteral | BigIntLiteral).value
} else if (
exp.ast.type === 'TemplateLiteral' &&
Expand Down

0 comments on commit 0c7817c

Please sign in to comment.