Skip to content

fix(parse): ignore undefined options so defaults are preserved#1241

Open
abhu85 wants to merge 1 commit into
C2FO:mainfrom
abhu85:fix/parser-options-undefined-delimiter
Open

fix(parse): ignore undefined options so defaults are preserved#1241
abhu85 wants to merge 1 commit into
C2FO:mainfrom
abhu85:fix/parser-options-undefined-delimiter

Conversation

@abhu85

@abhu85 abhu85 commented Jun 22, 2026

Copy link
Copy Markdown

Problem

Closes #1160.

ParserOptions declares optional fields with defaults, then does Object.assign(this, opts). Because Object.assign copies enumerable undefined values, explicitly passing an optional option as undefined overwrites its default. For delimiter this then throws:

new ParserOptions({ delimiter: undefined });
// TypeError: Cannot read properties of undefined (reading 'length')
//   at new ParserOptions (.../ParserOptions.ts:73)  // this.delimiter.length

The options type marks every field optional (delimiter?: string), so passing undefined should be equivalent to omitting it — i.e. fall back to the default , — not blow up. This bites anyone forwarding options that themselves default to undefined.

Fix

Filter out undefined entries before assigning, so defaults declared on the class are preserved:

const definedOpts = Object.entries(opts || {}).filter(([, value]) => {
    return value !== undefined;
});
Object.assign(this, Object.fromEntries(definedOpts));

This is general (any explicitly-undefined option now falls back to its default) and changes nothing for callers passing real values.

Test plan

  • Added ParserOptions test: { delimiter: undefined } resolves to the default ,.
  • New test fails on main with the reported TypeError; passes with the fix.
  • jest packages/parse373 passing, no regressions.
  • eslint --max-warnings 0 and prettier --check clean on the changed files.

`new ParserOptions({ delimiter: undefined })` threw `TypeError: Cannot
read properties of undefined (reading 'length')` because `Object.assign`
copied the explicit `undefined` over the default `,`. Optional options
are typed `?`, so passing `undefined` should fall back to the default.
Filter out `undefined` entries before assigning.
@c2fo-cibot c2fo-cibot Bot added the size/S Denotes a PR that changes 10-29 lines label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ParserOptions throws an error with undefined delimiter

1 participant