1- // @ts -expect-error types missing
2- import parse from 'css-tree/parser'
3- // @ts -expect-error types missing
4- import walk from 'css-tree/walker'
1+ import { walk , parse , type CssNode , type SelectorList } from '@eslint/css-tree'
52// @ts -expect-error types missing
63import { calculateForAST } from '@bramus/specificity/core'
74import { isSupportsBrowserhack , isMediaBrowserhack } from './atrules/atrules.js'
@@ -22,7 +19,6 @@ import { isIe9Hack } from './values/browserhacks.js'
2219import { basename } from './properties/property-utils.js'
2320import { Atrule , Selector , Dimension , Url , Value , Hash , Rule , Identifier , Func , Operator } from './css-tree-node-types.js'
2421import { KeywordSet } from './keyword-set.js'
25- import type { CssNode , Declaration , SelectorList } from 'css-tree'
2622
2723type Specificity = [ number , number , number ]
2824
@@ -61,16 +57,18 @@ export function analyze(css: string, options: Options = {}): any {
6157function analyzeInternal < T extends boolean > ( css : string , options : Options , useLocations : T ) {
6258 let start = Date . now ( )
6359
60+ type StringifiableNode = { loc ?: null | { start : { offset : number } ; end : { offset : number } } }
61+
6462 /**
6563 * Recreate the authored CSS from a CSSTree node
66- * @param { import('css-tree').CssNode } node - Node from CSSTree AST to stringify
67- * @returns { string } str - The stringified node
64+ * @param node - Node from CSSTree AST to stringify
65+ * @returns The stringified node
6866 */
69- function stringifyNode ( node : CssNode ) {
67+ function stringifyNode ( node : StringifiableNode ) {
7068 return stringifyNodePlain ( node ) . trim ( )
7169 }
7270
73- function stringifyNodePlain ( node : CssNode ) {
71+ function stringifyNodePlain ( node : StringifiableNode ) {
7472 let loc = node . loc !
7573 return css . substring ( loc . start . offset , loc . end . offset )
7674 }
@@ -103,7 +101,7 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
103101 } )
104102
105103 let startAnalysis = Date . now ( )
106- let linesOfCode = ast . loc . end . line - ast . loc . start . line + 1
104+ let linesOfCode = ast . loc ! . end . line - ast . loc ! . start . line + 1
107105
108106 // Atrules
109107 let atrules = new Collection ( useLocations )
@@ -257,7 +255,6 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
257255 }
258256 keyframes . p ( name , loc ! )
259257 } else if ( atRuleName === 'import' ) {
260- // @ts -expect-error Outdated css-tree types
261258 walk ( node , ( prelude_node ) => {
262259 if ( prelude_node . type === 'Condition' && prelude_node . kind === 'supports' ) {
263260 let prelude = stringifyNode ( prelude_node )
@@ -294,19 +291,14 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
294291 atRuleComplexities . push ( complexity )
295292 break
296293 }
297- // @ts -expect-error Oudated css-tree types
298294 case 'Layer' : {
299- // @ts -expect-error Oudated css-tree types
300295 if ( node . name !== null ) {
301- // @ts -expect-error Oudated css-tree types
302- layers . p ( node . name , node . loc )
296+ layers . p ( node . name , node . loc ! )
303297 }
304298 break
305299 }
306- // @ts -expect-error Oudated css-tree types
307300 case 'Feature' : {
308- // @ts -expect-error Oudated css-tree types
309- mediaFeatures . p ( node . name , node . loc )
301+ mediaFeatures . p ( node . name , node . loc ! )
310302 break
311303 }
312304 case Rule : {
@@ -467,7 +459,7 @@ function analyzeInternal<T extends boolean>(css: string, options: Options, useLo
467459 break
468460 }
469461
470- let declaration : Declaration = this . declaration
462+ let declaration = this . declaration !
471463 let { property, important } = declaration
472464 let complexity = 1
473465
0 commit comments