diff --git a/crates/forge_analyzer/src/definitions.rs b/crates/forge_analyzer/src/definitions.rs index e9b7bd2..32a6a4b 100644 --- a/crates/forge_analyzer/src/definitions.rs +++ b/crates/forge_analyzer/src/definitions.rs @@ -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}; @@ -146,6 +146,11 @@ pub fn run_resolver( // This for loop parses each token of each code statement in the file. 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, @@ -583,6 +588,7 @@ pub struct Environment { pub defs: Definitions, default_exports: FxHashMap, pub resolver: ResolverTable, + pub all_strings: Vec, } struct ImportCollector<'cx> { @@ -3299,6 +3305,26 @@ impl Visit for GlobalCollector<'_> { } } +struct StringCollector { + strings: Vec, +} + +impl Visit for StringCollector { + fn visit_str(&mut self, n: &Str) { + self.add_str(n.value.as_str().to_string()); + } + + fn visit_tpl(&mut self, n: &Tpl) { + self.add_str(n.quasis.iter().map(|val| val.raw.as_str()).collect()); + } +} + +impl StringCollector { + pub fn add_str(&mut self, n: String) { + self.strings.push(n); + } +} + impl Visit for ExportCollector<'_> { noop_visit_type!(); fn visit_export_decl(&mut self, n: &ExportDecl) {