@@ -8,6 +8,12 @@ import { Linter } from 'eslint';
8
8
import * as ts from 'typescript' ;
9
9
import { mapFilePath } from './path-utils' ;
10
10
11
+ /**
12
+ * Supports direct identifiers, and those nested within an object (of arbitrary depth)
13
+ * E.g. `...foo` and `...foo.bar.baz.qux` etc
14
+ */
15
+ const SPREAD_ELEMENTS_REGEXP = / \s * \. \. \. [ a - z A - Z 0 - 9 _ ] + ( \. [ a - z A - Z 0 - 9 _ ] + ) * , ? \n ? / g;
16
+
11
17
/**
12
18
* Remove all overrides from the config file
13
19
*/
@@ -87,11 +93,13 @@ export function hasOverride(
87
93
let objSource ;
88
94
if ( ts . isObjectLiteralExpression ( node ) ) {
89
95
objSource = node . getFullText ( ) ;
96
+ // strip any spread elements
97
+ objSource = objSource . replace ( SPREAD_ELEMENTS_REGEXP , '' ) ;
90
98
} else {
91
99
const fullNodeText =
92
100
node [ 'expression' ] . arguments [ 0 ] . body . expression . getFullText ( ) ;
93
101
// strip any spread elements
94
- objSource = fullNodeText . replace ( / \s * \. \. \. [ a - z A - Z 0 - 9 _ ] + , ? \n ? / , '' ) ;
102
+ objSource = fullNodeText . replace ( SPREAD_ELEMENTS_REGEXP , '' ) ;
95
103
}
96
104
const data = parseJson (
97
105
objSource
@@ -107,8 +115,6 @@ export function hasOverride(
107
115
return false ;
108
116
}
109
117
110
- const STRIP_SPREAD_ELEMENTS = / \s * \. \. \. [ a - z A - Z 0 - 9 _ ] + , ? \n ? / g;
111
-
112
118
function parseTextToJson ( text : string ) : any {
113
119
return parseJson (
114
120
text
@@ -153,7 +159,7 @@ export function replaceOverride(
153
159
const fullNodeText =
154
160
node [ 'expression' ] . arguments [ 0 ] . body . expression . getFullText ( ) ;
155
161
// strip any spread elements
156
- objSource = fullNodeText . replace ( STRIP_SPREAD_ELEMENTS , '' ) ;
162
+ objSource = fullNodeText . replace ( SPREAD_ELEMENTS_REGEXP , '' ) ;
157
163
start =
158
164
node [ 'expression' ] . arguments [ 0 ] . body . expression . properties . pos +
159
165
( fullNodeText . length - objSource . length ) ;
@@ -415,7 +421,7 @@ export function removePlugin(
415
421
const plugins = parseTextToJson (
416
422
pluginsElem . initializer
417
423
. getText ( )
418
- . replace ( STRIP_SPREAD_ELEMENTS , '' )
424
+ . replace ( SPREAD_ELEMENTS_REGEXP , '' )
419
425
) ;
420
426
421
427
if ( plugins . length > 1 ) {
0 commit comments