MCPcopy Create free account
hub / github.com/nodejs/node / collectReadsAndWrites

Function collectReadsAndWrites

test/fixtures/snapshot/typescript.js:161297–161633  ·  view source on GitHub ↗
(targetRange, scopes, enclosingTextRange, sourceFile, checker, cancellationToken)

Source from the content-addressed store, hash-verified

161295 Usage[Usage["Write"] = 2] = "Write";
161296 })(Usage || (Usage = {}));
161297 function collectReadsAndWrites(targetRange, scopes, enclosingTextRange, sourceFile, checker, cancellationToken) {
161298 var allTypeParameterUsages = new ts.Map(); // Key is type ID
161299 var usagesPerScope = [];
161300 var substitutionsPerScope = [];
161301 var functionErrorsPerScope = [];
161302 var constantErrorsPerScope = [];
161303 var visibleDeclarationsInExtractedRange = [];
161304 var exposedVariableSymbolSet = new ts.Map(); // Key is symbol ID
161305 var exposedVariableDeclarations = [];
161306 var firstExposedNonVariableDeclaration;
161307 var expression = !isReadonlyArray(targetRange.range)
161308 ? targetRange.range
161309 : targetRange.range.length === 1 && ts.isExpressionStatement(targetRange.range[0])
161310 ? targetRange.range[0].expression
161311 : undefined;
161312 var expressionDiagnostic;
161313 if (expression === undefined) {
161314 var statements = targetRange.range;
161315 var start = ts.first(statements).getStart();
161316 var end = ts.last(statements).end;
161317 expressionDiagnostic = ts.createFileDiagnostic(sourceFile, start, end - start, Messages.expressionExpected);
161318 }
161319 else if (checker.getTypeAtLocation(expression).flags & (16384 /* TypeFlags.Void */ | 131072 /* TypeFlags.Never */)) {
161320 expressionDiagnostic = ts.createDiagnosticForNode(expression, Messages.uselessConstantType);
161321 }
161322 // initialize results
161323 for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
161324 var scope = scopes_1[_i];
161325 usagesPerScope.push({ usages: new ts.Map(), typeParameterUsages: new ts.Map(), substitutions: new ts.Map() });
161326 substitutionsPerScope.push(new ts.Map());
161327 functionErrorsPerScope.push([]);
161328 var constantErrors = [];
161329 if (expressionDiagnostic) {
161330 constantErrors.push(expressionDiagnostic);
161331 }
161332 if (ts.isClassLike(scope) && ts.isInJSFile(scope)) {
161333 constantErrors.push(ts.createDiagnosticForNode(scope, Messages.cannotExtractToJSClass));
161334 }
161335 if (ts.isArrowFunction(scope) && !ts.isBlock(scope.body)) {
161336 // TODO (https://github.com/Microsoft/TypeScript/issues/18924): allow this
161337 constantErrors.push(ts.createDiagnosticForNode(scope, Messages.cannotExtractToExpressionArrowFunction));
161338 }
161339 constantErrorsPerScope.push(constantErrors);
161340 }
161341 var seenUsages = new ts.Map();
161342 var target = isReadonlyArray(targetRange.range) ? ts.factory.createBlock(targetRange.range) : targetRange.range;
161343 var unmodifiedNode = isReadonlyArray(targetRange.range) ? ts.first(targetRange.range) : targetRange.range;
161344 var inGenericContext = isInGenericContext(unmodifiedNode);
161345 collectUsages(target);
161346 // Unfortunately, this code takes advantage of the knowledge that the generated method
161347 // will use the contextual type of an expression as the return type of the extracted
161348 // method (and will therefore "use" all the types involved).
161349 if (inGenericContext && !isReadonlyArray(targetRange.range) && !ts.isJsxAttribute(targetRange.range)) {
161350 var contextualType = checker.getContextualType(targetRange.range); // TODO: GH#18217
161351 recordTypeParameterUsages(contextualType);
161352 }
161353 if (allTypeParameterUsages.size > 0) {
161354 var seenTypeParameterUsages = new ts.Map(); // Key is type ID

Callers 1

Calls 14

isReadonlyArrayFunction · 0.85
isInGenericContextFunction · 0.85
collectUsagesFunction · 0.85
_loop_18Function · 0.85
assertMethod · 0.80
forEachChildMethod · 0.80
forEachMethod · 0.65
hasMethod · 0.65
firstMethod · 0.45
lastMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected