Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit f8966ac

Browse files
author
g. nicholas d'andrea
committed
Prevent empty index access ([])
1 parent b25bbd7 commit f8966ac

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Diff for: packages/parse-mapping-lookup/src/grammar.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const definitions: Definitions<Forms> = {
4141

4242
value: ({ construct }) =>
4343
noCharOf("]").pipe(
44-
many(),
45-
map(characters => construct({ contents: characters.join("") }))
44+
then(noCharOf("]").pipe(many())),
45+
map(([first, rest]) => construct({ contents: [first, ...rest].join("") }))
4646
),
4747

4848
indexAccess: ({ construct, tie }) =>

Diff for: packages/parse-mapping-lookup/src/parser.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ const testCases = [
8686
position: 2
8787
}
8888
},
89+
{
90+
expression: `m[1].s[]`,
91+
trace: {
92+
position: 7
93+
}
94+
},
8995
{
9096
expression: `m[hex"deadbeef"]`,
9197
value: expression({

0 commit comments

Comments
 (0)