From e80562b716652cf64586fb9c906722cfd02a2376 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 22 Jun 2024 14:56:20 +0200 Subject: [PATCH 1/2] improve typings of constructor helpers --- postcss-selector-parser.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/postcss-selector-parser.d.ts b/postcss-selector-parser.d.ts index 9163ab1..a7fe54b 100644 --- a/postcss-selector-parser.d.ts +++ b/postcss-selector-parser.d.ts @@ -532,13 +532,13 @@ declare namespace parser { interface Identifier extends Base { type: "id"; } - function id(opts: any): any; + function id(opts: any): Identifier; function isIdentifier(node: any): node is Identifier; interface Nesting extends Base { type: "nesting"; } - function nesting(opts: any): any; + function nesting(opts: any): Nesting; function isNesting(node: any): node is Nesting; interface String extends Base { @@ -550,6 +550,6 @@ declare namespace parser { interface Universal extends Base { type: "universal"; } - function universal(opts?: NamespaceOptions): any; + function universal(opts?: NamespaceOptions): Universal; function isUniversal(node: any): node is Universal; } From 43f84328a95e491a01ebbef2930b84afc2a4ee51 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sun, 23 Jun 2024 12:20:04 +0200 Subject: [PATCH 2/2] add constructor tests and allow no args for nesting constructor --- postcss-selector-parser.d.ts | 2 +- src/__tests__/constructors.mjs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/constructors.mjs diff --git a/postcss-selector-parser.d.ts b/postcss-selector-parser.d.ts index a7fe54b..af609e6 100644 --- a/postcss-selector-parser.d.ts +++ b/postcss-selector-parser.d.ts @@ -538,7 +538,7 @@ declare namespace parser { interface Nesting extends Base { type: "nesting"; } - function nesting(opts: any): Nesting; + function nesting(opts?: any): Nesting; function isNesting(node: any): node is Nesting; interface String extends Base { diff --git a/src/__tests__/constructors.mjs b/src/__tests__/constructors.mjs new file mode 100644 index 0000000..6008638 --- /dev/null +++ b/src/__tests__/constructors.mjs @@ -0,0 +1,7 @@ +import test from 'ava'; +import parser from '../index.js'; + +test('constructors#nesting', (t) => { + t.deepEqual(parser.nesting().toString(), '&'); + t.deepEqual(parser.nesting({}).toString(), '&'); +});