Skip to content

Commit

Permalink
fix(fast-check): do not add warning diagnostic for js entrypoint with…
Browse files Browse the repository at this point in the history
… types (#386)
  • Loading branch information
dsherret authored Feb 16, 2024
1 parent 2341e9a commit e005651
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 39 deletions.
4 changes: 3 additions & 1 deletion src/fast_check/range_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ impl<'a> PublicRangeFinder<'a> {
return true; // just analyze it
};
match module {
crate::Module::Js(m) => is_typed_media_type(m.media_type),
crate::Module::Js(m) => {
is_typed_media_type(m.media_type) || m.maybe_types_dependency.is_some()
}
crate::Module::Json(_) => true,
crate::Module::Npm(_)
| crate::Module::Node(_)
Expand Down
15 changes: 14 additions & 1 deletion src/symbols/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,20 @@ impl<'a> RootSymbol<'a> {
};

match graph_module {
crate::Module::Js(js_module) => self.analyze_js_module(js_module),
crate::Module::Js(js_module) => js_module
.maybe_types_dependency
.as_ref()
.and_then(|types| {
types.dependency.maybe_specifier().and_then(|specifier| {
// shouldn't happen, but prevent circular loops
if specifier != &js_module.specifier {
self.module_from_specifier(specifier)
} else {
None
}
})
})
.or_else(|| self.analyze_js_module(js_module)),
crate::Module::Json(json_module) => {
Some(self.analyze_json_module(json_module))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# https://jsr.io/@scope/a/meta.json
{"versions": { "1.0.0": {} } }

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

# https://jsr.io/@scope/a/1.0.0/mod.d.ts
export function getRandom(): number;

# https://jsr.io/@scope/a/1.0.0/mod.js
/// <reference types="./mod.d.ts" />
export function getRandom() {
return Math.random();
}

# 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": 37,
"mediaType": "Dts",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.d.ts"
},
{
"kind": "esm",
"size": 93,
"typesDependency": {
"specifier": "./mod.d.ts",
"dependency": {
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.d.ts",
"span": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 33
}
}
}
},
"mediaType": "JavaScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.js"
}
],
"redirects": {
"jsr:@scope/a": "https://jsr.io/@scope/a/1.0.0/mod.js"
},
"packages": {
"@scope/a": "@scope/a@1.0.0"
}
}

Fast check https://jsr.io/@scope/a/1.0.0/mod.d.ts:
{}
export function getRandom(): number;
135 changes: 135 additions & 0 deletions tests/specs/graph/JsrSpecifiers_FastCheck_JsWithTsDecl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# 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/random.d.ts
export function getRandom(): number;

# https://jsr.io/@scope/a/1.0.0/random.js
/// <reference types="./random.d.ts" />
export function getRandom() {
return Math.random();
}

# https://jsr.io/@scope/a/1.0.0/mod.ts
export * from "./random.js";

# 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",
"dependencies": [
{
"specifier": "./random.js",
"code": {
"specifier": "https://jsr.io/@scope/a/1.0.0/random.js",
"span": {
"start": {
"line": 0,
"character": 14
},
"end": {
"line": 0,
"character": 27
}
}
}
}
],
"size": 29,
"mediaType": "TypeScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/mod.ts"
},
{
"kind": "esm",
"size": 37,
"mediaType": "Dts",
"specifier": "https://jsr.io/@scope/a/1.0.0/random.d.ts"
},
{
"kind": "esm",
"size": 96,
"typesDependency": {
"specifier": "./random.d.ts",
"dependency": {
"specifier": "https://jsr.io/@scope/a/1.0.0/random.d.ts",
"span": {
"start": {
"line": 0,
"character": 21
},
"end": {
"line": 0,
"character": 36
}
}
}
},
"mediaType": "JavaScript",
"specifier": "https://jsr.io/@scope/a/1.0.0/random.js"
}
],
"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:
{
"./random.d.ts": {
"code": {
"specifier": "https://jsr.io/@scope/a/1.0.0/random.d.ts",
"span": {
"start": {
"line": 0,
"character": 14
},
"end": {
"line": 0,
"character": 27
}
}
}
}
}
export * from "./random.d.ts";

Fast check https://jsr.io/@scope/a/1.0.0/random.d.ts:
{}
export function getRandom(): number;
Loading

0 comments on commit e005651

Please sign in to comment.