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

Function refineNode

test/fixtures/snapshot/typescript.js:160251–160279  ·  view source on GitHub ↗

* Attempt to refine the extraction node (generally, by shrinking it) to produce better results. * @param node The unrefined extraction node.

(node)

Source from the content-addressed store, hash-verified

160249 * @param node The unrefined extraction node.
160250 */
160251 function refineNode(node) {
160252 if (ts.isReturnStatement(node)) {
160253 if (node.expression) {
160254 return node.expression;
160255 }
160256 }
160257 else if (ts.isVariableStatement(node) || ts.isVariableDeclarationList(node)) {
160258 var declarations_5 = ts.isVariableStatement(node) ? node.declarationList.declarations : node.declarations;
160259 var numInitializers = 0;
160260 var lastInitializer = void 0;
160261 for (var _i = 0, declarations_4 = declarations_5; _i < declarations_4.length; _i++) {
160262 var declaration = declarations_4[_i];
160263 if (declaration.initializer) {
160264 numInitializers++;
160265 lastInitializer = declaration.initializer;
160266 }
160267 }
160268 if (numInitializers === 1) {
160269 return lastInitializer;
160270 }
160271 // No special handling if there are multiple initializers.
160272 }
160273 else if (ts.isVariableDeclaration(node)) {
160274 if (node.initializer) {
160275 return node.initializer;
160276 }
160277 }
160278 return node;
160279 }
160280 function checkRootNode(node) {
160281 if (ts.isIdentifier(ts.isExpressionStatement(node) ? node.expression : node)) {
160282 return [ts.createDiagnosticForNode(node, Messages.cannotExtractIdentifier)];

Callers 1

getRangeToExtractFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected