mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[postcss-less] add definitions (#46235)
* [postcss-less] add definitions https://github.com/shellscape/postcss-less * Remove needless `FunctionAtRule.params` * Bump postcss to the latest * Add `nodeToString()` type and more test cases
This commit is contained in:
parent
b2ac55feed
commit
60909bad58
55
types/postcss-less/index.d.ts
vendored
Normal file
55
types/postcss-less/index.d.ts
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// Type definitions for postcss-less 3.1
|
||||
// Project: https://github.com/shellscape/postcss-less
|
||||
// Definitions by: Masafumi Koba <https://github.com/ybiquitous>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as postcss from 'postcss';
|
||||
|
||||
export = postcssLess;
|
||||
|
||||
declare const postcssLess: postcss.Syntax & {
|
||||
parse: postcss.Parser;
|
||||
stringify: postcss.Stringifier;
|
||||
nodeToString: (node: postcss.Node) => string;
|
||||
};
|
||||
|
||||
declare namespace postcssLess {
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/nodes/import.js
|
||||
interface ImportAtRule extends postcss.AtRule {
|
||||
import: true;
|
||||
filename: string;
|
||||
options?: string;
|
||||
}
|
||||
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/nodes/variable.js
|
||||
interface VariableAtRule extends postcss.AtRule {
|
||||
variable: true;
|
||||
}
|
||||
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/LessParser.js#L147-L151
|
||||
interface MixinAtRule extends postcss.AtRule {
|
||||
mixin: true;
|
||||
important?: true;
|
||||
}
|
||||
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/LessParser.js#L57
|
||||
interface FunctionAtRule extends postcss.AtRule {
|
||||
function: true;
|
||||
}
|
||||
|
||||
type AtRule = ImportAtRule | VariableAtRule | MixinAtRule | FunctionAtRule;
|
||||
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/LessParser.js#L187
|
||||
interface ExtendRule extends postcss.Rule {
|
||||
extend: true;
|
||||
}
|
||||
|
||||
type Rule = ExtendRule;
|
||||
|
||||
// @see https://github.com/shellscape/postcss-less/blob/v3.1.4/lib/LessParser.js#L73
|
||||
interface InlineComment extends postcss.Comment {
|
||||
inline: true;
|
||||
}
|
||||
|
||||
type Comment = InlineComment;
|
||||
}
|
||||
6
types/postcss-less/package.json
Normal file
6
types/postcss-less/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"postcss": "^7.0.32"
|
||||
}
|
||||
}
|
||||
71
types/postcss-less/postcss-less-tests.ts
Normal file
71
types/postcss-less/postcss-less-tests.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import postcss = require('postcss');
|
||||
import less = require('postcss-less');
|
||||
|
||||
const lessCode = 'a { @link-color: blue; }';
|
||||
|
||||
postcss().process(lessCode, { syntax: less });
|
||||
|
||||
less.parse(lessCode).walkAtRules(atRule => {
|
||||
const lessAtRule = atRule as less.AtRule;
|
||||
|
||||
if ('import' in lessAtRule) {
|
||||
assert(lessAtRule.import === true);
|
||||
assert(typeof lessAtRule.filename === 'string');
|
||||
|
||||
const { options } = lessAtRule;
|
||||
if (options) {
|
||||
assert(typeof options === 'string');
|
||||
} else {
|
||||
assert(options === undefined);
|
||||
}
|
||||
}
|
||||
|
||||
if ('variable' in lessAtRule) {
|
||||
assert(lessAtRule.variable === true);
|
||||
}
|
||||
|
||||
if ('mixin' in lessAtRule) {
|
||||
assert(lessAtRule.mixin === true);
|
||||
|
||||
const { important } = lessAtRule;
|
||||
if (important) {
|
||||
assert(important === true);
|
||||
} else {
|
||||
assert(important === undefined);
|
||||
}
|
||||
}
|
||||
|
||||
if ('function' in lessAtRule) {
|
||||
assert(lessAtRule.function === true);
|
||||
}
|
||||
});
|
||||
|
||||
less.parse(lessCode).walkRules(rule => {
|
||||
const lessRule = rule as less.Rule;
|
||||
assert(lessRule.extend === true);
|
||||
});
|
||||
|
||||
less.parse(lessCode).walkComments(comment => {
|
||||
const lessComment = comment as less.Comment;
|
||||
assert(lessComment.inline === true);
|
||||
});
|
||||
|
||||
less.stringify(less.parse(lessCode), (part, node, type) => {
|
||||
assert(typeof part === 'string');
|
||||
assert(type === 'start');
|
||||
assert(type === 'end');
|
||||
|
||||
if (node) {
|
||||
assert(typeof node.root === 'function');
|
||||
} else {
|
||||
assert(node === undefined);
|
||||
}
|
||||
});
|
||||
|
||||
assert(typeof less.nodeToString(less.parse(lessCode)) === 'string');
|
||||
|
||||
function assert(condition: any) /* : asserts condition */ {
|
||||
if (!condition) {
|
||||
throw new Error('Assertion failed');
|
||||
}
|
||||
}
|
||||
23
types/postcss-less/tsconfig.json
Normal file
23
types/postcss-less/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"postcss-less-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/postcss-less/tslint.json
Normal file
1
types/postcss-less/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user