@@ -76,16 +76,30 @@ export default classes;
76
76
. filter ( ( [ classname ] ) => isValidVariable ( classname ) ) ;
77
77
78
78
filteredClasses . forEach ( ( [ classname , originalClassname ] ) => {
79
- const classRegexp = new RegExp ( `${ originalClassname } [\\s{]` , 'g' ) ;
80
-
81
- const matchedLine = cssLines . findIndex ( ( line ) => classRegexp . test ( line ) ) ;
82
- const matchedColumn =
83
- matchedLine && cssLines [ matchedLine ] . indexOf ( originalClassname ) ;
79
+ let matchedLine ;
80
+ let matchedColumn ;
81
+
82
+ for ( let i = 0 ; i < cssLines . length ; i ++ ) {
83
+ const match = new RegExp (
84
+ // NOTE: This excludes any match not starting with:
85
+ // - `.` for classnames,
86
+ // - `:` or ` ` for animation names,
87
+ // and any matches followed by valid CSS selector characters.
88
+ `[:.\\s]${ originalClassname } (?![_a-zA-Z0-9-])` ,
89
+ 'g' ,
90
+ ) . exec ( cssLines [ i ] ) ;
91
+
92
+ if ( match ) {
93
+ matchedLine = i ;
94
+ matchedColumn = match . index ;
95
+ break ;
96
+ }
97
+ }
84
98
85
99
const { line : lineNumber } = smc . originalPositionFor ( {
86
100
// Lines start at 1, not 0.
87
- line : matchedLine >= 0 ? matchedLine + 1 : 1 ,
88
- column : matchedColumn >= 0 ? matchedColumn : 0 ,
101
+ line : matchedLine ? matchedLine + 1 : 1 ,
102
+ column : matchedColumn ? matchedColumn : 0 ,
89
103
} ) ;
90
104
91
105
dtsLines [ lineNumber ? lineNumber - 1 : 0 ] +=
0 commit comments