How to use the typescript.createPropertyAccess 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 relay-tools / relay-compiler-language-typescript / transform / src / RelayQLPrinter.ts View on Github external
printVariable(name: string): Printable {
      // Assume that variables named like substitutions are substitutions.
      if (this.variableNames.hasOwnProperty(name)) {
        return ts.createCall(
          ts.createPropertyAccess(identify(this.tagName), ts.createIdentifier('__var')),
          undefined,
          [ts.createIdentifier(name)],
        );
      }
      return codify({
        kind: ts.createLiteral('CallVariable'),
        callVariableName: ts.createLiteral(name),
      });
    }
github TypeScriptToLua / TypeScriptToLua / src / Transformer.ts View on Github external
public visitIdentifier(node: ts.Identifier): ts.Identifier| ts.PropertyAccessExpression {
        // If we are in a namespace or a sourcefile that is a module check if this identifier is exported
        if (this.currentNamespace && tsHelper.isIdentifierExported(node, this.currentNamespace, this.checker)) {
            return ts.createPropertyAccess(this.currentNamespace.name, node);
        } else if (this.isModule && tsHelper.isIdentifierExported(node, this.sourceFile, this.checker)) {
            return ts.createPropertyAccess(ts.createIdentifier("exports"), node);
        }

        return node;
    }
github strothj / react-docgen-typescript-loader / src / generateDocgenCodeBlock.ts View on Github external
function setComponentDocGen(
  d: ComponentDoc,
  options: GeneratorOptions,
): ts.Statement {
  return insertTsIgnoreBeforeStatement(
    ts.createStatement(
      ts.createBinary(
        // SimpleComponent.__docgenInfo
        ts.createPropertyAccess(
          ts.createIdentifier(d.displayName),
          ts.createIdentifier("__docgenInfo"),
        ),
        ts.SyntaxKind.EqualsToken,
        ts.createObjectLiteral([
          // SimpleComponent.__docgenInfo.description
          ts.createPropertyAssignment(
            ts.createLiteral("description"),
            ts.createLiteral(d.description),
          ),
          // SimpleComponent.__docgenInfo.displayName
          ts.createPropertyAssignment(
            ts.createLiteral("displayName"),
            ts.createLiteral(d.displayName),
          ),
          // SimpleComponent.__docgenInfo.props
github angular / angular-cli / packages / @ngtools / webpack / src / transformers / replace_bootstrap.ts View on Github external
const idPlatformBrowser = ts.createUniqueName('__NgCli_bootstrap_');
      const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_');

      // Add the transform operations.
      const factoryClassName = entryModule.className + 'NgFactory';
      const factoryModulePath = normalizedEntryModulePath + '.ngfactory';
      ops.push(
        // Replace the entry module import.
        ...insertStarImport(sourceFile, idNgFactory, factoryModulePath),
        new ReplaceNodeOperation(sourceFile, entryModuleIdentifier,
          ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))),
        // Replace the platformBrowserDynamic import.
        ...insertStarImport(sourceFile, idPlatformBrowser, '@angular/platform-browser'),
        new ReplaceNodeOperation(sourceFile, platformBrowserDynamicIdentifier,
          ts.createPropertyAccess(idPlatformBrowser, 'platformBrowser')),
        new ReplaceNodeOperation(sourceFile, bootstrapModuleIdentifier,
          ts.createIdentifier('bootstrapModuleFactory')),
      );
    });
github MichaReiser / speedy.js / packages / compiler / src / code-generation / per-file / per-file-code-generator-source-file-rewriter.ts View on Github external
const initializer = ts.createCall(ts.createIdentifier(MODULE_LOADER_FACTORY_NAME), [], [
            ts.createLiteral(this.wasmUrl!),
            options
        ]);

        const statements = sourceFile.statements;
        const statementsToInsert = [];

        // var loadWasmModule = _moduleLoader(...);
        const loaderDeclaration = ts.createVariableDeclarationList([ts.createVariableDeclaration(this.loadWasmFunctionIdentifier, undefined, initializer)]);
        statementsToInsert.push(ts.createVariableStatement([], loaderDeclaration));

        // export let speedyJsGc = loadWasmModule_1.gc; or without export if only expose
        if (compilerOptions.exposeGc || compilerOptions.exportGc) {
            const speedyJsGcVariable = ts.createVariableDeclaration("speedyJsGc", undefined, ts.createPropertyAccess(this.loadWasmFunctionIdentifier, "gc"));
            const speedyJsGcDeclaration = ts.createVariableDeclarationList([speedyJsGcVariable], ts.NodeFlags.Const);
            const modifiers = compilerOptions.exportGc ? [ ts.createToken(ts.SyntaxKind.ExportKeyword) ] : [];
            statementsToInsert.push(ts.createVariableStatement(modifiers, speedyJsGcDeclaration));
        }

        return ts.updateSourceFileNode(sourceFile, [...statementsToInsert, ...statements]);
    }
github angular / tsickle / src / jsdoc_transformer.ts View on Github external
p => transformerUtil.createMultiLineComment(
          p, `Skipping unhandled member: ${escapeForComment(p.getText())}`)));

  for (const fnDecl of abstractMethods) {
    // If the function declaration is computed, its name is the computed expression; otherwise, its
    // name can be resolved to a string.
    const name = fnDecl.name && ts.isComputedPropertyName(fnDecl.name) ? fnDecl.name.expression :
                                                                         propertyName(fnDecl);
    if (!name) {
      mtt.error(fnDecl, 'anonymous abstract function');
      continue;
    }
    const {tags, parameterNames} = mtt.getFunctionTypeJSDoc([fnDecl], []);
    if (hasExportingDecorator(fnDecl, mtt.typeChecker)) tags.push({tagName: 'export'});
    // Use element access instead of property access for compued names.
    const lhs = typeof name === 'string' ? ts.createPropertyAccess(instancePropAccess, name) :
                                           ts.createElementAccess(instancePropAccess, name);
    // memberNamespace because abstract methods cannot be static in TypeScript.
    const abstractFnDecl = ts.createStatement(ts.createAssignment(
        lhs,
        ts.createFunctionExpression(
            /* modifiers */ undefined,
            /* asterisk */ undefined,
            /* name */ undefined,
            /* typeParameters */ undefined,
            parameterNames.map(
                n => ts.createParameter(
                    /* decorators */ undefined, /* modifiers */ undefined,
                    /* dotDotDot */ undefined, n)),
            undefined,
            ts.createBlock([]),
            )));
github woutervh- / typescript-is / src / transform-inline / visitor.ts View on Github external
const properties = visitorContext.checker.getPropertiesOfType(type);

    if (visitorContext.mode.type === 'type-check') {
        const conditions: ts.Expression[] = [];
        conditions.push(
            ts.createStrictEquality(
                ts.createTypeOf(accessor),
                ts.createStringLiteral('object')
            ),
            ts.createStrictInequality(
                accessor,
                ts.createNull()
            ),
            ts.createLogicalNot(
                ts.createCall(
                    ts.createPropertyAccess(ts.createIdentifier('Array'), ts.createIdentifier('isArray')),
                    undefined,
                    [accessor]
                )
            )
        );
        visitorContext.typeMapperStack.push(mapper);
        for (const property of properties) {
            conditions.push(visitPropertySymbol(property, accessor, visitorContext));
        }
        const stringIndexType = visitorContext.checker.getIndexTypeOfType(type, ts.IndexKind.String);
        if (stringIndexType) {
            const keyIdentifier = ts.createIdentifier('key');
            const itemAccessor = ts.createElementAccess(accessor, keyIdentifier);
            conditions.push(
                ts.createCall(
                    ts.createPropertyAccess(
github aurelia / aurelia / compiler / transformer.ts View on Github external
private createViewClassConstructor() {
    return ts.createConstructor(
      /** decorators */ undefined,
      /** modifiers */ undefined,
      /** params */[],
      ts.createBlock([
        ts.createStatement(
          ts.createCall(
            ts.createPropertyAccess(
              ts.createIdentifier('Object'),
              'defineProperty'
            ),
            /*typeArguments*/ undefined,
            /*arguments*/
            [
              ts.createThis(),
              ts.createLiteral(this.observerPropName),
              ts.createObjectLiteral(
                [
                  ts.createPropertyAssignment(
                    'value',
                    ts.createObjectLiteral(
                      this.templateFactory.observedProperties.map(op => ts.createPropertyAssignment(
                        op,
                        ts.createNew(
github Bearer / bearer-js / packages / transpiler / src / transformers / bearer.ts View on Github external
export function addComponentDidLoad(classNode: ts.ClassDeclaration): ts.ClassDeclaration {
  const assignSetupId = ts.createStatement(
    ts.createAssignment(
      ts.createPropertyAccess(ts.createThis(), [Component.bearerContext, Component.setupId].join('.')),
      ts.createPropertyAccess(ts.createThis(), Component.setupId)
    )
  )
  const ifSetupIdPresent = ts.createIf(
    ts.createPropertyAccess(ts.createThis(), Component.setupId),
    ts.createBlock([assignSetupId], true)
  )
  return createOrUpdateComponentDidLoad(classNode, block =>
    ts.updateBlock(block, [ifSetupIdPresent, ...block.statements])
  )
}
github aurelia / aurelia / compiler / template-transformer.ts View on Github external
/*decorators*/ undefined,
                        /*modifiers*/ undefined,
                        /*dotdotdot*/ undefined,
                        'b',
                        /*question*/undefined,
                        /*type*/undefined,
                        /*initializer*/undefined
                      )
                    ],
                    /*type*/ undefined,
                    ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
                    ts.createBlock(
                      [
                        ts.createStatement(
                          ts.createCall(
                            ts.createPropertyAccess(
                              ts.createIdentifier('b'),
                              TemplateTransformer.lifecycleMethods.bind
                            ),
                            /*typeArguments*/ undefined,
                            /*arguments*/
                            [
                              ts.createIdentifier(this.elementScopePropName)
                            ]
                          )
                        )
                      ],
                      /*multiline*/ true
                    )
                  )
                ]
              )