Skip to content

Commit 1043631

Browse files
authored
Merge pull request #483 from hildjj/type-errors
Fixes #482.
2 parents 38b2b80 + 9d2adfd commit 1043631

18 files changed

+454
-265
lines changed

docs/js/test-bundle.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/peg.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ export namespace compiler {
859859
* @param node Leaf node, representing calling a rule in an external library.
860860
* @param args Any arguments passed to the `Visitor`
861861
*/
862-
library_ref?(node: ast.LibraryReference, ...args: an[]): any;
862+
library_ref?(node: ast.LibraryReference, ...args: any[]): any;
863863

864864
/**
865865
* Default behavior: do nothing
@@ -1077,7 +1077,7 @@ export interface ParserOptions {
10771077
/**
10781078
* Pending list of expectations.
10791079
*/
1080-
peg$maxFailExpected?: Expectation[];
1080+
peg$maxFailExpected?: parser.Expectation[];
10811081
}
10821082

10831083
export interface LibraryResults {

package-lock.json

+278-197
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,31 @@
5353
"start": "cd docs && npm start"
5454
},
5555
"devDependencies": {
56-
"@peggyjs/eslint-config": "^3.2.1",
56+
"@peggyjs/eslint-config": "^3.2.2",
5757
"@rollup/plugin-commonjs": "^25.0.7",
5858
"@rollup/plugin-json": "^6.1.0",
5959
"@rollup/plugin-multi-entry": "^6.0.1",
6060
"@rollup/plugin-node-resolve": "^15.2.3",
6161
"@rollup/plugin-typescript": "^11.1.6",
6262
"@types/chai": "^4.3.11",
6363
"@types/jest": "^29.5.12",
64-
"@types/node": "^20.11.17",
65-
"@typescript-eslint/eslint-plugin": "^7.0.1",
66-
"@typescript-eslint/parser": "^7.0.1",
64+
"@types/node": "^20.11.20",
65+
"@typescript-eslint/eslint-plugin": "^7.0.2",
66+
"@typescript-eslint/parser": "^7.0.2",
6767
"chai": "^4.3.11",
6868
"chai-like": "^1.1.1",
6969
"copyfiles": "^2.4.1",
7070
"eslint": "^8.56.0",
7171
"eslint-plugin-compat": "4.2.0",
72+
"eslint-plugin-mocha": "10.3.0",
7273
"express": "4.18.2",
7374
"glob": "^10.3.10",
7475
"jest": "^29.7.0",
7576
"rimraf": "^5.0.5",
76-
"rollup": "^4.10.0",
77+
"rollup": "^4.12.0",
7778
"rollup-plugin-ignore": "1.0.10",
7879
"source-map": "^0.8.0-beta.0",
79-
"terser": "^5.27.0",
80+
"terser": "^5.28.1",
8081
"ts-jest": "^29.1.2",
8182
"tslib": "^2.6.2",
8283
"typescript": "^5.3.3"

test/api/generated-parser-api.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable mocha/no-setup-in-describe */
12
"use strict";
23

34
const chai = require("chai");

test/api/pegjs-api.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable mocha/no-setup-in-describe */
12
"use strict";
23

34
const chai = require("chai");
@@ -6,12 +7,9 @@ const pkg = require("../../package.json");
67
const { SourceMapConsumer } = require("source-map");
78
const { spy } = require("../utils.js");
89

9-
exports.peggyVersion = function peggyVersion() {
10-
return peg.VERSION;
11-
};
12-
1310
chai.use(require("chai-like"));
1411

12+
// eslint-disable-next-line mocha/no-top-level-hooks
1513
beforeEach(() => {
1614
// In the browser, initialize SourceMapConsumer's wasm bits.
1715
// This is *async*, so make sure to return the promise to make
@@ -343,6 +341,7 @@ describe("Peggy API", () => {
343341
gl,
344342
]) {
345343
describe(`with source = ${chai.util.inspect(source)}`, () => {
344+
/* eslint-disable mocha/consistent-spacing-between-blocks */
346345
it("global initializer", () => check(GLOBAL_INITIALIZER, source, "$top_level_initializer"));
347346
it("per-parse initializer", () => check(PER_PARSE_INITIALIZER, source, "$initializer"));
348347
it("action block", () => check(ACTION_BLOCK, source, null));
@@ -369,6 +368,7 @@ describe("Peggy API", () => {
369368
/s. = peg\$parseRULE_2/,
370369
].map(r => r.source).join(""))
371370
));
371+
/* eslint-enable mocha/consistent-spacing-between-blocks */
372372
});
373373
}
374374
});

test/behavior/generated-parser-behavior.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable mocha/no-setup-in-describe */
12
"use strict";
23

34
const chai = require("chai");
@@ -3007,6 +3008,7 @@ describe("generated parser behavior", () => {
30073008
});
30083009
});
30093010
});
3011+
30103012
describe("syntax errors", () => {
30113013
it("formats", () => {
30123014
const source = { source: "stdin", text: "===" };

test/cli/run.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable mocha/no-setup-in-describe */
2+
/* eslint-disable mocha/max-top-level-suites */
13
// This is typescript so that it only runs in node contexts, not on the web
24

35
import * as fs from "fs";
@@ -21,10 +23,12 @@ const packageJson = path.resolve(__dirname, "..", "..", "package.json");
2123
const grammarFile = path.resolve(__dirname, "..", "..", "examples", "json.pegjs");
2224
let tmpDir = "";
2325

26+
// eslint-disable-next-line mocha/no-top-level-hooks
2427
beforeAll(async() => {
2528
tmpDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "run-spec-"));
2629
});
2730

31+
// eslint-disable-next-line mocha/no-top-level-hooks
2832
afterAll(async() => {
2933
await fs.promises.rm(tmpDir, { recursive: true });
3034
});

test/cli/watcher.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("watches files", () => {
2121
return p;
2222
});
2323

24-
it.only("debounces", done => {
24+
it("debounces", done => {
2525
let count = 0;
2626
const fn = __filename;
2727
const base = path.basename(fn);

test/unit/compiler/passes/generate-js.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("compiler pass |generateJS|", () => {
2424
};
2525
const options
2626
= /** @type {PEG.SourceBuildOptions<PEG.SourceOutputs>} */({});
27+
2728
it("throws unless various grammar fields are set", () => {
2829
expect(
2930
() => pass(ast, options)

test/unit/compiler/passes/inference-match-result.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,43 @@ describe("compiler pass |inferenceMatchResult|", () => {
116116
expect(pass).to.changeAST("start = ''| .. |", { rules: [{ match: 1 }] });
117117
expect(pass).to.changeAST("start = []| .. |", { rules: [{ match: 1 }] });
118118
});
119+
119120
it("for | ..1| correctly", () => {
120121
expect(pass).to.changeAST("start = .| ..1|", { rules: [{ match: 1 }] });
121122
expect(pass).to.changeAST("start = ''| ..1|", { rules: [{ match: 1 }] });
122123
expect(pass).to.changeAST("start = []| ..1|", { rules: [{ match: 1 }] });
123124
});
125+
124126
it("for | ..3| correctly", () => {
125127
expect(pass).to.changeAST("start = .| ..3|", { rules: [{ match: 1 }] });
126128
expect(pass).to.changeAST("start = ''| ..3|", { rules: [{ match: 1 }] });
127129
expect(pass).to.changeAST("start = []| ..3|", { rules: [{ match: 1 }] });
128130
});
131+
129132
it("for |0.. | correctly", () => {
130133
expect(pass).to.changeAST("start = .|0.. |", { rules: [{ match: 1 }] });
131134
expect(pass).to.changeAST("start = ''|0.. |", { rules: [{ match: 1 }] });
132135
expect(pass).to.changeAST("start = []|0.. |", { rules: [{ match: 1 }] });
133136
});
137+
134138
it("for |1.. | correctly", () => {
135139
expect(pass).to.changeAST("start = .|1.. |", { rules: [{ match: 0 }] });
136140
expect(pass).to.changeAST("start = ''|1.. |", { rules: [{ match: 1 }] });
137141
expect(pass).to.changeAST("start = []|1.. |", { rules: [{ match: -1 }] });
138142
});
143+
139144
it("for |2.. | correctly", () => {
140145
expect(pass).to.changeAST("start = .|2.. |", { rules: [{ match: 0 }] });
141146
expect(pass).to.changeAST("start = ''|2.. |", { rules: [{ match: 1 }] });
142147
expect(pass).to.changeAST("start = []|2.. |", { rules: [{ match: -1 }] });
143148
});
149+
144150
it("for |2..3| correctly", () => {
145151
expect(pass).to.changeAST("start = .|2..3|", { rules: [{ match: 0 }] });
146152
expect(pass).to.changeAST("start = ''|2..3|", { rules: [{ match: 1 }] });
147153
expect(pass).to.changeAST("start = []|2..3|", { rules: [{ match: -1 }] });
148154
});
155+
149156
it("for | 42 | correctly", () => {
150157
expect(pass).to.changeAST("start = .| 42 |", { rules: [{ match: 0 }] });
151158
expect(pass).to.changeAST("start = ''| 42 |", { rules: [{ match: 1 }] });
@@ -159,16 +166,19 @@ describe("compiler pass |inferenceMatchResult|", () => {
159166
expect(pass).to.changeAST("start = ''| ..max|", { rules: [{ match: 0 }] });
160167
expect(pass).to.changeAST("start = []| ..max|", { rules: [{ match: 0 }] });
161168
});
169+
162170
it("for |min.. | correctly", () => {
163171
expect(pass).to.changeAST("start = .|min.. |", { rules: [{ match: 0 }] });
164172
expect(pass).to.changeAST("start = ''|min.. |", { rules: [{ match: 0 }] });
165173
expect(pass).to.changeAST("start = []|min.. |", { rules: [{ match: 0 }] });
166174
});
175+
167176
it("for |min..max| correctly", () => {
168177
expect(pass).to.changeAST("start = .|min..max|", { rules: [{ match: 0 }] });
169178
expect(pass).to.changeAST("start = ''|min..max|", { rules: [{ match: 0 }] });
170179
expect(pass).to.changeAST("start = []|min..max|", { rules: [{ match: 0 }] });
171180
});
181+
172182
it("for | exact | correctly", () => {
173183
expect(pass).to.changeAST("start = .|exact|", { rules: [{ match: 0 }] });
174184
expect(pass).to.changeAST("start = ''|exact|", { rules: [{ match: 0 }] });
@@ -182,16 +192,19 @@ describe("compiler pass |inferenceMatchResult|", () => {
182192
expect(pass).to.changeAST("start = ''| ..{}|", { rules: [{ match: 0 }] });
183193
expect(pass).to.changeAST("start = []| ..{}|", { rules: [{ match: 0 }] });
184194
});
195+
185196
it("for |{}.. | correctly", () => {
186197
expect(pass).to.changeAST("start = .|{}.. |", { rules: [{ match: 0 }] });
187198
expect(pass).to.changeAST("start = ''|{}.. |", { rules: [{ match: 0 }] });
188199
expect(pass).to.changeAST("start = []|{}.. |", { rules: [{ match: 0 }] });
189200
});
201+
190202
it("for |{}..{}| correctly", () => {
191203
expect(pass).to.changeAST("start = .|{}..{}|", { rules: [{ match: 0 }] });
192204
expect(pass).to.changeAST("start = ''|{}..{}|", { rules: [{ match: 0 }] });
193205
expect(pass).to.changeAST("start = []|{}..{}|", { rules: [{ match: 0 }] });
194206
});
207+
195208
it("for | {} | correctly", () => {
196209
expect(pass).to.changeAST("start = .|{}|", { rules: [{ match: 0 }] });
197210
expect(pass).to.changeAST("start = ''|{}|", { rules: [{ match: 0 }] });
@@ -215,6 +228,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
215228
expect(pass).to.changeAST("start = []| .. ,''|", { rules: [{ match: 1 }] });
216229
expect(pass).to.changeAST("start = []| .. ,[]|", { rules: [{ match: 1 }] });
217230
});
231+
218232
it("for | ..1, delimiter| correctly", () => {
219233
expect(pass).to.changeAST("start = .| ..1, .|", { rules: [{ match: 1 }] });
220234
expect(pass).to.changeAST("start = .| ..1,''|", { rules: [{ match: 1 }] });
@@ -228,6 +242,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
228242
expect(pass).to.changeAST("start = []| ..1,''|", { rules: [{ match: 1 }] });
229243
expect(pass).to.changeAST("start = []| ..1,[]|", { rules: [{ match: 1 }] });
230244
});
245+
231246
it("for | ..3, delimiter| correctly", () => {
232247
expect(pass).to.changeAST("start = .| ..3, .|", { rules: [{ match: 1 }] });
233248
expect(pass).to.changeAST("start = .| ..3,''|", { rules: [{ match: 1 }] });
@@ -241,6 +256,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
241256
expect(pass).to.changeAST("start = []| ..3,''|", { rules: [{ match: 1 }] });
242257
expect(pass).to.changeAST("start = []| ..3,[]|", { rules: [{ match: 1 }] });
243258
});
259+
244260
it("for |0.. , delimiter| correctly", () => {
245261
expect(pass).to.changeAST("start = .|0.. , .|", { rules: [{ match: 1 }] });
246262
expect(pass).to.changeAST("start = .|0.. ,''|", { rules: [{ match: 1 }] });
@@ -254,6 +270,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
254270
expect(pass).to.changeAST("start = []|0.. ,''|", { rules: [{ match: 1 }] });
255271
expect(pass).to.changeAST("start = []|0.. ,[]|", { rules: [{ match: 1 }] });
256272
});
273+
257274
it("for |1.. , delimiter| correctly", () => {
258275
expect(pass).to.changeAST("start = .|1.. , .|", { rules: [{ match: 0 }] });
259276
expect(pass).to.changeAST("start = .|1.. ,''|", { rules: [{ match: 0 }] });
@@ -267,6 +284,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
267284
expect(pass).to.changeAST("start = []|1.. ,''|", { rules: [{ match: -1 }] });
268285
expect(pass).to.changeAST("start = []|1.. ,[]|", { rules: [{ match: -1 }] });
269286
});
287+
270288
it("for |2.. , delimiter| correctly", () => {
271289
expect(pass).to.changeAST("start = .|2.. , .|", { rules: [{ match: 0 }] });
272290
expect(pass).to.changeAST("start = .|2.. ,''|", { rules: [{ match: 0 }] });
@@ -280,6 +298,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
280298
expect(pass).to.changeAST("start = []|2.. ,''|", { rules: [{ match: -1 }] });
281299
expect(pass).to.changeAST("start = []|2.. ,[]|", { rules: [{ match: -1 }] });
282300
});
301+
283302
it("for |2..3, delimiter| correctly", () => {
284303
expect(pass).to.changeAST("start = .|2..3, .|", { rules: [{ match: 0 }] });
285304
expect(pass).to.changeAST("start = .|2..3,''|", { rules: [{ match: 0 }] });
@@ -293,6 +312,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
293312
expect(pass).to.changeAST("start = []|2..3,''|", { rules: [{ match: -1 }] });
294313
expect(pass).to.changeAST("start = []|2..3,[]|", { rules: [{ match: -1 }] });
295314
});
315+
296316
it("for | 42 , delimiter| correctly", () => {
297317
expect(pass).to.changeAST("start = .| 42 , .|", { rules: [{ match: 0 }] });
298318
expect(pass).to.changeAST("start = .| 42 ,''|", { rules: [{ match: 0 }] });
@@ -322,6 +342,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
322342
expect(pass).to.changeAST("start = []| ..max,''|", { rules: [{ match: 0 }] });
323343
expect(pass).to.changeAST("start = []| ..max,[]|", { rules: [{ match: 0 }] });
324344
});
345+
325346
it("for |min.. , delimiter| correctly", () => {
326347
expect(pass).to.changeAST("start = .|min.. , .|", { rules: [{ match: 0 }] });
327348
expect(pass).to.changeAST("start = .|min.. ,''|", { rules: [{ match: 0 }] });
@@ -335,6 +356,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
335356
expect(pass).to.changeAST("start = []|min.. ,''|", { rules: [{ match: 0 }] });
336357
expect(pass).to.changeAST("start = []|min.. ,[]|", { rules: [{ match: 0 }] });
337358
});
359+
338360
it("for |min..max, delimiter| correctly", () => {
339361
expect(pass).to.changeAST("start = .|min..max, .|", { rules: [{ match: 0 }] });
340362
expect(pass).to.changeAST("start = .|min..max,''|", { rules: [{ match: 0 }] });
@@ -348,6 +370,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
348370
expect(pass).to.changeAST("start = []|min..max,''|", { rules: [{ match: 0 }] });
349371
expect(pass).to.changeAST("start = []|min..max,[]|", { rules: [{ match: 0 }] });
350372
});
373+
351374
it("for | exact , delimiter| correctly", () => {
352375
expect(pass).to.changeAST("start = .| exact , .|", { rules: [{ match: 0 }] });
353376
expect(pass).to.changeAST("start = .| exact ,''|", { rules: [{ match: 0 }] });
@@ -377,6 +400,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
377400
expect(pass).to.changeAST("start = []| ..{},''|", { rules: [{ match: 0 }] });
378401
expect(pass).to.changeAST("start = []| ..{},[]|", { rules: [{ match: 0 }] });
379402
});
403+
380404
it("for |{}.. , delimiter| correctly", () => {
381405
expect(pass).to.changeAST("start = .|{}.. , .|", { rules: [{ match: 0 }] });
382406
expect(pass).to.changeAST("start = .|{}.. ,''|", { rules: [{ match: 0 }] });
@@ -390,6 +414,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
390414
expect(pass).to.changeAST("start = []|{}.. ,''|", { rules: [{ match: 0 }] });
391415
expect(pass).to.changeAST("start = []|{}.. ,[]|", { rules: [{ match: 0 }] });
392416
});
417+
393418
it("for |{}..{}, delimiter| correctly", () => {
394419
expect(pass).to.changeAST("start = .|{}..{}, .|", { rules: [{ match: 0 }] });
395420
expect(pass).to.changeAST("start = .|{}..{},''|", { rules: [{ match: 0 }] });
@@ -403,6 +428,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
403428
expect(pass).to.changeAST("start = []|{}..{},''|", { rules: [{ match: 0 }] });
404429
expect(pass).to.changeAST("start = []|{}..{},[]|", { rules: [{ match: 0 }] });
405430
});
431+
406432
it("for | {} , delimiter| correctly", () => {
407433
expect(pass).to.changeAST("start = .| {} , .|", { rules: [{ match: 0 }] });
408434
expect(pass).to.changeAST("start = .| {} ,''|", { rules: [{ match: 0 }] });

test/unit/compiler/passes/merge-character-classes.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
7575
{ mergeCharacterClasses: true }
7676
);
7777
});
78+
7879
it("Merges case-independent single character literals, class, and ref_rules", () => {
7980
expect(pass).to.changeAST(
8081
[
@@ -141,6 +142,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
141142
{ mergeCharacterClasses: true }
142143
);
143144
});
145+
144146
it("Doesn't merge inappropriately", () => {
145147
expect(pass).to.changeAST(
146148
[
@@ -187,6 +189,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
187189
{ mergeCharacterClasses: true }
188190
);
189191
});
192+
190193
it("Handles undefined rule_refs", () => {
191194
expect(pass).to.changeAST(
192195
[

test/unit/compiler/stack.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ describe("utility class Stack", () => {
163163
+ "Bytecode: 42"
164164
);
165165
});
166+
166167
it("decreases in `if` and was not moving in `then`", () => {
167168
expect(() => {
168169
stack.checkedIf(0, () => stack.pop(), () => { /* Lint */ });
@@ -186,6 +187,7 @@ describe("utility class Stack", () => {
186187
+ "Bytecode: 42"
187188
);
188189
});
190+
189191
it("increases in `if` and was not moving in `then`", () => {
190192
expect(() => {
191193
stack.checkedIf(0, () => stack.push("2"), () => { /* Lint */ });
@@ -209,6 +211,7 @@ describe("utility class Stack", () => {
209211
+ "Bytecode: 42"
210212
);
211213
});
214+
212215
it("increases in `if` and decreases in `then`", () => {
213216
expect(() => {
214217
stack.checkedIf(0, () => stack.push("2"), () => stack.pop());

0 commit comments

Comments
 (0)