GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix nested unary minus printing as a Lua comment by bardrop · Pull Request #1736 · TypeScriptToLua/TypeScriptToLua

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #1733

printUnaryExpression printed the operator and the operand next to each other, so a negation whose operand also starts with - came out as --, which Lua reads as the start of a comment:

let a = 5;
return -(-a);
local a = 5
return --a   -- returns nothing

The same thing happens with -(-5), -(-(-a)), and with a const enum member that has a negative value (const enum E { A = -1 }; -E.A printed --1, because the inlined value is a negative numeric literal).

The printer now adds a space when the operator is - and the printed operand starts with -, so these print as - -a, - - -a, - -1. Other unary operators and operands are printed as before, so no snapshots change.

Tests: added functional tests in test/unit/expressions.spec.ts for -(-a), - -a, -(-(-a)), -(-a) * 2, -(-5), and the const enum case. All 6 fail before the change and pass after. npm test (lint + full jest run) passes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bardrop
fix nested unary minus printing as a Lua comment
7e2e53a
-(-a) was printed as --a, which Lua reads as a line comment.
Add a space when a negation's operand starts with a minus sign.

Fixes TypeScriptToLua#1733
@Perryvw
Perryvw merged commit 88d0001 into TypeScriptToLua:master Nov 12, 2026
5 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Nested unary negation -(-a) emits --a, which Lua parses as a comment

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@bardrop @Perryvw
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.