Skip to content

Commit 8176354

Browse files
committed
Fix the duplicate function implementation error that depended on order of files
1 parent 11b270f commit 8176354

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10770,6 +10770,7 @@ namespace ts {
1077010770

1077110771
let symbol = getSymbolOfNode(node);
1077210772
let firstDeclaration = getDeclarationOfKind(symbol, node.kind);
10773+
1077310774
// Only type check the symbol once
1077410775
if (node === firstDeclaration) {
1077510776
checkFunctionOrConstructorSymbol(symbol);
@@ -11782,7 +11783,13 @@ namespace ts {
1178211783
let symbol = getSymbolOfNode(node);
1178311784
let localSymbol = node.localSymbol || symbol;
1178411785

11785-
let firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
11786+
let firstDeclaration = forEach(symbol.declarations, declaration => {
11787+
// Get first non javascript function declaration
11788+
if (declaration.kind === node.kind && !isJavaScript(getSourceFile(declaration).fileName)) {
11789+
return declaration;
11790+
}
11791+
});
11792+
1178611793
// Only type check the symbol once
1178711794
if (node === firstDeclaration) {
1178811795
checkFunctionOrConstructorSymbol(localSymbol);

tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
// @emitThisFile: true
1212
////function foo() { return 30; }/*2*/
1313

14+
goTo.marker("1");
15+
verify.getSemanticDiagnostics('[]');
1416
goTo.marker("2");
15-
verify.getSemanticDiagnostics("[]");
17+
verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]');
1618
verify.verifyGetEmitOutputContentsForCurrentFile([
1719
{ fileName: "out.js", content: "function foo() { return 10; }\r\nfunction foo() { return 30; }\r\n" },
1820
{ fileName: "out.d.ts", content: "" }]);
1921
goTo.marker("2");
20-
verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]');
22+
verify.getSemanticDiagnostics('[\n {\n "message": "Duplicate function implementation.",\n "start": 9,\n "length": 3,\n "category": "error",\n "code": 2393\n }\n]');
23+
goTo.marker("1");
24+
verify.getSemanticDiagnostics('[]');

0 commit comments

Comments
 (0)