Skip to content

Commit 7a0061a

Browse files
Remove most direct uses of factory from src/compilers/transformers (microsoft#52957)
1 parent 6fe711f commit 7a0061a

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

src/compiler/transformers/classFields.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import {
4141
Expression,
4242
ExpressionStatement,
4343
ExpressionWithTypeArguments,
44-
factory,
4544
filter,
4645
find,
4746
findComputedPropertyNameCacheAssignment,
@@ -153,6 +152,7 @@ import {
153152
newPrivateEnvironment,
154153
Node,
155154
NodeCheckFlags,
155+
NodeFactory,
156156
nodeIsSynthesized,
157157
ObjectLiteralElement,
158158
OmittedExpression,
@@ -2457,13 +2457,15 @@ export function transformClassFields(context: TransformationContext): (x: Source
24572457
if (privateIdentifierInfo.kind === PrivateIdentifierKind.Field) {
24582458
if (!privateIdentifierInfo.isStatic) {
24592459
return createPrivateInstanceFieldInitializer(
2460+
factory,
24602461
receiver,
24612462
visitNode(property.initializer, initializerVisitor, isExpression),
24622463
privateIdentifierInfo.brandCheckIdentifier
24632464
);
24642465
}
24652466
else {
24662467
return createPrivateStaticFieldInitializer(
2468+
factory,
24672469
privateIdentifierInfo.variableName,
24682470
visitNode(property.initializer, initializerVisitor, isExpression)
24692471
);
@@ -2575,7 +2577,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
25752577
Debug.assert(weakSetName, "weakSetName should be set in private identifier environment");
25762578
statements.push(
25772579
factory.createExpressionStatement(
2578-
createPrivateInstanceMethodInitializer(receiver, weakSetName)
2580+
createPrivateInstanceMethodInitializer(factory, receiver, weakSetName)
25792581
)
25802582
);
25812583
}
@@ -3213,7 +3215,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
32133215
}
32143216
}
32153217

3216-
function createPrivateStaticFieldInitializer(variableName: Identifier, initializer: Expression | undefined) {
3218+
function createPrivateStaticFieldInitializer(factory: NodeFactory, variableName: Identifier, initializer: Expression | undefined) {
32173219
return factory.createAssignment(
32183220
variableName,
32193221
factory.createObjectLiteralExpression([
@@ -3222,15 +3224,15 @@ function createPrivateStaticFieldInitializer(variableName: Identifier, initializ
32223224
);
32233225
}
32243226

3225-
function createPrivateInstanceFieldInitializer(receiver: LeftHandSideExpression, initializer: Expression | undefined, weakMapName: Identifier) {
3227+
function createPrivateInstanceFieldInitializer(factory: NodeFactory, receiver: LeftHandSideExpression, initializer: Expression | undefined, weakMapName: Identifier) {
32263228
return factory.createCallExpression(
32273229
factory.createPropertyAccessExpression(weakMapName, "set"),
32283230
/*typeArguments*/ undefined,
32293231
[receiver, initializer || factory.createVoidZero()]
32303232
);
32313233
}
32323234

3233-
function createPrivateInstanceMethodInitializer(receiver: LeftHandSideExpression, weakSetName: Identifier) {
3235+
function createPrivateInstanceMethodInitializer(factory: NodeFactory, receiver: LeftHandSideExpression, weakSetName: Identifier) {
32343236
return factory.createCallExpression(
32353237
factory.createPropertyAccessExpression(weakSetName, "add"),
32363238
/*typeArguments*/ undefined,

src/compiler/transformers/declarations.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ import {
166166
Node,
167167
NodeArray,
168168
NodeBuilderFlags,
169+
NodeFactory,
169170
NodeFlags,
170171
NodeId,
171172
normalizeSlashes,
@@ -724,7 +725,7 @@ export function transformDeclarations(context: TransformationContext) {
724725
}
725726
const newParam = factory.updateParameterDeclaration(
726727
p,
727-
maskModifiers(p, modifierMask),
728+
maskModifiers(factory, p, modifierMask),
728729
p.dotDotDotToken,
729730
filterBindingPatternInitializersAndRenamings(p.name),
730731
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
@@ -1856,7 +1857,7 @@ function isAlwaysType(node: Node) {
18561857
}
18571858

18581859
// Elide "public" modifier, as it is the default
1859-
function maskModifiers(node: Node, modifierMask?: ModifierFlags, modifierAdditions?: ModifierFlags): Modifier[] | undefined {
1860+
function maskModifiers(factory: NodeFactory, node: Node, modifierMask?: ModifierFlags, modifierAdditions?: ModifierFlags): Modifier[] | undefined {
18601861
return factory.createModifiersFromModifierFlags(maskModifierFlags(node, modifierMask, modifierAdditions));
18611862
}
18621863

src/compiler/transformers/destructuring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
ElementAccessExpression,
1313
every,
1414
Expression,
15-
factory,
1615
forEach,
1716
getElementsOfBindingOrAssignmentPattern,
1817
getInitializerOfBindingOrAssignmentElement,
@@ -543,6 +542,7 @@ function createDefaultValueCheck(flattenContext: FlattenContext, value: Expressi
543542
* @param propertyName The destructuring property name.
544543
*/
545544
function createDestructuringPropertyAccess(flattenContext: FlattenContext, value: Expression, propertyName: PropertyName): LeftHandSideExpression {
545+
const { factory } = flattenContext.context;
546546
if (isComputedPropertyName(propertyName)) {
547547
const argumentExpression = ensureIdentifier(flattenContext, Debug.checkDefined(visitNode(propertyName.expression, flattenContext.visitor, isExpression)), /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
548548
return flattenContext.context.factory.createElementAccessExpression(value, argumentExpression);

src/compiler/transformers/taggedTemplate.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import {
22
CallExpression,
33
Debug,
44
Expression,
5-
factory,
65
getSourceTextOfNodeFromSourceFile,
76
hasInvalidEscape,
87
Identifier,
98
isExpression,
109
isExternalModule,
1110
isNoSubstitutionTemplateLiteral,
11+
NodeFactory,
1212
NoSubstitutionTemplateLiteral,
1313
setTextRange,
1414
SourceFile,
@@ -55,16 +55,18 @@ export function processTaggedTemplateExpression(
5555
return visitEachChild(node, visitor, context);
5656
}
5757

58+
const { factory } = context;
59+
5860
if (isNoSubstitutionTemplateLiteral(template)) {
59-
cookedStrings.push(createTemplateCooked(template));
60-
rawStrings.push(getRawLiteral(template, currentSourceFile));
61+
cookedStrings.push(createTemplateCooked(factory, template));
62+
rawStrings.push(getRawLiteral(factory, template, currentSourceFile));
6163
}
6264
else {
63-
cookedStrings.push(createTemplateCooked(template.head));
64-
rawStrings.push(getRawLiteral(template.head, currentSourceFile));
65+
cookedStrings.push(createTemplateCooked(factory, template.head));
66+
rawStrings.push(getRawLiteral(factory, template.head, currentSourceFile));
6567
for (const templateSpan of template.templateSpans) {
66-
cookedStrings.push(createTemplateCooked(templateSpan.literal));
67-
rawStrings.push(getRawLiteral(templateSpan.literal, currentSourceFile));
68+
cookedStrings.push(createTemplateCooked(factory, templateSpan.literal));
69+
rawStrings.push(getRawLiteral(factory, templateSpan.literal, currentSourceFile));
6870
templateArguments.push(Debug.checkDefined(visitNode(templateSpan.expression, visitor, isExpression)));
6971
}
7072
}
@@ -93,7 +95,7 @@ export function processTaggedTemplateExpression(
9395
return factory.createCallExpression(tag, /*typeArguments*/ undefined, templateArguments);
9496
}
9597

96-
function createTemplateCooked(template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) {
98+
function createTemplateCooked(factory: NodeFactory, template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) {
9799
return template.templateFlags ? factory.createVoidZero() : factory.createStringLiteral(template.text);
98100
}
99101

@@ -102,7 +104,7 @@ function createTemplateCooked(template: TemplateHead | TemplateMiddle | Template
102104
*
103105
* @param node The ES6 template literal.
104106
*/
105-
function getRawLiteral(node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) {
107+
function getRawLiteral(factory: NodeFactory, node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) {
106108
// Find original source text, since we need to emit the raw strings of the tagged template.
107109
// The raw strings contain the (escaped) strings of what the user wrote.
108110
// Examples: `\n` is converted to "\\n", a template string with a newline to "\n".

src/compiler/transformers/typeSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Debug,
1212
EntityName,
1313
Expression,
14-
factory,
1514
findAncestor,
1615
FunctionLikeDeclaration,
1716
getAllAccessorDeclarations,
@@ -137,6 +136,7 @@ export interface RuntimeTypeSerializer {
137136
/** @internal */
138137
export function createRuntimeTypeSerializer(context: TransformationContext): RuntimeTypeSerializer {
139138
const {
139+
factory,
140140
hoistVariableDeclaration
141141
} = context;
142142

0 commit comments

Comments
 (0)