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

Function containsTopLevelCommonjs

test/fixtures/snapshot/typescript.js:144755–144773  ·  view source on GitHub ↗
(sourceFile)

Source from the content-addressed store, hash-verified

144753 ts.computeSuggestionDiagnostics = computeSuggestionDiagnostics;
144754 // convertToEsModule only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
144755 function containsTopLevelCommonjs(sourceFile) {
144756 return sourceFile.statements.some(function (statement) {
144757 switch (statement.kind) {
144758 case 237 /* SyntaxKind.VariableStatement */:
144759 return statement.declarationList.declarations.some(function (decl) {
144760 return !!decl.initializer && ts.isRequireCall(propertyAccessLeftHandSide(decl.initializer), /*checkArgumentIsStringLiteralLike*/ true);
144761 });
144762 case 238 /* SyntaxKind.ExpressionStatement */: {
144763 var expression = statement.expression;
144764 if (!ts.isBinaryExpression(expression))
144765 return ts.isRequireCall(expression, /*checkArgumentIsStringLiteralLike*/ true);
144766 var kind = ts.getAssignmentDeclarationKind(expression);
144767 return kind === 1 /* AssignmentDeclarationKind.ExportsProperty */ || kind === 2 /* AssignmentDeclarationKind.ModuleExports */;
144768 }
144769 default:
144770 return false;
144771 }
144772 });
144773 }
144774 function propertyAccessLeftHandSide(node) {
144775 return ts.isPropertyAccessExpression(node) ? propertyAccessLeftHandSide(node.expression) : node;
144776 }

Callers 1

Calls 2

someMethod · 0.80

Tested by

no test coverage detected