1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(vendor): do not add absolute specifiers to scopes (#13710)

This commit is contained in:
David Sherret 2022-02-18 23:10:40 -05:00 committed by GitHub
parent 6830e004e6
commit 5d7e1229db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 6 deletions

View file

@ -568,6 +568,57 @@ mod test {
);
}
#[tokio::test]
async fn same_origin_absolute_with_redirect() {
let mut builder = VendorTestBuilder::with_default_setup();
let output = builder
.with_loader(|loader| {
loader
.add(
"/mod.ts",
r#"import "https://localhost/subdir/sub/mod.ts";"#,
)
.add(
"https://localhost/subdir/sub/mod.ts",
"import 'https://localhost/std/hash/mod.ts'",
)
.add_redirect(
"https://localhost/std/hash/mod.ts",
"https://localhost/std@0.1.0/hash/mod.ts",
)
.add(
"https://localhost/std@0.1.0/hash/mod.ts",
"export class Test {}",
);
})
.build()
.await
.unwrap();
assert_eq!(
output.import_map,
Some(json!({
"imports": {
"https://localhost/": "./localhost/",
"https://localhost/std/hash/mod.ts": "./localhost/std@0.1.0/hash/mod.ts"
}
}))
);
assert_eq!(
output.files,
to_file_vec(&[
(
"/vendor/localhost/std@0.1.0/hash/mod.ts",
"export class Test {}"
),
(
"/vendor/localhost/subdir/sub/mod.ts",
"import 'https://localhost/std/hash/mod.ts'"
),
]),
);
}
fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> {
items
.iter()

View file

@ -213,12 +213,7 @@ fn handle_dep_specifier(
return;
}
if referrer.origin() == specifier.origin() {
let imports = import_map.scope(base_specifier);
imports.add(sub_path.to_string(), &specifier);
} else {
import_map.imports.add(text.to_string(), &specifier);
}
import_map.imports.add(text.to_string(), &specifier);
} else {
let expected_relative_specifier_text =
mappings.relative_specifier_text(referrer, &specifier);