From 03dadc776cb462c8670c2b8a9c7c2a11039ef23f Mon Sep 17 00:00:00 2001 From: Richard Lea Date: Wed, 17 Oct 2018 00:56:12 +0900 Subject: [PATCH] fix(less): type definitions on options and rootFileInfo (#29631) * fix(less): type definitions on options and rootFileInfo Signed-off-by: Richard Lea * fix(less): addition to tests including newly defined options Signed-off-by: Richard Lea * fix(less): support number for math option Signed-off-by: Richard Lea --- types/less/index.d.ts | 60 ++++++++++++++++++++++++++++++++++++++-- types/less/less-tests.ts | 41 ++++++++++++++++++++++++++- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/types/less/index.d.ts b/types/less/index.d.ts index 7d69273a52..5068a49e16 100644 --- a/types/less/index.d.ts +++ b/types/less/index.d.ts @@ -1,18 +1,29 @@ -// Type definitions for LESS +// Type definitions for LESS 3.x // Project: http://lesscss.org/ // Definitions by: Tom Hasner // Pranay Prakash // Daniel Waxweiler +// Richard Lea // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace Less { + // https://github.com/less/less.js/blob/master/lib/less/import-manager.js#L10 interface RootFileInfo { + /** whether to adjust URL's to be relative */ + rewriteUrls?: boolean; + /** full resolved filename of current file */ filename: string; relativeUrls: boolean; + /** path to append to normal URLs for this node */ rootpath: string; + /** path to the current file, absolute */ currentDirectory: string; + /** absolute path to the entry file */ entryPath: string; + /** filename of the base file */ rootFilename: string; + /** whether the file should not be output and only output parts that are referenced */ + reference: boolean; } class PluginManager { @@ -59,11 +70,54 @@ declare namespace Less { contents: { [fileName: string]: string }; } + /** + * Reference to: + * * https://github.com/less/less.js/blob/master/bin/lessc + * * http://lesscss.org/usage/#less-options + * + * @interface Options + */ interface Options { sourceMap?: SourceMapOption; + /** Filename of the main file to be passed to less.render() */ filename?: string; + /** The locations for less looking for files in @import rules */ + paths?: string[]; + /** True, if run the less parser and just reports errors without any output. */ + lint?: boolean; + /** Pre-load global Less.js plugins */ plugins?: Plugin[]; - rootFileInfo?: RootFileInfo; + /** @deprecated If true, compress using less built-in compression. */ + compress?: boolean; + strictImports?: boolean; + /** If true, allow imports from insecure https hosts. */ + insecure?: boolean; + depends?: boolean; + maxLineLen?: number; + /** @deprecated If false, No color in compiling. */ + color?: boolean; + /** @deprecated False by default. */ + ieCompat?: boolean; + /** @deprecated If true, enable evaluation of JavaScript inline in `.less` files. */ + javascriptEnabled?: boolean; + /** Whether output file information and line numbers in compiled CSS code. */ + dumpLineNumbers?: "comment" | string; + /** Add a path to every generated import and url in output css files. */ + rootpath?: string; + /** Math mode options for avoiding symbol conficts on math expressions. */ + math?: 'always' | 'strict' | 'parens-division' | 'parens' | 'strict-legacy' | number; + /** If true, stops any warnings from being shown. */ + silent?: boolean; + /** Without this option, Less attempts to guess at the output unit when it does maths. */ + strictUnits?: boolean; + /** Defines a variable that can be referenced by the file. */ + globalVars?: { + [key: string] : string, + }; + /** Puts Var declaration at the end of base file. */ + modifyVars?: { + [key: string] : string, + }; } interface RenderError { @@ -109,7 +163,7 @@ interface LessStatic { refresh(reload?: boolean, modifyVars?: { [variable: string]: string }, clearFileCache?: boolean): Promise; version: number[]; - + watch(): void; } diff --git a/types/less/less-tests.ts b/types/less/less-tests.ts index 20a1f587a9..625db93e44 100644 --- a/types/less/less-tests.ts +++ b/types/less/less-tests.ts @@ -30,8 +30,47 @@ var myPlugin: Less.Plugin = { } }; +/** Reference to: + * https://github.com/less/less.js/blob/master/lib/less/default-options.js + */ var options: Less.Options = { - plugins: [myPlugin] + plugins: [myPlugin], + /** Tells less to generate a sourcemap. */ + sourceMap: {}, + /* Inline Javascript - @plugin still allowed */ + javascriptEnabled: false, + /* Outputs a makefile import dependency list to stdout. */ + depends: false, + /** (DEPRECATED) This does not utilise all the tricks of css compression. */ + compress: false, + /* Runs the less parser and just reports errors without any output. */ + lint: false, + /** Less will look for the file in @import rules through locations here. */ + paths: [], + /* color output in the terminal */ + color: true, + /** See: https://github.com/less/less.js/issues/656 */ + strictImports: false, + /* Allow Imports from Insecure HTTPS Hosts */ + insecure: true, + /** Add a path to every generated import and url in your css */ + rootpath: '', + /** + * How to process math + * 0 always - eagerly try to solve all operations + * 1 parens-division - require parens for division "/" + * 2 parens | strict - require parens for all operations + * 3 strict-legacy - legacy strict behavior (super-strict) + * https://github.com/less/less.js/blob/master/lib/less/constants.js#L2 + * https://github.com/less/less.js/blob/master/lib/less/utils.js#L54 + */ + math: 0, + /* Guess at the output unit when it does maths. */ + strictUnits: false, + /** Put declaration at the top of base less file. */ + globalVars: null, + /** Put the declaration at the end of base file. */ + modifyVars: null }; less.render("h1 { background: red; }", options);