Skip to content

Commit

Permalink
fix(fast_check): do not add init for var decl with declare keyword (#463
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsherret authored Apr 30, 2024
1 parent bf48a9f commit 4ee9d04
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/fast_check/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl<'a> FastCheckTransformer<'a> {
)?;
Ok(true)
}
Decl::Var(n) => self.transform_var(n, is_ambient),
Decl::Var(n) => self.transform_var(n, is_ambient || n.declare),
Decl::TsInterface(_) => Ok(self.public_ranges.contains(&public_range)),
Decl::TsTypeAlias(_) => Ok(self.public_ranges.contains(&public_range)),
Decl::TsEnum(_) => Ok(self.public_ranges.contains(&public_range)),
Expand Down Expand Up @@ -1262,7 +1262,7 @@ impl<'a> FastCheckTransformer<'a> {
) -> Result<bool, Vec<FastCheckDiagnostic>> {
n.decls.retain(|n| self.public_ranges.contains(&n.range()));

// don't need to do anything for these in a declaration file
// don't need to do anything for ambient decls
if !is_ambient {
for decl in &mut n.decls {
self.transform_var_declarator(decl)?;
Expand Down
70 changes: 70 additions & 0 deletions tests/specs/graph/fast_check/var_declare_keyword.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# https://jsr.io/@scope/a/meta.json
{"versions": { "1.0.0": {} } }

# https://jsr.io/@scope/a/1.0.0_meta.json
{ "exports": { ".": "./mod.ts" } }

# https://jsr.io/@scope/a/1.0.0/mod.ts
declare const existsNominal: unique symbol;

export type Exists<F> = F & { [existsNominal]: never };

# mod.ts
import 'jsr:@scope/a'

# output
{
"roots": [
"file:///mod.ts"
],
"modules": [
{
"kind": "esm",
"dependencies": [
{
"specifier": "jsr:@scope/a",
"code": {
"specifier": "jsr:@scope/a",
"span": {
"start": {
"line": 0,
"character": 7
},
"end": {
"line": 0,
"character": 21
}
}
}
}
],
"size": 22,
"mediaType": "TypeScript",
"specifier": "file:///mod.ts"
},
{
"kind": "esm",
"size": 101,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts"
}
],
"redirects": {
"jsr:@scope/a": "https://jsr.io/@scope/a/1.0.0/mod.ts"
},
"packages": {
"@scope/a": "@scope/a@1.0.0"
}
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
{}
declare const existsNominal: unique symbol;
export type Exists<F> = F & {
[existsNominal]: never;
};
--- DTS ---
declare const existsNominal: unique symbol;
export type Exists<F> = F & {
[existsNominal]: never;
};

0 comments on commit 4ee9d04

Please sign in to comment.