npm-package classes: this.m() dispatch ignores own-property method shadows (silently breaks rxjs operators)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Start by running the shadowlib/main.ts reproduction through scriptc’s npm-package compilation path and compare the native output with Node.js. Locate the compiler logic that resolves statically typed this.m() calls for imported classes and add a regression test covering own-property method shadows. Done means the native binary prints OWN hello, while existing npm-package and TypeScript compilation behavior remains intact.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
In npm-package classes compiled by scriptc, a method call this.m() inside a class method dispatches statically to the prototype method and ignores an own-property shadow installed on the instance (e.g. this.m = fn in a constructor). Dynamic reads of the same property observe the shadow correctly, so the write lands on the instance; only the statically resolved call is wrong. Node.js (and every JS engine) dispatches through the instance, so the own property wins.
This is a silent semantic divergence: no diagnostic is emitted, the program compiles cleanly, and method-style callbacks are silently replaced by the prototype implementation at runtime.
Real-world impact: rxjs operators become pass-throughs
This bug breaks rxjs ([email protected], dist/esm) completely but silently. OperatorSubscriber — the subscriber every operator (map, tap, filter, catchError, …) uses — installs its handlers as own properties in its constructor:
// rxjs dist/esm/internal/Subscriber.js (simplified)
export class OperatorSubscriber extends Subscriber {
constructor(destination, onNext, onComplete, onError) {
super(destination);
this._next = onNext ? v => { onNext(v) } : super._next;
// ...
}
}
Subscriber.prototype.next then does this._next(value). Under scriptc the own-property arrow is never invoked — the prototype _next runs instead — so every rxjs operator silently passes values through untransformed, tap side effects never fire, and catchError never intercepts. complete() propagation still works, which makes the failure look like "the stream just produces nothing useful" rather than an obvious crash. In a real program (npkill compiled fully static with zero Node islands) this meant scans "completed" instantly with zero results.
Minimal reproduction
node_modules/shadowlib/package.json:
{
"name": "shadowlib",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"exports": { ".": "./index.js" },
"types": "./index.d.ts"
}
node_modules/shadowlib/index.js:
class Base {
next(v) { this._next(v); }
_next(v) { console.log('PROTO', v); }
}
class Shadowed extends Base {
constructor(onNext) {
super();
if (onNext) { onNext.tag = 'own'; this._next = onNext; }
}
}
export { Base, Shadowed };
node_modules/shadowlib/index.d.ts:
export class Base {
next(v: string): void;
_next(v: string): void;
}
export class Shadowed extends Base {
constructor(onNext: ((v: string) => void) | undefined);
}
main.ts:
import { Shadowed } from 'shadowlib';
const s = new Shadowed((v: string) => console.log('OWN', v));
console.log('readback tag:', (s as any)._next.tag);
s.next('hello');
Expected (Node.js output)
readback tag: own
OWN hello
Actual (scriptc native binary)
readback tag: own
PROTO hello
Key observation: readback tag: own proves the shadow is installed on the instance and dynamic property reads find it. Only the this._next(v) call inside Base.next ignores it — so the write is fine, the dynamic read path is fine, and the statically-resolved method call is the divergence.
Notes
- The same pattern compiled as part of the program's own TypeScript sources does not reproduce the bug in simple probes (own-property shadows are honored); the divergence appears when the class comes from an npm package (
dist/esmunchecked JavaScript with a sibling.d.ts). - Plain
this._next.call(this, v)does not work around it (still statically resolved). A computed-key callthis['_next'].call(this, v)does observe the own property — this is the workaround currently carried as a patch on rxjs in npkill. - A possibly related compiler crash: giving
OperatorSubscriberextra expando fields (e.g. storing handlers as_nextImplinstead) triggersSC9001 duplicate function '%dyn.class.instanceof:…Subscription'— happy to file that separately if useful.
Environment
- scriptc: local build of
vercel-labs/scriptcmaster (post-0.4.17, incl. per-package export conditions) - target: macOS arm64 native executable
- rxjs 7.8.2, compiled statically via
scriptc.packages.rxjs.conditions = ["es2015"]
- Ngôn ngữ chính
- TypeScript
- Star
- 6.7k
- Fork
- 229
- Merge trung bình
- 14 giờ 29 phút
- Pull request đã merge (30 ngày)
- 787
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 vercel-labs/scriptc
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
vercel-labs/scriptc#4865 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
vercel-labs/scriptc#4864 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows ARM64 as a cross-compile targetCó thể đã có người làm @hum-n đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
vercel-labs/scriptc#4858 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
post-merge-bisect-unresolved
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 43/100
vercel-labs/scriptc#4791 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
post-merge-bisect-unconfirmed
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
vercel-labs/scriptc#4755 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của vercel-labs/scriptc
Issue tương tự
-
bug data-types
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
ClickHouse/clickhouse-js#1293 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: middleware enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
agent/quality testing
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/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 92/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
juspay/agent-distro#203 ·
Maintainer thường phản hồi trong vòng 1 ngày