1
- import {
2
- type Postcss ,
3
- type ChildNode as PostCssChildNode ,
4
- type Container as PostCssContainerNode ,
5
- type Input as PostCssInput ,
6
- type Root as PostCssRoot ,
7
- type Source as PostcssSource ,
8
- } from 'postcss'
1
+ import type * as postcss from 'postcss'
9
2
import { atRule , comment , decl , rule , type AstNode } from '../../tailwindcss/src/ast'
10
3
import { createLineTable , type LineTable } from '../../tailwindcss/src/source-maps/line-table'
11
4
import type { Source , SourceLocation } from '../../tailwindcss/src/source-maps/source'
@@ -15,10 +8,10 @@ const EXCLAMATION_MARK = 0x21
15
8
16
9
export function cssAstToPostCssAst (
17
10
ast : AstNode [ ] ,
18
- source : PostcssSource | undefined ,
19
- postcss : Postcss ,
20
- ) : PostCssRoot {
21
- let inputMap = new DefaultMap < Source , PostCssInput > ( ( src ) => {
11
+ source : postcss . Source | undefined ,
12
+ postcss : postcss . Postcss ,
13
+ ) : postcss . Root {
14
+ let inputMap = new DefaultMap < Source , postcss . Input > ( ( src ) => {
22
15
return new postcss . Input ( src . code , {
23
16
map : source ?. input . map ,
24
17
from : src . file ?? undefined ,
@@ -30,7 +23,7 @@ export function cssAstToPostCssAst(
30
23
let root = postcss . root ( )
31
24
root . source = source
32
25
33
- function toSource ( loc : SourceLocation | undefined ) : PostcssSource | undefined {
26
+ function toSource ( loc : SourceLocation | undefined ) : postcss . Source | undefined {
34
27
// Use the fallback if this node has no location info in the AST
35
28
if ( ! loc ) return
36
29
if ( ! loc [ 0 ] ) return
@@ -54,7 +47,7 @@ export function cssAstToPostCssAst(
54
47
}
55
48
}
56
49
57
- function updateSource ( astNode : PostCssChildNode , loc : SourceLocation | undefined ) {
50
+ function updateSource ( astNode : postcss . ChildNode , loc : SourceLocation | undefined ) {
58
51
let source = toSource ( loc )
59
52
60
53
// The `source` property on PostCSS nodes must be defined if present because
@@ -68,7 +61,7 @@ export function cssAstToPostCssAst(
68
61
}
69
62
}
70
63
71
- function transform ( node : AstNode , parent : PostCssContainerNode ) {
64
+ function transform ( node : AstNode , parent : postcss . Container ) {
72
65
// Declaration
73
66
if ( node . kind === 'declaration' ) {
74
67
let astNode = postcss . decl ( {
@@ -130,13 +123,13 @@ export function cssAstToPostCssAst(
130
123
return root
131
124
}
132
125
133
- export function postCssAstToCssAst ( root : PostCssRoot ) : AstNode [ ] {
134
- let inputMap = new DefaultMap < PostCssInput , Source > ( ( input ) => ( {
126
+ export function postCssAstToCssAst ( root : postcss . Root ) : AstNode [ ] {
127
+ let inputMap = new DefaultMap < postcss . Input , Source > ( ( input ) => ( {
135
128
file : input . file ?? input . id ?? null ,
136
129
code : input . css ,
137
130
} ) )
138
131
139
- function toSource ( node : PostCssChildNode ) : SourceLocation | undefined {
132
+ function toSource ( node : postcss . ChildNode ) : SourceLocation | undefined {
140
133
let source = node . source
141
134
if ( ! source ) return
142
135
@@ -149,7 +142,7 @@ export function postCssAstToCssAst(root: PostCssRoot): AstNode[] {
149
142
}
150
143
151
144
function transform (
152
- node : PostCssChildNode ,
145
+ node : postcss . ChildNode ,
153
146
parent : Extract < AstNode , { nodes : AstNode [ ] } > [ 'nodes' ] ,
154
147
) {
155
148
// Declaration
0 commit comments