Skip to content

Commit

Permalink
Fix vue 2.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Jun 25, 2024
1 parent 41ae68b commit 648fb13
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/preprocessors/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ export function vuePreprocessor(code: string, options: PrettierOptions) {
// https://github.com/vuejs/core/blob/b8fc18c0b23be9a77b05dc41ed452a87a0becf82/packages/compiler-core/src/ast.ts#L74-L80
// The node's range. The `start` is inclusive and `end` is exclusive.
// [start, end)
const { start, end } = block.loc;

// @ts-expect-error Some vue versions have a `block.loc`, others have start and end directly on the block
let {start, end} = block;
if ("loc" in block) {
start = block.loc.start.offset;
end = block.loc.end.offset;
}
const preprocessedBlockCode = sortScript(block, options);
result += code.slice(offset, start.offset) + preprocessedBlockCode;
offset = end.offset;
result += code.slice(offset, start) + preprocessedBlockCode;
offset = end;
}

// 4. Append the rest.
Expand Down

0 comments on commit 648fb13

Please sign in to comment.