]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(sfc): remove `<template inherit-attrs>` support
authorEvan You <yyx990803@gmail.com>
Wed, 23 Jun 2021 01:06:51 +0000 (21:06 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 23 Jun 2021 01:06:51 +0000 (21:06 -0400)
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index cbe4427c7d3791585abea7c3063150c5252201ad..d2bf3698aec5ce304b8984adb90f9b337a8c9025 100644 (file)
@@ -91,28 +91,6 @@ const myEmit = defineEmits(['foo', 'bar'])
   emits: ['foo', 'bar'],`)
   })
 
-  test('<template inherit-attrs="false">', () => {
-    const { content } = compile(`
-      <script>
-      export default {}
-      </script>
-      <template inherit-attrs="false">
-      {{ a }}
-      </template>
-      `)
-    assertCode(content)
-
-    const { content: content2 } = compile(`
-      <script setup>
-      const a = 1
-      </script>
-      <template inherit-attrs="false">
-      {{ a }}
-      </template>
-      `)
-    assertCode(content2)
-  })
-
   describe('<script> and <script setup> co-usage', () => {
     test('script first', () => {
       const { content } = compile(`
index 5789d67392d223d72efdc408370240b7685cd533..e4f201455c67853b22feafe5bdf27fefdae2e1b4 100644 (file)
@@ -96,10 +96,17 @@ export function compileScript(
     )
   }
 
+  // TODO remove on 3.2
+  if (sfc.template && sfc.template.attrs['inherit-attrs'] === 'false') {
+    warnOnce(
+      `experimetnal support for <template inherit-attrs="false"> support has ` +
+        `been removed. Use a <script> block with \`export default\` to ` +
+        `declare options.`
+    )
+  }
+
   const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
   const cssVars = sfc.cssVars
-  const hasInheritAttrsFlag =
-    sfc.template && sfc.template.attrs['inherit-attrs'] === 'false'
   const scriptLang = script && script.lang
   const scriptSetupLang = scriptSetup && scriptSetup.lang
   const isTS =
@@ -125,9 +132,8 @@ export function compileScript(
         sourceType: 'module'
       }).program.body
       const bindings = analyzeScriptBindings(scriptAst)
-      const needRewrite = cssVars.length || hasInheritAttrsFlag
       let content = script.content
-      if (needRewrite) {
+      if (cssVars.length) {
         content = rewriteDefault(content, `__default__`, plugins)
         if (cssVars.length) {
           content += genNormalScriptCssVarsCode(
@@ -137,9 +143,6 @@ export function compileScript(
             !!options.isProd
           )
         }
-        if (hasInheritAttrsFlag) {
-          content += `__default__.inheritAttrs = false`
-        }
         content += `\nexport default __default__`
       }
       return {
@@ -950,9 +953,6 @@ export function compileScript(
   // 11. finalize default export
   // expose: [] makes <script setup> components "closed" by default.
   let runtimeOptions = `\n  expose: [],`
-  if (hasInheritAttrsFlag) {
-    runtimeOptions += `\n  inheritAttrs: false,`
-  }
   if (hasInlinedSsrRenderFn) {
     runtimeOptions += `\n  __ssrInlineRender: true,`
   }