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