Skip to content

Commit

Permalink
a quick and dirty hack to shutdown ts80001
Browse files Browse the repository at this point in the history
Turn off the following suggestion:

File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module

related issues: microsoft#23391 microsoft/vscode#48132 microsoft/vscode#47299 microsoft/vscode#47458
  • Loading branch information
weakish committed Dec 15, 2019
1 parent 8a88c1c commit 5d5aab4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 49 deletions.
6 changes: 1 addition & 5 deletions lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -115574,11 +115574,7 @@ var ts;
program.getSemanticDiagnostics(sourceFile, cancellationToken);
var diags = [];
var checker = program.getTypeChecker();
if (sourceFile.commonJsModuleIndicator &&
(ts.programContainsEs6Modules(program) || ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}

var isJsFile = ts.isSourceFileJS(sourceFile);
visitedNestedConvertibleFunctions.clear();
check(sourceFile);
Expand Down
6 changes: 1 addition & 5 deletions lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -116087,11 +116087,7 @@ var ts;
program.getSemanticDiagnostics(sourceFile, cancellationToken);
var diags = [];
var checker = program.getTypeChecker();
if (sourceFile.commonJsModuleIndicator &&
(ts.programContainsEs6Modules(program) || ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}

var isJsFile = ts.isSourceFileJS(sourceFile);
visitedNestedConvertibleFunctions.clear();
check(sourceFile);
Expand Down
6 changes: 1 addition & 5 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -116076,11 +116076,7 @@ var ts;
program.getSemanticDiagnostics(sourceFile, cancellationToken);
var diags = [];
var checker = program.getTypeChecker();
if (sourceFile.commonJsModuleIndicator &&
(ts.programContainsEs6Modules(program) || ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}

var isJsFile = ts.isSourceFileJS(sourceFile);
visitedNestedConvertibleFunctions.clear();
check(sourceFile);
Expand Down
6 changes: 1 addition & 5 deletions lib/typescriptServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -116076,11 +116076,7 @@ var ts;
program.getSemanticDiagnostics(sourceFile, cancellationToken);
var diags = [];
var checker = program.getTypeChecker();
if (sourceFile.commonJsModuleIndicator &&
(ts.programContainsEs6Modules(program) || ts.compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
diags.push(ts.createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), ts.Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}

var isJsFile = ts.isSourceFileJS(sourceFile);
visitedNestedConvertibleFunctions.clear();
check(sourceFile);
Expand Down
31 changes: 2 additions & 29 deletions src/services/suggestionDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ namespace ts {
const diags: DiagnosticWithLocation[] = [];
const checker = program.getTypeChecker();

if (sourceFile.commonJsModuleIndicator &&
(programContainsEs6Modules(program) || compilerOptionsIndicateEs6Modules(program.getCompilerOptions())) &&
containsTopLevelCommonjs(sourceFile)) {
diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}


const isJsFile = isSourceFileJS(sourceFile);

Expand Down Expand Up @@ -79,28 +75,8 @@ namespace ts {
}
}

// convertToEs6Module only works on top-level, so don't trigger it if commonjs code only appears in nested scopes.
function containsTopLevelCommonjs(sourceFile: SourceFile): boolean {
return sourceFile.statements.some(statement => {
switch (statement.kind) {
case SyntaxKind.VariableStatement:
return (statement as VariableStatement).declarationList.declarations.some(decl =>
!!decl.initializer && isRequireCall(propertyAccessLeftHandSide(decl.initializer), /*checkArgumentIsStringLiteralLike*/ true));
case SyntaxKind.ExpressionStatement: {
const { expression } = statement as ExpressionStatement;
if (!isBinaryExpression(expression)) return isRequireCall(expression, /*checkArgumentIsStringLiteralLike*/ true);
const kind = getAssignmentDeclarationKind(expression);
return kind === AssignmentDeclarationKind.ExportsProperty || kind === AssignmentDeclarationKind.ModuleExports;
}
default:
return false;
}
});
}

function propertyAccessLeftHandSide(node: Expression): Expression {
return isPropertyAccessExpression(node) ? propertyAccessLeftHandSide(node.expression) : node;
}


function importNameForConvertToDefaultImport(node: AnyValidImportOrReExport): Identifier | undefined {
switch (node.kind) {
Expand Down Expand Up @@ -140,9 +116,6 @@ namespace ts {
return !!returnType && !!checker.getPromisedTypeOfPromise(returnType);
}

function getErrorNodeFromCommonJsIndicator(commonJsModuleIndicator: Node): Node {
return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator;
}

function hasReturnStatementWithPromiseHandler(body: Block): boolean {
return !!forEachReturnStatement(body, isReturnStatementWithFixablePromiseHandler);
Expand Down

0 comments on commit 5d5aab4

Please sign in to comment.