Skip to content

Commit 413881f

Browse files
committed
Ensure emitted d.ts files do not contain extraneous import expressions
These appear to break api-extractor, and we won't have a fix until TS starts to emit d.ts files using `import type { ... }` for imports that aren't explicitly written in the source files.
1 parent cf88621 commit 413881f

24 files changed

+350
-341
lines changed

Diff for: src/compiler/factory/utilities.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import {
22
AccessorDeclaration, addEmitFlags, AdditiveOperator, AdditiveOperatorOrHigher, AssertionLevel,
33
AssignmentOperatorOrHigher, BinaryExpression, BinaryOperator, BinaryOperatorToken, BindingOrAssignmentElement,
44
BindingOrAssignmentElementRestIndicator, BindingOrAssignmentElementTarget, BindingOrAssignmentPattern,
5-
BitwiseOperator, BitwiseOperatorOrHigher, BooleanLiteral, CharacterCodes, CommaListExpression,
5+
BitwiseOperator, BitwiseOperatorOrHigher, Block, BooleanLiteral, CharacterCodes, CommaListExpression,
66
compareStringsCaseSensitive, CompilerOptions, Debug, Declaration, EmitFlags, EmitHelperFactory, EmitHost,
77
EmitResolver, EntityName, EqualityOperator, EqualityOperatorOrHigher, ExclamationToken, ExponentiationOperator,
88
ExportDeclaration, Expression, ExpressionStatement, externalHelpersModuleNameText, first, firstOrUndefined,
99
ForInitializer, GeneratedIdentifier, GeneratedIdentifierFlags, GeneratedNamePart, GeneratedPrivateIdentifier,
10+
GetAccessorDeclaration,
1011
getAllAccessorDeclarations, getEmitFlags, getEmitHelpers, getEmitModuleKind, getESModuleInterop,
1112
getExternalModuleName, getExternalModuleNameFromPath, getJSDocType, getJSDocTypeTag, getModifiers,
1213
getNamespaceDeclarationNode, getOrCreateEmitNode, getOriginalNode, getParseTreeNode,
@@ -26,7 +27,7 @@ import {
2627
NumericLiteral, ObjectLiteralElementLike, ObjectLiteralExpression, or, OuterExpression, OuterExpressionKinds,
2728
outFile, parseNodeFactory, PlusToken, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier,
2829
PropertyAssignment, PropertyDeclaration, PropertyName, pushIfUnique, QuestionToken, ReadonlyKeyword,
29-
RelationalOperator, RelationalOperatorOrHigher, setOriginalNode, setParent, setStartsOnNewLine, setTextRange,
30+
RelationalOperator, RelationalOperatorOrHigher, SetAccessorDeclaration, setOriginalNode, setParent, setStartsOnNewLine, setTextRange,
3031
ShiftOperator, ShiftOperatorOrHigher, ShorthandPropertyAssignment, some, SourceFile, Statement, StringLiteral,
3132
SyntaxKind, TextRange, ThisTypeNode, Token, TypeNode, TypeParameterDeclaration,
3233
} from "../_namespaces/ts";
@@ -185,7 +186,7 @@ export function createForOfBindingStatement(factory: NodeFactory, node: ForIniti
185186
}
186187

187188
/** @internal */
188-
export function insertLeadingStatement(factory: NodeFactory, dest: Statement, source: Statement) {
189+
export function insertLeadingStatement(factory: NodeFactory, dest: Statement, source: Statement): Block {
189190
if (isBlock(dest)) {
190191
return factory.updateBlock(dest, setTextRange(factory.createNodeArray([source, ...dest.statements]), dest.statements));
191192
}
@@ -1456,7 +1457,7 @@ export function createAccessorPropertyBackingField(factory: NodeFactory, node: P
14561457
*
14571458
* @internal
14581459
*/
1459-
export function createAccessorPropertyGetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) {
1460+
export function createAccessorPropertyGetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName): GetAccessorDeclaration {
14601461
return factory.createGetAccessorDeclaration(
14611462
modifiers,
14621463
name,
@@ -1478,7 +1479,7 @@ export function createAccessorPropertyGetRedirector(factory: NodeFactory, node:
14781479
*
14791480
* @internal
14801481
*/
1481-
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) {
1482+
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName): SetAccessorDeclaration {
14821483
return factory.createSetAccessorDeclaration(
14831484
modifiers,
14841485
name,

Diff for: src/compiler/transformers/classFields.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
startOnNewLine, Statement, SuperProperty, SyntaxKind, TaggedTemplateExpression, ThisExpression,
3434
TransformationContext, TransformFlags, tryGetTextOfPropertyName, UnderscoreEscapedMap, unescapeLeadingUnderscores,
3535
VariableStatement, visitArray, visitEachChild, visitFunctionBody, visitIterationBody, visitNode, visitNodes,
36-
visitParameterList, VisitResult,
36+
visitParameterList, VisitResult, Bundle,
3737
} from "../_namespaces/ts";
3838

3939
const enum ClassPropertySubstitutionFlags {
@@ -168,7 +168,7 @@ const enum ClassFacts {
168168
*
169169
* @internal
170170
*/
171-
export function transformClassFields(context: TransformationContext) {
171+
export function transformClassFields(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
172172
const {
173173
factory,
174174
hoistVariableDeclaration,

Diff for: src/compiler/transformers/es2015.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
SyntaxKind, TaggedTemplateExpression, takeWhile, TemplateExpression, TextRange, TokenFlags, TransformationContext,
3434
TransformFlags, tryCast, unescapeLeadingUnderscores, unwrapInnermostStatementOfLabel, VariableDeclaration,
3535
VariableDeclarationList, VariableStatement, visitEachChild, visitNode, visitNodes, visitParameterList, VisitResult,
36-
VoidExpression, WhileStatement, YieldExpression,
36+
VoidExpression, WhileStatement, YieldExpression, Bundle,
3737
} from "../_namespaces/ts";
3838

3939
const enum ES2015SubstitutionFlags {
@@ -299,7 +299,7 @@ function createSpreadSegment(kind: SpreadSegmentKind, expression: Expression): S
299299
}
300300

301301
/** @internal */
302-
export function transformES2015(context: TransformationContext) {
302+
export function transformES2015(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
303303
const {
304304
factory,
305305
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/es2016.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
2-
BinaryExpression, chainBundle, Expression, isElementAccessExpression, isExpression, isPropertyAccessExpression,
2+
BinaryExpression, Bundle, chainBundle, Expression, isElementAccessExpression, isExpression, isPropertyAccessExpression,
33
Node, setTextRange, SourceFile, SyntaxKind, TransformationContext, TransformFlags, visitEachChild, visitNode,
44
VisitResult,
55
} from "../_namespaces/ts";
66

77
/** @internal */
8-
export function transformES2016(context: TransformationContext) {
8+
export function transformES2016(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
99
const {
1010
factory,
1111
hoistVariableDeclaration

Diff for: src/compiler/transformers/es2017.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
TypeReferenceSerializationKind, unescapeLeadingUnderscores, VariableDeclaration, VariableDeclarationList,
1616
VariableStatement, visitEachChild, visitFunctionBody, visitIterationBody, visitNode, visitNodes, visitParameterList,
1717
VisitResult,
18+
Bundle,
1819
} from "../_namespaces/ts";
1920

2021
type SuperContainer = ClassDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ConstructorDeclaration;
@@ -30,7 +31,7 @@ const enum ContextFlags {
3031
}
3132

3233
/** @internal */
33-
export function transformES2017(context: TransformationContext) {
34+
export function transformES2017(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
3435
const {
3536
factory,
3637
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/es2018.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
SourceFile, startOnNewLine, Statement, SyntaxKind, TaggedTemplateExpression, TextRange, Token,
1818
TransformationContext, TransformFlags, unwrapInnermostStatementOfLabel, VariableDeclaration, VariableStatement,
1919
visitEachChild, visitIterationBody, visitLexicalEnvironment, visitNode, visitNodes, visitParameterList, VisitResult,
20-
VoidExpression, YieldExpression,
20+
VoidExpression, YieldExpression, Bundle,
2121
} from "../_namespaces/ts";
2222

2323
const enum ESNextSubstitutionFlags {
@@ -58,7 +58,7 @@ const enum HierarchyFacts {
5858
}
5959

6060
/** @internal */
61-
export function transformES2018(context: TransformationContext) {
61+
export function transformES2018(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
6262
const {
6363
factory,
6464
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/es2019.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import {
2+
Bundle,
23
CatchClause, chainBundle, isBlock, Node, SourceFile, SyntaxKind, TransformationContext, TransformFlags,
34
visitEachChild, visitNode, VisitResult,
45
} from "../_namespaces/ts";
56

67
/** @internal */
7-
export function transformES2019(context: TransformationContext) {
8+
export function transformES2019(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
89
const factory = context.factory;
910
return chainBundle(context, transformSourceFile);
1011

Diff for: src/compiler/transformers/es2020.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AccessExpression, addEmitFlags, BinaryExpression, CallExpression, cast, chainBundle, Debug, DeleteExpression,
2+
AccessExpression, addEmitFlags, BinaryExpression, Bundle, CallExpression, cast, chainBundle, Debug, DeleteExpression,
33
EmitFlags, Expression, isCallChain, isExpression, isGeneratedIdentifier, isIdentifier, isNonNullChain,
44
isOptionalChain, isParenthesizedExpression, isSimpleCopiableExpression, isSyntheticReference,
55
isTaggedTemplateExpression, Node, OptionalChain, OuterExpressionKinds, ParenthesizedExpression, setOriginalNode,
@@ -8,7 +8,7 @@ import {
88
} from "../_namespaces/ts";
99

1010
/** @internal */
11-
export function transformES2020(context: TransformationContext) {
11+
export function transformES2020(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1212
const {
1313
factory,
1414
hoistVariableDeclaration,

Diff for: src/compiler/transformers/es2021.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
AssignmentExpression, BinaryExpression, chainBundle, getNonAssignmentOperatorForCompoundAssignment,
2+
AssignmentExpression, BinaryExpression, Bundle, chainBundle, getNonAssignmentOperatorForCompoundAssignment,
33
isAccessExpression, isExpression, isLeftHandSideExpression, isLogicalOrCoalescingAssignmentExpression,
44
isPropertyAccessExpression, isSimpleCopiableExpression, LogicalOrCoalescingAssignmentOperator, Node,
55
skipParentheses, SourceFile, SyntaxKind, Token, TransformationContext, TransformFlags, visitEachChild, visitNode,
66
VisitResult,
77
} from "../_namespaces/ts";
88

99
/** @internal */
10-
export function transformES2021(context: TransformationContext) {
10+
export function transformES2021(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1111
const {
1212
hoistVariableDeclaration,
1313
factory

Diff for: src/compiler/transformers/es5.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Bundle,
23
chainBundle, EmitHint, Expression, getOriginalNodeId, Identifier, idText, isIdentifier, isPrivateIdentifier,
34
isPropertyAccessExpression, isPropertyAssignment, JsxClosingElement, JsxEmit, JsxOpeningElement,
45
JsxSelfClosingElement, Node, nodeIsSynthesized, PropertyAccessExpression, PropertyAssignment, setTextRange,
@@ -12,7 +13,7 @@ import {
1213
*
1314
* @internal
1415
*/
15-
export function transformES5(context: TransformationContext) {
16+
export function transformES5(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1617
const { factory } = context;
1718
const compilerOptions = context.getCompilerOptions();
1819

Diff for: src/compiler/transformers/esnext.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {
2+
Bundle,
23
chainBundle, Node, SourceFile, TransformationContext, TransformFlags, visitEachChild, VisitResult,
34
} from "../_namespaces/ts";
45

56
/** @internal */
6-
export function transformESNext(context: TransformationContext) {
7+
export function transformESNext(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
78
return chainBundle(context, transformSourceFile);
89

910
function transformSourceFile(node: SourceFile) {

Diff for: src/compiler/transformers/generators.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
AccessorDeclaration, addEmitHelpers, addSyntheticTrailingComment, ArrayLiteralExpression, Associativity,
3-
BinaryExpression, Block, BreakStatement, CallExpression, CaseClause, chainBundle, CommaListExpression,
3+
BinaryExpression, Block, BreakStatement, Bundle, CallExpression, CaseClause, chainBundle, CommaListExpression,
44
ConditionalExpression, ContinueStatement, createExpressionForObjectLiteralElementLike, Debug, DoStatement,
55
ElementAccessExpression, EmitFlags, EmitHint, ESMap, Expression, ExpressionStatement, forEach, ForInStatement,
66
ForStatement, FunctionDeclaration, FunctionExpression, getEmitFlags, getEmitScriptTarget,
@@ -247,7 +247,7 @@ function getInstructionName(instruction: Instruction): string {
247247
}
248248

249249
/** @internal */
250-
export function transformGenerators(context: TransformationContext) {
250+
export function transformGenerators(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
251251
const {
252252
factory,
253253
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/jsx.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
addEmitHelpers, arrayFrom, chainBundle, createExpressionForJsxElement, createExpressionForJsxFragment,
2+
addEmitHelpers, arrayFrom, Bundle, chainBundle, createExpressionForJsxElement, createExpressionForJsxFragment,
33
createExpressionFromEntityName, createJsxFactoryExpression, Debug, emptyArray, Expression, filter, find, flatten,
44
GeneratedIdentifierFlags, getEmitScriptTarget, getEntries, getJSXImplicitImportBase, getJSXRuntimeImport,
55
getLineAndCharacterOfPosition, getOriginalNode, getSemanticJsxChildren, Identifier, idText, ImportSpecifier,
@@ -14,7 +14,7 @@ import {
1414
} from "../_namespaces/ts";
1515

1616
/** @internal */
17-
export function transformJsx(context: TransformationContext) {
17+
export function transformJsx(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1818
interface PerFileState {
1919
importSpecifier?: string;
2020
filenameDeclaration?: VariableDeclaration & { name: Identifier; };

Diff for: src/compiler/transformers/legacyDecorators.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
addEmitHelpers, addRange, AllDecorators, append, canHaveDecorators, chainBundle, childIsDecorated, ClassDeclaration,
2+
addEmitHelpers, addRange, AllDecorators, append, Bundle, canHaveDecorators, chainBundle, childIsDecorated, ClassDeclaration,
33
ClassElement, ClassExpression, ClassLikeDeclaration, classOrConstructorParameterIsDecorated, ConstructorDeclaration,
44
Decorator, elideNodes, EmitFlags, EmitHint, EnumMember, Expression, filter, flatMap, GetAccessorDeclaration,
55
getAllDecoratorsOfClass, getAllDecoratorsOfClassElement, getEmitFlags, getEmitScriptTarget, getOriginalNodeId,
@@ -14,7 +14,7 @@ import {
1414
} from "../_namespaces/ts";
1515

1616
/** @internal */
17-
export function transformLegacyDecorators(context: TransformationContext) {
17+
export function transformLegacyDecorators(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1818
const {
1919
factory,
2020
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/module/esnextAnd2015.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
addRange, append, chainBundle, createEmptyExports, createExternalHelpersImportDeclarationIfNeeded, Debug, EmitFlags,
2+
addRange, append, Bundle, chainBundle, createEmptyExports, createExternalHelpersImportDeclarationIfNeeded, Debug, EmitFlags,
33
EmitHint, ESMap, ExportAssignment, ExportDeclaration, Expression, GeneratedIdentifierFlags, getEmitFlags,
44
getEmitModuleKind, getEmitScriptTarget, getExternalModuleNameLiteral, hasSyntacticModifier, Identifier, idText,
55
ImportDeclaration, ImportEqualsDeclaration, insertStatementsAfterCustomPrologue,
@@ -10,7 +10,7 @@ import {
1010
} from "../../_namespaces/ts";
1111

1212
/** @internal */
13-
export function transformECMAScriptModule(context: TransformationContext) {
13+
export function transformECMAScriptModule(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1414
const {
1515
factory,
1616
getEmitHelperFactory: emitHelpers,

Diff for: src/compiler/transformers/module/module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
addEmitFlags, addEmitHelper, addEmitHelpers, addRange, append, ArrowFunction, BinaryExpression, BindingElement,
3+
Bundle,
34
CallExpression, chainBundle, ClassDeclaration, collectExternalModuleInfo, Debug, Declaration,
45
DestructuringAssignment, EmitFlags, EmitHelper, EmitHint, emptyArray, EndOfDeclarationMarker, ExportAssignment,
56
ExportDeclaration, Expression, ExpressionStatement, ExternalModuleInfo, firstOrUndefined,
@@ -27,7 +28,7 @@ import {
2728
} from "../../_namespaces/ts";
2829

2930
/** @internal */
30-
export function transformModule(context: TransformationContext) {
31+
export function transformModule(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
3132
interface AsynchronousDependencies {
3233
aliasedModuleNames: Expression[];
3334
unaliasedModuleNames: Expression[];

Diff for: src/compiler/transformers/module/system.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
addRange, append, BinaryExpression, BindingElement, Block, CaseBlock, CaseClause, CaseOrDefaultClause, CatchClause,
2+
addRange, append, BinaryExpression, BindingElement, Block, Bundle, CaseBlock, CaseClause, CaseOrDefaultClause, CatchClause,
33
chainBundle, ClassDeclaration, collectExternalModuleInfo, Debug, Declaration, DefaultClause,
44
DestructuringAssignment, DoStatement, EmitFlags, EmitHint, EndOfDeclarationMarker, ExportAssignment,
55
ExportDeclaration, Expression, ExpressionStatement, ExternalModuleInfo, firstOrUndefined,
@@ -25,7 +25,7 @@ import {
2525
} from "../../_namespaces/ts";
2626

2727
/** @internal */
28-
export function transformSystemModule(context: TransformationContext) {
28+
export function transformSystemModule(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
2929
interface DependencyGroup {
3030
name: StringLiteral;
3131
externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[];

Diff for: src/compiler/transformers/taggedTemplate.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CallExpression,
23
Debug, Expression, factory, getSourceTextOfNodeFromSourceFile, hasInvalidEscape, Identifier, isExpression,
34
isExternalModule, isNoSubstitutionTemplateLiteral, NoSubstitutionTemplateLiteral, setTextRange, SourceFile,
45
SyntaxKind, TaggedTemplateExpression, TemplateHead, TemplateLiteralLikeNode, TemplateMiddle, TemplateTail,
@@ -18,7 +19,7 @@ export function processTaggedTemplateExpression(
1819
visitor: Visitor,
1920
currentSourceFile: SourceFile,
2021
recordTaggedTemplateString: (temp: Identifier) => void,
21-
level: ProcessLevel) {
22+
level: ProcessLevel): TaggedTemplateExpression | CallExpression {
2223

2324
// Visit the tag expression
2425
const tag = visitNode(node.tag, visitor, isExpression);

Diff for: src/compiler/transformers/utilities.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
isPrivateIdentifier, isPropertyDeclaration, isStatic, isStringLiteralLike, isSuperCall, LogicalOperatorOrHigher,
1313
map, Map, MethodDeclaration, ModifierFlags, NamedImportBindings, NamespaceExport, Node, NodeArray,
1414
parameterIsThisKeyword, PrivateIdentifierAccessorDeclaration, PrivateIdentifierAutoAccessorPropertyDeclaration,
15-
PrivateIdentifierMethodDeclaration, PropertyDeclaration, skipParentheses, some, SourceFile, Statement, SyntaxKind,
15+
PrivateIdentifierMethodDeclaration, PropertyDeclaration, skipParentheses, some, SourceFile, Statement, SuperCall, SyntaxKind,
1616
TransformationContext, VariableDeclaration, VariableStatement,
1717
} from "../_namespaces/ts";
1818

@@ -332,7 +332,7 @@ export function getNonAssignmentOperatorForCompoundAssignment(kind: CompoundAssi
332332
*
333333
* @internal
334334
*/
335-
export function getSuperCallFromStatement(statement: Statement) {
335+
export function getSuperCallFromStatement(statement: Statement): SuperCall | undefined {
336336
if (!isExpressionStatement(statement)) {
337337
return undefined;
338338
}

0 commit comments

Comments
 (0)