TypeScript @angular-compiler-src-output-abstract_emitter.EmitterVisitorContext类(方法)实例源码

下面列出了TypeScript @angular-compiler-src-output-abstract_emitter.EmitterVisitorContext 类(方法)源码代码实例,从而了解它的用法。

作者:IdeaBlad    项目:angula   
// returns the number of segments per line
function nbSegmentsPerLine(ctx: EmitterVisitorContext) {
  const sm = ctx.toSourceMapGenerator('o.ts').toJSON() !;
  const lines = sm.mappings.split(';');
  return lines.map(l => {
    const m = l.match(/,/g);
    return m === null ? 1 : m.length + 1;
  });
}

作者:IdeaBlad    项目:angula   
// All lines / columns indexes are 0-based
// Note: source-map line indexes are 1-based, column 0-based
function expectMap(
    ctx: EmitterVisitorContext, genLine: number, genCol: number, source: string | null = null,
    srcLine: number | null = null, srcCol: number | null = null) {
  const sm = ctx.toSourceMapGenerator('o.ts').toJSON() !;
  const genPosition = {line: genLine + 1, column: genCol};
  const origPosition = originalPositionFor(sm, genPosition);
  expect(origPosition.source).toEqual(source);
  expect(origPosition.line).toEqual(srcLine === null ? null : srcLine + 1);
  expect(origPosition.column).toEqual(srcCol);
}

作者:AnthonyPAlice    项目:angula   
it('should generate unique argument names', () => {
   const externalIds = new Array(10).fill(1).map(
       (_, index) =>
           new o.ExternalReference(anotherModuleUrl, `id_${index}_`, {name: `id_${index}_`}));
   const externalIds1 = new Array(10).fill(1).map(
       (_, index) => new o.ExternalReference(
           anotherModuleUrl, `id_${index}_1`, {name: `id_${index}_1`}));
   const ctx = EmitterVisitorContext.createRoot();
   const converter = new JitEmitterVisitor(new JitReflector());
   converter.visitAllStatements(
       [o.literalArr([...externalIds1, ...externalIds].map(id => o.importExpr(id))).toStmt()],
       ctx);
   const args = converter.getArgs();
   expect(Object.keys(args).length).toBe(20);
 });

作者:IdeaBlad    项目:angula   
it('should map leading segment without span', () => {
        ctx.print(null, '....');
        ctx.print(createSourceSpan(fileA, 0), 'fileA-0');

        expectMap(ctx, 0, 0, 'o.ts', 0, 0);
        expectMap(ctx, 0, 4, 'a.js', 0, 0);
        expect(nbSegmentsPerLine(ctx)).toEqual([2]);
      });

作者:manekinekk    项目:angula   
it('should be able to shift the content', () => {
        ctx.print(createSourceSpan(fileA, 0), 'fileA-0');

        const sm = ctx.toSourceMapGenerator(null, 10).toJSON();
        const smc = new SourceMapConsumer(sm);
        expect(smc.originalPositionFor({line: 11, column: 0})).toEqual({
          line: 1,
          column: 0,
          source: 'a.js',
          name: null,
        });
      });


问题


面经


文章

微信
公众号

扫码关注公众号