From ec44d45205f3a844bfbb74e00c256b3bbd64c4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20K=C3=A4ll=C3=A9n?= Date: Sun, 18 Nov 2018 19:45:04 +0100 Subject: [PATCH] Improve types for csso (#30607) --- types/csso/csso-tests.ts | 26 +++++++++++++++++++++----- types/csso/index.d.ts | 23 ++++++++++++++++++++--- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/types/csso/csso-tests.ts b/types/csso/csso-tests.ts index 74e0b51dd9..fdcb102d61 100644 --- a/types/csso/csso-tests.ts +++ b/types/csso/csso-tests.ts @@ -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 diff --git a/types/csso/index.d.ts b/types/csso/index.d.ts index f89f395129..b12ce67b8d 100644 --- a/types/csso/index.d.ts +++ b/types/csso/index.d.ts @@ -1,8 +1,11 @@ // Type definitions for csso 3.5 // Project: https://github.com/css/csso // Definitions by: Christian Rackerseder +// Erik Källén // 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;