Skip to content

Commit

Permalink
Handle undefined as a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 7, 2023
1 parent 559528a commit 6c72b32
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
3 changes: 2 additions & 1 deletion valuescript_compiler/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::asm::{Number, Value};

pub const CONSTANTS: [(&'static str, Value); 2] = [
pub const CONSTANTS: [(&str, Value); 3] = [
("undefined", Value::Undefined),
("NaN", Value::Number(Number(std::f64::NAN))),
("Infinity", Value::Number(Number(std::f64::INFINITY))),
];
5 changes: 0 additions & 5 deletions valuescript_compiler/src/expression_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,11 +1282,6 @@ impl<'a> ExpressionCompiler<'a> {
ident: &swc_ecma_ast::Ident,
target_register: Option<Register>,
) -> CompiledExpression {
// TODO: Use constant instead?
if ident.sym.to_string() == "undefined" {
return Value::Undefined.to_ce();
}

let fn_as_owner_id = match self.fnc.scope_analysis.lookup(ident) {
Some(name) => match name.type_ == NameType::Function {
true => match name.id {
Expand Down
7 changes: 0 additions & 7 deletions valuescript_compiler/src/scope_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,13 +1584,6 @@ impl ScopeAnalysis {
}

fn ident(&mut self, scope: &Scope, ident: &swc_ecma_ast::Ident) {
if ident.sym.to_string() == "undefined" {
// The way that `undefined` is considered to be an identifier is an artifact of history. It's
// not an identifier (unless used in an identifier context like an object key), instead it's a
// keyword like `null`.
return;
}

let name_id = match scope.get(&ident.sym) {
Some(name_id) => name_id,
None => {
Expand Down

0 comments on commit 6c72b32

Please sign in to comment.