oxc_ecmascript/side_effects/
context.rs

1use oxc_ast::ast::Expression;
2
3use crate::GlobalContext;
4
5#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
6pub enum PropertyReadSideEffects {
7    /// Treat all property read accesses as side effect free.
8    None,
9    /// Treat all property read accesses as possible side effects.
10    #[default]
11    All,
12}
13
14pub trait MayHaveSideEffectsContext<'a>: GlobalContext<'a> {
15    /// Whether to respect the pure annotations.
16    ///
17    /// Pure annotations are the comments that marks that a expression is pure.
18    /// For example, `/* @__PURE__ */`, `/* #__NO_SIDE_EFFECTS__ */`.
19    ///
20    /// <https://rollupjs.org/configuration-options/#treeshake-annotations>
21    fn annotations(&self) -> bool;
22
23    /// Whether to treat this function call as pure.
24    ///
25    /// This function is called for normal function calls, new calls, and
26    /// tagged template calls (`foo()`, `new Foo()`, ``foo`b` ``).
27    ///
28    /// <https://rollupjs.org/configuration-options/#treeshake-manualpurefunctions>
29    fn manual_pure_functions(&self, callee: &Expression) -> bool;
30
31    /// Whether property read accesses have side effects.
32    ///
33    /// <https://rollupjs.org/configuration-options/#treeshake-propertyreadsideeffects>
34    fn property_read_side_effects(&self) -> PropertyReadSideEffects;
35
36    /// Whether accessing a global variable has side effects.
37    ///
38    /// Accessing a non-existing global variable will throw an error.
39    /// Global variable may be a getter that has side effects.
40    ///
41    /// <https://rollupjs.org/configuration-options/#treeshake-unknownglobalsideeffects>
42    fn unknown_global_side_effects(&self) -> bool;
43}