当前位置: 首页>>代码示例>>TypeScript>>正文


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

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


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

示例1: 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

示例2: it

  it('should not emit generated files whose sources are outside of the rootDir', () => {
    testSupport.writeFiles({
      'src/main.ts': createModuleAndCompSource('main'),
      'src/index.ts': `
          export * from './main';
        `
    });
    const options =
        testSupport.createCompilerOptions({rootDir: path.resolve(testSupport.basePath, 'src')});
    const host = ng.createCompilerHost({options});
    const writtenFileNames: string[] = [];
    const oldWriteFile = host.writeFile;
    host.writeFile = (fileName, data, writeByteOrderMark) => {
      writtenFileNames.push(fileName);
      oldWriteFile(fileName, data, writeByteOrderMark);
    };

    compile(/*oldProgram*/ undefined, options, /*rootNames*/ undefined, host);

    // no emit for files from node_modules as they are outside of rootDir
    expect(writtenFileNames.some(f => /node_modules/.test(f))).toBe(false);

    // emit all gen files for files under src/
    testSupport.shouldExist('built/main.js');
    testSupport.shouldExist('built/main.d.ts');
    testSupport.shouldExist('built/main.ngfactory.js');
    testSupport.shouldExist('built/main.ngfactory.d.ts');
    testSupport.shouldExist('built/main.ngsummary.json');
  });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:29,代码来源:program_spec.ts

示例3: 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

示例4: 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

示例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


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