Skip to content

Commit 3ea6869

Browse files
committed
wip: inline-template compat
1 parent 1390ece commit 3ea6869

File tree

4 files changed

+70
-25
lines changed

4 files changed

+70
-25
lines changed

packages/compiler-core/src/compat/compatConfig.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const enum CompilerDeprecationTypes {
2020
COMPILER_V_BIND_OBJECT_ORDER = 'COMPILER_V_BIND_OBJECT_ORDER',
2121
COMPILER_V_ON_NATIVE = 'COMPILER_V_ON_NATIVE',
2222
COMPILER_V_IF_V_FOR_PRECEDENCE = 'COMPILER_V_IF_V_FOR_PRECEDENCE',
23-
COMPILER_NATIVE_TEMPLATE = 'COMPILER_NATIVE_TEMPLATE'
23+
COMPILER_NATIVE_TEMPLATE = 'COMPILER_NATIVE_TEMPLATE',
24+
COMPILER_INLINE_TEMPLATE = 'COMPILER_INLINE_TEMPLATE',
25+
COMPILER_FILTER = 'COMPILER_FILTER'
2426
}
2527

2628
type DeprecationData = {
@@ -80,6 +82,16 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
8082
message:
8183
`<template> with no special directives will render as a native template ` +
8284
`element instead of its inner content in Vue 3.`
85+
},
86+
87+
[CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE]: {
88+
message: `"inline-template" has been removed in Vue 3.`,
89+
link: `https://v3.vuejs.org/guide/migration/inline-template-attribute.html`
90+
},
91+
92+
[CompilerDeprecationTypes.COMPILER_FILTER]: {
93+
message: `filters have been removed in Vue 3.`,
94+
link: `https://v3.vuejs.org/guide/migration/filters.html`
8395
}
8496
}
8597

packages/compiler-core/src/parse.ts

+22-1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,27 @@ function parseElement(
406406
const children = parseChildren(context, mode, ancestors)
407407
ancestors.pop()
408408

409+
// 2.x inline-template compat
410+
if (__COMPAT__) {
411+
const inlineTemplateProp = element.props.find(
412+
p => p.type === NodeTypes.ATTRIBUTE && p.name === 'inline-template'
413+
) as AttributeNode
414+
if (
415+
inlineTemplateProp &&
416+
checkCompatEnabled(
417+
CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE,
418+
context,
419+
inlineTemplateProp.loc
420+
)
421+
) {
422+
inlineTemplateProp.value!.content = getSelection(
423+
context,
424+
element.loc.end
425+
).source
426+
console.log(inlineTemplateProp)
427+
}
428+
}
429+
409430
element.children = children
410431

411432
// End tag.
@@ -516,7 +537,7 @@ function parseTag(
516537
return
517538
}
518539

519-
// warn v-if/v-for usage on the same element
540+
// 2.x deprecation checks
520541
if (__COMPAT__ && __DEV__ && !__TEST__) {
521542
let hasIf = false
522543
let hasFor = false

packages/runtime-core/src/component.ts

+24-17
Original file line numberDiff line numberDiff line change
@@ -712,24 +712,31 @@ export function finishComponentSetup(
712712
NOOP) as InternalRenderFunction
713713
} else if (!instance.render) {
714714
// could be set from setup()
715-
if (compile && Component.template && !Component.render) {
716-
if (__DEV__) {
717-
startMeasure(instance, `compile`)
718-
}
719-
const compilerOptions: CompilerOptions = {
720-
isCustomElement: instance.appContext.config.isCustomElement,
721-
delimiters: Component.delimiters
722-
}
723-
if (__COMPAT__) {
724-
// pass runtime compat config into the compiler
725-
compilerOptions.compatConfig = Object.create(globalCompatConfig)
726-
if (Component.compatConfig) {
727-
extend(compilerOptions.compatConfig, Component.compatConfig)
715+
if (compile && !Component.render) {
716+
const template =
717+
(__COMPAT__ &&
718+
instance.vnode.props &&
719+
instance.vnode.props['inline-template']) ||
720+
Component.template
721+
if (template) {
722+
if (__DEV__) {
723+
startMeasure(instance, `compile`)
724+
}
725+
const compilerOptions: CompilerOptions = {
726+
isCustomElement: instance.appContext.config.isCustomElement,
727+
delimiters: Component.delimiters
728+
}
729+
if (__COMPAT__) {
730+
// pass runtime compat config into the compiler
731+
compilerOptions.compatConfig = Object.create(globalCompatConfig)
732+
if (Component.compatConfig) {
733+
extend(compilerOptions.compatConfig, Component.compatConfig)
734+
}
735+
}
736+
Component.render = compile(template, compilerOptions)
737+
if (__DEV__) {
738+
endMeasure(instance, `compile`)
728739
}
729-
}
730-
Component.render = compile(Component.template, compilerOptions)
731-
if (__DEV__) {
732-
endMeasure(instance, `compile`)
733740
}
734741
}
735742

packages/runtime-core/src/componentProps.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,17 @@ function setFullProps(
297297
continue
298298
}
299299

300-
if (__COMPAT__ && key.startsWith('onHook:')) {
301-
softAssertCompatEnabled(
302-
DeprecationTypes.INSTANCE_EVENT_HOOKS,
303-
instance,
304-
key.slice(2).toLowerCase()
305-
)
300+
if (__COMPAT__) {
301+
if (key.startsWith('onHook:')) {
302+
softAssertCompatEnabled(
303+
DeprecationTypes.INSTANCE_EVENT_HOOKS,
304+
instance,
305+
key.slice(2).toLowerCase()
306+
)
307+
}
308+
if (key === 'inline-template') {
309+
continue
310+
}
306311
}
307312

308313
const value = rawProps[key]

0 commit comments

Comments
 (0)