Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Oct 9, 2020
1 parent 1d4cf14 commit 4469e09
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 52 deletions.
16 changes: 8 additions & 8 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ namespace ts {
}

function combineSymbolTables(first: SymbolTable, second: SymbolTable): SymbolTable;
function combineSymbolTables(first: SymbolTable | undefined, second: SymbolTable | undefined): SymbolTable | undefined;
function combineSymbolTables(first: SymbolTable | undefined, second: SymbolTable | undefined): SymbolTable | undefined;
function combineSymbolTables(first: SymbolTable | undefined, second: SymbolTable | undefined): SymbolTable | undefined {
if (!first?.size) return second;
if (!second?.size) return first;
Expand Down Expand Up @@ -9472,7 +9472,7 @@ namespace ts {
}
}
}
return memberTypeList
return memberTypeList;
}

function getDeclaredTypeOfEnum(symbol: Symbol): Type {
Expand Down Expand Up @@ -10401,25 +10401,25 @@ namespace ts {
}
setStructuredTypeMembers(type, members, emptyArray, emptyArray, undefined, undefined);
if (symbol.flags & SymbolFlags.Enum) {
const spreadEnumMembers: SpreadEnumMember[] = []
const spreadEnumMembers: SpreadEnumMember[] = [];
symbol.declarations.forEach(decl => {
if (isEnumDeclaration(decl)) {
decl.members.forEach(member => {
if (isSpreadEnumMember(member)) {
spreadEnumMembers.push(member)
spreadEnumMembers.push(member);
}
})
});
}
})
});
if (spreadEnumMembers.length) {
spreadEnumMembers.forEach(member => {
if (isIdentifier(member.name)) {
const sym = getResolvedSymbol(member.name)
const sym = getResolvedSymbol(member.name);
if (sym.flags & SymbolFlags.Enum) {
members = combineSymbolTables(members, getExportsOfSymbol(sym));
}
}
})
});
setStructuredTypeMembers(type, members, emptyArray, emptyArray, undefined, undefined);
}
}
Expand Down
69 changes: 41 additions & 28 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,7 @@ namespace ts {

const statements: Statement[] = [];
startLexicalEnvironment();
const members = map(node.members, transformEnumMember);
const members = map(node.members, transformEnumMemberLike);
insertStatementsAfterStandardPrologue(statements, endLexicalEnvironment());
addRange(statements, members);

Expand All @@ -2442,37 +2442,50 @@ namespace ts {
*
* @param member The enum member node.
*/
function transformEnumMember(member: EnumMember): Statement {
// enums don't support computed properties
// we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes
// old emitter always generate 'expression' part of the name as-is.
const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false);
const valueExpression = transformEnumMemberDeclarationValue(member);
const innerAssignment = factory.createAssignment(
factory.createElementAccessExpression(
currentNamespaceContainerName,
name
),
valueExpression
);
const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ?
innerAssignment :
factory.createAssignment(
function transformEnumMemberLike(member: EnumMemberLike): Statement {
if (isEnumMember(member)) {
// enums don't support computed properties
// we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes
// old emitter always generate 'expression' part of the name as-is.
const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false);
const valueExpression = transformEnumMemberDeclarationValue(member);
const innerAssignment = factory.createAssignment(
factory.createElementAccessExpression(
currentNamespaceContainerName,
innerAssignment
name
),
name
valueExpression
);
return setTextRange(
factory.createExpressionStatement(
setTextRange(
outerAssignment,
member
)
),
member
);
const outerAssignment = valueExpression.kind === SyntaxKind.StringLiteral ?
innerAssignment :
factory.createAssignment(
factory.createElementAccessExpression(
currentNamespaceContainerName,
innerAssignment
),
name
);
return setTextRange(
factory.createExpressionStatement(
setTextRange(
outerAssignment,
member
)
),
member
);
}
else {
return setTextRange(
factory.createExpressionStatement(
setTextRange(
emitHelpers().createAssignHelper([currentNamespaceContainerName, member.name as Identifier]),
member
)
),
member
);
}
}

/**
Expand Down
25 changes: 18 additions & 7 deletions tests/baselines/reference/spreadEnum1.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ declare let basic: BasicEvents;

declare let adv: AdvEvents;

// adv = basic;
adv = basic;

// basic = BasicEvents.Start;
// basic = BasicEvents.Finish;
basic = BasicEvents.Start;
basic = BasicEvents.Finish;

adv = AdvEvents.Start;
adv = AdvEvents.Finish;
Expand All @@ -28,20 +28,31 @@ adv = BasicEvents.Start;
adv = BasicEvents.Finish;

//// [spreadEnum1.js]
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var BasicEvents;
(function (BasicEvents) {
BasicEvents["Start"] = "Start";
BasicEvents["Finish"] = "Finish";
})(BasicEvents || (BasicEvents = {}));
var AdvEvents;
(function (AdvEvents) {
AdvEvents[AdvEvents["BasicEvents"] = void 0] = "BasicEvents";
__assign(AdvEvents, BasicEvents);
AdvEvents["Pause"] = "Pause";
AdvEvents["Resume"] = "Resume";
})(AdvEvents || (AdvEvents = {}));
// adv = basic;
// basic = BasicEvents.Start;
// basic = BasicEvents.Finish;
adv = basic;
basic = BasicEvents.Start;
basic = BasicEvents.Finish;
adv = AdvEvents.Start;
adv = AdvEvents.Finish;
adv = AdvEvents.Pause;
Expand Down
17 changes: 14 additions & 3 deletions tests/baselines/reference/spreadEnum1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ declare let adv: AdvEvents;
>adv : Symbol(adv, Decl(spreadEnum1.ts, 13, 11))
>AdvEvents : Symbol(AdvEvents, Decl(spreadEnum1.ts, 3, 1))

// adv = basic;
adv = basic;
>adv : Symbol(adv, Decl(spreadEnum1.ts, 13, 11))
>basic : Symbol(basic, Decl(spreadEnum1.ts, 11, 11))

// basic = BasicEvents.Start;
// basic = BasicEvents.Finish;
basic = BasicEvents.Start;
>basic : Symbol(basic, Decl(spreadEnum1.ts, 11, 11))
>BasicEvents.Start : Symbol(BasicEvents.Start, Decl(spreadEnum1.ts, 0, 18))
>BasicEvents : Symbol(BasicEvents, Decl(spreadEnum1.ts, 0, 0))
>Start : Symbol(BasicEvents.Start, Decl(spreadEnum1.ts, 0, 18))

basic = BasicEvents.Finish;
>basic : Symbol(basic, Decl(spreadEnum1.ts, 11, 11))
>BasicEvents.Finish : Symbol(BasicEvents.Finish, Decl(spreadEnum1.ts, 1, 20))
>BasicEvents : Symbol(BasicEvents, Decl(spreadEnum1.ts, 0, 0))
>Finish : Symbol(BasicEvents.Finish, Decl(spreadEnum1.ts, 1, 20))

adv = AdvEvents.Start;
>adv : Symbol(adv, Decl(spreadEnum1.ts, 13, 11))
Expand Down
20 changes: 17 additions & 3 deletions tests/baselines/reference/spreadEnum1.types
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,24 @@ declare let basic: BasicEvents;
declare let adv: AdvEvents;
>adv : AdvEvents

// adv = basic;
adv = basic;
>adv = basic : BasicEvents
>adv : AdvEvents
>basic : BasicEvents

// basic = BasicEvents.Start;
// basic = BasicEvents.Finish;
basic = BasicEvents.Start;
>basic = BasicEvents.Start : BasicEvents.Start
>basic : BasicEvents
>BasicEvents.Start : BasicEvents.Start
>BasicEvents : typeof BasicEvents
>Start : BasicEvents.Start

basic = BasicEvents.Finish;
>basic = BasicEvents.Finish : BasicEvents.Finish
>basic : BasicEvents
>BasicEvents.Finish : BasicEvents.Finish
>BasicEvents : typeof BasicEvents
>Finish : BasicEvents.Finish

adv = AdvEvents.Start;
>adv = AdvEvents.Start : BasicEvents.Start
Expand Down
6 changes: 3 additions & 3 deletions tests/cases/conformance/enums/spreadEnum1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ declare let basic: BasicEvents;

declare let adv: AdvEvents;

// adv = basic;
adv = basic;

// basic = BasicEvents.Start;
// basic = BasicEvents.Finish;
basic = BasicEvents.Start;
basic = BasicEvents.Finish;

adv = AdvEvents.Start;
adv = AdvEvents.Finish;
Expand Down

0 comments on commit 4469e09

Please sign in to comment.