Skip to content

Commit

Permalink
fix: don't mark invalid symbols as companion objects
Browse files Browse the repository at this point in the history
  • Loading branch information
0x706b committed Nov 1, 2022
1 parent 10d2a52 commit 87b8df8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
5 changes: 0 additions & 5 deletions effect/packages/package1/src/companions-everywhere.ts
Expand Up @@ -13,8 +13,3 @@ export const get: A = {}
* @tsplus static companions-everywhere/AOps __call
*/
export const callA = (): A => ({})

class X {}

new X()
X
1 change: 0 additions & 1 deletion effect/packages/package2/src/external-definitions.ts
@@ -1,4 +1,3 @@
import { Async } from '@fp-ts/core/Async'

Async.fromSync(() => console.log("Fluent in fp-ts!")).delay(1)

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -2790,16 +2790,19 @@ namespace ts {
if (symbol) {
if (companionSymbolCache.has(symbol)) {
result = symbol;
getSymbolLinks(symbol).isPossibleCompanionReference = true;
break loop;
}
if (symbol.exportSymbol && companionSymbolCache.has(symbol.exportSymbol)) {
result = symbol.exportSymbol;
getSymbolLinks(symbol.exportSymbol).isPossibleCompanionReference = true;
break loop;
}
if (symbol.declarations && symbol.declarations[0] && isImportSpecifier(symbol.declarations[0])) {
const originalSymbol = getTargetOfImportSpecifier(symbol.declarations[0], false);
if (originalSymbol && companionSymbolCache.has(originalSymbol)) {
result = originalSymbol;
getSymbolLinks(originalSymbol).isPossibleCompanionReference = true;
symbol.isReferenced = SymbolFlags.Value;
break loop;
}
Expand Down Expand Up @@ -5837,8 +5840,21 @@ namespace ts {
if (!type) {
return false
}
return !!(getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class)
|| (!!symbol?.declarations?.[0] && (isInterfaceDeclaration(symbol.declarations[0]) || isTypeAliasDeclaration(symbol.declarations[0])))

// Class companion object
if (getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & SymbolFlags.Class) {
return true
}

// Synthetic Interface or TypeAlias companion object
if (symbol && symbol.declarations && symbol.declarations.length > 0) {
const declaration = symbol.declarations[0]
if (isInterfaceDeclaration(declaration) || isTypeAliasDeclaration(declaration)) {
return !!getSymbolLinks(symbol).isPossibleCompanionReference;
}
}

return false
}
// TSPLUS EXTENSION END

Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Expand Up @@ -5817,6 +5817,7 @@ namespace ts {
type: Type,
tags: Set<string>
}
isPossibleCompanionReference?: boolean
// TSPLUS END
}

Expand Down

0 comments on commit 87b8df8

Please sign in to comment.