Skip to content

Commit c01299d

Browse files
authored
fix!: .or() chaining function now joins args with | (#541)
1 parent c4b6841 commit c01299d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/core/internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function createInput<
154154
and: Object.assign((...inputs: InputSource[]) => createInput(`${s}${exactly(...inputs)}`), {
155155
referenceTo: (groupName: string) => createInput(`${s}\\k<${groupName}>`),
156156
}),
157-
or: (...inputs) => createInput(`(?:${s}|${exactly(...inputs)})`),
157+
or: (...inputs) => createInput(`(?:${s}|${inputs.map(v => exactly(v)).join('|')})`),
158158
after: (...input) => createInput(`(?<=${exactly(...input)})${s}`),
159159
before: (...input) => createInput(`${s}(?=${exactly(...input)})`),
160160
notAfter: (...input) => createInput(`(?<!${exactly(...input)})${s}`),

test/inputs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describe('chained inputs', () => {
255255
const multi = multichar.or('foo', input.groupedAs('groupName'), exactly('bar').or(test))
256256
const regexp2 = new RegExp(multi as any)
257257
expect(regexp2).toMatchInlineSnapshot(
258-
'/\\(\\?:ab\\|foo\\(\\?<groupName>\\\\\\?\\)\\(\\?:bar\\|test\\\\\\.js\\)\\)/',
258+
'/\\(\\?:ab\\|foo\\|\\(\\?<groupName>\\\\\\?\\)\\|\\(\\?:bar\\|test\\\\\\.js\\)\\)/',
259259
)
260260
expectTypeOf(
261261
extractRegExp(multi),

0 commit comments

Comments
 (0)