@@ -24,6 +24,7 @@ import { IdTsDsl } from './expr/id';
2424import { LiteralTsDsl } from './expr/literal' ;
2525import { NewTsDsl } from './expr/new' ;
2626import { ObjectTsDsl } from './expr/object' ;
27+ import { PostfixTsDsl } from './expr/postfix' ;
2728import { PrefixTsDsl } from './expr/prefix' ;
2829import { ObjectPropTsDsl } from './expr/prop' ;
2930import { RegExpTsDsl } from './expr/regexp' ;
@@ -35,6 +36,8 @@ import { HintTsDsl } from './layout/hint';
3536import { NewlineTsDsl } from './layout/newline' ;
3637import { NoteTsDsl } from './layout/note' ;
3738import { BlockTsDsl } from './stmt/block' ;
39+ import type { ForCondition , ForIterable , ForMode } from './stmt/for' ;
40+ import { ForTsDsl } from './stmt/for' ;
3841import { IfTsDsl } from './stmt/if' ;
3942import { ReturnTsDsl } from './stmt/return' ;
4043import { StmtTsDsl } from './stmt/stmt' ;
@@ -88,6 +91,9 @@ const tsDsl = {
8891 /** Creates a constant variable declaration (`const`). */
8992 const : ( ...args : ConstructorParameters < typeof VarTsDsl > ) => new VarTsDsl ( ...args ) . const ( ) ,
9093
94+ /** Creates a postfix decrement expression (`i--`). */
95+ dec : ( ...args : ConstructorParameters < typeof PostfixTsDsl > ) => new PostfixTsDsl ( ...args ) . dec ( ) ,
96+
9197 /** Creates a decorator expression (e.g. `@decorator`). */
9298 decorator : ( ...args : ConstructorParameters < typeof DecoratorTsDsl > ) => new DecoratorTsDsl ( ...args ) ,
9399
@@ -103,14 +109,28 @@ const tsDsl = {
103109 /** Creates a field declaration in a class or object. */
104110 field : ( ...args : ConstructorParameters < typeof FieldTsDsl > ) => new FieldTsDsl ( ...args ) ,
105111
112+ /** Creates a for loop (for, for...of, for...in, or for await...of). */
113+ for : ( ( ...args : ReadonlyArray < any > ) => new ForTsDsl ( ...args ) ) as {
114+ ( variableOrInit ?: VarTsDsl ) : ForTsDsl < ForMode > ;
115+ (
116+ variableOrInit : VarTsDsl ,
117+ condition : ForCondition ,
118+ iterableOrUpdate ?: ForIterable ,
119+ ) : ForTsDsl < 'for' > ;
120+ < T extends ForMode > (
121+ variableOrInit : VarTsDsl ,
122+ mode : T ,
123+ iterableOrUpdate ?: ForIterable ,
124+ ) : ForTsDsl < T > ;
125+ } ,
126+
106127 /** Converts a runtime value into a corresponding expression node. */
107128 fromValue : ( ...args : Parameters < typeof exprValue > ) => exprValue ( ...args ) ,
108129
109130 /** Creates a function expression or declaration. */
110131 func : ( ( nameOrFn ?: any , fn ?: any ) => {
111132 if ( nameOrFn === undefined ) return new FuncTsDsl ( ) ;
112- if ( typeof nameOrFn !== 'string' ) return new FuncTsDsl ( nameOrFn ) ;
113- if ( fn === undefined ) return new FuncTsDsl ( nameOrFn ) ;
133+ if ( typeof nameOrFn !== 'string' || fn === undefined ) return new FuncTsDsl ( nameOrFn ) ;
114134 return new FuncTsDsl ( nameOrFn , fn ) ;
115135 } ) as {
116136 ( ) : FuncTsDsl < 'arrow' > ;
@@ -132,6 +152,9 @@ const tsDsl = {
132152 /** Creates an if statement. */
133153 if : ( ...args : ConstructorParameters < typeof IfTsDsl > ) => new IfTsDsl ( ...args ) ,
134154
155+ /** Creates a postfix increment expression (`i++`). */
156+ inc : ( ...args : ConstructorParameters < typeof PostfixTsDsl > ) => new PostfixTsDsl ( ...args ) . inc ( ) ,
157+
135158 /** Creates an initialization block or statement. */
136159 init : ( ...args : ConstructorParameters < typeof InitTsDsl > ) => new InitTsDsl ( ...args ) ,
137160
0 commit comments