Skip to content

Commit 3c74558

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR: use ObjectLiteralElement as an interface name and ObjectLitearlElementLike as a type alias
1 parent e1bfd7f commit 3c74558

File tree

9 files changed

+29
-36
lines changed

9 files changed

+29
-36
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5947,7 +5947,7 @@ namespace ts {
59475947

59485948
// Returns true if the given expression contains (at any level of nesting) a function or arrow expression
59495949
// that is subject to contextual typing.
5950-
function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean {
5950+
function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike): boolean {
59515951
Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node));
59525952
switch (node.kind) {
59535953
case SyntaxKind.FunctionExpression:
@@ -9792,7 +9792,7 @@ namespace ts {
97929792
return getContextualTypeForObjectLiteralElement(node);
97939793
}
97949794

9795-
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) {
9795+
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike) {
97969796
const objectLiteral = <ObjectLiteralExpression>element.parent;
97979797
const type = getApparentTypeOfContextualType(objectLiteral);
97989798
if (type) {
@@ -9909,7 +9909,7 @@ namespace ts {
99099909
return getContextualTypeForBinaryOperand(node);
99109910
case SyntaxKind.PropertyAssignment:
99119911
case SyntaxKind.ShorthandPropertyAssignment:
9912-
return getContextualTypeForObjectLiteralElement(<ObjectLiteralElement>parent);
9912+
return getContextualTypeForObjectLiteralElement(<ObjectLiteralElementLike>parent);
99139913
case SyntaxKind.ArrayLiteralExpression:
99149914
return getContextualTypeForElementExpression(node);
99159915
case SyntaxKind.ConditionalExpression:
@@ -13185,7 +13185,7 @@ namespace ts {
1318513185
return sourceType;
1318613186
}
1318713187

13188-
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElement, contextualMapper?: TypeMapper) {
13188+
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, contextualMapper?: TypeMapper) {
1318913189
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
1319013190
const name = <PropertyName>(<PropertyAssignment>property).name;
1319113191
if (name.kind === SyntaxKind.ComputedPropertyName) {
@@ -18445,7 +18445,7 @@ namespace ts {
1844518445
// for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) {
1844618446
if (expr.parent.kind === SyntaxKind.PropertyAssignment) {
1844718447
const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(<Expression>expr.parent.parent);
18448-
return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, <ObjectLiteralElement>expr.parent);
18448+
return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, <ObjectLiteralElementLike>expr.parent);
1844918449
}
1845018450
// Array literal assignment - array destructuring pattern
1845118451
Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression);

src/compiler/factory.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ namespace ts {
416416
return node;
417417
}
418418

419-
export function createObjectLiteral(properties?: ObjectLiteralElement[], location?: TextRange, multiLine?: boolean) {
419+
export function createObjectLiteral(properties?: ObjectLiteralElementLike[], location?: TextRange, multiLine?: boolean) {
420420
const node = <ObjectLiteralExpression>createNode(SyntaxKind.ObjectLiteralExpression, location);
421421
node.properties = createNodeArray(properties);
422422
if (multiLine) {
@@ -425,7 +425,7 @@ namespace ts {
425425
return node;
426426
}
427427

428-
export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElement[]) {
428+
export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElementLike[]) {
429429
if (node.properties !== properties) {
430430
return updateNode(createObjectLiteral(properties, node, node.multiLine), node);
431431
}
@@ -2069,7 +2069,7 @@ namespace ts {
20692069
}
20702070
}
20712071

2072-
export function createExpressionForObjectLiteralElement(node: ObjectLiteralExpression, property: ObjectLiteralElement, receiver: Expression): Expression {
2072+
export function createExpressionForObjectLiteralElementLike(node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression {
20732073
switch (property.kind) {
20742074
case SyntaxKind.GetAccessor:
20752075
case SyntaxKind.SetAccessor:
@@ -2086,7 +2086,7 @@ namespace ts {
20862086
function createExpressionForAccessorDeclaration(properties: NodeArray<Declaration>, property: AccessorDeclaration, receiver: Expression, multiLine: boolean) {
20872087
const { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(properties, property);
20882088
if (property === firstAccessor) {
2089-
const properties: ObjectLiteralElement[] = [];
2089+
const properties: ObjectLiteralElementLike[] = [];
20902090
if (getAccessor) {
20912091
const getterFunction = createFunctionExpression(
20922092
/*asteriskToken*/ undefined,

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,7 @@ namespace ts {
41214121
return undefined;
41224122
}
41234123

4124-
function parseObjectLiteralElement(): ObjectLiteralElement {
4124+
function parseObjectLiteralElement(): ObjectLiteralElementLike {
41254125
const fullStart = scanner.getStartPos();
41264126
const decorators = parseDecorators();
41274127
const modifiers = parseModifiers();

src/compiler/transformers/es6.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ namespace ts {
12591259
setNodeEmitFlags(propertyName, NodeEmitFlags.NoComments | NodeEmitFlags.NoLeadingSourceMap);
12601260
setSourceMapRange(propertyName, firstAccessor.name);
12611261

1262-
const properties: ObjectLiteralElement[] = [];
1262+
const properties: ObjectLiteralElementLike[] = [];
12631263
if (getAccessor) {
12641264
const getterFunction = transformFunctionLikeToExpression(getAccessor, /*location*/ undefined, /*name*/ undefined);
12651265
setSourceMapRange(getterFunction, getSourceMapRange(getAccessor));
@@ -2474,7 +2474,7 @@ namespace ts {
24742474
*
24752475
* @param node A MethodDeclaration node.
24762476
*/
2477-
function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElement {
2477+
function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElementLike {
24782478
// We should only get here for methods on an object literal with regular identifier names.
24792479
// Methods on classes are handled in visitClassDeclaration/visitClassExpression.
24802480
// Methods with computed property names are handled in visitObjectLiteralExpression.
@@ -2493,7 +2493,7 @@ namespace ts {
24932493
*
24942494
* @param node A ShorthandPropertyAssignment node.
24952495
*/
2496-
function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
2496+
function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
24972497
return createPropertyAssignment(
24982498
node.name,
24992499
getSynthesizedClone(node.name),

src/compiler/transformers/generators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,13 +1030,13 @@ namespace ts {
10301030
expressions.push(multiLine ? startOnNewLine(getMutableClone(temp)) : temp);
10311031
return inlineExpressions(expressions);
10321032

1033-
function reduceProperty(expressions: Expression[], property: ObjectLiteralElement) {
1033+
function reduceProperty(expressions: Expression[], property: ObjectLiteralElementLike) {
10341034
if (containsYield(property) && expressions.length > 0) {
10351035
emitStatement(createStatement(inlineExpressions(expressions)));
10361036
expressions = [];
10371037
}
10381038

1039-
const expression = createExpressionForObjectLiteralElement(node, property, temp);
1039+
const expression = createExpressionForObjectLiteralElementLike(node, property, temp);
10401040
const visited = visitNode(expression, visitor, isExpression);
10411041
if (visited) {
10421042
if (multiLine) {

src/compiler/transformers/module/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ namespace ts {
850850
return node;
851851
}
852852

853-
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
853+
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
854854
const name = node.name;
855855
const exportedOrImportedName = substituteExpressionIdentifier(name);
856856
if (exportedOrImportedName !== name) {

src/compiler/transformers/module/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ namespace ts {
288288
}
289289
}
290290

291-
const exportedNames: ObjectLiteralElement[] = [];
291+
const exportedNames: ObjectLiteralElementLike[] = [];
292292
if (exportedLocalNames) {
293293
for (const exportedLocalName of exportedLocalNames) {
294294
// write name of exported declaration, i.e 'export var x...'
@@ -1107,7 +1107,7 @@ namespace ts {
11071107
return false;
11081108
}
11091109

1110-
function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElement): boolean {
1110+
function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElementLike): boolean {
11111111
if (isShorthandPropertyAssignment(node)) {
11121112
return isExportedBinding(node.name);
11131113
}

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ namespace ts {
15601560

15611561
function addNewTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) {
15621562
if (compilerOptions.emitDecoratorMetadata) {
1563-
let properties: ObjectLiteralElement[];
1563+
let properties: ObjectLiteralElementLike[];
15641564
if (shouldAddTypeMetadata(node)) {
15651565
(properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeTypeOfNode(node))));
15661566
}
@@ -3273,7 +3273,7 @@ namespace ts {
32733273
return node;
32743274
}
32753275

3276-
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement {
3276+
function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
32773277
if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) {
32783278
const name = node.name;
32793279
const exportedName = trySubstituteNamespaceExportedName(name);

src/compiler/types.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ namespace ts {
316316
// Property assignments
317317
PropertyAssignment,
318318
ShorthandPropertyAssignment,
319-
SpreadObjectLiteralAssignment,
320319

321320
// Enum
322321
EnumMember,
@@ -644,23 +643,23 @@ namespace ts {
644643
initializer?: Expression; // Optional initializer
645644
}
646645

647-
export interface ObjectLiteralElementLike extends Declaration {
646+
export interface ObjectLiteralElement extends Declaration {
648647
_objectLiteralBrandBrand: any;
649648
name?: PropertyName;
650649
}
651650

652-
export type ObjectLiteralElement = PropertyAssignment | ShorthandPropertyAssignment | SpreadObjectLiteralAssignment | MethodDeclaration | AccessorDeclaration;
651+
export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration;
653652

654653
// @kind(SyntaxKind.PropertyAssignment)
655-
export interface PropertyAssignment extends ObjectLiteralElementLike {
654+
export interface PropertyAssignment extends ObjectLiteralElement {
656655
_propertyAssignmentBrand: any;
657656
name: PropertyName;
658657
questionToken?: Node;
659658
initializer: Expression;
660659
}
661660

662661
// @kind(SyntaxKind.ShorthandPropertyAssignment)
663-
export interface ShorthandPropertyAssignment extends ObjectLiteralElementLike {
662+
export interface ShorthandPropertyAssignment extends ObjectLiteralElement {
664663
name: Identifier;
665664
questionToken?: Node;
666665
// used when ObjectLiteralExpression is used in ObjectAssignmentPattern
@@ -669,12 +668,6 @@ namespace ts {
669668
objectAssignmentInitializer?: Expression;
670669
}
671670

672-
// @kind(SyntaxKind.SpreadObjectLiteralAssignment)
673-
export interface SpreadObjectLiteralAssignment extends ObjectLiteralElementLike, SpreadElementExpression {
674-
_spreadObjectLiteralAssignmentBrand: any;
675-
dotDotDotToken?: Node;
676-
}
677-
678671
// SyntaxKind.VariableDeclaration
679672
// SyntaxKind.Parameter
680673
// SyntaxKind.BindingElement
@@ -749,7 +742,7 @@ namespace ts {
749742
// at later stages of the compiler pipeline. In that case, you can either check the parent kind
750743
// of the method, or use helpers like isObjectLiteralMethodDeclaration
751744
// @kind(SyntaxKind.MethodDeclaration)
752-
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElementLike {
745+
export interface MethodDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
753746
name: PropertyName;
754747
body?: FunctionBody;
755748
}
@@ -767,7 +760,7 @@ namespace ts {
767760

768761
// See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a
769762
// ClassElement and an ObjectLiteralElement.
770-
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElementLike {
763+
export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement {
771764
_accessorDeclarationBrand: any;
772765
name: PropertyName;
773766
body: FunctionBody;
@@ -1063,13 +1056,13 @@ namespace ts {
10631056
* JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type
10641057
* ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.)
10651058
**/
1066-
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElementLike> extends PrimaryExpression, Declaration {
1059+
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, Declaration {
10671060
properties: NodeArray<T>;
10681061
}
10691062

10701063
// An ObjectLiteralExpression is the declaration node for an anonymous symbol.
10711064
// @kind(SyntaxKind.ObjectLiteralExpression)
1072-
export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElement> {
1065+
export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase<ObjectLiteralElementLike> {
10731066
/* @internal */
10741067
multiLine?: boolean;
10751068
}
@@ -1213,7 +1206,7 @@ namespace ts {
12131206
export interface DebuggerStatement extends Statement { }
12141207

12151208
// @kind(SyntaxKind.MissingDeclaration)
1216-
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElementLike, TypeElement {
1209+
export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement {
12171210
name?: Identifier;
12181211
}
12191212

0 commit comments

Comments
 (0)