josdejong / josdejong/mathjs

Parsing unit fails with parentheses and exponents; documentation unclear

Open
#2,771 15 comments 0 reactions 0 assignees View on GitHub
bug category:units documentation
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

When trying to parse the unit `lbf/(mile/h)^2` a SyntaxError is thrown.

`SyntaxError: Unexpected "^" in "lbf/(mile/h)^2" at index 12`

This is unexpected since the unit should be valid and math.evaluate() can parse it without issue (see interactive prompt on https://mathjs.org/)

Narrowing down the issue it seems to be related to the `^` after the brackets.

**To Reproduce**

These tests reproduce the issue.

**The original unit**
```js
it('should convert a unit with squared brackets (original)', function () {
const u = Unit.parse('lbf/(mile/h)^2')
assert.notEqual(u, null)
})
```

**Only squared brackets:**

```js
it('should convert a unit with squared brackets (reduced)', function () {
const u = Unit.parse('(h)^2')
assert.notEqual(u, null)
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.