Skip to content

Conversation

@AnslemHack
Copy link

@AnslemHack AnslemHack commented Oct 31, 2025

Fixes #3585 where mathjs incorrectly accepts ?.. (double-dot after optional chaining), which is invalid in JavaScript.

   1. Don't ignore ?. between expressions that can be implicitly multiplied
   2. Allow an undefined function in optional chaining function call,
      by whatever means that function was generated.
   3. Disallow optional chaining assignment.

   Adds tests for all three.
@gwhitney
Copy link
Collaborator

gwhitney commented Nov 1, 2025

Since @AnslemHack had fixed one problem recently found, it was most convenient to use this PR as a base for fixes to the three additional problems with optional chaining that I found while reviewing this PR. (I hope nobody involved minds -- if you want me to revert and file a separate PR I would be happy to instead.)

Anyhow, now this PR:
Resolves #3580, #3586, #3587.

Funny how code (e.g. look in parseAccessors in src/expressions/parse.js) can actually become simpler by fixing bugs.

Anyhow, now that I've changed a bunch in parseAccessors, another maintainer (likely @josdejong, especially since he was planning to anyway) should review this, not me any further.

@gwhitney gwhitney changed the title reject double dot after optional chaining operator reject double dot after optional chaining operator, etc. Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants