11import { MappedComponent } from "@solid-devtools/shared/graph"
22import { LOCATION_ATTRIBUTE_NAME } from "@solid-devtools/shared/variables"
3- import { isMac } from "@solid-primitives/platform"
3+ import { isWindows } from "@solid-primitives/platform"
44import { SelectedComponent } from "."
55import { ElementLocation } from "./goToSource"
66
77const 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
1012export 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
2119export 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