Skip to content

Commit

Permalink
Typeof shorthand prop (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasavila00 authored Oct 31, 2024
1 parent 61ad358 commit 72eab85
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 11 deletions.
8 changes: 8 additions & 0 deletions e2e-tests/standalone-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# node-server

## 1.0.53

### Patch Changes

- Updated dependencies
- @beff/cli@0.0.56
- @beff/client@0.0.56

## 1.0.52

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/standalone-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "standalone-parser",
"version": "1.0.52",
"version": "1.0.53",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@beff/cli": "workspace:^0.0.55",
"@beff/cli": "workspace:^0.0.56",
"@beff/client": "workspace:^",
"vitest": "^0.34.4",
"zod": "^3.23.5"
Expand Down
6 changes: 6 additions & 0 deletions packages/beff-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @beff/cli

## 0.0.56

### Patch Changes

- Typeof shorthand

## 0.0.55

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/beff-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beff/cli",
"version": "0.0.55",
"version": "0.0.56",
"description": "",
"bin": {
"beff": "./bin/index.js"
Expand Down
8 changes: 8 additions & 0 deletions packages/beff-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @beff/client

## 0.0.56

### Patch Changes

- Typeof shorthand
- Updated dependencies
- @beff/cli@0.0.56

## 0.0.55

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/beff-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beff/client",
"version": "0.0.55",
"version": "0.0.56",
"description": "",
"main": "dist/cjs/index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@beff/cli": "workspace:^0.0.55",
"@beff/cli": "workspace:^0.0.56",
"zod": "^3.23.5"
},
"devDependencies": {
Expand Down
8 changes: 6 additions & 2 deletions packages/beff-core/src/type_to_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,12 @@ impl<'a, 'b, R: FileManager> TypeToSchema<'a, 'b, R> {
let value = self.typeof_expr(&p.value, as_const)?;
vs.insert(key, value.required());
}
Prop::Shorthand(_)
| Prop::Assign(_)
Prop::Shorthand(p) => {
let key: String = p.sym.to_string();
let value = self.typeof_expr(&Expr::Ident(p.clone()), as_const)?;
vs.insert(key, value.required());
}
Prop::Assign(_)
| Prop::Getter(_)
| Prop::Setter(_)
| Prop::Method(_) => {
Expand Down
11 changes: 11 additions & 0 deletions packages/beff-core/tests/print_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,17 @@ mod tests {
"#));
}
#[test]
fn ok_repro8() {
insta::assert_snapshot!(ok(r#"
const x = (it: string) => it;
const def = "def";
export const ABC = {a: `b`, c: `d${x("d")}d`, def ,} as const satisfies Record<string, string>;
export type AllTs = (keyof typeof ABC);
parse.buildParsers<{ AllTs: AllTs }>();
"#));
}
#[test]
fn ok_void() {
insta::assert_snapshot!(ok(r#"
export type IX = void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: packages/beff-core/tests/print_parser.rs
expression: "ok(r#\"\n const x = (it: string) => it;\n const def = \"def\";\n export const ABC = {a: `b`, c: `d${x(\"d\")}d`, def ,} as const satisfies Record<string, string>;\n export type AllTs = (keyof typeof ABC);\n\n parse.buildParsers<{ AllTs: AllTs }>();\n \"#)"
---
type AllTs = "a" | "c" | "def";
type AllTs = AllTs;
2 changes: 1 addition & 1 deletion packages/beff-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@babel/code-frame": "^7.22.13",
"@beff/cli": "workspace:^0.0.55",
"@beff/cli": "workspace:^0.0.56",
"@types/babel__code-frame": "^7.0.4",
"@types/node": "^20.6.2",
"@types/vscode": "^1.73.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72eab85

Please sign in to comment.