Skip to content

Remove most direct uses of factory from src/compilers/transformers #52957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/compiler/transformers/classFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {
Expression,
ExpressionStatement,
ExpressionWithTypeArguments,
factory,
filter,
find,
findComputedPropertyNameCacheAssignment,
Expand Down Expand Up @@ -153,6 +152,7 @@ import {
newPrivateEnvironment,
Node,
NodeCheckFlags,
NodeFactory,
nodeIsSynthesized,
ObjectLiteralElement,
OmittedExpression,
Expand Down Expand Up @@ -2457,13 +2457,15 @@ export function transformClassFields(context: TransformationContext): (x: Source
if (privateIdentifierInfo.kind === PrivateIdentifierKind.Field) {
if (!privateIdentifierInfo.isStatic) {
return createPrivateInstanceFieldInitializer(
factory,
receiver,
visitNode(property.initializer, initializerVisitor, isExpression),
privateIdentifierInfo.brandCheckIdentifier
);
}
else {
return createPrivateStaticFieldInitializer(
factory,
privateIdentifierInfo.variableName,
visitNode(property.initializer, initializerVisitor, isExpression)
);
Expand Down Expand Up @@ -2575,7 +2577,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
Debug.assert(weakSetName, "weakSetName should be set in private identifier environment");
statements.push(
factory.createExpressionStatement(
createPrivateInstanceMethodInitializer(receiver, weakSetName)
createPrivateInstanceMethodInitializer(factory, receiver, weakSetName)
)
);
}
Expand Down Expand Up @@ -3213,7 +3215,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
}
}

function createPrivateStaticFieldInitializer(variableName: Identifier, initializer: Expression | undefined) {
function createPrivateStaticFieldInitializer(factory: NodeFactory, variableName: Identifier, initializer: Expression | undefined) {
return factory.createAssignment(
variableName,
factory.createObjectLiteralExpression([
Expand All @@ -3222,15 +3224,15 @@ function createPrivateStaticFieldInitializer(variableName: Identifier, initializ
);
}

function createPrivateInstanceFieldInitializer(receiver: LeftHandSideExpression, initializer: Expression | undefined, weakMapName: Identifier) {
function createPrivateInstanceFieldInitializer(factory: NodeFactory, receiver: LeftHandSideExpression, initializer: Expression | undefined, weakMapName: Identifier) {
return factory.createCallExpression(
factory.createPropertyAccessExpression(weakMapName, "set"),
/*typeArguments*/ undefined,
[receiver, initializer || factory.createVoidZero()]
);
}

function createPrivateInstanceMethodInitializer(receiver: LeftHandSideExpression, weakSetName: Identifier) {
function createPrivateInstanceMethodInitializer(factory: NodeFactory, receiver: LeftHandSideExpression, weakSetName: Identifier) {
return factory.createCallExpression(
factory.createPropertyAccessExpression(weakSetName, "add"),
/*typeArguments*/ undefined,
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import {
Node,
NodeArray,
NodeBuilderFlags,
NodeFactory,
NodeFlags,
NodeId,
normalizeSlashes,
Expand Down Expand Up @@ -724,7 +725,7 @@ export function transformDeclarations(context: TransformationContext) {
}
const newParam = factory.updateParameterDeclaration(
p,
maskModifiers(p, modifierMask),
maskModifiers(factory, p, modifierMask),
p.dotDotDotToken,
filterBindingPatternInitializersAndRenamings(p.name),
resolver.isOptionalParameter(p) ? (p.questionToken || factory.createToken(SyntaxKind.QuestionToken)) : undefined,
Expand Down Expand Up @@ -1856,7 +1857,7 @@ function isAlwaysType(node: Node) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/destructuring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ElementAccessExpression,
every,
Expression,
factory,
forEach,
getElementsOfBindingOrAssignmentPattern,
getInitializerOfBindingOrAssignmentElement,
Expand Down Expand Up @@ -543,6 +542,7 @@ function createDefaultValueCheck(flattenContext: FlattenContext, value: Expressi
* @param propertyName The destructuring property name.
*/
function createDestructuringPropertyAccess(flattenContext: FlattenContext, value: Expression, propertyName: PropertyName): LeftHandSideExpression {
const { factory } = flattenContext.context;
if (isComputedPropertyName(propertyName)) {
const argumentExpression = ensureIdentifier(flattenContext, Debug.checkDefined(visitNode(propertyName.expression, flattenContext.visitor, isExpression)), /*reuseIdentifierExpressions*/ false, /*location*/ propertyName);
return flattenContext.context.factory.createElementAccessExpression(value, argumentExpression);
Expand Down
20 changes: 11 additions & 9 deletions src/compiler/transformers/taggedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {
CallExpression,
Debug,
Expression,
factory,
getSourceTextOfNodeFromSourceFile,
hasInvalidEscape,
Identifier,
isExpression,
isExternalModule,
isNoSubstitutionTemplateLiteral,
NodeFactory,
NoSubstitutionTemplateLiteral,
setTextRange,
SourceFile,
Expand Down Expand Up @@ -55,16 +55,18 @@ export function processTaggedTemplateExpression(
return visitEachChild(node, visitor, context);
}

const { factory } = context;

if (isNoSubstitutionTemplateLiteral(template)) {
cookedStrings.push(createTemplateCooked(template));
rawStrings.push(getRawLiteral(template, currentSourceFile));
cookedStrings.push(createTemplateCooked(factory, template));
rawStrings.push(getRawLiteral(factory, template, currentSourceFile));
}
else {
cookedStrings.push(createTemplateCooked(template.head));
rawStrings.push(getRawLiteral(template.head, currentSourceFile));
cookedStrings.push(createTemplateCooked(factory, template.head));
rawStrings.push(getRawLiteral(factory, template.head, currentSourceFile));
for (const templateSpan of template.templateSpans) {
cookedStrings.push(createTemplateCooked(templateSpan.literal));
rawStrings.push(getRawLiteral(templateSpan.literal, currentSourceFile));
cookedStrings.push(createTemplateCooked(factory, templateSpan.literal));
rawStrings.push(getRawLiteral(factory, templateSpan.literal, currentSourceFile));
templateArguments.push(Debug.checkDefined(visitNode(templateSpan.expression, visitor, isExpression)));
}
}
Expand Down Expand Up @@ -93,7 +95,7 @@ export function processTaggedTemplateExpression(
return factory.createCallExpression(tag, /*typeArguments*/ undefined, templateArguments);
}

function createTemplateCooked(template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) {
function createTemplateCooked(factory: NodeFactory, template: TemplateHead | TemplateMiddle | TemplateTail | NoSubstitutionTemplateLiteral) {
return template.templateFlags ? factory.createVoidZero() : factory.createStringLiteral(template.text);
}

Expand All @@ -102,7 +104,7 @@ function createTemplateCooked(template: TemplateHead | TemplateMiddle | Template
*
* @param node The ES6 template literal.
*/
function getRawLiteral(node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) {
function getRawLiteral(factory: NodeFactory, node: TemplateLiteralLikeNode, currentSourceFile: SourceFile) {
// Find original source text, since we need to emit the raw strings of the tagged template.
// The raw strings contain the (escaped) strings of what the user wrote.
// Examples: `\n` is converted to "\\n", a template string with a newline to "\n".
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/typeSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Debug,
EntityName,
Expression,
factory,
findAncestor,
FunctionLikeDeclaration,
getAllAccessorDeclarations,
Expand Down Expand Up @@ -137,6 +136,7 @@ export interface RuntimeTypeSerializer {
/** @internal */
export function createRuntimeTypeSerializer(context: TransformationContext): RuntimeTypeSerializer {
const {
factory,
hoistVariableDeclaration
} = context;

Expand Down