Skip to content

Commit

Permalink
Merge pull request #123 from bloomberg/isolated-declarations-pr-review
Browse files Browse the repository at this point in the history
Fixed imports to use namespace imports. Other minor fixes
  • Loading branch information
dragomirtitian authored Nov 29, 2023
2 parents c0831c2 + 7067307 commit d9328ea
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 161 deletions.
1 change: 1 addition & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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";
export * from "../transformers/declarations/types";
export * from "../transformers/declarations";
export * from "../transformer";
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
createEmptyExports,
createGetSymbolAccessibilityDiagnosticForNode,
createGetSymbolAccessibilityDiagnosticForNodeName,
createLocalInferenceResolver,
createSymbolTable,
createUnparsedSourceFile,
Debug,
Expand Down Expand Up @@ -165,6 +166,7 @@ import {
LateBoundDeclaration,
LateVisibilityPaintedStatement,
length,
LocalInferenceResolver,
map,
mapDefined,
MethodDeclaration,
Expand Down Expand Up @@ -238,10 +240,6 @@ import {
VisitResult,
} from "../_namespaces/ts";
import * as moduleSpecifiers from "../_namespaces/ts.moduleSpecifiers";
import {
createLocalInferenceResolver,
LocalInferenceResolver,
} from "./declarations/localInferenceResolver";

/** @internal */
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined {
Expand Down
196 changes: 102 additions & 94 deletions src/compiler/transformers/declarations/emitBinder.ts

Large diffs are not rendered by default.

16 changes: 7 additions & 9 deletions src/compiler/transformers/declarations/emitResolver.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
appendIfUnique,
bindSourceFileForDeclarationEmit,
ComputedPropertyName,
createEvaluator,
Debug,
Declaration,
DeclarationName,
determineIfDeclarationIsVisible,
ElementAccessExpression,
EmitDeclarationNodeLinks,
EmitDeclarationSymbol,
emptyArray,
EntityNameOrEntityNameExpression,
EnumDeclaration,
Expand All @@ -21,6 +24,7 @@ import {
FunctionLikeDeclaration,
getAnyImportSyntax,
getFirstIdentifier,
getMemberKey,
getNameOfDeclaration,
getParseTreeNode,
getTextOfNode,
Expand All @@ -46,6 +50,7 @@ import {
isInJSFile,
isLateVisibilityPaintedStatement,
isNumericLiteral,
IsolatedEmitResolver,
isPartOfTypeNode,
isPrefixUnaryExpression,
isPropertyAccessExpression,
Expand Down Expand Up @@ -78,15 +83,8 @@ import {
SyntaxKind,
VariableDeclaration,
} from "../../_namespaces/ts";
import {
bindSourceFileForDeclarationEmit,
EmitDeclarationNodeLinks,
EmitDeclarationSymbol,
getMemberKey,
} from "./emitBinder";
import {
IsolatedEmitResolver,
} from "./types";



/** @internal */
export function createEmitDeclarationResolver(file: SourceFile): IsolatedEmitResolver {
Expand Down
85 changes: 36 additions & 49 deletions src/compiler/transformers/declarations/localInferenceResolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import {
ArrayLiteralExpression,
ArrowFunction,
AsExpression,
ClassExpression,
createDiagnosticForNode,
createPropertyNameNodeForIdentifierOrLiteral,
DiagnosticMessage,
Diagnostics,
EntityNameOrEntityNameExpression,
ExportAssignment,
FunctionExpression,
GetAccessorDeclaration,
getCommentRange,
getEmitScriptTarget,
getMemberKeyFromElement,
setCommentRange,
} from "../../_namespaces/ts";
import {
Diagnostics,
} from "../../diagnosticInformationMap.generated";
import {
HasInferredType,
hasSyntacticModifier,
Identifier,
isClassExpression,
isComputedPropertyName,
isConstTypeReference,
isEntityNameExpression,
isExportAssignment,
isGetAccessorDeclaration,
isIdentifier,
Expand All @@ -18,83 +30,55 @@ import {
isNoSubstitutionTemplateLiteral,
isNumericLiteral,
isOmittedExpression,
isOptionalDeclaration,
isParameter,
isPrefixUnaryExpression,
isPrivateIdentifier,
isPropertyAssignment,
isPropertyDeclaration,
isPropertyName,
isSetAccessorDeclaration,
isShorthandPropertyAssignment,
isSpreadAssignment,
isSpreadElement,
isStringDoubleQuoted,
isStringLiteral,
isStringLiteralLike,
isTypeLiteralNode,
isTypeNode,
isTypeParameterDeclaration,
isTypeReferenceNode,
isUnionTypeNode,
isVariableDeclaration,
} from "../../factory/nodeTests";
import {
setTextRange,
} from "../../factory/utilitiesPublic";
import {
nullTransformationContext,
} from "../../transformer";
import {
ArrayLiteralExpression,
ArrowFunction,
AsExpression,
ClassExpression,
DiagnosticMessage,
EntityNameOrEntityNameExpression,
ExportAssignment,
FunctionExpression,
GetAccessorDeclaration,
HasInferredType,
Identifier,
KeywordTypeSyntaxKind,
LiteralExpression,
MethodDeclaration,
ModifierFlags,
Node,
NodeArray,
NodeFlags,
nullTransformationContext,
ObjectLiteralExpression,
ParameterDeclaration,
ParenthesizedExpression,
PrefixUnaryExpression,
PropertyName,
SetAccessorDeclaration,
setCommentRange,
setTextRange,
SourceFile,
SyntaxKind,
TransformationContext,
TypeAssertion,
TypeElement,
TypeNode,
Visitor,
VisitResult,
} from "../../types";
import {
createDiagnosticForNode,
createPropertyNameNodeForIdentifierOrLiteral,
getEmitScriptTarget,
hasSyntacticModifier,
isEntityNameExpression,
isOptionalDeclaration,
isStringDoubleQuoted,
} from "../../utilities";
import {
isConstTypeReference,
isPropertyName,
isStringLiteralLike,
isTypeNode,
unescapeLeadingUnderscores,
} from "../../utilitiesPublic";
import {
visitEachChild,
visitNode,
visitNodes,
} from "../../visitorPublic";
Visitor,
VisitResult,
} from "../../_namespaces/ts";

enum NarrowBehavior {
None = 0,
Expand All @@ -115,6 +99,9 @@ export interface LocalInferenceResolver {
makeInvalidType(): Node;
fromInitializer(node: HasInferredType | ExportAssignment, type: TypeNode | undefined, sourceFile: SourceFile): TypeNode;
}
/**
* @internal
*/
export function createLocalInferenceResolver({
setEnclosingDeclarations,
visitDeclarationSubtree,
Expand Down Expand Up @@ -696,15 +683,15 @@ export function createLocalInferenceResolver({
* function x(o = "", v: string)
*/
if (node.initializer && !isOptional) {
localType.typeNode = addUndefinedInUnion(localType.typeNode);
}
localType.typeNode = addUndefinedInUnion(localType.typeNode);
}
/**
* Constructor properties that are optional must have | undefined included to work well with exactOptionalPropertyTypes
* constructor(public x?: number) -> x?: number | undefined
*/
if (isOptional && !node.initializer && hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
localType.typeNode = addUndefinedInUnion(localType.typeNode);
}
}
}
}
else if (type) {
Expand Down Expand Up @@ -732,7 +719,7 @@ export function createLocalInferenceResolver({
localType = localInference(node.initializer);
if (isOptionalDeclaration(node)) {
localType.typeNode = addUndefinedInUnion(localType.typeNode);
}
}
}
else if (isInterfaceDeclaration(node.parent) || isTypeLiteralNode(node.parent)) {
return factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ function createEmitDeclarationHost(options: TranspileDeclarationsOptions): EmitH
useCaseSensitiveFileNames: () => !!options.useCaseSensitiveFileNames,
getCompilerOptions: () => options.compilerOptions,
getCommonSourceDirectory: () => ensureTrailingDirectorySeparator(options.commonSourceDirectory ?? "."),
redirectTargetsMap: undefined!, // new Map(),
get redirectTargetsMap(): never {
Debug.fail("redirectTargetsMap should not be used in isolated declarations");
return undefined!; // Need return despite fail call GH#52214
},
directoryExists: throws,
fileExists: throws,
readFile: throws,
Expand Down Expand Up @@ -86,7 +89,7 @@ export function transpileDeclaration(sourceFile: SourceFile, transpileOptions: T
addDiagnostic(diag: any) {
diagnostics.push(diag);
},
} as Partial<TransformationContext> as TransformationContext);
} as TransformationContext);
const result = transformer(sourceFile);

const printer = createPrinter({
Expand Down
3 changes: 3 additions & 0 deletions src/harness/_namespaces/fixer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Generated file to emulate the fixer namespace. */

export * from "../isolatedDeclarationFixer";
2 changes: 1 addition & 1 deletion src/harness/isolatedDeclarationFixer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fake from "./_namespaces/fakes";
import * as ts from "./_namespaces/ts";
import * as vfs from "./_namespaces/vfs";
import * as fake from "./fakesHosts";

export const isolatedDeclarationsErrors = new Set([
ts.Diagnostics.Declaration_emit_for_this_file_requires_type_resolution_An_explicit_type_annotation_may_unblock_declaration_emit.code,
Expand Down
3 changes: 3 additions & 0 deletions src/testRunner/_namespaces/fixer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Generated file to emulate the fixer namespace. */

export * from "../../harness/_namespaces/fixer";
4 changes: 2 additions & 2 deletions src/testRunner/compilerRunner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as compiler from "./_namespaces/compiler";
import {
fixTestFiles,
} from "../harness/isolatedDeclarationFixer";
import * as compiler from "./_namespaces/compiler";
} from "./_namespaces/fixer";
import {
Baseline,
Compiler,
Expand Down

0 comments on commit d9328ea

Please sign in to comment.