microts: negating a negative module constant emits `--` and breaks the guest build of a compiled model
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu trong microts/compiler/aot-model-js.ts, tại các nhánh rawExpr case "literal" và case "unary", nơi toán tử được nối vào toán hạng đã có dấu; phía Rust có cùng hình dạng trong microts/compiler/aot-model-codegen.ts quanh các dòng 526-529. Tái hiện bằng hai lệnh tools/pocket.ts compile và kiểm tra gen/app_model.rs để xem đầu ra --24f64. Hoàn tất nghĩa là bản build guest phân tích cú pháp, bản build AOT không phát ra cảnh báo double_negations, và flip() trả về 24.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- TypeScript
- Star
- 1.6k
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pocket-stack/pocketjs
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pocket-stack/pocketjs#725 ·
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
pocket-stack/pocketjs#724 ·
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
pocket-stack/pocketjs#728 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
pocket-stack/pocketjs#727 ·
-
enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
pocket-stack/pocketjs#726 ·
Tất cả issue của pocket-stack/pocketjs
Issue tương tự
-
kind:defect
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mux-labs/mux-frontend#1240 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: agents-mcp priority: normal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Wait for the IDS correction dialog to settle in the stale-audit testCó thể đã có người làm @louistrue đã nhận hôm nay. Đang mởready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Hono path parameters with a regex pattern keep the pattern in the OpenAPI pathCó thể đã có người làm @0z5a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/chanfana#400 ·
Maintainer thường phản hồi trong vòng 1 ngày