mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-25 06:24:27 +08:00
A Date field reads through the class's checked-dynamic property view and
writes its toJSON text, so json-class-fields.ts compiled and matched Node
while the diagnostics test expected a refusal. The Date cases move to
6000-json-stringify-class-instances.ts.
RegExp and Promise fields read through the view but the runtime JSON
traversal has no writer for them: a RegExp field threw at run time where
Node writes {}, and a Promise field failed to link. Both are now refused
at compile time naming the field, also inside a field's arrays, records
and unions, and the fixture covers them.
23 lines
587 B
TypeScript
23 lines
587 B
TypeScript
// JSON.stringify reads class instances through their checked-dynamic
|
|
// property view. A class whose declared field holds a RegExp or a Promise,
|
|
// which the runtime JSON traversal cannot write, is refused at compile
|
|
// time, naming the field.
|
|
class Pattern {
|
|
name = "digits";
|
|
source = /\d+/g;
|
|
}
|
|
|
|
class Job {
|
|
title = "fetch";
|
|
pending = Promise.resolve(1);
|
|
}
|
|
|
|
class Catalog {
|
|
title = "team";
|
|
patterns: Pattern[] = [new Pattern()];
|
|
}
|
|
|
|
console.log(JSON.stringify(new Pattern()));
|
|
console.log(JSON.stringify(new Job()));
|
|
console.log(JSON.stringify({ catalog: new Catalog() }));
|