1- import { runWithSourceMaps as run , html , css } from './util/run'
1+ import postcss from 'postcss'
2+ import { runWithSourceMaps as run , html , css , map } from './util/run'
23import { parseSourceMaps } from './util/source-maps'
34
45it ( 'apply generates source maps' , async ( ) => {
@@ -39,7 +40,6 @@ it('apply generates source maps', async () => {
3940 expect ( sources ) . not . toContain ( '<no source>' )
4041 expect ( sources . length ) . toBe ( 1 )
4142
42- // It would make the tests nicer to read and write
4343 expect ( annotations ) . toMatchSnapshot ( )
4444} )
4545
@@ -60,7 +60,6 @@ it('preflight + base have source maps', async () => {
6060 expect ( sources ) . not . toContain ( '<no source>' )
6161 expect ( sources . length ) . toBe ( 1 )
6262
63- // It would make the tests nicer to read and write
6463 expect ( annotations ) . toMatchSnapshot ( )
6564} )
6665
@@ -81,7 +80,6 @@ it('utilities have source maps', async () => {
8180 expect ( sources ) . not . toContain ( '<no source>' )
8281 expect ( sources . length ) . toBe ( 1 )
8382
84- // It would make the tests nicer to read and write
8583 expect ( annotations ) . toStrictEqual ( [ '2:4 -> 1:0' , '2:4-23 -> 2:4-24' , '2:4 -> 3:4' , '2:23 -> 4:0' ] )
8684} )
8785
@@ -102,6 +100,50 @@ it('components have source maps', async () => {
102100 expect ( sources ) . not . toContain ( '<no source>' )
103101 expect ( sources . length ) . toBe ( 1 )
104102
105- // It would make the tests nicer to read and write
103+ expect ( annotations ) . toMatchSnapshot ( )
104+ } )
105+
106+ it ( 'source maps for layer rules are not rewritten to point to @tailwind directives' , async ( ) => {
107+ let config = {
108+ content : [ { raw : `font-normal foo hover:foo` } ] ,
109+ }
110+
111+ let utilitiesFile = postcss . parse (
112+ css `
113+ @tailwind utilities;
114+ ` ,
115+ { from : 'components.css' , map : { prev : map } }
116+ )
117+
118+ let mainCssFile = postcss . parse (
119+ css `
120+ @layer utilities {
121+ .foo {
122+ background-color : red;
123+ }
124+ }
125+ ` ,
126+ { from : 'input.css' , map : { prev : map } }
127+ )
128+
129+ // Just pretend that there's an @import in `mainCssFile` that imports the nodes from `utilitiesFile`
130+ let input = postcss . root ( {
131+ nodes : [ ...utilitiesFile . nodes , ...mainCssFile . nodes ] ,
132+ source : mainCssFile . source ,
133+ } )
134+
135+ let result = await run ( input , config )
136+
137+ let { sources, annotations } = parseSourceMaps ( result )
138+
139+ // All CSS generated by Tailwind CSS should be annotated with source maps
140+ // And always be able to point to the original source file
141+ expect ( sources ) . not . toContain ( '<no source>' )
142+
143+ // And we should see that the source map for the layer rule is not rewritten
144+ // to point to the @tailwind directive but instead points to the original
145+ expect ( sources . length ) . toBe ( 2 )
146+ expect ( sources ) . toEqual ( [ 'components.css' , 'input.css' ] )
147+
106148 expect ( annotations ) . toMatchSnapshot ( )
107149} )
0 commit comments