ソースを参照

fix(compiler-sfc): fix defineExpose() codegen regression from #7949

Evan You 3 年 前
コミット
a94072dd2c

+ 2 - 2
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

@@ -645,7 +645,7 @@ exports[`SFC compile <script setup> > defineExpose() 1`] = `
 "export default {
   setup(__props, { expose: __expose }) {
 
-expose({ foo: 123 })
+__expose({ foo: 123 })
 
 return {  }
 }
@@ -1319,7 +1319,7 @@ exports[`SFC compile <script setup> > inlineTemplate mode > with defineExpose()
   setup(__props, { expose: __expose }) {
 
         const count = ref(0)
-        expose({ count })
+        __expose({ count })
         
 return () => {}
 }

+ 1 - 1
packages/compiler-sfc/__tests__/compileScript.spec.ts

@@ -276,7 +276,7 @@ defineExpose({ foo: 123 })
     // should generate correct setup signature
     expect(content).toMatch(`setup(__props, { expose: __expose }) {`)
     // should replace callee
-    expect(content).toMatch(/\bexpose\(\{ foo: 123 \}\)/)
+    expect(content).toMatch(/\b__expose\(\{ foo: 123 \}\)/)
   })
 
   test('<script> after <script setup> the script content not end with `\\n`', () => {

+ 1 - 1
packages/compiler-sfc/src/compileScript.ts

@@ -1252,7 +1252,7 @@ export function compileScript(
         s.overwrite(
           callee.start! + startOffset,
           callee.end! + startOffset,
-          'expose'
+          '__expose'
         )
       }
     }