Skip to content

Commit

Permalink
EAS-2573 : Add GraphQL support for the permission scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
gersbach committed Dec 23, 2024
1 parent 054198a commit cbac9e8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 42 additions & 1 deletion crates/forge_analyzer/src/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![allow(dead_code, unused)]

use std::borrow::BorrowMut;
use std::env;
use std::hash::Hash;
use std::{borrow::Borrow, fmt, mem};
use std::{env, string};

use crate::utils::{calls_method, eq_prop_name};
use forge_file_resolver::{FileResolver, ForgeResolver};
Expand Down Expand Up @@ -144,6 +144,29 @@ pub fn run_resolver(
) -> Environment {
let mut environment = Environment::new();

for (curr_mod, module) in modules.iter_enumerated() {
let mut string_collector = StringCollector { strings: vec![] };

module.visit_children_with(&mut string_collector);
environment.all_strings.extend(string_collector.strings);

let mut export_collector = ExportCollector {
res_table: &mut environment.resolver,
curr_mod,
exports: vec![],
default: None,
};
module.visit_children_with(&mut export_collector);
let mod_id = environment
.exports
.push_and_get_key(export_collector.exports);
debug_assert_eq!(curr_mod, mod_id);
if let Some(default) = export_collector.default {
let def_id = environment.default_exports.insert(curr_mod, default);
debug_assert_eq!(def_id, None, "def_id shouldn't be set");
}
}

// This for loop parses each token of each code statement in the file.
for (curr_mod, module) in modules.iter_enumerated() {
let mut export_collector = ExportCollector {
Expand Down Expand Up @@ -583,6 +606,7 @@ pub struct Environment {
pub defs: Definitions,
default_exports: FxHashMap<ModId, DefId>,
pub resolver: ResolverTable,
pub all_strings: Vec<Atom>,
}

struct ImportCollector<'cx> {
Expand Down Expand Up @@ -3298,6 +3322,23 @@ impl Visit for GlobalCollector<'_> {
}
}

struct StringCollector {
strings: Vec<Atom>,
}

impl Visit for StringCollector {
fn visit_str(&mut self, n: &Str) {
self.add_str(n);
}
}

impl StringCollector {
pub fn add_str(&mut self, n: &Str) {
let a = n.value.clone();
self.strings.push(a);
}
}

impl Visit for ExportCollector<'_> {
noop_visit_type!();
fn visit_export_decl(&mut self, n: &ExportDecl) {
Expand Down
2 changes: 2 additions & 0 deletions crates/fsrt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ pub(crate) fn scan_directory<'a>(
}
}

// TODO: map permissions here for proj.env.all_strings, will implement after new API is merged in

let mut used_graphql_perms: Vec<&str> = definition_analysis_interp
.value_manager
.varid_to_value_with_proj
Expand Down

0 comments on commit cbac9e8

Please sign in to comment.