Skip to content

fix(compiler-sfc): Compilation of expose removes inlineTemplate restriction #9159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ import { ref } from 'vue'
import * as tree from './tree'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)
const constant = {}
Expand Down Expand Up @@ -831,7 +832,8 @@ import ChildComp from './Child.vue'
import vMyDir from './my-dir'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


return (_ctx, _cache) => {
Expand All @@ -854,7 +856,8 @@ exports[`SFC compile <script setup> > inlineTemplate mode > should work 1`] = `
import { ref } from 'vue'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)

Expand All @@ -876,7 +879,8 @@ import { ref } from 'vue'

export default {
__ssrInlineRender: true,
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)
const style = { color: 'red' }
Expand Down Expand Up @@ -905,7 +909,8 @@ exports[`SFC compile <script setup> > inlineTemplate mode > template assignment
import { ref } from 'vue'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)
const maybe = foo()
Expand Down Expand Up @@ -962,7 +967,8 @@ exports[`SFC compile <script setup> > inlineTemplate mode > template destructure
import { ref } from 'vue'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const val = {}
const count = ref(0)
Expand Down Expand Up @@ -993,7 +999,8 @@ exports[`SFC compile <script setup> > inlineTemplate mode > template update expr
import { ref } from 'vue'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)
const maybe = foo()
Expand Down Expand Up @@ -1052,7 +1059,8 @@ exports[`SFC compile <script setup> > inlineTemplate mode > v-model codegen 1`]
import { ref } from 'vue'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const count = ref(0)
const maybe = foo()
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,7 @@ describe('SFC compile <script setup>', () => {
// check snapshot and make sure helper imports and
// hoists are placed correctly.
assertCode(content)
// in inline mode, no need to call expose() since nothing is exposed
// anyway!
expect(content).not.toMatch(`expose()`)
expect(content).toMatch(`expose()`)
})

test('with defineExpose()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ exports[`sfc reactive props destructure > aliasing 1`] = `

export default {
props: ['foo'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


let x = foo
Expand All @@ -26,7 +27,8 @@ exports[`sfc reactive props destructure > basic usage 1`] = `

export default {
props: ['foo'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


console.log(__props.foo)
Expand All @@ -45,7 +47,8 @@ exports[`sfc reactive props destructure > computed static key 1`] = `

export default {
props: ['foo'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


console.log(__props.foo)
Expand All @@ -67,7 +70,8 @@ export default {
bar: () => ({}),
func: () => {}, __skip_func: true
}),
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();



Expand All @@ -87,7 +91,8 @@ export default {
func: () => {}, __skip_func: true,
ext: x, __skip_ext: true
}),
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();



Expand All @@ -105,7 +110,8 @@ export default {
foo: 1,
"foo:bar": 'foo-bar'
}),
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();



Expand All @@ -125,7 +131,8 @@ export default /*#__PURE__*/_defineComponent({
"foo:bar": { type: String, required: true, default: 'foo-bar' },
"onUpdate:modelValue": { type: Function, required: true }
},
setup(__props: any) {
setup(__props: any, { expose: __expose }) {
__expose();



Expand All @@ -144,7 +151,8 @@ export default /*#__PURE__*/_defineComponent({
bar: { type: Object, required: false, default: () => ({}) },
func: { type: Function, required: false, default: () => {} }
},
setup(__props: any) {
setup(__props: any, { expose: __expose }) {
__expose();



Expand All @@ -166,7 +174,8 @@ export default /*#__PURE__*/_defineComponent({
boolb: { type: [Boolean, Number] },
func: { type: Function, default: () => {} }
},
setup(__props: any) {
setup(__props: any, { expose: __expose }) {
__expose();



Expand All @@ -181,7 +190,8 @@ exports[`sfc reactive props destructure > defineProps/defineEmits in multi-varia
export default {
props: ['item'],
emits: ['a'],
setup(__props, { emit: __emit }) {
setup(__props, { expose: __expose, emit: __emit }) {
__expose();

const props = __props,
emit = __emit;
Expand All @@ -196,7 +206,8 @@ exports[`sfc reactive props destructure > multi-variable declaration 1`] = `
"
export default {
props: ['item'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const a = 1;

Expand All @@ -210,7 +221,8 @@ exports[`sfc reactive props destructure > multi-variable declaration fix #6757
"
export default {
props: ['item'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const a = 1;

Expand All @@ -224,7 +236,8 @@ exports[`sfc reactive props destructure > multi-variable declaration fix #7422 1
"
export default {
props: ['item'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const a = 0,
b = 0;
Expand All @@ -241,7 +254,8 @@ exports[`sfc reactive props destructure > multiple variable declarations 1`] = `

export default {
props: ['foo'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const bar = 'fish', hello = 'world'

Expand All @@ -257,7 +271,8 @@ exports[`sfc reactive props destructure > nested scope 1`] = `
"
export default {
props: ['foo', 'bar'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


function test(foo) {
Expand All @@ -277,7 +292,8 @@ exports[`sfc reactive props destructure > non-identifier prop names 1`] = `

export default {
props: { 'foo.bar': Function },
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


let x = __props["foo.bar"]
Expand All @@ -295,7 +311,8 @@ exports[`sfc reactive props destructure > rest spread 1`] = `

export default {
props: ['foo', 'bar', 'baz'],
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const rest = _createPropsRestProxy(__props, ["foo","bar"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ exports[`sfc hoist static > should enable when only script setup 1`] = `
const foo = 'bar'

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const foo = 'bar'

Expand All @@ -22,7 +23,8 @@ exports[`sfc hoist static > should hoist expressions 1`] = `
const sequence = (1, true, 'foo', 1)

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


return () => {}
Expand All @@ -40,7 +42,8 @@ exports[`sfc hoist static > should hoist literal value 1`] = `
const template = \`str\`

export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();


return () => {}
Expand All @@ -58,7 +61,8 @@ export default {
default: defaultValue
}
},
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();



Expand All @@ -72,7 +76,8 @@ exports[`sfc hoist static > should not hoist a constant initialized to a referen
"import { defineComponent as _defineComponent } from 'vue'

export default /*#__PURE__*/_defineComponent({
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const KEY1 = Boolean
const KEY2 = [Boolean]
Expand All @@ -94,7 +99,8 @@ return () => {}
exports[`sfc hoist static > should not hoist a function or class 1`] = `
"
export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const fn = () => {}
function fn2() {}
Expand All @@ -109,7 +115,8 @@ return () => {}
exports[`sfc hoist static > should not hoist a object or array 1`] = `
"
export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const obj = { foo: 'bar' }
const arr = [1, 2, 3]
Expand All @@ -123,7 +130,8 @@ return () => {}
exports[`sfc hoist static > should not hoist a variable 1`] = `
"
export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

let KEY1 = 'default value'
var KEY2 = 123
Expand All @@ -139,7 +147,8 @@ return () => {}
exports[`sfc hoist static > should not hoist when disabled 1`] = `
"
export default {
setup(__props) {
setup(__props, { expose: __expose }) {
__expose();

const foo = 'bar'

Expand Down
20 changes: 16 additions & 4 deletions packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ describe('sfc hoist static', () => {
regex: BindingTypes.SETUP_CONST,
undef: BindingTypes.SETUP_MAYBE_REF,
})
expect(content).toMatch(`setup(__props) {\n\n ${code}`)
expect(content).toMatch(`setup(__props, { expose: __expose }) {
__expose();

${code}`)
assertCode(content)
})

Expand Down Expand Up @@ -133,7 +136,10 @@ describe('sfc hoist static', () => {
KEY6: BindingTypes.SETUP_CONST,
i: BindingTypes.SETUP_LET,
})
expect(content).toMatch(`setup(__props) {\n\n ${code}`)
expect(content).toMatch(`setup(__props, { expose: __expose }) {
__expose();

${code}`)
assertCode(content)
})

Expand All @@ -151,7 +157,10 @@ describe('sfc hoist static', () => {
arr: BindingTypes.SETUP_CONST,
obj: BindingTypes.SETUP_CONST,
})
expect(content).toMatch(`setup(__props) {\n\n ${code}`)
expect(content).toMatch(`setup(__props, { expose: __expose }) {
__expose();

${code}`)
assertCode(content)
})

Expand All @@ -171,7 +180,10 @@ describe('sfc hoist static', () => {
fn: BindingTypes.SETUP_CONST,
fn2: BindingTypes.SETUP_CONST,
})
expect(content).toMatch(`setup(__props) {\n\n ${code}`)
expect(content).toMatch(`setup(__props, { expose: __expose }) {
__expose();

${code}`)
assertCode(content)
})

Expand Down
Loading
Loading