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


TypeScript SourceMapGenerator.toJSON方法代码示例

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


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

示例1: generateSourceMap

function generateSourceMap(
  filename: string,
  source: string,
  generated: string,
  sourceRoot: string
): RawSourceMap {
  const map = new SourceMapGenerator({
    file: filename.replace(/\\/g, '/'),
    sourceRoot: sourceRoot.replace(/\\/g, '/')
  })
  map.setSourceContent(filename, source)
  generated.split(splitRE).forEach((line, index) => {
    if (!emptyRE.test(line)) {
      map.addMapping({
        source: filename,
        original: {
          line: index + 1,
          column: 0
        },
        generated: {
          line: index + 1,
          column: 0
        }
      })
    }
  })
  return map.toJSON()
}
开发者ID:mvolkmann,项目名称:MyUnixEnv,代码行数:28,代码来源:parse.ts

示例2: createJsIdentitySourcemap

/**
 * Creates an identity source map from JS script content. Can offset original
 * line/column data for inline script elements.
 */
function createJsIdentitySourcemap(
    sourceUrl: string,
    sourceContent: string,
    lineOffset: number,
    firstLineCharOffset: number) {
  const generator = new SourceMapGenerator();
  const tokens = espree.tokenize(
      sourceContent, {loc: true, ecmaVersion: 2017, sourceType: 'module'});
  tokens.forEach((token) => {
    if (!token.loc) {
      return null;
    }
    const mapping: Mapping = {
      original: {
        line: token.loc.start.line + lineOffset,
        column: token.loc.start.column +
            (token.loc.start.line === 1 ? firstLineCharOffset : 0)
      },
      generated: token.loc.start,
      source: sourceUrl
    };

    if (token.type === 'Identifier') {
      mapping.name = token.value;
    }

    generator.addMapping(mapping);
  });

  return generator.toJSON();
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:35,代码来源:source-map.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: sourceMapGeneratorToConsumer

export function sourceMapGeneratorToConsumer(
    sourceMapGenerator: SourceMapGenerator, fileName?: string,
    sourceName?: string): SourceMapConsumer {
  const rawSourceMap = sourceMapGenerator.toJSON();
  if (sourceName) {
    rawSourceMap.sources = [sourceName];
  }
  if (fileName) {
    rawSourceMap.file = fileName;
  }
  return new SourceMapConsumer(rawSourceMap);
}
开发者ID:Jaspreet-Lamba,项目名称:adminpanel,代码行数:12,代码来源:source_map_utils.ts


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