99import ts from 'typescript' ;
1010
1111/** Whether the current TypeScript version is after 4.8. */
12- export const IS_AFTER_TS_48 = isAfterVersion ( 4 , 8 ) ;
12+ const IS_AFTER_TS_48 = isAfterVersion ( 4 , 8 ) ;
1313
1414/** Whether the current TypeScript version is after 4.7. */
1515const IS_AFTER_TS_47 = isAfterVersion ( 4 , 7 ) ;
@@ -91,6 +91,24 @@ export const updateClassDeclaration: Ts48UpdateClassDeclarationFn = IS_AFTER_TS_
9191 ts . factory . updateClassDeclaration as any ) (
9292 node , ...splitModifiers ( combinedModifiers ) , name , typeParameters , heritageClauses , members ) ;
9393
94+ /** Type of `ts.factory.createClassDeclaration` in TS 4.8+. */
95+ type Ts48CreateClassDeclarationFn =
96+ ( modifiers : readonly ModifierLike [ ] | undefined , name : ts . Identifier | undefined ,
97+ typeParameters : readonly ts . TypeParameterDeclaration [ ] | undefined ,
98+ heritageClauses : readonly ts . HeritageClause [ ] | undefined ,
99+ members : readonly ts . ClassElement [ ] ) => ts . ClassDeclaration ;
100+
101+ /**
102+ * Creates a `ts.ClassDeclaration` declaration.
103+ *
104+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
105+ * We should remove it once we have dropped support for the older versions.
106+ */
107+ export const createClassDeclaration : Ts48CreateClassDeclarationFn = IS_AFTER_TS_48 ?
108+ ( ts . factory . createClassDeclaration as any ) :
109+ ( combinedModifiers , name , typeParameters , heritageClauses , members ) =>
110+ ( ts . factory . createClassDeclaration as any ) (
111+ ...splitModifiers ( combinedModifiers ) , name , typeParameters , heritageClauses , members ) ;
94112
95113/** Type of `ts.factory.updateMethodDeclaration` in TS 4.8+. */
96114type Ts48UpdateMethodDeclarationFn =
@@ -114,6 +132,26 @@ export const updateMethodDeclaration: Ts48UpdateMethodDeclarationFn = IS_AFTER_T
114132 node , ...splitModifiers ( modifiers ) , asteriskToken , name , questionToken , typeParameters ,
115133 parameters , type , body ) ;
116134
135+ /** Type of `ts.factory.createMethodDeclaration` in TS 4.8+. */
136+ type Ts48CreateMethodDeclarationFn =
137+ ( modifiers : readonly ModifierLike [ ] | undefined , asteriskToken : ts . AsteriskToken | undefined ,
138+ name : ts . PropertyName , questionToken : ts . QuestionToken | undefined ,
139+ typeParameters : readonly ts . TypeParameterDeclaration [ ] | undefined ,
140+ parameters : readonly ts . ParameterDeclaration [ ] , type : ts . TypeNode | undefined ,
141+ body : ts . Block | undefined ) => ts . MethodDeclaration ;
142+
143+ /**
144+ * Creates a `ts.MethodDeclaration` declaration.
145+ *
146+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
147+ * We should remove it once we have dropped support for the older versions.
148+ */
149+ export const createMethodDeclaration : Ts48CreateMethodDeclarationFn = IS_AFTER_TS_48 ?
150+ ( ts . factory . createMethodDeclaration as any ) :
151+ ( modifiers , asteriskToken , name , questionToken , typeParameters , parameters , type , body ) =>
152+ ( ts . factory . createMethodDeclaration as any ) (
153+ ...splitModifiers ( modifiers ) , asteriskToken , name , questionToken , typeParameters ,
154+ parameters , type , body ) ;
117155
118156/** Type of `ts.factory.updatePropertyDeclaration` in TS 4.8+. */
119157type Ts48UpdatePropertyDeclarationFn =
@@ -153,15 +191,12 @@ export const createPropertyDeclaration: Ts48CreatePropertyDeclarationFn = IS_AFT
153191 ( ts . factory . createPropertyDeclaration as any ) (
154192 ...splitModifiers ( modifiers ) , name , questionOrExclamationToken , type , initializer ) ;
155193
156-
157-
158194/** Type of `ts.factory.updateGetAccessorDeclaration` in TS 4.8+. */
159195type Ts48UpdateGetAccessorDeclarationFn =
160196 ( node : ts . GetAccessorDeclaration , modifiers : readonly ModifierLike [ ] | undefined ,
161197 name : ts . PropertyName , parameters : readonly ts . ParameterDeclaration [ ] ,
162198 type : ts . TypeNode | undefined , body : ts . Block | undefined ) => ts . GetAccessorDeclaration ;
163199
164-
165200/**
166201 * Updates a `ts.GetAccessorDeclaration` declaration.
167202 *
@@ -174,6 +209,23 @@ export const updateGetAccessorDeclaration: Ts48UpdateGetAccessorDeclarationFn =
174209 ( ts . factory . updateGetAccessorDeclaration as any ) (
175210 node , ...splitModifiers ( modifiers ) , name , parameters , type , body ) ;
176211
212+ /** Type of `ts.factory.createGetAccessorDeclaration` in TS 4.8+. */
213+ type Ts48CreateGetAccessorDeclarationFn =
214+ ( modifiers : readonly ModifierLike [ ] | undefined , name : ts . PropertyName ,
215+ parameters : readonly ts . ParameterDeclaration [ ] , type : ts . TypeNode | undefined ,
216+ body : ts . Block | undefined ) => ts . GetAccessorDeclaration ;
217+
218+ /**
219+ * Creates a `ts.GetAccessorDeclaration` declaration.
220+ *
221+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
222+ * We should remove it once we have dropped support for the older versions.
223+ */
224+ export const createGetAccessorDeclaration : Ts48CreateGetAccessorDeclarationFn = IS_AFTER_TS_48 ?
225+ ( ts . factory . createGetAccessorDeclaration as any ) :
226+ ( modifiers , name , parameters , type , body ) => ( ts . factory . createGetAccessorDeclaration as any ) (
227+ ...splitModifiers ( modifiers ) , name , parameters , type , body ) ;
228+
177229/** Type of `ts.factory.updateSetAccessorDeclaration` in TS 4.8+. */
178230type Ts48UpdateSetAccessorDeclarationFn =
179231 ( node : ts . SetAccessorDeclaration , modifiers : readonly ModifierLike [ ] | undefined ,
@@ -191,7 +243,22 @@ export const updateSetAccessorDeclaration: Ts48UpdateSetAccessorDeclarationFn =
191243 ( node , modifiers , name , parameters , body ) => ( ts . factory . updateSetAccessorDeclaration as any ) (
192244 node , ...splitModifiers ( modifiers ) , name , parameters , body ) ;
193245
246+ /** Type of `ts.factory.createSetAccessorDeclaration` in TS 4.8+. */
247+ type Ts48CreateSetAccessorDeclarationFn =
248+ ( modifiers : readonly ModifierLike [ ] | undefined , name : ts . PropertyName ,
249+ parameters : readonly ts . ParameterDeclaration [ ] , body : ts . Block | undefined ) =>
250+ ts . SetAccessorDeclaration ;
194251
252+ /**
253+ * Creates a `ts.GetAccessorDeclaration` declaration.
254+ *
255+ * TODO(crisbeto): this is a backwards-compatibility layer for versions of TypeScript less than 4.8.
256+ * We should remove it once we have dropped support for the older versions.
257+ */
258+ export const createSetAccessorDeclaration : Ts48CreateSetAccessorDeclarationFn = IS_AFTER_TS_48 ?
259+ ( ts . factory . createSetAccessorDeclaration as any ) :
260+ ( modifiers , name , parameters , body ) => ( ts . factory . createSetAccessorDeclaration as any ) (
261+ ...splitModifiers ( modifiers ) , name , parameters , body ) ;
195262
196263/** Type of `ts.factory.updateConstructorDeclaration` in TS 4.8+. */
197264type Ts48UpdateConstructorDeclarationFn =
0 commit comments