mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-13 04:57:55 -06:00
Remove most direct uses of factory from src/compilers/transformers (#52957)
This commit is contained in:
parent
6fe711f85a
commit
7a0061aa96
@ -41,7 +41,6 @@ import {
|
||||
Expression,
|
||||
ExpressionStatement,
|
||||
ExpressionWithTypeArguments,
|
||||
factory,
|
||||
filter,
|
||||
find,
|
||||
findComputedPropertyNameCacheAssignment,
|
||||
@ -153,6 +152,7 @@ import {
|
||||
newPrivateEnvironment,
|
||||
Node,
|
||||
NodeCheckFlags,
|
||||
NodeFactory,
|
||||
nodeIsSynthesized,
|
||||
ObjectLiteralElement,
|
||||
OmittedExpression,
|
||||
@ -2457,6 +2457,7 @@ 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
|
||||
@ -2464,6 +2465,7 @@ export function transformClassFields(context: TransformationContext): (x: Source
|
||||
}
|
||||
else {
|
||||
return createPrivateStaticFieldInitializer(
|
||||
factory,
|
||||
privateIdentifierInfo.variableName,
|
||||
visitNode(property.initializer, initializerVisitor, isExpression)
|
||||
);
|
||||
@ -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)
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -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([
|
||||
@ -3222,7 +3224,7 @@ 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,
|
||||
@ -3230,7 +3232,7 @@ function createPrivateInstanceFieldInitializer(receiver: LeftHandSideExpression,
|
||||
);
|
||||
}
|
||||
|
||||
function createPrivateInstanceMethodInitializer(receiver: LeftHandSideExpression, weakSetName: Identifier) {
|
||||
function createPrivateInstanceMethodInitializer(factory: NodeFactory, receiver: LeftHandSideExpression, weakSetName: Identifier) {
|
||||
return factory.createCallExpression(
|
||||
factory.createPropertyAccessExpression(weakSetName, "add"),
|
||||
/*typeArguments*/ undefined,
|
||||
|
||||
@ -166,6 +166,7 @@ import {
|
||||
Node,
|
||||
NodeArray,
|
||||
NodeBuilderFlags,
|
||||
NodeFactory,
|
||||
NodeFlags,
|
||||
NodeId,
|
||||
normalizeSlashes,
|
||||
@ -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,
|
||||
@ -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));
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@ import {
|
||||
ElementAccessExpression,
|
||||
every,
|
||||
Expression,
|
||||
factory,
|
||||
forEach,
|
||||
getElementsOfBindingOrAssignmentPattern,
|
||||
getInitializerOfBindingOrAssignmentElement,
|
||||
@ -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);
|
||||
|
||||
@ -2,13 +2,13 @@ import {
|
||||
CallExpression,
|
||||
Debug,
|
||||
Expression,
|
||||
factory,
|
||||
getSourceTextOfNodeFromSourceFile,
|
||||
hasInvalidEscape,
|
||||
Identifier,
|
||||
isExpression,
|
||||
isExternalModule,
|
||||
isNoSubstitutionTemplateLiteral,
|
||||
NodeFactory,
|
||||
NoSubstitutionTemplateLiteral,
|
||||
setTextRange,
|
||||
SourceFile,
|
||||
@ -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)));
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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".
|
||||
|
||||
@ -11,7 +11,6 @@ import {
|
||||
Debug,
|
||||
EntityName,
|
||||
Expression,
|
||||
factory,
|
||||
findAncestor,
|
||||
FunctionLikeDeclaration,
|
||||
getAllAccessorDeclarations,
|
||||
@ -137,6 +136,7 @@ export interface RuntimeTypeSerializer {
|
||||
/** @internal */
|
||||
export function createRuntimeTypeSerializer(context: TransformationContext): RuntimeTypeSerializer {
|
||||
const {
|
||||
factory,
|
||||
hoistVariableDeclaration
|
||||
} = context;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user