11<!-- @[h1([pkg.name]), paragraph([pkg.description])]-->
2+
23# typescript-transform-macros
34
45Typescript Transform Macros
6+
57<!-- /@-->
68
79<!-- @shields("npm", "prettier", "ConventionalCommits", "spacemacs")-->
10+
811[ ![ npm version] ( https://img.shields.io/npm/v/typescript-transform-macros.svg )] ( https://www.npmjs.com/package/typescript-transform-macros ) [ ![ code style: prettier] ( https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square )] ( https://github.com/prettier/prettier ) [ ![ Conventional Commits] ( https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg )] ( https://conventionalcommits.org ) [ ![ Built with Spacemacs] ( https://raw.githubusercontent.com/syl20bnr/spacemacs/master/assets/spacemacs-badge.svg?sanitize=true )] ( http://spacemacs.org )
12+
913<!-- /@-->
1014
1115Examples from < https://github.com/codemix/babel-plugin-macros > .
1216
1317<!-- @installation()-->
18+
1419## Installation
1520
1621``` sh
1722npm install --save-dev typescript-transform-macros
1823```
24+
1925<!-- /@-->
2026
2127## Usage with [ ttypescript] ( https://github.com/cevek/ttypescript/ )
@@ -40,25 +46,11 @@ declare function MACRO<T>(t: T): T;
4046
4147_ Input:_
4248
43- <!-- @snippet("./src/__fixtures/input.ts")-->
49+ <!-- @snippet("./examples/ttypescript/index.ts")-->
50+
4451``` ts
4552declare function MACRO<T >(t : T ): T ;
4653
47- const FILTER = MACRO (
48- <T >(
49- inputConst : T [],
50- visitor : (value : T , index ? : number , input ? : T []) => boolean
51- ) => {
52- const input = inputConst ;
53- const length = input .length ;
54- const result = [];
55- for (let i = 0 ; i < length ; i ++ ) {
56- if (visitor (input [i ], i , input )) result .push (input [i ]);
57- }
58- return result ;
59- }
60- );
61-
6254const MAP = MACRO (
6355 < T , L > (
6456 inputConst : T [],
@@ -74,34 +66,25 @@ const MAP = MACRO(
7466 }
7567);
7668
77- function demo() {
78- return FILTER (MAP ([1 , 2 , 3 , 4 ], item => item + 1 ), v => v % 2 === 0 );
79- }
69+ console .log (MAP ([1 , 2 , 3 ], n => 3 * n + 1 ));
8070```
71+
8172<!-- /@-->
8273
8374_ Output:_
8475
85- <!-- @snippet("./src/__fixtures/expected.js")-->
76+ <!-- @example("./examples/ttypescript/index.js")-->
77+
8678``` js
87- function demo () {
88- const __input4 = [1 , 2 , 3 , 4 ];
89- const __length4 = __input4 .length ;
90- const __result4 = new Array (__length4);
91- for (let __i4 = 0 ; __i4 < __length4; __i4++ ) {
92- __result4[__i4] =
93- __input4[__i4]
94- + 1 ;
95- }
96- const __input2 = __result4;
97- const __length2 = __input2 .length ;
98- const __result2 = [];
99- for (let __i2 = 0 ; __i2 < __length2; __i2++ ) {
100- if (__input2[__i2]
101- % 2 === 0 )
102- __result2 .push (__input2[__i2]);
103- }
104- return __result2;
79+ " use strict" ;
80+ const __input2 = [1 , 2 , 3 ];
81+ const __length2 = __input2 .length ;
82+ const __result2 = new Array (__length2);
83+ for (let __i2 = 0 ; __i2 < __length2; __i2++ ) {
84+ __result2[__i2] = 3 * __input2[__i2] + 1 ;
10585}
86+ console .log (__result2);
87+ // > [ 4, 7, 10 ]
10688```
89+
10790<!-- /@-->
0 commit comments