ソースを参照

fix(compiler-sfc): preserve old deindent behavior for pug

fix #12611
Evan You 4 年 前
コミット
1294385300
1 ファイル変更6 行追加1 行削除
  1. 6 1
      packages/compiler-sfc/src/parseComponent.ts

+ 6 - 1
packages/compiler-sfc/src/parseComponent.ts

@@ -10,6 +10,7 @@ export const DEFAULT_FILENAME = 'anonymous.vue'
 const splitRE = /\r?\n/g
 const replaceRE = /./g
 const isSpecialTag = makeMap('script,style,template', true)
+const isNeedIndentLang = makeMap('pug,jade')
 
 export interface SFCCustomBlock {
   type: string
@@ -177,7 +178,11 @@ export function parseComponent(
     if (depth === 1 && currentBlock) {
       currentBlock.end = start
       let text = source.slice(currentBlock.start, currentBlock.end)
-      if (options.deindent) {
+      if (
+        options.deindent ||
+        // certain langs like pug are indent sensitive, preserve old behavior
+        (currentBlock.lang && isNeedIndentLang(currentBlock.lang))
+      ) {
         text = deindent(text)
       }
       // pad content so that linters and pre-processors can output correct