Commit e3980f0c authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

WIP debugging

parent 8e3102cf
...@@ -562,6 +562,12 @@ where ...@@ -562,6 +562,12 @@ where
} }
} }
AliasKey::Wildcard { suffix } => { AliasKey::Wildcard { suffix } => {
println!(
"AliasKey::Wildcard {} {}*{}",
self.request.describe_as_string(),
prefix,
suffix
);
// This is quite messy as we'd have to match against the FS to do this // This is quite messy as we'd have to match against the FS to do this
// properly. For now, try to support as many cases as possible (and as are // properly. For now, try to support as many cases as possible (and as are
// actually used). // actually used).
...@@ -570,6 +576,7 @@ where ...@@ -570,6 +576,7 @@ where
// The request is a constant string, so the PatriciaMap lookup already // The request is a constant string, so the PatriciaMap lookup already
// ensured that the prefix is matching the request. // ensured that the prefix is matching the request.
let remaining = &request[prefix.len()..]; let remaining = &request[prefix.len()..];
println!("1");
remaining.ends_with(&**suffix) remaining.ends_with(&**suffix)
} else if let Pattern::Concatenation(req) = self.request } else if let Pattern::Concatenation(req) = self.request
&& let [ && let [
...@@ -582,6 +589,7 @@ where ...@@ -582,6 +589,7 @@ where
// The request might be more specific than the mapping, e.g. for // The request might be more specific than the mapping, e.g. for
// `require('@/foo/' + dyn)` into a `@/*` mapping // `require('@/foo/' + dyn)` into a `@/*` mapping
println!("2");
req_prefix.starts_with(&**prefix) req_prefix.starts_with(&**prefix)
} else if let Pattern::Concatenation(req) = self.request } else if let Pattern::Concatenation(req) = self.request
&& let [ && let [
...@@ -590,12 +598,16 @@ where ...@@ -590,12 +598,16 @@ where
Pattern::Constant(req_suffix), Pattern::Constant(req_suffix),
] = req.as_slice() ] = req.as_slice()
{ {
println!("3");
req_prefix.starts_with(&**prefix) && req_suffix.ends_with(&**suffix) req_prefix.starts_with(&**prefix) && req_suffix.ends_with(&**suffix)
} else if !self.request.could_match(prefix) { } else if !self.request.could_match(prefix) {
// There's no way it could match if the prefix can't match. // If the whole of the prefix doesn't match, then it can't possibly
// match.
println!("4");
false false
} else if suffix.is_empty() { } else if suffix.is_empty() {
// Prefix matches the request, and suffix is empty. // Prefix could match the request, and suffix is empty.
println!("5");
true true
} else { } else {
// It may or may not match, throw an error. // It may or may not match, throw an error.
...@@ -607,13 +619,24 @@ where ...@@ -607,13 +619,24 @@ where
suffix, suffix,
))); )));
}; };
println!(
"AliasKey::Wildcard {} {}*{}, {}",
self.request.describe_as_string(),
prefix,
suffix,
is_match
);
if is_match { if is_match {
let mut remaining = self.request.clone(); let mut remaining = self.request.clone();
if let Err(e) = remaining.strip_prefix_len(prefix.len()) { if let Err(e) = remaining.strip_constant_prefix_len(prefix.len()) {
return Some(Err(e.context(self.request.describe_as_string()))); return Some(Err(e.context(format!(
"{}.strip_constant_prefix_len({:?}.len())",
self.request.describe_as_string(),
prefix
))));
} }
remaining.strip_suffix_len(suffix.len()); remaining.strip_constant_suffix_len(suffix.len());
let output = template.replace(&remaining); let output = template.replace(&remaining);
return Some(Ok(AliasMatch { return Some(Ok(AliasMatch {
......
...@@ -227,18 +227,18 @@ impl Pattern { ...@@ -227,18 +227,18 @@ impl Pattern {
longest_common_suffix(&strings) longest_common_suffix(&strings)
} }
pub fn strip_prefix(&self, prefix: &str) -> Result<Option<Self>> { pub fn strip_constant_prefix(&self, prefix: &str) -> Result<Option<Self>> {
if self.must_match(prefix) { if self.must_match(prefix) {
let mut pat = self.clone(); let mut pat = self.clone();
pat.strip_prefix_len(prefix.len())?; pat.strip_constant_prefix_len(prefix.len())?;
Ok(Some(pat)) Ok(Some(pat))
} else { } else {
Ok(None) Ok(None)
} }
} }
pub fn strip_prefix_len(&mut self, len: usize) -> Result<()> { pub fn strip_constant_prefix_len(&mut self, len: usize) -> Result<()> {
fn strip_prefix_internal(pattern: &mut Pattern, chars_to_strip: &mut usize) -> Result<()> { fn strip_internal(pattern: &mut Pattern, chars_to_strip: &mut usize) -> Result<()> {
match pattern { match pattern {
Pattern::Constant(c) => { Pattern::Constant(c) => {
let c_len = c.len(); let c_len = c.len();
...@@ -252,15 +252,15 @@ impl Pattern { ...@@ -252,15 +252,15 @@ impl Pattern {
Pattern::Concatenation(list) => { Pattern::Concatenation(list) => {
for c in list { for c in list {
if *chars_to_strip > 0 { if *chars_to_strip > 0 {
strip_prefix_internal(c, chars_to_strip)?; strip_internal(c, chars_to_strip)?;
} }
} }
} }
Pattern::Alternatives(_) => { Pattern::Alternatives(_) => {
bail!("strip_prefix pattern must be normalized"); bail!("strip_constant_prefix_len pattern must be normalized");
} }
Pattern::Dynamic | Pattern::DynamicNoSlash => { Pattern::Dynamic | Pattern::DynamicNoSlash => {
bail!("strip_prefix prefix is too long"); bail!("strip_constant_prefix_len prefix is too long");
} }
} }
Ok(()) Ok(())
...@@ -269,21 +269,17 @@ impl Pattern { ...@@ -269,21 +269,17 @@ impl Pattern {
match &mut *self { match &mut *self {
c @ Pattern::Constant(_) | c @ Pattern::Concatenation(_) => { c @ Pattern::Constant(_) | c @ Pattern::Concatenation(_) => {
let mut len_local = len; let mut len_local = len;
strip_prefix_internal(c, &mut len_local)?; strip_internal(c, &mut len_local)?;
} }
Pattern::Alternatives(list) => { Pattern::Alternatives(list) => {
for c in list { for c in list {
let mut len_local = len; let mut len_local = len;
strip_prefix_internal(c, &mut len_local)?; strip_internal(c, &mut len_local)?;
} }
} }
Pattern::Dynamic | Pattern::DynamicNoSlash => { Pattern::Dynamic | Pattern::DynamicNoSlash => {
if len > 0 { if len > 0 {
bail!( bail!("strip_constant_prefix_len prefix is too long",);
"strip_prefix prefix ({}) is too long: {}",
len,
self.describe_as_string()
);
} }
} }
}; };
...@@ -293,8 +289,8 @@ impl Pattern { ...@@ -293,8 +289,8 @@ impl Pattern {
Ok(()) Ok(())
} }
pub fn strip_suffix_len(&mut self, len: usize) { pub fn strip_constant_suffix_len(&mut self, len: usize) {
fn strip_suffix_internal(pattern: &mut Pattern, chars_to_strip: &mut usize) { fn strip_internal(pattern: &mut Pattern, chars_to_strip: &mut usize) {
match pattern { match pattern {
Pattern::Constant(c) => { Pattern::Constant(c) => {
let c_len = c.len(); let c_len = c.len();
...@@ -308,7 +304,7 @@ impl Pattern { ...@@ -308,7 +304,7 @@ impl Pattern {
Pattern::Concatenation(list) => { Pattern::Concatenation(list) => {
for c in list.iter_mut().rev() { for c in list.iter_mut().rev() {
if *chars_to_strip > 0 { if *chars_to_strip > 0 {
strip_suffix_internal(c, chars_to_strip); strip_internal(c, chars_to_strip);
} }
} }
} }
...@@ -324,12 +320,12 @@ impl Pattern { ...@@ -324,12 +320,12 @@ impl Pattern {
match &mut *self { match &mut *self {
c @ Pattern::Constant(_) | c @ Pattern::Concatenation(_) => { c @ Pattern::Constant(_) | c @ Pattern::Concatenation(_) => {
let mut len_local = len; let mut len_local = len;
strip_suffix_internal(c, &mut len_local); strip_internal(c, &mut len_local);
} }
Pattern::Alternatives(list) => { Pattern::Alternatives(list) => {
for c in list { for c in list {
let mut len_local = len; let mut len_local = len;
strip_suffix_internal(c, &mut len_local); strip_internal(c, &mut len_local);
} }
} }
Pattern::Dynamic | Pattern::DynamicNoSlash => { Pattern::Dynamic | Pattern::DynamicNoSlash => {
...@@ -2169,9 +2165,9 @@ mod tests { ...@@ -2169,9 +2165,9 @@ mod tests {
} }
#[test] #[test]
fn strip_prefix() { fn strip_constant_prefix() {
fn strip(mut pat: Pattern, n: usize) -> Pattern { fn strip(mut pat: Pattern, n: usize) -> Pattern {
pat.strip_prefix_len(n).unwrap(); pat.strip_constant_prefix_len(n).unwrap();
pat pat
} }
...@@ -2212,7 +2208,7 @@ mod tests { ...@@ -2212,7 +2208,7 @@ mod tests {
#[test] #[test]
fn strip_suffix() { fn strip_suffix() {
fn strip(mut pat: Pattern, n: usize) -> Pattern { fn strip(mut pat: Pattern, n: usize) -> Pattern {
pat.strip_suffix_len(n); pat.strip_constant_suffix_len(n);
pat pat
} }
......
...@@ -426,7 +426,7 @@ pub async fn type_resolve( ...@@ -426,7 +426,7 @@ pub async fn type_resolve(
fragment: _, fragment: _,
} = &*request.await? } = &*request.await?
{ {
let mut m = if let Some(mut stripped) = m.strip_prefix("@")? { let mut m = if let Some(mut stripped) = m.strip_constant_prefix("@")? {
stripped.replace_constants(&|c| Some(Pattern::Constant(c.replace("/", "__").into()))); stripped.replace_constants(&|c| Some(Pattern::Constant(c.replace("/", "__").into())));
stripped stripped
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment