* @param {string} declarationContents
(declarationContents)
| 131 | * @param {string} declarationContents |
| 132 | */ |
| 133 | function removeReactModuleAugmentations(declarationContents) { |
| 134 | REACT_MODULE_AUGMENTATION_START_REGEX.lastIndex = 0; |
| 135 | |
| 136 | let strippedDeclarationContents = ''; |
| 137 | let contentCursor = 0; |
| 138 | let reactModuleAugmentationMatch; |
| 139 | |
| 140 | while ( |
| 141 | (reactModuleAugmentationMatch = |
| 142 | REACT_MODULE_AUGMENTATION_START_REGEX.exec(declarationContents)) !== null |
| 143 | ) { |
| 144 | const augmentationStartIndex = reactModuleAugmentationMatch.index; |
| 145 | const openingBraceIndex = REACT_MODULE_AUGMENTATION_START_REGEX.lastIndex - 1; |
| 146 | const augmentationEndIndex = getMatchingClosingBraceIndex( |
| 147 | declarationContents, |
| 148 | openingBraceIndex, |
| 149 | ); |
| 150 | |
| 151 | if (augmentationEndIndex === -1) { |
| 152 | throw new Error( |
| 153 | `Could not find end of React module augmentation near index ${augmentationStartIndex}.`, |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | strippedDeclarationContents += declarationContents.slice(contentCursor, augmentationStartIndex); |
| 158 | contentCursor = augmentationEndIndex + 1; |
| 159 | |
| 160 | while ( |
| 161 | contentCursor < declarationContents.length && |
| 162 | /\s/.test(declarationContents.charAt(contentCursor)) |
| 163 | ) { |
| 164 | contentCursor += 1; |
| 165 | } |
| 166 | |
| 167 | if (declarationContents.charAt(contentCursor) === ';') { |
| 168 | contentCursor += 1; |
| 169 | } |
| 170 | |
| 171 | while ( |
| 172 | contentCursor < declarationContents.length && |
| 173 | (declarationContents.charAt(contentCursor) === '\n' || |
| 174 | declarationContents.charAt(contentCursor) === '\r') |
| 175 | ) { |
| 176 | contentCursor += 1; |
| 177 | } |
| 178 | |
| 179 | REACT_MODULE_AUGMENTATION_START_REGEX.lastIndex = contentCursor; |
| 180 | } |
| 181 | |
| 182 | if (contentCursor === 0) { |
| 183 | return declarationContents; |
| 184 | } |
| 185 | |
| 186 | strippedDeclarationContents += declarationContents.slice(contentCursor); |
| 187 | return strippedDeclarationContents; |
| 188 | } |
| 189 | |
| 190 | /** |
no test coverage detected
searching dependent graphs…