Skip to content

Commit f7a7c42

Browse files
committed
Merge branch 'bandaloo-never-token'
2 parents b6909ff + 751cf45 commit f7a7c42

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lib/generate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
}
5757

5858
options = options || {};
59-
tabulated = lines.map(function addIndent(line, i) {
59+
var tabulated = lines.map(function addIndent(line, i) {
6060
var shouldIndent = true;
6161

6262
if(i == 0 && !options.indentFirst) {
@@ -193,7 +193,7 @@
193193
output += parser.customTokens.map(function (token) { return "declare var " + token + ": any;\n" }).join("")
194194
output += parser.body.join('\n');
195195
output += "\n";
196-
output += "interface NearleyToken {";
196+
output += "interface NearleyToken {\n";
197197
output += " value: any;\n";
198198
output += " [key: string]: any;\n";
199199
output += "};\n";
@@ -202,7 +202,7 @@
202202
output += " reset: (chunk: string, info: any) => void;\n";
203203
output += " next: () => NearleyToken | undefined;\n";
204204
output += " save: () => any;\n";
205-
output += " formatError: (token: NearleyToken) => string;\n";
205+
output += " formatError: (token: never) => string;\n";
206206
output += " has: (tokenType: string) => boolean;\n";
207207
output += "};\n";
208208
output += "\n";

test/nearleyc.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function prettyPrint(grammar) {
1818
return grammar.rules.map(g => g.toString())
1919
}
2020

21+
function typeScriptCheck(isStrict) {
22+
const {outPath, stdout, stderr} = externalNearleyc("grammars/typescript-test.ne", ".ts");
23+
expect(stderr).toBe("");
24+
expect(stdout).toBe("");
25+
const spawnSync = sh(`tsc ${isStrict ? "--strict" : ""} ${outPath}.ts`);
26+
expect(spawnSync.stdout).toBe(""); // type errors get logged to stdout, not stderr
27+
const grammar = nearley.Grammar.fromCompiled(require(`./${outPath}.js`).default);
28+
expect(parse(grammar, "<123>")).toEqual([ [ '<', '123', '>' ] ]);
29+
}
30+
2131

2232
describe("bin/nearleyc", function() {
2333
after(cleanup)
@@ -61,12 +71,12 @@ describe("bin/nearleyc", function() {
6171

6272
it('builds for TypeScript', function() {
6373
this.timeout(10000); // It takes a while to run tsc!
64-
const {outPath, stdout, stderr} = externalNearleyc("grammars/typescript-test.ne", ".ts");
65-
expect(stderr).toBe("");
66-
expect(stdout).toBe("");
67-
sh(`tsc ${outPath}.ts`);
68-
const grammar = nearley.Grammar.fromCompiled(require(`./${outPath}.js`).default);
69-
expect(parse(grammar, "<123>")).toEqual([ [ '<', '123', '>' ] ]);
74+
typeScriptCheck(false);
75+
});
76+
77+
it('builds for TypeScript with `--strict` with no type errors', function() {
78+
this.timeout(10000);
79+
typeScriptCheck(true);
7080
});
7181

7282
it('builds modules in folders', function() {

0 commit comments

Comments
 (0)