diff --git a/src/transformers/pug.ts b/src/transformers/pug.ts index b02192bf..81693c1b 100644 --- a/src/transformers/pug.ts +++ b/src/transformers/pug.ts @@ -1,5 +1,6 @@ import detectIndent from 'detect-indent'; import pug from 'pug'; +import lex from 'pug-lexer'; import type { Transformer, Options } from '../types'; @@ -68,7 +69,18 @@ const transformer: Transformer = async ({ }; const { type: indentationType } = detectIndent(content); - const input = `${GET_MIXINS(indentationType ?? 'space')}\n${content}`; + let input = `${GET_MIXINS(indentationType ?? 'space')}\n${content}`; + const tokens = lex(input); + const extendsToken = tokens.find((token) => token.type === 'extends'); + + if (extendsToken) { + const lines = input.split('\n'); + const [extendsLine] = lines.splice(extendsToken.loc.start.line - 1, 1); + + lines.unshift(extendsLine); + input = lines.join('\n'); + } + const compiled = pug.compile( input, pugOptions,