mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Index quoted get: and set: method names under their own keys
This commit is contained in:
@@ -477,7 +477,7 @@ interface ReceiverIndex {
|
||||
/** By a method or generic method its base chain declares. */
|
||||
methods: Map<string, number[]>;
|
||||
/** By a method, generic method or accessor its base chain declares (an
|
||||
* accessor under its property name), or a field it has. */
|
||||
* accessor under its key and under its property name), or a field it has. */
|
||||
members: Map<string, number[]>;
|
||||
rooted: number[];
|
||||
}
|
||||
@@ -504,11 +504,12 @@ function receiverIndex(lowerer: Lowerer, plans: readonly PropertyReceiver[]): Re
|
||||
for (let c: ClassInfo | null = info; c; c = c.base) {
|
||||
for (const name of c.methods.keys()) {
|
||||
add(methods, name, position);
|
||||
add(
|
||||
members,
|
||||
name.startsWith("get:") || name.startsWith("set:") ? name.slice(4) : name,
|
||||
position,
|
||||
);
|
||||
// A `get:`/`set:` key is an accessor of the property after the
|
||||
// prefix, or a method whose quoted name has that prefix; the test
|
||||
// looks up both.
|
||||
add(members, name, position);
|
||||
if (name.startsWith("get:") || name.startsWith("set:"))
|
||||
add(members, name.slice(4), position);
|
||||
}
|
||||
if (c.genericMethods)
|
||||
for (const name of c.genericMethods.keys()) {
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"order": [
|
||||
"<repo>/tests/corpus/class-quoted-accessor-keys.mjs"
|
||||
],
|
||||
"diags": []
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Methods whose quoted names begin with "get:" or "set:", next to an
|
||||
// accessor of the property after the prefix, read and called through
|
||||
// untyped values.
|
||||
class Quoted {
|
||||
"get:size"() {
|
||||
return "method get:size";
|
||||
}
|
||||
"set:size"(value) {
|
||||
return `method set:size ${value}`;
|
||||
}
|
||||
get size() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
class Sized {
|
||||
constructor() {
|
||||
this.size = 5;
|
||||
}
|
||||
}
|
||||
const values = [new Quoted(), new Sized(), { "get:size": () => "record get:size", size: 1 }];
|
||||
for (const value of values) {
|
||||
const getter = value["get:size"];
|
||||
console.log(typeof getter, getter?.call(value));
|
||||
console.log(typeof value["set:size"], value.size);
|
||||
if (value instanceof Quoted) console.log(value["get:size"](), value["set:size"](7));
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "plain": 3900, "san": 4000 }
|
||||
Reference in New Issue
Block a user