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

TypeScript compiler.StaticReflector类代码示例

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

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



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

示例1: init

 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);
   symbolResolver =
       new StaticSymbolResolver(host, symbolCache, new MockSummaryResolver([]), errorRecorder);
   reflector = new StaticReflector(symbolResolver, decorators, [], errorRecorder);
   noContext = reflector.getStaticSymbol('', '');
 }
开发者ID:acramatte,项目名称:angular,代码行数:11,代码来源:static_reflector_spec.ts


示例2: it

  it('should quote identifiers quoted in the source', () => {
    const sourceText = `
      import {Component} from '@angular/core';

      @Component({
        providers: [{ provide: 'SomeToken', useValue: {a: 1, 'b': 2, c: 3, 'd': 4}}]
      })
      export class MyComponent {}
    `;
    const source = ts.createSourceFile('test.ts', sourceText, ts.ScriptTarget.Latest);
    const collector = new MetadataCollector({quotedNames: true});
    const stubHost = new StubReflectorHost();
    const symbolCache = new StaticSymbolCache();
    const symbolResolver =
        new StaticSymbolResolver(stubHost, symbolCache, new MockSummaryResolver());
    const reflector = new StaticReflector(symbolResolver);

    // Get the metadata from the above source
    const metadata = collector.getMetadata(source);
    const componentMetadata = metadata.metadata['MyComponent'];

    // Get the first argument of the decorator call which is passed to @Component
    expect(isClassMetadata(componentMetadata)).toBeTruthy();
    if (!isClassMetadata(componentMetadata)) return;
    const decorators = componentMetadata.decorators;
    const firstDecorator = decorators[0];
    expect(isMetadataSymbolicCallExpression(firstDecorator)).toBeTruthy();
    if (!isMetadataSymbolicCallExpression(firstDecorator)) return;
    const firstArgument = firstDecorator.arguments[0];

    // Simplify this value using the StaticReflector
    const context = reflector.getStaticSymbol('none', 'none');
    const argumentValue = reflector.simplify(context, firstArgument);

    // Convert the value to an output AST
    const outputAst = convertValueToOutputAst(argumentValue);
    const statement = outputAst.toStmt();

    // Convert the value to text using the typescript emitter
    const emitter = new TypeScriptEmitter(new StubImportResolver());
    const text = emitter.emitStatements('module', [statement], []);

    // Expect the keys for 'b' and 'd' to be quoted but 'a' and 'c' not to be.
    expect(text).toContain('\'b\': 2');
    expect(text).toContain('\'d\': 4');
    expect(text).not.toContain('\'a\'');
    expect(text).not.toContain('\'c\'');
  });
开发者ID:DzmitryShylovich,项目名称:angular,代码行数:48,代码来源:ts_emitter_node_only_spec.ts


示例3: it

 it('should be able to get metadata for a class with nested method calls', () => {
   const annotations = reflector.annotations(
       reflector.getStaticSymbol('/tmp/src/static-method-call.ts', 'MyFactoryComponent'));
   expect(annotations.length).toBe(1);
   expect(annotations[0].providers).toEqual({
     provide: 'c',
     useFactory:
         reflector.getStaticSymbol('/tmp/src/static-method.ts', 'AnotherModule', ['someFactory'])
   });
 });
开发者ID:willyelm,项目名称:angular,代码行数:10,代码来源:static_reflector_spec.ts


示例4: MyValidationDecorator

  it('should not throw on unknown decorators', () => {
    const data = Object.create(DEFAULT_TEST_DATA);
    const file = '/tmp/src/app.component.ts';
    data[file] = `
      import { Component } from '@angular/core';

      export const enum TypeEnum {
        type
      }

      export function MyValidationDecorator(p1: any, p2: any): any {
        return null;
      }

      export function ValidationFunction(a1: any): any {
        return null;
      }

      @Component({
        selector: 'my-app',
        template: "<h1>Hello {{name}}</h1>",
      })
      export class AppComponent  {
        name = 'Angular';

        @MyValidationDecorator( TypeEnum.type, ValidationFunction({option: 'value'}))
        myClassProp: number;
    }`;
    init(data);
    const appComponent = reflector.getStaticSymbol(file, 'AppComponent');
    expect(() => reflector.propMetadata(appComponent)).not.toThrow();
  });
开发者ID:JSMike,项目名称:angular,代码行数:32,代码来源:static_reflector_spec.ts


示例5: it

 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'})]))])]))
   ])]);
 });
开发者ID:JSMike,项目名称:angular,代码行数:16,代码来源:static_reflector_spec.ts


示例6: it

  it('should continue to aggresively evaluate enum member accessors', () => {
    const data = Object.create(DEFAULT_TEST_DATA);
    const file = '/tmp/src/my_component.ts';
    data[file] = `
      import {Component} from '@angular/core';
      import {intermediate} from './index';

      @Component({
        template: '<div></div>',
        providers: [{provide: 'foo', useValue: [...intermediate]}]
      })
      export class MyComponent { }
    `;
    data['/tmp/src/intermediate.ts'] = `
      import {MyEnum} from './indirect';
      export const intermediate = [{
        data: {
          c: [MyEnum.Value]
        }
      }];`;
    data['/tmp/src/index.ts'] = `export * from './intermediate';`;
    data['/tmp/src/indirect.ts'] = `export * from './consts';`;
    data['/tmp/src/consts.ts'] = `
      export enum MyEnum {
        Value = 3
      }
    `;
    init(data);

    expect(reflector.annotations(reflector.getStaticSymbol(file, 'MyComponent'))[0]
               .providers[0]
               .useValue)
        .toEqual([{data: {c: [3]}}]);
  });
开发者ID:smart-web-rock,项目名称:angular,代码行数:34,代码来源:static_reflector_spec.ts


示例7: it

  it('should be able to inject a ctor parameter with a @Inject and a type expression', () => {
    const data = Object.create(DEFAULT_TEST_DATA);
    const file = '/tmp/src/invalid-component.ts';
    data[file] = `
        import {Injectable, Inject} from '@angular/core';

        @Injectable()
        export class SomeClass {
          constructor (@Inject('some-token') a: {a: string, b: string}) {}
        }
      `;
    init(data);

    const someClass = reflector.getStaticSymbol(file, 'SomeClass');
    const parameters = reflector.parameters(someClass);
    expect(compilerCore.createInject.isTypeOf(parameters[0][0])).toBe(true);
  });
开发者ID:MarkPieszak,项目名称:angular,代码行数:17,代码来源:static_reflector_spec.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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