Skip to content

Commit

Permalink
Merge pull request #8 from hildjj/maxFailPos
Browse files Browse the repository at this point in the history
maxFailPos
  • Loading branch information
hildjj authored Nov 9, 2024
2 parents 1103908 + 3962202 commit db30b58
Show file tree
Hide file tree
Showing 9 changed files with 970 additions and 409 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_call:
secrets:
CODECOV_TOKEN:
required: true

jobs:
build:

strategy:
matrix:
node-version: [18.x, 20.x, 21.x, 22.x]
node-version: [18.x, 20.x, 21.x, 22.x, 23.x]
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish Package to npmjs
on:
release:
types: [published]
workflow_call:
secrets:
NPM_TOKEN:
required: true

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
cache: pnpm
- run: pnpm i -r
- run: npm run build
- run: npm run test
- run: npm pkg delete devDependencies scripts packageManager
- run: npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage/
node_modules/
node_modules/
.vscode/
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import js from "@peggyjs/eslint-config/flat/module.js";
import modern from "@peggyjs/eslint-config/flat/modern.js";
import js from "@peggyjs/eslint-config/module.js";
import modern from "@peggyjs/eslint-config/modern.js";

export default [
{
Expand All @@ -9,6 +9,6 @@ export default [
"**/*.ts",
],
},
js,
modern,
...js,
...modern,
];
4 changes: 2 additions & 2 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ export type PeggyTestOptions<T> = {
/**
* See https://github.com/peggyjs/peggy/issues/512
*/
export type Parser = import('peggy').Parser & {
export type Parser = import("peggy").Parser & {
StartRules: string[];
};
export type Location = import('peggy').Location;
export type Location = import("peggy").Location;
export type TestPeggyOptions = {
/**
* Do not delete the generated file.
Expand Down
12 changes: 11 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ let counter = 0;
function checkParserStarts(grammar, starts, modified, counts) {
for (const start of starts) {
const startRule = start.startRule || undefined; // NOT `??`
const peg$maxFailPos = start.peg$maxFailPos ?? 0;
const peg$maxFailPos = start.peg$maxFailPos ?? undefined;
const options = start.options ?? {};
const invalid = start.invalid ?? INVALID;
if (!modified && options.peg$startRuleFunction) {
Expand Down Expand Up @@ -93,12 +93,19 @@ function checkParserStarts(grammar, starts, modified, counts) {
peg$FAILED: {},
peg$maxFailPos,
};
if (peg$maxFailPos === undefined) {
delete expectedLib.peg$maxFailPos;
}
let lib = grammar.parse(start.validInput, {
peg$library: true,
startRule,
...options,
});
delete lib.peg$maxFailExpected;
if (peg$maxFailPos === undefined) {
delete lib.peg$maxFailPos;
}

if (typeof expected === "function") {
// @ts-ignore
lib.peg$result = expected(lib.peg$result);
Expand All @@ -112,6 +119,9 @@ function checkParserStarts(grammar, starts, modified, counts) {
...options,
});
delete lib.peg$maxFailExpected;
if (peg$maxFailPos === undefined) {
delete lib.peg$maxFailPos;
}
if (typeof expected === "function") {
// @ts-ignore
lib.peg$result = expected(lib.peg$result);
Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@peggyjs/coverage",
"version": "1.1.1",
"version": "1.2.0",
"decription": "Generate better code coverage for Peggy grammars",
"main": "lib/index.js",
"type": "module",
Expand Down Expand Up @@ -28,17 +28,23 @@
"test": "c8 node --test test/*.test.js"
},
"dependencies": {
"peggy": "4.0.2",
"peggy": "4.1.1",
"source-map-generator": "0.8.0"
},
"devDependencies": {
"@peggyjs/eslint-config": "3.2.4",
"@types/node": "20.12.10",
"c8": "9.1.0",
"eslint": "8.57.0",
"typescript": "5.4.5"
"@peggyjs/eslint-config": "5.0.1",
"@types/node": "22.9.0",
"c8": "10.1.2",
"eslint": "9.14.0",
"typescript": "5.6.3"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"braces": "^3.0.3",
"micromatch": "^4.0.8"
}
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18"
}
Expand Down
Loading

0 comments on commit db30b58

Please sign in to comment.