當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript source-map.SourceMapGenerator類代碼示例

本文整理匯總了TypeScript中source-map.SourceMapGenerator的典型用法代碼示例。如果您正苦於以下問題:TypeScript SourceMapGenerator類的具體用法?TypeScript SourceMapGenerator怎麽用?TypeScript SourceMapGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SourceMapGenerator類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: merge

export function merge(
  oldMap: RawSourceMap,
  newMap: RawSourceMap
): RawSourceMap {
  if (!oldMap) return newMap
  if (!newMap) return oldMap

  const oldMapConsumer: SourceMapConsumer = new SourceMapConsumer(oldMap) as any
  const newMapConsumer: SourceMapConsumer = new SourceMapConsumer(newMap) as any
  const mergedMapGenerator = new SourceMapGenerator()

  // iterate on new map and overwrite original position of new map with one of old map
  newMapConsumer.eachMapping((mapping: MappingItem) => {
    // pass when `originalLine` is null.
    // It occurs in case that the node does not have origin in original code.
    if (mapping.originalLine == null) return

    const origPosInOldMap = oldMapConsumer.originalPositionFor({
      line: mapping.originalLine,
      column: mapping.originalColumn
    })

    if (origPosInOldMap.source == null) return

    mergedMapGenerator.addMapping({
      original: {
        line: origPosInOldMap.line,
        column: origPosInOldMap.column
      },
      generated: {
        line: mapping.generatedLine,
        column: mapping.generatedColumn
      },
      source: origPosInOldMap.source,
      name: origPosInOldMap.name
    } as any)
  })

  const maps = [oldMap, newMap]
  const consumers = [oldMapConsumer, newMapConsumer]
  consumers.forEach((consumer, index) => {
    maps[index].sources.forEach(sourceFile => {
      const sourceContent = consumer.sourceContentFor(sourceFile, true)
      if (sourceContent !== null) {
        mergedMapGenerator.setSourceContent(sourceFile, sourceContent)
      }
    })
  })

  return JSON.parse(mergedMapGenerator.toString())
}
開發者ID:vuejs,項目名稱:vue-component-compiler,代碼行數:51,代碼來源:source-map.ts

示例5: combineSourceMaps

function combineSourceMaps(
    program: ts.Program, filePath: string, tscSourceMapText: string): string {
  const tscSourceMap = parseSourceMap(tscSourceMapText);
  let tscSourceMapGenerator: SourceMapGenerator|undefined;
  for (const sourceFileName of tscSourceMap.sources) {
    const sourceFile = program.getSourceFile(sourceFileName);
    if (!sourceFile || !containsInlineSourceMap(sourceFile.text)) {
      continue;
    }
    const preexistingSourceMapText = extractInlineSourceMap(sourceFile.text);
    if (!tscSourceMapGenerator) {
      tscSourceMapGenerator = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(tscSourceMap));
    }
    tscSourceMapGenerator.applySourceMap(
        new SourceMapConsumer(parseSourceMap(preexistingSourceMapText, sourceFileName)));
  }
  return tscSourceMapGenerator ? tscSourceMapGenerator.toString() : tscSourceMapText;
}
開發者ID:lucidsoftware,項目名稱:tsickle,代碼行數:18,代碼來源:transformer.ts

示例6: mergeSourceMaps

export function mergeSourceMaps(
    oldMap: RawSourceMap | null, newMap: RawSourceMap): SourceMapConverter {
  if (!oldMap) {
    return fromObject(newMap);
  }
  const oldMapConsumer = new SourceMapConsumer(oldMap);
  const newMapConsumer = new SourceMapConsumer(newMap);
  const mergedMapGenerator = SourceMapGenerator.fromSourceMap(newMapConsumer);
  mergedMapGenerator.applySourceMap(oldMapConsumer);
  const merged = fromJSON(mergedMapGenerator.toString());
  return merged;
}
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:12,代碼來源:renderer.ts

示例7: 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

示例8: it

  it('should properly combine mapped characters from same source', () => {
    generator.addMapping(
        {generated: {line: 1, column: 0}, original: {line: 1, column: 0}, source: './origin-a.ts'});

    generator.addMapping(
        {generated: {line: 1, column: 1}, original: {line: 1, column: 0}, source: './origin-b.ts'});

    generator.addMapping({
      generated: {line: 1, column: 2},
      original: {line: 10, column: 0},
      source: './origin-a.ts'
    });

    // A => origin-a (1 byte), B => origin-b (two bytes)
    const mapPath = writeFile('/test.map', generator.toString());
    const inputPath = writeFile('/test.js', `ABB`);

    const {sizeResult} = new SizeTracker(inputPath, mapPath);

    expect(sizeResult.unmapped).toBe(0);
    expect(sizeResult.files).toEqual({
      size: 3,
      'origin-a.ts': 2,
      'origin-b.ts': 1,
    });
  });
開發者ID:marclaval,項目名稱:angular,代碼行數:26,代碼來源:size_tracking_spec.ts


注:本文中的source-map.SourceMapGenerator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。