Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #3422 parse dot operators after an implicit multiplication with symbol E #3425

Merged
merged 1 commit into from
Mar 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: #3422 parse dot operators after an implicit multiplication with …
…symbol E
josdejong committed Mar 19, 2025
commit 35cb34a154a2de788a260cd4455c03928d888d6e
2 changes: 1 addition & 1 deletion src/expression/parse.js
Original file line number Diff line number Diff line change
@@ -420,7 +420,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({
if (parse.isDecimalMark(currentCharacter(state), nextCharacter(state))) {
throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"')
}
} else if (nextCharacter(state) === '.') {
} else if (parse.isDecimalMark(nextCharacter(state), state.expression.charAt(state.index + 2))) {
next(state)
throw createSyntaxError(state, 'Digit expected, got "' + currentCharacter(state) + '"')
}
15 changes: 15 additions & 0 deletions test/unit-tests/expression/parse.test.js
Original file line number Diff line number Diff line change
@@ -290,6 +290,21 @@ describe('parse', function () {
approxEqual(parseAndEval('2e'), 2 * Math.E)
})

it('should parse dot operators after a value', function () {
approxEqual(parseAndEval('2.*3'), 6)
approxEqual(parseAndEval('2./3'), 2 / 3)
approxEqual(parseAndEval('2.^3'), 2 ** 3)
})

it('should parse dot operators after an implicit multiplication with symbol E', function () {
approxEqual(parseAndEval('2E.*3'), 2 * Math.E * 3)
approxEqual(parseAndEval('2E./3'), 2 * Math.E / 3)
approxEqual(parseAndEval('2E.^3'), 2 * Math.E ** 3)
approxEqual(parseAndEval('2e.*3'), 2 * Math.E * 3)
approxEqual(parseAndEval('2e./3'), 2 * Math.E / 3)
approxEqual(parseAndEval('2e.^3'), 2 * Math.E ** 3)
})

it('should throw an error with invalid numbers', function () {
assert.throws(function () { parseAndEval('.') }, /Value expected/)
assert.throws(function () { parseAndEval('3.2.2') }, SyntaxError)