Skip to content

Commit

Permalink
small performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Janther committed Aug 21, 2023
1 parent 326ddfb commit 4d4ea98
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/common/printer-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const printComments = (node, path, options, filter = () => true) => {
// since it depends on the version of Prettier being used.
// Mocking the behaviour will introduce a lot of maintenance in the tests.
/* c8 ignore start */
return isPrettier2()
return isPrettier2
? document.parts // Prettier V2
: document; // Prettier V3
/* c8 ignore stop */
Expand Down
8 changes: 4 additions & 4 deletions src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import { util, version } from 'prettier';
import satisfies from 'semver/functions/satisfies.js';

export const prettierVersionSatisfies = (range) => satisfies(version, range);
export const isPrettier2 = () => prettierVersionSatisfies('^2.3.0');
export const isPrettier2 = prettierVersionSatisfies('^2.3.0');

// The following functions will never be 100% covered in a single run
// since it depends on the version of Prettier being used.
// Mocking the behaviour will introduce a lot of maintenance in the tests.
/* c8 ignore start */
export function isNextLineEmpty(text, startIndex) {
return isPrettier2()
return isPrettier2
? util.isNextLineEmptyAfterIndex(text, startIndex)
: util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex`
}

export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
return isPrettier2()
return isPrettier2
? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
: util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed
}

export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
return isPrettier2()
return isPrettier2
? text.charAt(
util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
)
Expand Down

0 comments on commit 4d4ea98

Please sign in to comment.