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

TypeScript compiler.StaticSymbolResolverHost类代码示例

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

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



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

示例1: describe

describe('StaticReflector', () => {
  let noContext: StaticSymbol;
  let host: StaticSymbolResolverHost;
  let symbolResolver: StaticSymbolResolver;
  let reflector: StaticReflector;

  function init(
      testData: {[key: string]: any} = DEFAULT_TEST_DATA,
      decorators: {name: string, filePath: string, ctor: any}[] = []) {
    const symbolCache = new StaticSymbolCache();
    host = new MockStaticSymbolResolverHost(testData);
    symbolResolver = new StaticSymbolResolver(host, symbolCache, new MockSummaryResolver([]));
    reflector = new StaticReflector(symbolResolver, decorators);
    noContext = reflector.getStaticSymbol('', '');
  }

  beforeEach(() => init());

  function simplify(context: StaticSymbol, value: any) {
    return reflector.simplify(context, value);
  }

  it('should get annotations for NgFor', () => {
    const NgFor = reflector.findDeclaration('@angular/common/src/directives/ng_for', 'NgFor');
    const annotations = reflector.annotations(NgFor);
    expect(annotations.length).toEqual(1);
    const annotation = annotations[0];
    expect(annotation.selector).toEqual('[ngFor][ngForOf]');
    expect(annotation.inputs).toEqual(['ngForTrackBy', 'ngForOf', 'ngForTemplate']);
  });

  it('should get constructor for NgFor', () => {
    const NgFor = reflector.findDeclaration('@angular/common/src/directives/ng_for', 'NgFor');
    const ViewContainerRef = reflector.findDeclaration(
        '@angular/core/src/linker/view_container_ref', 'ViewContainerRef');
    const TemplateRef =
        reflector.findDeclaration('@angular/core/src/linker/template_ref', 'TemplateRef');
    const IterableDiffers = reflector.findDeclaration(
        '@angular/core/src/change_detection/differs/iterable_differs', 'IterableDiffers');
    const ChangeDetectorRef = reflector.findDeclaration(
        '@angular/core/src/change_detection/change_detector_ref', 'ChangeDetectorRef');

    const parameters = reflector.parameters(NgFor);
    expect(parameters).toEqual([
      [ViewContainerRef], [TemplateRef], [IterableDiffers], [ChangeDetectorRef]
    ]);
  });

  it('should get annotations for HeroDetailComponent', () => {
    const HeroDetailComponent =
        reflector.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
    const annotations = reflector.annotations(HeroDetailComponent);
    expect(annotations.length).toEqual(1);
    const annotation = annotations[0];
    expect(annotation.selector).toEqual('my-hero-detail');
    expect(annotation.animations).toEqual([trigger('myAnimation', [
      state('state1', style({'background': 'white'})),
      transition(
          '* => *',
          sequence([group([animate(
              '1s 0.5s',
              keyframes([style({'background': 'blue'}), style({'background': 'red'})]))])]))
    ])]);
  });

  it('should get and empty annotation list for an unknown class', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const annotations = reflector.annotations(UnknownClass);
    expect(annotations).toEqual([]);
  });

  it('should get and empty annotation list for a symbol with null value', () => {
    init({
      '/tmp/test.ts': `
        export var x = null;
      `
    });
    const annotations = reflector.annotations(reflector.getStaticSymbol('/tmp/test.ts', 'x'));
    expect(annotations).toEqual([]);
  });

  it('should get propMetadata for HeroDetailComponent', () => {
    const HeroDetailComponent =
        reflector.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
    const props = reflector.propMetadata(HeroDetailComponent);
    expect(props['hero']).toBeTruthy();
    expect(props['onMouseOver']).toEqual([new HostListener('mouseover', ['$event'])]);
  });

  it('should get an empty object from propMetadata for an unknown class', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const properties = reflector.propMetadata(UnknownClass);
    expect(properties).toEqual({});
  });

  it('should get empty parameters list for an unknown class ', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const parameters = reflector.parameters(UnknownClass);
    expect(parameters).toEqual([]);
  });
//.........这里部分代码省略.........
开发者ID:JSMike,项目名称:angular,代码行数:101,代码来源:static_reflector_spec.ts


示例2: describe

describe('StaticReflector', () => {
  let noContext: StaticSymbol;
  let host: StaticSymbolResolverHost;
  let symbolResolver: StaticSymbolResolver;
  let reflector: StaticReflector;

  function init(
      testData: {[key: string]: any} = DEFAULT_TEST_DATA,
      decorators: {name: string, filePath: string, ctor: any}[] = [],
      errorRecorder?: (error: any, fileName: string) => void, collectorOptions?: CollectorOptions) {
    const symbolCache = new StaticSymbolCache();
    host = new MockStaticSymbolResolverHost(testData, collectorOptions);
    const summaryResolver = new MockSummaryResolver([]);
    spyOn(summaryResolver, 'isLibraryFile').and.returnValue(false);
    symbolResolver = new StaticSymbolResolver(host, symbolCache, summaryResolver, errorRecorder);
    reflector = new StaticReflector(summaryResolver, symbolResolver, decorators, [], errorRecorder);
    noContext = reflector.getStaticSymbol('', '');
  }

  beforeEach(() => init());

  function simplify(context: StaticSymbol, value: any) {
    return reflector.simplify(context, value);
  }

  it('should get annotations for NgFor', () => {
    const NgFor = reflector.findDeclaration('@angular/common/src/directives/ng_for', 'NgFor');
    const annotations = reflector.annotations(NgFor);
    expect(annotations.length).toEqual(1);
    const annotation = annotations[0];
    expect(annotation.selector).toEqual('[ngFor][ngForOf]');
    expect(annotation.inputs).toEqual(['ngForTrackBy', 'ngForOf', 'ngForTemplate']);
  });

  it('should get constructor for NgFor', () => {
    const NgFor = reflector.findDeclaration('@angular/common/src/directives/ng_for', 'NgFor');
    const ViewContainerRef = reflector.findDeclaration('@angular/core', 'ViewContainerRef');
    const TemplateRef = reflector.findDeclaration('@angular/core', 'TemplateRef');
    const IterableDiffers = reflector.findDeclaration('@angular/core', 'IterableDiffers');
    const ChangeDetectorRef = reflector.findDeclaration('@angular/core', 'ChangeDetectorRef');

    const parameters = reflector.parameters(NgFor);
    expect(parameters).toEqual([
      [ViewContainerRef], [TemplateRef], [IterableDiffers], [ChangeDetectorRef]
    ]);
  });

  it('should get annotations for HeroDetailComponent', () => {
    const HeroDetailComponent =
        reflector.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
    const annotations = reflector.annotations(HeroDetailComponent);
    expect(annotations.length).toEqual(1);
    const annotation = annotations[0];
    expect(annotation.selector).toEqual('my-hero-detail');
  });

  it('should get and empty annotation list for an unknown class', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const annotations = reflector.annotations(UnknownClass);
    expect(annotations).toEqual([]);
  });

  it('should get and empty annotation list for a symbol with null value', () => {
    init({
      '/tmp/test.ts': `
        export var x = null;
      `
    });
    const annotations = reflector.annotations(reflector.getStaticSymbol('/tmp/test.ts', 'x'));
    expect(annotations).toEqual([]);
  });

  it('should get propMetadata for HeroDetailComponent', () => {
    const HeroDetailComponent =
        reflector.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
    const props = reflector.propMetadata(HeroDetailComponent);
    expect(props['hero']).toBeTruthy();
    expect(props['onMouseOver']).toEqual([compilerCore.createHostListener(
        'mouseover', ['$event'])]);
  });

  it('should get an empty object from propMetadata for an unknown class', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const properties = reflector.propMetadata(UnknownClass);
    expect(properties).toEqual({});
  });

  it('should get empty parameters list for an unknown class ', () => {
    const UnknownClass = reflector.findDeclaration('src/app/app.component', 'UnknownClass');
    const parameters = reflector.parameters(UnknownClass);
    expect(parameters).toEqual([]);
  });

  it('should provide context for errors reported by the collector', () => {
    const SomeClass = reflector.findDeclaration('src/error-reporting', 'SomeClass');
    expect(() => reflector.annotations(SomeClass))
        .toThrow(new Error(
            'Error encountered resolving symbol values statically. A reasonable error message (position 13:34 in the original .ts file), resolving symbol ErrorSym in /tmp/src/error-references.d.ts, resolving symbol Link2 in /tmp/src/error-references.d.ts, resolving symbol Link1 in /tmp/src/error-references.d.ts, resolving symbol SomeClass in /tmp/src/error-reporting.d.ts, resolving symbol SomeClass in /tmp/src/error-reporting.d.ts'));
  });

//.........这里部分代码省略.........
开发者ID:smart-web-rock,项目名称:angular,代码行数:101,代码来源:static_reflector_spec.ts


示例3: it

 it('should record data about the error in the exception', () => {
   let threw = false;
   try {
     const metadata = host.getMetadataFor('/tmp/src/invalid-metadata.ts');
     expect(metadata).toBeDefined();
     const moduleMetadata: any = metadata[0]['metadata'];
     expect(moduleMetadata).toBeDefined();
     const classData: any = moduleMetadata['InvalidMetadata'];
     expect(classData).toBeDefined();
     simplify(
         reflector.getStaticSymbol('/tmp/src/invalid-metadata.ts', ''), classData.decorators[0]);
   } catch (e) {
     expect(e.fileName).toBe('/tmp/src/invalid-metadata.ts');
     threw = true;
   }
   expect(threw).toBe(true);
 });
开发者ID:JSMike,项目名称:angular,代码行数:17,代码来源:static_reflector_spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript compiler.UrlResolver类代码示例发布时间:2022-05-28
下一篇:
TypeScript compiler.StaticSymbolCache类代码示例发布时间: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