/
parser-api.js
43 lines (39 loc) · 1.03 KB
/
parser-api.js
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
"use strict";
const prettier = require("prettier/local");
const runPrettier = require("../runPrettier");
test("allows custom parser provided as object", () => {
const output = prettier.format("1", {
parser(text) {
expect(text).toEqual("1");
return {
type: "Literal",
value: 2,
raw: "2"
};
}
});
expect(output).toEqual("2");
});
test("allows usage of prettier's supported parsers", () => {
const output = prettier.format("foo ( )", {
parser(text, parsers) {
expect(typeof parsers.babel).toEqual("function");
expect(typeof parsers.babylon).toEqual("function");
const ast = parsers.babel(text);
ast.program.body[0].expression.callee.name = "bar";
return ast;
}
});
expect(output).toEqual("bar();\n");
});
describe("allows passing a string to resolve a parser", () => {
runPrettier("./custom-parsers/", [
"--end-of-line",
"lf",
"./custom-rename-input.js",
"--parser",
"./custom-rename-parser"
]).test({
status: 0
});
});