mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Fix scope bug
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// //! test_output("foo")
|
||||
//! test_output("foo")
|
||||
|
||||
export default () => {
|
||||
class X {
|
||||
@@ -714,10 +714,10 @@ impl ModuleCompiler {
|
||||
let mut static_: Object = Object::default();
|
||||
|
||||
let defn_name = match ident {
|
||||
Some(ident) => match self
|
||||
.scope_analysis
|
||||
.lookup_value(&OwnerId::Module, &Ident::from_swc_ident(ident))
|
||||
{
|
||||
Some(ident) => match self.scope_analysis.lookup_value(
|
||||
&OwnerId::Module, // TODO: Do we need the scope/owner_id to be passed in instead?
|
||||
&Ident::from_swc_ident(ident),
|
||||
) {
|
||||
Some(Value::Pointer(p)) => p,
|
||||
_ => {
|
||||
self.internal_error(
|
||||
|
||||
@@ -40,6 +40,7 @@ pub enum OwnerId {
|
||||
}
|
||||
|
||||
pub trait ScopeTrait {
|
||||
fn trace(&self);
|
||||
fn get(&self, name: &swc_atoms::JsWord) -> Option<NameId>;
|
||||
fn set(
|
||||
&self,
|
||||
@@ -52,6 +53,24 @@ pub trait ScopeTrait {
|
||||
}
|
||||
|
||||
impl ScopeTrait for Scope {
|
||||
fn trace(&self) {
|
||||
println!(
|
||||
"scope trace {:?} names: {:?}",
|
||||
&self.borrow().owner_id,
|
||||
&self
|
||||
.borrow()
|
||||
.name_map
|
||||
.keys()
|
||||
.map(|k| k.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
);
|
||||
|
||||
match &self.borrow().parent {
|
||||
Some(parent) => parent.trace(),
|
||||
None => println!("scope trace end"),
|
||||
};
|
||||
}
|
||||
|
||||
fn get(&self, name: &swc_atoms::JsWord) -> Option<NameId> {
|
||||
match self.borrow().name_map.get(name) {
|
||||
Some(mapped_name) => Some(mapped_name.clone()),
|
||||
|
||||
@@ -254,7 +254,14 @@ impl ScopeAnalysis {
|
||||
Some(name_id) => {
|
||||
let name = self.names.get(&name_id).expect("Name not found");
|
||||
|
||||
if name.type_ != NameType::This {
|
||||
let name_span = match name.id {
|
||||
NameId::Span(span) => Some(span),
|
||||
NameId::This(span) => Some(span),
|
||||
NameId::Builtin(_) => None,
|
||||
NameId::Constant(_) => None,
|
||||
};
|
||||
|
||||
if name.type_ != NameType::This && name_span == Some(origin_ident.span) {
|
||||
match &name.value {
|
||||
// Already inserted, skip
|
||||
Value::Pointer(_) => return,
|
||||
|
||||
Reference in New Issue
Block a user