1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

Update to dprint 0.18.3 and the latest version of swc (#5509)

This commit is contained in:
David Sherret 2020-05-17 12:56:22 -04:00 committed by GitHub
parent e16eb9e108
commit a054250a2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 131 additions and 38 deletions

46
Cargo.lock generated
View file

@ -16,15 +16,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
[[package]]
name = "ahash"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f33b5018f120946c1dcf279194f238a9f146725593ead1c08fa47ff22b0b5d3"
dependencies = [
"const-random",
]
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.3.2" version = "0.3.2"
@ -462,7 +453,7 @@ version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93b8a57df1b6a3f0a96df85297d506a871b31252df23f969b9837ccb5d07455c" checksum = "93b8a57df1b6a3f0a96df85297d506a871b31252df23f969b9837ccb5d07455c"
dependencies = [ dependencies = [
"ahash 0.3.2", "ahash",
"cfg-if", "cfg-if",
"num_cpus", "num_cpus",
] ]
@ -627,9 +618,9 @@ dependencies = [
[[package]] [[package]]
name = "dprint-plugin-typescript" name = "dprint-plugin-typescript"
version = "0.17.2" version = "0.18.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e945fe5978d1cb0edddf522dc360c8a5d691ecd2fe98a9de74efb3997ed0ec6" checksum = "63a30d83f56d1adb78643a99a81fe25b5b9b6bff7798623a13caa12040f9899d"
dependencies = [ dependencies = [
"dprint-core", "dprint-core",
"serde", "serde",
@ -945,16 +936,6 @@ dependencies = [
"tokio-util", "tokio-util",
] ]
[[package]]
name = "hashbrown"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6073d0ca812575946eb5f35ff68dbe519907b25c42530389ff946dc84c6ead"
dependencies = [
"ahash 0.2.18",
"autocfg 0.1.7",
]
[[package]] [[package]]
name = "headers" name = "headers"
version = "0.3.2" version = "0.3.2"
@ -2411,9 +2392,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_common" name = "swc_common"
version = "0.5.9" version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f17c61920fa7307f5ea35ecf5f05d455a2610cdb2582dbcf81dbeaa361a3788" checksum = "ac5dc408a5004d6d82914e8c415f4c2a8c716b53ff766ab13af9bf0e5a286d98"
dependencies = [ dependencies = [
"ast_node", "ast_node",
"atty", "atty",
@ -2422,7 +2403,6 @@ dependencies = [
"either", "either",
"from_variant", "from_variant",
"fxhash", "fxhash",
"hashbrown",
"log 0.4.8", "log 0.4.8",
"parking_lot 0.7.1", "parking_lot 0.7.1",
"scoped-tls", "scoped-tls",
@ -2435,9 +2415,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_ast" name = "swc_ecma_ast"
version = "0.18.1" version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31fb43e08500984ecb795ac12cc41a7dac3e55cc649a5e576fd808917a35a525" checksum = "cb6105718e50b118ff100acda244b6df4f3f46de76b03e5d1baeaa3e69f97a6a"
dependencies = [ dependencies = [
"enum_kind", "enum_kind",
"num-bigint", "num-bigint",
@ -2449,9 +2429,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_parser" name = "swc_ecma_parser"
version = "0.21.10" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb9f7ffcb1d0fac1a6002a5775ef56defcc44dff43e333bbe6fe3804062fde1" checksum = "6ddb997ff7671faf7e55040233ed814bed1f69b6d1ad7a0fe78948ebf42d3d6a"
dependencies = [ dependencies = [
"either", "either",
"enum_kind", "enum_kind",
@ -2483,9 +2463,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_visit" name = "swc_ecma_visit"
version = "0.1.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bdd4d87e6499ff8cc3b32981ab2a3917cea4002a0c4523868181f59d14f4638" checksum = "802b13ac5811ebc6897c9a1ed999aa9ca3dd6faf8e664b9df44e162e2b3a03ed"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"swc_atoms", "swc_atoms",
@ -2496,9 +2476,9 @@ dependencies = [
[[package]] [[package]]
name = "swc_ecma_visit_macros" name = "swc_ecma_visit_macros"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ceb3a3184ba505b3f94fa4132a72e754d361ad9913b7e0dc4f01ab38649a9d26" checksum = "9083af117bcb987631d99129ce57e634315267d84521fd562926135fa49bee38"
dependencies = [ dependencies = [
"Inflector", "Inflector",
"pmutil", "pmutil",

View file

@ -29,7 +29,7 @@ byteorder = "1.3.4"
clap = "2.33.0" clap = "2.33.0"
dirs = "2.0.2" dirs = "2.0.2"
dlopen = "0.1.8" dlopen = "0.1.8"
dprint-plugin-typescript = "0.17.2" dprint-plugin-typescript = "0.18.3"
futures = { version = "0.3.4", features = ["compat", "io-compat"] } futures = { version = "0.3.4", features = ["compat", "io-compat"] }
glob = "0.3.0" glob = "0.3.0"
http = "0.2.1" http = "0.2.1"
@ -60,7 +60,7 @@ walkdir = "2.3.1"
warp = "0.2.2" warp = "0.2.2"
semver-parser = "0.9.0" semver-parser = "0.9.0"
uuid = { version = "0.8.1", features = ["v4"] } uuid = { version = "0.8.1", features = ["v4"] }
swc_ecma_visit = "0.1.0" swc_ecma_visit = "0.4.0"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = "0.3.8" winapi = "0.3.8"

View file

@ -123,10 +123,10 @@ pub fn class_to_class_def(
let mut params = vec![]; let mut params = vec![];
for param in &ctor.params { for param in &ctor.params {
use crate::swc_ecma_ast::PatOrTsParamProp::*; use crate::swc_ecma_ast::ParamOrTsParamProp::*;
let param_def = match param { let param_def = match param {
Pat(pat) => pat_to_param_def(pat), Param(param) => pat_to_param_def(&param.pat),
TsParamProp(ts_param_prop) => { TsParamProp(ts_param_prop) => {
use swc_ecma_ast::TsParamPropParam; use swc_ecma_ast::TsParamPropParam;

View file

@ -25,7 +25,7 @@ pub fn function_to_function_def(
let mut params = vec![]; let mut params = vec![];
for param in &function.params { for param in &function.params {
let param_def = pat_to_param_def(param); let param_def = pat_to_param_def(&param.pat);
params.push(param_def); params.push(param_def);
} }

View file

@ -1435,3 +1435,101 @@ export function fooFn(a: number) {
.contains("function fooFn(a: number)") .contains("function fooFn(a: number)")
); );
} }
#[tokio::test]
async fn ts_lit_types() {
let source_code = r#"
export type boolLit = false;
export type strLit = "text";
export type tplLit = `text`;
export type numLit = 5;
"#;
let loader =
TestLoader::new(vec![("test.ts".to_string(), source_code.to_string())]);
let entries = DocParser::new(loader).parse("test.ts").await.unwrap();
let actual = serde_json::to_value(entries).unwrap();
let expected_json = json!([
{
"kind": "typeAlias",
"name": "boolLit",
"location": {
"filename": "test.ts",
"line": 2,
"col": 0
},
"jsDoc": null,
"typeAliasDef": {
"tsType": {
"repr": "false",
"kind": "literal",
"literal": {
"kind": "boolean",
"boolean": false
}
},
"typeParams": []
}
}, {
"kind": "typeAlias",
"name": "strLit",
"location": {
"filename": "test.ts",
"line": 3,
"col": 0
},
"jsDoc": null,
"typeAliasDef": {
"tsType": {
"repr": "text",
"kind": "literal",
"literal": {
"kind": "string",
"string": "text"
}
},
"typeParams": []
}
}, {
"kind": "typeAlias",
"name": "tplLit",
"location": {
"filename": "test.ts",
"line": 4,
"col": 0
},
"jsDoc": null,
"typeAliasDef": {
"tsType": {
"repr": "text",
"kind": "literal",
"literal": {
"kind": "string",
"string": "text"
}
},
"typeParams": []
}
}, {
"kind": "typeAlias",
"name": "numLit",
"location": {
"filename": "test.ts",
"line": 5,
"col": 0
},
"jsDoc": null,
"typeAliasDef": {
"tsType": {
"repr": "5",
"kind": "literal",
"literal": {
"kind": "number",
"number": 5.0
}
},
"typeParams": []
}
}
]);
assert_eq!(actual, expected_json);
}

View file

@ -69,6 +69,21 @@ impl Into<TsTypeDef> for &TsLitType {
boolean: None, boolean: None,
}, },
), ),
TsLit::Tpl(tpl) => {
// A template literal in a type is not allowed to have
// expressions, so there will only be one quasi.
let quasi = tpl.quasis.get(0).expect("Expected tpl to have a quasi.");
let text = quasi.raw.value.to_string();
(
text.clone(),
LiteralDef {
kind: LiteralDefKind::String, // semantically the same
number: None,
string: Some(text),
boolean: None,
},
)
}
TsLit::Bool(bool_) => ( TsLit::Bool(bool_) => (
bool_.value.to_string(), bool_.value.to_string(),
LiteralDef { LiteralDef {