Skip to content

Commit f0dcf9e

Browse files
committed
chore: updated code
1 parent 3013572 commit f0dcf9e

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

packages/compiler-core/src/ast.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
CREATE_VNODE,
1212
CREATE_ELEMENT_VNODE,
1313
CREATE_BLOCK,
14-
CREATE_ELEMENT_BLOCK
14+
CREATE_ELEMENT_BLOCK,
15+
RESOLVE_SETUP_RETURNED
1516
} from './runtimeHelpers'
1617
import { PropsExpression } from './transforms/transformElement'
1718
import { ImportItem, TransformContext } from './transform'
@@ -822,6 +823,10 @@ export function getVNodeBlockHelper(ssr: boolean, isComponent: boolean) {
822823
return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK
823824
}
824825

826+
export function getSetupReturnedHelper() {
827+
return RESOLVE_SETUP_RETURNED
828+
}
829+
825830
export function convertToBlock(
826831
node: VNodeCall,
827832
{ helper, removeHelper, inSSR }: TransformContext

packages/compiler-core/src/codegen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
VNodeCall,
2727
SequenceExpression,
2828
getVNodeBlockHelper,
29-
getVNodeHelper
29+
getVNodeHelper,
30+
getSetupReturnedHelper
3031
} from './ast'
3132
import { SourceMapGenerator, RawSourceMap } from 'source-map-js'
3233
import {
@@ -231,6 +232,8 @@ export function generate(
231232
if (!__BROWSER__ && options.bindingMetadata && !options.inline) {
232233
// binding optimization args
233234
args.push('$props', '$setup', '$data', '$options')
235+
// Add helper 'getSetupReturnedHelper' for $setup
236+
context.helper(getSetupReturnedHelper())
234237
}
235238
const signature =
236239
!__BROWSER__ && options.isTS

packages/compiler-core/src/runtimeHelpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const CREATE_COMMENT = Symbol(__DEV__ ? `createCommentVNode` : ``)
1212
export const CREATE_TEXT = Symbol(__DEV__ ? `createTextVNode` : ``)
1313
export const CREATE_STATIC = Symbol(__DEV__ ? `createStaticVNode` : ``)
1414
export const RESOLVE_COMPONENT = Symbol(__DEV__ ? `resolveComponent` : ``)
15+
export const RESOLVE_SETUP_RETURNED = Symbol(__DEV__ ? `resolveSetupReturned` : ``)
1516
export const RESOLVE_DYNAMIC_COMPONENT = Symbol(
1617
__DEV__ ? `resolveDynamicComponent` : ``
1718
)
@@ -57,6 +58,7 @@ export const helperNameMap: Record<symbol, string> = {
5758
[CREATE_TEXT]: `createTextVNode`,
5859
[CREATE_STATIC]: `createStaticVNode`,
5960
[RESOLVE_COMPONENT]: `resolveComponent`,
61+
[RESOLVE_SETUP_RETURNED]:`resolveSetupReturned`,
6062
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
6163
[RESOLVE_DIRECTIVE]: `resolveDirective`,
6264
[RESOLVE_FILTER]: `resolveFilter`,

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
TemplateTextChildNode,
2020
DirectiveArguments,
2121
createVNodeCall,
22-
ConstantTypes
22+
ConstantTypes,
23+
getSetupReturnedHelper
2324
} from '../ast'
2425
import {
2526
PatchFlags,
@@ -369,10 +370,11 @@ function resolveSetupReference(name: string, context: TransformContext) {
369370
checkType(BindingTypes.SETUP_REACTIVE_CONST) ||
370371
checkType(BindingTypes.LITERAL_CONST)
371372
if (fromConst) {
373+
const helper = context.helperString
372374
return context.inline
373375
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
374376
fromConst
375-
: `$setup[${JSON.stringify(fromConst)}]`
377+
: `${helper(getSetupReturnedHelper())}(${JSON.stringify(fromConst)}, $setup)`
376378
}
377379

378380
const fromMaybeRef =

packages/runtime-core/src/helpers/resolveAssets.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,18 @@ function resolve(registry: Record<string, any> | undefined, name: string) {
141141
registry[capitalize(camelize(name))])
142142
)
143143
}
144+
145+
/**
146+
* @private
147+
*/
148+
export function resolveSetupReturned(name:string, setupReturn: any) {
149+
if(!setupReturn) return name
150+
const returnValue = setupReturn[name]
151+
if(returnValue && returnValue.__file && isLateTag(name as string)){
152+
const extra =
153+
`\nIf this is a native custom element, make sure to exclude it from ` +
154+
`component resolution via compilerOptions.isCustomElement.`
155+
warn(`Failed to resolve component: ${name}${extra}`)
156+
}
157+
return returnValue
158+
}

packages/runtime-core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ export {
128128
export {
129129
resolveComponent,
130130
resolveDirective,
131-
resolveDynamicComponent
131+
resolveDynamicComponent,
132+
resolveSetupReturned
132133
} from './helpers/resolveAssets'
133134
// For integration with runtime compiler
134135
export { registerRuntimeCompiler, isRuntimeOnly } from './component'

0 commit comments

Comments
 (0)