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'
82import { atRule , comment , decl , rule , type AstNode } from '../../tailwindcss/src/ast'
93import { createLineTable , type LineTable } from '../../tailwindcss/src/source-maps/line-table'
104import type { Source , SourceLocation } from '../../tailwindcss/src/source-maps/source'
115import { DefaultMap } from '../../tailwindcss/src/utils/default-map'
126
137const EXCLAMATION_MARK = 0x21
148
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 , {
1816 map : source ?. input . map ,
1917 from : src . file ?? undefined ,
2018 } )
@@ -25,7 +23,7 @@ export function cssAstToPostCssAst(ast: AstNode[], source: PostcssSource | undef
2523 let root = postcss . root ( )
2624 root . source = source
2725
28- function toSource ( loc : SourceLocation | undefined ) : PostcssSource | undefined {
26+ function toSource ( loc : SourceLocation | undefined ) : postcss . Source | undefined {
2927 // Use the fallback if this node has no location info in the AST
3028 if ( ! loc ) return
3129 if ( ! loc [ 0 ] ) return
@@ -49,7 +47,7 @@ export function cssAstToPostCssAst(ast: AstNode[], source: PostcssSource | undef
4947 }
5048 }
5149
52- function updateSource ( astNode : PostCssChildNode , loc : SourceLocation | undefined ) {
50+ function updateSource ( astNode : postcss . ChildNode , loc : SourceLocation | undefined ) {
5351 let source = toSource ( loc )
5452
5553 // The `source` property on PostCSS nodes must be defined if present because
@@ -63,7 +61,7 @@ export function cssAstToPostCssAst(ast: AstNode[], source: PostcssSource | undef
6361 }
6462 }
6563
66- function transform ( node : AstNode , parent : PostCssContainerNode ) {
64+ function transform ( node : AstNode , parent : postcss . Container ) {
6765 // Declaration
6866 if ( node . kind === 'declaration' ) {
6967 let astNode = postcss . decl ( {
@@ -125,13 +123,13 @@ export function cssAstToPostCssAst(ast: AstNode[], source: PostcssSource | undef
125123 return root
126124}
127125
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 ) => ( {
130128 file : input . file ?? input . id ?? null ,
131129 code : input . css ,
132130 } ) )
133131
134- function toSource ( node : PostCssChildNode ) : SourceLocation | undefined {
132+ function toSource ( node : postcss . ChildNode ) : SourceLocation | undefined {
135133 let source = node . source
136134 if ( ! source ) return
137135
@@ -144,7 +142,7 @@ export function postCssAstToCssAst(root: PostCssRoot): AstNode[] {
144142 }
145143
146144 function transform (
147- node : PostCssChildNode ,
145+ node : postcss . ChildNode ,
148146 parent : Extract < AstNode , { nodes : AstNode [ ] } > [ 'nodes' ] ,
149147 ) {
150148 // Declaration
0 commit comments