Skip to content

Commit

Permalink
Cleanup of duplicate code due to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Mar 25, 2015
1 parent ea15225 commit a60d591
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 170 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11387,7 +11387,7 @@ module ts {
return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher);
}
else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) {
let accessors = mergeAccessorDeclarations((<ClassDeclaration>node.parent).members, <AccessorDeclaration>node);
let accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, <AccessorDeclaration>node);
if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) {
return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name);
}
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ module ts {
return ~low;
}

export function foldLeft<T>(array: T[], f: (a: T, x: T) => T): T;
export function foldLeft<T, U>(array: T[], f: (a: U, x: T) => U, initial: U): U;
export function foldLeft<T, U>(array: T[], f: (a: U, x: T) => U, initial?: U): U {
export function reduceLeft<T>(array: T[], f: (a: T, x: T) => T): T;
export function reduceLeft<T, U>(array: T[], f: (a: U, x: T) => U, initial: U): U;
export function reduceLeft<T, U>(array: T[], f: (a: U, x: T) => U, initial?: U): U {
if (array) {
var count = array.length;
if (count > 0) {
Expand All @@ -179,9 +179,9 @@ module ts {
return initial;
}

export function foldRight<T>(array: T[], f: (a: T, x: T) => T): T;
export function foldRight<T, U>(array: T[], f: (a: U, x: T) => U, initial: U): U;
export function foldRight<T, U>(array: T[], f: (a: U, x: T) => U, initial?: U): U {
export function reduceRight<T>(array: T[], f: (a: T, x: T) => T): T;
export function reduceRight<T, U>(array: T[], f: (a: U, x: T) => U, initial: U): U;
export function reduceRight<T, U>(array: T[], f: (a: U, x: T) => U, initial?: U): U {
if (array) {
var pos = array.length - 1;
if (pos >= 0) {
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module ts {

// flag enum used to request and track usages of few dedicated temp variables
// enum values are used to set/check bit values and thus should not have bit collisions.
let accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, node);
const enum TempVariableKind {
auto = 0,
_i = 1,
Expand Down Expand Up @@ -1497,7 +1496,7 @@ module ts {

case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
let { firstAccessor, getAccessor, setAccessor } = mergeAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);
let { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);

// Only emit the first accessor.
if (firstAccessor !== property) {
Expand Down Expand Up @@ -3327,7 +3326,7 @@ module ts {
emitTrailingComments(member);
}
else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) {
let accessors = mergeAccessorDeclarations(node.members, <AccessorDeclaration>member);
let accessors = getAllAccessorDeclarations(node.members, <AccessorDeclaration>member);
if (member === accessors.firstAccessor) {
writeLine();
emitStart(member);
Expand Down Expand Up @@ -3815,7 +3814,7 @@ module ts {

case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
let accessors = mergeAccessorDeclarations(node.members, <AccessorDeclaration>member);
let accessors = getAllAccessorDeclarations(node.members, <AccessorDeclaration>member);
if (member !== accessors.firstAccessor) {
// skip the second accessor as we processed it with the first.
return;
Expand Down
8 changes: 0 additions & 8 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,6 @@ module ts {
body: Block;
}

// A merged view of get/set accessors
export interface MergedAccessorDeclarations {
getAccessor: AccessorDeclaration;
setAccessor: AccessorDeclaration;
firstAccessor: AccessorDeclaration;
secondAccessor: AccessorDeclaration;
}

export interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
Expand Down
55 changes: 5 additions & 50 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,56 +575,6 @@ module ts {
return (<CallExpression>node).expression;
}

export function mergeAccessorDeclarations(declarations: NodeArray<Declaration>, accessor: AccessorDeclaration): MergedAccessorDeclarations {
let firstAccessor: AccessorDeclaration;
let secondAccessor: AccessorDeclaration;
let getAccessor: AccessorDeclaration;
let setAccessor: AccessorDeclaration;
if (hasDynamicName(accessor)) {
firstAccessor = accessor;
if (accessor.kind === SyntaxKind.GetAccessor) {
getAccessor = accessor;
}
else if (accessor.kind === SyntaxKind.SetAccessor) {
setAccessor = accessor;
}
else {
Debug.fail("Accessor has wrong kind");
}
}
else {
forEach(declarations, (member: Declaration) => {
if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor)
&& (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) {
let memberName = getPropertyNameForPropertyNameNode(member.name);
let accessorName = getPropertyNameForPropertyNameNode(accessor.name);
if (memberName === accessorName) {
if (!firstAccessor) {
firstAccessor = <AccessorDeclaration>member;
}
else if (!secondAccessor) {
secondAccessor = <AccessorDeclaration>member;
}

if (member.kind === SyntaxKind.GetAccessor && !getAccessor) {
getAccessor = <AccessorDeclaration>member;
}

if (member.kind === SyntaxKind.SetAccessor && !setAccessor) {
setAccessor = <AccessorDeclaration>member;
}
}
}
});
}
return {
firstAccessor,
secondAccessor,
getAccessor,
setAccessor
};
}

export function nodeCanBeDecorated(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.ClassDeclaration:
Expand Down Expand Up @@ -1626,6 +1576,7 @@ module ts {

export function getAllAccessorDeclarations(declarations: NodeArray<Declaration>, accessor: AccessorDeclaration) {
let firstAccessor: AccessorDeclaration;
let secondAccessor: AccessorDeclaration;
let getAccessor: AccessorDeclaration;
let setAccessor: AccessorDeclaration;
if (hasDynamicName(accessor)) {
Expand All @@ -1650,6 +1601,9 @@ module ts {
if (!firstAccessor) {
firstAccessor = <AccessorDeclaration>member;
}
else if (!secondAccessor) {
secondAccessor = <AccessorDeclaration>member;
}

if (member.kind === SyntaxKind.GetAccessor && !getAccessor) {
getAccessor = <AccessorDeclaration>member;
Expand All @@ -1664,6 +1618,7 @@ module ts {
}
return {
firstAccessor,
secondAccessor,
getAccessor,
setAccessor
};
Expand Down
6 changes: 0 additions & 6 deletions tests/baselines/reference/APISample_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,6 @@ declare module "typescript" {
_accessorDeclarationBrand: any;
body: Block;
}
interface MergedAccessorDeclarations {
getAccessor: AccessorDeclaration;
setAccessor: AccessorDeclaration;
firstAccessor: AccessorDeclaration;
secondAccessor: AccessorDeclaration;
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
Expand Down
19 changes: 0 additions & 19 deletions tests/baselines/reference/APISample_compile.types
Original file line number Diff line number Diff line change
Expand Up @@ -1440,25 +1440,6 @@ declare module "typescript" {
body: Block;
>body : Block
>Block : Block
}
interface MergedAccessorDeclarations {
>MergedAccessorDeclarations : MergedAccessorDeclarations

getAccessor: AccessorDeclaration;
>getAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

setAccessor: AccessorDeclaration;
>setAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

firstAccessor: AccessorDeclaration;
>firstAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

secondAccessor: AccessorDeclaration;
>secondAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
>IndexSignatureDeclaration : IndexSignatureDeclaration
Expand Down
6 changes: 0 additions & 6 deletions tests/baselines/reference/APISample_linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,6 @@ declare module "typescript" {
_accessorDeclarationBrand: any;
body: Block;
}
interface MergedAccessorDeclarations {
getAccessor: AccessorDeclaration;
setAccessor: AccessorDeclaration;
firstAccessor: AccessorDeclaration;
secondAccessor: AccessorDeclaration;
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
Expand Down
19 changes: 0 additions & 19 deletions tests/baselines/reference/APISample_linter.types
Original file line number Diff line number Diff line change
Expand Up @@ -1586,25 +1586,6 @@ declare module "typescript" {
body: Block;
>body : Block
>Block : Block
}
interface MergedAccessorDeclarations {
>MergedAccessorDeclarations : MergedAccessorDeclarations

getAccessor: AccessorDeclaration;
>getAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

setAccessor: AccessorDeclaration;
>setAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

firstAccessor: AccessorDeclaration;
>firstAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

secondAccessor: AccessorDeclaration;
>secondAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
>IndexSignatureDeclaration : IndexSignatureDeclaration
Expand Down
6 changes: 0 additions & 6 deletions tests/baselines/reference/APISample_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,6 @@ declare module "typescript" {
_accessorDeclarationBrand: any;
body: Block;
}
interface MergedAccessorDeclarations {
getAccessor: AccessorDeclaration;
setAccessor: AccessorDeclaration;
firstAccessor: AccessorDeclaration;
secondAccessor: AccessorDeclaration;
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
Expand Down
19 changes: 0 additions & 19 deletions tests/baselines/reference/APISample_transform.types
Original file line number Diff line number Diff line change
Expand Up @@ -1536,25 +1536,6 @@ declare module "typescript" {
body: Block;
>body : Block
>Block : Block
}
interface MergedAccessorDeclarations {
>MergedAccessorDeclarations : MergedAccessorDeclarations

getAccessor: AccessorDeclaration;
>getAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

setAccessor: AccessorDeclaration;
>setAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

firstAccessor: AccessorDeclaration;
>firstAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

secondAccessor: AccessorDeclaration;
>secondAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
>IndexSignatureDeclaration : IndexSignatureDeclaration
Expand Down
6 changes: 0 additions & 6 deletions tests/baselines/reference/APISample_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,6 @@ declare module "typescript" {
_accessorDeclarationBrand: any;
body: Block;
}
interface MergedAccessorDeclarations {
getAccessor: AccessorDeclaration;
setAccessor: AccessorDeclaration;
firstAccessor: AccessorDeclaration;
secondAccessor: AccessorDeclaration;
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
_indexSignatureDeclarationBrand: any;
}
Expand Down
19 changes: 0 additions & 19 deletions tests/baselines/reference/APISample_watcher.types
Original file line number Diff line number Diff line change
Expand Up @@ -1709,25 +1709,6 @@ declare module "typescript" {
body: Block;
>body : Block
>Block : Block
}
interface MergedAccessorDeclarations {
>MergedAccessorDeclarations : MergedAccessorDeclarations

getAccessor: AccessorDeclaration;
>getAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

setAccessor: AccessorDeclaration;
>setAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

firstAccessor: AccessorDeclaration;
>firstAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration

secondAccessor: AccessorDeclaration;
>secondAccessor : AccessorDeclaration
>AccessorDeclaration : AccessorDeclaration
}
interface IndexSignatureDeclaration extends SignatureDeclaration, ClassElement {
>IndexSignatureDeclaration : IndexSignatureDeclaration
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/declarationEmitDefaultExport2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default class {
}

//// [declarationEmitDefaultExport2.js]
export default class {
export default class {
}


Expand Down

0 comments on commit a60d591

Please sign in to comment.