-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathprinter.js
More file actions
50 lines (41 loc) · 1.04 KB
/
printer.js
File metadata and controls
50 lines (41 loc) · 1.04 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as nodes from './nodes/index.js';
import { printWarning } from './common/print-warning.js';
import {
hasNodeIgnoreComment,
prettierVersionSatisfies
} from './common/util.js';
import ignoreComments from './comments/ignore.js';
function once(factory) {
let value;
return () => {
if (typeof value === 'undefined') {
value = factory();
}
return value;
};
}
const warnDeprecation = once(() => {
printWarning(
`The 'antlr' parser has been deprecated, please use 'slang' instead.`
);
return true;
});
function genericPrint(path, options, print) {
warnDeprecation();
const node = path.getValue();
if (node === null) {
return '';
}
if (!(node.type in nodes)) {
throw new Error(`Unknown type: ${JSON.stringify(node.type)}`);
}
if (hasNodeIgnoreComment(node)) {
ignoreComments(path);
return options.originalText.slice(
options.locStart(node),
options.locEnd(node) + 1
);
}
return nodes[node.type].print({ node, options, path, print });
}
export default genericPrint;