Skip to content

Commit

Permalink
Merge pull request #1815 from remcohaszing/fix-types
Browse files Browse the repository at this point in the history
Fix type definitions
  • Loading branch information
ai committed Apr 15, 2023
2 parents c6dd496 + 98de266 commit a9a157a
Show file tree
Hide file tree
Showing 33 changed files with 983 additions and 752 deletions.
95 changes: 52 additions & 43 deletions lib/at-rule.d.ts
@@ -1,48 +1,53 @@
import Container, { ContainerProps } from './container.js'

interface AtRuleRaws extends Record<string, unknown> {
/**
* The space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
*/
before?: string
declare namespace AtRule {
export interface AtRuleRaws extends Record<string, unknown> {
/**
* The space symbols before the node. It also stores `*`
* and `_` symbols before the declaration (IE hack).
*/
before?: string

/**
* The space symbols after the last child of the node to the end of the node.
*/
after?: string
/**
* The space symbols after the last child of the node to the end of the node.
*/
after?: string

/**
* The space between the at-rule name and its parameters.
*/
afterName?: string
/**
* The space between the at-rule name and its parameters.
*/
afterName?: string

/**
* The symbols between the last parameter and `{` for rules.
*/
between?: string
/**
* The symbols between the last parameter and `{` for rules.
*/
between?: string

/**
* Contains `true` if the last child has an (optional) semicolon.
*/
semicolon?: boolean
/**
* Contains `true` if the last child has an (optional) semicolon.
*/
semicolon?: boolean

/**
* The rule’s selector with comments.
*/
params?: {
value: string
raw: string
/**
* The rule’s selector with comments.
*/
params?: {
value: string
raw: string
}
}
}

export interface AtRuleProps extends ContainerProps {
/** Name of the at-rule. */
name: string
/** Parameters following the name of the at-rule. */
params?: string | number
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: AtRuleRaws
export interface AtRuleProps extends ContainerProps {
/** Name of the at-rule. */
name: string
/** Parameters following the name of the at-rule. */
params?: string | number
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: AtRuleRaws
}

// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { AtRule_ as default }
}

/**
Expand Down Expand Up @@ -70,10 +75,10 @@ export interface AtRuleProps extends ContainerProps {
* media.nodes //=> []
* ```
*/
export default class AtRule extends Container {
declare class AtRule_ extends Container {
type: 'atrule'
parent: Container | undefined
raws: AtRuleRaws
raws: AtRule.AtRuleRaws

/**
* The at-rule’s name immediately follows the `@`.
Expand All @@ -98,9 +103,13 @@ export default class AtRule extends Container {
*/
params: string

constructor(defaults?: AtRuleProps)
assign(overrides: object | AtRuleProps): this
clone(overrides?: Partial<AtRuleProps>): this
cloneBefore(overrides?: Partial<AtRuleProps>): this
cloneAfter(overrides?: Partial<AtRuleProps>): this
constructor(defaults?: AtRule.AtRuleProps)
assign(overrides: object | AtRule.AtRuleProps): this
clone(overrides?: Partial<AtRule.AtRuleProps>): this
cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
}

declare class AtRule extends AtRule_ {}

export = AtRule
61 changes: 35 additions & 26 deletions lib/comment.d.ts
@@ -1,28 +1,33 @@
import Container from './container.js'
import Node, { NodeProps } from './node.js'

interface CommentRaws extends Record<string, unknown> {
/**
* The space symbols before the node.
*/
before?: string
declare namespace Comment {
export interface CommentRaws extends Record<string, unknown> {
/**
* The space symbols before the node.
*/
before?: string

/**
* The space symbols between `/*` and the comment’s text.
*/
left?: string
/**
* The space symbols between `/*` and the comment’s text.
*/
left?: string

/**
* The space symbols between the comment’s text.
*/
right?: string
}
/**
* The space symbols between the comment’s text.
*/
right?: string
}

export interface CommentProps extends NodeProps {
/** Content of the comment. */
text: string
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: CommentRaws
export interface CommentProps extends NodeProps {
/** Content of the comment. */
text: string
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
raws?: CommentRaws
}

// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Comment_ as default }
}

/**
Expand All @@ -38,19 +43,23 @@ export interface CommentProps extends NodeProps {
* Comments inside selectors, at-rule parameters, or declaration values
* will be stored in the `raws` properties explained above.
*/
export default class Comment extends Node {
declare class Comment_ extends Node {
type: 'comment'
parent: Container | undefined
raws: CommentRaws
raws: Comment.CommentRaws

/**
* The comment's text.
*/
text: string

constructor(defaults?: CommentProps)
assign(overrides: object | CommentProps): this
clone(overrides?: Partial<CommentProps>): this
cloneBefore(overrides?: Partial<CommentProps>): this
cloneAfter(overrides?: Partial<CommentProps>): this
constructor(defaults?: Comment.CommentProps)
assign(overrides: object | Comment.CommentProps): this
clone(overrides?: Partial<Comment.CommentProps>): this
cloneBefore(overrides?: Partial<Comment.CommentProps>): this
cloneAfter(overrides?: Partial<Comment.CommentProps>): this
}

declare class Comment extends Comment_ {}

export = Comment
37 changes: 23 additions & 14 deletions lib/container.d.ts
Expand Up @@ -4,20 +4,25 @@ import Comment from './comment.js'
import AtRule from './at-rule.js'
import Rule from './rule.js'

interface ValueOptions {
/**
* An array of property names.
*/
props?: string[]
declare namespace Container {
export interface ValueOptions {
/**
* An array of property names.
*/
props?: string[]

/**
* String that’s used to narrow down values and speed up the regexp search.
*/
fast?: string
}
/**
* String that’s used to narrow down values and speed up the regexp search.
*/
fast?: string
}

export interface ContainerProps extends NodeProps {
nodes?: (ChildNode | ChildProps)[]
}

export interface ContainerProps extends NodeProps {
nodes?: (ChildNode | ChildProps)[]
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { Container_ as default }
}

/**
Expand All @@ -27,7 +32,7 @@ export interface ContainerProps extends NodeProps {
* Note that all containers can store any content. If you write a rule inside
* a rule, PostCSS will parse it.
*/
export default abstract class Container<
declare abstract class Container_<
Child extends Node = ChildNode
> extends Node {
/**
Expand Down Expand Up @@ -390,7 +395,7 @@ export default abstract class Container<
*/
replaceValues(
pattern: string | RegExp,
options: ValueOptions,
options: Container.ValueOptions,
replaced: string | { (substring: string, ...args: any[]): string }
): this
replaceValues(
Expand Down Expand Up @@ -440,3 +445,7 @@ export default abstract class Container<
*/
index(child: Child | number): number
}

declare class Container<Child extends Node = ChildNode> extends Container_<Child> {}

export = Container
35 changes: 22 additions & 13 deletions lib/css-syntax-error.d.ts
@@ -1,18 +1,23 @@
import { FilePosition } from './input.js'

/**
* A position that is part of a range.
*/
export interface RangePosition {
declare namespace CssSyntaxError {
/**
* The line number in the input.
* A position that is part of a range.
*/
line: number
export interface RangePosition {
/**
* The line number in the input.
*/
line: number

/**
* The column number in the input.
*/
column: number
/**
* The column number in the input.
*/
column: number
}

// eslint-disable-next-line @typescript-eslint/no-use-before-define
export { CssSyntaxError_ as default }
}

/**
Expand Down Expand Up @@ -44,7 +49,7 @@ export interface RangePosition {
* }
* ```
*/
export default class CssSyntaxError {
declare class CssSyntaxError_ {
/**
* Instantiates a CSS syntax error. Can be instantiated for a single position
* or for a range.
Expand All @@ -59,8 +64,8 @@ export default class CssSyntaxError {
*/
constructor(
message: string,
lineOrStartPos?: number | RangePosition,
columnOrEndPos?: number | RangePosition,
lineOrStartPos?: number | CssSyntaxError.RangePosition,
columnOrEndPos?: number | CssSyntaxError.RangePosition,
source?: string,
file?: string,
plugin?: string
Expand Down Expand Up @@ -237,3 +242,7 @@ export default class CssSyntaxError {
*/
showSourceCode(color?: boolean): string
}

declare class CssSyntaxError extends CssSyntaxError_ {}

export = CssSyntaxError

0 comments on commit a9a157a

Please sign in to comment.