Skip to content

Commit

Permalink
before class->fct refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
eddow committed Nov 17, 2024
1 parent 826f0ed commit 67501a6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# 1.0.11

## Fix

- Source map restoration
- prototype line consistence

# 1.0.10

## Change

- linter from prettier+eslint to biome

## Bug-fix
## Fix

- `KeySet` now rooted on `Object.create(null)` instead of `{}` so that `'constructor' in secludedProperties` is false
- Temporary object (modified as head with `this` diamond as proxy) now has good constructor and `instanceof`
Expand Down
3 changes: 2 additions & 1 deletion src/seclude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function Seclude<TBase extends Ctor, Keys extends (keyof InstanceType<TBa
}
}
const diamond = diamondSecluded ? Diamond(PropertyCollector) : PropertyCollector
// TODO: Should be a function with a proxy prototype: not a prototype whose prototype is a proxy
class GateKeeper extends diamond {
/*static (obj: GateKeeper): TBase | undefined {
return privates.get(obj)
Expand Down Expand Up @@ -115,7 +116,7 @@ export function Seclude<TBase extends Ctor, Keys extends (keyof InstanceType<TBa
return rv
}
/**
* Mambo jumbo to determine who is `this`
* Mumbo jumbo to determine who is `this`
* Because the prototype becomes the object being constructed, we have to invent a constructor who has this object
* as prototype
*/
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export function nextInFLeg(
/* istanbul ignore next: internal bug guard */
if (ndx <= 0) throw new Error('Inconsistent diamond hierarchy')
}
let rv: PropertyDescriptor | undefined
do rv = nextInLine(fLeg[ndx++], name)
while (!rv && ndx < fLeg.length)
return rv
while (ndx < fLeg.length) {
const rv = nextInLine(fLeg[ndx++], name)
if (rv) return rv
}
}

export const allFLegs = new WeakMap<Ctor, Ctor[]>()
Expand Down
35 changes: 35 additions & 0 deletions test/prototypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Diamond from '../src'

class X {}

class A extends Diamond(X) {}

class B extends A {}
class C extends A {}

class D extends Diamond(B, C) {}

test('prototype console', () => {
const d = new D()

for (
let browser = Object.getPrototypeOf(d);
browser !== Object.prototype;
browser = Object.getPrototypeOf(browser)
) {
console.log(browser.constructor.name)
}
})
test('prototype line', () => {
const expected = ['D', 'Diamond', 'B', 'A', 'C', 'A', 'X', 'Object']
const d = new D()

for (
let browser = Object.getPrototypeOf(d);
browser !== Object.prototype;
browser = Object.getPrototypeOf(browser)
) {
expect(browser.constructor.name).toBe(expected.shift())
}
expect(expected).toEqual(['Object'])
})
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"moduleResolution": "Node",
"target": "ESNext",
"module": "ESNext",
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": false,
Expand Down

0 comments on commit 67501a6

Please sign in to comment.