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
@@ -57,16 +53,18 @@ export function analyze(css: string, options: Options = {}) {
5753 let useLocations = settings . useLocations === true
5854 let start = Date . now ( )
5955
56+ type StringifiableNode = { loc ?: null | { start : { offset : number } ; end : { offset : number } } }
57+
6058 /**
6159 * Recreate the authored CSS from a CSSTree node
62- * @param { import('css-tree').CssNode } node - Node from CSSTree AST to stringify
63- * @returns { string } str - The stringified node
60+ * @param node - Node from CSSTree AST to stringify
61+ * @returns The stringified node
6462 */
65- function stringifyNode ( node : CssNode ) {
63+ function stringifyNode ( node : StringifiableNode ) {
6664 return stringifyNodePlain ( node ) . trim ( )
6765 }
6866
69- function stringifyNodePlain ( node : CssNode ) {
67+ function stringifyNodePlain ( node : StringifiableNode ) {
7068 let loc = node . loc !
7169 return css . substring ( loc . start . offset , loc . end . offset )
7270 }
@@ -93,7 +91,7 @@ export function analyze(css: string, options: Options = {}) {
9391 } )
9492
9593 let startAnalysis = Date . now ( )
96- let linesOfCode = ast . loc . end . line - ast . loc . start . line + 1
94+ let linesOfCode = ast . loc ! . end . line - ast . loc ! . start . line + 1
9795
9896 // Atrules
9997 let atrules = new Collection ( useLocations )
@@ -247,7 +245,6 @@ export function analyze(css: string, options: Options = {}) {
247245 }
248246 keyframes . p ( name , loc ! )
249247 } else if ( atRuleName === 'import' ) {
250- // @ts -expect-error Outdated css-tree types
251248 walk ( node , ( prelude_node ) => {
252249 if ( prelude_node . type === 'Condition' && prelude_node . kind === 'supports' ) {
253250 let prelude = stringifyNode ( prelude_node )
@@ -284,19 +281,14 @@ export function analyze(css: string, options: Options = {}) {
284281 atRuleComplexities . push ( complexity )
285282 break
286283 }
287- // @ts -expect-error Oudated css-tree types
288284 case 'Layer' : {
289- // @ts -expect-error Oudated css-tree types
290285 if ( node . name !== null ) {
291- // @ts -expect-error Oudated css-tree types
292- layers . p ( node . name , node . loc )
286+ layers . p ( node . name , node . loc ! )
293287 }
294288 break
295289 }
296- // @ts -expect-error Oudated css-tree types
297290 case 'Feature' : {
298- // @ts -expect-error Oudated css-tree types
299- mediaFeatures . p ( node . name , node . loc )
291+ mediaFeatures . p ( node . name , node . loc ! )
300292 break
301293 }
302294 case Rule : {
@@ -457,7 +449,7 @@ export function analyze(css: string, options: Options = {}) {
457449 break
458450 }
459451
460- let declaration : Declaration = this . declaration
452+ let declaration = this . declaration !
461453 let { property, important } = declaration
462454 let complexity = 1
463455
0 commit comments