From b61ca19bfe5ef225068340549f869221c717bd5d Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Thu, 29 Feb 2024 13:03:40 -0700 Subject: [PATCH] Fixes #23. Add null check. --- .npmignore | 1 + lib/index.js | 4 +- package.json | 6 +- pnpm-lock.yaml | 32 +++---- test/index.test.js | 6 ++ test/snapshots/index.test.js.md | 143 ++++++++++++++++++++++++++++++ test/snapshots/index.test.js.snap | Bin 0 -> 1111 bytes 7 files changed, 172 insertions(+), 20 deletions(-) create mode 100644 test/snapshots/index.test.js.md create mode 100644 test/snapshots/index.test.js.snap diff --git a/.npmignore b/.npmignore index c3cc410..be2fc37 100644 --- a/.npmignore +++ b/.npmignore @@ -13,3 +13,4 @@ tsconfig.json vendor/*/rationale.md eslint.config.js .ncurc +.gitattributes diff --git a/lib/index.js b/lib/index.js index 8043da1..4dc3d07 100644 --- a/lib/index.js +++ b/lib/index.js @@ -113,7 +113,9 @@ const visit = peggy.compiler.visitor.build({ } } - if (node.min.type === "constant" && !node.min.value) { + if (!node.min + || ((node.min.type === "constant") + && (node.min.value === 0))) { return new ZeroOrMore( visit(node.expression, context), { rep, min, max } diff --git a/package.json b/package.json index a7553b5..402a1b4 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,11 @@ }, "devDependencies": { "@peggyjs/eslint-config": "^3.2.4", - "@peggyjs/eslint-plugin": "2.0.2", - "@types/node": "^20.11.21", + "@peggyjs/eslint-plugin": "2.1.0", + "@types/node": "^20.11.24", "@typescript-eslint/eslint-plugin": "^7.1.0", "@typescript-eslint/parser": "^7.1.0", - "ava": "^6.1.1", + "ava": "^6.1.2", "c8": "^9.1.0", "chokidar-cli": "^3.0.0", "eslint": "^8.57.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 489df10..655e3bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,11 +17,11 @@ devDependencies: specifier: ^3.2.4 version: 3.2.4(@typescript-eslint/eslint-plugin@7.1.0)(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3) '@peggyjs/eslint-plugin': - specifier: 2.0.2 - version: 2.0.2(@peggyjs/eslint-parser@2.0.6)(eslint@8.57.0) + specifier: 2.1.0 + version: 2.1.0(@peggyjs/eslint-parser@2.0.6)(eslint@8.57.0) '@types/node': - specifier: ^20.11.21 - version: 20.11.21 + specifier: ^20.11.24 + version: 20.11.24 '@typescript-eslint/eslint-plugin': specifier: ^7.1.0 version: 7.1.0(@typescript-eslint/parser@7.1.0)(eslint@8.57.0)(typescript@5.3.3) @@ -29,8 +29,8 @@ devDependencies: specifier: ^7.1.0 version: 7.1.0(eslint@8.57.0)(typescript@5.3.3) ava: - specifier: ^6.1.1 - version: 6.1.1 + specifier: ^6.1.2 + version: 6.1.2 c8: specifier: ^9.1.0 version: 9.1.0 @@ -206,16 +206,15 @@ packages: engines: {node: '>=18'} dev: true - /@peggyjs/eslint-plugin@2.0.2(@peggyjs/eslint-parser@2.0.6)(eslint@8.57.0): - resolution: {integrity: sha512-UsgfNY5JUe4bDE6yonabrOS9PFD8aSbITNKw5YOpvWUidE+Cq6MaA3NmKbWzx9L6pPy7415Wz8MndEBMLCsx2Q==} + /@peggyjs/eslint-plugin@2.1.0(@peggyjs/eslint-parser@2.0.6)(eslint@8.57.0): + resolution: {integrity: sha512-wJ4VV5jgTZJBq1aLGiqqeFAOLHq9I0VUwXqMf5ecO0VVis2IWZBqv0xvQh9hByzo/lXvWL0FAPownncGmN59XQ==} engines: {node: '>=20.8'} peerDependencies: '@peggyjs/eslint-parser': ^2.0.6 eslint: '>=8.57.0' dependencies: '@peggyjs/eslint-parser': 2.0.6 - '@peggyjs/from-mem': 1.2.1 - enhanced-resolve: 5.15.0 + enhanced-resolve: 5.15.1 eslint: 8.57.0 dev: true @@ -224,6 +223,7 @@ packages: engines: {node: '>=18'} dependencies: semver: 7.6.0 + dev: false /@rollup/pluginutils@4.2.1: resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==} @@ -329,8 +329,8 @@ packages: resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} dev: true - /@types/node@20.11.21: - resolution: {integrity: sha512-/ySDLGscFPNasfqStUuWWPfL78jompfIoVzLJPVVAHBh6rpG68+pI2Gk+fNLeI8/f1yPYL4s46EleVIc20F1Ow==} + /@types/node@20.11.24: + resolution: {integrity: sha512-Kza43ewS3xoLgCEpQrsT+xRo/EJej1y0kVYGiLFE1NEODXGzTfwiC6tXTLMQskn1X4/Rjlh0MQUvx9W+L9long==} dependencies: undici-types: 5.26.5 dev: true @@ -696,8 +696,8 @@ packages: resolution: {integrity: sha512-tLRNUXati5MFePdAk8dw7Qt7DpxPB60ofAgn8WRhW6a2rcimZnYBP9oxHiv0OHy+Wz7kPMG+t4LGdt31+4EmGg==} dev: true - /ava@6.1.1: - resolution: {integrity: sha512-A+DG0Ag0e5zvt262Ze0pG5QH7EBmhn+DB9uK7WkUtJVAtGjZFeKTpUOKx339DMGn53+FB24pCJC5klX2WU4VOw==} + /ava@6.1.2: + resolution: {integrity: sha512-WcpxJ8yZ7mk9ABTinD0IAjcemovSeVGjuuwZx0JS9johREWFeLTl8UP6wd7l6nmnrWqkKZdwaD71a/ocH4qPKw==} engines: {node: ^18.18 || ^20.8 || ^21} hasBin: true peerDependencies: @@ -1069,8 +1069,8 @@ packages: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} dev: true - /enhanced-resolve@5.15.0: - resolution: {integrity: sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg==} + /enhanced-resolve@5.15.1: + resolution: {integrity: sha512-3d3JRbwsCLJsYgvb6NuWEG44jjPSOMuS73L/6+7BZuoKm3W+qXnSoIYVHi8dG7Qcg4inAY4jbzkZ7MnskePeDg==} engines: {node: '>=10.13.0'} dependencies: graceful-fs: 4.2.11 diff --git a/test/index.test.js b/test/index.test.js index 4eb7dc1..2b3c4d4 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -37,3 +37,9 @@ test("actions", t => { test("wrapCount", t => { t.is(wrapCount(null), null); }); + +test("it handles single-value repeats", t => { + const diag = tracks({ text: "x = 'x'|2|" }); + t.snapshot(diag.toStandalone()); +}); + diff --git a/test/snapshots/index.test.js.md b/test/snapshots/index.test.js.md new file mode 100644 index 0000000..7adf53a --- /dev/null +++ b/test/snapshots/index.test.js.md @@ -0,0 +1,143 @@ +# Snapshot report for `test/index.test.js` + +The actual snapshot is saved in `index.test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## it handles single-value repeats + +> Snapshot 1 + + `␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ..␊ + ␊ + ␊ + 2␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + "x"␊ + ␊ + ␊ + ␊ + ␊ + ␊ + repeat␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + x␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ␊ + ` diff --git a/test/snapshots/index.test.js.snap b/test/snapshots/index.test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..9a325c017410f233211dc348e28d5f63e647b22d GIT binary patch literal 1111 zcmV-d1gQH#RzVaVNrBohER*+f?mdSOe|p?@l%=-MSgqr_cu4+-I&)`-`;%x^|Z~%W}2$P&Dztj?w*3;;{B0fWR66 zJANp5sbl3zRm(8k@Atue5(t@v7(y88Y>mnCz*+e;WQZ1vMQCTe&Fv}!N|LgE6tY-* z_K_1s?{vB#dgBZl_#YIJ%8XP*SBCh@t|sN3qr%mY#z zYBWF|-FE{eGf@1kIGDI5U>oPpxnRkE!`O8sx^Ku(ZQibjJAX214WnjwsBIsfSk(bD zgJ3$%5i-S&@qp$A)pXj=p)+?9LpL}Iy~}l&#`6oIs6%M< zg@nE@>3jK3NIC#>8V}-}H8_VUNkmc5QUSf9G8!t zuyz;(XQu9vNVps50vgACvH6a2_#)%uN;44=(oKRdNiDYf7aEi~yn^Eot4&jV)$d-4 zQ92Zr1uF>$oaslxuWHbqKJJvz3cVPZK1mYc$%%-|HZzUdqQv-0lott}37y6Pc7YH? z-o`t4T@ptn(UxlrM^+Wa{kgLsW4ETFYZ;1X=P zj_8IS8RttNvn{!U_x62`W;^DhJ&ICkH^EbYrquxyq7-#S66%5&OP`cUZm<Tdf{h(Dr_|{=EES`cqybT*ayWYQqAVWC9@E$=!IlNGAA_nJE zsS|q%bia=6z z>pXu