Skip to content

Commit

Permalink
Remove binder from transpileDeclaration implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirtitian committed Jan 18, 2024
1 parent 418f975 commit f68c7da
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 1,038 deletions.
1 change: 0 additions & 1 deletion src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export * from "../transformers/module/system";
export * from "../transformers/module/esnextAnd2015";
export * from "../transformers/module/node";
export * from "../transformers/declarations/diagnostics";
export * from "../transformers/declarations/emitBinder";
export * from "../transformers/declarations/emitResolver";
export * from "../transformers/declarations/transpileDeclaration";
export * from "../transformers/declarations/localInferenceResolver";
Expand Down
64 changes: 3 additions & 61 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ import {
getAllJSDocTags,
getAllowSyntheticDefaultImports,
getAncestor,
getAnyImportSyntax,
getAssignedExpandoInitializer,
getAssignmentDeclarationKind,
getAssignmentDeclarationPropertyAccessKind,
Expand Down Expand Up @@ -329,6 +328,7 @@ import {
getModeForUsageLocation,
getModifiers,
getModuleInstanceState,
getModuleSpecifierForImportOrExport,
getNameFromImportAttribute,
getNameFromIndexInfo,
getNameOfDeclaration,
Expand Down Expand Up @@ -1477,14 +1477,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : ObjectFlags.FreshLiteral;
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;

var { hasVisibleDeclarations, isEntityNameVisible } = createEntityVisibilityChecker({
var { hasVisibleDeclarations, isEntityNameVisible, collectLinkedAliases } = createEntityVisibilityChecker({
defaultSymbolAccessibility: SymbolAccessibility.NotAccessible,
isThisAccessible,
isDeclarationVisible,
markDeclarationAsVisible(declaration) {
getNodeLinks(declaration).isVisible = true;
},
resolveName,
getTargetOfExportSpecifier,
});
var checkBinaryExpression = createCheckBinaryExpression();
var emitResolver = createResolver();
Expand Down Expand Up @@ -4168,23 +4169,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return exportDefaultSymbol;
}

function getModuleSpecifierForImportOrExport(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportOrExportSpecifier): Expression | undefined {
switch (node.kind) {
case SyntaxKind.ImportClause:
return node.parent.moduleSpecifier;
case SyntaxKind.ImportEqualsDeclaration:
return isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined;
case SyntaxKind.NamespaceImport:
return node.parent.parent.moduleSpecifier;
case SyntaxKind.ImportSpecifier:
return node.parent.parent.parent.moduleSpecifier;
case SyntaxKind.ExportSpecifier:
return node.parent.parent.moduleSpecifier;
default:
return Debug.assertNever(node);
}
}

function reportNonDefaultExport(moduleSymbol: Symbol, node: ImportClause) {
if (moduleSymbol.exports?.has(node.symbol.escapedName)) {
error(
Expand Down Expand Up @@ -10367,48 +10351,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}

function collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined {
let exportSymbol: Symbol | undefined;
if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) {
exportSymbol = resolveName(node, node.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, node, /*isUse*/ false);
}
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
exportSymbol = getTargetOfExportSpecifier(node.parent as ExportSpecifier, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
}
let result: Node[] | undefined;
let visited: Set<number> | undefined;
if (exportSymbol) {
visited = new Set();
visited.add(getSymbolId(exportSymbol));
buildVisibleNodeList(exportSymbol.declarations);
}
return result;

function buildVisibleNodeList(declarations: Declaration[] | undefined) {
forEach(declarations, declaration => {
const resultNode = getAnyImportSyntax(declaration) || declaration;
if (setVisibility) {
getNodeLinks(declaration).isVisible = true;
}
else {
result = result || [];
pushIfUnique(result, resultNode);
}

if (isInternalModuleImportEqualsDeclaration(declaration)) {
// Add the referenced top container visible
const internalModuleReference = declaration.moduleReference as Identifier | QualifiedName;
const firstIdentifier = getFirstIdentifier(internalModuleReference);
const importSymbol = resolveName(declaration, firstIdentifier.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
if (importSymbol && visited) {
if (tryAddToSet(visited, getSymbolId(importSymbol))) {
buildVisibleNodeList(importSymbol.declarations);
}
}
}
});
}
}

/**
* Push an entry on the type resolution stack. If an entry with the given target and the given property name
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,6 @@ export namespace Debug {
}
}

/**
* Asserts the symbol is defined and is of the right kind (originating in TSC or sample DTE depending o the test that is currently being run)
* The default implementation just asserts the symbol is not null
* In tests it is overridden to ensure we don't accidentally use TSC symbols in DTE
*/
// eslint-disable-next-line prefer-const
export let assertSymbolValid = (symbol: Symbol) => {
assert(symbol, "Symbol not defined");
};
/**
* Asserts a value has the specified type in typespace only (does not perform a runtime assertion).
* This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and
Expand Down
Loading

0 comments on commit f68c7da

Please sign in to comment.