Skip to content

Commit

Permalink
fix: pug formatter extra spaces
Browse files Browse the repository at this point in the history
close #1784
  • Loading branch information
johnsoncodehk committed Sep 4, 2022
1 parent 28b56e0 commit 6d93d9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vue-language-core/src/generators/template.ts
Expand Up @@ -61,6 +61,7 @@ export function isIntrinsicElement(runtimeMode: 'runtime-dom' | 'runtime-uni-app
export function generate(
ts: typeof import('typescript/lib/tsserverlibrary'),
vueCompilerOptions: _VueCompilerOptions,
sourceTemplate: string,
sourceLang: string,
templateAst: CompilerDOM.RootNode,
hasScriptSetup: boolean,
Expand Down Expand Up @@ -309,14 +310,16 @@ export function generate(
let rightCharacter: string;

// fix https://github.com/johnsoncodehk/volar/issues/1787
while ((leftCharacter = templateAst.loc.source.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
while ((leftCharacter = sourceTemplate.substring(start - 1, start)).trim() === '' && leftCharacter.length) {
start--;
content = leftCharacter + content;
}
while ((rightCharacter = templateAst.loc.source.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
while ((rightCharacter = sourceTemplate.substring(start + content.length, start + content.length + 1)).trim() === '' && rightCharacter.length) {
content = content + rightCharacter;
}

console.log(content, node.loc.source, sourceTemplate.substring(start - 10, start));

writeInterpolation(
content,
start,
Expand Down
1 change: 1 addition & 0 deletions packages/vue-language-core/src/plugins/vue-tsx.ts
Expand Up @@ -131,6 +131,7 @@ const plugin: VueLanguagePlugin = ({ modules, vueCompilerOptions, compilerOption
return templateGen.generate(
ts,
vueCompilerOptions,
sfc.template?.content ?? '',
sfc.template?.lang ?? 'html',
sfc.templateAst,
!!sfc.scriptSetup,
Expand Down

0 comments on commit 6d93d9d

Please sign in to comment.