-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathbackward-compatibility.js
More file actions
34 lines (28 loc) · 1.26 KB
/
backward-compatibility.js
File metadata and controls
34 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { util } from 'prettier';
import { prettierVersionSatisfies } from './util.js';
export const isPrettier2 = prettierVersionSatisfies('^2.3.0');
// The functions in this file 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.
export function isNextLineEmpty(text, startIndex) {
return isPrettier2
? util.isNextLineEmptyAfterIndex(text, startIndex)
: util.isNextLineEmpty(text, startIndex); // V3 deprecated `isNextLineEmptyAfterIndex`
}
export function getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd) {
return isPrettier2
? util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
: util.getNextNonSpaceNonCommentCharacterIndex(text, locEnd(node)); // V3 signature changed
}
export function getNextNonSpaceNonCommentCharacter(text, node, locEnd) {
return isPrettier2
? text.charAt(
util.getNextNonSpaceNonCommentCharacterIndex(text, node, locEnd)
)
: util.getNextNonSpaceNonCommentCharacter(text, locEnd(node)); // V3 exposes this function directly
}
export function isLast(path, key, index) {
return isPrettier2
? index === path.getParentNode()[key].length - 1
: path.isLast;
}