Skip to content

Commit 6d1f90e

Browse files
committed
chore: Synchronize the main branch code
1 parent eca0e1c commit 6d1f90e

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed

packages/compiler-core/__tests__/transforms/transformElement.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ describe('compiler: element transform', () => {
9999
expect(node.tag).toBe(`$setup["Example"]`)
100100
})
101101

102+
test('resolve component from setup bindings & component', () => {
103+
const { root, node } = parseWithElementTransform(`<Example/>`, {
104+
bindingMetadata: {
105+
Example: BindingTypes.SETUP_CONST,
106+
},
107+
})
108+
expect(root.helpers).not.toContain(RESOLVE_COMPONENT)
109+
expect(node.tag).toBe(`_resolveSetupReturned("Example", $setup)`)
110+
})
111+
102112
test('resolve component from setup bindings (inline)', () => {
103113
const { root, node } = parseWithElementTransform(`<Example/>`, {
104114
inline: true,

packages/compiler-core/src/ast.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
OPEN_BLOCK,
1010
type RENDER_LIST,
1111
type RENDER_SLOT,
12+
RESOLVE_SETUP_RETURNED,
1213
WITH_DIRECTIVES,
1314
type WITH_MEMO,
1415
} from './runtimeHelpers'
@@ -868,6 +869,10 @@ export function getVNodeBlockHelper(
868869
return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK
869870
}
870871

872+
export function getSetupReturnedHelper() {
873+
return RESOLVE_SETUP_RETURNED
874+
}
875+
871876
export function convertToBlock(
872877
node: VNodeCall,
873878
{ helper, removeHelper, inSSR }: TransformContext,

packages/compiler-core/src/codegen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type TemplateLiteral,
2525
type TextNode,
2626
type VNodeCall,
27+
getSetupReturnedHelper,
2728
getVNodeBlockHelper,
2829
getVNodeHelper,
2930
locStub,
@@ -320,6 +321,8 @@ export function generate(
320321
if (!__BROWSER__ && options.bindingMetadata && !options.inline) {
321322
// binding optimization args
322323
args.push('$props', '$setup', '$data', '$options')
324+
// Add helper 'getSetupReturnedHelper' for $setup
325+
context.helper(getSetupReturnedHelper())
323326
}
324327
const signature =
325328
!__BROWSER__ && options.isTS

packages/compiler-core/src/runtimeHelpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export const CREATE_STATIC: unique symbol = Symbol(
2626
export const RESOLVE_COMPONENT: unique symbol = Symbol(
2727
__DEV__ ? `resolveComponent` : ``,
2828
)
29+
export const RESOLVE_SETUP_RETURNED: unique symbol = Symbol(
30+
__DEV__ ? `resolveSetupReturned` : ``,
31+
)
2932
export const RESOLVE_DYNAMIC_COMPONENT: unique symbol = Symbol(
3033
__DEV__ ? `resolveDynamicComponent` : ``,
3134
)
@@ -98,6 +101,7 @@ export const helperNameMap: Record<symbol, string> = {
98101
[CREATE_TEXT]: `createTextVNode`,
99102
[CREATE_STATIC]: `createStaticVNode`,
100103
[RESOLVE_COMPONENT]: `resolveComponent`,
104+
[RESOLVE_SETUP_RETURNED]: `resolveSetupReturned`,
101105
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
102106
[RESOLVE_DIRECTIVE]: `resolveDirective`,
103107
[RESOLVE_FILTER]: `resolveFilter`,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
createObjectProperty,
2222
createSimpleExpression,
2323
createVNodeCall,
24+
getSetupReturnedHelper,
2425
} from '../ast'
2526
import {
2627
PatchFlags,
@@ -344,10 +345,13 @@ function resolveSetupReference(name: string, context: TransformContext) {
344345
checkType(BindingTypes.SETUP_REACTIVE_CONST) ||
345346
checkType(BindingTypes.LITERAL_CONST)
346347
if (fromConst) {
348+
const helper = context.helperString
347349
return context.inline
348350
? // in inline mode, const setup bindings (e.g. imports) can be used as-is
349351
fromConst
350-
: `$setup[${JSON.stringify(fromConst)}]`
352+
: `${helper(getSetupReturnedHelper())}(${JSON.stringify(
353+
fromConst,
354+
)}, $setup)`
351355
}
352356

353357
const fromMaybeRef =

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
2+
type ComponentInternalInstance,
3+
type ComponentInternalOptions,
24
type ComponentOptions,
35
type ConcreteComponent,
46
currentInstance,
57
getComponentName,
68
} from '../component'
79
import { currentRenderingInstance } from '../componentRenderContext'
810
import type { Directive } from '../directives'
9-
import { camelize, capitalize, isString } from '@vue/shared'
11+
import { camelize, capitalize, isLateTag, isString } from '@vue/shared'
1012
import { warn } from '../warning'
1113
import type { VNodeTypes } from '../vnode'
1214

@@ -106,18 +108,26 @@ function resolveAsset(
106108
resolve(instance[type] || (Component as ComponentOptions)[type], name) ||
107109
// global registration
108110
resolve(instance.appContext[type], name)
109-
110111
if (!res && maybeSelfReference) {
111112
// fallback to implicit self-reference
112113
return Component
113114
}
114115

115-
if (__DEV__ && warnMissing && !res) {
116-
const extra =
117-
type === COMPONENTS
118-
? `\nIf this is a native custom element, make sure to exclude it from ` +
116+
if (
117+
__DEV__ &&
118+
warnMissing &&
119+
((!res && !isLateTag(name)) || (res && isLateTag(name)))
120+
) {
121+
let extra = ''
122+
if (type === COMPONENTS) {
123+
if (isLateTag(name)) {
124+
extra = `\nplease do not use built-in tag names as component names.`
125+
} else {
126+
extra =
127+
`\nIf this is a native custom element, make sure to exclude it from ` +
119128
`component resolution via compilerOptions.isCustomElement.`
120-
: ``
129+
}
130+
}
121131
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`)
122132
}
123133

@@ -138,3 +148,23 @@ function resolve(registry: Record<string, any> | undefined, name: string) {
138148
registry[capitalize(camelize(name))])
139149
)
140150
}
151+
152+
/**
153+
* @private
154+
*/
155+
export function resolveSetupReturned(
156+
name: string,
157+
setupReturn: ComponentInternalInstance['setupState'],
158+
): unknown {
159+
if (!setupReturn) return name
160+
const returnValue = setupReturn[name]
161+
if (
162+
returnValue &&
163+
(returnValue as ComponentInternalOptions).__file &&
164+
isLateTag(name as string)
165+
) {
166+
const extra = `\nplease do not use built-in tag names as component names.`
167+
warn(`Failed to resolve component: ${name},${extra}`)
168+
}
169+
return returnValue
170+
}

packages/runtime-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export {
144144
resolveComponent,
145145
resolveDirective,
146146
resolveDynamicComponent,
147+
resolveSetupReturned,
147148
} from './helpers/resolveAssets'
148149
// For integration with runtime compiler
149150
export { registerRuntimeCompiler, isRuntimeOnly } from './component'

packages/shared/src/domTagConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const HTML_TAGS =
1414
'option,output,progress,select,textarea,details,dialog,menu,' +
1515
'summary,template,blockquote,iframe,tfoot'
1616

17+
const LATE_ADDED_TAGS = 'search'
18+
1719
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element
1820
const SVG_TAGS =
1921
'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
@@ -62,3 +64,6 @@ export const isMathMLTag: (key: string) => boolean =
6264
*/
6365
export const isVoidTag: (key: string) => boolean =
6466
/*@__PURE__*/ makeMap(VOID_TAGS)
67+
68+
export const isLateTag: (key: string) => boolean =
69+
/*#__PURE__*/ makeMap(LATE_ADDED_TAGS)

0 commit comments

Comments
 (0)