1/* 2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { updateNodeByNode } from "../utilities/private" 17import { 18 ArrowFunctionExpression, 19 AssignmentExpression, 20 CallExpression, 21 ETSParameterExpression, 22 EtsScript, 23 ExpressionStatement, 24 FunctionDeclaration, 25 FunctionExpression, 26 IfStatement, 27 MethodDefinition, 28 NumberLiteral, 29 StructDeclaration, 30 VariableDeclaration, 31 VariableDeclarator, 32 ETSStringLiteralType 33} from "../types" 34import { MemberExpression } from "../to-be-generated/MemberExpression" 35import { AstNode } from "../peers/AstNode" 36import { 37 AnnotationUsage, 38 BinaryExpression, 39 BlockStatement, 40 ClassDeclaration, 41 ClassDefinition, 42 ClassProperty, 43 ConditionalExpression, 44 ETSImportDeclaration, 45 ETSFunctionType, 46 ETSPrimitiveType, 47 ETSTypeReference, 48 ETSTypeReferencePart, 49 ETSUndefinedType, 50 ETSUnionType, 51 FunctionSignature, 52 Identifier, 53 ImportSpecifier, 54 NullLiteral, 55 ReturnStatement, 56 ScriptFunction, 57 StringLiteral, 58 SuperExpression, 59 ThisExpression, 60 TSInterfaceBody, 61 TSInterfaceDeclaration, 62 TSNonNullExpression, 63 TSTypeParameter, 64 TSTypeParameterDeclaration, 65 TSTypeParameterInstantiation, 66 TypeNode, 67 UndefinedLiteral, 68 TSAsExpression, 69 TSTypeAliasDeclaration, 70 ChainExpression, 71 BlockExpression, 72 ETSNewClassInstanceExpression, 73 BooleanLiteral, 74 ObjectExpression, 75 Property, 76 TemplateLiteral, 77 ArrayExpression, 78 TryStatement, 79 ForUpdateStatement, 80 ForInStatement, 81 ForOfStatement, 82} from "../../generated" 83import { 84 Es2pandaModifierFlags 85} from "../../generated/Es2pandaEnums" 86import { 87 classPropertySetOptional, 88 hasModifierFlag 89} from "../utilities/public" 90import { updateIdentifier } from "../node-utilities/Identifier" 91import { updateCallExpression } from "../node-utilities/CallExpression" 92import { updateExpressionStatement } from "../node-utilities/ExpressionStatement" 93import { updateMemberExpression } from "../node-utilities/MemberExpression" 94import { updateFunctionDeclaration } from "../node-utilities/FunctionDeclaration" 95import { updateBlockStatement } from "../node-utilities/BlockStatement" 96import { updateArrowFunctionExpression } from "../node-utilities/ArrowFunctionExpression" 97import { updateScriptFunction } from "../node-utilities/ScriptFunction" 98import { updateStringLiteral } from "../node-utilities/StringLiteral" 99import { updateNumberLiteral } from "../node-utilities/NumberLiteral" 100import { updateETSParameterExpression } from "../node-utilities/ETSParameterExpression" 101import { updateTSTypeParameter } from "../node-utilities/TSTypeParameter" 102import { updateTSTypeParameterDeclaration } from "../node-utilities/TSTypeParameterDeclaration" 103import { updateETSPrimitiveType } from "../node-utilities/ETSPrimitiveType" 104import { updateETSTypeReference } from "../node-utilities/ETSTypeReference" 105import { updateETSTypeReferencePart } from "../node-utilities/ETSTypeReferencePart" 106import { updateETSImportDeclaration } from "../node-utilities/ETSImportDeclaration" 107import { updateImportSpecifier } from "../node-utilities/ImportSpecifier" 108import { updateVariableDeclaration } from "../node-utilities/VariableDeclaration" 109import { updateVariableDeclarator } from "../node-utilities/VariableDeclarator" 110import { updateETSUnionType } from "../node-utilities/ETSUnionType" 111import { updateReturnStatement } from "../node-utilities/ReturnStatement" 112import { updateIfStatement } from "../node-utilities/IfStatement" 113import { updateBinaryExpression } from "../node-utilities/BinaryExpression" 114import { updateClassDeclaration } from "../node-utilities/ClassDeclaration" 115import { updateStructDeclaration } from "../node-utilities/StructDeclaration" 116import { updateClassDefinition } from "../node-utilities/ClassDefinition" 117import { updateClassProperty } from "../node-utilities/ClassProperty" 118import { updateETSFunctionType } from "../node-utilities/ETSFunctionType" 119import { updateFunctionExpression } from "../node-utilities/FunctionExpression" 120import { updateMethodDefinition } from "../node-utilities/MethodDefinition" 121import { updateSuperExpression } from "../node-utilities/SuperExpression" 122import { updateTSTypeParameterInstantiation } from "../node-utilities/TSTypeParameterInstantiation" 123import { updateTSInterfaceDeclaration } from "../node-utilities/TSInterfaceDeclaration" 124import { updateTSInterfaceBody } from "../node-utilities/TSInterfaceBody" 125import { updateUndefinedLiteral } from "../node-utilities/UndefinedLiteral" 126import { updateAnnotationUsage, update1AnnotationUsage } from "../node-utilities/AnnotationUsage" 127import { updateAssignmentExpression } from "../node-utilities/AssignmentExpression" 128import { updateETSUndefinedType } from "../node-utilities/ETSUndefinedType" 129import { updateConditionalExpression } from "../node-utilities/ConditionalExpression" 130import { updateTSAsExpression } from "../node-utilities/TSAsExpression" 131import { updateThisExpression } from "../node-utilities/ThisExpression" 132import { updateTSTypeAliasDeclaration } from "../node-utilities/TSTypeAliasDeclaration" 133import { updateTSNonNullExpression } from "../node-utilities/TSNonNullExpression" 134import { updateChainExpression } from "../node-utilities/ChainExpression" 135import { updateBlockExpression } from "../node-utilities/BlockExpression" 136import { updateNullLiteral } from "../node-utilities/NullLiteral" 137import { updateETSNewClassInstanceExpression } from "../node-utilities/ETSNewClassInstanceExpression" 138import { updateObjectExpression } from "../node-utilities/ObjectExpression" 139import { updateProperty } from "../node-utilities/Property" 140import { updateTemplateLiteral } from "../node-utilities/TemplateLiteral" 141import { updateArrayExpression } from "../node-utilities/ArrayExpression"; 142import { updateTryStatement } from '../node-utilities/TryStatement'; 143import { updateForUpdateStatement } from '../node-utilities/ForUpdateStatement'; 144import { updateForInStatement } from '../node-utilities/ForInStatement'; 145import { updateForOfStatement } from '../node-utilities/ForOfStatement'; 146 147export const factory = { 148 get createIdentifier() { 149 return Identifier.create2Identifier 150 }, 151 get updateIdentifier() { 152 return updateIdentifier 153 }, 154 get createCallExpression() { 155 return CallExpression.create 156 }, 157 get updateCallExpression() { 158 return updateCallExpression 159 }, 160 get createExpressionStatement() { 161 return ExpressionStatement.create 162 }, 163 get updateExpressionStatement() { 164 return updateExpressionStatement 165 }, 166 get createMemberExpression() { 167 return MemberExpression.create 168 }, 169 get updateMemberExpression() { 170 return updateMemberExpression 171 }, 172 get createEtsScript() { 173 return EtsScript.createFromSource 174 }, 175 get updateEtsScript() { 176 return EtsScript.updateByStatements 177 }, 178 get createFunctionDeclaration() { 179 return FunctionDeclaration.create 180 }, 181 get updateFunctionDeclaration() { 182 return updateFunctionDeclaration 183 }, 184 get createBlock() { 185 return BlockStatement.createBlockStatement 186 }, 187 get updateBlock() { 188 return updateBlockStatement 189 }, 190 get createArrowFunction() { 191 return ArrowFunctionExpression.create 192 }, 193 get updateArrowFunction() { 194 return updateArrowFunctionExpression 195 }, 196 get createScriptFunction() { 197 return ScriptFunction.createScriptFunction 198 }, 199 get updateScriptFunction() { 200 return updateScriptFunction 201 }, 202 get createStringLiteral() { 203 return StringLiteral.create1StringLiteral 204 }, 205 get updateStringLiteral() { 206 return updateStringLiteral 207 }, 208 get create1StringLiteral() { 209 return StringLiteral.create1StringLiteral 210 }, 211 get update1StringLiteral() { 212 return updateStringLiteral 213 }, 214 get createNumericLiteral() { 215 return NumberLiteral.create 216 }, 217 get updateNumericLiteral() { 218 return updateNumberLiteral 219 }, 220 get createParameterDeclaration() { 221 return ETSParameterExpression.create 222 }, 223 get updateParameterDeclaration() { 224 return updateETSParameterExpression 225 }, 226 get createTypeParameter() { 227 return TSTypeParameter.createTSTypeParameter 228 }, 229 get updateTypeParameter() { 230 return updateTSTypeParameter 231 }, 232 get createTypeParameterDeclaration() { 233 return TSTypeParameterDeclaration.createTSTypeParameterDeclaration 234 }, 235 get updateTypeParameterDeclaration() { 236 return updateTSTypeParameterDeclaration 237 }, 238 get createPrimitiveType() { 239 return ETSPrimitiveType.createETSPrimitiveType 240 }, 241 get updatePrimitiveType() { 242 return updateETSPrimitiveType 243 }, 244 get createTypeReference() { 245 return ETSTypeReference.createETSTypeReference 246 }, 247 get updateTypeReference() { 248 return updateETSTypeReference 249 }, 250 get createTypeReferencePart() { 251 return ETSTypeReferencePart.createETSTypeReferencePart 252 }, 253 get updateTypeReferencePart() { 254 return updateETSTypeReferencePart 255 }, 256 get createImportDeclaration() { 257 return ETSImportDeclaration.createETSImportDeclaration 258 }, 259 get updateImportDeclaration() { 260 return updateETSImportDeclaration 261 }, 262 get createImportSpecifier() { 263 return ImportSpecifier.createImportSpecifier 264 }, 265 get updateImportSpecifier() { 266 return updateImportSpecifier 267 }, 268 get createVariableDeclaration() { 269 return VariableDeclaration.create 270 }, 271 get updateVariableDeclaration() { 272 return updateVariableDeclaration 273 }, 274 get createVariableDeclarator() { 275 return VariableDeclarator.create 276 }, 277 get updateVariableDeclarator() { 278 return updateVariableDeclarator 279 }, 280 get createUnionType() { 281 return ETSUnionType.createETSUnionType 282 }, 283 get updateUnionType() { 284 return updateETSUnionType 285 }, 286 get createReturnStatement() { 287 return ReturnStatement.create1ReturnStatement 288 }, 289 get updateReturnStatement() { 290 return updateReturnStatement 291 }, 292 get createIfStatement() { 293 return IfStatement.create 294 }, 295 get updateIfStatement() { 296 return updateIfStatement 297 }, 298 get createBinaryExpression() { 299 return BinaryExpression.createBinaryExpression 300 }, 301 get updateBinaryExpression() { 302 return updateBinaryExpression 303 }, 304 get createClassDeclaration() { 305 return ClassDeclaration.createClassDeclaration 306 }, 307 get updateClassDeclaration() { 308 return updateClassDeclaration 309 }, 310 get createStructDeclaration() { 311 return StructDeclaration.create 312 }, 313 get updateStructDeclaration() { 314 return updateStructDeclaration 315 }, 316 get createClassDefinition() { 317 return ClassDefinition.createClassDefinition 318 }, 319 get updateClassDefinition() { 320 return updateClassDefinition 321 }, 322 get createClassProperty() { 323 return ClassProperty.createClassProperty 324 }, 325 get updateClassProperty() { 326 return updateClassProperty 327 }, 328 get createFunctionType() { 329 return ETSFunctionType.createETSFunctionType 330 }, 331 get updateFunctionType() { 332 return updateETSFunctionType 333 }, 334 get createFunctionExpression() { 335 return FunctionExpression.create 336 }, 337 get updateFunctionExpression() { 338 return updateFunctionExpression 339 }, 340 get createMethodDefinition() { 341 return MethodDefinition.create 342 }, 343 get updateMethodDefinition() { 344 return updateMethodDefinition 345 }, 346 get createSuperExpression() { 347 return SuperExpression.createSuperExpression 348 }, 349 get updateSuperExpression() { 350 return updateSuperExpression 351 }, 352 get createTSTypeParameterInstantiation() { 353 return TSTypeParameterInstantiation.createTSTypeParameterInstantiation 354 }, 355 get updateTSTypeParameterInstantiation() { 356 return updateTSTypeParameterInstantiation 357 }, 358 get createInterfaceDeclaration() { 359 return TSInterfaceDeclaration.createTSInterfaceDeclaration 360 }, 361 get updateInterfaceDeclaration() { 362 return updateTSInterfaceDeclaration 363 }, 364 get createInterfaceBody() { 365 return TSInterfaceBody.createTSInterfaceBody 366 }, 367 get updateInterfaceBody() { 368 return updateTSInterfaceBody 369 }, 370 get createUndefinedLiteral() { 371 return UndefinedLiteral.createUndefinedLiteral 372 }, 373 get updateUndefinedLiteral() { 374 return updateUndefinedLiteral 375 }, 376 get createAnnotationUsage() { 377 return AnnotationUsage.createAnnotationUsage 378 }, 379 get updateAnnotationUsage() { 380 return updateAnnotationUsage 381 }, 382 get create1AnnotationUsage(): (...args: Parameters<typeof AnnotationUsage.create1AnnotationUsage>) => AnnotationUsage { 383 return AnnotationUsage.create1AnnotationUsage; 384 }, 385 get update1AnnotationUsage(): (...args: Parameters<typeof update1AnnotationUsage>) => AnnotationUsage { 386 return update1AnnotationUsage; 387 }, 388 get createAssignmentExpression() { 389 return AssignmentExpression.create 390 }, 391 get updateAssignmentExpression() { 392 return updateAssignmentExpression 393 }, 394 get createETSUndefinedType() { 395 return ETSUndefinedType.createETSUndefinedType 396 }, 397 get updateETSUndefinedType() { 398 return updateETSUndefinedType 399 }, 400 get createFunctionSignature() { 401 return FunctionSignature.createFunctionSignature 402 }, 403 get createConditionalExpression() { 404 return ConditionalExpression.createConditionalExpression 405 }, 406 get updateConditionalExpression() { 407 return updateConditionalExpression 408 }, 409 get createTSAsExpression() { 410 return TSAsExpression.createTSAsExpression 411 }, 412 get updateTSAsExpression() { 413 return updateTSAsExpression 414 }, 415 get createThisExpression() { 416 return ThisExpression.createThisExpression 417 }, 418 get updateThisExpression() { 419 return updateThisExpression 420 }, 421 get createTSTypeAliasDeclaration() { 422 return TSTypeAliasDeclaration.createTSTypeAliasDeclaration 423 }, 424 get updateTSTypeAliasDeclaration() { 425 return updateTSTypeAliasDeclaration 426 }, 427 get createTSNonNullExpression() { 428 return TSNonNullExpression.createTSNonNullExpression 429 }, 430 get updateTSNonNullExpression() { 431 return updateTSNonNullExpression 432 }, 433 get createChainExpression() { 434 return ChainExpression.createChainExpression 435 }, 436 get updateChainExpression() { 437 return updateChainExpression 438 }, 439 get createBlockExpression() { 440 return BlockExpression.createBlockExpression 441 }, 442 get updateBlockExpression() { 443 return updateBlockExpression 444 }, 445 get createNullLiteral() { 446 return NullLiteral.createNullLiteral 447 }, 448 get updateNullLiteral() { 449 return updateNullLiteral 450 }, 451 get createETSNewClassInstanceExpression() { 452 return ETSNewClassInstanceExpression.createETSNewClassInstanceExpression 453 }, 454 get updateETSNewClassInstanceExpression() { 455 return updateETSNewClassInstanceExpression 456 }, 457 get createETSStringLiteralType() { 458 return ETSStringLiteralType.create; 459 }, 460 get createBooleanLiteral(): (...args: Parameters<typeof BooleanLiteral.createBooleanLiteral>) => BooleanLiteral { 461 return BooleanLiteral.createBooleanLiteral; 462 }, 463 get createObjectExpression(): (...args: Parameters<typeof ObjectExpression.createObjectExpression>) => ObjectExpression { 464 return ObjectExpression.createObjectExpression; 465 }, 466 get updateObjectExpression(): (...args: Parameters<typeof updateObjectExpression>) => ObjectExpression { 467 return updateObjectExpression; 468 }, 469 get createProperty(): (...args: Parameters<typeof Property.createProperty>) => Property { 470 return Property.createProperty; 471 }, 472 get updateProperty(): (...args: Parameters<typeof updateProperty>) => Property { 473 return updateProperty; 474 }, 475 get createTemplateLiteral(): (...args: Parameters<typeof TemplateLiteral.createTemplateLiteral>) => TemplateLiteral { 476 return TemplateLiteral.createTemplateLiteral; 477 }, 478 get updateTemplateLiteral(): (...args: Parameters<typeof updateTemplateLiteral>) => TemplateLiteral { 479 return updateTemplateLiteral; 480 }, 481 get createArrayExpression(): (...args: Parameters<typeof ArrayExpression.createArrayExpression>) => ArrayExpression { 482 return ArrayExpression.createArrayExpression; 483 }, 484 get updateArrayExpression(): (...args: Parameters<typeof updateArrayExpression>) => ArrayExpression { 485 return updateArrayExpression; 486 }, 487 get createTryStatement(): (...args: Parameters<typeof TryStatement.createTryStatement>) => TryStatement { 488 return TryStatement.createTryStatement; 489 }, 490 get updateTryStatement(): (...args: Parameters<typeof updateTryStatement>) => TryStatement { 491 return updateTryStatement; 492 }, 493 get createForUpdateStatement(): ( 494 ...args: Parameters<typeof ForUpdateStatement.createForUpdateStatement> 495 ) => ForUpdateStatement { 496 return ForUpdateStatement.createForUpdateStatement; 497 }, 498 get updateForUpdateStatement(): (...args: Parameters<typeof updateForUpdateStatement>) => ForUpdateStatement { 499 return updateForUpdateStatement; 500 }, 501 get createForInStatement(): (...args: Parameters<typeof ForInStatement.createForInStatement>) => ForInStatement { 502 return ForInStatement.createForInStatement; 503 }, 504 get updateForInStatement(): (...args: Parameters<typeof updateForInStatement>) => ForInStatement { 505 return updateForInStatement; 506 }, 507 get createForOfStatement(): (...args: Parameters<typeof ForOfStatement.createForOfStatement>) => ForOfStatement { 508 return ForOfStatement.createForOfStatement; 509 }, 510 get updateForOfStatement(): (...args: Parameters<typeof updateForOfStatement>) => ForOfStatement { 511 return updateForOfStatement; 512 }, 513 /** @deprecated */ 514 createTypeParameter1_(name: Identifier, constraint?: TypeNode, defaultType?: TypeNode) { 515 return TSTypeParameter.createTSTypeParameter(Identifier.create1Identifier(name.name), constraint, defaultType) 516 }, 517} 518