File tree Expand file tree Collapse file tree 3 files changed +17
-48
lines changed Expand file tree Collapse file tree 3 files changed +17
-48
lines changed Original file line number Diff line number Diff line change 1
1
import { clearComments } from './parseCssVars' ;
2
2
3
- const cssClassNameReg = / (? = ( [ \. ] { 1 } [ a - z A - Z _ ] + [ \w \_ \- ] * ) [ \s \. \, \+ \{ \> # \: ] { 1 } ) / g ;
3
+ const cssClassNameReg = / (? = ( \. [ a - z _ ] [ - \w ] * ) [ \s . , + ~ > : # [ { ] ) / gi ;
4
4
5
5
export function * parseCssClassNames ( styleContent : string ) {
6
6
styleContent = clearComments ( styleContent ) ;
7
7
const matches = styleContent . matchAll ( cssClassNameReg ) ;
8
8
for ( const match of matches ) {
9
- if ( match . index !== undefined ) {
10
- const matchText = match [ 1 ] ;
11
- if ( matchText !== undefined ) {
12
- yield { offset : match . index , text : matchText } ;
13
- }
9
+ const matchText = match [ 1 ] ;
10
+ if ( matchText ) {
11
+ yield { offset : match . index , text : matchText } ;
14
12
}
15
13
}
16
14
}
Original file line number Diff line number Diff line change 1
1
// https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/cssVars.ts#L47-L61
2
2
3
- const vBindCssVarReg = / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ ' " ] [ ^ ) ] * ) ) \s * \) / g ;
3
+ const vBindCssVarReg = / \b v - b i n d \( \s * (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ a - z _ ] \w * ) ) \s * \) / gi ;
4
4
const commentReg1 = / \/ \* ( [ \s \S ] * ?) \* \/ / g;
5
5
const commentReg2 = / \/ \/ ( [ \s \S ] * ?) \n / g;
6
6
7
7
export function * parseCssVars ( styleContent : string ) {
8
8
styleContent = clearComments ( styleContent ) ;
9
9
const matchs = styleContent . matchAll ( vBindCssVarReg ) ;
10
10
for ( const match of matchs ) {
11
- if ( match . index !== undefined ) {
12
- const matchText = match [ 1 ] ?? match [ 2 ] ?? match [ 3 ] ;
13
- if ( matchText !== undefined ) {
14
- const offset = match . index + styleContent . slice ( match . index ) . indexOf ( matchText ) ;
15
- yield { offset, text : matchText } ;
16
- }
11
+ const matchText = match . slice ( 1 ) . find ( t => t ) ;
12
+ if ( matchText ) {
13
+ const offset = match . index + styleContent . slice ( match . index ) . indexOf ( matchText ) ;
14
+ yield { offset, text : matchText } ;
17
15
}
18
16
}
19
17
}
Original file line number Diff line number Diff line change @@ -185,7 +185,6 @@ describe('Renaming', async () => {
185
185
.bar { color: v-bind(foo|); }
186
186
.bar { color: v-bind('foo'); }
187
187
.bar { color: v-bind("foo"); }
188
- .bar { color: v-bind(foo + foo); }
189
188
.bar { color: v-bind('foo + foo'); }
190
189
.bar { color: v-bind("foo + foo"); }
191
190
.bar { color: v-bind(); }
@@ -199,32 +198,6 @@ describe('Renaming', async () => {
199
198
{
200
199
"changes": {
201
200
"file://\${testWorkspacePath}/fixture.vue": [
202
- {
203
- "newText": "bar",
204
- "range": {
205
- "end": {
206
- "character": 34,
207
- "line": 10,
208
- },
209
- "start": {
210
- "character": 31,
211
- "line": 10,
212
- },
213
- },
214
- },
215
- {
216
- "newText": "bar",
217
- "range": {
218
- "end": {
219
- "character": 28,
220
- "line": 10,
221
- },
222
- "start": {
223
- "character": 25,
224
- "line": 10,
225
- },
226
- },
227
- },
228
201
{
229
202
"newText": "bar",
230
203
"range": {
@@ -256,11 +229,11 @@ describe('Renaming', async () => {
256
229
"range": {
257
230
"end": {
258
231
"character": 35,
259
- "line": 12 ,
232
+ "line": 11 ,
260
233
},
261
234
"start": {
262
235
"character": 32,
263
- "line": 12 ,
236
+ "line": 11 ,
264
237
},
265
238
},
266
239
},
@@ -269,11 +242,11 @@ describe('Renaming', async () => {
269
242
"range": {
270
243
"end": {
271
244
"character": 29,
272
- "line": 12 ,
245
+ "line": 11 ,
273
246
},
274
247
"start": {
275
248
"character": 26,
276
- "line": 12 ,
249
+ "line": 11 ,
277
250
},
278
251
},
279
252
},
@@ -282,11 +255,11 @@ describe('Renaming', async () => {
282
255
"range": {
283
256
"end": {
284
257
"character": 35,
285
- "line": 11 ,
258
+ "line": 10 ,
286
259
},
287
260
"start": {
288
261
"character": 32,
289
- "line": 11 ,
262
+ "line": 10 ,
290
263
},
291
264
},
292
265
},
@@ -295,11 +268,11 @@ describe('Renaming', async () => {
295
268
"range": {
296
269
"end": {
297
270
"character": 29,
298
- "line": 11 ,
271
+ "line": 10 ,
299
272
},
300
273
"start": {
301
274
"character": 26,
302
- "line": 11 ,
275
+ "line": 10 ,
303
276
},
304
277
},
305
278
},
You can’t perform that action at this time.
0 commit comments