Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deno_ast 0.29 #290

Merged
merged 1 commit into from
Aug 31, 2023
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
58 changes: 26 additions & 32 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 4 additions & 4 deletions js/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -746,7 +746,7 @@ Deno.test({
],
"kind": "esm",
"mediaType": MediaType.JavaScript,
"size": 129,
"size": 125,
"specifier": "file:///a/test01.js",
});
},
Expand Down
2 changes: 1 addition & 1 deletion js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 33 additions & 33 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,66 +169,66 @@ 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<String, ImportAssertion>),
Known(HashMap<String, ImportAttribute>),
}

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(),
),
}
}

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,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -391,7 +391,7 @@ mod test {
character: 4,
},
},
import_assertions: ImportAssertions::None,
import_attributes: ImportAttributes::None,
},
DependencyDescriptor {
kind: DependencyKind::Export,
Expand All @@ -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),
])),
},
]),
Expand All @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -575,7 +575,7 @@ mod test {
"range": [[0, 0], [0, 0]],
"specifier": "./test",
"specifierRange": [[0, 0], [0, 0]],
"importAssertions": "unknown",
"importAttributes": "unknown",
}),
);
}
Expand Down
Loading
Loading