Skip to content

Commit

Permalink
Rename factory methods to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jun 15, 2020
1 parent 7dbd48b commit 417b0a6
Show file tree
Hide file tree
Showing 54 changed files with 908 additions and 907 deletions.
134 changes: 67 additions & 67 deletions src/compat/deprecations.ts

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4292,7 +4292,7 @@ namespace ts {
if (type.flags & TypeFlags.NumberLiteral) {
const value = (<NumberLiteralType>type).value;
context.approximateLength += ("" + value).length;
return factory.createLiteralTypeNode(value < 0 ? factory.createPrefix(SyntaxKind.MinusToken, factory.createNumericLiteral(-value)) : factory.createNumericLiteral(value));
return factory.createLiteralTypeNode(value < 0 ? factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(-value)) : factory.createNumericLiteral(value));
}
if (type.flags & TypeFlags.BigIntLiteral) {
context.approximateLength += (pseudoBigIntToString((<BigIntLiteralType>type).value).length) + 1;
Expand Down Expand Up @@ -5517,7 +5517,7 @@ namespace ts {
const identifier = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping);
identifier.symbol = symbol;

return index > 0 ? factory.createPropertyAccess(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier;
return index > 0 ? factory.createPropertyAccessExpression(createExpressionFromSymbolChain(chain, index - 1), identifier) : identifier;
}
else {
if (firstChar === CharacterCodes.openBracket) {
Expand All @@ -5539,7 +5539,7 @@ namespace ts {
expression = setEmitFlags(factory.createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping);
expression.symbol = symbol;
}
return factory.createElementAccess(createExpressionFromSymbolChain(chain, index - 1), expression);
return factory.createElementAccessExpression(createExpressionFromSymbolChain(chain, index - 1), expression);
}
}
}
Expand All @@ -5562,7 +5562,7 @@ namespace ts {
return fromNameType;
}
if (isKnownSymbol(symbol)) {
return factory.createComputedPropertyName(factory.createPropertyAccess(factory.createIdentifier("Symbol"), (symbol.escapedName as string).substr(3)));
return factory.createComputedPropertyName(factory.createPropertyAccessExpression(factory.createIdentifier("Symbol"), (symbol.escapedName as string).substr(3)));
}
const rawName = unescapeLeadingUnderscores(symbol.escapedName);
return createPropertyNameNodeForIdentifierOrLiteral(rawName, singleQuote);
Expand Down Expand Up @@ -7577,7 +7577,7 @@ namespace ts {
const propName = getDestructuringPropertyName(node);
if (propName) {
const literal = setTextRange(parseNodeFactory.createStringLiteral(propName), node);
const result = setTextRange(parseNodeFactory.createElementAccess(parentAccess, literal), node);
const result = setTextRange(parseNodeFactory.createElementAccessExpression(parentAccess, literal), node);
setParent(literal, result);
setParent(result, node);
result.flowNode = parentAccess.flowNode;
Expand Down Expand Up @@ -7869,7 +7869,7 @@ namespace ts {
}

function getFlowTypeInConstructor(symbol: Symbol, constructor: ConstructorDeclaration) {
const reference = factory.createPropertyAccess(factory.createThis(), unescapeLeadingUnderscores(symbol.escapedName));
const reference = factory.createPropertyAccessExpression(factory.createThis(), unescapeLeadingUnderscores(symbol.escapedName));
setParent(reference.expression, reference);
setParent(reference, constructor);
reference.flowNode = constructor.returnFlowNode;
Expand Down Expand Up @@ -34238,7 +34238,7 @@ namespace ts {
}

function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
const reference = factory.createPropertyAccess(factory.createThis(), propName);
const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
setParent(reference.expression, reference);
setParent(reference, constructor);
reference.flowNode = constructor.returnFlowNode;
Expand Down
52 changes: 26 additions & 26 deletions src/compiler/factory/emitHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace ts {
context.requestEmitHelper(decorateHelper);

const argumentsArray: Expression[] = [];
argumentsArray.push(factory.createArrayLiteral(decoratorExpressions, /*multiLine*/ true));
argumentsArray.push(factory.createArrayLiteralExpression(decoratorExpressions, /*multiLine*/ true));
argumentsArray.push(target);
if (memberName) {
argumentsArray.push(memberName);
Expand All @@ -96,7 +96,7 @@ namespace ts {
}
}

return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__decorate"),
/*typeArguments*/ undefined,
argumentsArray
Expand All @@ -105,7 +105,7 @@ namespace ts {

function createMetadataHelper(metadataKey: string, metadataValue: Expression) {
context.requestEmitHelper(metadataHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__metadata"),
/*typeArguments*/ undefined,
[
Expand All @@ -118,7 +118,7 @@ namespace ts {
function createParamHelper(expression: Expression, parameterOffset: number, location?: TextRange) {
context.requestEmitHelper(paramHelper);
return setTextRange(
factory.createCall(
factory.createCallExpression(
getUnscopedHelperName("__param"),
/*typeArguments*/ undefined,
[
Expand All @@ -134,12 +134,12 @@ namespace ts {

function createAssignHelper(attributesSegments: Expression[]) {
if (context.getCompilerOptions().target! >= ScriptTarget.ES2015) {
return factory.createCall(factory.createPropertyAccess(factory.createIdentifier("Object"), "assign"),
return factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier("Object"), "assign"),
/*typeArguments*/ undefined,
attributesSegments);
}
context.requestEmitHelper(assignHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__assign"),
/*typeArguments*/ undefined,
attributesSegments
Expand All @@ -148,7 +148,7 @@ namespace ts {

function createAwaitHelper(expression: Expression) {
context.requestEmitHelper(awaitHelper);
return factory.createCall(getUnscopedHelperName("__await"), /*typeArguments*/ undefined, [expression]);
return factory.createCallExpression(getUnscopedHelperName("__await"), /*typeArguments*/ undefined, [expression]);
}

function createAsyncGeneratorHelper(generatorFunc: FunctionExpression, hasLexicalThis: boolean) {
Expand All @@ -158,7 +158,7 @@ namespace ts {
// Mark this node as originally an async function
(generatorFunc.emitNode || (generatorFunc.emitNode = {} as EmitNode)).flags |= EmitFlags.AsyncFunctionBody | EmitFlags.ReuseTempVariableScope;

return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__asyncGenerator"),
/*typeArguments*/ undefined,
[
Expand All @@ -172,7 +172,7 @@ namespace ts {
function createAsyncDelegatorHelper(expression: Expression) {
context.requestEmitHelper(awaitHelper);
context.requestEmitHelper(asyncDelegator);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__asyncDelegator"),
/*typeArguments*/ undefined,
[expression]
Expand All @@ -181,7 +181,7 @@ namespace ts {

function createAsyncValuesHelper(expression: Expression) {
context.requestEmitHelper(asyncValues);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__asyncValues"),
/*typeArguments*/ undefined,
[expression]
Expand All @@ -206,7 +206,7 @@ namespace ts {
computedTempVariableOffset++;
// typeof _tmp === "symbol" ? _tmp : _tmp + ""
propertyNames.push(
factory.createConditional(
factory.createConditionalExpression(
factory.createTypeCheck(temp, "symbol"),
/*questionToken*/ undefined,
temp,
Expand All @@ -220,13 +220,13 @@ namespace ts {
}
}
}
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__rest"),
/*typeArguments*/ undefined,
[
value,
setTextRange(
factory.createArrayLiteral(propertyNames),
factory.createArrayLiteralExpression(propertyNames),
location
)]
);
Expand All @@ -250,7 +250,7 @@ namespace ts {
// Mark this node as originally an async function
(generatorFunc.emitNode || (generatorFunc.emitNode = {} as EmitNode)).flags |= EmitFlags.AsyncFunctionBody | EmitFlags.ReuseTempVariableScope;

return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__awaiter"),
/*typeArguments*/ undefined,
[
Expand All @@ -266,7 +266,7 @@ namespace ts {

function createExtendsHelper(name: Identifier) {
context.requestEmitHelper(extendsHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__extends"),
/*typeArguments*/ undefined,
[name, factory.createUniqueName("_super", GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel)]
Expand All @@ -275,7 +275,7 @@ namespace ts {

function createTemplateObjectHelper(cooked: ArrayLiteralExpression, raw: ArrayLiteralExpression) {
context.requestEmitHelper(templateObjectHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__makeTemplateObject"),
/*typeArguments*/ undefined,
[cooked, raw]
Expand All @@ -285,7 +285,7 @@ namespace ts {
function createSpreadHelper(argumentList: readonly Expression[]) {
context.requestEmitHelper(readHelper);
context.requestEmitHelper(spreadHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__spread"),
/*typeArguments*/ undefined,
argumentList
Expand All @@ -294,7 +294,7 @@ namespace ts {

function createSpreadArraysHelper(argumentList: readonly Expression[]) {
context.requestEmitHelper(spreadArraysHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__spreadArrays"),
/*typeArguments*/ undefined,
argumentList
Expand All @@ -305,7 +305,7 @@ namespace ts {

function createValuesHelper(expression: Expression) {
context.requestEmitHelper(valuesHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__values"),
/*typeArguments*/ undefined,
[expression]
Expand All @@ -314,7 +314,7 @@ namespace ts {

function createReadHelper(iteratorRecord: Expression, count: number | undefined) {
context.requestEmitHelper(readHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__read"),
/*typeArguments*/ undefined,
count !== undefined
Expand All @@ -327,7 +327,7 @@ namespace ts {

function createGeneratorHelper(body: FunctionExpression) {
context.requestEmitHelper(generatorHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__generator"),
/*typeArguments*/ undefined,
[factory.createThis(), body]);
Expand All @@ -337,15 +337,15 @@ namespace ts {

function createCreateBindingHelper(module: Expression, inputName: Expression, outputName: Expression | undefined) {
context.requestEmitHelper(createBindingHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__createBinding"),
/*typeArguments*/ undefined,
[factory.createIdentifier("exports"), module, inputName, ...(outputName ? [outputName] : [])]);
}

function createImportStarHelper(expression: Expression) {
context.requestEmitHelper(importStarHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__importStar"),
/*typeArguments*/ undefined,
[expression]
Expand All @@ -359,7 +359,7 @@ namespace ts {

function createImportDefaultHelper(expression: Expression) {
context.requestEmitHelper(importDefaultHelper);
return factory.createCall(
return factory.createCallExpression(
getUnscopedHelperName("__importDefault"),
/*typeArguments*/ undefined,
[expression]
Expand All @@ -370,12 +370,12 @@ namespace ts {

function createClassPrivateFieldGetHelper(receiver: Expression, privateField: Identifier) {
context.requestEmitHelper(classPrivateFieldGetHelper);
return factory.createCall(getUnscopedHelperName("__classPrivateFieldGet"), /*typeArguments*/ undefined, [receiver, privateField]);
return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldGet"), /*typeArguments*/ undefined, [receiver, privateField]);
}

function createClassPrivateFieldSetHelper(receiver: Expression, privateField: Identifier, value: Expression) {
context.requestEmitHelper(classPrivateFieldSetHelper);
return factory.createCall(getUnscopedHelperName("__classPrivateFieldSet"), /*typeArguments*/ undefined, [receiver, privateField, value]);
return factory.createCallExpression(getUnscopedHelperName("__classPrivateFieldSet"), /*typeArguments*/ undefined, [receiver, privateField, value]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/factory/nodeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ts {

function convertToFunctionBlock(node: ConciseBody, multiLine?: boolean): Block {
if (isBlock(node)) return node;
const returnStatement = factory.createReturn(node);
const returnStatement = factory.createReturnStatement(node);
setTextRange(returnStatement, node);
const body = factory.createBlock([returnStatement], multiLine);
setTextRange(body, node);
Expand Down Expand Up @@ -44,7 +44,7 @@ namespace ts {
if (isBindingElement(element)) {
if (element.dotDotDotToken) {
Debug.assertNode(element.name, isIdentifier);
return setOriginalNode(setTextRange(factory.createSpread(element.name), element), element);
return setOriginalNode(setTextRange(factory.createSpreadElement(element.name), element), element);
}
const expression = convertToAssignmentElementTarget(element.name);
return element.initializer
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace ts {
if (isObjectBindingPattern(node)) {
return setOriginalNode(
setTextRange(
factory.createObjectLiteral(map(node.elements, convertToObjectAssignmentElement)),
factory.createObjectLiteralExpression(map(node.elements, convertToObjectAssignmentElement)),
node
),
node
Expand All @@ -106,7 +106,7 @@ namespace ts {
if (isArrayBindingPattern(node)) {
return setOriginalNode(
setTextRange(
factory.createArrayLiteral(map(node.elements, convertToArrayAssignmentElement)),
factory.createArrayLiteralExpression(map(node.elements, convertToArrayAssignmentElement)),
node
),
node
Expand Down
Loading

0 comments on commit 417b0a6

Please sign in to comment.