Skip to content

Commit

Permalink
Parser improvements (#125)
Browse files Browse the repository at this point in the history
* Parser improvements
* Small fix to class name being "extends"
  • Loading branch information
kaleidawave committed Mar 15, 2024
1 parent 338b1ad commit 78e3839
Show file tree
Hide file tree
Showing 59 changed files with 955 additions and 1,042 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/performance-and-size.yml
Expand Up @@ -45,7 +45,6 @@ jobs:
env:
CARGO_PROFILE_RELEASE_DEBUG: true


- name: Download files
run: |
curl https://esm.sh/v128/react-dom@18.2.0/es2022/react-dom.mjs > react.js
Expand All @@ -62,7 +61,7 @@ jobs:
\`\`\`ts
" >> $GITHUB_STEP_SUMMARY
lines=$(scc -c --no-cocomo -f json .\private\tocheck\all.ts | jq ".[0].Code")
echo "// $lines of TypeScript"
echo "// $lines of TypeScript" >> $GITHUB_STEP_SUMMARY
cat demo.ts >> $GITHUB_STEP_SUMMARY
echo "\`\`\`
</details>
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -25,14 +25,14 @@ Now in the `ezno` directory, `cargo run` should show the CLI.
If you don't want to run the whole Ezno CLI. You can run just the checker with

```shell
cargo run -p ezno-checker -F ezno-parser --example check path/to/file.ts
cargo run -p ezno-checker --example run path/to/file.ts
```

If you want to check all the checker tests

```shell
cargo test -p ezno-checker-specification
# To including staging.md (which is really useful for keeping new fixes/additions separate)
# To include the Staging file (which is really useful for keeping new fixes/additions separate)
cargo test -p ezno-checker-specification -F staging
# and for all the tests (which includes all of to_implement.md)
cargo test -p ezno-checker-specification -F all
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@ A JavaScript compiler and TypeScript checker written in Rust with a focus on sta
> [!IMPORTANT]
> Ezno is in active development and **currently does not support enough features to check existing projects**. Check out the [getting started guide](./checker/docs/getting-started.md) for experimenting with what it [currently supports](./checker/specification/specification.md).
<!-- Currently out ![project lines of code](https://projects.kaleidawave.workers.dev/project/ezno/badge) -->
<!-- ![project lines of code](https://projects.kaleidawave.workers.dev/project/ezno/badge) -->

What Ezno is
- A type checker for JavaScript usable through a CLI ([with a LSP also in the works](https://github.com/kaleidawave/ezno/issues/22))
Expand Down
Binary file added checker/definitions/internal.ts.d2.bin
Binary file not shown.
75 changes: 1 addition & 74 deletions checker/specification/specification.md
Expand Up @@ -718,17 +718,6 @@ doThing(6, 1) satisfies 6;

- Expected 2, found 5

#### Generic condition

```ts
declare function isNumber<T>(t: T): T extends number ? true : false;

isNumber(5) satisfies true;
isNumber("5") satisfies number;
```

- Expected number, found false

### Effects

> Side effects of functions. Registered internally as `Event`s
Expand Down Expand Up @@ -1445,7 +1434,7 @@ interface X {
> In the future, their definition could be considered and evaluated at runtime
```ts
/hi/ satisfies string;
const regexp = /hi/ satisfies string;
```

- Expected string, found /hi/
Expand Down Expand Up @@ -1558,34 +1547,6 @@ d satisfies 1;

- Expected 1, found 2

#### Try-catch and throw

```ts
try {
throw 2
} catch (err) {
err satisfies string
}
```

- Expected string, found 2

#### Throw effects carry through

```ts
function throwType(a) {
throw a
}

try {
throwType(3)
} catch (err) {
err satisfies string
}
```

- Expected string, found 3

#### Interface merging

```ts
Expand Down Expand Up @@ -1916,28 +1877,6 @@ getSecondCharacter("string") satisfies "b";
- Expected boolean, found (s: string) => string | undefined
- Expected "b", found "t"

#### Double generics

> Really want to only have one covariant and one contravariant but want to keep TSC semantics
```ts
declare function what<T>(a: T, b: T): T;

what(2, 3) satisfies string;
```

- Expected string, found 2 | 3

#### More accurate generic

```ts
declare function unwrap<T>(a: T | { item: T }): T;

unwrap({ item: 5 }) satisfies string;
```

- Expected string, found 5

#### As casts

> Disabled normally, allowed for these tests. Provides TSC compatibility and because narrowing not implemented (including secret feature)
Expand Down Expand Up @@ -2072,18 +2011,6 @@ function add() {

- Argument of type "hi" is not assignable to parameter of type number

#### Across alias

```ts
type WithLabel<T> = { label: string, item: T };

declare function getItem<T>(a: WithLabel<T>): T;

getItem({ label: "item 1", item: 5 }) satisfies string;
```

- Expected string, found 5

#### Mapped types

```ts
Expand Down
77 changes: 77 additions & 0 deletions checker/specification/to_implement.md
Expand Up @@ -596,3 +596,80 @@ y.pop();

- TODO cannot push
- TODO cannot pop

### Breaking

> Were working, but a temporary change broke them
#### Try-catch and throw

```ts
try {
throw 2
} catch (err) {
err satisfies string
}
```

- Expected string, found 2

#### Throw effects carry through

```ts
function throwType(a) {
throw a
}

try {
throwType(3)
} catch (err) {
err satisfies string
}
```

- Expected string, found 3

#### Generic condition

```ts
declare function isNumber<T>(t: T): T extends number ? true : false;

isNumber(5) satisfies true;
isNumber("5") satisfies number;
```

- Expected number, found false

#### More accurate generic

```ts
declare function unwrap<T>(a: T | { item: T }): T;

unwrap({ item: 5 }) satisfies string;
```

- Expected string, found 5

#### Across alias

```ts
type WithLabel<T> = { label: string, item: T };

declare function getItem<T>(a: WithLabel<T>): T;

getItem({ label: "item 1", item: 5 }) satisfies string;
```

- Expected string, found 5

#### Double generics

> Really want to only have one covariant and one contravariant but want to keep TSC semantics
```ts
declare function what<T>(a: T, b: T): T;

what(2, 3) satisfies string;
```

- Expected string, found 2 | 3
4 changes: 1 addition & 3 deletions checker/src/synthesis/declarations.rs
Expand Up @@ -81,9 +81,7 @@ pub(crate) fn synthesise_declaration<T: crate::ReadFromFS>(
}
}
}
Declaration::DeclareFunction(_)
| Declaration::DeclareVariable(_)
| Declaration::DeclareInterface(_)
Declaration::DeclareVariable(_)
| Declaration::Function(_)
| Declaration::Enum(_)
| Declaration::Interface(_)
Expand Down

0 comments on commit 78e3839

Please sign in to comment.