Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/expression/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '"')
}
Expand Down
15 changes: 15 additions & 0 deletions test/unit-tests/expression/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down