Skip to content

Commit

Permalink
Don't use empty obj as default arg value
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Nov 16, 2024
1 parent a393651 commit 238fdb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ function genRecursion({ref}, state) {
Given a `CharacterClassRange` node, returns an array of chars that are a case variant of a char in
the range, and aren't already in the range.
*/
function getCasesOutsideCharClassRange(node, {firstOnly} = {}) {
function getCasesOutsideCharClassRange(node, options) {
const firstOnly = !!options?.firstOnly;
const min = node.min.value;
const max = node.max.value;
const found = [];
Expand Down
18 changes: 13 additions & 5 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ function createAssertionFromToken({type, kind, negate}) {
return node;
}

function createBackreference(ref, {orphan} = {}) {
function createBackreference(ref, options) {
const orphan = !!options?.orphan;
return {
type: AstTypes.Backreference,
...(orphan && {orphan}),
Expand Down Expand Up @@ -556,7 +557,9 @@ function createFlags({ignoreCase, dotAll, extended}) {
};
}

function createGroup({atomic, flags} = {}) {
function createGroup(options) {
const atomic = options?.atomic;
const flags = options?.flags;
return {
type: AstTypes.Group,
...(atomic && {atomic}),
Expand All @@ -565,11 +568,16 @@ function createGroup({atomic, flags} = {}) {
};
}

function createLookaround({behind = false, negate = false} = {}) {
function createLookaround(options) {
const opts = {
behind: false,
negate: false,
...options,
};
return {
type: AstTypes.Assertion,
kind: behind ? AstAssertionKinds.lookbehind : AstAssertionKinds.lookahead,
negate,
kind: opts.behind ? AstAssertionKinds.lookbehind : AstAssertionKinds.lookahead,
negate: opts.negate,
alternatives: [createAlternative()],
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,8 @@ function isValidGroupNameJs(name) {
}

// Returns a single node, either the given node or all nodes wrapped in a noncapturing group
function parseFragment(pattern, {skipPropertyNameValidation} = {}) {
function parseFragment(pattern, options) {
const skipPropertyNameValidation = !!options?.skipPropertyNameValidation;
const ast = parse(tokenize(pattern), {skipPropertyNameValidation});
const alts = ast.pattern.alternatives;
if (alts.length > 1 || alts[0].elements.length > 1) {
Expand Down

0 comments on commit 238fdb9

Please sign in to comment.