From 1294385300742acbea5f05c166685bd4a1fab35a Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 5 Jul 2022 10:32:56 +0800 Subject: [PATCH] fix(compiler-sfc): preserve old deindent behavior for pug fix #12611 --- packages/compiler-sfc/src/parseComponent.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/parseComponent.ts b/packages/compiler-sfc/src/parseComponent.ts index 0849a649c2e..39322a3efd4 100644 --- a/packages/compiler-sfc/src/parseComponent.ts +++ b/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