Skip to content

Commit bb294f7

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 0b8b109 commit bb294f7

24 files changed

+351
-342
lines changed

src/compiler/factory/utilities.ts

Lines changed: 6 additions & 5 deletions
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
}
@@ -1435,7 +1436,7 @@ export function createAccessorPropertyBackingField(factory: NodeFactory, node: P
14351436
/**
14361437
* Creates a {@link GetAccessorDeclaration} that reads from a private backing field.
14371438
*/
1438-
export function createAccessorPropertyGetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) {
1439+
export function createAccessorPropertyGetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName): GetAccessorDeclaration {
14391440
return factory.createGetAccessorDeclaration(
14401441
modifiers,
14411442
name,
@@ -1456,7 +1457,7 @@ export function createAccessorPropertyGetRedirector(factory: NodeFactory, node:
14561457
/**
14571458
* Creates a {@link SetAccessorDeclaration} that writes to a private backing field.
14581459
*/
1459-
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName) {
1460+
export function createAccessorPropertySetRedirector(factory: NodeFactory, node: PropertyDeclaration, modifiers: ModifiersArray | undefined, name: PropertyName): SetAccessorDeclaration {
14601461
return factory.createSetAccessorDeclaration(
14611462
modifiers,
14621463
name,

src/compiler/transformers/classFields.ts

Lines changed: 2 additions & 2 deletions
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 {
@@ -167,7 +167,7 @@ const enum ClassFacts {
167167
* where declarations are elided and initializers are transformed as assignments in the constructor.
168168
* When --useDefineForClassFields is on, this transforms to ECMAScript semantics, with Object.defineProperty.
169169
*/
170-
export function transformClassFields(context: TransformationContext) {
170+
export function transformClassFields(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
171171
const {
172172
factory,
173173
hoistVariableDeclaration,

src/compiler/transformers/es2015.ts

Lines changed: 2 additions & 2 deletions
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,

src/compiler/transformers/es2016.ts

Lines changed: 2 additions & 2 deletions
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

src/compiler/transformers/es2017.ts

Lines changed: 2 additions & 1 deletion
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,

src/compiler/transformers/es2018.ts

Lines changed: 2 additions & 2 deletions
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,

src/compiler/transformers/es2019.ts

Lines changed: 2 additions & 1 deletion
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

src/compiler/transformers/es2020.ts

Lines changed: 2 additions & 2 deletions
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,

src/compiler/transformers/es2021.ts

Lines changed: 2 additions & 2 deletions
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

src/compiler/transformers/es5.ts

Lines changed: 2 additions & 1 deletion
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,
@@ -11,7 +12,7 @@ import {
1112
*
1213
* @param context Context and state information for the transformation.
1314
*/
14-
export function transformES5(context: TransformationContext) {
15+
export function transformES5(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
1516
const { factory } = context;
1617
const compilerOptions = context.getCompilerOptions();
1718

0 commit comments

Comments
 (0)