• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript compiler-cli.createProgram函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular/compiler-cli.createProgram函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createProgram函数的具体用法?TypeScript createProgram怎么用?TypeScript createProgram使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createProgram函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: compile

       () => {
         testSupport.write('src/index.ts', fileWithGoodContent);

         // compile angular and produce .ngsummary.json / ngfactory.d.ts files
         compile();

         testSupport.write('src/ok.ts', fileWithGoodContent);
         testSupport.write('src/error.ts', fileWithStructuralError);

         // Make sure the ok.ts file is before the error.ts file,
         // so we added a .ngfactory.ts file for it.
         const allRootNames = resolveFiles(
             ['src/ok.ts', 'src/error.ts'].map(fn => path.resolve(testSupport.basePath, fn)));

         const options = testSupport.createCompilerOptions({
           noResolve: true,
           generateCodeForLibraries: false,
         });
         const host = ng.createCompilerHost({options});
         const originalGetSourceFile = host.getSourceFile;
         host.getSourceFile =
             (fileName: string, languageVersion: ts.ScriptTarget,
              onError?: ((message: string) => void) | undefined): ts.SourceFile => {
               // We should never try to load .ngfactory.ts files
               if (fileName.match(/\.ngfactory\.ts$/)) {
                 throw new Error(`Non existent ngfactory file: ` + fileName);
               }
               return originalGetSourceFile.call(host, fileName, languageVersion, onError);
             };
         const program = ng.createProgram({rootNames: allRootNames, options, host});
         const structuralErrors = program.getNgStructuralDiagnostics();
         expect(structuralErrors.length).toBe(1);
         expect(structuralErrors[0].messageText).toContain('Function calls are not supported.');
       });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:34,代码来源:program_spec.ts


示例2: it

    it('should include non-formatted errors (e.g. invalid templateUrl)', () => {
      testSupport.write('src/index.ts', `
        import {Component, NgModule} from '@angular/core';

        @Component({
          selector: 'my-component',
          templateUrl: 'template.html',   // invalid template url
        })
        export class MyComponent {}

        @NgModule({
          declarations: [MyComponent]
        })
        export class MyModule {}
      `);

      const options = testSupport.createCompilerOptions();
      const host = ng.createCompilerHost({options});
      const program = ng.createProgram({
        rootNames: [path.resolve(testSupport.basePath, 'src/index.ts')],
        options,
        host,
      });

      const structuralErrors = program.getNgStructuralDiagnostics();
      expect(structuralErrors.length).toBe(1);
      expect(structuralErrors[0].messageText).toContain('Couldn\'t resolve resource template.html');
    });
开发者ID:IdeaBlade,项目名称:angular,代码行数:28,代码来源:program_spec.ts


示例3: it

  it('should report errors for ts and ng errors on emit with noEmitOnError=true', () => {
    testSupport.writeFiles({
      'src/main.ts': `
        import {Component, NgModule} from '@angular/core';

        // Ts error
        let x: string = 1;

        // Ng error
        @Component({selector: 'comp', templateUrl: './main.html'})
        export class MyComp {}

        @NgModule({declarations: [MyComp]})
        export class MyModule {}
        `,
      'src/main.html': '{{nonExistent}}'
    });
    const options = testSupport.createCompilerOptions({noEmitOnError: true});
    const host = ng.createCompilerHost({options});
    const program1 = ng.createProgram(
        {rootNames: [path.resolve(testSupport.basePath, 'src/main.ts')], options, host});
    const errorDiags =
        program1.emit().diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
    expect(formatDiagnostics(errorDiags))
        .toContain(`src/main.ts(5,13): error TS2322: Type '1' is not assignable to type 'string'.`);
    expect(formatDiagnostics(errorDiags))
        .toContain(
            `src/main.html(1,1): error TS100: Property 'nonExistent' does not exist on type 'MyComp'.`);
  });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:29,代码来源:program_spec.ts


示例4: createProgram

 function createProgram(rootNames: string[], overrideOptions: ng.CompilerOptions = {}) {
   const options = testSupport.createCompilerOptions(overrideOptions);
   const host = ng.createCompilerHost({options});
   const program = ng.createProgram(
       {rootNames: rootNames.map(p => path.resolve(testSupport.basePath, p)), options, host});
   return {program, options};
 }
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:7,代码来源:program_spec.ts


示例5: it

 it('should typecheck templates even if skipTemplateCodegen is set', () => {
   testSupport.writeFiles({
     'src/main.ts': createModuleAndCompSource('main', `{{nonExistent}}`),
   });
   const options = testSupport.createCompilerOptions({skipTemplateCodegen: true});
   const host = ng.createCompilerHost({options});
   const program = ng.createProgram(
       {rootNames: [path.resolve(testSupport.basePath, 'src/main.ts')], options, host});
   const diags = program.getNgSemanticDiagnostics();
   expect(diags.length).toBe(1);
   expect(diags[0].messageText).toBe(`Property 'nonExistent' does not exist on type 'mainComp'.`);
 });
开发者ID:smart-web-rock,项目名称:angular,代码行数:12,代码来源:program_spec.ts


示例6: compile

    function compile(oldProgram?: ng.Program): ng.Program {
      const options = testSupport.createCompilerOptions();
      const rootNames = [path.resolve(testSupport.basePath, 'src/index.ts')];

      const program = ng.createProgram({
        rootNames: rootNames,
        options: testSupport.createCompilerOptions(),
        host: ng.createCompilerHost({options}), oldProgram,
      });
      expectNoDiagnosticsInProgram(options, program);
      program.emit();
      return program;
    }
开发者ID:angularbrasil,项目名称:angular,代码行数:13,代码来源:program_spec.ts


示例7: lazyRoutesTest

function lazyRoutesTest() {
  const basePath = path.join(__dirname, '../ngtools_src');
  const project = path.join(basePath, 'tsconfig-build.json');

  const config = readConfiguration(project);
  const host = ts.createCompilerHost(config.options, true);
  const program = createProgram({
    rootNames: config.rootNames,
    options: config.options, host,
  });

  config.options.basePath = basePath;
  config.options.rootDir = basePath;

  const lazyRoutes = program.listLazyRoutes('app.module#AppModule');
  const expectations: {[route: string]: string} = {
    './lazy.module#LazyModule': 'lazy.module.ts',
    './feature/feature.module#FeatureModule': 'feature/feature.module.ts',
    './feature/lazy-feature.module#LazyFeatureModule': 'feature/lazy-feature.module.ts',
    './feature.module#FeatureModule': 'feature/feature.module.ts',
    './lazy-feature-nested.module#LazyFeatureNestedModule': 'feature/lazy-feature-nested.module.ts',
    'feature2/feature2.module#Feature2Module': 'feature2/feature2.module.ts',
    './default.module': 'feature2/default.module.ts',
    'feature/feature.module#FeatureModule': 'feature/feature.module.ts'
  };

  lazyRoutes.forEach(lazyRoute => {
    const routeName = lazyRoute.route;

    // Normalize the module path and the expected module path so that these can be compared
    // on Windows where path separators are not consistent with TypeScript internal paths.
    const modulePath = path.normalize(lazyRoute.referencedModule.filePath);
    const expectedModulePath = path.normalize(path.join(basePath, expectations[routeName]));

    assert(routeName in expectations, `Found a route that was not expected: "${routeName}".`);
    assert(
        modulePath === expectedModulePath,
        `Route "${routeName}" does not point to the expected absolute path ` +
            `"${expectedModulePath}". It points to "${modulePath}"`);
  });

  // Verify that all expectations were met.
  assert.deepEqual(
      lazyRoutes.map(lazyRoute => lazyRoute.route), Object.keys(expectations),
      `Expected routes listed to be: \n` +
          `  ${JSON.stringify(Object.keys(expectations))}\n` +
          `Actual:\n` +
          `  ${JSON.stringify(Object.keys(lazyRoutes))}\n`);
}
开发者ID:Cammisuli,项目名称:angular,代码行数:49,代码来源:test_ngtools_api.ts


示例8: compileLib

 function compileLib(libName: string) {
   testSupport.writeFiles({
     [`${libName}_src/index.ts`]: createModuleAndCompSource(libName),
   });
   const options = testSupport.createCompilerOptions();
   const program = ng.createProgram({
     rootNames: [path.resolve(testSupport.basePath, `${libName}_src/index.ts`)],
     options,
     host: ng.createCompilerHost({options}),
   });
   expectNoDiagnosticsInProgram(options, program);
   fs.symlinkSync(
       path.resolve(testSupport.basePath, 'built', `${libName}_src`),
       path.resolve(testSupport.basePath, 'node_modules', libName));
   program.emit({emitFlags: ng.EmitFlags.DTS | ng.EmitFlags.JS | ng.EmitFlags.Metadata});
 }
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:16,代码来源:program_spec.ts



注:本文中的@angular/compiler-cli.createProgram函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap