Преглед изворни кода

fix(compiler-vapor): stringify number prop value

三咲智子 Kevin Deng пре 1 година
родитељ
комит
0c7817ceed

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

@@ -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
 }"
 `;
@@ -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
 }"
 `;

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

@@ -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>")

+ 6 - 0
packages/compiler-vapor/__tests__/transforms/vBind.spec.ts

@@ -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) }')
+  })
 })

+ 1 - 5
packages/compiler-vapor/src/utils.ts

@@ -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' &&