How to use the typescript.createCall function in typescript

To help you get started, we’ve selected a few typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Bearer / bearer-js / packages / transpiler / src / transformers / output-decorator.ts View on Github external
function createFunctionCall(meta: OutputMeta) {
  const newValueInitializer = ts.createBinary(
    ts.createIdentifier(data),
    ts.createToken(ts.SyntaxKind.BarBarToken),
    ts.createPropertyAccess(ts.createThis(), meta.propDeclarationName)
  )
  // TODO use referenceKeyName
  const emit = createEmitCall(meta, [
    ts.createShorthandPropertyAssignment(meta.referenceKeyName),
    ts.createPropertyAssignment(meta.propDeclarationName, newValueInitializer)
  ])

  return ts.createCall(
    ts.createPropertyAccess(
      ts.createCall(ts.createPropertyAccess(ts.createThis(), meta.functionName), undefined, [
        ts.createObjectLiteral([
          ts.createPropertyAssignment(meta.functionPropertyName, ts.createIdentifier(newValue)),
          ts.createPropertyAssignment(
            meta.functionReferenceIdKeyName,
            ts.createPropertyAccess(ts.createThis(), meta.functionReferenceIdValue || meta.propDeclarationNameRefId)
          )
        ])
      ]),
      'then'
    ),
    undefined,
    [
      ts.createArrowFunction(
        undefined,
        undefined,
        // [],
github MichaReiser / speedy.js / packages / compiler / src / code-generation / per-file / per-file-code-generator-source-file-rewriter.ts View on Github external
const args = signature.declaration.parameters.map(parameter => this.castToWasm(
            parameter,
            this.loadWasmFunctionIdentifier!,
            typesIdentifier,
            argumentObjects)
        );

        const functionCall = ts.createCall(targetFunction, [], args);
        const castedResult = this.castToJs(functionCall, signature.getReturnType(), this.loadWasmFunctionIdentifier!, typesIdentifier);
        const resultIdentifier = ts.createUniqueName("result");
        const resultVariable = ts.createVariableDeclaration(resultIdentifier, undefined, castedResult);
        bodyStatements.push(ts.createVariableStatement(undefined, [resultVariable]));

        if (!this.context.compilationContext.compilerOptions.disableHeapNukeOnExit) {
            // speedyJsGc();
            bodyStatements.push(ts.createStatement(ts.createCall(ts.createPropertyAccess(this.loadWasmFunctionIdentifier, "gc"), [], [])));
        }

        bodyStatements.push(ts.createReturn(resultIdentifier));

        // function (instance) { ... }
        const instanceParameter = ts.createParameter(undefined, undefined, undefined, instanceIdentifier);
        const loadHandlerBody = ts.createBlock(bodyStatements);
        const loadedHandler = ts.createFunctionExpression(undefined, undefined, "instanceLoaded", undefined, [ instanceParameter ], undefined, loadHandlerBody);

        // loadWasmModule().then(instance => );
        const loadInstance = ts.createCall(this.loadWasmFunctionIdentifier, [], []);
        const instanceLoaded = ts.createCall(ts.createPropertyAccess(loadInstance, "then"), [], [ loadedHandler ]);

        return ts.updateFunctionDeclaration(
            functionDeclaration,
            functionDeclaration.decorators,
github MichaReiser / speedy.js / packages / compiler / src / code-generation / per-file / per-file-code-generator-source-file-rewriter.ts View on Github external
if (!this.context.compilationContext.compilerOptions.disableHeapNukeOnExit) {
            // speedyJsGc();
            bodyStatements.push(ts.createStatement(ts.createCall(ts.createPropertyAccess(this.loadWasmFunctionIdentifier, "gc"), [], [])));
        }

        bodyStatements.push(ts.createReturn(resultIdentifier));

        // function (instance) { ... }
        const instanceParameter = ts.createParameter(undefined, undefined, undefined, instanceIdentifier);
        const loadHandlerBody = ts.createBlock(bodyStatements);
        const loadedHandler = ts.createFunctionExpression(undefined, undefined, "instanceLoaded", undefined, [ instanceParameter ], undefined, loadHandlerBody);

        // loadWasmModule().then(instance => );
        const loadInstance = ts.createCall(this.loadWasmFunctionIdentifier, [], []);
        const instanceLoaded = ts.createCall(ts.createPropertyAccess(loadInstance, "then"), [], [ loadedHandler ]);

        return ts.updateFunctionDeclaration(
            functionDeclaration,
            functionDeclaration.decorators,
            (functionDeclaration.modifiers || [] as ts.Modifier[]).filter(modifier => modifier.kind !== ts.SyntaxKind.AsyncKeyword),
            functionDeclaration.asteriskToken,
            functionDeclaration.name,
            functionDeclaration.typeParameters,
            functionDeclaration.parameters,
            functionDeclaration.type,
            ts.createBlock([typesDeclaration, ts.createReturn(instanceLoaded)])
        );
    }
github fabiandev / ts-runtime / test / components / util.ts View on Github external
it('should fail if property access expression does not consist of identifiers', () => {
        const input = ts.createPropertyAccess(ts.createCall(ts.createIdentifier('foo'), void 0, void 0), ts.createIdentifier('bar'));
        util.expectProgramError(() => u.getPropertyAccessExpressionTextOrFail(input));
      });
    });
github woutervh- / typescript-is / src / transform-module / visitor.ts View on Github external
let expression: ts.Expression;
        if (ts.isInterfaceDeclaration(node)) {
            expression = visitInterfaceDeclaration(node, accessor, visitorContext);
        } else if (ts.isTypeParameterDeclaration(node)) {
            throw new Error('Unbound type parameter: ' + node.getText() + ' at ' + reportNode(node));
        } else {
            throw new Error('Unsupported declaration kind: ' + node.kind);
        }
        visitorContext.typeCheckFunctionAccessorTopLevel = null;
        visitorContext.typeDefinitions[name] = constructArrowFunction(
            accessor,
            expression
        );
        visitorContext.typeCheckFunctionAccessorTopLevel = typeCheckFunctionAccessorTopLevel;
    }
    return ts.createCall(
        typeCheckFunctionAccessorTopLevel !== null
            ? typeCheckFunctionAccessorTopLevel
            : visitorContext.typeCheckFunctionAccessor,
        undefined,
        [
            accessor,
            ts.createStringLiteral(name)
        ]
    );
}
github woutervh- / typescript-is / src / transform-inline / validation-report-solver.ts View on Github external
const errorIdentifier = ts.createIdentifier('error');
        const prevIdentifier = ts.createIdentifier('prev');
        const nextIdentifier = ts.createIdentifier('next');
        return ts.createArrowFunction(
            undefined,
            undefined,
            [],
            undefined,
            undefined,
            ts.createBlock([
                ts.createVariableStatement(
                    [ts.createModifier(ts.SyntaxKind.ConstKeyword)],
                    [ts.createVariableDeclaration(
                        errorIdentifier,
                        undefined,
                        ts.createCall(
                            ts.createPropertyAccess(
                                ts.createArrayLiteral(conditions),
                                'reduce'
                            ),
                            undefined,
                            [
                                ts.createArrowFunction(
                                    undefined,
                                    undefined,
                                    [
                                        ts.createParameter(undefined, undefined, undefined, prevIdentifier, undefined, undefined, undefined),
                                        ts.createParameter(undefined, undefined, undefined, nextIdentifier, undefined, undefined, undefined)
                                    ],
                                    undefined,
                                    undefined,
                                    ts.createBinary(
github ng-qt / ng-qt / packages / devkit / src / transformers / inline-assets-transformer.ts View on Github external
function createDefaultRequireCall(literal: ts.StringLiteral) {
      return ts.createPropertyAccess(
        ts.createCall(ts.createIdentifier(REQUIRE), undefined, [literal]),
        EXPORT_DEFAULT,
      );
    }
github jdiaz5513 / capnp-ts / packages / capnpc-ts / src / generators.ts View on Github external
case s.Type.ANY_POINTER:
      getArgs = [offsetLiteral, THIS];

      if (defaultValue) getArgs.push(defaultValue);

      adopt = true;
      disown = true;
      /** __S.getPointer(0, this) */
      get = ts.createCall(
        ts.createPropertyAccess(STRUCT, "getPointer"),
        __,
        getArgs
      );
      has = true;
      /** __S.copyFrom(value, __S.getPointer(0, this)) */
      set = ts.createCall(ts.createPropertyAccess(STRUCT, "copyFrom"), __, [
        VALUE,
        get
      ]);

      break;

    case s.Type.BOOL:
    case s.Type.ENUM:
    case s.Type.FLOAT32:
    case s.Type.FLOAT64:
    case s.Type.INT16:
    case s.Type.INT32:
    case s.Type.INT64:
    case s.Type.INT8:
    case s.Type.UINT16:
    case s.Type.UINT32:
github neo-one-suite / neo-one / packages / neo-one-smart-contract-compiler / src / transpile / transpiler / NEOTranspiler.ts View on Github external
ts.createStringLiteral(name),
      );

      if (ts.isMethodDeclaration(method)) {
        const returnType = this.context.analysis.getType(method);
        const shouldReturn = returnType !== undefined && !tsUtils.type_.isVoidish(returnType);
        methodStatement = processMethod(method, name, shouldReturn);
      } else if (ts.isConstructorDeclaration(method)) {
        methodStatement = processMethod(method, name, true);
      } else if (
        ts.isGetAccessorDeclaration(method) ||
        ts.isPropertyDeclaration(method) ||
        tsUtils.guards.isParameterDeclaration(method)
      ) {
        methodStatement = ts.createExpressionStatement(
          ts.createCall(ts.createIdentifier(this.getInternalIdentifier(method, 'doReturn')), undefined, [
            tsUtils.modifier.isReadonly(method) && tsUtils.initializer.getInitializer(method) === undefined
              ? ts.createCall(
                  ts.createPropertyAccess(
                    ts.createIdentifier(contractIdentifier),
                    `get${name[0].toUpperCase()}${name.slice(1)}`,
                  ),
                  undefined,
                  [],
                )
              : ts.createPropertyAccess(ts.createIdentifier(contractIdentifier), name),
          ]),
        );
      } else {
        const param = tsUtils.parametered.getParameters(method)[0];

        condition = ts.createBinary(
github woutervh- / typescript-is / src / transform-inline / validation-report-solver.ts View on Github external
),
                            undefined,
                            [
                                ts.createArrowFunction(
                                    undefined,
                                    undefined,
                                    [
                                        ts.createParameter(undefined, undefined, undefined, prevIdentifier, undefined, undefined, undefined),
                                        ts.createParameter(undefined, undefined, undefined, nextIdentifier, undefined, undefined, undefined)
                                    ],
                                    undefined,
                                    undefined,
                                    ts.createBinary(
                                        prevIdentifier,
                                        ts.SyntaxKind.BarBarToken,
                                        ts.createCall(nextIdentifier, undefined, undefined)
                                    )
                                ),
                                ts.createNull()
                            ]
                        )
                    )]
                ),
                ts.createReturn(
                    ts.createBinary(
                        errorIdentifier,
                        ts.SyntaxKind.AmpersandAmpersandToken,
                        ts.createBinary(
                            ts.createStringLiteral(`at ${validationReport.path.join('.')}; cause: `),
                            ts.SyntaxKind.PlusToken,
                            errorIdentifier
                        )