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

TypeScript compiler.toTypeScript函数代码示例

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

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



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

示例1: it

    it('should not reexport type symbols mentioned in constructors', () => {
      const libInput: MockDirectory = {
        'lib': {
          'base.ts': `
            export type AType = {};

            export class AClass {
              constructor(a: AType) {}
            }
          `
        }
      };
      const appInput: MockDirectory = {
        'app': {
          'main.ts': `
            export * from '../lib/base';
          `
        }
      };

      const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true});
      const {genFiles: appGenFiles} =
          compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true});
      const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts');
      expect(toTypeScript(appNgFactory)).not.toContain('AType');
    });
开发者ID:smart-web-rock,项目名称:angular,代码行数:26,代码来源:compiler_spec.ts


示例2: it

  it('should create @Injectable summaries', () => {
    const appDir = {
      'app.module.ts': `
        import { Injectable } from '@angular/core';

        export class Dep {}

        @Injectable()
        export class MyService {
          constructor(d: Dep) {}
        }
      `
    };
    const rootDir = {'app': appDir};

    const genFile =
        compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts');
    const genSource = toTypeScript(genFile);

    expect(genSource).toContain(`import * as i0 from '/app/app.module'`);
    expect(genSource).toContain('export function MyServiceNgSummary()');
    // Note: CompileSummaryKind.Injectable = 3
    expect(genSource).toMatch(/summaryKind:3,\s*type:\{\s*reference:i0.MyService/);
    expect(genSource).toContain('token:{identifier:{reference:i0.Dep}}');
  });
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:25,代码来源:jit_summaries_spec.ts


示例3: it

    it('should not reexport already exported symbols except for lowered symbols', () => {
      const libInput: MockDirectory = {
        'lib': {
          'base.ts': `
            export const exportedVar = 1;

            // A symbol introduced by lowering expressions
            export const ɵ1 = 'lowered symbol';
          `
        }
      };
      const appInput: MockDirectory = {
        'app': {
          'main.ts': `export * from '../lib/base';`,
        }
      };

      const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true});
      const {genFiles: appGenFiles} =
          compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true});
      const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts');
      const appNgFactoryTs = toTypeScript(appNgFactory);

      // we don't need to reexport exported symbols via the .ngfactory
      // as we can refer to them via the reexport.
      expect(appNgFactoryTs).not.toContain('exportedVar');

      // although ɵ1 is reexported via `export *`, we still need to reexport it
      // via the .ngfactory as tsickle expands `export *` into named exports,
      // and doesn't know about our lowered symbols as we introduce them
      // after the typecheck phase.
      expect(appNgFactoryTs).toContain('ɵ1');
    });
开发者ID:DeepanParikh,项目名称:angular,代码行数:33,代码来源:compiler_spec.ts


示例4: it

      it('should map non template parts to the source file', () => {
        appDir['app.component.ts'] = createComponentSource(templateDecorator('Hello World!'));

        const genFile = compileApp();
        const genSource = toTypeScript(genFile);
        const sourceMap = extractSourceMap(genSource) !;
        expect(originalPositionFor(sourceMap, {line: 1, column: 0}))
            .toEqual({line: 1, column: 0, source: ngComponentPath});
      });
开发者ID:cooperka,项目名称:angular,代码行数:9,代码来源:compiler_spec.ts


示例5: constructor

       () => {
         const lib1Input: MockDirectory = {
           'lib1': {
             'base.ts': `
            export class AParam {}

            export class Base {
              constructor(a: AParam) {}
              ngOnDestroy() {}
            }
          `
           }
         };

         const lib2Input: MockDirectory = {
           'lib2': {
             'middle.ts': `
            import {Base} from '../lib1/base';
            export class Middle extends Base {}
          `
           }
         };


         const appInput: MockDirectory = {
           'app': {
             'main.ts': `
            import {NgModule, Component} from '@angular/core';
            import {Middle} from '../lib2/middle';

            @Component({template: ''})
            export class Extends extends Middle {}

            @NgModule({
              declarations: [Extends]
            })
            export class MyModule {}
          `
           }
         };
         const {outDir: lib1OutDir} =
             compile([lib1Input, getAngularSummaryFiles()], {useSummaries: true});
         const {outDir: lib2OutDir} =
             compile([lib1OutDir, lib2Input, getAngularSummaryFiles()], {useSummaries: true});
         const {genFiles} = compile(
             [lib1OutDir, lib2OutDir, appInput, getAngularSummaryFiles()], {useSummaries: true});

         const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts') !;
         const flags = NodeFlags.TypeDirective | NodeFlags.Component | NodeFlags.OnDestroy;
         const mainNgFactorySource = toTypeScript(mainNgFactory);
         expect(mainNgFactorySource).toContain(`import * as i2 from '/lib1/base';`);
         expect(mainNgFactorySource).toContain(`${flags},(null as any),0,i1.Extends,[i2.AParam]`);
       });
开发者ID:Cammisuli,项目名称:angular,代码行数:53,代码来源:compiler_spec.ts


示例6: it

    it('should include inputs, outputs and ng-content selectors in the component factory', () => {
      const FILES: MockDirectory = {
        app: {
          'app.ts': `
                import {Component, NgModule, Input, Output} from '@angular/core';

                @Component({
                  selector: 'my-comp',
                  template:
                  '<ng-content select="child1"></ng-content>' +
                  '<ng-content></ng-content>' +
                  '<ng-template><ng-content select="child2"></ng-content></ng-template>' +
                  '<ng-content select="child3"></ng-content>' +
                  '<ng-content select="child1"></ng-content>'
                })
                export class MyComp {
                  @Input('aInputName')
                  aInputProp: string;

                  @Output('aOutputName')
                  aOutputProp: any;
                }

                @NgModule({
                  declarations: [MyComp]
                })
                export class MyModule {}
              `
        }
      };
      const {genFiles} = compile([FILES, angularFiles]);
      const genFile = genFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts') !;
      const genSource = toTypeScript(genFile);
      const createComponentFactoryCall = /ɵccf\([^)]*\)/m.exec(genSource) ![0].replace(/\s*/g, '');
      // selector
      expect(createComponentFactoryCall).toContain('my-comp');
      // inputs
      expect(createComponentFactoryCall).toContain(`{aInputProp:'aInputName'}`);
      // outputs
      expect(createComponentFactoryCall).toContain(`{aOutputProp:'aOutputName'}`);
      // ngContentSelectors - note that the catch-all doesn't have to appear at the start
      expect(createComponentFactoryCall).toContain(`['child1','*','child2','child3','child1']`);
    });
开发者ID:Cammisuli,项目名称:angular,代码行数:43,代码来源:compiler_spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript compiler.visitAstChildren函数代码示例发布时间:2022-05-28
下一篇:
TypeScript compiler.templateVisitAll函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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