]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: inline-template compat
authorEvan You <yyx990803@gmail.com>
Sun, 18 Apr 2021 03:19:40 +0000 (23:19 -0400)
committerEvan You <yyx990803@gmail.com>
Sun, 18 Apr 2021 03:19:40 +0000 (23:19 -0400)
packages/compiler-core/src/compat/compatConfig.ts
packages/compiler-core/src/parse.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentProps.ts

index 208f3d5318bf54a4086426f41f891844d937ad2e..e73c8a1b499a3f947bc63a2ca7c9d7e539397daf 100644 (file)
@@ -20,7 +20,9 @@ export const enum CompilerDeprecationTypes {
   COMPILER_V_BIND_OBJECT_ORDER = 'COMPILER_V_BIND_OBJECT_ORDER',
   COMPILER_V_ON_NATIVE = 'COMPILER_V_ON_NATIVE',
   COMPILER_V_IF_V_FOR_PRECEDENCE = 'COMPILER_V_IF_V_FOR_PRECEDENCE',
-  COMPILER_NATIVE_TEMPLATE = 'COMPILER_NATIVE_TEMPLATE'
+  COMPILER_NATIVE_TEMPLATE = 'COMPILER_NATIVE_TEMPLATE',
+  COMPILER_INLINE_TEMPLATE = 'COMPILER_INLINE_TEMPLATE',
+  COMPILER_FILTER = 'COMPILER_FILTER'
 }
 
 type DeprecationData = {
@@ -80,6 +82,16 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
     message:
       `<template> with no special directives will render as a native template ` +
       `element instead of its inner content in Vue 3.`
+  },
+
+  [CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE]: {
+    message: `"inline-template" has been removed in Vue 3.`,
+    link: `https://v3.vuejs.org/guide/migration/inline-template-attribute.html`
+  },
+
+  [CompilerDeprecationTypes.COMPILER_FILTER]: {
+    message: `filters have been removed in Vue 3.`,
+    link: `https://v3.vuejs.org/guide/migration/filters.html`
   }
 }
 
index feee2a812394cf3407c70c24b252e4064376bb85..6335df7a366a8704c7d217f3388a2c03597ea4b5 100644 (file)
@@ -406,6 +406,27 @@ function parseElement(
   const children = parseChildren(context, mode, ancestors)
   ancestors.pop()
 
+  // 2.x inline-template compat
+  if (__COMPAT__) {
+    const inlineTemplateProp = element.props.find(
+      p => p.type === NodeTypes.ATTRIBUTE && p.name === 'inline-template'
+    ) as AttributeNode
+    if (
+      inlineTemplateProp &&
+      checkCompatEnabled(
+        CompilerDeprecationTypes.COMPILER_INLINE_TEMPLATE,
+        context,
+        inlineTemplateProp.loc
+      )
+    ) {
+      inlineTemplateProp.value!.content = getSelection(
+        context,
+        element.loc.end
+      ).source
+      console.log(inlineTemplateProp)
+    }
+  }
+
   element.children = children
 
   // End tag.
@@ -516,7 +537,7 @@ function parseTag(
     return
   }
 
-  // warn v-if/v-for usage on the same element
+  // 2.x deprecation checks
   if (__COMPAT__ && __DEV__ && !__TEST__) {
     let hasIf = false
     let hasFor = false
index 8323144e9070804f8e51db638da08dd15ccda424..0c6c2ca8f3fec26e33582747e305ac5faf4352f0 100644 (file)
@@ -712,24 +712,31 @@ export function finishComponentSetup(
       NOOP) as InternalRenderFunction
   } else if (!instance.render) {
     // could be set from setup()
-    if (compile && Component.template && !Component.render) {
-      if (__DEV__) {
-        startMeasure(instance, `compile`)
-      }
-      const compilerOptions: CompilerOptions = {
-        isCustomElement: instance.appContext.config.isCustomElement,
-        delimiters: Component.delimiters
-      }
-      if (__COMPAT__) {
-        // pass runtime compat config into the compiler
-        compilerOptions.compatConfig = Object.create(globalCompatConfig)
-        if (Component.compatConfig) {
-          extend(compilerOptions.compatConfig, Component.compatConfig)
+    if (compile && !Component.render) {
+      const template =
+        (__COMPAT__ &&
+          instance.vnode.props &&
+          instance.vnode.props['inline-template']) ||
+        Component.template
+      if (template) {
+        if (__DEV__) {
+          startMeasure(instance, `compile`)
+        }
+        const compilerOptions: CompilerOptions = {
+          isCustomElement: instance.appContext.config.isCustomElement,
+          delimiters: Component.delimiters
+        }
+        if (__COMPAT__) {
+          // pass runtime compat config into the compiler
+          compilerOptions.compatConfig = Object.create(globalCompatConfig)
+          if (Component.compatConfig) {
+            extend(compilerOptions.compatConfig, Component.compatConfig)
+          }
+        }
+        Component.render = compile(template, compilerOptions)
+        if (__DEV__) {
+          endMeasure(instance, `compile`)
         }
-      }
-      Component.render = compile(Component.template, compilerOptions)
-      if (__DEV__) {
-        endMeasure(instance, `compile`)
       }
     }
 
index 1a789b6693511d65e6c1b6f1769ba5e95f350487..40765ba9f6992ee8b5acbaa6e4ae9c6e8c42a040 100644 (file)
@@ -297,12 +297,17 @@ function setFullProps(
         continue
       }
 
-      if (__COMPAT__ && key.startsWith('onHook:')) {
-        softAssertCompatEnabled(
-          DeprecationTypes.INSTANCE_EVENT_HOOKS,
-          instance,
-          key.slice(2).toLowerCase()
-        )
+      if (__COMPAT__) {
+        if (key.startsWith('onHook:')) {
+          softAssertCompatEnabled(
+            DeprecationTypes.INSTANCE_EVENT_HOOKS,
+            instance,
+            key.slice(2).toLowerCase()
+          )
+        }
+        if (key === 'inline-template') {
+          continue
+        }
       }
 
       const value = rawProps[key]