How to use the ts-morph.VariableDeclarationKind.Const function in ts-morph

To help you get started, we’ve selected a few ts-morph 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 brianzinn / react-babylonjs / tools / generate-code.ts View on Github external
generatedCodeSourceFile.addVariableStatement({
    declarationKind: VariableDeclarationKind.Const,
    isExported: false,
    declarations: [{
      name: 'classesMap',
      type: "object",
      initializer: `{\n${Array.from(factoryClasses.entries())
          .map(([alias, className]) =>
            `${classToIntrinsic(className)}: ${alias},${className}: ${alias}`)
          .join(',\n')}}`
    }]
  });

  // for going from camelCase on vrExperienceHelper to VRExperienceHelper to locate generated classes.
  generatedCodeSourceFile.addVariableStatement({
    declarationKind: VariableDeclarationKind.Const,
    isExported: true,
    declarations: [{
      name: 'intrinsicClassMap',
      type: "object",
      initializer: `{\n${Array.from(factoryClasses.entries())
          .map(([alias, className]) =>
            `${classToIntrinsic(className)}:'${className}'`)
          .join(',\n')},
          ${createdMeshClasses.map(meshName =>
            `${classToIntrinsic(meshName)}:'${meshName}'`)
          .join(',\n')}
        }`
    }]
  });

  const functionDeclaration:FunctionDeclaration = generatedCodeSourceFile.addFunction({
github anoaland / anoa-cli / src / generators / store / reducer-generator.ts View on Github external
}
    ])

    // generate reducers const
    const reducerRootName = 'reducers'
    const reducersVarStatement =
      reducerRootSourceFile.getVariableStatement(reducerRootName) ||
      reducerRootSourceFile.addVariableStatement({
        isExported: true,
        declarations: [
          {
            name: reducerRootName,
            initializer: `combineReducers({})`
          }
        ],
        declarationKind: VariableDeclarationKind.Const
      })

    const reducers = reducersVarStatement.getDescendantsOfKind(
      SyntaxKind.ObjectLiteralExpression
    )[0]

    if (!reducers) {
      throw new Error('Invalid reducer file.')
    }

    reducers.addPropertyAssignment({
      name,
      initializer: reducerName
    })

    // generate root action types
github anoaland / anoa-cli / src / services / theme / builders / create-theme / index.ts View on Github external
folder,
      filesystem: { cwd },
      strings: { camelCase, kebabCase },
      print: { spin, colors }
    } = this.context

    const spinner = spin('Generating...')

    const { name, filePath, base } = this.qa.result

    const themeFile = this.project.createSourceFile(filePath)
    ReactUtils.addNamedImport(themeFile, base.path, base.name)

    themeFile.addVariableStatement({
      isExported: true,
      declarationKind: VariableDeclarationKind.Const,
      declarations: [
        {
          name,
          initializer: `${base.name}.extend(
            {
              // override default theme variables
            },
            vars => ({
              // override default theme styles
            })
          )`
        }
      ]
    })

    const stylesFile = this.project.addExistingSourceFile(
github brianzinn / react-babylonjs / tools / generate-code.ts View on Github external
alias: fileModuleDeclaration.moduleDeclaration.importAlias
        })

        if (fileModuleDeclaration.hostComponent && !factoryClasses.has(fileModuleDeclaration.moduleDeclaration.importAlias)) {
          factoryClasses.set(fileModuleDeclaration.moduleDeclaration.importAlias, fileModuleDeclaration.moduleDeclaration.className);
        }
      })
    })
  })

  // we can do this as long as there are no classes with the same name across imports
  // otherwise we can just use a Set with importalias, but need to generate more metadata.
  // ie: classseMap = { BabylonjsCoreBox, BabylonjsCoreSphere, ... };
  // We generate both IntrinsicType (ie: arcRotateCamera) and "component" (ie: ArcRotateCamera), but will remove "component" when local JSX is ready.
  generatedCodeSourceFile.addVariableStatement({
    declarationKind: VariableDeclarationKind.Const,
    isExported: false,
    declarations: [{
      name: 'classesMap',
      type: "object",
      initializer: `{\n${Array.from(factoryClasses.entries())
          .map(([alias, className]) =>
            `${classToIntrinsic(className)}: ${alias},${className}: ${alias}`)
          .join(',\n')}}`
    }]
  });

  // for going from camelCase on vrExperienceHelper to VRExperienceHelper to locate generated classes.
  generatedCodeSourceFile.addVariableStatement({
    declarationKind: VariableDeclarationKind.Const,
    isExported: true,
    declarations: [{
github anoaland / anoa-cli / src / generators / nav / navigator-generator.ts View on Github external
path.dirname(screenToAttach.sourceFile.getFilePath()),
          'nav.ts'
        )
      : folder.navigator(kebabCase(name) + '.ts')

    this.project = new Project()
    this.sourceFile = this.project.createSourceFile(filePath)

    this.sourceFile.addImportDeclaration({
      namedImports: [this.navigatorFn, 'createAppContainer'],
      moduleSpecifier: 'react-navigation'
    })

    this.sourceFile.addVariableStatement({
      isExported: true,
      declarationKind: VariableDeclarationKind.Const,
      declarations: [
        {
          name,
          initializer: this.generateNavigator()
        }
      ]
    })

    const screenAttached = this.attachToScreen()

    const source = tools.source()

    await source.prettifySoureFile(this.sourceFile)
    if (screenToAttach) {
      await source.prettifySoureFile(this.screenFile)
    }
github anoaland / anoa-cli / src / services / store / builders / reducer / reducer-generator.ts View on Github external
type: `Reducer<${reducerStateName}, ${reducerActionTypeName}>`,
          initializer: `(state = {
            ${stateInitializer}
          },
          action
          ) => {
            switch (action.type) {
              ${body || ''}          
              default:
                return state
            }
          }`
        }
      ],
      isExported: true,
      declarationKind: VariableDeclarationKind.Const
    })

    await this.source.prettifySoureFile(reducerFile)
  }
}
github Azure / autorest.typescript / src / generators / operationGenerator.ts View on Github external
operationGroupDetails.operations.forEach(operation => {
    const operationName = normalizeName(operation.name, NameType.Property);
    const operationSpec = transformOperationSpec(operation);
    file.addVariableStatement({
      declarationKind: VariableDeclarationKind.Const,
      declarations: [
        {
          name: `${operationName}OperationSpec`,
          type: "coreHttp.OperationSpec",
          initializer: buildSpec(operationSpec)
        }
      ]
    });
  });
}
github aurelia / aurelia / tools / api-doc-generator / src / helpers / common / variable / variable-utils.ts View on Github external
export function getVariableKind(kind: VariableDeclarationKind): VariableKind {
    switch (kind) {
        case VariableDeclarationKind.Const:
            return VariableKind.Const;
        case VariableDeclarationKind.Let:
            return VariableKind.Let;
        case VariableDeclarationKind.Var:
            return VariableKind.Var;
    }
}
github denoland / deno / tools / ts_library_builder / ast_util.ts View on Github external
export function addVariableDeclaration(
  node: StatementedNode,
  name: string,
  type: string,
  isConst: boolean,
  hasDeclareKeyword?: boolean,
  jsdocs?: JSDoc[]
): VariableStatement {
  return node.addVariableStatement({
    declarationKind: isConst
      ? VariableDeclarationKind.Const
      : VariableDeclarationKind.Let,
    declarations: [{ name, type }],
    docs: jsdocs && jsdocs.map(jsdoc => jsdoc.getText()),
    hasDeclareKeyword
  });
}
github dsherret / ts-ast-viewer / scripts / createCompilerVersions.ts View on Github external
namedImports: ["assertNever"],
    moduleSpecifier: "../utils"
}, {
    kind: StructureKind.TypeAlias,
    isExported: true,
    name: "CompilerVersions",
    type: versions.map(v => `"${v.version}"`).join(" | ")
}, {
    kind: StructureKind.TypeAlias,
    isExported: true,
    name: "CompilerPackageNames",
    type: versions.map(v => `"${v.name}"`).join(" | ")
}, {
    kind: StructureKind.VariableStatement,
    isExported: true,
    declarationKind: VariableDeclarationKind.Const,
    declarations: [{
        name: "compilerVersionCollection",
        initializer: writer => {
            writer.write("[").newLine();
            writer.indent(() => {
                for (let i = 0; i < versions.length; i++) {
                    const version = versions[i];
                    writer.write(`{ version: "${version.version}", packageName: "${version.name}" }`);
                    if (i < versions.length - 1)
                        writer.write(",");
                    writer.newLine();
                }
            });
            writer.write("]");
        },
        type: "{ version: CompilerVersions; packageName: CompilerPackageNames; }[]"