Skip to content

Commit

Permalink
rewrite parsing, evaluation, and serialization (#67)
Browse files Browse the repository at this point in the history
Adds support for the indented syntax, plain CSS imports, `@forward`, and many other previously missing features.
  • Loading branch information
connorskees authored Dec 26, 2022
1 parent b913eab commit ffaee04
Show file tree
Hide file tree
Showing 194 changed files with 21,373 additions and 15,839 deletions.
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

0 comments on commit ffaee04

Please sign in to comment.