Skip to content

Commit

Permalink
fix: skip void expressions in statement parselet
Browse files Browse the repository at this point in the history
  • Loading branch information
lavyyy committed Oct 1, 2024
1 parent cf0c469 commit c6e456d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @lunarclient/molang

## 1.0.9

### Patch Changes

- fix: skip void expressions in statement parselet

## 1.0.8

### Patch Changes
Expand Down
10 changes: 10 additions & 0 deletions __tests__/inferReturn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ test('Infer return at end of statement with function', () => {

expect(molang.execute(statement)).toBe(100)
})

test('Infer return at end of statement with negative variable', () => {
const statement = `v.y = 10;`

expect(molang.execute(statement)).toBe(0)

const statement2 = `-v.y;`

expect(molang.execute(statement2)).toBe(-10)
})
4 changes: 4 additions & 0 deletions lib/parser/parselets/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class StatementParselet implements IInfixParselet {
if (!parser.match('CURLY_RIGHT', false)) {
do {
let expr = parser.parseExpression(this.precedence)

// skip void expressions, this is so the optimizer doesnt register them as they're unnecessary and causes them to be infered as a returnable statement
if (expr.type === 'VoidExpression') continue

if (parser.config.useOptimizer) {
if (expr.isStatic()) {
if (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lunarclient/molang",
"version": "1.0.8",
"version": "1.0.9",
"description": "Lunar Client's fork of bridge-core's molang parser",
"main": "lib/main.ts",
"files": [
Expand Down

0 comments on commit c6e456d

Please sign in to comment.