Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement more logic for file loader / resolver for multi-file tests #705

Open
Tracked by #1074
kdy1 opened this issue Feb 15, 2023 · 12 comments
Open
Tracked by #1074

Implement more logic for file loader / resolver for multi-file tests #705

kdy1 opened this issue Feb 15, 2023 · 12 comments
Labels
good first issue Good for newcomers

Comments

@kdy1
Copy link
Member

kdy1 commented Feb 15, 2023

#700 enabled a multi-file testing system, but the loader/resolver is not good enough.
But I want to work on other things first, so I'm filing an issue instead.

If you run check.sh, you will see panic messages starting with not yet implemented: .

e.g.

========== Running test moduleResolution/importFromDot.ts
Source:
// @module: commonjs

// @Filename: a.ts
export const rootA = 0;

// @Filename: a/index.ts
export const indexInA = 0;

// @Filename: a/b.ts
import { indexInA, rootA } from ".";


[crates/stc_ts_type_checker/tests/tsc.rs:305] &libs = [
    Es5,
    Dom,
]
load_file: Real("a/b.ts")
resolve: Real("a/b.ts") "."
thread 'conformance::moduleResolution::importFromDot.ts' panicked at 'not yet implemented: resolve: Real("a/b.ts") "."', crates/stc_ts_type_checker/tests/tsc.rs:523:9
stack backtrace:
   0: rust_begin_unwind

Relevant code:

#[derive(Clone)]
struct TestFileSystem {
files: Arc<Vec<(String, String)>>,
}
impl Resolve for TestFileSystem {
fn resolve(&self, base: &FileName, module_specifier: &str) -> Result<FileName, Error> {
println!("resolve: {:?} {:?}", base, module_specifier);
if !module_specifier.starts_with('.') {
return NodeResolver.resolve(base, module_specifier);
}
if let Some(name) = module_specifier.strip_prefix("./") {
return Ok(FileName::Real(name.into()));
}
todo!("resolve: current = {:?}; target ={:?}", base, module_specifier);
}
}
impl LoadFile for TestFileSystem {
fn load_file(&self, cm: &Arc<SourceMap>, filename: &Arc<FileName>) -> Result<(Arc<SourceFile>, Syntax), Error> {
println!("load_file: {:?} ", filename);
if self.files.is_empty() {
return DefaultFileLoader.load_file(cm, filename);
}
for (name, content) in self.files.iter() {
if filename.to_string() == *name || format!("{}.ts", filename) == *name || format!("{}.tsx", filename) == *name {
let fm = cm.new_source_file((**filename).clone(), content.clone());
return Ok((fm, Syntax::Typescript(Default::default())));
}
}
todo!("load_file: {:?} ", filename);
}
}

@kdy1 kdy1 added this to the v0.0.1: Correctness milestone Feb 15, 2023
@kdy1 kdy1 added the good first issue Good for newcomers label Feb 15, 2023
@infix
Copy link
Contributor

infix commented Feb 15, 2023

I'd love to work on this

@kdy1
Copy link
Member Author

kdy1 commented Feb 16, 2023

Thank you!

@kdy1
Copy link
Member Author

kdy1 commented Feb 23, 2023

Note: Additionally, we need to handle resolving like node_modules/foo/bar.
Maybe we can create a temporary directory and reuse NodeResolver instead of reimplementing a full resolver/loader for testing

@infix
Copy link
Contributor

infix commented Feb 23, 2023

That makes sense, I was extremely busy last week didn't have time to work on this, will try to find some time this weekend. Sorry for the delay man.

@kdy1
Copy link
Member Author

kdy1 commented Feb 23, 2023

No worries, really. It's definitely not something you should be sorry.
I found that we need node_modules support while trying to make more good first issues.

@kdy1
Copy link
Member Author

kdy1 commented Mar 23, 2023

@infix Are you still willing to work on this?

@infix
Copy link
Contributor

infix commented Mar 23, 2023

Sorry for the delay, I'm still interested and I'll dedicate some time this weekend!

@kdy1
Copy link
Member Author

kdy1 commented Mar 23, 2023

No worries, I'm just checking. And thank you!

@DavidHancu
Copy link

Hi @kdy1! If this still needs attention, I'd be willing to work on it.
I've already implemented the TypeScript Module Resolution system before (for my Turboprisma project), so it should be pretty easy to do.

@kdy1
Copy link
Member Author

kdy1 commented May 28, 2023

It will be really nice, thank you!

@infix
Copy link
Contributor

infix commented May 30, 2023

@DavidHancu go for it man. I can't really dedicate time to this.

@sunrabbit123
Copy link
Collaborator

resolve import . at #1064
resolve emit error about not exist file #1076

kdy1 pushed a commit that referenced this issue Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Development

No branches or pull requests

4 participants