當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。