feat(compiler-sfc): <script setup> defineProps destructure transform (#4690)
This commit is contained in:
@@ -82,6 +82,11 @@ export const enum BindingTypes {
|
||||
* declared as a prop
|
||||
*/
|
||||
PROPS = 'props',
|
||||
/**
|
||||
* a local alias of a `<script setup>` destructured prop.
|
||||
* the original is stored in __propsAliases of the bindingMetadata object.
|
||||
*/
|
||||
PROPS_ALIASED = 'props-aliased',
|
||||
/**
|
||||
* a let binding (may or may not be a ref)
|
||||
*/
|
||||
@@ -110,6 +115,7 @@ export type BindingMetadata = {
|
||||
[key: string]: BindingTypes | undefined
|
||||
} & {
|
||||
__isScriptSetup?: boolean
|
||||
__propsAliases?: Record<string, string>
|
||||
}
|
||||
|
||||
interface SharedTransformCodegenOptions {
|
||||
|
||||
@@ -188,11 +188,16 @@ export function processExpression(
|
||||
// use __props which is generated by compileScript so in ts mode
|
||||
// it gets correct type
|
||||
return `__props.${raw}`
|
||||
} else if (type === BindingTypes.PROPS_ALIASED) {
|
||||
// prop with a different local alias (from defineProps() destructure)
|
||||
return `__props.${bindingMetadata.__propsAliases![raw]}`
|
||||
}
|
||||
} else {
|
||||
if (type && type.startsWith('setup')) {
|
||||
// setup bindings in non-inline mode
|
||||
return `$setup.${raw}`
|
||||
} else if (type === BindingTypes.PROPS_ALIASED) {
|
||||
return `$props.${bindingMetadata.__propsAliases![raw]}`
|
||||
} else if (type) {
|
||||
return `$${type}.${raw}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user