diff --git a/Cargo.lock b/Cargo.lock index ac5171403..ca7153fb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -129,12 +129,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "data-url" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d7439c3735f405729d52c3fbbe4de140eaf938a1fe47d227c27f8254d4302a5" - [[package]] name = "data-url" version = "0.3.0" @@ -143,9 +137,9 @@ checksum = "41b319d1b62ffbd002e057f36bebd1f42b9f97927c9577461d855f3513c4289f" [[package]] name = "deno_ast" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00c93119b1c487a85603406a988a0ca9a1d0e5315404cccc5c158fb484b1f5a2" +checksum = "b041461b8b531a409fc635a5a476aee79b82f2c502d1d279c5995b6768ed944a" dependencies = [ "deno_media_type", "dprint-swc-ext", @@ -173,7 +167,7 @@ version = "0.52.1" dependencies = [ "anyhow", "async-trait", - "data-url 0.3.0", + "data-url", "deno_ast", "deno_semver", "futures", @@ -208,11 +202,11 @@ dependencies = [ [[package]] name = "deno_media_type" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001d69b833ed4d244b608bab9c07069bfb570f631b763b58e73f82a020bf84ef" +checksum = "a798670c20308e5770cc0775de821424ff9e85665b602928509c8c70430b3ee0" dependencies = [ - "data-url 0.2.0", + "data-url", "serde", "url", ] @@ -238,9 +232,9 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "dprint-swc-ext" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f115ea5b6f5d0d02a25a9364f41b8c4f857452c299309dcfd29a694724d0566" +checksum = "6a0a2492465344a58a37ae119de59e81fe5a2885f2711c7b5048ef0dfa14ce42" dependencies = [ "bumpalo", "num-bigint", @@ -975,9 +969,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8066e17abb484602da673e2d35138ab32ce53f26368d9c92113510e1659220b" +checksum = "9f54563d7dcba626d4acfe14ed12def7ecc28e004debe3ecd2c3ee07cc47e449" dependencies = [ "once_cell", "rustc-hash", @@ -989,9 +983,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.31.21" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5823ef063f116ad281cde9700f5be6dfb182e543ce3f62c42cee1c03ffbc6b" +checksum = "39cb7fcd56655c8ae7dcf2344f0be6cbff4d9c7cb401fe3ec8e56e1de8dfe582" dependencies = [ "ast_node", "better_scoped_tls", @@ -1015,9 +1009,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.107.7" +version = "0.109.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7191c8c57af059b75a2aadc927a2608c3962d19e4d09ce8f9c3f03739ddf833" +checksum = "7bc2286cedd688a68f214faa1c19bb5cceab7c9c54d0cbe3273e4c1704e38f69" dependencies = [ "bitflags 2.4.0", "is-macro", @@ -1032,9 +1026,9 @@ dependencies = [ [[package]] name = "swc_ecma_dep_graph" -version = "0.109.15" +version = "0.111.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1295557b5960eb97ec63fc2008be0a101d1ff7d2163a1031b3d31d3c898d5bb3" +checksum = "c5526adf6a434f145c8caf7e3a2dba554a2ad09b84467b6a62210f9ef0af0f71" dependencies = [ "swc_atoms", "swc_common", @@ -1044,9 +1038,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.43.23" +version = "0.44.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82f47bb1ab686f603da93a8b6e559d69b42369ab47d5dee6bdda38ae5902dc2a" +checksum = "e7d7c322462657ae27ac090a2c89f7e456c94416284a2f5ecf66c43a6a3c19d1" dependencies = [ "anyhow", "pathdiff", @@ -1057,9 +1051,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.137.15" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c0d554865a63bfa58cf1c433fa91d7d4adf40030fa8e4530e8065d0578166a" +checksum = "3eab46cb863bc5cd61535464e07e5b74d5f792fa26a27b9f6fd4c8daca9903b7" dependencies = [ "either", "num-bigint", @@ -1077,9 +1071,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.130.24" +version = "0.132.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d8ca5dd849cea79e6a9792d725f4082ad3ade7a9541fba960c42d55ae778f2" +checksum = "01ffd4a8149052bfc1ec1832fcbe04f317846ce635a49ec438df33b06db27d26" dependencies = [ "better_scoped_tls", "bitflags 2.4.0", @@ -1100,9 +1094,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.120.19" +version = "0.122.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb60e20e1eb9e9f7c88d99ac8659fd0561d70abd27853f550fbd907a448c878" +checksum = "11006a3398ffd4693c4d3b0a1b1a5030edbdc04228159f5301120a6178144708" dependencies = [ "indexmap 1.9.3", "num_cpus", @@ -1118,9 +1112,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.93.7" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb23a48abd9f5731b6275dbf4ea89f6e03dc60b7c8e3e1e383bb4a6c39fd7e25" +checksum = "0f628ec196e76e67892441e14eef2e423a738543d32bffdabfeec20c29582117" dependencies = [ "num-bigint", "swc_atoms", diff --git a/Cargo.toml b/Cargo.toml index 6be6c056b..136a75989 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ type_tracing = ["deno_ast/transforms", "deno_ast/visit", "deno_ast/utils"] anyhow = "1.0.43" async-trait = "0.1.68" data-url = "0.3.0" -deno_ast = { version = "0.28.0", features = ["dep_graph", "module_specifier"] } +deno_ast = { version = "0.29.0", features = ["dep_graph", "module_specifier"] } deno_semver = "0.4.0" futures = "0.3.26" indexmap = { version = "2", features = ["serde"] } diff --git a/js/test.ts b/js/test.ts index 54380a69a..86077bc71 100644 --- a/js/test.ts +++ b/js/test.ts @@ -696,14 +696,14 @@ Deno.test({ }); Deno.test({ - name: "parseModule() - import assertions", + name: "parseModule() - import attributes", async fn() { await init(); const module = parseModule( "file:///a/test01.js", ` - import a from "./a.json" assert { type: "json" }; - await import("./b.json", { assert: { type: "json" } }); + import a from "./a.json" with { type: "json" }; + await import("./b.json", { with: { type: "json" } }); `, ); assertEquals(module, { @@ -746,7 +746,7 @@ Deno.test({ ], "kind": "esm", "mediaType": MediaType.JavaScript, - "size": 129, + "size": 125, "specifier": "file:///a/test01.js", }); }, diff --git a/js/types.d.ts b/js/types.d.ts index 5b30a776f..ab62ac523 100644 --- a/js/types.d.ts +++ b/js/types.d.ts @@ -94,7 +94,7 @@ export interface TypesDependencyJson { /** The kind of module. * * For asserted modules, the value of the `asserted` property is set to the - * `type` value of the assertion. + * `type` value of the import attribute. * * Dependency analysis is not performed for asserted or Script modules * currently. Synthetic modules were injected into the graph with their own diff --git a/src/analyzer.rs b/src/analyzer.rs index bdbd428e3..8e95612fd 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -169,57 +169,57 @@ impl DependencyKind { #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(untagged)] -pub enum ImportAssertion { - /// The value of this assertion could not be statically analyzed. +pub enum ImportAttribute { + /// The value of this attribute could not be statically analyzed. Unknown, - /// The value of this assertion is a statically analyzed string. + /// The value of this attribute is a statically analyzed string. Known(String), } -impl ImportAssertion { +impl ImportAttribute { // can't use swc's type directly because we need to make it serialize & deserialize pub fn from_swc(value: deno_ast::swc::dep_graph::ImportAssertion) -> Self { use deno_ast::swc::dep_graph::ImportAssertion::*; match value { - Unknown => ImportAssertion::Unknown, - Known(value) => ImportAssertion::Known(value), + Unknown => ImportAttribute::Unknown, + Known(value) => ImportAttribute::Known(value), } } } #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub enum ImportAssertions { - /// There was no import assertions object literal. +pub enum ImportAttributes { + /// There was no import attributes object literal. None, - /// The set of assertion keys could not be statically analyzed. + /// The set of attribute keys could not be statically analyzed. Unknown, - /// The set of assertion keys is statically analyzed, though each respective + /// The set of attribute keys is statically analyzed, though each respective /// value may or may not not be for dynamic imports. - Known(HashMap), + Known(HashMap), } -impl Default for ImportAssertions { +impl Default for ImportAttributes { fn default() -> Self { Self::None } } -impl ImportAssertions { +impl ImportAttributes { pub fn is_none(&self) -> bool { - matches!(self, ImportAssertions::None) + matches!(self, ImportAttributes::None) } // can't use this type directly because we need to make it serialize & deserialize - pub fn from_swc(value: deno_ast::swc::dep_graph::ImportAssertions) -> Self { - use deno_ast::swc::dep_graph::ImportAssertions::*; + pub fn from_swc(value: deno_ast::swc::dep_graph::ImportAttributes) -> Self { + use deno_ast::swc::dep_graph::ImportAttributes::*; match value { - None => ImportAssertions::None, - Unknown => ImportAssertions::Unknown, - Known(value) => ImportAssertions::Known( + None => ImportAttributes::None, + Unknown => ImportAttributes::Unknown, + Known(value) => ImportAttributes::Known( value .into_iter() - .map(|(key, value)| (key, ImportAssertion::from_swc(value))) + .map(|(key, value)| (key, ImportAttribute::from_swc(value))) .collect(), ), } @@ -227,8 +227,8 @@ impl ImportAssertions { pub fn get(&self, key: &str) -> Option<&String> { match self { - ImportAssertions::Known(map) => match map.get(key) { - Some(ImportAssertion::Known(value)) => Some(value), + ImportAttributes::Known(map) => match map.get(key) { + Some(ImportAttribute::Known(value)) => Some(value), _ => None, }, _ => None, @@ -277,9 +277,9 @@ pub struct DependencyDescriptor { pub specifier: String, /// The range of the specifier. pub specifier_range: PositionRange, - /// Import assertions for this dependency. - #[serde(skip_serializing_if = "ImportAssertions::is_none", default)] - pub import_assertions: ImportAssertions, + /// Import attributes for this dependency. + #[serde(skip_serializing_if = "ImportAttributes::is_none", default)] + pub import_attributes: ImportAttributes, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -391,7 +391,7 @@ mod test { character: 4, }, }, - import_assertions: ImportAssertions::None, + import_attributes: ImportAttributes::None, }, DependencyDescriptor { kind: DependencyKind::Export, @@ -406,13 +406,13 @@ mod test { start: Position::zeroed(), end: Position::zeroed(), }, - import_assertions: ImportAssertions::Known(HashMap::from([ - ("key".to_string(), ImportAssertion::Unknown), + import_attributes: ImportAttributes::Known(HashMap::from([ + ("key".to_string(), ImportAttribute::Unknown), ( "key2".to_string(), - ImportAssertion::Known("value".to_string()), + ImportAttribute::Known("value".to_string()), ), - ("kind".to_string(), ImportAssertion::Unknown), + ("kind".to_string(), ImportAttribute::Unknown), ])), }, ]), @@ -438,7 +438,7 @@ mod test { "range": [[0, 0], [0, 0]], "specifier": "./test2", "specifierRange": [[0, 0], [0, 0]], - "importAssertions": { + "importAttributes": { "known": { "key": null, "key2": "value", @@ -561,7 +561,7 @@ mod test { start: Position::zeroed(), end: Position::zeroed(), }, - import_assertions: ImportAssertions::Unknown, + import_attributes: ImportAttributes::Unknown, }; run_serialization_test( &module_info, @@ -575,7 +575,7 @@ mod test { "range": [[0, 0], [0, 0]], "specifier": "./test", "specifierRange": [[0, 0], [0, 0]], - "importAssertions": "unknown", + "importAttributes": "unknown", }), ); } diff --git a/src/ast.rs b/src/ast.rs index e7751fdf8..f10bd5c43 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -10,7 +10,7 @@ use crate::analyzer::TypeScriptReference; use crate::graph::Position; use crate::module_specifier::ModuleSpecifier; use crate::DependencyKind; -use crate::ImportAssertions; +use crate::ImportAttributes; use deno_ast::SourcePos; use deno_ast::SourceRange; @@ -336,7 +336,7 @@ fn analyze_dependencies( SourceRange::unsafely_from_span(d.specifier_span), parsed_source.text_info(), ), - import_assertions: ImportAssertions::from_swc(d.import_assertions), + import_attributes: ImportAttributes::from_swc(d.import_attributes), }) .collect() } @@ -587,31 +587,35 @@ mod tests { } #[test] - fn test_analyze_dependencies_import_assertions() { + fn test_analyze_dependencies_import_attributes() { let specifier = ModuleSpecifier::parse("file:///a/test.ts").expect("bad specifier"); - let source = r#" - import a from "./a.json" assert { type: "json" }; - await import("./b.json", { assert: { type: "json" } }); - "#; - let parsed_source = DefaultModuleParser::default() - .parse_module(&specifier, source.into(), MediaType::TypeScript) - .unwrap(); - let module_info = DefaultModuleAnalyzer::module_info(&parsed_source); - let dependencies = module_info.dependencies; - assert_eq!(dependencies.len(), 2); - assert!(!dependencies[0].is_dynamic); - assert_eq!(dependencies[0].specifier.to_string(), "./a.json"); - assert_eq!( - dependencies[0].import_assertions.get("type"), - Some(&"json".to_string()) - ); - assert!(dependencies[1].is_dynamic); - assert_eq!(dependencies[1].specifier.to_string(), "./b.json"); - assert_eq!( - dependencies[1].import_assertions.get("type"), - Some(&"json".to_string()) - ); + for keyword in ["assert", "with"] { + let source = format!( + " + import a from \"./a.json\" {keyword} {{ type: \"json\" }}; + await import(\"./b.json\", {{ {keyword}: {{ type: \"json\" }} }}); + " + ); + let parsed_source = DefaultModuleParser::default() + .parse_module(&specifier, source.into(), MediaType::TypeScript) + .unwrap(); + let module_info = DefaultModuleAnalyzer::module_info(&parsed_source); + let dependencies = module_info.dependencies; + assert_eq!(dependencies.len(), 2); + assert!(!dependencies[0].is_dynamic); + assert_eq!(dependencies[0].specifier.to_string(), "./a.json"); + assert_eq!( + dependencies[0].import_attributes.get("type"), + Some(&"json".to_string()) + ); + assert!(dependencies[1].is_dynamic); + assert_eq!(dependencies[1].specifier.to_string(), "./b.json"); + assert_eq!( + dependencies[1].import_attributes.get("type"), + Some(&"json".to_string()) + ); + } } #[test] diff --git a/src/graph.rs b/src/graph.rs index da6f996a9..47c9dbe76 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -8,7 +8,7 @@ use crate::analyzer::PositionRange; use crate::analyzer::SpecifierWithRange; use crate::analyzer::TypeScriptReference; use crate::DefaultModuleAnalyzer; -use crate::ImportAssertions; +use crate::ImportAttributes; use crate::ReferrerImports; use crate::deno::resolve_version; @@ -168,7 +168,7 @@ pub enum ModuleError { actual_media_type: MediaType, expected_media_type: MediaType, }, - UnsupportedImportAssertionType { + UnsupportedImportAttributeType { specifier: ModuleSpecifier, range: Range, kind: String, @@ -186,7 +186,7 @@ impl ModuleError { | Self::UnknownPackage { specifier: s, .. } | Self::UnknownPackageReq { specifier: s, .. } | Self::InvalidTypeAssertion { specifier: s, .. } - | Self::UnsupportedImportAssertionType { specifier: s, .. } => s, + | Self::UnsupportedImportAttributeType { specifier: s, .. } => s, } } @@ -202,7 +202,7 @@ impl ModuleError { } Self::ParseErr(_, _) => None, Self::InvalidTypeAssertion { range, .. } => Some(range), - Self::UnsupportedImportAssertionType { range, .. } => Some(range), + Self::UnsupportedImportAttributeType { range, .. } => Some(range), } } } @@ -218,7 +218,7 @@ impl std::error::Error for ModuleError { | Self::UnknownPackageReq { .. } | Self::UnsupportedMediaType(_, _, _) | Self::InvalidTypeAssertion { .. } - | Self::UnsupportedImportAssertionType { .. } => None, + | Self::UnsupportedImportAttributeType { .. } => None, } } } @@ -232,16 +232,16 @@ impl fmt::Display for ModuleError { write!(f, "Unknown package: {package_name}\n Specifier: {specifier}"), Self::UnknownPackageReq { package_req, specifier, .. } => write!(f, "Could not find constraint in the list of versions: {package_req}\n Specifier: {specifier}"), - Self::UnsupportedMediaType(specifier, MediaType::Json, ..) => write!(f, "Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import assertion with the type of \"json\".\n Specifier: {specifier}"), + Self::UnsupportedMediaType(specifier, MediaType::Json, ..) => write!(f, "Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import attribute with the type of \"json\".\n Specifier: {specifier}"), Self::UnsupportedMediaType(specifier, media_type, ..) => write!(f, "Expected a JavaScript or TypeScript module, but identified a {media_type} module. Importing these types of modules is currently not supported.\n Specifier: {specifier}"), Self::Missing(specifier, _) => write!(f, "Module not found \"{specifier}\"."), Self::MissingDynamic(specifier, _) => write!(f, "Dynamic import not found \"{specifier}\"."), Self::InvalidTypeAssertion { specifier, actual_media_type: MediaType::Json, expected_media_type, .. } => - write!(f, "Expected a {expected_media_type} module, but identified a Json module. Consider importing Json modules with an import assertion with the type of \"json\".\n Specifier: {specifier}"), + write!(f, "Expected a {expected_media_type} module, but identified a Json module. Consider importing Json modules with an import attribute with the type of \"json\".\n Specifier: {specifier}"), Self::InvalidTypeAssertion { specifier, actual_media_type, expected_media_type, .. } => write!(f, "Expected a {expected_media_type} module, but identified a {actual_media_type} module.\n Specifier: {specifier}"), - Self::UnsupportedImportAssertionType { specifier, kind, .. } => - write!(f, "The import assertion type of \"{kind}\" is unsupported.\n Specifier: {specifier}"), + Self::UnsupportedImportAttributeType { specifier, kind, .. } => + write!(f, "The import attribute type of \"{kind}\" is unsupported.\n Specifier: {specifier}"), } } } @@ -547,11 +547,10 @@ pub struct Import { pub range: Range, #[serde(skip_serializing_if = "is_false")] pub is_dynamic: bool, - // Don't include assertions in `deno info --json`, since they may be unstable: - // https://github.com/denoland/deno/issues/17944. Assertion error strings - // eventually will be included in a separate `Import::errors`, however. + // Don't include attributes in `deno info --json` until someone has a need. + // Attribute error strings eventually will be included in a separate `Import::errors`, however. #[serde(skip_serializing)] - pub assertions: ImportAssertions, + pub attributes: ImportAttributes, } #[derive(Debug, Default, Clone, Serialize)] @@ -563,9 +562,10 @@ pub struct Dependency { pub maybe_type: Resolution, #[serde(skip_serializing_if = "is_false")] pub is_dynamic: bool, + // todo(dsherret): rename to attributeType in 2.0 #[serde(rename = "assertionType", skip_serializing_if = "Option::is_none")] - pub maybe_assert_type: Option, - // TODO(nayeemrmn): Replace `maybe_assert_type` with this in the serialization + pub maybe_attribute_type: Option, + // TODO(nayeemrmn): Replace `maybe_attribute_type` with this in the serialization // for 2.0. #[serde(skip_serializing)] pub imports: Vec, @@ -840,7 +840,7 @@ impl GraphImport { is_dynamic: false, maybe_code: Resolution::None, maybe_type, - maybe_assert_type: None, + maybe_attribute_type: None, imports: vec![], }, ) @@ -1616,7 +1616,7 @@ pub(crate) fn parse_module( specifier: &ModuleSpecifier, maybe_headers: Option<&HashMap>, content: Arc, - maybe_assert_type: Option, + maybe_attribute_type: Option, maybe_referrer: Option, maybe_resolver: Option<&dyn Resolver>, module_analyzer: &dyn ModuleAnalyzer, @@ -1632,7 +1632,7 @@ pub(crate) fn parse_module( && (is_root || is_dynamic_branch || matches!( - maybe_assert_type.as_ref().map(|t| t.kind.as_str()), + maybe_attribute_type.as_ref().map(|t| t.kind.as_str()), Some("json") )) { @@ -1644,22 +1644,22 @@ pub(crate) fn parse_module( })); } - if let Some(assert_type) = maybe_assert_type { - if assert_type.kind == "json" { + if let Some(attribute_type) = maybe_attribute_type { + if attribute_type.kind == "json" { return Err(ModuleGraphError::ModuleError( ModuleError::InvalidTypeAssertion { specifier: specifier.clone(), - range: assert_type.range, + range: attribute_type.range, actual_media_type: media_type, expected_media_type: MediaType::Json, }, )); } else { return Err(ModuleGraphError::ModuleError( - ModuleError::UnsupportedImportAssertionType { + ModuleError::UnsupportedImportAttributeType { specifier: specifier.clone(), - range: assert_type.range, - kind: assert_type.kind, + range: attribute_type.range, + kind: attribute_type.kind, }, )); } @@ -1757,7 +1757,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::TsReferencePath, range, is_dynamic: false, - assertions: Default::default(), + attributes: Default::default(), }); } TypeScriptReference::Types(specifier) => { @@ -1783,7 +1783,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::TsReferenceTypes, range, is_dynamic: false, - assertions: Default::default(), + attributes: Default::default(), }); } } @@ -1833,7 +1833,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::JsxImportSource, range, is_dynamic: false, - assertions: Default::default(), + attributes: Default::default(), }); } } @@ -1854,7 +1854,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::JsDoc, range, is_dynamic: false, - assertions: Default::default(), + attributes: Default::default(), }); } @@ -1922,10 +1922,10 @@ pub(crate) fn parse_esm_module_from_module_info( .dependencies .entry(desc.specifier.to_string()) .or_default(); - // TODO(nayeemrmn): Import assertions should be visited and checked for + // TODO(nayeemrmn): Import attributes should be visited and checked for // every import, not one per specifier. - if dep.maybe_assert_type.is_none() { - dep.maybe_assert_type = desc.import_assertions.get("type").cloned(); + if dep.maybe_attribute_type.is_none() { + dep.maybe_attribute_type = desc.import_attributes.get("type").cloned(); } let range = Range::from_position_range( module.specifier.clone(), @@ -1945,7 +1945,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::TsType, range, is_dynamic: desc.is_dynamic, - assertions: desc.import_assertions.clone(), + attributes: desc.import_attributes.clone(), }); } else { if dep.maybe_code.is_none() { @@ -1965,7 +1965,7 @@ pub(crate) fn parse_esm_module_from_module_info( kind: ImportKind::Es, range, is_dynamic: desc.is_dynamic, - assertions: desc.import_assertions.clone(), + attributes: desc.import_attributes.clone(), }); } if dep.maybe_type.is_none() { @@ -2066,9 +2066,9 @@ struct PendingInfo { type PendingInfoFuture = LocalBoxFuture<'static, PendingInfo>; #[derive(PartialEq, Eq, Hash)] -pub(crate) struct AssertTypeWithRange { +pub(crate) struct AttributeTypeWithRange { range: Range, - /// The kind of assertion (ex. "json"). + /// The kind of attribute (ex. "json"). kind: String, } @@ -2120,9 +2120,9 @@ struct PendingState { deno: PendingDenoState, npm: PendingNpmState, pending_specifiers: - HashMap>>, + HashMap>>, dynamic_branches: - HashMap)>, + HashMap)>, } #[derive(Clone)] @@ -2706,7 +2706,7 @@ impl<'a, 'graph> Builder<'a, 'graph> { specifier: &ModuleSpecifier, maybe_range: Option<&Range>, is_dynamic: bool, - maybe_assert_type: Option, + maybe_assert_type: Option, maybe_version_info: Option<&DenoPackageVersionInfoExt>, ) { let specifier = self.graph.redirects.get(specifier).unwrap_or(specifier); @@ -3055,7 +3055,7 @@ impl<'a, 'graph> Builder<'a, 'graph> { &mut self, requested_specifier: &ModuleSpecifier, response: &PendingInfoResponse, - maybe_assert_type: Option, + maybe_assert_type: Option, maybe_referrer: Option, maybe_version_info: Option<&DenoPackageVersionInfoExt>, ) { @@ -3099,7 +3099,7 @@ impl<'a, 'graph> Builder<'a, 'graph> { specifier: &ModuleSpecifier, maybe_headers: Option<&HashMap>, content_or_module_info: ContentOrModuleInfo, - maybe_assert_type: Option, + maybe_assert_type: Option, maybe_referrer: Option, maybe_version_info: Option<&DenoPackageVersionInfoExt>, ) -> ModuleSlot { @@ -3177,9 +3177,9 @@ impl<'a, 'graph> Builder<'a, 'graph> { let specifier = &resolved.specifier; let range = &resolved.range; let maybe_assert_type_with_range = dep - .maybe_assert_type + .maybe_attribute_type .as_ref() - .map(|assert_type| AssertTypeWithRange { + .map(|assert_type| AttributeTypeWithRange { range: range.clone(), kind: assert_type.clone(), }); @@ -3210,9 +3210,9 @@ impl<'a, 'graph> Builder<'a, 'graph> { let specifier = &resolved.specifier; let range = &resolved.range; let maybe_assert_type_with_range = dep - .maybe_assert_type + .maybe_attribute_type .as_ref() - .map(|assert_type| AssertTypeWithRange { + .map(|assert_type| AttributeTypeWithRange { range: range.clone(), kind: assert_type.clone(), }); @@ -3559,7 +3559,7 @@ where #[cfg(test)] mod tests { use crate::DefaultModuleAnalyzer; - use crate::ImportAssertion; + use crate::ImportAttribute; use pretty_assertions::assert_eq; use super::*; @@ -4166,7 +4166,7 @@ mod tests { }, }, is_dynamic: false, - assertions: ImportAssertions::None, + attributes: ImportAttributes::None, }, Import { specifier: "file:///bar.ts".to_string(), @@ -4183,7 +4183,7 @@ mod tests { }, }, is_dynamic: false, - assertions: ImportAssertions::None, + attributes: ImportAttributes::None, }, Import { specifier: "file:///bar.ts".to_string(), @@ -4200,7 +4200,7 @@ mod tests { }, }, is_dynamic: false, - assertions: ImportAssertions::None, + attributes: ImportAttributes::None, }, Import { specifier: "file:///bar.ts".to_string(), @@ -4217,7 +4217,7 @@ mod tests { }, }, is_dynamic: true, - assertions: ImportAssertions::None, + attributes: ImportAttributes::None, }, Import { specifier: "file:///bar.ts".to_string(), @@ -4234,7 +4234,7 @@ mod tests { }, }, is_dynamic: true, - assertions: ImportAssertions::Unknown, + attributes: ImportAttributes::Unknown, }, Import { specifier: "file:///bar.ts".to_string(), @@ -4251,7 +4251,7 @@ mod tests { }, }, is_dynamic: false, - assertions: ImportAssertions::None, + attributes: ImportAttributes::None, }, ] ); @@ -4272,9 +4272,9 @@ mod tests { }, }, is_dynamic: false, - assertions: ImportAssertions::Known(HashMap::from_iter(vec![( + attributes: ImportAttributes::Known(HashMap::from_iter(vec![( "type".to_string(), - ImportAssertion::Known("json".to_string()) + ImportAttribute::Known("json".to_string()) )])), },] ); diff --git a/src/lib.rs b/src/lib.rs index 921e89efa..09d1da821 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,8 +22,8 @@ pub use analyzer::analyze_deno_types; pub use analyzer::Comment; pub use analyzer::DependencyDescriptor; pub use analyzer::DependencyKind; -pub use analyzer::ImportAssertion; -pub use analyzer::ImportAssertions; +pub use analyzer::ImportAttribute; +pub use analyzer::ImportAttributes; pub use analyzer::ModuleAnalyzer; pub use analyzer::ModuleInfo; pub use analyzer::PositionRange; @@ -1632,7 +1632,7 @@ export function a(a) { } #[tokio::test] - async fn test_build_graph_import_assertions() { + async fn test_build_graph_import_attributes() { let mut loader = setup( vec![ ( @@ -1641,11 +1641,11 @@ export function a(a) { specifier: "file:///a/test01.ts", maybe_headers: None, content: r#" - import a from "./a.json" assert { type: "json" }; - const b = await import("./b.json", { assert: { type: "json" } }); - export * as c from "./c.json" assert { type: "json" }; + import a from "./a.json" with { type: "json" }; + const b = await import("./b.json", { with: { type: "json" } }); + export * as c from "./c.json" with { type: "json" }; const json = "json"; - const d = await import("./d.json", { assert: { type: json } }); + const d = await import("./d.json", { with: { type: json } }); "#, }, ), @@ -1799,7 +1799,7 @@ export function a(a) { ], "kind": "esm", "mediaType": "TypeScript", - "size": 329, + "size": 321, "specifier": "file:///a/test01.ts" } ], @@ -1968,7 +1968,7 @@ export function a(a) { "modules": [ { "specifier": "file:///a/a.json", - "error": "Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import assertion with the type of \"json\".\n Specifier: file:///a/a.json" + "error": "Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import attribute with the type of \"json\".\n Specifier: file:///a/a.json" }, { "kind": "asserted", @@ -1982,7 +1982,7 @@ export function a(a) { }, { "specifier": "file:///a/d.json", - "error": "The import assertion type of \"css\" is unsupported.\n Specifier: file:///a/d.json" + "error": "The import attribute type of \"css\" is unsupported.\n Specifier: file:///a/d.json" }, { "specifier": "file:///a/e.wasm",