From d5b5176756eda0ddda7a3682fe70ebc0d552f3ee Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Fri, 12 Jun 2020 11:26:17 +0100 Subject: [PATCH] make pseudo class name meta always an array --- src/class-names/extractClassNames.js | 10 +++------- src/lsp/providers/completionProvider.ts | 4 ++-- src/lsp/util/stringify.ts | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/class-names/extractClassNames.js b/src/class-names/extractClassNames.js index 2aa426b..4c2cb38 100644 --- a/src/class-names/extractClassNames.js +++ b/src/class-names/extractClassNames.js @@ -36,7 +36,7 @@ function getClassNamesFromSelector(selector) { className: node.value.trim(), scope: createSelectorFromNodes(scope), __rule: j === subSelectors[i].nodes.length - 1, - __pseudo: pseudo.length === 0 ? null : pseudo.map(String), + __pseudo: pseudo.map(String), }) } scope.push(node, ...pseudo) @@ -115,9 +115,7 @@ async function process(groups) { dsetEach(tree, [...baseKeys, ...index], decls) } - if (classNames[i].__pseudo) { - dset(tree, [...baseKeys, '__pseudo'], classNames[i].__pseudo) - } + dset(tree, [...baseKeys, ...index, '__pseudo'], classNames[i].__pseudo) dset(tree, [...baseKeys, ...index, '__scope'], classNames[i].scope) dset( tree, @@ -126,9 +124,7 @@ async function process(groups) { ) // common context - if (classNames[i].__pseudo) { - context.push(...classNames[i].__pseudo) - } + context.push(...classNames[i].__pseudo) for (let i = 0; i < contextKeys.length; i++) { if (typeof commonContext[contextKeys[i]] === 'undefined') { diff --git a/src/lsp/providers/completionProvider.ts b/src/lsp/providers/completionProvider.ts index eae7546..8f47ca6 100644 --- a/src/lsp/providers/completionProvider.ts +++ b/src/lsp/providers/completionProvider.ts @@ -200,8 +200,8 @@ function provideAtApplyCompletions( return ( !Array.isArray(info) && info.__source === 'utilities' && - (info.__context || []).length === 0 && - (info.__pseudo || []).length === 0 + info.__context.length === 0 && + info.__pseudo.length === 0 ) } ) diff --git a/src/lsp/util/stringify.ts b/src/lsp/util/stringify.ts index 976f8b9..6490c34 100644 --- a/src/lsp/util/stringify.ts +++ b/src/lsp/util/stringify.ts @@ -54,7 +54,7 @@ export function stringifyCss(className: string, obj: any): string { } function augmentClassName(className: string, obj: any): string { - const pseudo = obj.__pseudo ? obj.__pseudo.join('') : '' + const pseudo = obj.__pseudo.join('') const scope = obj.__scope ? `${obj.__scope} ` : '' return `${scope}.${escapeClassName(className)}${pseudo}` }