diff --git a/bin/build.sh b/bin/build.sh index c3d6cfd..6324d85 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -36,7 +36,7 @@ for t in lib/*.d.ts; do sed -i '.tmp' -e 's/split(text: string): any;/split(text: string): string[];/g' $t sed -i '.tmp' -e 's/splitn(text: string, limit: number): any;/splitn(text: string, limit: number): string[];/g' $t sed -i '.tmp' -e 's/syntax(): any;/syntax(): Hir;/g' $t - sed -i '.tmp' -e 's/captureNames(): any\[\];/captureNames(): string[];/g' $t + sed -i '.tmp' -e 's/captureNames(): any\[\];/captureNames(): (string | null)[];/g' $t sed -i '.tmp' -e 's/captures(text: string): any;/captures(text: string): Captures | undefined;/g' $t sed -i '.tmp' -e 's/capturesAll(text: string): any;/capturesAll(text: string): Captures[];/g' $t sed -i '.tmp' -e 's/matches(text: string): any\[\];/matches(text: string): number[];/g' $t @@ -48,7 +48,7 @@ for t in lib/*.d.ts; do sed -i -e 's/split(text: string): any;/split(text: string): string[];/g' $t sed -i -e 's/splitn(text: string, limit: number): any;/splitn(text: string, limit: number): string[];/g' $t sed -i -e 's/syntax(): any;/syntax(): Hir;/g' $t - sed -i -e 's/captureNames(): any\[\];/captureNames(): string[];/g' $t + sed -i -e 's/captureNames(): any\[\];/captureNames(): (string | null)[];/g' $t sed -i -e 's/captures(text: string): any;/captures(text: string): Captures | undefined;/g' $t sed -i -e 's/capturesAll(text: string): any;/capturesAll(text: string): Captures[];/g' $t sed -i -e 's/matches(text: string): any\[\];/matches(text: string): number[];/g' $t diff --git a/src/rregex.rs b/src/rregex.rs index ab0d782..a6916f0 100644 --- a/src/rregex.rs +++ b/src/rregex.rs @@ -152,7 +152,10 @@ impl RRegex { pub fn capture_names(&self) -> Vec { self.regex .capture_names() - .filter_map(|item| item.map(JsValue::from)) + .map(|item| match item { + Some(name) => JsValue::from(name), + None => JsValue::NULL, + }) .collect() } diff --git a/test/rregex.test.ts b/test/rregex.test.ts index 005d9d3..a750899 100644 --- a/test/rregex.test.ts +++ b/test/rregex.test.ts @@ -121,6 +121,7 @@ describe(`RRegex`, () => { test(`captureNames`, () => { const regex = new RRegex('(?P\\d{4})-(?P\\d{2})-(?P\\d{2})') expect(regex.captureNames()).toEqual([ + null, "y", "m", "d",