Skip to content

Commit

Permalink
Object destructuring, this unbinding and checking (#127)
Browse files Browse the repository at this point in the history
* Fixes #98 & #106
* Checks `this` type in functions
* Improves destructuring API
* Specification test 200

---------

Co-authored-by: Ben <[email protected]>
  • Loading branch information
lemueldls and kaleidawave authored Apr 10, 2024
1 parent 0fa4fa8 commit 3fab1f7
Show file tree
Hide file tree
Showing 26 changed files with 834 additions and 317 deletions.
Binary file modified checker/definitions/internal.ts.d.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion checker/definitions/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ declare function satisfies<T>(t: T): T;

@Constant
declare function compile_type_to_object<T>(): any;
// ↑↑ Ezno Functions ↑↑
// ↑↑ Ezno Functions ↑↑
50 changes: 48 additions & 2 deletions checker/specification/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,16 @@ callToUpperCase("hi") satisfies "HEY";

- Expected "HEY", found "HI"

#### String internal `this` unbinding error

```ts
const { toUpperCase } = "hi";

toUpperCase();
```

- The 'this' context of the function is expected to be string, found undefined

#### Calling new on a function

```ts
Expand Down Expand Up @@ -739,7 +749,7 @@ doThing(6, 1) satisfies 6;
let a: number = 0
function func() {
a = 4;
// Important that subsequent reads use the
// Important that subsequent reads use the
// new value, not the same free variable
a satisfies 4;
}
Expand Down Expand Up @@ -1569,7 +1579,7 @@ interface X {
interface X {
c: number
}

const x: X = { a: "field", b: false, c: false }
const y: X = { a: "field", b: false, c: 2 }
}
Expand Down Expand Up @@ -1658,6 +1668,27 @@ try {

- Expected string, found 3

#### Object destructuring assignment

```ts
const o = { a: 1, b: { c: 3 } };

let a, b, c;
({
c = o.a++,
b: { c: b = 7 },
a,
} = o);

a satisfies string;
b satisfies boolean;
c satisfies 3;
```

- Expected string, found 2
- Expected boolean, found 3
- Expected 3, found 1

### Async and `Promise`s

> Position of await is not checked (here is fine because top level await)
Expand Down Expand Up @@ -1692,6 +1723,21 @@ x.value satisfies string

- Expected string, found 4

#### Class `this` unbinding

```ts
class X {
method() {
return this;
}
}

const { method } = new X();
method();
```

- The 'this' context of the function is expected to be X, found undefined

#### Property keys

> Property keys are synthesised once and their effects run once (as opposed to their value)
Expand Down
Loading

0 comments on commit 3fab1f7

Please sign in to comment.