diff --git a/packages/tailwindcss/src/ast.ts b/packages/tailwindcss/src/ast.ts index 4c5cd40da..5f3032b54 100644 --- a/packages/tailwindcss/src/ast.ts +++ b/packages/tailwindcss/src/ast.ts @@ -1,6 +1,7 @@ import { Polyfills } from '.' import { parseAtRule } from './css-parser' import type { DesignSystem } from './design-system' +import type { Source, SourceLocation } from './source-maps/source' import { Theme, ThemeOptions } from './theme' import { DefaultMap } from './utils/default-map' import { extractUsedVariables } from './utils/variables' @@ -12,6 +13,9 @@ export type StyleRule = { kind: 'rule' selector: string nodes: AstNode[] + + src?: SourceLocation + dst?: SourceLocation } export type AtRule = { @@ -19,6 +23,9 @@ export type AtRule = { name: string params: string nodes: AstNode[] + + src?: SourceLocation + dst?: SourceLocation } export type Declaration = { @@ -26,22 +33,34 @@ export type Declaration = { property: string value: string | undefined important: boolean + + src?: SourceLocation + dst?: SourceLocation } export type Comment = { kind: 'comment' value: string + + src?: SourceLocation + dst?: SourceLocation } export type Context = { kind: 'context' context: Record nodes: AstNode[] + + src?: undefined + dst?: undefined } export type AtRoot = { kind: 'at-root' nodes: AstNode[] + + src?: undefined + dst?: undefined } export type Rule = StyleRule | AtRule diff --git a/packages/tailwindcss/src/source-maps/source.ts b/packages/tailwindcss/src/source-maps/source.ts new file mode 100644 index 000000000..c3a4f8988 --- /dev/null +++ b/packages/tailwindcss/src/source-maps/source.ts @@ -0,0 +1,27 @@ +/** + * The source code for one or more nodes in the AST + * + * This generally corresponds to a stylesheet + */ +export interface Source { + /** + * The path to the file that contains the referenced source code + * + * If this references the *output* source code, this is `null`. + */ + file: string | null + + /** + * The referenced source code + */ + code: string +} + +/** + * The file and offsets within it that this node covers + * + * This can represent either: + * - A location in the original CSS which caused this node to be created + * - A location in the output CSS where this node resides + */ +export type SourceLocation = [source: Source, start: number, end: number]