当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript source-map.SourceMapConsumer类代码示例

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


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

示例1: parseInt

    browser.manage().logs().get('browser').then(function(logs) {
      var errorLine = null;
      var errorColumn = null;
      logs.forEach(function(log) {
        var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
        if (match) {
          errorLine = parseInt(match[1]);
          errorColumn = parseInt(match[2]);
        }
      });

      expect(errorLine).not.toBeNull();
      expect(errorColumn).not.toBeNull();


      var sourceMapData = fs.readFileSync('dist/js/prod/es5/playground/src/sourcemap/index.js.map');
      var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));

      var originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});

      var sourceCodeLines =
          fs.readFileSync('modules/playground/src/sourcemap/index.ts', {encoding: 'UTF-8'})
              .split('\n');
      expect(sourceCodeLines[originalPosition.line - 1])
          .toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
    });
开发者ID:TedSander,项目名称:angular,代码行数:26,代码来源:sourcemap_spec.ts

示例2: testMapping

  async function testMapping(
      sourcemap: RawSourceMap, html: string, name: string) {
    const consumer = new SourceMapConsumer(sourcemap!);
    let foundMapping = false;
    const mappings: MappingItem[] = [];
    consumer.eachMapping((mapping) => mappings.push(mapping));
    for (let j = 0; j < mappings.length; j++) {
      if (mappings[j].name === name) {
        foundMapping = true;
        const generatedLine = getLine(html, mappings[j].generatedLine);
        assert(generatedLine, 'generated line not found');
        assert.equal(
            mappings[j].generatedColumn,
            generatedLine!.indexOf(name),
            'generated column');

        const originalContents =
            await urlLoader.load(mappings[j].source as ResolvedUrl);
        const originalLine =
            getLine(originalContents, mappings[j].originalLine);
        assert(originalLine, 'original line not found');
        assert.equal(
            mappings[j].originalColumn,
            originalLine!.indexOf(name),
            'original column');
      }
    }
  }
开发者ID:Polymer,项目名称:tools,代码行数:28,代码来源:sourcemap_test.ts

示例3: offsetSourceMap

function offsetSourceMap(
    sourcemap: RawSourceMap, lineOffset: number, firstLineCharOffset: number) {
  const consumer = new SourceMapConsumer(sourcemap);
  const generator = new SourceMapGenerator();

  consumer.eachMapping((mapping) => {
    if (typeof mapping.originalLine !== 'number' ||
        typeof mapping.originalColumn !== 'number') {
      return;
    }
    const newMapping: Mapping = {
      source: mapping.source,
      generated: {
        line: mapping.generatedLine + lineOffset,
        column: mapping.generatedColumn +
            (mapping.generatedLine === 1 ? firstLineCharOffset : 0)
      },
      original: {line: mapping.originalLine, column: mapping.originalColumn}
    };

    if (mapping.name) {
      newMapping.name = mapping.name;
    }

    generator.addMapping(newMapping);
  });

  return generator.toJSON();
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:29,代码来源:source-map.ts

示例4: parseInt

    browser.manage().logs().get(logging.Type.BROWSER).then(function(logs: any) {
      let errorLine: number = null;
      let errorColumn: number = null;
      logs.forEach(function(log: any) {
        const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m);
        if (match) {
          errorLine = parseInt(match[1]);
          errorColumn = parseInt(match[2]);
        }
      });

      expect(errorLine).not.toBeNull();
      expect(errorColumn).not.toBeNull();


      const content =
          fs.readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
      const marker = '//# sourceMappingURL=data:application/json;base64,';
      const index = content.indexOf(marker);
      const sourceMapData =
          Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');

      const decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));

      const originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});

      const sourceCodeLines = fs.readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
                                  encoding: 'UTF-8'
                                }).split('\n');
      expect(sourceCodeLines[originalPosition.line - 1])
          .toMatch(/throw new Error\(\'Sourcemap test\'\)/);
    });
开发者ID:BobChao87,项目名称:angular,代码行数:32,代码来源:sourcemap_spec.ts

示例5: parseInt

    browser.manage().logs().get('browser').then(function(logs) {
      var errorLine = null;
      var errorColumn = null;
      logs.forEach(function(log) {
        var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
        if (match) {
          errorLine = parseInt(match[1]);
          errorColumn = parseInt(match[2]);
        }
      });

      expect(errorLine).not.toBeNull();
      expect(errorColumn).not.toBeNull();


      const content =
          fs.readFileSync('dist/all/playground/src/sourcemap/index.js').toString("utf8");
      const marker = "//# sourceMappingURL=data:application/json;base64,";
      const index = content.indexOf(marker);
      const sourceMapData =
          new Buffer(content.substring(index + marker.length), 'base64').toString("utf8");

      var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));

      var originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});

      var sourceCodeLines =
          fs.readFileSync('modules/playground/src/sourcemap/index.ts', {encoding: 'UTF-8'})
              .split('\n');
      expect(sourceCodeLines[originalPosition.line - 1])
          .toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
    });
开发者ID:0xJoKe,项目名称:angular,代码行数:32,代码来源:sourcemap_spec.ts

示例6: originalPositionFor

export function originalPositionFor(
    sourceMap: SourceMap, genPosition: {line: number, column: number}): SourceLocation {
  const smc = new SourceMapConsumer(sourceMap);
  // Note: We don't return the original object as it also contains a `name` property
  // which is always null and we don't want to include that in our assertions...
  const {line, column, source} = smc.originalPositionFor(genPosition);
  return {line, column, source};
}
开发者ID:JohnnyQQQQ,项目名称:angular,代码行数:8,代码来源:source_map_util.ts

示例7: expectMap

// 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,
    srcLine: number = null, srcCol: number = null) {
  const sm = ctx.toSourceMapGenerator().toJSON();
  const smc = new SourceMapConsumer(sm);
  const genPosition = {line: genLine + 1, column: genCol};
  const origPosition = smc.originalPositionFor(genPosition);
  expect(origPosition.source).toEqual(source);
  expect(origPosition.line).toEqual(srcLine === null ? null : srcLine + 1);
  expect(origPosition.column).toEqual(srcCol);
}
开发者ID:manekinekko,项目名称:angular,代码行数:13,代码来源:abstract_emitter_node_only_spec.ts

示例8: it

      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,
        });
      });
开发者ID:manekinekko,项目名称:angular,代码行数:12,代码来源:abstract_emitter_node_only_spec.ts

示例9: mappingItemsOf

 function mappingItemsOf(text: string): MappingItem[] {
   // find the source map:
   const sourceMapMatch = /sourceMappingURL\=data\:application\/json;base64,(.*)$/.exec(text);
   const sourceMapBase64 = sourceMapMatch ![1];
   const sourceMapBuffer = Buffer.from(sourceMapBase64, 'base64');
   const sourceMapText = sourceMapBuffer.toString('utf8');
   const sourceMap: RawSourceMap = JSON.parse(sourceMapText);
   const consumer = new SourceMapConsumer(sourceMap);
   const mappings: MappingItem[] = [];
   consumer.eachMapping(mapping => { mappings.push(mapping); });
   return mappings;
 }
开发者ID:AnthonyPAlicea,项目名称:angular,代码行数:12,代码来源:node_emitter_spec.ts

示例10: _updateLocation

  // Update a location object from a SourceMap. Will ignore the location if the sourcemap does
  // not have a valid mapping.
  private _updateLocation(consumer: SourceMapConsumer, location: CoverageLocation) {
    const start = consumer.originalPositionFor(location.start);
    const end = consumer.originalPositionFor(location.end);

    // Filter invalid original positions.
    if (start.line !== null && start.column !== null) {
      // Filter unwanted properties.
      location.start = { line: start.line, column: start.column };
    }
    if (end.line !== null && end.column !== null) {
      location.end = { line: end.line, column: end.column };
    }
  }
开发者ID:DevIntent,项目名称:angular-cli,代码行数:15,代码来源:test.ts


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