Skip to content

Commit 835fc82

Browse files
committed
chore: Synchronize the main branch code
1 parent d0cf234 commit 835fc82

File tree

8 files changed

+69
-7
lines changed

8 files changed

+69
-7
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'
@@ -875,6 +876,10 @@ export function getVNodeBlockHelper(
875876
return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK
876877
}
877878

879+
export function getSetupReturnedHelper() {
880+
return RESOLVE_SETUP_RETURNED
881+
}
882+
878883
export function convertToBlock(
879884
node: VNodeCall,
880885
{ 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,
@@ -336,6 +337,8 @@ export function generate(
336337
if (!__BROWSER__ && options.bindingMetadata && !options.inline) {
337338
// binding optimization args
338339
args.push('$props', '$setup', '$data', '$options')
340+
// Add helper 'getSetupReturnedHelper' for $setup
341+
context.helper(getSetupReturnedHelper())
339342
}
340343
const signature =
341344
!__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: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {
22
type ComponentInternalInstance,
3+
type ComponentInternalOptions,
34
type ComponentOptions,
45
type ConcreteComponent,
56
currentInstance,
67
getComponentName,
78
} from '../component'
89
import { currentRenderingInstance } from '../componentRenderContext'
910
import type { Directive } from '../directives'
10-
import { camelize, capitalize, isString } from '@vue/shared'
11+
import { camelize, capitalize, isLateTag, isString } from '@vue/shared'
1112
import { warn } from '../warning'
1213
import type { VNodeTypes } from '../vnode'
1314

@@ -118,12 +119,21 @@ function resolveAsset(
118119
return Component
119120
}
120121

121-
if (__DEV__ && warnMissing && !res) {
122-
const extra =
123-
type === COMPONENTS
124-
? `\nIf this is a native custom element, make sure to exclude it from ` +
122+
if (
123+
__DEV__ &&
124+
warnMissing &&
125+
((!res && !isLateTag(name)) || (res && isLateTag(name)))
126+
) {
127+
let extra = ''
128+
if (type === COMPONENTS) {
129+
if (isLateTag(name)) {
130+
extra = `\nplease do not use built-in tag names as component names.`
131+
} else {
132+
extra =
133+
`\nIf this is a native custom element, make sure to exclude it from ` +
125134
`component resolution via compilerOptions.isCustomElement.`
126-
: ``
135+
}
136+
}
127137
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}${extra}`)
128138
}
129139

@@ -144,3 +154,23 @@ function resolve(registry: Record<string, any> | undefined, name: string) {
144154
registry[capitalize(camelize(name))])
145155
)
146156
}
157+
158+
/**
159+
* @private
160+
*/
161+
export function resolveSetupReturned(
162+
name: string,
163+
setupReturn: ComponentInternalInstance['setupState'],
164+
): unknown {
165+
if (!setupReturn) return name
166+
const returnValue = setupReturn[name]
167+
if (
168+
returnValue &&
169+
(returnValue as ComponentInternalOptions).__file &&
170+
isLateTag(name as string)
171+
) {
172+
const extra = `\nplease do not use built-in tag names as component names.`
173+
warn(`Failed to resolve component: ${name},${extra}`)
174+
}
175+
return returnValue
176+
}

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)