microts: negating a negative module constant emits `--` and breaks the guest build of a compiled model
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust, typescript
- Domain
- compilers
Research direction
Start in microts/compiler/aot-model-js.ts, at the rawExpr case "literal" and case "unary" branches, where the operator is concatenated onto the already-signed operand; the Rust side has the same shape in microts/compiler/aot-model-codegen.ts around lines 526-529. Reproduce with the two tools/pocket.ts compile commands and inspect gen/app_model.rs for the --24f64 output. Done means the guest build parses, the AOT build emits no double_negations warning, and flip() yields 24.
Written by the indexing model from the issue text.
Description
Version
PocketJS v0.17.0 (83c6cac9, current main). macOS 27.2 arm64, Bun 1.4.2, Rust 1.98.1.
Repro
pocket.host.json, pocket.host.config.ts (aot: true, model: "compiled") and main.tsx as in #720.
// app.ts
import { createSignal } from "solid-js";
import type { f64 } from "@pocketjs/framework/solid/std";
const TILT: f64 = -24;
export const [value, setValue] = createSignal<f64>(0);
export function flip(): void {
setValue(-TILT);
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import { flip, value } from "./app";
export default function App() {
return (
<View class="w-full h-full p-4 bg-slate-100" focusable onPress={() => flip()}>
<Text class="text-lg text-slate-900">{value()}</Text>
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
Actual
The guest build stops:
SyntaxError: app.ts: Invalid left-hand side in prefix operation. (9:55)
code: "BABEL_PARSE_ERROR"
The AOT build succeeds; gen/app_model.rs contains let write_0 = --24f64;, which rustc compiles as a double negation and reports:
warning: use of a double negation
= note: `#[warn(double_negations)]` on by default
| Constant and use | Guest build |
|---|---|
const TILT: f64 = -24; and -TILT |
Invalid left-hand side in prefix operation |
const TILT: f64 = -24; and -(TILT) |
same error |
const TILT = -24; and -TILT |
same error |
const TILT: f64 = 24; and -TILT |
builds |
const TILT: f64 = -24; and 1 - TILT |
builds |
Expected
Both builds compile, flip sets the value to 24, and the generated Rust has no warning.
Cause
The constant is inlined as a literal, and a negative literal is written with its sign: rawExpr case "literal" (microts/compiler/aot-model-js.ts:64) returns JSON.stringify(-24), that is -24. case "unary" (aot-model-js.ts:73) concatenates the operator and the operand without a separator, (${e.operator}${expr(e.operand)}), giving (--24), a prefix decrement of a literal. A -0 literal is written as -0 and meets the same path. The Rust generator builds a unary node over the same literal (microts/compiler/aot-model-codegen.ts:526–529), which prints as --24f64.
A space or parentheses around the operand ((- -24), -(-24f64)) fixes both outputs.
Workaround
Subtract from zero: setValue(0 - TILT).
- Dominant language
- TypeScript
- Stars
- 1.6k
- Forks
- 88
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pocket-stack/pocketjs
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pocket-stack/pocketjs#725 ·
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 85/100
pocket-stack/pocketjs#724 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 62/100
pocket-stack/pocketjs#728 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
pocket-stack/pocketjs#727 ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 52/100
pocket-stack/pocketjs#726 ·
All issues in pocket-stack/pocketjs
Similar issues
-
dream report: normalizeMutation discards ok/status, consumers can only string-match the summaryOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
thecodacus/understory#61 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Termix-SSH/Plugin-Hosts-Config#14 · 1 comment ·
Maintainers usually reply within 4 days
-
ai-generated priority: p2 size: s type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
JonathanTSilva/jts-website#92 ·
Maintainers usually reply within 1 day
-
Toast announcer reads a doubled period when a toast's title ends in punctuationPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel-labs/ui#999 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ehmpathy/rhachet-roles-ehmpathy#1443 ·
Maintainers usually reply within 1 day