dependents / dependents/node-detective-scss

At-rule preludes: every bare identifier is reported as a dependency (@keyframes, @media, @forward ... show)

Open
#38 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Filing this as a generalisation of #14, which reports the `@use "x" as ns` case. The root cause looks identical, but the effect is broader than the `as` keyword: **any bare identifier appearing in an at-rule prelude is returned as a dependency**, including at-rules that can never carry an import.

## Reproduction

`detective-scss@5.0.2`, Node v24.13.0:

```js
const detective = require('detective-scss');

console.log(detective('@keyframes fade { from { opacity: 0 } }'));
// -> [ 'fade' ] expected: []

console.log(detective('@media screen and (min-width: 40px) { .a { color: red } }'));
// -> [ 'screen', 'and' ] expected: []

console.log(detective('@use "a" as c;'));
// -> [ 'a', 'as', 'c' ] expected: [ 'a' ] (this is #14)

console.log(detective('@use "a" as *;'));
// -> [ 'a', 'as' ] expected: [ 'a' ]

console.log(detective('@forward "a" show $b;'));
// -> [ 'a', 'show' ] expected: [ 'a' ]
```

Not affected, for contrast - their preludes carry no bare identifier at the top level:

```js
detective('@supports (display: grid) { .a { display: grid } }') // -> []
detective('@font-face { font-family: Foo; src: url(a.woff2) }') // -> []
detective('@use "a";') // -> [ 'a' ] correct
detective('@import "a";') // -> [ 'a' ] correct
```

## Why it matters downstream

`detective-scss` is reached through `precinct` -> `madge`. On a mid-sized Vue codebase (1014 files), `madge --circular` reports these phantom specifiers as unresolved dependencies on every run. They are not actionable: the only ways to silence them would be to stop using `@use ... as *` or to rename `@keyframes`, i.e. to degrade working stylesheets to satisfy the parser.

`@keyframes` is the most likely to bite, since animation names are arbitrary and plentiful. `@media` only shows up when the query uses the `screen and (...)` form rather than a bare parenthesised condition - which is probably why this has gone unnoticed.

## Suggested direction

`@import`, `@use` and `@forward` are the only at-rules that can introduce a dependency, and in each case the dependency is the **quoted string that immediately follows the at-rule name**. Restricting extraction to that position - rather than collecting identifier tokens from the whole prelude - would fix #14 and the cases above together.

Happy to test a patch against a real codebase if that helps.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the detective-scss entry point and trace how at-rule preludes are scanned for dependencies. Add regression coverage for the @keyframes, @media, @use, and @forward examples, then run the existing test suite. Done means only the quoted dependency immediately following @import, @use, or @forward is reported, while the other shown cases return empty or expected results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.