Skip to content

Commit

Permalink
Merge pull request peggyjs#483 from hildjj/type-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj authored Feb 23, 2024
2 parents 38b2b80 + 9d2adfd commit 1043631
Show file tree
Hide file tree
Showing 18 changed files with 454 additions and 265 deletions.
2 changes: 1 addition & 1 deletion docs/js/test-bundle.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/peg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ export namespace compiler {
* @param node Leaf node, representing calling a rule in an external library.
* @param args Any arguments passed to the `Visitor`
*/
library_ref?(node: ast.LibraryReference, ...args: an[]): any;
library_ref?(node: ast.LibraryReference, ...args: any[]): any;

/**
* Default behavior: do nothing
Expand Down Expand Up @@ -1077,7 +1077,7 @@ export interface ParserOptions {
/**
* Pending list of expectations.
*/
peg$maxFailExpected?: Expectation[];
peg$maxFailExpected?: parser.Expectation[];
}

export interface LibraryResults {
Expand Down
475 changes: 278 additions & 197 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,31 @@
"start": "cd docs && npm start"
},
"devDependencies": {
"@peggyjs/eslint-config": "^3.2.1",
"@peggyjs/eslint-config": "^3.2.2",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-multi-entry": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/chai": "^4.3.11",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.17",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"chai": "^4.3.11",
"chai-like": "^1.1.1",
"copyfiles": "^2.4.1",
"eslint": "^8.56.0",
"eslint-plugin-compat": "4.2.0",
"eslint-plugin-mocha": "10.3.0",
"express": "4.18.2",
"glob": "^10.3.10",
"jest": "^29.7.0",
"rimraf": "^5.0.5",
"rollup": "^4.10.0",
"rollup": "^4.12.0",
"rollup-plugin-ignore": "1.0.10",
"source-map": "^0.8.0-beta.0",
"terser": "^5.27.0",
"terser": "^5.28.1",
"ts-jest": "^29.1.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
Expand Down
1 change: 1 addition & 0 deletions test/api/generated-parser-api.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-setup-in-describe */
"use strict";

const chai = require("chai");
Expand Down
8 changes: 4 additions & 4 deletions test/api/pegjs-api.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-setup-in-describe */
"use strict";

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

exports.peggyVersion = function peggyVersion() {
return peg.VERSION;
};

chai.use(require("chai-like"));

// eslint-disable-next-line mocha/no-top-level-hooks
beforeEach(() => {
// In the browser, initialize SourceMapConsumer's wasm bits.
// This is *async*, so make sure to return the promise to make
Expand Down Expand Up @@ -343,6 +341,7 @@ describe("Peggy API", () => {
gl,
]) {
describe(`with source = ${chai.util.inspect(source)}`, () => {
/* eslint-disable mocha/consistent-spacing-between-blocks */
it("global initializer", () => check(GLOBAL_INITIALIZER, source, "$top_level_initializer"));
it("per-parse initializer", () => check(PER_PARSE_INITIALIZER, source, "$initializer"));
it("action block", () => check(ACTION_BLOCK, source, null));
Expand All @@ -369,6 +368,7 @@ describe("Peggy API", () => {
/s. = peg\$parseRULE_2/,
].map(r => r.source).join(""))
));
/* eslint-enable mocha/consistent-spacing-between-blocks */
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions test/behavior/generated-parser-behavior.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-setup-in-describe */
"use strict";

const chai = require("chai");
Expand Down Expand Up @@ -3007,6 +3008,7 @@ describe("generated parser behavior", () => {
});
});
});

describe("syntax errors", () => {
it("formats", () => {
const source = { source: "stdin", text: "===" };
Expand Down
4 changes: 4 additions & 0 deletions test/cli/run.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mocha/no-setup-in-describe */
/* eslint-disable mocha/max-top-level-suites */
// This is typescript so that it only runs in node contexts, not on the web

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

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

// eslint-disable-next-line mocha/no-top-level-hooks
afterAll(async() => {
await fs.promises.rm(tmpDir, { recursive: true });
});
Expand Down
2 changes: 1 addition & 1 deletion test/cli/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("watches files", () => {
return p;
});

it.only("debounces", done => {
it("debounces", done => {
let count = 0;
const fn = __filename;
const base = path.basename(fn);
Expand Down
1 change: 1 addition & 0 deletions test/unit/compiler/passes/generate-js.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("compiler pass |generateJS|", () => {
};
const options
= /** @type {PEG.SourceBuildOptions<PEG.SourceOutputs>} */({});

it("throws unless various grammar fields are set", () => {
expect(
() => pass(ast, options)
Expand Down
26 changes: 26 additions & 0 deletions test/unit/compiler/passes/inference-match-result.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,43 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = ''| .. |", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| .. |", { rules: [{ match: 1 }] });
});

it("for | ..1| correctly", () => {
expect(pass).to.changeAST("start = .| ..1|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = ''| ..1|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| ..1|", { rules: [{ match: 1 }] });
});

it("for | ..3| correctly", () => {
expect(pass).to.changeAST("start = .| ..3|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = ''| ..3|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| ..3|", { rules: [{ match: 1 }] });
});

it("for |0.. | correctly", () => {
expect(pass).to.changeAST("start = .|0.. |", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = ''|0.. |", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []|0.. |", { rules: [{ match: 1 }] });
});

it("for |1.. | correctly", () => {
expect(pass).to.changeAST("start = .|1.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|1.. |", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []|1.. |", { rules: [{ match: -1 }] });
});

it("for |2.. | correctly", () => {
expect(pass).to.changeAST("start = .|2.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|2.. |", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []|2.. |", { rules: [{ match: -1 }] });
});

it("for |2..3| correctly", () => {
expect(pass).to.changeAST("start = .|2..3|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|2..3|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []|2..3|", { rules: [{ match: -1 }] });
});

it("for | 42 | correctly", () => {
expect(pass).to.changeAST("start = .| 42 |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''| 42 |", { rules: [{ match: 1 }] });
Expand All @@ -159,16 +166,19 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = ''| ..max|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []| ..max|", { rules: [{ match: 0 }] });
});

it("for |min.. | correctly", () => {
expect(pass).to.changeAST("start = .|min.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|min.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|min.. |", { rules: [{ match: 0 }] });
});

it("for |min..max| correctly", () => {
expect(pass).to.changeAST("start = .|min..max|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|min..max|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|min..max|", { rules: [{ match: 0 }] });
});

it("for | exact | correctly", () => {
expect(pass).to.changeAST("start = .|exact|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|exact|", { rules: [{ match: 0 }] });
Expand All @@ -182,16 +192,19 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = ''| ..{}|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []| ..{}|", { rules: [{ match: 0 }] });
});

it("for |{}.. | correctly", () => {
expect(pass).to.changeAST("start = .|{}.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|{}.. |", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|{}.. |", { rules: [{ match: 0 }] });
});

it("for |{}..{}| correctly", () => {
expect(pass).to.changeAST("start = .|{}..{}|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|{}..{}|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|{}..{}|", { rules: [{ match: 0 }] });
});

it("for | {} | correctly", () => {
expect(pass).to.changeAST("start = .|{}|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = ''|{}|", { rules: [{ match: 0 }] });
Expand All @@ -215,6 +228,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []| .. ,''|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| .. ,[]|", { rules: [{ match: 1 }] });
});

it("for | ..1, delimiter| correctly", () => {
expect(pass).to.changeAST("start = .| ..1, .|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = .| ..1,''|", { rules: [{ match: 1 }] });
Expand All @@ -228,6 +242,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []| ..1,''|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| ..1,[]|", { rules: [{ match: 1 }] });
});

it("for | ..3, delimiter| correctly", () => {
expect(pass).to.changeAST("start = .| ..3, .|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = .| ..3,''|", { rules: [{ match: 1 }] });
Expand All @@ -241,6 +256,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []| ..3,''|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []| ..3,[]|", { rules: [{ match: 1 }] });
});

it("for |0.. , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|0.. , .|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = .|0.. ,''|", { rules: [{ match: 1 }] });
Expand All @@ -254,6 +270,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|0.. ,''|", { rules: [{ match: 1 }] });
expect(pass).to.changeAST("start = []|0.. ,[]|", { rules: [{ match: 1 }] });
});

it("for |1.. , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|1.. , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|1.. ,''|", { rules: [{ match: 0 }] });
Expand All @@ -267,6 +284,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|1.. ,''|", { rules: [{ match: -1 }] });
expect(pass).to.changeAST("start = []|1.. ,[]|", { rules: [{ match: -1 }] });
});

it("for |2.. , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|2.. , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|2.. ,''|", { rules: [{ match: 0 }] });
Expand All @@ -280,6 +298,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|2.. ,''|", { rules: [{ match: -1 }] });
expect(pass).to.changeAST("start = []|2.. ,[]|", { rules: [{ match: -1 }] });
});

it("for |2..3, delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|2..3, .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|2..3,''|", { rules: [{ match: 0 }] });
Expand All @@ -293,6 +312,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|2..3,''|", { rules: [{ match: -1 }] });
expect(pass).to.changeAST("start = []|2..3,[]|", { rules: [{ match: -1 }] });
});

it("for | 42 , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .| 42 , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .| 42 ,''|", { rules: [{ match: 0 }] });
Expand Down Expand Up @@ -322,6 +342,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []| ..max,''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []| ..max,[]|", { rules: [{ match: 0 }] });
});

it("for |min.. , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|min.. , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|min.. ,''|", { rules: [{ match: 0 }] });
Expand All @@ -335,6 +356,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|min.. ,''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|min.. ,[]|", { rules: [{ match: 0 }] });
});

it("for |min..max, delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|min..max, .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|min..max,''|", { rules: [{ match: 0 }] });
Expand All @@ -348,6 +370,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|min..max,''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|min..max,[]|", { rules: [{ match: 0 }] });
});

it("for | exact , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .| exact , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .| exact ,''|", { rules: [{ match: 0 }] });
Expand Down Expand Up @@ -377,6 +400,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []| ..{},''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []| ..{},[]|", { rules: [{ match: 0 }] });
});

it("for |{}.. , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|{}.. , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|{}.. ,''|", { rules: [{ match: 0 }] });
Expand All @@ -390,6 +414,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|{}.. ,''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|{}.. ,[]|", { rules: [{ match: 0 }] });
});

it("for |{}..{}, delimiter| correctly", () => {
expect(pass).to.changeAST("start = .|{}..{}, .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .|{}..{},''|", { rules: [{ match: 0 }] });
Expand All @@ -403,6 +428,7 @@ describe("compiler pass |inferenceMatchResult|", () => {
expect(pass).to.changeAST("start = []|{}..{},''|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = []|{}..{},[]|", { rules: [{ match: 0 }] });
});

it("for | {} , delimiter| correctly", () => {
expect(pass).to.changeAST("start = .| {} , .|", { rules: [{ match: 0 }] });
expect(pass).to.changeAST("start = .| {} ,''|", { rules: [{ match: 0 }] });
Expand Down
3 changes: 3 additions & 0 deletions test/unit/compiler/passes/merge-character-classes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
{ mergeCharacterClasses: true }
);
});

it("Merges case-independent single character literals, class, and ref_rules", () => {
expect(pass).to.changeAST(
[
Expand Down Expand Up @@ -141,6 +142,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
{ mergeCharacterClasses: true }
);
});

it("Doesn't merge inappropriately", () => {
expect(pass).to.changeAST(
[
Expand Down Expand Up @@ -187,6 +189,7 @@ describe("compiler pass |mergeCharacterClasses|", () => {
{ mergeCharacterClasses: true }
);
});

it("Handles undefined rule_refs", () => {
expect(pass).to.changeAST(
[
Expand Down
3 changes: 3 additions & 0 deletions test/unit/compiler/stack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ describe("utility class Stack", () => {
+ "Bytecode: 42"
);
});

it("decreases in `if` and was not moving in `then`", () => {
expect(() => {
stack.checkedIf(0, () => stack.pop(), () => { /* Lint */ });
Expand All @@ -186,6 +187,7 @@ describe("utility class Stack", () => {
+ "Bytecode: 42"
);
});

it("increases in `if` and was not moving in `then`", () => {
expect(() => {
stack.checkedIf(0, () => stack.push("2"), () => { /* Lint */ });
Expand All @@ -209,6 +211,7 @@ describe("utility class Stack", () => {
+ "Bytecode: 42"
);
});

it("increases in `if` and decreases in `then`", () => {
expect(() => {
stack.checkedIf(0, () => stack.push("2"), () => stack.pop());
Expand Down
Loading

0 comments on commit 1043631

Please sign in to comment.