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

rewrite parsing, evaluation, and serialization #67

Merged
merged 98 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
c514596
tmp
connorskees Dec 9, 2022
9012b47
tmp
connorskees Dec 13, 2022
f069383
tmp
connorskees Dec 14, 2022
0a31c01
tmp
connorskees Dec 14, 2022
4ca114e
optim
connorskees Dec 15, 2022
ab37049
remove superfluous clones
connorskees Dec 15, 2022
8a6ee42
more spans
connorskees Dec 15, 2022
1b55821
resolve hang
connorskees Dec 15, 2022
60f42aa
panic less
connorskees Dec 15, 2022
e59a622
tmp
connorskees Dec 15, 2022
f0d4fa6
fix more tests
connorskees Dec 16, 2022
d25b106
change number operations
connorskees Dec 16, 2022
29289ab
modules
connorskees Dec 16, 2022
af23500
use different chars for no-unicode
connorskees Dec 16, 2022
b0df312
update span for function calls
connorskees Dec 16, 2022
277e6cf
rewrite media parsing, implement keywords fn
connorskees Dec 17, 2022
a4ca306
refactor
connorskees Dec 17, 2022
c0a1423
clippy
connorskees Dec 17, 2022
96fa552
complex units, at root queries, media query bugs
connorskees Dec 17, 2022
2198cd8
feature complete `@supports`, `@use` * alias, more robust min-max, be…
connorskees Dec 18, 2022
e2a381c
basic `@forward` support, resolve `@supports` condition bugs
connorskees Dec 19, 2022
662116e
implement clamp, math module improvements, implement calc-args and ca…
connorskees Dec 19, 2022
9a7faa6
fmt, minor `@supports` fix
connorskees Dec 19, 2022
d60885c
remove dead code
connorskees Dec 19, 2022
b45edb4
remove benches
connorskees Dec 19, 2022
d552d20
update changelog, readme
connorskees Dec 19, 2022
dae6ac5
refactor, remove dead value code, unignore newly-passing tests
connorskees Dec 19, 2022
c2acc82
more robust `@forward`
connorskees Dec 19, 2022
e35c404
more robust `@forward`
connorskees Dec 19, 2022
71fb2a1
more `@forward`
connorskees Dec 19, 2022
30b9bdf
implement `@import` conditions
connorskees Dec 19, 2022
95660da
unary and bin ops for calculation values
connorskees Dec 20, 2022
e0ffd7d
rewrite serialization, make all tests pass, make bootstrap work
connorskees Dec 21, 2022
e2c17f3
refactor whitespace methods
connorskees Dec 21, 2022
9b87894
refactor
connorskees Dec 21, 2022
2011f4c
fix scope bugs, change color format
connorskees Dec 22, 2022
0a1ecfe
support :where, better handle 3arg special rgb/rgba
connorskees Dec 22, 2022
2d7fbab
better support 1 arg rgb/rgba
connorskees Dec 22, 2022
7c56310
fix error messages, list.slash arg len
connorskees Dec 22, 2022
0e28825
more robust hsl impl
connorskees Dec 22, 2022
703d919
fix slash bug, hsl conversion bug, simplify complex units, more suppo…
connorskees Dec 22, 2022
2ddc6cc
fix directory imports
connorskees Dec 22, 2022
66b2014
refactor import tests, import path resolution
connorskees Dec 22, 2022
15e8046
allow explicit file extensions in imports
connorskees Dec 22, 2022
def2322
change evaluation order of load paths
connorskees Dec 22, 2022
0ab3725
allow calc+str, slash separator in more places
connorskees Dec 22, 2022
4a16b1f
restructure
connorskees Dec 22, 2022
4e325dd
do not crash when comparing non-finite numbers
connorskees Dec 22, 2022
2fbef20
update changelog and readme
connorskees Dec 22, 2022
c89d427
refactor calculation serialization
connorskees Dec 22, 2022
eb7dfb5
small refactor
connorskees Dec 22, 2022
6e1a49a
remove unused parens
connorskees Dec 22, 2022
53c8041
clippy
connorskees Dec 23, 2022
e9b41a7
remove bigint and num traits dep
connorskees Dec 23, 2022
e97a9bc
tidy
connorskees Dec 23, 2022
9beca64
resolve `@for` crash for invalid keyword
connorskees Dec 23, 2022
badd725
resolve crashes
connorskees Dec 23, 2022
7678ef9
more crashes
connorskees Dec 23, 2022
d2b040a
do not crash for `@use` when importing empty string
connorskees Dec 23, 2022
6ca33fb
resolve media query crash
connorskees Dec 23, 2022
fcd1f4d
crashes, 2 arg rgb
connorskees Dec 23, 2022
7fec8ae
fully implement complex units
connorskees Dec 23, 2022
c50eece
color bug, unit equality bug, extend error message, add ignored tests
connorskees Dec 23, 2022
e11710a
resolve crash on custom property in weird places
connorskees Dec 23, 2022
8926958
resolve arg crash
connorskees Dec 23, 2022
586203e
do not use nightly fn
connorskees Dec 23, 2022
c9bfe2a
resolve last arg crash
connorskees Dec 23, 2022
a368d3e
tidy
connorskees Dec 23, 2022
5a0ef64
rename parser to visitor in builtins
connorskees Dec 23, 2022
4bb4663
unify different number types
connorskees Dec 23, 2022
236cb26
update changelog
connorskees Dec 23, 2022
5e24fae
clippy+lints
connorskees Dec 24, 2022
89d7201
recognize mixins when `@use` is aliased to `*`
connorskees Dec 24, 2022
c64caa6
solve some hwb failures
connorskees Dec 24, 2022
5151e25
support 1 arg hwb
connorskees Dec 24, 2022
a46e90c
add back support for compressed output
connorskees Dec 24, 2022
deeec7d
resolve borrow mut crash
connorskees Dec 24, 2022
d024427
improve error message
connorskees Dec 24, 2022
edccc12
don't use fmt to serialize selectors
connorskees Dec 24, 2022
3b61c5f
specialized serialization for type selectors
connorskees Dec 24, 2022
fe4a442
append to imports only when necessary
connorskees Dec 24, 2022
5d9e301
remove superfluous selector wrapper
connorskees Dec 24, 2022
d8daa51
add back (partial) support for meta.load-css
connorskees Dec 24, 2022
235b0b5
Revert "remove superfluous selector wrapper"
connorskees Dec 24, 2022
3c02d0c
resolve calculation todo
connorskees Dec 24, 2022
4949187
serialize media queries in final pass
connorskees Dec 24, 2022
79accc3
more accurate spans
connorskees Dec 24, 2022
94184d5
clippy todo: review changes
connorskees Dec 24, 2022
f9bd375
Merge branch 'master' of https://github.com/connorskees/grass into re…
connorskees Dec 24, 2022
8f552b9
update dart-sass version in CI
connorskees Dec 25, 2022
1ce2b84
rewrite
connorskees Dec 25, 2022
84e7c7d
update dart-sass version
connorskees Dec 25, 2022
9c97ccd
add ignored at-root test
connorskees Dec 25, 2022
c0c505c
support the indented syntax
connorskees Dec 26, 2022
a2ff27e
simplify lifetimes
connorskees Dec 26, 2022
6179d0e
better parsing of loud comments in sass
connorskees Dec 26, 2022
da77ce7
restructure
connorskees Dec 26, 2022
36de6a8
fmt
connorskees Dec 26, 2022
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
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/incorrect-sass-output.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
name: Incorrect SASS Output
about: There exists a differential between the output of grass and dart-sass
name: Incorrect Sass Output
about: `grass` and `dart-sass` differ in output or `grass` reports and error for a valid style sheet
title: ''
labels: bug
assignees: connorskees

---

**Minimal Reproducible Example**:
**Failing Sass**:
```
a {
color: red;
}
```

<!-- Showing output from both tools is optional, but does help in debugging -->
**`grass` Output**:
```
a {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ jobs:
- name: Build
run: cargo build

- name: Install dart-sass 1.36.0
- name: Install dart-sass 1.54.3
run: |
wget https://github.com/sass/dart-sass/releases/download/1.36.0/dart-sass-1.36.0-linux-x64.tar.gz
tar -xzvf dart-sass-1.36.0-linux-x64.tar.gz
wget https://github.com/sass/dart-sass/releases/download/1.54.3/dart-sass-1.54.3-linux-x64.tar.gz
tar -xzvf dart-sass-1.54.3-linux-x64.tar.gz

- name: Install bootstrap
run: git clone --depth=1 --branch v5.0.2 https://github.com/twbs/bootstrap.git
Expand Down
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
# TBD

- complete rewrite of parsing, evaluation, and serialization steps
- **implement the indented syntax**
- **implement plain CSS imports**
- support for custom properties
- represent all numbers as f64, rather than using arbitrary precision
- implement media query merging
- implement builtin function `keywords`
- implement Infinity and -Infinity
- implement the `@forward` rule
- feature complete parsing of `@supports` conditions
- support media queries level 4
- implement calculation simplification and the calculation value type
- implement builtin fns `calc-args`, `calc-name`
- add builtin math module variables `$epsilon`, `$max-safe-integer`, `$min-safe-integer`, `$max-number`, `$min-number`
- allow angle units `turn` and `grad` in builtin trigonometry functions
- implement `@at-root` conditions
- implement `@import` conditions
- remove dependency on `num-rational` and `beef`
- support control flow inside declaration blocks
For example:
```scss
a {
-webkit-: {
@if 1 == 1 {
scrollbar: red
}
}
}
```

will now emit

```css
a {
-webkit-scrollbar: red;
}
```
- always emit `rgb`/`rgba`/`hsl`/`hsla` for colors declared as such in expanded mode
- more efficiently compress colors in compressed mode
- treat `:where` the same as `:is` in extension
- support "import-only" files
- treat `@elseif` the same as `@else if`
- implement division of non-comparable units and feature complete support for complex units
- support 1 arg color.hwb()

UPCOMING:

- error when `@extend` is used across `@media` boundaries
- more robust support for NaN in builtin functions

# 0.11.2

- make `grass::Error` a `Send` type
Expand Down
49 changes: 9 additions & 40 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,32 @@ path = "src/lib.rs"
# crate-type = ["cdylib", "rlib"]
bench = false

[[bench]]
path = "benches/variables.rs"
name = "variables"
harness = false

[[bench]]
path = "benches/colors.rs"
name = "colors"
harness = false

[[bench]]
path = "benches/numbers.rs"
name = "numbers"
harness = false

[[bench]]
path = "benches/control_flow.rs"
name = "control_flow"
harness = false

[[bench]]
path = "benches/styles.rs"
name = "styles"
harness = false


[dependencies]
clap = { version = "2.34.0", optional = true }
num-rational = "0.4"
num-bigint = "0.4"
num-traits = "0.2.14"
# todo: use lazy_static
once_cell = "1.15.0"
# todo: use xorshift for random numbers
rand = { version = "0.8", optional = true }
# todo: update to use asref<path>
# todo: update to expose more info (for eww)
# todo: update to use text_size::TextRange
codemap = "0.1.3"
wasm-bindgen = { version = "0.2.68", optional = true }
beef = "0.5"
# todo: use phf for global functions
phf = { version = "0.11", features = ["macros"] }
# criterion is not a dev-dependency because it makes tests take too
# long to compile, and you cannot make dev-dependencies optional
criterion = { version = "0.4.0", optional = true }
indexmap = "1.9.1"
indexmap = "1.9.0"
# todo: do we really need interning for things?
lasso = "0.6"

[features]
# todo: no commandline by default
default = ["commandline", "random"]
# Option (enabled by default): build a binary using clap
commandline = ["clap"]
# Option: enable nightly-only features (for right now, only the `track_caller` attribute)
nightly = []
# Option (enabled by default): enable the builtin functions `random([$limit])` and `unique-id()`
random = ["rand"]
# Option: expose JavaScript-friendly WebAssembly exports
wasm-exports = ["wasm-bindgen"]
# Option: enable features that assist in profiling (e.g. inline(never))
profiling = []
# Option: enable criterion for benchmarking
bench = ["criterion"]

[dev-dependencies]
tempfile = "3.3.0"
Expand Down
48 changes: 11 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
This crate aims to provide a high level interface for compiling Sass into
plain CSS. It offers a very limited API, currently exposing only 2 functions.

In addition to a library, also included is a binary that is intended to act as an invisible
In addition to a library, this crate also includes a binary that is intended to act as an invisible
replacement to the Sass commandline executable.

This crate aims to achieve complete feature parity with the `dart-sass` reference
implementation. A deviation from the `dart-sass` implementation can be considered
a bug except for in the following situations:

- Error messages
- Error spans
- Certain aspects of the indented syntax
- Potentially others in the future
a bug except for in the case of error message and error spans.

[Documentation](https://docs.rs/grass/)
[crates.io](https://crates.io/crates/grass)
Expand All @@ -24,17 +19,7 @@ a bug except for in the following situations:

Every commit of `grass` is tested against bootstrap v5.0.2, and every release is tested against the last 2,500 commits of bootstrap's `main` branch.

That said, there are a number of known missing features and bugs. The notable features remaining are

```
indented syntax
@forward and more complex uses of @use
@at-root and @import media queries
@media query merging
/ as a separator in color functions, e.g. rgba(255, 255, 255 / 0)
Infinity and -Infinity
builtin meta function `keywords`
```
That said, there are a number of known missing features and bugs. The rough edges of `grass` largely include `@forward` and more complex uses of `@uses`. We support basic usage of these rules, but more advanced features such as `@import`ing modules containing `@forward` with prefixes may not behave as expected.

All known missing features and bugs are tracked in [#19](https://github.com/connorskees/grass/issues/19).

Expand All @@ -44,11 +29,10 @@ All known missing features and bugs are tracked in [#19](https://github.com/conn

`grass` experimentally releases a
[WASM version of the library to npm](https://www.npmjs.com/package/@connorskees/grass),
compiled using wasm-bindgen. To use `grass` in your JavaScript projects, just run
`npm install @connorskees/grass` to add it to your package.json. Better documentation
for this version will be provided when the library becomes more stable.
compiled using wasm-bindgen. To use `grass` in your JavaScript projects, run
`npm install @connorskees/grass` to add it to your package.json. This version of grass is not currently well documented, but one can find example usage in the [`grassmeister` repository](https://github.com/connorskees/grassmeister).

## Features
## Cargo Features

### commandline

Expand All @@ -73,28 +57,16 @@ are in the official spec.

Having said that, to run the official test suite,

```bash
git clone https://github.com/connorskees/grass --recursive
cd grass
cargo b --release
./sass-spec/sass-spec.rb -c './target/release/grass'
```

Note: you will have to install [ruby](https://www.ruby-lang.org/en/downloads/),
[bundler](https://bundler.io/) and run `bundle install` in `./sass-spec/`.
This might also require you to install the requirements separately
for [curses](https://github.com/ruby/curses).

Alternatively, it is possible to use nodejs to run the spec,

```bash
# This script expects node >=v14.14.0. Check version with `node --version`
git clone https://github.com/connorskees/grass --recursive
cd grass && cargo b --release
cd sass-spec && npm install
npm run sass-spec -- --command '../target/release/grass'
npm run sass-spec -- --impl=dart-sass --command '../target/release/grass'
```

The spec runner does not work on Windows.

These numbers come from a default run of the Sass specification as shown above.

```
Expand All @@ -103,3 +75,5 @@ PASSING: 4205
FAILING: 2051
TOTAL: 6256
```

<!-- todo: msrv 1.41.1 -->
5 changes: 0 additions & 5 deletions benches/big_for.scss

This file was deleted.

26 changes: 0 additions & 26 deletions benches/colors.rs

This file was deleted.

11 changes: 0 additions & 11 deletions benches/control_flow.rs

This file was deleted.

77 changes: 0 additions & 77 deletions benches/many_floats.scss

This file was deleted.

Loading