Skip to content

fix: panic due to scope analysis before transpile #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions api/Cargo.lock

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

6 changes: 3 additions & 3 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ deno_semver = "0.5.2"
flate2 = "1"
thiserror = "1"
async-tar = "0.4.2"
deno_graph = "0.71.2"
deno_ast = "0.36.1"
deno_doc = { version = "0.123.0", features = ["tree-sitter"] }
deno_graph = "0.72.0"
deno_ast = "0.37.0"
deno_doc = { version = "0.124.0", features = ["tree-sitter"] }
comrak = { version = "0.20.0", default-features = false }
async-trait = "0.1.73"
jsonwebkey = { version = "0.3.5", features = ["jsonwebtoken", "jwt-convert"] }
Expand Down
16 changes: 7 additions & 9 deletions api/src/npm/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use deno_ast::swc::ast::Lit;
use deno_ast::swc::ast::Module;
use deno_ast::swc::ast::NamedExport;
use deno_ast::swc::ast::Str;
use deno_ast::swc::common::Globals;
use deno_ast::swc::common::Mark;
use deno_ast::swc::visit::as_folder;
use deno_ast::swc::visit::noop_visit_mut_type;
use deno_ast::swc::visit::FoldWith;
Expand Down Expand Up @@ -45,22 +43,22 @@ pub fn transpile_to_js(
let source_map =
SourceMap::single(source_url, source.text_info().text_str().to_string());

let mut folder = as_folder(NpmImportTransform);
let program = source.program_ref().clone().fold_with(&mut folder);

// needs to align with what's done internally in source map
assert_eq!(1, source.text_info().range().start.as_byte_pos().0);
// we need the comments to be mutable, so make it single threaded
let comments = source.comments().as_single_threaded();
let globals = Globals::new();
deno_ast::swc::common::GLOBALS.set(&globals, || {
let top_level_mark = Mark::fresh(Mark::root());
source.globals().with(|marks| {
let mut folder = as_folder(NpmImportTransform);
// todo(dsherret): this shouldn't clone the entire program. Probably we
// should add a way to run `transpile` with custom folders
let program = source.program_ref().clone().fold_with(&mut folder);

let program = fold_program(
program,
&transpile_options,
&source_map,
&comments,
top_level_mark,
marks,
source.diagnostics(),
)?;

Expand Down