Skip to content

Commit 4b75c6f

Browse files
committed
fix: resolve TypeScript type errors in index.ts
- Type `src` parameter as `string` and `references` as `string[]` - Guard against undefined `firstNode` and `lastNode` from postcss-values-parser
1 parent 61f8367 commit 4b75c6f

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎src/index.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414

1515
const debug = debuglog('detective-postcss');
1616

17-
function detective(src, options: detective.Options = { url: false }) {
18-
let references = [];
17+
function detective(src: string, options: detective.Options = { url: false }) {
18+
let references: string[] = [];
1919
let root;
2020
try {
2121
root = parse(src);
@@ -27,14 +27,18 @@ function detective(src, options: detective.Options = { url: false }) {
2727
let file = null;
2828
if (isImportRule(rule)) {
2929
const firstNode = postCssParseValue(rule.params).first;
30-
file = getValueOrUrl(firstNode);
31-
if (file) {
32-
debug('found %s of %s', '@import', file);
30+
if (firstNode) {
31+
file = getValueOrUrl(firstNode);
32+
if (file) {
33+
debug('found %s of %s', '@import', file);
34+
}
3335
}
3436
}
3537

3638
if (isValueRule(rule)) {
3739
const lastNode = postCssParseValue(rule.params).last;
40+
if (!lastNode) return;
41+
3842
const prevNode = lastNode.prev();
3943

4044
if (prevNode && isFrom(prevNode)) {

0 commit comments

Comments
 (0)