Search


Search something to see results

ParserSyncOptions

Sync parseroptions

interface ParserSyncOptions {
    arena?: AstArena;
    computeCalcExpression?: boolean;
    computeShorthand?: boolean;
    computeTransform?: boolean;
    cwd?: string;
    evaluateMixins?: boolean;
    expandIfSyntax?: boolean;
    expandNestingRules?: boolean;
    inlineCssVariables?: boolean;
    inputSourceMap?: string | SourceMapObject;
    keepMixins?: boolean;
    lenient?: boolean;
    minify?: boolean;
    minifyAST?: boolean;
    module?:
        | boolean
        | ModuleSyncOptions
        | ModuleCaseTransformEnum
        | ModuleScopeEnumOptions;
    nestingRules?: boolean;
    parseColor?: boolean;
    pass?: number;
    removeCharset?: boolean;
    removeDuplicateDeclarations?: string
    | boolean
    | string[];
    removeEmpty?: boolean;
    removePrefix?: boolean;
    resolve?: (
        url: string,
        currentUrl: string,
        currentWorkingDirectory?: string,
    ) => { absolute: string; relative: string };
    resolveUrls?: boolean;
    signal?: AbortSignal;
    source?: SourceFile | null;
    sourcemap?: boolean | "inline";
    sourcesMap?: Map<number, SourceFile>;
    src?: string;
    validation?: boolean;
    visitor?: any;
}

Hierarchy (View Summary)

Index

Properties

arena?: AstArena

Arena the ast nodes are allocated in. Created by the parser when omitted. Nested parses (@import) allocate their nodes in the parent arena.

computeCalcExpression?: boolean

Compute css math functions

computeShorthand?: boolean

Compute shorthand properties

computeTransform?: boolean

Compute css transform functions

cwd?: string

Current working directory

evaluateMixins?: boolean

Evaluate css mixins and custom functions: the @apply rules are replaced by the body of the mixin they reference, the private variables (@private, mixin arguments and the custom properties of the rule) are substituted. the custom function calls (--fn(1px)) are replaced by the result of the function. see https://drafts.csswg.org/css-mixins-1/


import {transform} from '@tbela99/css-parser';

const css = `
@mixin --only-descs(--arg) {
color: var(--arg);
& * { color: var(--arg, red); }
}
.foo {
@apply --only-descs(green);
}
`;

const result = await transform(css, {evaluateMixins: true, expandNestingRules: true});

console.log(result.code);
// .foo,.foo *{color:green}
expandIfSyntax?: boolean

Experimental, convert css if() function into legacy syntax.

expandNestingRules?: boolean

Expand nested rules

inlineCssVariables?: boolean

Inline css variables

inputSourceMap?: string | SourceMapObject

Input source map

keepMixins?: boolean

Keep the mixins and the custom functions once they are evaluated, see evaluateMixins. By default, the evaluated mixins and custom functions, and the mixins that are not referenced, are dropped and replaced with a comment

lenient?: boolean

Lenient validation. retain nodes that failed validation

minify?: boolean

Enable minification

minifyAST?: boolean

enable ast minification

module?:
    | boolean
    | ModuleSyncOptions
    | ModuleCaseTransformEnum
    | ModuleScopeEnumOptions

CSS modules options

nestingRules?: boolean

Generate nested rules

parseColor?: boolean

Parse color tokens

pass?: number

Define minification passes.

removeCharset?: boolean

Remove at-rule charset

removeDuplicateDeclarations?: string | boolean | string[]

Remove duplicate declarations from the same rule. if passed as a string array, duplicated declarations are removed, except for those in the array


import {transform} from '@tbela99/css-parser';

const css = `

.table {

width: 100%;
width: calc(100% + 40px);
margin-left: 20px;
margin-left: min(100% , 20px)
}

`;
const result = await transform(css, {

beautify: true,
validation: true,
removeDuplicateDeclarations: ['width']
}
);

console.log(result.code);
removeEmpty?: boolean

Remove empty ast nodes

removePrefix?: boolean

Remove css prefix

resolve?: (
    url: string,
    currentUrl: string,
    currentWorkingDirectory?: string,
) => { absolute: string; relative: string }

Url and path resolver

resolveUrls?: boolean

Resolve urls

signal?: AbortSignal

Abort signal

Example: abort after 10 seconds


const result = await parse(cssString, {
signal: AbortSignal.timeout(10000)
});
source?: SourceFile | null

Source file to be used for sourcemap

sourcemap?: boolean | "inline"

Include sourcemap in the ast. Sourcemap info is always generated

sourcesMap?: Map<number, SourceFile>

Source file to be used for sourcemap

src?: string

Source file to be used for sourcemap

validation?: boolean

Enable CSS validation

visitor?: any

Node visitor VisitorSyncNodeMap[]