Skip to content

Commit f00abc6

Browse files
Change ParameterType.regexps type (#133)
* Change ParameterType.expression type * fix typo * Export the new types
1 parent f5e2391 commit f00abc6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
- [JavaScript] The `ParameterType` constructor's `regexps` parameter has a new type: `type Regexps = StringOrRegExp | readonly StringOrRegExp[]; type StringOrRegExp = string | RegExp`.
12+
1013
## [15.2.0] - 2022-05-24
1114
### Added
1215
- [JavaScript] Add `ParameterInfo` ([#124](https://github.com/cucumber/cucumber-expressions/pull/124))

javascript/src/ParameterType.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ interface Constructor<T> extends Function {
1010

1111
type Factory<T> = (...args: unknown[]) => T
1212

13+
export type Regexps = StringOrRegExp | readonly StringOrRegExp[]
14+
export type StringOrRegExp = string | RegExp
15+
1316
export default class ParameterType<T> {
1417
private transformFn: (...match: readonly string[]) => T | PromiseLike<T>
1518

@@ -40,16 +43,16 @@ export default class ParameterType<T> {
4043

4144
/**
4245
* @param name {String} the name of the type
43-
* @param regexps {Array.<RegExp>,RegExp,Array.<String>,String} that matches the type
46+
* @param regexps {Array.<RegExp | String>,RegExp,String} that matche the type
4447
* @param type {Function} the prototype (constructor) of the type. May be null.
4548
* @param transform {Function} function transforming string to another type. May be null.
4649
* @param useForSnippets {boolean} true if this should be used for snippets. Defaults to true.
4750
* @param preferForRegexpMatch {boolean} true if this is a preferential type. Defaults to false.
4851
*/
4952
constructor(
5053
public readonly name: string | undefined,
51-
regexps: readonly RegExp[] | readonly string[] | RegExp | string,
52-
public readonly type: Constructor<T> | Factory<T> | string | null,
54+
regexps: Regexps,
55+
public readonly type: Constructor<T> | Factory<T> | null,
5356
transform: (...match: string[]) => T | PromiseLike<T>,
5457
public readonly useForSnippets: boolean,
5558
public readonly preferForRegexpMatch: boolean
@@ -77,11 +80,8 @@ export default class ParameterType<T> {
7780
}
7881
}
7982

80-
type StringOrRegexp = string | RegExp
81-
82-
function stringArray(regexps: readonly StringOrRegexp[] | StringOrRegexp): string[] {
83-
// @ts-ignore
84-
const array: StringOrRegexp[] = Array.isArray(regexps) ? regexps : [regexps]
83+
function stringArray(regexps: Regexps): string[] {
84+
const array: StringOrRegExp[] = Array.isArray(regexps) ? regexps : [regexps]
8585
return array.map((r) => (r instanceof RegExp ? regexpSource(r) : r))
8686
}
8787

0 commit comments

Comments
 (0)