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

[BUG] Expression parser fails with operators other than +/-* like roundTo() #9

Open
freemansoft opened this issue Oct 11, 2023 · 4 comments

Comments

@freemansoft
Copy link
Collaborator

freemansoft commented Oct 11, 2023

ℹ️ Info

The expression parser does not handle some function calls or power operators.

Version: 0.2.0-alpha current head of the main branch

💬 Description

The expression parser for math operations will return incorrect results for math functions on operations.

solved to `NaN` for {"value": roundTo({semantic.fontSize.base} / {semantic.fontSize.scale}, 0), "type": "fontSizes", "path": ".semantic.fontSize", "name": "sm", "variableName": "semanticFontSizeSm" }

solved to `0.0` for {"value": roundTo({semantic.fontSize.base} * {semantic.fontSize.scale}^7, 0), "type": "fontSizes", "path": ".semantic.fontSize", "name": "6xl", "variableName": "semanticFontSize6xl" }

where base and scale have values though the values really don't matter

  "fontSize"
      "base": {
        "type": "fontSizes",
        "value": "16"
      },
      "scale": {
        "type": "fontSizes",
        "value": "1.2"
      },

📜 tokens file you tried to import

Example 2 in PR #4 demonstrates this. There extra logging in that PR

@mark-nicepants
Copy link
Owner

Can this be closed now that #4 is merged?

@freemansoft
Copy link
Collaborator Author

I'm pretty sure that function-based math operations are not implemented. The example in the PR had the roundTo(x,y) and ^ operations removed from the JSON.

@mark-nicepants
Copy link
Owner

Aah ok, I understand it better now. It's not a bug, but a missing feature. What type of token export generated these?

@freemansoft
Copy link
Collaborator Author

The current code fails silently I thin returning null for any clause that contains a function. This means you get a NaN if there is a division operator or a null if there is one of the other operators. The code should abort or log errors or something if it runs across an unsupported function.

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

No branches or pull requests

2 participants