Skip to content

Commit

Permalink
Fix node.parent.nodes type
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 6, 2024
1 parent 65075df commit 5e7449f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/at-rule.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Container, { ContainerProps } from './container.js'
import Container, {
ContainerProps,
ContainerWithChildren
} from './container.js'

declare namespace AtRule {
export interface AtRuleRaws extends Record<string, unknown> {
Expand Down Expand Up @@ -116,7 +119,7 @@ declare class AtRule_ extends Container {
* ```
*/
params: string
parent: Container | undefined
parent: ContainerWithChildren | undefined

raws: AtRule.AtRuleRaws

Expand Down
6 changes: 6 additions & 0 deletions lib/container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import Node, { ChildNode, ChildProps, NodeProps } from './node.js'
import Rule from './rule.js'

declare namespace Container {
export class ContainerWithChildren<
Child extends Node = ChildNode
> extends Container_<Child> {
nodes: Child[]
}

export interface ValueOptions {
/**
* String that’s used to narrow down values and speed up the regexp search.
Expand Down
4 changes: 2 additions & 2 deletions lib/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Container from './container.js'
import { ContainerWithChildren } from './container.js'
import Node from './node.js'

declare namespace Declaration {
Expand Down Expand Up @@ -79,7 +79,7 @@ declare class Declaration_ extends Node {
*/
important: boolean

parent: Container | undefined
parent: ContainerWithChildren | undefined

/**
* The property name for a CSS declaration.
Expand Down
7 changes: 5 additions & 2 deletions lib/rule.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Container, { ContainerProps } from './container.js'
import Container, {
ContainerProps,
ContainerWithChildren
} from './container.js'

declare namespace Rule {
export interface RuleRaws extends Record<string, unknown> {
Expand Down Expand Up @@ -70,7 +73,7 @@ declare namespace Rule {
*/
declare class Rule_ extends Container {
nodes: NonNullable<Container['nodes']>
parent: Container | undefined
parent: ContainerWithChildren | undefined
raws: Rule.RuleRaws
/**
* The rule’s full selector represented as a string.
Expand Down
2 changes: 1 addition & 1 deletion test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const plugin: PluginCreator<string> = prop => {
return {
Declaration: (decl, { Comment, result }) => {
if (decl.prop === prop) {
decl.warn(result, `${decl.prop} found`)
decl.warn(result, `${decl.prop} found in ${decl.parent?.nodes.length}`)
decl.replaceWith(new Comment({ text: `${decl.prop} removed` }))
}
},
Expand Down

0 comments on commit 5e7449f

Please sign in to comment.