Skip to content

Improve @at-root behavior #147

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

Merged
merged 25 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
34ead38
tests: Normalize expected and actual strings to reduce noise
maranomynet Oct 1, 2022
87d30eb
style: Add @ts-check and JSDoc type definitions to surface errors
maranomynet Oct 4, 2022
f848d45
tests: Add more passing tests
maranomynet Oct 4, 2022
0832195
tests: Add failing tests for valid uses of `@at-root`
maranomynet Oct 5, 2022
8004a96
style: Rename functions and variables for clarity
maranomynet Oct 1, 2022
8d55747
rafactor: Resolve non-critical/false-positive type-checking issues
maranomynet Sep 30, 2022
c7a73d6
fix: Logic/typing error when handling @at-root rules
maranomynet Oct 5, 2022
800d131
refactor: Simplify existing logic
maranomynet Oct 1, 2022
e427a6d
fix: Move all preceeding comments with rule
maranomynet Oct 5, 2022
16c7282
fix: `@layer` blocks should also bubble
maranomynet Oct 5, 2022
37c75f9
fix: Correctly handle `with`/`without` parameters on `@at-root`
maranomynet Oct 4, 2022
3561b2e
feat: Add option `rootRuleName` to rename the custom `@at-root` rule
maranomynet Oct 5, 2022
59d784e
style: Auto formatting/linting
maranomynet Oct 5, 2022
d085b71
fix: Remove hasRootRule optimization
maranomynet Oct 5, 2022
99823d2
fix: Add back hasRootRule optimization, scoped to root node
maranomynet Oct 5, 2022
de5fbfc
docs: Update README
maranomynet Oct 5, 2022
46829dc
style: Reformat test input
maranomynet Oct 5, 2022
57655e3
tests: Add more `@at-rule` test, some failing
maranomynet Oct 5, 2022
0b16af0
fix: Failing `@at-root` edge cases
maranomynet Oct 5, 2022
4789f12
style: Fix typo in function name, remove console.log
maranomynet Oct 5, 2022
cb127a3
refactor: Remove @ts-check hack code path, use type assertion instead
maranomynet Oct 5, 2022
738c417
test: Remove comments
maranomynet Oct 5, 2022
91448d3
refactor: Use root#walkAtRules
maranomynet Oct 5, 2022
fcbb368
chore: Tweak eslint rule value
maranomynet Oct 5, 2022
ce88aac
refactor: Fix linting errors …
maranomynet Oct 6, 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## Upcoming...
* ... <!-- Add new lines here. -->
* fix: Correctly handle `with`/`without` parameters on `@at-root`
* feat: Add option `rootRuleName` to rename the custom `@at-root` rule
* fix: Errors when handling sibling `@at-root` rule blocks
* fix: Move all preceeding comments with rule
* fix: `@layer` blocks should also bubble

## 5.0.6
* Fixed custom at-rules nesting (by @bsak-shell).

Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ module.exports = {

### `bubble`

By default, plugin will bubble only `@media` and `@supports` at-rules.
You can add your custom at-rules to this list by `bubble` option:
By default, plugin will bubble only `@media`, `@supports` and `@layer`
at-rules. Use this option to add your custom at-rules to this list.

```js
postcss([ require('postcss-nested')({ bubble: ['phone'] }) ])
Expand Down Expand Up @@ -196,3 +196,27 @@ Will be compiled to:
```

This is especially useful if you want to export the empty classes with `postcss-modules`.


### `rootRuleName`

The plugin supports the SCSS custom at-rule `@at-root` which breaks rule
blocks out of their nested position. If you want, you can choose a new
custom name for this rule in your code.

```js
postcss([ require('postcss-nested')({ rootRuleName: '_escape-nesting' }) ])
```

```css
/* input */
.a {
color: white;
@_escape-nesting {
.b { color: black; }
}
}
/* output */
.a { color: white; }
.b { color: black; }
```
11 changes: 9 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { PluginCreator } from 'postcss'
declare namespace nested {
interface Options {
/**
* By default, plugin will bubble only `@media` and `@supports` at-rules.
* You can add your custom at-rules to this list by this option.
* By default, plugin will bubble only `@media`, `@supports` and `@layer`
* at-rules. Use this option to add your custom at-rules to this list.
*/
bubble?: string[]

Expand All @@ -24,6 +24,13 @@ declare namespace nested {
* to preserve them.
*/
preserveEmpty?: boolean

/**
* The plugin supports the SCSS custom at-rule `@at-root` which breaks
* rule blocks out of their nested position. If you want, you can choose
* a new custom name for this rule in your code.
*/
rootRuleName?: string
}

type Nested = PluginCreator<Options>
Expand Down
Loading