mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2026-01-18 16:17:36 +00:00
542 lines
13 KiB
JavaScript
542 lines
13 KiB
JavaScript
import postcss from 'postcss'
|
|
import { parseSourceMaps } from './util/source-maps'
|
|
import { runWithSourceMaps as run, html, css, map } from './util/run'
|
|
|
|
test('apply generates source maps', async () => {
|
|
let config = {
|
|
content: [
|
|
{
|
|
raw: html`
|
|
<div class="with-declaration"></div>
|
|
<div class="with-comment"></div>
|
|
<div class="just-apply"></div>
|
|
`,
|
|
},
|
|
],
|
|
corePlugins: { preflight: false },
|
|
}
|
|
|
|
let input = css`
|
|
.with-declaration {
|
|
background-color: red;
|
|
@apply h-4 w-4 bg-green-500;
|
|
}
|
|
|
|
.with-comment {
|
|
/* sourcemap will work here too */
|
|
@apply h-4 w-4 bg-red-500;
|
|
}
|
|
|
|
.just-apply {
|
|
@apply h-4 w-4 bg-black;
|
|
}
|
|
`
|
|
|
|
let result = await run(input, config)
|
|
let { sources, annotations } = parseSourceMaps(result)
|
|
|
|
// All CSS generated by Tailwind CSS should be annotated with source maps
|
|
// And always be able to point to the original source file
|
|
expect(sources).not.toContain('<no source>')
|
|
expect(sources.length).toBe(1)
|
|
|
|
expect(annotations).toEqual([
|
|
'2:4 -> 2:4',
|
|
'3:6-27 -> 3:6-27',
|
|
'4:6-33 -> 4:6-18',
|
|
'4:6-33 -> 5:6-17',
|
|
'4:6-33 -> 6:6-24',
|
|
'4:6-33 -> 7:6-61',
|
|
'5:4 -> 8:4',
|
|
'7:4 -> 10:4',
|
|
'8:6-39 -> 11:6-39',
|
|
'9:6-31 -> 12:6-18',
|
|
'9:6-31 -> 13:6-17',
|
|
'9:6-31 -> 14:6-24',
|
|
'9:6-31 -> 15:6-61',
|
|
'10:4 -> 16:4',
|
|
'13:6 -> 18:4',
|
|
'13:6-29 -> 19:6-18',
|
|
'13:6-29 -> 20:6-17',
|
|
'13:6-29 -> 21:6-24',
|
|
'13:6 -> 22:6',
|
|
'13:29 -> 23:0',
|
|
])
|
|
})
|
|
|
|
test('preflight + base have source maps', async () => {
|
|
let config = {
|
|
content: [],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind base;
|
|
`
|
|
|
|
let result = await run(input, config)
|
|
let { sources, annotations } = parseSourceMaps(result)
|
|
|
|
// All CSS generated by Tailwind CSS should be annotated with source maps
|
|
// And always be able to point to the original source file
|
|
expect(sources).not.toContain('<no source>')
|
|
expect(sources.length).toBe(1)
|
|
|
|
expect(annotations).toEqual([
|
|
'2:4 -> 1:0',
|
|
'2:18-4 -> 3:1-2',
|
|
'2:18 -> 6:1',
|
|
'2:4 -> 8:0',
|
|
'2:4-18 -> 11:2-32',
|
|
'2:4-18 -> 12:2-25',
|
|
'2:4-18 -> 13:2-29',
|
|
'2:4-18 -> 14:2-31',
|
|
'2:18 -> 15:0',
|
|
'2:4 -> 17:0',
|
|
'2:4-18 -> 19:2-18',
|
|
'2:18 -> 20:0',
|
|
'2:4 -> 22:0',
|
|
'2:18 -> 30:1',
|
|
'2:4 -> 32:0',
|
|
'2:4-18 -> 34:2-26',
|
|
'2:4-18 -> 35:2-40',
|
|
'2:4-18 -> 36:2-26',
|
|
'2:4-18 -> 37:2-21',
|
|
'2:4-18 -> 38:2-137',
|
|
'2:4-18 -> 39:2-39',
|
|
'2:4-18 -> 40:2-41',
|
|
'2:4-18 -> 41:2-50',
|
|
'2:18 -> 42:0',
|
|
'2:4 -> 44:0',
|
|
'2:18 -> 47:1',
|
|
'2:4 -> 49:0',
|
|
'2:4-18 -> 50:2-19',
|
|
'2:4-18 -> 51:2-30',
|
|
'2:18 -> 52:0',
|
|
'2:4 -> 54:0',
|
|
'2:18 -> 58:1',
|
|
'2:4 -> 60:0',
|
|
'2:4-18 -> 61:2-19',
|
|
'2:4-18 -> 62:2-24',
|
|
'2:4-18 -> 63:2-31',
|
|
'2:18 -> 64:0',
|
|
'2:4 -> 66:0',
|
|
'2:18 -> 68:1',
|
|
'2:4 -> 70:0',
|
|
'2:4-18 -> 71:2-35',
|
|
'2:18 -> 72:0',
|
|
'2:4 -> 74:0',
|
|
'2:18 -> 76:1',
|
|
'2:4 -> 78:0',
|
|
'2:4-18 -> 84:2-20',
|
|
'2:4-18 -> 85:2-22',
|
|
'2:18 -> 86:0',
|
|
'2:4 -> 88:0',
|
|
'2:18 -> 90:1',
|
|
'2:4 -> 92:0',
|
|
'2:4-18 -> 93:2-16',
|
|
'2:4-18 -> 94:2-26',
|
|
'2:18 -> 95:0',
|
|
'2:4 -> 97:0',
|
|
'2:18 -> 99:1',
|
|
'2:4 -> 101:0',
|
|
'2:4-18 -> 103:2-21',
|
|
'2:18 -> 104:0',
|
|
'2:4 -> 106:0',
|
|
'2:18 -> 111:1',
|
|
'2:4 -> 113:0',
|
|
'2:4-18 -> 117:2-121',
|
|
'2:4-18 -> 118:2-39',
|
|
'2:4-18 -> 119:2-41',
|
|
'2:4-18 -> 120:2-24',
|
|
'2:18 -> 121:0',
|
|
'2:4 -> 123:0',
|
|
'2:18 -> 125:1',
|
|
'2:4 -> 127:0',
|
|
'2:4-18 -> 128:2-16',
|
|
'2:18 -> 129:0',
|
|
'2:4 -> 131:0',
|
|
'2:18 -> 133:1',
|
|
'2:4 -> 135:0',
|
|
'2:4-18 -> 137:2-16',
|
|
'2:4-18 -> 138:2-16',
|
|
'2:4-18 -> 139:2-20',
|
|
'2:4-18 -> 140:2-26',
|
|
'2:18 -> 141:0',
|
|
'2:4 -> 143:0',
|
|
'2:4-18 -> 144:2-17',
|
|
'2:18 -> 145:0',
|
|
'2:4 -> 147:0',
|
|
'2:4-18 -> 148:2-13',
|
|
'2:18 -> 149:0',
|
|
'2:4 -> 151:0',
|
|
'2:18 -> 155:1',
|
|
'2:4 -> 157:0',
|
|
'2:4-18 -> 158:2-24',
|
|
'2:4-18 -> 159:2-31',
|
|
'2:4-18 -> 160:2-35',
|
|
'2:18 -> 161:0',
|
|
'2:4 -> 163:0',
|
|
'2:18 -> 167:1',
|
|
'2:4 -> 169:0',
|
|
'2:4-18 -> 174:2-30',
|
|
'2:4-18 -> 175:2-40',
|
|
'2:4-18 -> 176:2-42',
|
|
'2:4-18 -> 177:2-25',
|
|
'2:4-18 -> 178:2-30',
|
|
'2:4-18 -> 179:2-30',
|
|
'2:4-18 -> 180:2-33',
|
|
'2:4-18 -> 181:2-24',
|
|
'2:4-18 -> 182:2-19',
|
|
'2:4-18 -> 183:2-20',
|
|
'2:18 -> 184:0',
|
|
'2:4 -> 186:0',
|
|
'2:18 -> 188:1',
|
|
'2:4 -> 190:0',
|
|
'2:4-18 -> 192:2-22',
|
|
'2:18 -> 193:0',
|
|
'2:4 -> 195:0',
|
|
'2:18 -> 198:1',
|
|
'2:4 -> 200:0',
|
|
'2:4-18 -> 204:2-36',
|
|
'2:4-18 -> 205:2-39',
|
|
'2:4-18 -> 206:2-32',
|
|
'2:18 -> 207:0',
|
|
'2:4 -> 209:0',
|
|
'2:18 -> 211:1',
|
|
'2:4 -> 213:0',
|
|
'2:4-18 -> 214:2-15',
|
|
'2:18 -> 215:0',
|
|
'2:4 -> 217:0',
|
|
'2:18 -> 219:1',
|
|
'2:4 -> 221:0',
|
|
'2:4-18 -> 222:2-18',
|
|
'2:18 -> 223:0',
|
|
'2:4 -> 225:0',
|
|
'2:18 -> 227:1',
|
|
'2:4 -> 229:0',
|
|
'2:4-18 -> 230:2-26',
|
|
'2:18 -> 231:0',
|
|
'2:4 -> 233:0',
|
|
'2:18 -> 235:1',
|
|
'2:4 -> 237:0',
|
|
'2:4-18 -> 239:2-14',
|
|
'2:18 -> 240:0',
|
|
'2:4 -> 242:0',
|
|
'2:18 -> 245:1',
|
|
'2:4 -> 247:0',
|
|
'2:4-18 -> 248:2-39',
|
|
'2:4-18 -> 249:2-30',
|
|
'2:18 -> 250:0',
|
|
'2:4 -> 252:0',
|
|
'2:18 -> 254:1',
|
|
'2:4 -> 256:0',
|
|
'2:4-18 -> 257:2-26',
|
|
'2:18 -> 258:0',
|
|
'2:4 -> 260:0',
|
|
'2:18 -> 263:1',
|
|
'2:4 -> 265:0',
|
|
'2:4-18 -> 266:2-36',
|
|
'2:4-18 -> 267:2-23',
|
|
'2:18 -> 268:0',
|
|
'2:4 -> 270:0',
|
|
'2:18 -> 272:1',
|
|
'2:4 -> 274:0',
|
|
'2:4-18 -> 275:2-20',
|
|
'2:18 -> 276:0',
|
|
'2:4 -> 278:0',
|
|
'2:18 -> 280:1',
|
|
'2:4 -> 282:0',
|
|
'2:4-18 -> 295:2-11',
|
|
'2:18 -> 296:0',
|
|
'2:4 -> 298:0',
|
|
'2:4-18 -> 299:2-11',
|
|
'2:4-18 -> 300:2-12',
|
|
'2:18 -> 301:0',
|
|
'2:4 -> 303:0',
|
|
'2:4-18 -> 304:2-12',
|
|
'2:18 -> 305:0',
|
|
'2:4 -> 307:0',
|
|
'2:4-18 -> 310:2-18',
|
|
'2:4-18 -> 311:2-11',
|
|
'2:4-18 -> 312:2-12',
|
|
'2:18 -> 313:0',
|
|
'2:4 -> 315:0',
|
|
'2:18 -> 317:1',
|
|
'2:4 -> 318:0',
|
|
'2:4-18 -> 319:2-12',
|
|
'2:18 -> 320:0',
|
|
'2:4 -> 322:0',
|
|
'2:18 -> 324:1',
|
|
'2:4 -> 326:0',
|
|
'2:4-18 -> 327:2-18',
|
|
'2:18 -> 328:0',
|
|
'2:4 -> 330:0',
|
|
'2:18 -> 333:1',
|
|
'2:4 -> 335:0',
|
|
'2:4-18 -> 337:2-20',
|
|
'2:4-18 -> 338:2-24',
|
|
'2:18 -> 339:0',
|
|
'2:4 -> 341:0',
|
|
'2:18 -> 343:1',
|
|
'2:4 -> 345:0',
|
|
'2:4-18 -> 347:2-17',
|
|
'2:18 -> 348:0',
|
|
'2:4 -> 350:0',
|
|
'2:18 -> 352:1',
|
|
'2:4 -> 353:0',
|
|
'2:4-18 -> 354:2-17',
|
|
'2:18 -> 355:0',
|
|
'2:4 -> 357:0',
|
|
'2:18 -> 361:1',
|
|
'2:4 -> 363:0',
|
|
'2:4-18 -> 371:2-24',
|
|
'2:4-18 -> 372:2-32',
|
|
'2:18 -> 373:0',
|
|
'2:4 -> 375:0',
|
|
'2:18 -> 377:1',
|
|
'2:4 -> 379:0',
|
|
'2:4-18 -> 381:2-17',
|
|
'2:4-18 -> 382:2-14',
|
|
'2:18 -> 383:0',
|
|
'2:4-18 -> 385:0-72',
|
|
'2:4 -> 386:0',
|
|
'2:4-18 -> 387:2-15',
|
|
'2:18 -> 388:0',
|
|
'2:4 -> 390:0',
|
|
'2:4-18 -> 391:2-26',
|
|
'2:4-18 -> 392:2-26',
|
|
'2:4-18 -> 393:2-21',
|
|
'2:4-18 -> 394:2-21',
|
|
'2:4-18 -> 395:2-16',
|
|
'2:4-18 -> 396:2-16',
|
|
'2:4-18 -> 397:2-16',
|
|
'2:4-18 -> 398:2-17',
|
|
'2:4-18 -> 399:2-17',
|
|
'2:4-18 -> 400:2-15',
|
|
'2:4-18 -> 401:2-15',
|
|
'2:4-18 -> 402:2-20',
|
|
'2:4-18 -> 403:2-40',
|
|
'2:4-18 -> 404:2-32',
|
|
'2:4-18 -> 405:2-31',
|
|
'2:4-18 -> 406:2-30',
|
|
'2:4-18 -> 407:2-17',
|
|
'2:4-18 -> 408:2-22',
|
|
'2:4-18 -> 409:2-24',
|
|
'2:4-18 -> 410:2-25',
|
|
'2:4-18 -> 411:2-26',
|
|
'2:4-18 -> 412:2-20',
|
|
'2:4-18 -> 413:2-29',
|
|
'2:4-18 -> 414:2-30',
|
|
'2:4-18 -> 415:2-40',
|
|
'2:4-18 -> 416:2-36',
|
|
'2:4-18 -> 417:2-29',
|
|
'2:4-18 -> 418:2-24',
|
|
'2:4-18 -> 419:2-32',
|
|
'2:4-18 -> 420:2-14',
|
|
'2:4-18 -> 421:2-20',
|
|
'2:4-18 -> 422:2-18',
|
|
'2:4-18 -> 423:2-19',
|
|
'2:4-18 -> 424:2-20',
|
|
'2:4-18 -> 425:2-16',
|
|
'2:4-18 -> 426:2-18',
|
|
'2:4-18 -> 427:2-15',
|
|
'2:4-18 -> 428:2-21',
|
|
'2:4-18 -> 429:2-23',
|
|
'2:4-18 -> 430:2-29',
|
|
'2:4-18 -> 431:2-27',
|
|
'2:4-18 -> 432:2-28',
|
|
'2:4-18 -> 433:2-29',
|
|
'2:4-18 -> 434:2-25',
|
|
'2:4-18 -> 435:2-26',
|
|
'2:4-18 -> 436:2-27',
|
|
'2:4-18 -> 437:2-24',
|
|
'2:4-18 -> 438:2-22',
|
|
'2:4-18 -> 439:2-24',
|
|
'2:4-18 -> 440:2-23',
|
|
'2:4 -> 441:2',
|
|
'2:18 -> 442:0',
|
|
'2:4 -> 444:0',
|
|
'2:4-18 -> 445:2-26',
|
|
'2:4-18 -> 446:2-26',
|
|
'2:4-18 -> 447:2-21',
|
|
'2:4-18 -> 448:2-21',
|
|
'2:4-18 -> 449:2-16',
|
|
'2:4-18 -> 450:2-16',
|
|
'2:4-18 -> 451:2-16',
|
|
'2:4-18 -> 452:2-17',
|
|
'2:4-18 -> 453:2-17',
|
|
'2:4-18 -> 454:2-15',
|
|
'2:4-18 -> 455:2-15',
|
|
'2:4-18 -> 456:2-20',
|
|
'2:4-18 -> 457:2-40',
|
|
'2:4-18 -> 458:2-32',
|
|
'2:4-18 -> 459:2-31',
|
|
'2:4-18 -> 460:2-30',
|
|
'2:4-18 -> 461:2-17',
|
|
'2:4-18 -> 462:2-22',
|
|
'2:4-18 -> 463:2-24',
|
|
'2:4-18 -> 464:2-25',
|
|
'2:4-18 -> 465:2-26',
|
|
'2:4-18 -> 466:2-20',
|
|
'2:4-18 -> 467:2-29',
|
|
'2:4-18 -> 468:2-30',
|
|
'2:4-18 -> 469:2-40',
|
|
'2:4-18 -> 470:2-36',
|
|
'2:4-18 -> 471:2-29',
|
|
'2:4-18 -> 472:2-24',
|
|
'2:4-18 -> 473:2-32',
|
|
'2:4-18 -> 474:2-14',
|
|
'2:4-18 -> 475:2-20',
|
|
'2:4-18 -> 476:2-18',
|
|
'2:4-18 -> 477:2-19',
|
|
'2:4-18 -> 478:2-20',
|
|
'2:4-18 -> 479:2-16',
|
|
'2:4-18 -> 480:2-18',
|
|
'2:4-18 -> 481:2-15',
|
|
'2:4-18 -> 482:2-21',
|
|
'2:4-18 -> 483:2-23',
|
|
'2:4-18 -> 484:2-29',
|
|
'2:4-18 -> 485:2-27',
|
|
'2:4-18 -> 486:2-28',
|
|
'2:4-18 -> 487:2-29',
|
|
'2:4-18 -> 488:2-25',
|
|
'2:4-18 -> 489:2-26',
|
|
'2:4-18 -> 490:2-27',
|
|
'2:4-18 -> 491:2-24',
|
|
'2:4-18 -> 492:2-22',
|
|
'2:4-18 -> 493:2-24',
|
|
'2:4-18 -> 494:2-23',
|
|
'2:4 -> 495:2',
|
|
'2:18 -> 496:0',
|
|
])
|
|
})
|
|
|
|
test('utilities have source maps', async () => {
|
|
let config = {
|
|
content: [{ raw: `text-red-500` }],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind utilities;
|
|
`
|
|
|
|
let result = await run(input, config)
|
|
let { sources, annotations } = parseSourceMaps(result)
|
|
|
|
// All CSS generated by Tailwind CSS should be annotated with source maps
|
|
// And always be able to point to the original source file
|
|
expect(sources).not.toContain('<no source>')
|
|
expect(sources.length).toBe(1)
|
|
|
|
expect(annotations).toStrictEqual(['2:4 -> 1:0', '2:4-23 -> 2:4-24', '2:4 -> 3:4', '2:23 -> 4:0'])
|
|
})
|
|
|
|
test('components have source maps', async () => {
|
|
let config = {
|
|
content: [{ raw: `container` }],
|
|
}
|
|
|
|
let input = css`
|
|
@tailwind components;
|
|
`
|
|
|
|
let result = await run(input, config)
|
|
let { sources, annotations } = parseSourceMaps(result)
|
|
|
|
// All CSS generated by Tailwind CSS should be annotated with source maps
|
|
// And always be able to point to the original source file
|
|
expect(sources).not.toContain('<no source>')
|
|
expect(sources.length).toBe(1)
|
|
|
|
expect(annotations).toEqual([
|
|
'2:4 -> 1:0',
|
|
'2:4 -> 2:4',
|
|
'2:24 -> 3:0',
|
|
'2:4 -> 4:0',
|
|
'2:4 -> 5:4',
|
|
'2:4 -> 6:8',
|
|
'2:24 -> 7:4',
|
|
'2:24 -> 8:0',
|
|
'2:4 -> 9:0',
|
|
'2:4 -> 10:4',
|
|
'2:4 -> 11:8',
|
|
'2:24 -> 12:4',
|
|
'2:24 -> 13:0',
|
|
'2:4 -> 14:0',
|
|
'2:4 -> 15:4',
|
|
'2:4 -> 16:8',
|
|
'2:24 -> 17:4',
|
|
'2:24 -> 18:0',
|
|
'2:4 -> 19:0',
|
|
'2:4 -> 20:4',
|
|
'2:4 -> 21:8',
|
|
'2:24 -> 22:4',
|
|
'2:24 -> 23:0',
|
|
'2:4 -> 24:0',
|
|
'2:4 -> 25:4',
|
|
'2:4 -> 26:8',
|
|
'2:24 -> 27:4',
|
|
'2:24 -> 28:0',
|
|
])
|
|
})
|
|
|
|
test('source maps for layer rules are not rewritten to point to @tailwind directives', async () => {
|
|
let config = {
|
|
content: [{ raw: `font-normal foo hover:foo lg:foo` }],
|
|
}
|
|
|
|
let utilitiesFile = postcss.parse(
|
|
css`
|
|
@tailwind utilities;
|
|
`,
|
|
{ from: 'components.css', map: { prev: map } }
|
|
)
|
|
|
|
let mainCssFile = postcss.parse(
|
|
css`
|
|
@layer utilities {
|
|
.foo {
|
|
background-color: red;
|
|
}
|
|
}
|
|
`,
|
|
{ from: 'input.css', map: { prev: map } }
|
|
)
|
|
|
|
// Just pretend that there's an @import in `mainCssFile` that imports the nodes from `utilitiesFile`
|
|
let input = postcss.root({
|
|
nodes: [...utilitiesFile.nodes, ...mainCssFile.nodes],
|
|
source: mainCssFile.source,
|
|
})
|
|
|
|
let result = await run(input, config)
|
|
|
|
let { sources, annotations } = parseSourceMaps(result)
|
|
|
|
// All CSS generated by Tailwind CSS should be annotated with source maps
|
|
// And always be able to point to the original source file
|
|
expect(sources).not.toContain('<no source>')
|
|
|
|
// And we should see that the source map for the layer rule is not rewritten
|
|
// to point to the @tailwind directive but instead points to the original
|
|
expect(sources.length).toBe(2)
|
|
expect(sources).toEqual(['components.css', 'input.css'])
|
|
|
|
expect(annotations).toEqual([
|
|
'2:6 -> 1:0',
|
|
'2:6 -> 2:10',
|
|
'2:25 -> 3:0',
|
|
'3:8 -> 4:8',
|
|
'4:10-31 -> 5:10-31',
|
|
'5:8 -> 6:8',
|
|
'3:8 -> 7:8',
|
|
'4:10-31 -> 8:10-31',
|
|
'5:8 -> 9:8',
|
|
'1:0 -> 10:8',
|
|
'3:8 -> 11:8',
|
|
'4:10-31 -> 12:10-31',
|
|
'5:8 -> 13:8',
|
|
'7:4 -> 14:0',
|
|
])
|
|
})
|