Skip to content

Commit

Permalink
Make ModuleSpecifier a type alias, not wrapper struct (denoland#9531)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Feb 17, 2021
1 parent f6d6b24 commit c7dabc9
Show file tree
Hide file tree
Showing 34 changed files with 594 additions and 801 deletions.
24 changes: 10 additions & 14 deletions cli/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::media_type::MediaType;
use crate::tsc_config;

use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
use deno_core::ModuleSpecifier;
use std::error::Error;
Expand Down Expand Up @@ -78,7 +79,7 @@ impl Into<Location> for swc_common::Loc {

impl Into<ModuleSpecifier> for Location {
fn into(self) -> ModuleSpecifier {
ModuleSpecifier::resolve_url_or_path(&self.filename).unwrap()
resolve_url_or_path(&self.filename).unwrap()
}
}

Expand Down Expand Up @@ -593,9 +594,7 @@ mod tests {

#[test]
fn test_parsed_module_analyze_dependencies() {
let specifier =
ModuleSpecifier::resolve_url_or_path("https://deno.land/x/mod.js")
.unwrap();
let specifier = resolve_url_or_path("https://deno.land/x/mod.js").unwrap();
let source = r#"import * as bar from "./test.ts";
const foo = await import("./foo.ts");
"#;
Expand Down Expand Up @@ -634,9 +633,8 @@ mod tests {

#[test]
fn test_transpile() {
let specifier =
ModuleSpecifier::resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let specifier = resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let source = r#"
enum D {
A,
Expand Down Expand Up @@ -668,9 +666,8 @@ mod tests {

#[test]
fn test_transpile_tsx() {
let specifier =
ModuleSpecifier::resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let specifier = resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let source = r#"
export class A {
render() {
Expand All @@ -688,9 +685,8 @@ mod tests {

#[test]
fn test_transpile_decorators() {
let specifier =
ModuleSpecifier::resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let specifier = resolve_url_or_path("https://deno.land/x/mod.ts")
.expect("could not resolve specifier");
let source = r#"
function enumerable(value: boolean) {
return function (
Expand All @@ -701,7 +697,7 @@ mod tests {
descriptor.enumerable = value;
};
}
export class A {
@enumerable(false)
a() {
Expand Down
38 changes: 14 additions & 24 deletions cli/auth_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ impl AuthTokens {
/// matching is case insensitive.
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<AuthToken> {
self.0.iter().find_map(|t| {
let url = specifier.as_url();
let hostname = if let Some(port) = url.port() {
format!("{}:{}", url.host_str()?, port)
let hostname = if let Some(port) = specifier.port() {
format!("{}:{}", specifier.host_str()?, port)
} else {
url.host_str()?.to_string()
specifier.host_str()?.to_string()
};
if hostname.to_lowercase().ends_with(&t.host) {
Some(t.clone())
Expand All @@ -70,46 +69,40 @@ impl AuthTokens {
#[cfg(test)]
mod tests {
use super::*;
use deno_core::resolve_url;

#[test]
fn test_auth_token() {
let auth_tokens = AuthTokens::new(Some("[email protected]".to_string()));
let fixture =
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap();
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer abc123"
);
let fixture =
ModuleSpecifier::resolve_url("https://www.deno.land/x/mod.ts").unwrap();
let fixture = resolve_url("https://www.deno.land/x/mod.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer abc123".to_string()
);
let fixture =
ModuleSpecifier::resolve_url("http:https://127.0.0.1:8080/x/mod.ts").unwrap();
let fixture = resolve_url("http:https://127.0.0.1:8080/x/mod.ts").unwrap();
assert_eq!(auth_tokens.get(&fixture), None);
let fixture =
ModuleSpecifier::resolve_url("https://deno.land.example.com/x/mod.ts")
.unwrap();
resolve_url("https://deno.land.example.com/x/mod.ts").unwrap();
assert_eq!(auth_tokens.get(&fixture), None);
let fixture =
ModuleSpecifier::resolve_url("https://deno.land:8080/x/mod.ts").unwrap();
let fixture = resolve_url("https://deno.land:8080/x/mod.ts").unwrap();
assert_eq!(auth_tokens.get(&fixture), None);
}

#[test]
fn test_auth_tokens_multiple() {
let auth_tokens =
AuthTokens::new(Some("[email protected];[email protected]".to_string()));
let fixture =
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap();
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer abc123".to_string()
);
let fixture =
ModuleSpecifier::resolve_url("http:https://example.com/a/file.ts").unwrap();
let fixture = resolve_url("http:https://example.com/a/file.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer def456".to_string()
Expand All @@ -120,11 +113,9 @@ mod tests {
fn test_auth_tokens_port() {
let auth_tokens =
AuthTokens::new(Some("[email protected]:8080".to_string()));
let fixture =
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap();
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
assert_eq!(auth_tokens.get(&fixture), None);
let fixture =
ModuleSpecifier::resolve_url("http:https://deno.land:8080/x/mod.ts").unwrap();
let fixture = resolve_url("http:https://deno.land:8080/x/mod.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer abc123".to_string()
Expand All @@ -134,8 +125,7 @@ mod tests {
#[test]
fn test_auth_tokens_contain_at() {
let auth_tokens = AuthTokens::new(Some("abc@[email protected]".to_string()));
let fixture =
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap();
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
assert_eq!(
auth_tokens.get(&fixture).unwrap().to_string(),
"Bearer abc@123".to_string()
Expand Down
Loading

0 comments on commit c7dabc9

Please sign in to comment.