import type ts from 'typescript' ; import type { ArrayLiteralExpression , BigIntLiteral , BinaryExpression , BinaryOperator , BinaryOperatorToken , Block , CallExpression , ColonToken , ConditionalExpression , ElementAccessExpression , OmittedExpression , Expression , ExpressionStatement , ForStatement , FunctionExpression , FunctionTypeNode , Identifier , IfStatement , ImportDeclaration , KeywordTypeNode , KeywordTypeSyntaxKind , LiteralType , MethodDeclaration , Node , NodeArray , NodeFlags , NullLiteral , NumericLiteral , ObjectLiteralElementLike , ObjectLiteralExpression , ParameterDeclaration , PostfixUnaryExpression , PostfixUnaryOperator , PrefixUnaryExpression , PrivateIdentifier , PropertyAccessExpression , PropertyAssignment , PropertyDeclaration , PropertyName , PropertySignature , PunctuationSyntaxKind , PunctuationToken , QuestionToken , ReturnStatement , SourceFile , SpreadElement , StringLiteral , TokenFlags , TypeElement , TypeLiteralNode , TypeNode , TypeQueryNode , TypeReferenceNode , VariableDeclaration , VariableDeclarationList , VariableStatement , VoidExpression , } from 'typescript' ; import { Statement } from 'typescript/lib/tsserverlibrary' ; import { core } from '../transformer/core/core' ; export function createArrayLiteral ( elements ? , multiLine ? ) { return core . ts . factory . createArrayLiteralExpression ( elements , multiLine ) ; } export function createVariableStatement ( declarationList ) { return core . ts . factory . createVariableStatement ( undefined , declarationList ) ; } export function createVariableDeclarationList ( declarations , flags ? ) { return core . ts . factory . createVariableDeclarationList ( declarations , flags ) ; } export function createIdentifier ( text ) { return core . ts . factory . createIdentifier ( text ) ; } export function createNumericLiteral ( value , numericLiteralFlags ? ) { return core . ts . factory . createNumericLiteral ( value , numericLiteralFlags ) ; } export function createArrowFunction ( block , parameter = [ ] ) { return core . ts . factory . createArrowFunction ( undefined , undefined , parameter , undefined , core . ts . factory . createToken ( core . ts . SyntaxKind . EqualsGreaterThanToken ) , block ) ; } export function createFunctionExpression ( block , parameter = [ ] ) { return core . ts . factory . createFunctionExpression ( undefined , undefined , undefined , undefined , parameter , undefined , block ) ; } export function createFunctionExpressionReturn ( descriptorToReturn , parameter = [ ] ) { const block = core . ts . factory . createBlock ( [ core . ts . factory . createReturnStatement ( descriptorToReturn ) , ] ) ; return core . ts . factory . createFunctionExpression ( undefined , undefined , undefined , undefined , parameter , undefined , block ) ; } export function createBlock ( statements , multiLine ? ) { return core . ts . factory . createBlock ( statements , multiLine ) ; } export function createReturnStatement ( expression ? ) { return core . ts . factory . createReturnStatement ( expression ) ; } export function createCall ( expression , argumentExpressions ) { return core . ts . factory . createCallExpression ( expression , undefined , argumentExpressions ) ; } export function createIIFE ( block ) { return createCall ( core . ts . factory . createParenthesizedExpression ( core . ts . factory . createFunctionExpression ( undefined , undefined , undefined , undefined , [ ] , undefined , block ) ) , [ ] ) ; } export function createEmptyProperty ( ) { return createProperty ( '' , undefined ) ; } export function createProperty ( propertyName , type ) { return core . ts . factory . createPropertyDeclaration ( undefined , undefined , propertyName , undefined , type , undefined ) ; } export function createPropertySignature ( propertyName , type ) { return core . ts . factory . createPropertySignature ( [ ] , propertyName , undefined , type ) ; } export function createParameter ( parameterName ) { return core . ts . factory . createParameterDeclaration ( undefined , undefined , undefined , createIdentifier ( parameterName ) , undefined , undefined , undefined ) ; } export function createParameterFromIdentifier ( identifier ) { return core . ts . factory . createParameterDeclaration ( undefined , undefined , undefined , identifier , undefined , undefined , undefined ) ; } export function createMethod ( methodName , body , parameterNames = [ ] ) { const parameters = parameterNames . map ( ( parameterName ) => core . ts . factory . createParameterDeclaration ( undefined , undefined , undefined , parameterName , undefined , undefined , undefined ) ) ; return core . ts . factory . createMethodDeclaration ( undefined , undefined , undefined , createIdentifier ( methodName ) , undefined , undefined , parameters , undefined , body ) ; } export function createVariableDeclaration ( variableIdentifier , initializer ) { return core . ts . factory . createVariableDeclaration ( variableIdentifier , undefined , undefined , initializer ) ; } export function createPropertyAccess ( expression , name ) { return core . ts . factory . createPropertyAccessExpression ( expression , name ) ; } export function createSpread ( expression ) { return core . ts . factory . createSpreadElement ( expression ) ; } export function createStringLiteral ( text ) { return core . ts . factory . createStringLiteral ( text ) ; } export function createLogicalNot ( operand ) { return core . ts . factory . createLogicalNot ( operand ) ; } export function createLiteral ( type ) { if ( typeof type . value === 'string' ) { return createStringLiteral ( type . value ) ; } if ( typeof type . value === 'number' ) { return createNumericLiteral ( type . value ) ; } return core . ts . factory . createBigIntLiteral ( type . value ) ; } export function createNodeArray < T extends Node > ( elements ? , hasTrailingComma ? ) { return core . ts . factory . createNodeArray ( elements , hasTrailingComma ) ; } export function createArrayTypeNode ( ) { return core . ts . factory . createArrayTypeNode ( core . ts . factory . createKeywordTypeNode ( core . ts . SyntaxKind . AnyKeyword ) ) ; } export function createTypeNode < TKind extends KeywordTypeSyntaxKind > ( kind ) { return core . ts . factory . createKeywordTypeNode ( kind ) ; } export function createFunctionTypeNode ( typeNode ) { return core . ts . factory . createFunctionTypeNode ( [ ] , [ ] , typeNode ) ; } export function createNode ( ) { return core . ts . factory . createKeywordTypeNode ( core . ts . SyntaxKind . NumberKeyword ) ; } export function createObjectLiteral ( properties ? , multiLine ? ) { return core . ts . factory . createObjectLiteralExpression ( properties , multiLine ) ; } export function createBinaryExpression ( left , operator , right ) { return core . ts . factory . createBinaryExpression ( left , operator , right ) ; } export function createPunctuationToken < TKind extends PunctuationSyntaxKind > ( token ) { return core . ts . factory . createToken ( token ) ; } export function createIfStatement ( expression , block ) { return core . ts . factory . createIfStatement ( expression , block , undefined ) ; } export function createReturn ( expression ) { return core . ts . factory . createReturnStatement ( expression ) ; } export function createExpressionStatement ( binaryExpression ) { return core . ts . factory . createExpressionStatement ( binaryExpression ) ; } export function createElementAccessExpression ( identifier , literalProperty ) { return core . ts . factory . createElementAccessExpression ( identifier , literalProperty ) ; } export function createPropertyAssignment ( name , expression ) { return core . ts . factory . createPropertyAssignment ( name , expression ) ; } export function createElementAccess ( expression , index ) { return core . ts . factory . createElementAccessExpression ( expression , index ) ; } export function createConditional ( condition , questionToken , whenTrue , colonToken , whenFalse ) { return core . ts . factory . createConditionalExpression ( condition , questionToken , whenTrue , colonToken , whenFalse ) ; } export function updateSourceFileNode ( node , statements ) { return core . ts . factory . updateSourceFile ( node , statements ) ; } export function createImportAllAs ( moduleName , filenameToImportFrom ) { return core . ts . factory . createImportDeclaration ( [ ] , [ ] , core . ts . factory . createImportClause ( false , undefined , core . ts . factory . createNamespaceImport ( moduleName ) ) , core . ts . factory . createStringLiteral ( filenameToImportFrom ) ) ; } export function createForStatement ( initializer , condition , incrementor , statement ) { return core . ts . factory . createForStatement ( initializer , condition , incrementor , statement ) ; } export function createPostfix ( operand , operator ) { return core . ts . factory . createPostfixUnaryExpression ( operand , operator ) ; } export function createOmittedExpression ( ) { return core . ts . factory . createOmittedExpression ( ) ; } export function createTypeReferenceNode ( identifier ) { return core . ts . factory . createTypeReferenceNode ( identifier , undefined ) ; } export function createNew ( expression ) { return core . ts . factory . createNewExpression ( expression , undefined , undefined ) ; } export function createNull ( ) { return core . ts . factory . createNull ( ) ; } export function createTypeQueryNode ( identifier ) { return core . ts . factory . createTypeQueryNode ( identifier ) ; } export function createTypeLiteralNode ( typeElements ) { return core . ts . factory . createTypeLiteralNode ( typeElements ) ; } export function createVoidZero ( ) { return core . ts . factory . createVoidZero ( ) ; }