Skip to content

Commit 3a51140

Browse files
authored
refactor(es): Make the code compile with miri (#8836)
1 parent c90c199 commit 3a51140

File tree

10 files changed

+13
-35
lines changed

10 files changed

+13
-35
lines changed

crates/swc_ecma_codegen/src/comments.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use swc_common::comments::CommentKind;
2-
31
use super::*;
42

53
macro_rules! write_comments {

crates/swc_ecma_codegen/src/text_writer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use swc_common::Span;
2-
31
pub use self::{basic_impl::JsWriter, semicolon::omit_trailing_semi};
42
use super::*;
53

crates/swc_ecma_parser/src/lexer/jsx.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use either::Either;
22

33
use super::*;
4-
use crate::token::Token;
54

65
impl<'a> Lexer<'a> {
76
pub(super) fn read_jsx_token(&mut self) -> LexResult<Option<Token>> {

crates/swc_ecma_parser/src/lexer/number.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use std::{borrow::Cow, fmt::Write};
77
use either::Either;
88
use num_bigint::BigInt as BigIntValue;
99
use num_traits::{Num as NumTrait, ToPrimitive};
10-
use smartstring::{LazyCompact, SmartString};
10+
use smartstring::LazyCompact;
1111
use swc_common::SyntaxContext;
1212
use tracing::trace;
1313

1414
use super::*;
15-
use crate::error::SyntaxError;
1615

1716
struct LazyBigInt<const RADIX: u8> {
1817
value: String,

crates/swc_ecma_parser/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,20 @@ expose!(parse_file_as_script, Script, |p| { p.parse_script() });
509509
expose!(parse_file_as_program, Program, |p| { p.parse_program() });
510510

511511
#[inline(always)]
512-
#[cfg(any(target_arch = "wasm32", target_arch = "arm", not(feature = "stacker")))]
512+
#[cfg(any(
513+
target_arch = "wasm32",
514+
target_arch = "arm",
515+
not(feature = "stacker"),
516+
// miri does not work with stacker
517+
miri
518+
))]
513519
fn maybe_grow<R, F: FnOnce() -> R>(_red_zone: usize, _stack_size: usize, callback: F) -> R {
514520
callback()
515521
}
516522

517523
#[inline(always)]
518524
#[cfg(all(
519-
not(any(target_arch = "wasm32", target_arch = "arm")),
525+
not(any(target_arch = "wasm32", target_arch = "arm", miri)),
520526
feature = "stacker"
521527
))]
522528
fn maybe_grow<R, F: FnOnce() -> R>(red_zone: usize, stack_size: usize, callback: F) -> R {

crates/swc_ecma_parser/src/parser/class_and_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use swc_common::{Spanned, SyntaxContext};
22

33
use super::*;
4-
use crate::{error::SyntaxError, lexer::TokenContext, Tokens};
4+
use crate::lexer::TokenContext;
55

66
/// Parser for function expression and function declaration.
77
impl<I: Tokens> Parser<I> {

crates/swc_ecma_parser/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use either::Either;
2-
use swc_common::{ast_node, collections::AHashMap, util::take::Take, Spanned};
2+
use swc_common::{ast_node, util::take::Take, Spanned};
33

44
use super::{pat::PatType, util::ExprExt, *};
55
use crate::{lexer::TokenContext, parser::class_and_fn::IsSimpleParameterList};

crates/swc_ecma_parser/src/parser/expr/ops.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Parser for unary operations and binary operations.
2-
use swc_common::Spanned;
32
use tracing::trace;
43

54
use super::*;

crates/swc_ecma_parser/src/parser/jsx.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use either::Either;
2-
use swc_common::{Span, Spanned, SyntaxContext};
2+
use swc_common::{Spanned, SyntaxContext};
33

44
use super::*;
55

@@ -439,27 +439,6 @@ impl<I: Tokens> Parser<I> {
439439
}
440440
}
441441

442-
trait IsFragment {
443-
fn is_fragment(&self) -> bool;
444-
}
445-
446-
impl IsFragment for Either<JSXOpeningFragment, JSXOpeningElement> {
447-
fn is_fragment(&self) -> bool {
448-
matches!(*self, Either::Left(..))
449-
}
450-
}
451-
452-
impl IsFragment for Either<JSXClosingFragment, JSXClosingElement> {
453-
fn is_fragment(&self) -> bool {
454-
matches!(*self, Either::Left(..))
455-
}
456-
}
457-
impl<T: IsFragment> IsFragment for Option<T> {
458-
fn is_fragment(&self) -> bool {
459-
self.as_ref().map(|s| s.is_fragment()).unwrap_or(false)
460-
}
461-
}
462-
463442
fn get_qualified_jsx_name(name: &JSXElementName) -> JsWord {
464443
fn get_qualified_obj_name(obj: &JSXObject) -> JsWord {
465444
match *obj {

crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use swc_common::{
66
util::take::Take,
77
Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
88
};
9-
use swc_ecma_ast::{Ident, Lit, *};
9+
use swc_ecma_ast::*;
1010
use swc_ecma_transforms_base::{
1111
ext::ExprRefExt,
1212
pass::RepeatedJsPass,

0 commit comments

Comments
 (0)