Improve types for csso (#30607)

This commit is contained in:
Erik Källén
2018-11-18 19:45:04 +01:00
committed by Pranav Senthilnathan
parent 09298b425d
commit ec44d45205
2 changed files with 41 additions and 8 deletions

View File

@@ -15,7 +15,7 @@ csso.minify('.test { color: #ff0000; }', {
logger: () => {}
});
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000').css;
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000').css; // $ExpectType string
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000').map;
csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000', {
sourceMap: true,
@@ -27,14 +27,30 @@ csso.minifyBlock('color: rgba(255, 0, 0, 1); color: #ff0000', {
forceMediaMerge: true,
clone: false,
comments: '',
logger: () => {}
logger: () => {},
usage: {
tags: ['ul', 'li'],
ids: ['x'],
classes: ['a', 'b'],
blacklist: {
tags: ['body'],
ids: ['y'],
classes: ['c'],
},
scopes: [
['a', 'b', 'c'],
['d', 'e']
],
},
});
csso.compress({}).ast;
csso.compress({}, {
csso.compress({ type: 'CDC' }).ast; // $ExpectType CssNode
csso.compress({ type: 'CDC' }, {
restructure: false,
forceMediaMerge: true,
clone: false,
comments: '',
logger: () => {}
}).ast;
}).ast; // $ExpectType CssNode
csso.syntax.parse('.b {font-weight: bold}'); // $ExpectType CssNode

23
types/csso/index.d.ts vendored
View File

@@ -1,8 +1,11 @@
// Type definitions for csso 3.5
// Project: https://github.com/css/csso
// Definitions by: Christian Rackerseder <https://github.com/screendriver>
// Erik Källén <https://github.com/erik-kallen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
// TypeScript Version: 2.7
import * as csstree from 'css-tree';
declare namespace csso {
interface Result {
@@ -16,6 +19,18 @@ declare namespace csso {
map: object | null;
}
interface Usage {
tags?: string[];
ids?: string[];
classes?: string[];
scopes?: string[][];
blacklist?: {
tags?: string[];
ids?: string[];
classes?: string[];
};
}
interface CompressOptions {
/**
* Disable or enable a structure optimisations.
@@ -44,7 +59,7 @@ declare namespace csso {
/**
* Usage data for advanced optimisations.
*/
usage?: object;
usage?: Usage;
/**
* Function to track every step of transformation.
*/
@@ -100,7 +115,9 @@ interface Csso {
/**
* Does the main task compress an AST.
*/
compress(ast: object, options?: csso.CompressOptions): { ast: object };
compress(ast: csstree.CssNode, options?: csso.CompressOptions): { ast: csstree.CssNode };
syntax: typeof csstree;
}
declare const csso: Csso;