diff --git a/packages/compiler-sfc/src/parseComponent.ts b/packages/compiler-sfc/src/parseComponent.ts index 39322a3efd4..65b858c9fc0 100644 --- a/packages/compiler-sfc/src/parseComponent.ts +++ b/packages/compiler-sfc/src/parseComponent.ts @@ -10,7 +10,6 @@ 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 @@ -179,9 +178,13 @@ export function parseComponent( currentBlock.end = start let text = source.slice(currentBlock.start, currentBlock.end) if ( - options.deindent || - // certain langs like pug are indent sensitive, preserve old behavior - (currentBlock.lang && isNeedIndentLang(currentBlock.lang)) + options.deindent === true || + // by default, deindent unless it's script with default lang or ts + (options.deindent !== false && + !( + currentBlock.type === 'script' && + (!currentBlock.lang || currentBlock.lang === 'ts') + )) ) { text = deindent(text) } diff --git a/packages/compiler-sfc/test/parseComponent.spec.ts b/packages/compiler-sfc/test/parseComponent.spec.ts index 4624bb2040d..83f73483e0c 100644 --- a/packages/compiler-sfc/test/parseComponent.spec.ts +++ b/packages/compiler-sfc/test/parseComponent.spec.ts @@ -25,8 +25,7 @@ describe('Single File Component parser', () => {