Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ capacity_builder = "0.5.0"
chrono = { version = "0.4.42", default-features = false, features = ["serde"] }
data-url = "0.3.0"
# this is optional in order to support using parsers other than swc
deno_ast = { version = "0.52.0", features = ["emit"], optional = true }
deno_ast = { version = "0.53.0", features = ["emit"], optional = true }
deno_error.workspace = true
deno_media_type = { version = "0.3.0", features = ["decoding", "data_url", "module_specifier"] }
deno_media_type = { version = "0.4.0", features = ["decoding", "data_url", "module_specifier"] }
deno_path_util = "0.6.4"
deno_semver = "0.9.0"
deno_unsync.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion js/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ Deno.test({
await assertRejects(
async () => {
await parseModule(
"file:///a/test.md",
"file:///a/test.js",
new TextEncoder().encode(`# Some Markdown\n\n**bold**`),
);
},
Expand Down
50 changes: 28 additions & 22 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ pub struct JsonModule {
}

impl JsonModule {
/// Return the size in bytes of the content of the JSON module.
/// Return the size in bytes of the content of the module.
pub fn size(&self) -> usize {
self.source.text.len()
}
Expand Down Expand Up @@ -1888,6 +1888,7 @@ impl<'a, 'options> ModuleEntryIterator<'a, 'options> {
MediaType::Css
| MediaType::SourceMap
| MediaType::Html
| MediaType::Markdown
| MediaType::Sql
| MediaType::Jsonc
| MediaType::Json5
Expand Down Expand Up @@ -2951,6 +2952,19 @@ pub(crate) async fn parse_module_source_and_info(
);
}

if let Some(attribute_type) = opts.maybe_attribute_type
&& !matches!(attribute_type.kind.as_str(), "json" | "text" | "bytes")
{
return Err(
ModuleErrorKind::UnsupportedImportAttributeType {
specifier: opts.specifier,
referrer: attribute_type.range.clone(),
kind: attribute_type.kind.clone(),
}
.into_box(),
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this fixes anything, but it's more correct to test this here instead of after resolving json modules.


// here we check any media types that should have assertions made against them
// if they aren't the root and add them to the graph, otherwise we continue
if media_type == MediaType::Json
Expand All @@ -2974,27 +2988,18 @@ pub(crate) async fn parse_module_source_and_info(
});
}

if let Some(attribute_type) = opts.maybe_attribute_type {
if attribute_type.kind == "json" {
return Err(
ModuleErrorKind::InvalidTypeAssertion {
specifier: opts.specifier.clone(),
referrer: attribute_type.range.clone(),
actual_media_type: media_type,
expected_media_type: MediaType::Json,
}
.into_box(),
);
} else if !matches!(attribute_type.kind.as_str(), "text" | "bytes") {
return Err(
ModuleErrorKind::UnsupportedImportAttributeType {
specifier: opts.specifier,
referrer: attribute_type.range.clone(),
kind: attribute_type.kind.clone(),
}
.into_box(),
);
}
if let Some(attribute_type) = opts.maybe_attribute_type
&& attribute_type.kind == "json"
{
return Err(
ModuleErrorKind::InvalidTypeAssertion {
specifier: opts.specifier.clone(),
referrer: attribute_type.range.clone(),
actual_media_type: media_type,
expected_media_type: MediaType::Json,
}
.into_box(),
);
}

if matches!(media_type, MediaType::Cjs | MediaType::Cts)
Expand Down Expand Up @@ -3100,6 +3105,7 @@ pub(crate) async fn parse_module_source_and_info(
| MediaType::Sql
| MediaType::Jsonc
| MediaType::Json5
| MediaType::Markdown
| MediaType::Unknown => Err(
ModuleErrorKind::UnsupportedMediaType {
specifier: opts.specifier,
Expand Down
15 changes: 13 additions & 2 deletions tests/specs/ecosystem/happy_js/happy_opfs/1_0_0.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ happy-js/happy-opfs/1.0.0
-- stdout --

-- stderr --
error: npm package '@jsr/happy-js__happy-rusty' does not exist.
at file://<tmpdir>/src/fs/opfs_ext.ts:1:29
TS2304 [ERROR]: Cannot find name 'FileSystemHandle'.
*/ export function readDir(dirPath: string): Promise<Result<AsyncIterableIterator<[string, FileSystemHandle]>, Error>> {
~~~~~~~~~~~~~~~~
at file://<tmpdir>/src/fs/opfs_core.ts:13:93

TS2304 [ERROR]: Cannot find name 'FileSystemHandle'.
*/ export function stat(path: string): Promise<Result<FileSystemHandle, Error>> {
~~~~~~~~~~~~~~~~
at file://<tmpdir>/src/fs/opfs_core.ts:35:56

Found 2 errors.

error: Type checking failed.

8 changes: 6 additions & 2 deletions tests/specs/ecosystem/stump/adapter_filesystem/0_0_1.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ stump/adapter-filesystem/0.0.1
-- stdout --

-- stderr --
error: npm package '@jsr/stump__core' does not exist.
at file://<tmpdir>/src/base.ts:1:62
TS4114 [ERROR]: This member must have an 'override' modifier because it overrides a member in the base class 'FileSystemAdapter<Meta>'.
public ingestLogs(logs: Array<Log<Meta>>): Promise<void> {
~~~~~~~~~~
at file://<tmpdir>/src/drivers/bun/index.ts:7:10

error: Type checking failed.

49 changes: 47 additions & 2 deletions tests/specs/ecosystem/zeppet/actions/2_1_3.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,51 @@ zeppet/actions/2.1.3
-- stdout --

-- stderr --
error: npm package '@jsr/zeppet__core' does not exist.
at file://<tmpdir>/src/index.ts:1:44
TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
export const listen = <K extends keyof HTMLElementEventMap>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void): ActionFn =>({} as never);
~~~~~~~~~~~~~~~~~~~
at file://<tmpdir>/src/index.ts:5:40

TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
export const listen = <K extends keyof HTMLElementEventMap>(eventName: K, handler: (event: HTMLElementEventMap[K]) => void): ActionFn =>({} as never);
~~~~~~~~~~~~~~~~~~~
at file://<tmpdir>/src/index.ts:5:92

TS2304 [ERROR]: Cannot find name 'HTMLElement'.
export const bindFieldToObs = <T extends HTMLElement, K extends keyof T>(field: K, obs: Observer<NonNullable<T[K]>>)=>(element: T): T =>({} as never);
~~~~~~~~~~~
at file://<tmpdir>/src/index.ts:6:42

TS2304 [ERROR]: Cannot find name 'HTMLElement'.
at file://<tmpdir>/src/index.ts:7:48

TS2304 [ERROR]: Cannot find name 'HTMLElement'.
at file://<tmpdir>/src/index.ts:8:41

TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
at file://<tmpdir>/src/index.ts:8:73

TS2304 [ERROR]: Cannot find name 'HTMLElementEventMap'.
at file://<tmpdir>/src/index.ts:8:154

TS2304 [ERROR]: Cannot find name 'HTMLInputElement'.
export const bindInput = <T extends HTMLInputElement>(obs: Observer<string>): Action<T> =>({} as never);
~~~~~~~~~~~~~~~~
at file://<tmpdir>/src/index.ts:9:37

TS2304 [ERROR]: Cannot find name 'HTMLElement'.
at file://<tmpdir>/src/index.ts:10:34

TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
at file://<tmpdir>/src/index.ts:10:63

TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
at file://<tmpdir>/src/index.ts:10:179

TS2304 [ERROR]: Cannot find name 'HTMLElementTagNameMap'.
at file://<tmpdir>/src/index.ts:10:208

Found 12 errors.

error: Type checking failed.