TypeScript @angular-compiler-testing-src-output-source_map_util.originalPositionFor类(方法)实例源码

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

作者:DeepanParik    项目:angula   
it('should map non template parts to the factory 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: ngFactoryPath});
      });

作者: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);
}

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

        const sm = ctx.toSourceMapGenerator('o.ts', 10).toJSON() !;
        expect(originalPositionFor(sm, {line: 11, column: 0})).toEqual({
          line: 1,
          column: 0,
          source: 'a.js',
        });
      });

作者:Cammisul    项目:angula   
it('should emit an inline source map', () => {
        const source = new ParseSourceFile(';;;var', 'in.js');
        const startLocation = new ParseLocation(source, 0, 0, 3);
        const endLocation = new ParseLocation(source, 7, 0, 6);
        const sourceSpan = new ParseSourceSpan(startLocation, endLocation);
        const someVar = o.variable('someVar', null, sourceSpan);
        const sm = emitSourceMap(someVar.toStmt(), '/* MyPreamble \n */');

        expect(sm.sources).toEqual([someGenFilePath, 'in.js']);
        expect(sm.sourcesContent).toEqual([' ', ';;;var']);
        expect(originalPositionFor(sm, {line: 3, column: 0}))
            .toEqual({line: 1, column: 3, source: 'in.js'});
      });


问题


面经


文章

微信
公众号

扫码关注公众号