Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 74 additions & 74 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions crates/perry-hir/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ pub(crate) use builtins::{
};

mod uses_this;
pub(crate) use uses_this::{
closure_uses_new_target, closure_uses_this, uses_new_target_expr, uses_new_target_stmt,
uses_this_expr, uses_this_stmt,
};
pub(crate) use uses_this::{closure_uses_new_target, closure_uses_this, uses_this_stmt};

mod value_types;
pub use value_types::{infer_expr_type, infer_refinable_expr_type, HirTypeEnv, HirTypeFacts};
Expand Down Expand Up @@ -467,7 +464,7 @@ pub fn substitute_lexical_this_in_stmts(stmts: &mut [Stmt], replacement: &Expr)
}

fn substitute_lexical_this_in_stmt(stmt: &mut Stmt, replacement: &Expr) {
let mut on_expr = |e: &mut Expr| substitute_lexical_this_in_expr(e, replacement);
let on_expr = |e: &mut Expr| substitute_lexical_this_in_expr(e, replacement);
match stmt {
Stmt::Let { init, .. } => {
if let Some(e) = init {
Expand Down
4 changes: 2 additions & 2 deletions crates/perry-hir/src/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn audit_module_capabilities(
// `is_host = false`. Default-deny still safer than crash.
Vec::new()
};
if allowed.iter().any(|t| *t == "*") {
if allowed.contains(&"*") {
return Vec::new();
}
let mut ctx = WalkCtx {
Expand Down Expand Up @@ -227,7 +227,7 @@ fn visit_stmt(stmt: &Stmt, ctx: &mut WalkCtx) {

fn visit_expr(expr: &Expr, ctx: &mut WalkCtx) {
if let Some((cap, kind)) = required_capability(expr) {
if !ctx.allowed.iter().any(|t| *t == cap) {
if !ctx.allowed.contains(&cap) {
ctx.violations.push(CapabilityViolation {
source: ctx.source.clone(),
package: ctx.package.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/perry-hir/src/destructuring/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(crate) fn ast_expr_contains_function_expr(e: &ast::Expr) -> bool {
}
Expr::New(n) => {
ast_expr_contains_function_expr(&n.callee)
|| n.args.as_ref().map_or(false, |args| {
|| n.args.as_ref().is_some_and(|args| {
args.iter()
.any(|a| ast_expr_contains_function_expr(&a.expr))
})
Expand Down
4 changes: 1 addition & 3 deletions crates/perry-hir/src/destructuring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,4 @@ pub(crate) use helpers::{
};
pub(crate) use pattern_binding::{lower_pattern_binding, lower_pattern_binding_into};
pub(crate) use var_decl::lower_var_decl_with_destructuring;
pub(crate) use var_decl_sources::{
require_resolvable_native_specifier, resolvable_native_module_for_spec,
};
pub(crate) use var_decl_sources::resolvable_native_module_for_spec;
18 changes: 9 additions & 9 deletions crates/perry-hir/src/destructuring/var_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ pub(crate) fn lower_var_decl_with_destructuring(
) || decl
.init
.as_deref()
.map_or(false, ast_expr_contains_function_expr);
.is_some_and(ast_expr_contains_function_expr);
let pre_id = if is_function_expr_init
&& !ctx.pre_registered_module_vars.contains(&name)
&& ctx.lookup_local(&name).is_none()
Expand All @@ -1479,10 +1479,10 @@ pub(crate) fn lower_var_decl_with_destructuring(
let init = decl.init.as_ref().map(|e| lower_expr(ctx, e)).transpose()?;
if matches!(ty, Type::Any) {
match &init {
Some(Expr::NativeMethodCall { module, method, .. }) => {
if module == "stream" && method == "from" {
ty = Type::Named("Readable".to_string());
}
Some(Expr::NativeMethodCall { module, method, .. })
if module == "stream" && method == "from" =>
{
ty = Type::Named("Readable".to_string());
}
Some(Expr::NewDynamic { callee, .. }) => {
if let Expr::PropertyGet { object, property } = callee.as_ref() {
Expand Down Expand Up @@ -1858,10 +1858,10 @@ pub(crate) fn lower_var_decl_with_destructuring(
// recogniser later emits
// `RegisterFunctionPrototypeMethod { func:
// LocalGet(M_id), … }`.
Expr::LocalGet(src_local) => {
if ctx.function_valued_locals.contains(src_local) {
ctx.prototype_function_locals.insert(id, *src_local);
}
Expr::LocalGet(src_local)
if ctx.function_valued_locals.contains(src_local) =>
{
ctx.prototype_function_locals.insert(id, *src_local);
}
_ => {}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/perry-hir/src/egress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ fn visit_expr(expr: &Expr, ctx: &mut WalkCtx) {

fn check_url(ctx: &mut WalkCtx, kind: &'static str, url: &Expr) {
match url {
// NOTE: do not collapse this into a match-guard (`Expr::String(s) if ...`).
// An allowlisted literal must be accepted here, not fall through to the
// dynamic-host arm below. clippy's collapsible_if/match-guard rewrite
// changes the semantics; keep the explicit nested `if`.
Expr::String(s) => {
if !url_matches_allowlist(s, ctx.allowed_hosts) {
ctx.violations.push(EgressViolation {
Expand All @@ -260,6 +264,10 @@ fn check_url(ctx: &mut WalkCtx, kind: &'static str, url: &Expr) {

fn check_host(ctx: &mut WalkCtx, kind: &'static str, host: &Expr) {
match host {
// NOTE: do not collapse this into a match-guard (`Expr::String(s) if ...`).
// An allowlisted literal must be accepted here, not fall through to the
// dynamic-host arm below. clippy's collapsible_if/match-guard rewrite
// changes the semantics; keep the explicit nested `if`.
Expr::String(s) => {
if !host_matches_allowlist(s, ctx.allowed_hosts) {
ctx.violations.push(EgressViolation {
Expand Down
4 changes: 1 addition & 3 deletions crates/perry-hir/src/js_transform/cross_module_natives.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::ir::{Expr, Module, ModuleKind, Stmt};
use perry_types::LocalId;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{BTreeMap, HashMap};

use super::*;
/// Information about a native instance exported from another module
#[derive(Debug, Clone)]
pub struct ExportedNativeInstance {
Expand Down
3 changes: 1 addition & 2 deletions crates/perry-hir/src/js_transform/imports.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ir::{Expr, Module, ModuleKind, Stmt};
use perry_types::LocalId;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{HashMap, HashSet};

use super::*;
/// Information about a JavaScript module import
#[derive(Debug, Clone)]
pub struct JsImportInfo {
Expand Down
5 changes: 2 additions & 3 deletions crates/perry-hir/src/js_transform/local_natives.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::ir::{Expr, Module, ModuleKind, Stmt};
use crate::ir::{Expr, Module, Stmt};
use perry_types::LocalId;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::HashMap;

use super::*;
/// Fix local native instance method calls within the same module
///
/// This function tracks variables that are assigned from native module creation functions
Expand Down
4 changes: 0 additions & 4 deletions crates/perry-hir/src/js_transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
//! 6. Transforms new expressions for JS classes to JsNew
//! 7. Wraps closures passed to JS functions with JsCreateCallback

use crate::ir::{Expr, Module, ModuleKind, Stmt};
use perry_types::LocalId;
use std::collections::{BTreeMap, HashMap, HashSet};

mod cross_module_natives;
mod imports;
mod local_natives;
Expand Down
12 changes: 4 additions & 8 deletions crates/perry-hir/src/lower/eval_super_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,11 @@ fn scan_expr(scan: &mut Scan, expr: &ast::Expr, transparent: bool) {
E::PrivateName(p) => {
scan.private_refs.push(format!("#{}", p.name));
}
E::Ident(id) => {
if transparent && id.sym.as_ref() == "arguments" {
scan.arguments_ref = true;
}
E::Ident(id) if transparent && id.sym.as_ref() == "arguments" => {
scan.arguments_ref = true;
}
E::MetaProp(mp) => {
if transparent && mp.kind == ast::MetaPropKind::NewTarget {
scan.new_target = true;
}
E::MetaProp(mp) if transparent && mp.kind == ast::MetaPropKind::NewTarget => {
scan.new_target = true;
}
E::Unary(u) => scan_expr(scan, &u.arg, transparent),
E::Update(u) => scan_expr(scan, &u.arg, transparent),
Expand Down
23 changes: 6 additions & 17 deletions crates/perry-hir/src/lower/expr_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,19 +685,9 @@ fn lower_assignment_target(
} else {
None
}
} else if let Some(func_id) = ctx.lookup_func(&cls_name) {
// Top-level / globally-registered function
// without a corresponding local binding
// (rare; most function decls also get a
// local). FuncRef lowering produces the
// singleton wrapper closure — paired
// with the matching `new` site that
// also lowers `<Ident>` through FuncRef
// (the codegen-side `try_static_class_name`
// path), the bits agree.
Some(ProtoOwner::Func(Expr::FuncRef(func_id)))
} else {
None
ctx.lookup_func(&cls_name)
.map(|func_id| ProtoOwner::Func(Expr::FuncRef(func_id)))
}
} else {
None
Expand All @@ -724,12 +714,11 @@ fn lower_assignment_target(
ctx.prototype_function_aliases.get(&id).copied()
{
Some(ProtoOwner::Func(Expr::FuncRef(func_id)))
} else if let Some(src_local) =
ctx.prototype_function_locals.get(&id).copied()
{
Some(ProtoOwner::Func(Expr::LocalGet(src_local)))
} else {
None
ctx.prototype_function_locals
.get(&id)
.copied()
.map(|src_local| ProtoOwner::Func(Expr::LocalGet(src_local)))
}
} else {
None
Expand Down
18 changes: 5 additions & 13 deletions crates/perry-hir/src/lower/expr_call/array_only_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
//!
//! Extracted from `expr_call/mod.rs` as a mechanical move.

use anyhow::{anyhow, Result};
use perry_types::{LocalId, Type};
use anyhow::Result;
use perry_types::Type;
use swc_ecma_ast as ast;

use crate::ir::*;
use crate::lower_types::extract_ts_type_with_ctx;

/// Is `expr` a reference to a node:stream class constructor — bare
/// (`Readable`) or namespaced (`stream.Readable`)? Used by
Expand Down Expand Up @@ -240,10 +239,7 @@ fn chain_roots_at_iterator_from(expr: &ast::Expr) -> bool {
}
}

use super::super::{
extract_typed_parse_source_order, is_generator_call_expr, is_widget_modifier_name, lower_expr,
resolve_typed_parse_ty, LoweringContext,
};
use super::super::{lower_expr, LoweringContext};

pub(super) fn try_array_only_methods(
ctx: &mut LoweringContext,
Expand Down Expand Up @@ -438,11 +434,7 @@ pub(super) fn try_array_only_methods(
) || ctx
.fetch_call_response_locals
.contains(obj_ident.sym.as_ref()));
if is_fetch_headers {
true
} else {
false
}
is_fetch_headers
} else {
false
}
Expand Down Expand Up @@ -1161,7 +1153,7 @@ pub(super) fn try_array_only_methods(
// final length, which is exactly what the last
// element of the `Sequence` yields. (#4508)
let mut stmts: Vec<Expr> = Vec::with_capacity(args.len());
for (ast_arg, arg) in call.args.iter().zip(args.into_iter()) {
for (ast_arg, arg) in call.args.iter().zip(args) {
let method = if ast_arg.spread.is_some() {
"push_spread"
} else {
Expand Down
Loading
Loading