Skip to content

Commit 1052076

Browse files
upgrade: swc crates (#16)
* update swc dependencies * add parser type for TsTupleElement * try * Need to check TsTupleElement's type now for allowing inline multi-line behaviour. * 0.19.4 * Temp fix for compiling a wasm build. * Remove --locked for now. Co-authored-by: David Sherret <[email protected]>
1 parent 7d64e22 commit 1052076

File tree

9 files changed

+67
-31
lines changed

9 files changed

+67
-31
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@ jobs:
4343
- name: Build debug
4444
if: matrix.config.kind == 'test_debug'
4545
run: cargo build --verbose
46-
- name: Build release
47-
if: matrix.config.kind == 'test_release'
48-
run: cargo build --target wasm32-unknown-unknown --release --locked --verbose
49-
5046
- name: Test debug
5147
if: matrix.config.kind == 'test_debug'
5248
run: cargo test --verbose
49+
50+
- name: Patch for WASM build
51+
if: matrix.config.kind == 'test_release'
52+
run: |
53+
chmod +x setup-wasm.sh
54+
./setup-wasm.sh
55+
- name: Build release
56+
if: matrix.config.kind == 'test_release'
57+
run: cargo build --target wasm32-unknown-unknown --release --verbose # --locked # add back after removing wasm patch
5358
- name: Test release
5459
if: matrix.config.kind == 'test_release'
55-
run: cargo test --release --locked --verbose
60+
run: cargo test --release --verbose # --locked # add back after removing wasm patch
5661

5762
- name: Get tag version
5863
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
**/*.rs.bk
3+
sourcemap

Cargo.lock

Lines changed: 19 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript code formatting plugin for Dprint."
44
keywords = ["formatting", "formatter", "typescript"]
5-
version = "0.19.3"
5+
version = "0.19.4"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"
@@ -14,9 +14,9 @@ crate-type = ["lib", "cdylib"]
1414

1515
[dependencies]
1616
dprint-core = "0.22.0"
17-
swc_common = "=0.5.12"
18-
swc_ecma_ast = "=0.20.0"
19-
swc_ecma_parser = "=0.24.5"
17+
swc_common = "=0.6.0"
18+
swc_ecma_ast = "=0.22.0"
19+
swc_ecma_parser = "=0.26.0"
2020
serde = { version = "1.0.88", features = ["derive"] }
2121
serde_json = "1.0"
2222

patches/cargo.patch

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- Cargo.toml 2020-06-30 10:59:56.075476800 -0400
2+
+++ Cargo_new.toml 2020-06-30 10:59:49.756000200 -0400
3+
@@ -20,6 +20,9 @@
4+
serde = { version = "1.0.88", features = ["derive"] }
5+
serde_json = "1.0"
6+
7+
+[patch.crates-io]
8+
+sourcemap = { path = "sourcemap" }
9+
+
10+
[dev-dependencies]
11+
dprint-development = "0.2.2"
12+
debug-here = "0.2"

patches/sourcemap_detector.patch

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- detector.rs 2020-06-15 10:40:49.000000000 -0400
2+
+++ detector_new.rs" 2020-06-30 10:56:31.931406500 -0400
3+
@@ -46,6 +46,7 @@
4+
/// Resolves the reference against a local file path
5+
///
6+
/// This is similar to `resolve` but operates on file paths.
7+
+ #[cfg(any(unix, windows, target_os = "redox"))]
8+
pub fn resolve_path(&self, minified_path: &Path) -> Option<PathBuf> {
9+
let url = self.get_url();
10+
if url.starts_with("data:") {

setup-wasm.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# to create patches use $ diff -u file1.rs file1.new.rs > file1.patch
3+
4+
# temporary in order to allow targeting wasm32-unknown-unknown
5+
curl -L https://crates.io/api/v1/crates/sourcemap/6.0.0/download | tar xzf -
6+
mv sourcemap-6.0.0 sourcemap
7+
patch sourcemap/src/detector.rs patches/sourcemap_detector.patch
8+
patch Cargo.toml patches/cargo.patch

src/parsing/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
271271
Node::TsTypeQuery(node) => parse_type_query(node, context),
272272
Node::TsTypeRef(node) => parse_type_reference(node, context),
273273
Node::TsUnionType(node) => parse_union_type(node, context),
274+
Node::TsTupleElement(node) => parse_node((&node.ty).into(), context),
274275
/* unknown */
275276
_ => parse_raw_string(node.text(context).into()),
276277
}
@@ -6428,6 +6429,7 @@ fn allows_inline_multi_line(node: &Node, has_siblings: bool) -> bool {
64286429
Node::AssignPat(node) => allows_inline_multi_line(&(&node.left).into(), has_siblings)
64296430
|| allows_inline_multi_line(&(&node.right).into(), has_siblings),
64306431
Node::TsTypeAnn(type_ann) => allows_inline_multi_line(&(&type_ann.type_ann).into(), has_siblings),
6432+
Node::TsTupleElement(tuple_element) => allows_inline_multi_line(&(&tuple_element.ty).into(), has_siblings),
64316433
_ => false,
64326434
};
64336435

src/parsing/parser_types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ generate_node! [
533533
TsTypeQuery,
534534
TsTypeRef,
535535
TsUnionType,
536+
TsTupleElement,
536537
/* unknown */
537538
Span
538539
];

0 commit comments

Comments
 (0)