Skip to content

Commit d09293f

Browse files
Sujay JayakarConvex, Inc.
authored andcommitted
Resolve mounted exports (#28621)
GitOrigin-RevId: eef704a1cbb1508861ff37c607d56368d2059c49
1 parent 47e1b06 commit d09293f

File tree

2 files changed

+69
-10
lines changed

2 files changed

+69
-10
lines changed

sync_types/src/module_path.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use std::{
88
str::FromStr,
99
};
1010

11-
use crate::path::check_valid_path_component;
11+
use crate::path::{
12+
check_valid_path_component,
13+
PathComponent,
14+
};
1215

1316
pub const SYSTEM_UDF_DIR: &str = "_system";
1417
pub const DEPS_DIR: &str = "_deps";
@@ -38,14 +41,15 @@ impl ModulePath {
3841
&self.path
3942
}
4043

41-
pub fn components(&self) -> impl Iterator<Item = &str> {
42-
self.path
43-
.components()
44-
.map(|component| match component {
45-
Component::Normal(c) => c,
46-
c => panic!("Unexpected component {c:?}"),
47-
})
48-
.map(|c| c.to_str().expect("Non-unicode data in module path?"))
44+
pub fn components(&self) -> impl Iterator<Item = PathComponent> + '_ {
45+
self.path.components().map(|component| match component {
46+
Component::Normal(c) => c
47+
.to_str()
48+
.expect("Non-unicode data in module path?")
49+
.parse()
50+
.expect("Invalid path component"),
51+
c => panic!("Unexpected component {c:?}"),
52+
})
4953
}
5054

5155
/// Does a module live within the `_system/` directory?

sync_types/src/path.rs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
use crate::identifier::MAX_IDENTIFIER_LEN;
1+
use std::{
2+
ops::Deref,
3+
str::FromStr,
4+
};
5+
6+
use crate::{
7+
identifier::MAX_IDENTIFIER_LEN,
8+
FunctionName,
9+
};
210

311
pub fn check_valid_path_component(s: &str) -> anyhow::Result<()> {
412
if s.len() > MAX_IDENTIFIER_LEN {
@@ -21,3 +29,50 @@ pub fn check_valid_path_component(s: &str) -> anyhow::Result<()> {
2129
}
2230
Ok(())
2331
}
32+
33+
#[derive(Debug, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
34+
pub struct PathComponent(String);
35+
36+
impl FromStr for PathComponent {
37+
type Err = anyhow::Error;
38+
39+
fn from_str(s: &str) -> Result<Self, Self::Err> {
40+
check_valid_path_component(s)?;
41+
Ok(Self(s.to_owned()))
42+
}
43+
}
44+
45+
impl Deref for PathComponent {
46+
type Target = str;
47+
48+
fn deref(&self) -> &Self::Target {
49+
&self.0
50+
}
51+
}
52+
53+
impl From<PathComponent> for String {
54+
fn from(p: PathComponent) -> Self {
55+
p.0
56+
}
57+
}
58+
59+
impl From<FunctionName> for PathComponent {
60+
fn from(function_name: FunctionName) -> Self {
61+
function_name
62+
.parse()
63+
.expect("FunctionName isn't a valid PathComponent")
64+
}
65+
}
66+
67+
#[cfg(any(test, feature = "testing"))]
68+
impl proptest::arbitrary::Arbitrary for PathComponent {
69+
type Parameters = ();
70+
type Strategy = proptest::strategy::BoxedStrategy<Self>;
71+
72+
fn arbitrary_with((): Self::Parameters) -> Self::Strategy {
73+
use proptest::prelude::*;
74+
"_?[a-zA-Z0-9_]{1,60}(\\.js)?"
75+
.prop_filter_map("Invalid path component", |s| s.parse().ok())
76+
.boxed()
77+
}
78+
}

0 commit comments

Comments
 (0)