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

Function getImportConversionInfo

test/fixtures/snapshot/typescript.js:159352–159378  ·  view source on GitHub ↗
(context, considerPartialSpans)

Source from the content-addressed store, hash-verified

159350 }
159351 });
159352 function getImportConversionInfo(context, considerPartialSpans) {
159353 if (considerPartialSpans === void 0) { considerPartialSpans = true; }
159354 var file = context.file;
159355 var span = ts.getRefactorContextSpan(context);
159356 var token = ts.getTokenAtPosition(file, span.start);
159357 var importDecl = considerPartialSpans ? ts.findAncestor(token, ts.isImportDeclaration) : ts.getParentNodeInSpan(token, file, span);
159358 if (!importDecl || !ts.isImportDeclaration(importDecl))
159359 return { error: "Selection is not an import declaration." };
159360 var end = span.start + span.length;
159361 var nextToken = ts.findNextToken(importDecl, importDecl.parent, file);
159362 if (nextToken && end > nextToken.getStart())
159363 return undefined;
159364 var importClause = importDecl.importClause;
159365 if (!importClause) {
159366 return { error: ts.getLocaleSpecificMessage(ts.Diagnostics.Could_not_find_import_clause) };
159367 }
159368 if (!importClause.namedBindings) {
159369 return { error: ts.getLocaleSpecificMessage(ts.Diagnostics.Could_not_find_namespace_import_or_named_imports) };
159370 }
159371 if (importClause.namedBindings.kind === 268 /* SyntaxKind.NamespaceImport */) {
159372 return { convertTo: 0 /* ImportKind.Named */, import: importClause.namedBindings };
159373 }
159374 var shouldUseDefault = getShouldUseDefault(context.program, importClause);
159375 return shouldUseDefault
159376 ? { convertTo: 1 /* ImportKind.Default */, import: importClause.namedBindings }
159377 : { convertTo: 2 /* ImportKind.Namespace */, import: importClause.namedBindings };
159378 }
159379 function getShouldUseDefault(program, importClause) {
159380 return ts.getAllowSyntheticDefaultImports(program.getCompilerOptions())
159381 && isExportEqualsModule(importClause.parent.moduleSpecifier, program.getTypeChecker());

Callers 1

typescript.jsFile · 0.85

Calls 1

getShouldUseDefaultFunction · 0.85

Tested by

no test coverage detected