Unverified Commit bf4de72c authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: move assignment_scopes computation into ImportMap (#92835)

I'm moving all of the export-related logic into `EvalContext` (and thus `ImportMap`) so that `VarGraph` is only needed for computing the references, and not the exports.

The change in the snapshots is 
```diff
-*anonymous function 170* (const after eval) = (...) => [file]
+*anonymous function 170* = (...) => [file]
```
which is fine, since computing the "is reassigned" data for something that isn't actually a variable was non-sensical anyway.
parent 5fc848b3
...@@ -20,7 +20,7 @@ use turbopack_core::{ ...@@ -20,7 +20,7 @@ use turbopack_core::{
use turbopack_ecmascript::{ use turbopack_ecmascript::{
AnalyzeMode, AnalyzeMode,
analyzer::{ analyzer::{
graph::{EvalContext, VarGraph, VarMeta, create_graph}, graph::{EvalContext, VarGraph, create_graph},
imports::ImportAttributes, imports::ImportAttributes,
linker::link, linker::link,
test_utils::{early_visitor, visitor}, test_utils::{early_visitor, visitor},
...@@ -115,7 +115,7 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) { ...@@ -115,7 +115,7 @@ fn bench_link(b: &mut Bencher, input: &BenchInput) {
b.to_async(rt).iter(|| async { b.to_async(rt).iter(|| async {
let var_cache = Default::default(); let var_cache = Default::default();
for VarMeta { value, .. } in input.var_graph.values.values() { for value in input.var_graph.values.values() {
VcStorage::with(async { VcStorage::with(async {
let compile_time_info = CompileTimeInfo::builder( let compile_time_info = CompileTimeInfo::builder(
Environment::new(ExecutionEnvironment::NodeJsLambda( Environment::new(ExecutionEnvironment::NodeJsLambda(
......
...@@ -32,9 +32,7 @@ use crate::{ ...@@ -32,9 +32,7 @@ use crate::{
analyzer::{WellKnownObjectKind, is_unresolved}, analyzer::{WellKnownObjectKind, is_unresolved},
code_gen::CodeGen, code_gen::CodeGen,
references::{ references::{
constant_value::parse_single_expr_lit, constant_value::parse_single_expr_lit, esm::EsmModuleItem, for_each_ident_in_pat,
esm::{EsmModuleItem, Liveness},
for_each_ident_in_pat,
}, },
utils::{AstPathRange, unparen}, utils::{AstPathRange, unparen},
}; };
...@@ -273,26 +271,34 @@ impl Effect { ...@@ -273,26 +271,34 @@ impl Effect {
} }
} }
#[derive(Debug)]
pub enum AssignmentScope { pub enum AssignmentScope {
/// assigned in the root scope
ModuleEval, ModuleEval,
/// assigned in a function scopes
Function, Function,
} }
/// Tracks the locations where this was assigned to:
/// This is used to track the _liveness_ of exports.
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AssignmentScopes { pub enum AssignmentScopes {
/// assigned only in the root scope
AllInModuleEvalScope, AllInModuleEvalScope,
/// assigned in any set of function scopes
AllInFunctionScopes, AllInFunctionScopes,
/// assigned in both module and function scopes
Mixed, Mixed,
} }
impl AssignmentScopes { impl AssignmentScopes {
fn new(initial: AssignmentScope) -> Self { pub fn new(initial: AssignmentScope) -> Self {
match initial { match initial {
AssignmentScope::ModuleEval => AssignmentScopes::AllInModuleEvalScope, AssignmentScope::ModuleEval => AssignmentScopes::AllInModuleEvalScope,
AssignmentScope::Function => AssignmentScopes::AllInFunctionScopes, AssignmentScope::Function => AssignmentScopes::AllInFunctionScopes,
} }
} }
fn merge(self, other: AssignmentScope) -> Self { pub fn merge(self, other: AssignmentScope) -> Self {
// If the other assignment kind is the same as the current one, return the current one. // If the other assignment kind is the same as the current one, return the current one.
if self == Self::new(other) { if self == Self::new(other) {
self self
...@@ -302,37 +308,6 @@ impl AssignmentScopes { ...@@ -302,37 +308,6 @@ impl AssignmentScopes {
} }
} }
#[derive(Debug, Clone)]
pub struct VarMeta {
pub value: JsValue,
/// Tracks the locations where this was assigned to:
/// - [`AssignmentScopes::AllInModuleEvalScope`] if it was assigned only in the root scope
/// - [`AssignmentScopes::AllInFunctionScopes`] if it was assigned in any set of function
/// scopes
/// - [`AssignmentScopes::Mixed`] if it was assigned in both
///
/// This is used to track the _liveness_ of exports.
pub assignment_scopes: AssignmentScopes,
}
impl VarMeta {
pub fn new(value: JsValue, kind: AssignmentScope) -> Self {
Self {
value,
assignment_scopes: AssignmentScopes::new(kind),
}
}
pub fn normalize(&mut self) {
self.value.normalize();
}
fn add_alt(&mut self, value: JsValue, kind: AssignmentScope) {
self.value.add_alt(value);
self.assignment_scopes = self.assignment_scopes.merge(kind);
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum DeclUsage { pub enum DeclUsage {
SideEffects, SideEffects,
...@@ -359,7 +334,7 @@ impl DeclUsage { ...@@ -359,7 +334,7 @@ impl DeclUsage {
#[derive(Debug)] #[derive(Debug)]
pub struct VarGraph { pub struct VarGraph {
pub values: FxHashMap<Id, VarMeta>, pub values: FxHashMap<Id, JsValue>,
/// Map [`JsValue::FreeVar`] names to their [`Id`] to facilitate lookups into [`Self::values`]. /// Map [`JsValue::FreeVar`] names to their [`Id`] to facilitate lookups into [`Self::values`].
/// ///
...@@ -388,29 +363,6 @@ impl VarGraph { ...@@ -388,29 +363,6 @@ impl VarGraph {
effect.normalize(); effect.normalize();
} }
} }
/// Returns the liveness of a given export identifier. An export is live if it might
/// change values after module evaluation.
pub fn get_export_ident_liveness(&self, id: Id) -> Liveness {
if let Some(VarMeta {
value: _,
assignment_scopes: assignment_kinds,
}) = self.values.get(&id)
{
// If all assignments are in module scope, the export is not live.
if *assignment_kinds != AssignmentScopes::AllInModuleEvalScope {
Liveness::Live
} else {
Liveness::Constant
}
} else {
// If we haven't computed a value for it, that means it might be
// - A free variable or
// - an imported variable
// In those cases, we just assume that the value is live since we don't know anything
Liveness::Live
}
}
} }
pub fn create_graph( pub fn create_graph(
...@@ -1556,15 +1508,10 @@ impl Analyzer<'_> { ...@@ -1556,15 +1508,10 @@ impl Analyzer<'_> {
self.data.free_var_ids.insert(id.0.clone(), id.clone()); self.data.free_var_ids.insert(id.0.clone(), id.clone());
} }
let kind = if self.is_in_fn() {
AssignmentScope::Function
} else {
AssignmentScope::ModuleEval
};
if let Some(prev) = self.data.values.get_mut(&id) { if let Some(prev) = self.data.values.get_mut(&id) {
prev.add_alt(value, kind); prev.add_alt(value);
} else { } else {
self.data.values.insert(id, VarMeta::new(value, kind)); self.data.values.insert(id, value);
} }
// TODO(kdy1): We may need to report an error for this. // TODO(kdy1): We may need to report an error for this.
// Variables declared with `var` are hoisted, but using undefined as its // Variables declared with `var` are hoisted, but using undefined as its
......
use std::{borrow::Cow, collections::BTreeMap, fmt::Display, sync::Arc}; use std::{
borrow::Cow,
collections::{BTreeMap, hash_map::Entry},
fmt::Display,
sync::Arc,
};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
...@@ -22,7 +27,10 @@ use turbopack_core::loader::WebpackLoaderItem; ...@@ -22,7 +27,10 @@ use turbopack_core::loader::WebpackLoaderItem;
use super::{JsValue, ModuleValue, top_level_await::has_top_level_await}; use super::{JsValue, ModuleValue, top_level_await::has_top_level_await};
use crate::{ use crate::{
SpecifiedModuleType, SpecifiedModuleType,
analyzer::{ConstantValue, ObjectPart, graph::VarGraph}, analyzer::{
ConstantValue, ObjectPart,
graph::{AssignmentScope, AssignmentScopes, EvalContext},
},
magic_identifier::{MAGIC_IDENTIFIER_DEFAULT_EXPORT, MAGIC_IDENTIFIER_DEFAULT_EXPORT_ATOM}, magic_identifier::{MAGIC_IDENTIFIER_DEFAULT_EXPORT, MAGIC_IDENTIFIER_DEFAULT_EXPORT_ATOM},
references::{ references::{
esm::{EsmAssetReference, EsmExport, Liveness}, esm::{EsmAssetReference, EsmExport, Liveness},
...@@ -311,6 +319,10 @@ pub(crate) struct ImportMap { ...@@ -311,6 +319,10 @@ pub(crate) struct ImportMap {
/// as a whole. /// as a whole.
full_star_imports: FxHashSet<Wtf8Atom>, full_star_imports: FxHashSet<Wtf8Atom>,
/// Map from export binding id to the scopes where it's assigned. This is used to determine
/// whether an export is live or not.
pub(super) assignment_scopes: FxHashMap<Id, AssignmentScopes>,
/// Map from exported name to local binding id (includes the syntax context). /// Map from exported name to local binding id (includes the syntax context).
pub(crate) exports_ids: FxHashMap<RcStr, Id>, pub(crate) exports_ids: FxHashMap<RcStr, Id>,
} }
...@@ -481,7 +493,7 @@ impl ImportMap { ...@@ -481,7 +493,7 @@ impl ImportMap {
pub fn as_esm_exports( pub fn as_esm_exports(
&self, &self,
import_references: &[ResolvedVc<EsmAssetReference>], import_references: &[ResolvedVc<EsmAssetReference>],
var_graph: &VarGraph, eval_context: &EvalContext,
) -> Result<FrozenMap<RcStr, EsmExport>> { ) -> Result<FrozenMap<RcStr, EsmExport>> {
Ok(FrozenMap::from( Ok(FrozenMap::from(
self.exports self.exports
...@@ -494,7 +506,7 @@ impl ImportMap { ...@@ -494,7 +506,7 @@ impl ImportMap {
// it is likely that these are not always actually mutable. // it is likely that these are not always actually mutable.
Liveness::Mutable Liveness::Mutable
} else { } else {
var_graph.get_export_ident_liveness( eval_context.imports.get_export_ident_liveness(
self.exports_ids.get(name).cloned().with_context(|| { self.exports_ids.get(name).cloned().with_context(|| {
format!("Exported binding {name} not found in exports_ids") format!("Exported binding {name} not found in exports_ids")
})?, })?,
...@@ -523,6 +535,25 @@ impl ImportMap { ...@@ -523,6 +535,25 @@ impl ImportMap {
self.reexport_namespaces.iter().copied() self.reexport_namespaces.iter().copied()
} }
/// Returns the liveness of a given export identifier. An export is live if it might change
/// values after module evaluation.
pub fn get_export_ident_liveness(&self, id: Id) -> Liveness {
if let Some(assignment_scopes) = self.assignment_scopes.get(&id) {
// If all assignments are in module scope, the export is not live.
if *assignment_scopes != AssignmentScopes::AllInModuleEvalScope {
Liveness::Live
} else {
Liveness::Constant
}
} else {
// If we haven't computed a value for it, that means it might be
// - A free variable or
// - an imported variable
// In those cases, we just assume that the value is live since we don't know anything
Liveness::Live
}
}
/// Analyze ES import /// Analyze ES import
pub(super) fn analyze(m: &Program, comments: Option<&dyn Comments>) -> Self { pub(super) fn analyze(m: &Program, comments: Option<&dyn Comments>) -> Self {
let mut data = ImportMap::default(); let mut data = ImportMap::default();
...@@ -530,6 +561,7 @@ impl ImportMap { ...@@ -530,6 +561,7 @@ impl ImportMap {
data: &mut data, data: &mut data,
comments, comments,
namespace_imports_to_specifier: FxIndexMap::default(), namespace_imports_to_specifier: FxIndexMap::default(),
is_in_fn: false,
}; };
// A prepass to detect imports to be able to rewrite import+export pairs to true reexports // A prepass to detect imports to be able to rewrite import+export pairs to true reexports
...@@ -649,6 +681,8 @@ struct Analyzer<'a> { ...@@ -649,6 +681,8 @@ struct Analyzer<'a> {
/// Map from local identifier of namespace imports to module path, used temporarily during /// Map from local identifier of namespace imports to module path, used temporarily during
/// analysis to detect dynamic accesses to namespace imports. /// analysis to detect dynamic accesses to namespace imports.
namespace_imports_to_specifier: FxIndexMap<Id, Wtf8Atom>, namespace_imports_to_specifier: FxIndexMap<Id, Wtf8Atom>,
is_in_fn: bool,
} }
impl Analyzer<'_> { impl Analyzer<'_> {
...@@ -673,6 +707,23 @@ impl Analyzer<'_> { ...@@ -673,6 +707,23 @@ impl Analyzer<'_> {
i i
} }
} }
fn register_assignment_scope(&mut self, id: Id) {
let scope = if self.is_in_fn {
AssignmentScope::Function
} else {
AssignmentScope::ModuleEval
};
match self.data.assignment_scopes.entry(id) {
Entry::Occupied(mut e) => {
*e.get_mut() = e.get().merge(scope);
}
Entry::Vacant(e) => {
e.insert(AssignmentScopes::new(scope));
}
}
}
} }
impl Visit for Analyzer<'_> { impl Visit for Analyzer<'_> {
...@@ -970,6 +1021,37 @@ impl Visit for Analyzer<'_> { ...@@ -970,6 +1021,37 @@ impl Visit for Analyzer<'_> {
n.visit_children_with(self); n.visit_children_with(self);
} }
fn visit_getter_prop(&mut self, node: &GetterProp) {
let old_is_in_fn = self.is_in_fn;
self.is_in_fn = true;
node.visit_children_with(self);
self.is_in_fn = old_is_in_fn;
}
fn visit_setter_prop(&mut self, node: &SetterProp) {
let old_is_in_fn = self.is_in_fn;
self.is_in_fn = true;
node.visit_children_with(self);
self.is_in_fn = old_is_in_fn;
}
fn visit_function(&mut self, node: &Function) {
let old_is_in_fn = self.is_in_fn;
self.is_in_fn = true;
node.visit_children_with(self);
self.is_in_fn = old_is_in_fn;
}
fn visit_constructor(&mut self, node: &Constructor) {
let old_is_in_fn = self.is_in_fn;
self.is_in_fn = true;
node.visit_children_with(self);
self.is_in_fn = old_is_in_fn;
}
fn visit_arrow_expr(&mut self, node: &ArrowExpr) {
let old_is_in_fn = self.is_in_fn;
self.is_in_fn = true;
node.visit_children_with(self);
self.is_in_fn = old_is_in_fn;
}
fn visit_member_expr(&mut self, node: &MemberExpr) { fn visit_member_expr(&mut self, node: &MemberExpr) {
if let MemberProp::Ident(..) | MemberProp::PrivateName(..) = &node.prop if let MemberProp::Ident(..) | MemberProp::PrivateName(..) = &node.prop
&& node.obj.is_ident() && node.obj.is_ident()
...@@ -982,32 +1064,74 @@ impl Visit for Analyzer<'_> { ...@@ -982,32 +1064,74 @@ impl Visit for Analyzer<'_> {
} }
fn visit_pat(&mut self, pat: &Pat) { fn visit_pat(&mut self, pat: &Pat) {
if let Pat::Ident(i) = pat if let Pat::Ident(i) = pat {
&& let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) self.register_assignment_scope(i.to_id());
{ if let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) {
self.data.full_star_imports.insert(module_path.clone()); self.data.full_star_imports.insert(module_path.clone());
} }
} else {
pat.visit_children_with(self); pat.visit_children_with(self);
} }
}
fn visit_simple_assign_target(&mut self, node: &SimpleAssignTarget) { fn visit_simple_assign_target(&mut self, node: &SimpleAssignTarget) {
if let SimpleAssignTarget::Ident(i) = node if let SimpleAssignTarget::Ident(i) = node {
&& let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) self.register_assignment_scope(i.to_id());
{ if let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) {
self.data.full_star_imports.insert(module_path.clone()); self.data.full_star_imports.insert(module_path.clone());
} }
} else {
node.visit_children_with(self); node.visit_children_with(self);
} }
}
fn visit_expr(&mut self, node: &Expr) { fn visit_expr(&mut self, node: &Expr) {
if let Expr::Ident(i) = node if let Expr::Ident(i) = node {
&& let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) if let Some(module_path) = self.namespace_imports_to_specifier.get(&i.to_id()) {
{
self.data.full_star_imports.insert(module_path.clone()); self.data.full_star_imports.insert(module_path.clone());
} }
} else {
node.visit_children_with(self);
}
}
fn visit_fn_expr(&mut self, node: &FnExpr) {
if let Some(ident) = &node.ident {
self.register_assignment_scope(ident.to_id());
}
node.visit_children_with(self);
}
fn visit_decl(&mut self, node: &Decl) {
match node {
Decl::Class(c) => {
self.register_assignment_scope(c.ident.to_id());
}
Decl::Fn(f) => {
self.register_assignment_scope(f.ident.to_id());
}
Decl::Using(v) => {
let ids: Vec<Id> = find_pat_ids(&v.decls);
for id in ids {
self.register_assignment_scope(id);
}
}
Decl::Var(v) => {
let ids: Vec<Id> = find_pat_ids(&v.decls);
for id in ids {
self.register_assignment_scope(id);
}
}
Decl::TsInterface(_) | Decl::TsTypeAlias(_) | Decl::TsEnum(_) | Decl::TsModule(_) => {}
}
node.visit_children_with(self);
}
fn visit_update_expr(&mut self, node: &UpdateExpr) {
if let Some(key) = node.arg.as_ident() {
// node.arg can also be a member expression
self.register_assignment_scope(key.to_id());
}
node.visit_children_with(self); node.visit_children_with(self);
} }
} }
......
...@@ -6,7 +6,6 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -6,7 +6,6 @@ use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::ecma::ast::Id; use swc_core::ecma::ast::Id;
use super::{JsValue, graph::VarGraph}; use super::{JsValue, graph::VarGraph};
use crate::analyzer::graph::VarMeta;
pub async fn link<'a, B, RB, F, RF>( pub async fn link<'a, B, RB, F, RF>(
graph: &VarGraph, graph: &VarGraph,
...@@ -123,7 +122,7 @@ where ...@@ -123,7 +122,7 @@ where
if let Some(val) = var_cache_lock.as_deref().and_then(|cache| cache.get(&var)) { if let Some(val) = var_cache_lock.as_deref().and_then(|cache| cache.get(&var)) {
total_nodes += val.total_nodes(); total_nodes += val.total_nodes();
done.push(val.clone()); done.push(val.clone());
} else if let Some(VarMeta { value, .. }) = graph.values.get(&var) { } else if let Some(value) = graph.values.get(&var) {
cycle_stack.insert(var.clone()); cycle_stack.insert(var.clone());
work_queue_stack.push(Step::LeaveVar(var)); work_queue_stack.push(Step::LeaveVar(var));
total_nodes += value.total_nodes(); total_nodes += value.total_nodes();
......
...@@ -3756,10 +3756,7 @@ mod tests { ...@@ -3756,10 +3756,7 @@ mod tests {
}; };
use crate::{ use crate::{
AnalyzeMode, AnalyzeMode,
analyzer::{ analyzer::{graph::AssignmentScopes, imports::ImportAttributes},
graph::{AssignmentScopes, VarMeta},
imports::ImportAttributes,
},
}; };
#[fixture("tests/analyzer/graph/**/input.js")] #[fixture("tests/analyzer/graph/**/input.js")]
...@@ -3854,23 +3851,20 @@ mod tests { ...@@ -3854,23 +3851,20 @@ mod tests {
"{:#?}", "{:#?}",
named_values named_values
.iter() .iter()
.map(|(name, (_, VarMeta { value, .. }))| (name, value)) .map(|(name, (_, value))| (name, value))
.collect::<Vec<_>>() .collect::<Vec<_>>()
)) ))
.compare_to_file(&graph_snapshot_path) .compare_to_file(&graph_snapshot_path)
.unwrap(); .unwrap();
} }
NormalizedOutput::from(explain_all(named_values.iter().map( NormalizedOutput::from(explain_all(named_values.iter().map(
|( |(name, (id, value))| {
name,
( (
_, name,
VarMeta {
value, value,
assignment_scopes, eval_context.imports.assignment_scopes.get(id).copied(),
)
}, },
),
)| (name, value, Some(*assignment_scopes)),
))) )))
.compare_to_file(&graph_explained_snapshot_path) .compare_to_file(&graph_explained_snapshot_path)
.unwrap(); .unwrap();
......
...@@ -867,7 +867,7 @@ async fn analyze_ecmascript_module_internal( ...@@ -867,7 +867,7 @@ async fn analyze_ecmascript_module_internal(
.collect(); .collect();
let esm_exports = eval_context let esm_exports = eval_context
.imports .imports
.as_esm_exports(&import_references, &var_graph)?; .as_esm_exports(&import_references, eval_context)?;
for idx in eval_context.imports.reexports_reference_idxs() { for idx in eval_context.imports.reexports_reference_idxs() {
analysis.add_esm_reexport_reference(idx); analysis.add_esm_reexport_reference(idx);
......
*anonymous function 170* (const after eval) = (...) => [file] *anonymous function 170* = (...) => [file]
*anonymous function 254* (const after eval) = (...) => FreeVar(require)["resolve"](file) *anonymous function 254* = (...) => FreeVar(require)["resolve"](file)
*anonymous function 88* (const after eval) = (...) => file *anonymous function 88* = (...) => file
a (const after eval) = ["../lib/a.js", "../lib/b.js"] a (const after eval) = ["../lib/a.js", "../lib/b.js"]
......
*anonymous function 116* (const after eval) = (...) => 3 *anonymous function 116* = (...) => 3
*anonymous function 339* = (...) => 3 *anonymous function 339* = (...) => 3
*arrow function 11* (const after eval) = (...) => 1 *arrow function 11* = (...) => 1
*arrow function 214* = (...) => 1 *arrow function 214* = (...) => 1
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
*arrow function 299* = (...) => 2 *arrow function 299* = (...) => 2
*arrow function 30* (const after eval) = (...) => 2 *arrow function 30* = (...) => 2
*arrow function 50* (const after eval) = (...) => 1 *arrow function 50* = (...) => 1
*arrow function 83* (const after eval) = (...) => 2 *arrow function 83* = (...) => 2
a (const after eval) = *arrow function 11* a (const after eval) = *arrow function 11*
......
*arrow function 425* (const after eval) = (...) => *arrow function 431* *arrow function 425* = (...) => *arrow function 431*
*arrow function 431* = (...) => *arrow function 437* *arrow function 431* = (...) => *arrow function 437*
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
*arrow function 449* = (...) => 1 *arrow function 449* = (...) => 1
*arrow function 468* (const after eval) = (...) => *arrow function 474* *arrow function 468* = (...) => *arrow function 474*
*arrow function 474* = (...) => *arrow function 480* *arrow function 474* = (...) => *arrow function 480*
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*arrow function 492* = (...) => 2 *arrow function 492* = (...) => 2
*arrow function 511* (const after eval) = (...) => *arrow function 517* *arrow function 511* = (...) => *arrow function 517*
*arrow function 517* = (...) => *arrow function 523* *arrow function 517* = (...) => *arrow function 523*
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
*arrow function 535* = (...) => 2 *arrow function 535* = (...) => 2
*arrow function 554* (const after eval) = (...) => *arrow function 560* *arrow function 554* = (...) => *arrow function 560*
*arrow function 560* = (...) => *arrow function 566* *arrow function 560* = (...) => *arrow function 566*
......
*anonymous function 25* (const after eval) = (...) => undefined *anonymous function 25* = (...) => undefined
a (const after eval) = (...) => undefined a (const after eval) = (...) => undefined
......
*arrow function 105* (const after eval) = (...) => value2 *arrow function 105* = (...) => value2
Fun (const after eval) = (...) => value Fun (const after eval) = (...) => value
......
*arrow function 2666* (const after eval) = (...) => ( *arrow function 2666* = (...) => (
| [ | [
"node", "node",
[ [
......
*arrow function 19* (const after eval) = (...) => false *arrow function 19* = (...) => false
run (const after eval) = (...) => ("should not run" | "should run") run (const after eval) = (...) => ("should not run" | "should run")
......
*anonymous function 66* (const after eval) = (...) => undefined *anonymous function 66* = (...) => undefined
*arrow function 118* (const after eval) = (...) => undefined *arrow function 118* = (...) => undefined
*arrow function 229* (const after eval) = (...) => undefined *arrow function 229* = (...) => undefined
a (const after eval) = (...) => undefined a (const after eval) = (...) => undefined
......
*arrow function 907* (const after eval) = (...) => undefined *arrow function 907* = (...) => undefined
ConstAfterEvalClass (const after eval) = ???*0* ConstAfterEvalClass (const after eval) = ???*0*
- *0* unsupported expression - *0* unsupported expression
...@@ -8,6 +8,14 @@ d1 (const after eval) = 2 ...@@ -8,6 +8,14 @@ d1 (const after eval) = 2
default_function_export_const_after_eval (const after eval) = (...) => undefined default_function_export_const_after_eval (const after eval) = (...) => undefined
foo_const_after_eval (const after eval) = {...???*0*, ...???*1*}
- *0* unsupported object part
⚠️ This value might have side effects
- *1* unsupported object part
⚠️ This value might have side effects
getter_not_const_after_eval = (1 | 2)
i (const after eval) = (0 | ???*0*) i (const after eval) = (0 | ???*0*)
- *0* updated with update expression - *0* updated with update expression
⚠️ This value might have side effects ⚠️ This value might have side effects
...@@ -25,3 +33,9 @@ named_let_export_const_after_eval_2 (const after eval) = (???*0* | 5) ...@@ -25,3 +33,9 @@ named_let_export_const_after_eval_2 (const after eval) = (???*0* | 5)
named_let_export_not_const_after_eval = (1 | 5) named_let_export_not_const_after_eval = (1 | 5)
named_let_export_not_const_after_eval_2 = (1 | 3) named_let_export_not_const_after_eval_2 = (1 | 3)
setter_not_const_after_eval = (1 | 2)
v = ???*0*
- *0* v
⚠️ pattern without value
...@@ -39,6 +39,56 @@ ...@@ -39,6 +39,56 @@
), ),
), ),
), ),
(
"foo_const_after_eval",
Object {
total_nodes: 3,
parts: [
Spread(
Unknown {
original_value: None,
reason: "unsupported object part",
has_side_effects: true,
},
),
Spread(
Unknown {
original_value: None,
reason: "unsupported object part",
has_side_effects: true,
},
),
],
mutable: true,
},
),
(
"getter_not_const_after_eval",
Alternatives {
total_nodes: 3,
values: [
Constant(
Num(
ConstantNumber(
TotalOrderF64(
1.0,
),
),
),
),
Constant(
Num(
ConstantNumber(
TotalOrderF64(
2.0,
),
),
),
),
],
logical_property: None,
},
),
( (
"i", "i",
Alternatives { Alternatives {
...@@ -195,4 +245,46 @@ ...@@ -195,4 +245,46 @@
logical_property: None, logical_property: None,
}, },
), ),
(
"setter_not_const_after_eval",
Alternatives {
total_nodes: 3,
values: [
Constant(
Num(
ConstantNumber(
TotalOrderF64(
1.0,
),
),
),
),
Constant(
Num(
ConstantNumber(
TotalOrderF64(
2.0,
),
),
),
),
],
logical_property: None,
},
),
(
"v",
Unknown {
original_value: Some(
Variable(
(
"v",
#11,
),
),
),
reason: "pattern without value",
has_side_effects: false,
},
),
] ]
...@@ -37,5 +37,13 @@ export class ConstAfterEvalClass { ...@@ -37,5 +37,13 @@ export class ConstAfterEvalClass {
} }
} }
let getter_not_const_after_eval = 1
let setter_not_const_after_eval = 1
let foo_const_after_eval = {
get x() {
getter_not_const_after_eval = 2
},
set x(v) {
setter_not_const_after_eval = 2
},
}
...@@ -8,6 +8,14 @@ d1 = 2 ...@@ -8,6 +8,14 @@ d1 = 2
default_function_export_const_after_eval = (...) => undefined default_function_export_const_after_eval = (...) => undefined
foo_const_after_eval = {...???*0*, ...???*1*}
- *0* unsupported object part
⚠️ This value might have side effects
- *1* unsupported object part
⚠️ This value might have side effects
getter_not_const_after_eval = (1 | 2)
i = (0 | ???*0*) i = (0 | ???*0*)
- *0* updated with update expression - *0* updated with update expression
⚠️ This value might have side effects ⚠️ This value might have side effects
...@@ -25,3 +33,9 @@ named_let_export_const_after_eval_2 = (???*0* | 5) ...@@ -25,3 +33,9 @@ named_let_export_const_after_eval_2 = (???*0* | 5)
named_let_export_not_const_after_eval = (1 | 5) named_let_export_not_const_after_eval = (1 | 5)
named_let_export_not_const_after_eval_2 = (1 | 3) named_let_export_not_const_after_eval_2 = (1 | 3)
setter_not_const_after_eval = (1 | 2)
v = ???*0*
- *0* v
⚠️ pattern without value
*arrow function 24* (const after eval) = (...) => FreeVar(JSON)["stringify"]( *arrow function 24* = (...) => FreeVar(JSON)["stringify"](
{ {
"condition": (variable === "true"), "condition": (variable === "true"),
"buggedConditionalCheck": ((variable === "true") ? "true" : "false") "buggedConditionalCheck": ((variable === "true") ? "true" : "false")
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
*anonymous function 5936* = (...) => {"type": "sort_expression", "expression": expression, "order": order} *anonymous function 5936* = (...) => {"type": "sort_expression", "expression": expression, "order": order}
*anonymous function 625* (const after eval) = (...) => `Expected ${describeExpected(expected)} but ${describeFound(found)} found.` *anonymous function 625* = (...) => `Expected ${describeExpected(expected)} but ${describeFound(found)} found.`
*anonymous function 6287* = (...) => {"type": "scalar_function_expression", "name": name, "arguments": args, "udf": true} *anonymous function 6287* = (...) => {"type": "scalar_function_expression", "name": name, "arguments": args, "udf": true}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment