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

Refactor and improve file loading #150

Merged
merged 1 commit into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ project adheres to
now holds a `Name` rather than just a `String` for the variable name.
Also, both now holds a `SourcePos`.
* `Error::error` now takes an `Into<String>` argument (PR #151).
* The module `input` contains types types with `Context<L>`, `Loader`,
`FsLoader`, and `FsContext`, replacing the old `FileContext` and
`FsFileContext`. Also, the types `SourceKind` and `SourceName` are moved
from top-level into the `input` module (PR #150).
* The `parse_value_data` function is removed. Please create a `SourceFile`
and use the `parse` method on that instead (PR #150).

### Improvements

Expand All @@ -41,6 +47,9 @@ project adheres to
error reporting improvements (PR #148).
* Allow interpolation in css min and max function arguments.
* The url for `@use` and `@forward` must be quoted.
* Improve detection of import loops (PR #150).
* When loading files, Don't apply suffix / index-adding rules if the file
name already has a suffix (PR #150).
* Some `@` rules are now forbidden in some places as they should (PR #145).
* The css `var(...)` function is now parsed as a proper function, and not
as a special string (PR #147).
Expand All @@ -53,6 +62,9 @@ project adheres to
* Somtimes a trailing comma in argument lists is preserved (PR #147).
* Simplified `main` of the command-line by returning a `Result` (PR #151).
* Update sass-spec test suite to 2022-07-18.
* Handle tests referencing `input.scss` in spectest (include it among the
mock files, if mentioned in itself or any existing mock file) (PR #150).
* Use `lazy-regex` in spectest (PR #150).
* Some cleanups.

Thanks to @fasterthanlime (again) for reporting the problem with
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ required-features = ["spectest"]

[features]
commandline = ["clap"]
spectest = ["yaml-rust", "deunicode", "hrx-get", "regex"]
spectest = ["yaml-rust", "deunicode", "hrx-get", "lazy-regex"]
unimplemented_args = []

[dependencies]
Expand All @@ -41,7 +41,7 @@ tracing = "0.1.34"
clap = { version = "3.0.0", features = ["derive", "wrap_help"], optional = true }
deunicode = { version = "1.0", optional = true }
hrx-get = { version = "0.2.0", optional = true }
regex = { version = "1.1.0", optional = true }
lazy-regex = { version = "2.3.0", optional = true }
yaml-rust = { version = "0.4", optional = true }

[badges]
Expand Down
4 changes: 4 additions & 0 deletions src/css/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl CssString {
pub fn value(&self) -> &str {
&self.value
}
/// Take the string value, discarding quote information.
pub fn take_value(self) -> String {
self.value
}
/// Access the quotes
pub fn quotes(&self) -> Quotes {
self.quotes
Expand Down
29 changes: 21 additions & 8 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ pub enum Error {
/// This error will be wrapped in a BadCall, giving the pos of the call.
BadArguments(ArgsError, SourcePos),
/// Tried to import file at pos while already importing it at pos.
ImportLoop(SourcePos, SourcePos),
///
/// The bool is true for a used module and false for an import.
ImportLoop(bool, SourcePos, Option<SourcePos>),
/// A range error
BadRange(RangeError),
/// Error parsing sass data.
Expand Down Expand Up @@ -60,13 +62,24 @@ impl fmt::Debug for Error {
Error::BadArgument(ref name, ref problem) => {
write!(out, "${}: {}", name, problem)
}
Error::ParseError(ref err) => err.fmt(out),
Error::ImportLoop(ref pos, ref oldpos) => {
writeln!(out, "This file is already being loaded.")?;
pos.show_detail(out, '^', " new load")?;
writeln!(out)?;
oldpos.show_detail(out, '=', " original load")?;
pos.show_files(out)
Error::ParseError(ref err) => fmt::Display::fmt(err, out),
Error::ImportLoop(ref module, ref pos, ref oldpos) => {
if *module {
writeln!(
out,
"Module loop: this module is already being loaded."
)?;
} else {
writeln!(out, "This file is already being loaded.")?;
}
if let Some(oldpos) = oldpos {
pos.show_detail(out, '^', " new load")?;
writeln!(out)?;
oldpos.show_detail(out, '=', " original load")?;
pos.show_files(out)
} else {
pos.show(out)
}
}
Error::BadCall(ref msg, ref callpos, ref declpos) => {
writeln!(out, "{}", msg)?;
Expand Down
210 changes: 0 additions & 210 deletions src/file_context.rs

This file was deleted.

Loading