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

Improve AtRule#nodes type #1921

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/at-rule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ declare class AtRule_ extends Container {
* ```
*/
name: string
/**
* An array containing the layer’s children.
*
* ```js
* const root = postcss.parse('@layer example { a { color: black } }')
* const layer = root.first
* layer.nodes.length //=> 1
* layer.nodes[0].selector //=> 'a'
* ```
*
* Can be `undefinded` if the at-rule has no body.
*
* ```js
* const root = postcss.parse('@layer a, b, c;')
* const layer = root.first
* layer.nodes //=> undefined
* ```
*/
node: Container['nodes'] | undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be nodes: instead of node:?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry. I was wondering why that was working all of a sudden. Because with this change TS is not happy:

Property 'nodes' in type 'AtRule_' is not assignable to the same property in base type 'Container_'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will open a new PR, I already have a branch ready :D

/**
* The at-rule’s parameters, the values that follow the at-rule’s name
* but precede any `{}` block.
Expand Down
6 changes: 6 additions & 0 deletions test/at-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ test('clone spaces from another at-rule', () => {
is(rule.toString(), '@page 1{}')
})

test('at-rule without body has no nodes property', () => {
let root = parse('@layer a, b, c;');
let layer = root.first as AtRule
type(layer.nodes, 'undefined')
});

test.run()