( jsCodeString: string, definedTypeNames?: string[], )
| 230 | } |
| 231 | |
| 232 | export function stripBasicTypescriptTypes( |
| 233 | jsCodeString: string, |
| 234 | definedTypeNames?: string[], |
| 235 | ): string { |
| 236 | /** Remove type definitions like `: string`, `: number`, `: any` etc. **/ |
| 237 | definedTypeNames = definedTypeNames ?? []; |
| 238 | |
| 239 | // Remove interface definitions |
| 240 | const interfaces = jsCodeString.match( |
| 241 | /(?:export )?interface\s+(\w+)\s*\{[^}]+}/g, |
| 242 | ); |
| 243 | if (interfaces) { |
| 244 | definedTypeNames.push( |
| 245 | // ...interfaces.map((i) => i.match(/(?:export )?interface\s+(\w+)/)[1]), |
| 246 | ...interfaces.map((i) => i.match(/(?:export )?interface\s+(\w+)/)![1]), |
| 247 | ); |
| 248 | } |
| 249 | jsCodeString = jsCodeString.replace( |
| 250 | /(?:export )?interface\s+(\w+)\s*\{[^}]+}/g, |
| 251 | "", |
| 252 | ); |
| 253 | |
| 254 | // Remove type definitions |
| 255 | const types = jsCodeString.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/g); |
| 256 | if (types) { |
| 257 | definedTypeNames.push( |
| 258 | // ...types.map((i) => i.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/)[1]), |
| 259 | ...types.map((i) => i.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/)![1]), |
| 260 | ); |
| 261 | } |
| 262 | jsCodeString = jsCodeString.replace(/(export )?type\s*\w+\s*=\s*\w+;?/g, ""); |
| 263 | |
| 264 | jsCodeString = jsCodeString.replace( |
| 265 | new RegExp( |
| 266 | `: (${ |
| 267 | definedTypeNames.length > 0 |
| 268 | ? definedTypeNames |
| 269 | .map((t) => t.replace(/([\[|(){])/g, "\\$1") + "\\b") |
| 270 | .join("|") + "|" |
| 271 | : "" |
| 272 | }any\[]|string\[]|number\[]|null\[]|boolean\[]|object\[]|any|string|number|null|boolean|object|Record<string,\s*(any|string|number|null|boolean|object)>)(\[])?`, |
| 273 | "g", |
| 274 | ), |
| 275 | "", |
| 276 | ); |
| 277 | |
| 278 | return jsCodeString; |
| 279 | } |
| 280 | |
| 281 | export function shouldTerminateDataAnalysisStreaming( |
| 282 | streamedText: string, |
no outgoing calls
no test coverage detected