Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
fix(utils): placeholders should be the frontest
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Jul 1, 2017
1 parent b9fc8cb commit cff4d79
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ exports[`should generate correctly with curried types 1`] = `
*/
declare const $: $_000;
type $_000 = {
(a: boolean, _b: PH, c: string): $_101;
(_a: PH, b: number, c: string): $_011;
(_a: PH, _b: PH, c: string): $_001;
(_a: PH, b: number, c: string): $_011;
(a: boolean, _b: PH, c: string): $_101;
(a: boolean, b: number, c: string): $_111;
(_a: PH, b: number): $_010;
(a: boolean, b: number): $_110;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ interface CurriedFunction2<T1, T2, R> {
(v1: T1): CurriedFunction1<T2, R>;
}
interface CurriedFunction3<T1, T2, T3, R> {
(v1: T1, _2: PH, v3: T3): CurriedFunction1<T2, R>;
(_1: PH, v2: T2, v3: T3): CurriedFunction1<T1, R>;
(_1: PH, _2: PH, v3: T3): CurriedFunction2<T1, T2, R>;
(_1: PH, v2: T2, v3: T3): CurriedFunction1<T1, R>;
(v1: T1, _2: PH, v3: T3): CurriedFunction1<T2, R>;
(v1: T1, v2: T2, v3: T3): R;
(_1: PH, v2: T2): CurriedFunction2<T1, T3, R>;
(v1: T1, v2: T2): CurriedFunction1<T3, R>;
<$SEL extends \\"101\\">(): (v1: T1, _2: PH, v3: T3) => CurriedFunction1<T2, R>;
<$SEL extends \\"011\\">(): (_1: PH, v2: T2, v3: T3) => CurriedFunction1<T1, R>;
<$SEL extends \\"001\\">(): (_1: PH, _2: PH, v3: T3) => CurriedFunction2<T1, T2, R>;
<$SEL extends \\"011\\">(): (_1: PH, v2: T2, v3: T3) => CurriedFunction1<T1, R>;
<$SEL extends \\"101\\">(): (v1: T1, _2: PH, v3: T3) => CurriedFunction1<T2, R>;
<$SEL extends \\"111\\">(): (v1: T1, v2: T2, v3: T3) => R;
<$SEL extends \\"01\\">(): (_1: PH, v2: T2) => CurriedFunction2<T1, T3, R>;
<$SEL extends \\"11\\">(): (v1: T1, v2: T2) => CurriedFunction1<T3, R>;
Expand All @@ -41,9 +41,9 @@ interface CurriedFunction2<T1, T2, R> {
(v1: T1): CurriedFunction1<T2, R>;
}
interface CurriedFunction3<T1, T2, T3, R> {
(v1: T1, _2: PH, v3: T3): CurriedFunction1<T2, R>;
(_1: PH, v2: T2, v3: T3): CurriedFunction1<T1, R>;
(_1: PH, _2: PH, v3: T3): CurriedFunction2<T1, T2, R>;
(_1: PH, v2: T2, v3: T3): CurriedFunction1<T1, R>;
(v1: T1, _2: PH, v3: T3): CurriedFunction1<T2, R>;
(v1: T1, v2: T2, v3: T3): R;
(_1: PH, v2: T2): CurriedFunction2<T1, T3, R>;
(v1: T1, v2: T2): CurriedFunction1<T3, R>;
Expand Down
14 changes: 13 additions & 1 deletion templates/utils/sort-signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@ export const sort_signatures = (signatures: dts.IObjectMember[]) => {
return (parameters_1.length !== parameters_2.length)
? get_length_order(parameters_2.length) - get_length_order(parameters_1.length)
// tslint:disable-next-line:strict-boolean-expressions
: (parameters_2.findIndex(is_placeholder) - parameters_1.findIndex(is_placeholder)) || (normal1.index - normal2.index);
: get_function_order(parameters_2) - get_function_order(parameters_1) || (normal1.index - normal2.index);
}).map(normal => normal.value);
return [
...members.slice(0, -1),
...selectables,
...members.slice(-1),
];

function get_function_order(parameters: dts.IParameterDeclaration[]) {
let point = 0;

parameters.forEach((parameter, index) => {
if (!is_placeholder(parameter)) {
// tslint:disable-next-line:no-bitwise
point += 1 << (parameters.length - index);
}
});

return -point;
}
function is_placeholder(parameter: dts.IParameterDeclaration) {
return ((parameter.type as dts.IGeneralType).name === placeholder_name_abbr);
}
Expand Down

0 comments on commit cff4d79

Please sign in to comment.