Skip to content

Commit

Permalink
Fix the sass-parser types to work with the latest PostCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Sep 3, 2024
1 parent 56a4237 commit 807dce2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 49 deletions.
12 changes: 0 additions & 12 deletions pkg/sass-parser/lib/src/postcss.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,4 @@

import * as postcss from 'postcss';

declare module 'postcss' {
interface Container<Child extends postcss.Node = postcss.ChildNode> {
// We need to be able to override this and call it as a super method.
// TODO - postcss/postcss#1957: Remove this
/** @hidden */
normalize(
node: string | postcss.ChildProps | postcss.Node,
sample: postcss.Node | undefined
): Child[];
}
}

export const isClean: unique symbol;
16 changes: 4 additions & 12 deletions pkg/sass-parser/lib/src/statement/at-rule-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {AtRule, ChildNode, ChildProps, Comment, Declaration, NewNode} from '.';
* @hidden
*/
export class _AtRule<
Props extends Partial<postcss.AtRuleProps>,
Props
> extends postcss.AtRule {
declare nodes: ChildNode[];

Expand All @@ -36,21 +36,13 @@ export class _AtRule<
every(
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
): boolean;
index(child: ChildNode | number): number;
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
next(): ChildNode | undefined;
prepend(...nodes: NewNode[]): this;
prev(): ChildNode | undefined;
push(child: ChildNode): this;
removeChild(child: ChildNode | number): this;
replaceWith(
...nodes: (
| postcss.Node
| ReadonlyArray<postcss.Node>
| ChildProps
| ReadonlyArray<ChildProps>
)[]
...nodes: NewNode[]
): this;
root(): Root;
some(
Expand Down
10 changes: 7 additions & 3 deletions pkg/sass-parser/lib/src/statement/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export type ChildProps = postcss.ChildProps | RuleProps | GenericAtRuleProps;
* @category Statement
*/
export interface ContainerProps extends NodeProps {
nodes?: (postcss.Node | ChildProps)[];
nodes?: ReadonlyArray<postcss.Node | ChildProps>;
}

/**
* A {@link Statement} that has actual child nodes.
*
* @category Statement
*/
export type StatementWithChildren = postcss.Container<ChildNode> & {
export type StatementWithChildren = postcss.Container<postcss.ChildNode> & {
nodes: ChildNode[];
} & Statement;

Expand Down Expand Up @@ -123,7 +123,11 @@ export type NewNode =
| undefined;

/** PostCSS's built-in normalize function. */
const postcssNormalize = postcss.Container.prototype.normalize;
const postcssNormalize = postcss.Container.prototype["normalize"] as (
nodes: postcss.NewChild,
sample: postcss.Node | undefined,
type?: 'prepend' | false
) => postcss.ChildNode[];

/**
* A wrapper around {@link postcssNormalize} that converts the results to the
Expand Down
14 changes: 3 additions & 11 deletions pkg/sass-parser/lib/src/statement/root-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ export class _Root extends postcss.Root {
every(
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
): boolean;
index(child: ChildNode | number): number;
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
next(): ChildNode | undefined;
prepend(...nodes: NewNode[]): this;
prev(): ChildNode | undefined;
push(child: ChildNode): this;
removeChild(child: ChildNode | number): this;
replaceWith(
...nodes: (
| postcss.Node
| ReadonlyArray<postcss.Node>
| ChildProps
| ReadonlyArray<ChildProps>
)[]
...nodes: NewNode[]
): this;
root(): Root;
some(
Expand Down
14 changes: 3 additions & 11 deletions pkg/sass-parser/lib/src/statement/rule-internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ export class _Rule extends postcss.Rule {
every(
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
): boolean;
index(child: ChildNode | number): number;
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
next(): ChildNode | undefined;
prepend(...nodes: NewNode[]): this;
prev(): ChildNode | undefined;
push(child: ChildNode): this;
removeChild(child: ChildNode | number): this;
replaceWith(
...nodes: (
| postcss.Node
| ReadonlyArray<postcss.Node>
| ChildProps
| ReadonlyArray<ChildProps>
)[]
...nodes: NewNode[]
): this;
root(): Root;
some(
Expand Down

0 comments on commit 807dce2

Please sign in to comment.