Skip to content

Commit 3111100

Browse files
authored
Fix the sass-parser types to work with the latest PostCSS (#2331)
Closes #2329
1 parent 88568af commit 3111100

File tree

6 files changed

+70
-114
lines changed

6 files changed

+70
-114
lines changed

.github/workflows/test.yml

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -312,63 +312,61 @@ jobs:
312312
env:
313313
CHROME_EXECUTABLE: chrome
314314

315-
# TODO - sass/dart-sass#2329: Re-enable once these errors are resolved.
315+
sass_parser_tests:
316+
name: "sass-parser Tests | Dart ${{ matrix.dart_channel }} | Node ${{ matrix.node-version }}"
317+
runs-on: ubuntu-latest
316318

317-
# sass_parser_tests:
318-
# name: "sass-parser Tests | Dart ${{ matrix.dart_channel }} | Node ${{ matrix.node-version }}"
319-
# runs-on: ubuntu-latest
319+
strategy:
320+
fail-fast: false
321+
matrix:
322+
dart_channel: [stable]
323+
node-version: ['lts/*']
324+
include:
325+
# Test older LTS versions
326+
#
327+
# TODO: Test on lts/-2 and lts/-3 once they support
328+
# `structuredClone()` (that is, once they're v18 or later).
329+
- os: ubuntu-latest
330+
dart_channel: stable
331+
node-version: lts/-1
332+
# Test LTS version with dart dev channel
333+
- os: ubuntu-latest
334+
dart_channel: dev
335+
node-version: 'lts/*'
320336

321-
# strategy:
322-
# fail-fast: false
323-
# matrix:
324-
# dart_channel: [stable]
325-
# node-version: ['lts/*']
326-
# include:
327-
# # Test older LTS versions
328-
# #
329-
# # TODO: Test on lts/-2 and lts/-3 once they support
330-
# # `structuredClone()` (that is, once they're v18 or later).
331-
# - os: ubuntu-latest
332-
# dart_channel: stable
333-
# node-version: lts/-1
334-
# # Test LTS version with dart dev channel
335-
# - os: ubuntu-latest
336-
# dart_channel: dev
337-
# node-version: 'lts/*'
337+
steps:
338+
- uses: actions/checkout@v4
339+
- uses: ./.github/util/initialize
340+
with:
341+
dart-sdk: ${{ matrix.dart_channel }}
342+
github-token: ${{ github.token }}
343+
node-version: ${{ matrix.node-version }}
338344

339-
# steps:
340-
# - uses: actions/checkout@v4
341-
# - uses: ./.github/util/initialize
342-
# with:
343-
# dart-sdk: ${{ matrix.dart_channel }}
344-
# github-token: ${{ github.token }}
345-
# node-version: ${{ matrix.node-version }}
346-
347-
# - run: dart run grinder pkg-npm-dev
348-
# env: {UPDATE_SASS_SASS_REPO: false}
349-
# - run: npm link
350-
# working-directory: build/npm
351-
# - run: npm install
352-
# working-directory: pkg/sass-parser/
353-
# - run: npm link sass
354-
# working-directory: pkg/sass-parser/
355-
# - name: Run tests
356-
# run: npm test
357-
# working-directory: pkg/sass-parser/
345+
- run: dart run grinder pkg-npm-dev
346+
env: {UPDATE_SASS_SASS_REPO: false}
347+
- run: npm link
348+
working-directory: build/npm
349+
- run: npm install
350+
working-directory: pkg/sass-parser/
351+
- run: npm link sass
352+
working-directory: pkg/sass-parser/
353+
- name: Run tests
354+
run: npm test
355+
working-directory: pkg/sass-parser/
358356

359-
# sass_parser_static_analysis:
360-
# name: "sass-parser Static Analysis"
361-
# runs-on: ubuntu-latest
357+
sass_parser_static_analysis:
358+
name: "sass-parser Static Analysis"
359+
runs-on: ubuntu-latest
362360

363-
# steps:
364-
# - uses: actions/checkout@v4
365-
# - uses: actions/setup-node@v4
366-
# with: {node-version: 'lts/*'}
367-
# - run: npm install
368-
# working-directory: pkg/sass-parser/
369-
# - name: Run static analysis
370-
# run: npm run check
371-
# working-directory: pkg/sass-parser/
361+
steps:
362+
- uses: actions/checkout@v4
363+
- uses: actions/setup-node@v4
364+
with: {node-version: 'lts/*'}
365+
- run: npm install
366+
working-directory: pkg/sass-parser/
367+
- name: Run static analysis
368+
run: npm run check
369+
working-directory: pkg/sass-parser/
372370

373371
# TODO - postcss/postcss#1958: Enable this once PostCSS doesn't have TypeDoc
374372
# warnings.

pkg/sass-parser/lib/src/postcss.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,4 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import * as postcss from 'postcss';
6-
7-
declare module 'postcss' {
8-
interface Container<Child extends postcss.Node = postcss.ChildNode> {
9-
// We need to be able to override this and call it as a super method.
10-
// TODO - postcss/postcss#1957: Remove this
11-
/** @hidden */
12-
normalize(
13-
node: string | postcss.ChildProps | postcss.Node,
14-
sample: postcss.Node | undefined
15-
): Child[];
16-
}
17-
}
18-
195
export const isClean: unique symbol;

pkg/sass-parser/lib/src/statement/at-rule-internal.d.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ import * as postcss from 'postcss';
66

77
import {Rule} from './rule';
88
import {Root} from './root';
9-
import {AtRule, ChildNode, ChildProps, Comment, Declaration, NewNode} from '.';
9+
import {AtRule, ChildNode, Comment, Declaration, NewNode} from '.';
1010

1111
/**
1212
* A fake intermediate class to convince TypeScript to use Sass types for
1313
* various upstream methods.
1414
*
1515
* @hidden
1616
*/
17-
export class _AtRule<
18-
Props extends Partial<postcss.AtRuleProps>,
19-
> extends postcss.AtRule {
17+
export class _AtRule<Props> extends postcss.AtRule {
2018
declare nodes: ChildNode[];
2119

2220
// Override the PostCSS container types to constrain them to Sass types only.
@@ -36,22 +34,12 @@ export class _AtRule<
3634
every(
3735
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
3836
): boolean;
39-
index(child: ChildNode | number): number;
40-
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
41-
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
37+
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
38+
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
4239
next(): ChildNode | undefined;
4340
prepend(...nodes: NewNode[]): this;
4441
prev(): ChildNode | undefined;
45-
push(child: ChildNode): this;
46-
removeChild(child: ChildNode | number): this;
47-
replaceWith(
48-
...nodes: (
49-
| postcss.Node
50-
| ReadonlyArray<postcss.Node>
51-
| ChildProps
52-
| ReadonlyArray<ChildProps>
53-
)[]
54-
): this;
42+
replaceWith(...nodes: NewNode[]): this;
5543
root(): Root;
5644
some(
5745
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean

pkg/sass-parser/lib/src/statement/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export type ChildProps = postcss.ChildProps | RuleProps | GenericAtRuleProps;
6363
* @category Statement
6464
*/
6565
export interface ContainerProps extends NodeProps {
66-
nodes?: (postcss.Node | ChildProps)[];
66+
nodes?: ReadonlyArray<postcss.Node | ChildProps>;
6767
}
6868

6969
/**
7070
* A {@link Statement} that has actual child nodes.
7171
*
7272
* @category Statement
7373
*/
74-
export type StatementWithChildren = postcss.Container<ChildNode> & {
74+
export type StatementWithChildren = postcss.Container<postcss.ChildNode> & {
7575
nodes: ChildNode[];
7676
} & Statement;
7777

@@ -123,7 +123,11 @@ export type NewNode =
123123
| undefined;
124124

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

128132
/**
129133
* A wrapper around {@link postcssNormalize} that converts the results to the

pkg/sass-parser/lib/src/statement/root-internal.d.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as postcss from 'postcss';
66

77
import {Rule} from './rule';
88
import {Root, RootProps} from './root';
9-
import {AtRule, ChildNode, ChildProps, Comment, Declaration, NewNode} from '.';
9+
import {AtRule, ChildNode, Comment, Declaration, NewNode} from '.';
1010

1111
/**
1212
* A fake intermediate class to convince TypeScript to use Sass types for
@@ -34,22 +34,12 @@ export class _Root extends postcss.Root {
3434
every(
3535
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
3636
): boolean;
37-
index(child: ChildNode | number): number;
38-
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
39-
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
37+
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
38+
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
4039
next(): ChildNode | undefined;
4140
prepend(...nodes: NewNode[]): this;
4241
prev(): ChildNode | undefined;
43-
push(child: ChildNode): this;
44-
removeChild(child: ChildNode | number): this;
45-
replaceWith(
46-
...nodes: (
47-
| postcss.Node
48-
| ReadonlyArray<postcss.Node>
49-
| ChildProps
50-
| ReadonlyArray<ChildProps>
51-
)[]
52-
): this;
42+
replaceWith(...nodes: NewNode[]): this;
5343
root(): Root;
5444
some(
5545
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean

pkg/sass-parser/lib/src/statement/rule-internal.d.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as postcss from 'postcss';
66

77
import {Rule, RuleProps} from './rule';
88
import {Root} from './root';
9-
import {AtRule, ChildNode, ChildProps, Comment, Declaration, NewNode} from '.';
9+
import {AtRule, ChildNode, Comment, Declaration, NewNode} from '.';
1010

1111
/**
1212
* A fake intermediate class to convince TypeScript to use Sass types for
@@ -34,22 +34,12 @@ export class _Rule extends postcss.Rule {
3434
every(
3535
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean
3636
): boolean;
37-
index(child: ChildNode | number): number;
38-
insertAfter(oldNode: ChildNode | number, newNode: NewNode): this;
39-
insertBefore(oldNode: ChildNode | number, newNode: NewNode): this;
37+
insertAfter(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
38+
insertBefore(oldNode: postcss.ChildNode | number, newNode: NewNode): this;
4039
next(): ChildNode | undefined;
4140
prepend(...nodes: NewNode[]): this;
4241
prev(): ChildNode | undefined;
43-
push(child: ChildNode): this;
44-
removeChild(child: ChildNode | number): this;
45-
replaceWith(
46-
...nodes: (
47-
| postcss.Node
48-
| ReadonlyArray<postcss.Node>
49-
| ChildProps
50-
| ReadonlyArray<ChildProps>
51-
)[]
52-
): this;
42+
replaceWith(...nodes: NewNode[]): this;
5343
root(): Root;
5444
some(
5545
condition: (node: ChildNode, index: number, nodes: ChildNode[]) => boolean

0 commit comments

Comments
 (0)