Skip to content

Commit

Permalink
feat: support concurrent diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
spence committed May 17, 2024
1 parent 91bb1ef commit f763ed2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typescript = ["transforms", "swc_ecma_transforms_typescript"]
utils = ["swc_ecma_utils"]
view = ["dprint-swc-ext/view"]
visit = ["swc_ecma_visit", "swc_visit", "swc_visit_macros", "swc_macros_common"]
concurrent = ["swc_common/concurrent"]

[dependencies]
anyhow = { version = "1.0.64", optional = true }
Expand Down
9 changes: 4 additions & 5 deletions src/source_map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use std::rc::Rc;

use swc_common::sync::Lrc;
use crate::swc::common::FileName;
use crate::swc::common::SourceFile;

Expand Down Expand Up @@ -31,7 +30,7 @@ impl IntoSwcFileName for &str {

#[derive(Clone, Default)]
pub struct SourceMap {
inner: Rc<crate::swc::common::SourceMap>,
inner: Lrc<crate::swc::common::SourceMap>,
}

impl SourceMap {
Expand All @@ -43,15 +42,15 @@ impl SourceMap {
map
}

pub fn inner(&self) -> &Rc<crate::swc::common::SourceMap> {
pub fn inner(&self) -> &Lrc<crate::swc::common::SourceMap> {
&self.inner
}

pub fn new_source_file(
&self,
file_name: impl IntoSwcFileName,
source: String,
) -> Rc<SourceFile> {
) -> Lrc<SourceFile> {
self
.inner
.new_source_file(file_name.into_file_name(), source)
Expand Down
7 changes: 5 additions & 2 deletions src/transpiling/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use std::rc::Rc;
use std::sync::Arc;
use swc_common::sync::{Lrc, Send, Sync};

use anyhow::Result;
use swc_ecma_visit::as_folder;
Expand Down Expand Up @@ -308,9 +308,12 @@ fn transpile(

#[derive(Default, Clone)]
struct DiagnosticCollector {
diagnostics_cell: Rc<RefCell<Vec<SwcDiagnostic>>>,
diagnostics_cell: Lrc<RefCell<Vec<SwcDiagnostic>>>,
}

unsafe impl Send for DiagnosticCollector {}
unsafe impl Sync for DiagnosticCollector {}

impl DiagnosticCollector {
pub fn into_handler(self) -> crate::swc::common::errors::Handler {
crate::swc::common::errors::Handler::with_emitter(
Expand Down

0 comments on commit f763ed2

Please sign in to comment.