Skip to content

Commit d9328ea

Browse files
Merge pull request #123 from bloomberg/isolated-declarations-pr-review
Fixed imports to use namespace imports. Other minor fixes
2 parents c0831c2 + 7067307 commit d9328ea

File tree

10 files changed

+162
-161
lines changed

10 files changed

+162
-161
lines changed

src/compiler/_namespaces/ts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export * from "../transformers/declarations/diagnostics";
6060
export * from "../transformers/declarations/emitBinder";
6161
export * from "../transformers/declarations/emitResolver";
6262
export * from "../transformers/declarations/transpileDeclaration";
63+
export * from "../transformers/declarations/localInferenceResolver";
6364
export * from "../transformers/declarations/types";
6465
export * from "../transformers/declarations";
6566
export * from "../transformer";

src/compiler/transformers/declarations.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
createEmptyExports,
2929
createGetSymbolAccessibilityDiagnosticForNode,
3030
createGetSymbolAccessibilityDiagnosticForNodeName,
31+
createLocalInferenceResolver,
3132
createSymbolTable,
3233
createUnparsedSourceFile,
3334
Debug,
@@ -165,6 +166,7 @@ import {
165166
LateBoundDeclaration,
166167
LateVisibilityPaintedStatement,
167168
length,
169+
LocalInferenceResolver,
168170
map,
169171
mapDefined,
170172
MethodDeclaration,
@@ -238,10 +240,6 @@ import {
238240
VisitResult,
239241
} from "../_namespaces/ts";
240242
import * as moduleSpecifiers from "../_namespaces/ts.moduleSpecifiers";
241-
import {
242-
createLocalInferenceResolver,
243-
LocalInferenceResolver,
244-
} from "./declarations/localInferenceResolver";
245243

246244
/** @internal */
247245
export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined {

src/compiler/transformers/declarations/emitBinder.ts

Lines changed: 102 additions & 94 deletions
Large diffs are not rendered by default.

src/compiler/transformers/declarations/emitResolver.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import {
22
appendIfUnique,
3+
bindSourceFileForDeclarationEmit,
34
ComputedPropertyName,
45
createEvaluator,
56
Debug,
67
Declaration,
78
DeclarationName,
89
determineIfDeclarationIsVisible,
910
ElementAccessExpression,
11+
EmitDeclarationNodeLinks,
12+
EmitDeclarationSymbol,
1013
emptyArray,
1114
EntityNameOrEntityNameExpression,
1215
EnumDeclaration,
@@ -21,6 +24,7 @@ import {
2124
FunctionLikeDeclaration,
2225
getAnyImportSyntax,
2326
getFirstIdentifier,
27+
getMemberKey,
2428
getNameOfDeclaration,
2529
getParseTreeNode,
2630
getTextOfNode,
@@ -46,6 +50,7 @@ import {
4650
isInJSFile,
4751
isLateVisibilityPaintedStatement,
4852
isNumericLiteral,
53+
IsolatedEmitResolver,
4954
isPartOfTypeNode,
5055
isPrefixUnaryExpression,
5156
isPropertyAccessExpression,
@@ -78,15 +83,8 @@ import {
7883
SyntaxKind,
7984
VariableDeclaration,
8085
} from "../../_namespaces/ts";
81-
import {
82-
bindSourceFileForDeclarationEmit,
83-
EmitDeclarationNodeLinks,
84-
EmitDeclarationSymbol,
85-
getMemberKey,
86-
} from "./emitBinder";
87-
import {
88-
IsolatedEmitResolver,
89-
} from "./types";
86+
87+
9088

9189
/** @internal */
9290
export function createEmitDeclarationResolver(file: SourceFile): IsolatedEmitResolver {

src/compiler/transformers/declarations/localInferenceResolver.ts

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import {
2+
ArrayLiteralExpression,
3+
ArrowFunction,
4+
AsExpression,
5+
ClassExpression,
6+
createDiagnosticForNode,
7+
createPropertyNameNodeForIdentifierOrLiteral,
8+
DiagnosticMessage,
9+
Diagnostics,
10+
EntityNameOrEntityNameExpression,
11+
ExportAssignment,
12+
FunctionExpression,
13+
GetAccessorDeclaration,
214
getCommentRange,
15+
getEmitScriptTarget,
316
getMemberKeyFromElement,
4-
setCommentRange,
5-
} from "../../_namespaces/ts";
6-
import {
7-
Diagnostics,
8-
} from "../../diagnosticInformationMap.generated";
9-
import {
17+
HasInferredType,
18+
hasSyntacticModifier,
19+
Identifier,
1020
isClassExpression,
1121
isComputedPropertyName,
22+
isConstTypeReference,
23+
isEntityNameExpression,
1224
isExportAssignment,
1325
isGetAccessorDeclaration,
1426
isIdentifier,
@@ -18,83 +30,55 @@ import {
1830
isNoSubstitutionTemplateLiteral,
1931
isNumericLiteral,
2032
isOmittedExpression,
33+
isOptionalDeclaration,
2134
isParameter,
2235
isPrefixUnaryExpression,
2336
isPrivateIdentifier,
2437
isPropertyAssignment,
2538
isPropertyDeclaration,
39+
isPropertyName,
2640
isSetAccessorDeclaration,
2741
isShorthandPropertyAssignment,
2842
isSpreadAssignment,
2943
isSpreadElement,
44+
isStringDoubleQuoted,
3045
isStringLiteral,
46+
isStringLiteralLike,
3147
isTypeLiteralNode,
48+
isTypeNode,
3249
isTypeParameterDeclaration,
3350
isTypeReferenceNode,
3451
isUnionTypeNode,
3552
isVariableDeclaration,
36-
} from "../../factory/nodeTests";
37-
import {
38-
setTextRange,
39-
} from "../../factory/utilitiesPublic";
40-
import {
41-
nullTransformationContext,
42-
} from "../../transformer";
43-
import {
44-
ArrayLiteralExpression,
45-
ArrowFunction,
46-
AsExpression,
47-
ClassExpression,
48-
DiagnosticMessage,
49-
EntityNameOrEntityNameExpression,
50-
ExportAssignment,
51-
FunctionExpression,
52-
GetAccessorDeclaration,
53-
HasInferredType,
54-
Identifier,
5553
KeywordTypeSyntaxKind,
5654
LiteralExpression,
5755
MethodDeclaration,
5856
ModifierFlags,
5957
Node,
6058
NodeArray,
6159
NodeFlags,
60+
nullTransformationContext,
6261
ObjectLiteralExpression,
6362
ParameterDeclaration,
6463
ParenthesizedExpression,
6564
PrefixUnaryExpression,
6665
PropertyName,
6766
SetAccessorDeclaration,
67+
setCommentRange,
68+
setTextRange,
6869
SourceFile,
6970
SyntaxKind,
7071
TransformationContext,
7172
TypeAssertion,
7273
TypeElement,
7374
TypeNode,
74-
Visitor,
75-
VisitResult,
76-
} from "../../types";
77-
import {
78-
createDiagnosticForNode,
79-
createPropertyNameNodeForIdentifierOrLiteral,
80-
getEmitScriptTarget,
81-
hasSyntacticModifier,
82-
isEntityNameExpression,
83-
isOptionalDeclaration,
84-
isStringDoubleQuoted,
85-
} from "../../utilities";
86-
import {
87-
isConstTypeReference,
88-
isPropertyName,
89-
isStringLiteralLike,
90-
isTypeNode,
9175
unescapeLeadingUnderscores,
92-
} from "../../utilitiesPublic";
93-
import {
9476
visitEachChild,
9577
visitNode,
9678
visitNodes,
97-
} from "../../visitorPublic";
79+
Visitor,
80+
VisitResult,
81+
} from "../../_namespaces/ts";
9882

9983
enum NarrowBehavior {
10084
None = 0,
@@ -115,6 +99,9 @@ export interface LocalInferenceResolver {
11599
makeInvalidType(): Node;
116100
fromInitializer(node: HasInferredType | ExportAssignment, type: TypeNode | undefined, sourceFile: SourceFile): TypeNode;
117101
}
102+
/**
103+
* @internal
104+
*/
118105
export function createLocalInferenceResolver({
119106
setEnclosingDeclarations,
120107
visitDeclarationSubtree,
@@ -696,15 +683,15 @@ export function createLocalInferenceResolver({
696683
* function x(o = "", v: string)
697684
*/
698685
if (node.initializer && !isOptional) {
699-
localType.typeNode = addUndefinedInUnion(localType.typeNode);
700-
}
686+
localType.typeNode = addUndefinedInUnion(localType.typeNode);
687+
}
701688
/**
702689
* Constructor properties that are optional must have | undefined included to work well with exactOptionalPropertyTypes
703690
* constructor(public x?: number) -> x?: number | undefined
704691
*/
705692
if (isOptional && !node.initializer && hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
706693
localType.typeNode = addUndefinedInUnion(localType.typeNode);
707-
}
694+
}
708695
}
709696
}
710697
else if (type) {
@@ -732,7 +719,7 @@ export function createLocalInferenceResolver({
732719
localType = localInference(node.initializer);
733720
if (isOptionalDeclaration(node)) {
734721
localType.typeNode = addUndefinedInUnion(localType.typeNode);
735-
}
722+
}
736723
}
737724
else if (isInterfaceDeclaration(node.parent) || isTypeLiteralNode(node.parent)) {
738725
return factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);

src/compiler/transformers/declarations/transpileDeclaration.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ function createEmitDeclarationHost(options: TranspileDeclarationsOptions): EmitH
4040
useCaseSensitiveFileNames: () => !!options.useCaseSensitiveFileNames,
4141
getCompilerOptions: () => options.compilerOptions,
4242
getCommonSourceDirectory: () => ensureTrailingDirectorySeparator(options.commonSourceDirectory ?? "."),
43-
redirectTargetsMap: undefined!, // new Map(),
43+
get redirectTargetsMap(): never {
44+
Debug.fail("redirectTargetsMap should not be used in isolated declarations");
45+
return undefined!; // Need return despite fail call GH#52214
46+
},
4447
directoryExists: throws,
4548
fileExists: throws,
4649
readFile: throws,
@@ -86,7 +89,7 @@ export function transpileDeclaration(sourceFile: SourceFile, transpileOptions: T
8689
addDiagnostic(diag: any) {
8790
diagnostics.push(diag);
8891
},
89-
} as Partial<TransformationContext> as TransformationContext);
92+
} as TransformationContext);
9093
const result = transformer(sourceFile);
9194

9295
const printer = createPrinter({

src/harness/_namespaces/fixer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Generated file to emulate the fixer namespace. */
2+
3+
export * from "../isolatedDeclarationFixer";

src/harness/isolatedDeclarationFixer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as fake from "./_namespaces/fakes";
12
import * as ts from "./_namespaces/ts";
23
import * as vfs from "./_namespaces/vfs";
3-
import * as fake from "./fakesHosts";
44

55
export const isolatedDeclarationsErrors = new Set([
66
ts.Diagnostics.Declaration_emit_for_this_file_requires_type_resolution_An_explicit_type_annotation_may_unblock_declaration_emit.code,

src/testRunner/_namespaces/fixer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Generated file to emulate the fixer namespace. */
2+
3+
export * from "../../harness/_namespaces/fixer";

src/testRunner/compilerRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import * as compiler from "./_namespaces/compiler";
12
import {
23
fixTestFiles,
3-
} from "../harness/isolatedDeclarationFixer";
4-
import * as compiler from "./_namespaces/compiler";
4+
} from "./_namespaces/fixer";
55
import {
66
Baseline,
77
Compiler,

0 commit comments

Comments
 (0)