Skip to content

Commit 9b08b3d

Browse files
committed
fix
1 parent 94d8530 commit 9b08b3d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/core/test-utils/src/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ function prepareNodeContext(
946946
}
947947

948948
if (path.extname(res) === '.node') {
949+
// $FlowFixMe[unsupported-syntax]
949950
return require(res);
950951
}
951952

packages/transformers/js/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn transform(
485485
source_map: source_map.clone(),
486486
items: &mut global_deps,
487487
global_mark,
488-
globals: HashMap::new(),
488+
globals: IndexMap::new(),
489489
filename: Path::new(&config.filename),
490490
unresolved_mark,
491491
has_node_replacements: &mut result.has_node_replacements,

packages/transformers/js/core/src/node_replacer.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::{collections::HashMap, ffi::OsStr, path::Path};
1+
use std::{ffi::OsStr, path::Path};
22

3+
use indexmap::IndexMap;
34
use swc_core::{
45
common::{sync::Lrc, Mark, SourceMap, SyntaxContext, DUMMY_SP},
56
ecma::{
@@ -24,7 +25,7 @@ use crate::{
2425
pub struct NodeReplacer<'a> {
2526
pub source_map: Lrc<SourceMap>,
2627
pub global_mark: Mark,
27-
pub globals: HashMap<JsWord, (SyntaxContext, ast::Stmt)>,
28+
pub globals: IndexMap<JsWord, (SyntaxContext, ast::Stmt)>,
2829
pub filename: &'a Path,
2930
pub is_esm: bool,
3031
pub unresolved_mark: Mark,
@@ -186,7 +187,7 @@ impl<'a> VisitMut for NodeReplacer<'a> {
186187
0..0,
187188
self
188189
.globals
189-
.drain()
190+
.drain(..)
190191
.map(|(_, (_, stmt))| ast::ModuleItem::Stmt(stmt)),
191192
);
192193
}
@@ -268,7 +269,7 @@ console.log(__filename);
268269
let output_code = run_visit(code, |context| NodeReplacer {
269270
source_map: context.source_map.clone(),
270271
global_mark: context.global_mark,
271-
globals: HashMap::new(),
272+
globals: IndexMap::new(),
272273
filename: Path::new("/path/random.js"),
273274
has_node_replacements: &mut has_node_replacements,
274275
items: &mut items,
@@ -303,7 +304,7 @@ console.log(__dirname);
303304
let output_code = run_visit(code, |context| NodeReplacer {
304305
source_map: context.source_map.clone(),
305306
global_mark: context.global_mark,
306-
globals: HashMap::new(),
307+
globals: IndexMap::new(),
307308
filename: Path::new("/path/random.js"),
308309
has_node_replacements: &mut has_node_replacements,
309310
items: &mut items,
@@ -341,7 +342,7 @@ function something(__filename, __dirname) {
341342
let output_code = run_visit(code, |context| NodeReplacer {
342343
source_map: context.source_map.clone(),
343344
global_mark: context.global_mark,
344-
globals: HashMap::new(),
345+
globals: IndexMap::new(),
345346
filename: Path::new("/path/random.js"),
346347
has_node_replacements: &mut has_node_replacements,
347348
items: &mut items,
@@ -374,7 +375,7 @@ const filename = obj.__filename;
374375
let output_code = run_visit(code, |context| NodeReplacer {
375376
source_map: context.source_map.clone(),
376377
global_mark: context.global_mark,
377-
globals: HashMap::new(),
378+
globals: IndexMap::new(),
378379
filename: Path::new("/path/random.js"),
379380
has_node_replacements: &mut has_node_replacements,
380381
items: &mut items,
@@ -403,7 +404,7 @@ const filename = obj[__filename];
403404
let output_code = run_visit(code, |context| NodeReplacer {
404405
source_map: context.source_map.clone(),
405406
global_mark: context.global_mark,
406-
globals: HashMap::new(),
407+
globals: IndexMap::new(),
407408
filename: Path::new("/path/random.js"),
408409
has_node_replacements: &mut has_node_replacements,
409410
items: &mut items,
@@ -434,7 +435,7 @@ console.log(__dirname);
434435
let output_code = run_visit(code, |context| NodeReplacer {
435436
source_map: context.source_map.clone(),
436437
global_mark: context.global_mark,
437-
globals: HashMap::new(),
438+
globals: IndexMap::new(),
438439
filename: Path::new("/path/random.js"),
439440
has_node_replacements: &mut has_node_replacements,
440441
items: &mut items,

0 commit comments

Comments
 (0)