Skip to content

Commit 0c1892f

Browse files
committed
locator: Use windows path regex only for windows
1 parent c408963 commit 0c1892f

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solid-devtools/locator": patch
3+
---
4+
5+
Use windows path regex only for windows. (Related #66)

packages/locator/src/findComponent.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import { MappedComponent } from "@solid-devtools/shared/graph"
22
import { LOCATION_ATTRIBUTE_NAME } from "@solid-devtools/shared/variables"
3-
import { isMac } from "@solid-primitives/platform"
3+
import { isWindows } from "@solid-primitives/platform"
44
import { SelectedComponent } from "."
55
import { ElementLocation } from "./goToSource"
66

77
const LOC_ATTR_REGEX_WIN = /^((?:[^\\/:*?"<>|]+\\)*[^\\/:*?"<>|]+):([0-9]+):([0-9]+)$/
8-
const LOC_ATTR_REGEX_MAC = /^((?:[^\\:*?"<>|]+\/)*[^\\/:*?"<>|]+):([0-9]+):([0-9]+)$/
8+
const LOC_ATTR_REGEX_UNIX = /^((?:[^\\:*?"<>|]+\/)*[^\\/:*?"<>|]+):([0-9]+):([0-9]+)$/
9+
10+
const LOC_ATTR_REGEX = isWindows ? LOC_ATTR_REGEX_WIN : LOC_ATTR_REGEX_UNIX
911

1012
export function getLocationFromAttribute(value: string): ElementLocation | null {
11-
const match = value.match(isMac ? LOC_ATTR_REGEX_MAC : LOC_ATTR_REGEX_WIN)
13+
const match = value.match(LOC_ATTR_REGEX)
1214
if (!match) return null
1315
const [, filePath, line, column] = match
14-
return {
15-
filePath,
16-
line: +line,
17-
column: +column,
18-
}
16+
return { filePath, line: +line, column: +column }
1917
}
2018

2119
export function getLocationFromElement(element: Element): ElementLocation | null {
@@ -52,12 +50,7 @@ export function findComponent(
5250
const cached = findComponentCache.get(el)
5351
if (cached !== undefined) {
5452
checked.forEach(cel => findComponentCache.set(cel, cached))
55-
return cached
56-
? {
57-
...cached,
58-
location: location ?? cached.location,
59-
}
60-
: null
53+
return cached ? { ...cached, location: location ?? cached.location } : null
6154
}
6255

6356
checked.push(el)
@@ -68,11 +61,7 @@ export function findComponent(
6861
(Array.isArray(comp.resolved) && comp.resolved.some(e => e === el)) ||
6962
el === comp.resolved
7063
) {
71-
const obj = {
72-
name: comp.name,
73-
element: el,
74-
location,
75-
}
64+
const obj = { name: comp.name, element: el, location }
7665
checked.forEach(cel => findComponentCache.set(cel, obj))
7766
return obj
7867
}

0 commit comments

Comments
 (0)