From 0944374e2b34f7b4753a1623f232f1ee9ce29a3e Mon Sep 17 00:00:00 2001 From: lidlanca <8693091+lidlanca@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:17:26 +0000 Subject: [PATCH 1/3] fix(compiler-sfc) fix setup result binding of primitive for non inlined mode. make it consistent with inlined behaviour --- .../__snapshots__/compileScript.spec.ts.snap | 48 +++++++++---------- .../__tests__/compileScript.spec.ts | 17 +++---- packages/compiler-sfc/src/compileScript.ts | 28 ++++++++++- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap index de223bf91d8..dd11de6ef07 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap @@ -13,7 +13,7 @@ export default /*#__PURE__*/Object.assign(__default__, { x() -return { n, x } +return { n, get x(){return x} } } })" @@ -30,7 +30,7 @@ export default /*#__PURE__*/Object.assign(__default__, { x() -return { n, x } +return { n, get x(){return x} } } })" @@ -51,7 +51,7 @@ export default /*#__PURE__*/_defineComponent({ x() -return { x } +return { get x(){return x} } } })" @@ -71,7 +71,7 @@ export default /*#__PURE__*/Object.assign(__default__, { x() -return { n, def, x } +return { n, def, get x(){return x} } } })" @@ -91,7 +91,7 @@ export default /*#__PURE__*/Object.assign(__default__, { x() -return { n, x } +return { n, get x(){return x} } } })" @@ -111,7 +111,7 @@ export default /*#__PURE__*/Object.assign(__default__, { x() -return { n, x } +return { n, get x(){return x} } } })" @@ -276,7 +276,7 @@ let a = _ref(1 + (( __restore(), __temp ))) -return { a } +return { get a(){return a}, set a(v){a=v} } } }" @@ -416,7 +416,7 @@ const props = __props -return { props, propsModel } +return { props, get propsModel(){return propsModel} } } }" @@ -433,7 +433,7 @@ export default { const props = __props -return { props, x } +return { props, get x(){return x} } } }" @@ -502,7 +502,7 @@ export default /*#__PURE__*/_defineComponent({ const cond = true -return { cond, bar, baz } +return { cond, get bar(){return bar}, get baz(){return baz} } } })" @@ -518,7 +518,7 @@ export default /*#__PURE__*/_defineComponent({ const fooBar: FooBar = 1 -return { fooBar, FooBaz, FooQux, foo } +return { fooBar, get FooBaz(){return FooBaz}, get FooQux(){return FooQux}, get foo(){return foo} } } })" @@ -533,7 +533,7 @@ export default /*#__PURE__*/_defineComponent({ expose(); -return { vMyDir } +return { get vMyDir(){return vMyDir} } } })" @@ -548,7 +548,7 @@ export default /*#__PURE__*/_defineComponent({ expose(); -return { VAR, VAR3 } +return { get VAR(){return VAR}, get VAR3(){return VAR3} } } })" @@ -563,7 +563,7 @@ export default /*#__PURE__*/_defineComponent({ expose(); -return { FooBaz, Last } +return { get FooBaz(){return FooBaz}, get Last(){return Last} } } })" @@ -578,7 +578,7 @@ export default /*#__PURE__*/_defineComponent({ expose(); -return { x, z, x$y } +return { get x(){return x}, get z(){return z}, get x$y(){return x$y} } } })" @@ -602,7 +602,7 @@ export default { -return { bar } +return { get bar(){return bar} } } }" @@ -641,7 +641,7 @@ export default { let foo = _ref(1) -return { foo, ref } +return { get foo(){return foo}, set foo(v){foo=v}, get ref(){return ref} } } }" @@ -656,7 +656,7 @@ export default { x() -return { x } +return { get x(){return x} } } }" @@ -675,7 +675,7 @@ export default { const r = ref(0) -return { r, ref } +return { r, get ref(){return ref} } } }" @@ -690,7 +690,7 @@ export default { expose(); -return { a, b } +return { get a(){return a}, get b(){return b} } } }" @@ -705,7 +705,7 @@ export default { expose(); -return { ref } +return { get ref(){return ref} } } }" @@ -1017,7 +1017,7 @@ export default { function c() {} class d {} -return { aa, bb, cc, dd, a, b, c, d, xx, x } +return { get aa(){return aa}, set aa(v){aa=v}, bb, cc, dd, get a(){return a}, set a(v){a=v}, b, c, d, get xx(){return xx}, get x(){return x} } } }" @@ -1361,7 +1361,7 @@ export default /*#__PURE__*/_defineComponent({ expose(); -return { Baz } +return { get Baz(){return Baz} } } })" @@ -1422,7 +1422,7 @@ const props = __props as { -return { props, defaults } +return { props, get defaults(){return defaults} } } })" diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index 17c97745e32..fe98c27e5af 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -20,7 +20,8 @@ describe('SFC compile `) - expect(content).toMatch('return { aa, bb, cc, dd, a, b, c, d, xx, x }') + expect(content).toMatch('return { get aa(){return aa}, set aa(v){aa=v}, bb, cc, dd, get a(){return a}, set a(v){a=v}, b, c, d, get xx(){return xx}, get x(){return x} }') + expect(bindings).toStrictEqual({ x: BindingTypes.SETUP_MAYBE_REF, a: BindingTypes.SETUP_LET, @@ -355,7 +356,7 @@ defineExpose({ foo: 123 }) // FooBaz: used as PascalCase component // FooQux: used as kebab-case component // foo: lowercase component - expect(content).toMatch(`return { fooBar, FooBaz, FooQux, foo }`) + expect(content).toMatch(`return { fooBar, get FooBaz(){return FooBaz}, get FooQux(){return FooQux}, get foo(){return foo} }`) assertCode(content) }) @@ -368,7 +369,7 @@ defineExpose({ foo: 123 })
`) - expect(content).toMatch(`return { vMyDir }`) + expect(content).toMatch(`return { get vMyDir(){return vMyDir} }`) assertCode(content) }) @@ -383,7 +384,7 @@ defineExpose({ foo: 123 }) `) - expect(content).toMatch(`return { cond, bar, baz }`) + expect(content).toMatch(`return { cond, get bar(){return bar}, get baz(){return baz} }`) assertCode(content) }) @@ -399,7 +400,7 @@ defineExpose({ foo: 123 }) // x: used in interpolation // y: should not be matched by {{ yy }} or 'y' in binding exps // x$y: #4274 should escape special chars when creating Regex - expect(content).toMatch(`return { x, z, x$y }`) + expect(content).toMatch(`return { get x(){return x}, get z(){return z}, get x$y(){return x$y} }`) assertCode(content) }) @@ -414,7 +415,7 @@ defineExpose({ foo: 123 }) `) // VAR2 should not be matched - expect(content).toMatch(`return { VAR, VAR3 }`) + expect(content).toMatch(`return { get VAR(){return VAR}, get VAR3(){return VAR3} }`) assertCode(content) }) @@ -429,7 +430,7 @@ defineExpose({ foo: 123 })