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


TypeScript SourceMapGenerator.toString方法代码示例

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


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

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

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

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

示例4: assembleFromSource


//.........这里部分代码省略.........
              style.media
            )} })\n`
          : '') +
        (style.moduleName
          ? `Object.defineProperty(this, "${
              style.moduleName
            }", { value: ${tokens} })` + '\n'
          : '')
      )
    })}
  }` : 'undefined'}
  /* scoped */
  const __vue_scope_id__ = ${hasScopedStyle ? e(scopeId) : 'undefined'}
  /* module identifier */
  const __vue_module_identifier__ = ${
    compiler.template.optimizeSSR ? e(scopeId) : 'undefined'
  }
  /* functional template */
  const __vue_is_functional_template__ = ${e(template.functional)}
  /* component normalizer */
  ${normalizeComponent}
  /* style inject */
  ${hasStyle && !compiler.template.optimizeSSR ? createInjector : ''}
  /* style inject SSR */
  ${hasStyle && compiler.template.optimizeSSR ? createInjectorSSR : ''}

  `

  // generate source map.
  {
    const input = script.source.split('\n')

    input.forEach((sourceLine, index) => {
      if (!sourceLine) return
      const matches = /export\s+default/.exec(sourceLine)
      if (matches) {
        const pos = sourceLine.indexOf(matches[0])
        if (pos > 0) {
          mapGenerator.addMapping({
            source: filename,
            original: { line: index + 1, column: 0 },
            generated: { line: index + 2, column: 0 }
          })
        }

        mapGenerator.addMapping({
          source: filename,
          original: { line: index + 1, column: pos },
          generated: { line: index + 2, column: pos }
        })

        if (sourceLine.substr(pos + matches[0].length)) {
          mapGenerator.addMapping({
            source: filename,
            original: { line: index + 1, column: pos + matches[0].length },
            generated: { line: index + 2, column: pos + DEFAULT_EXPORT.length }
          })
        }
      } else {
        mapGenerator.addMapping({
          source: filename,
          original: { line: index + 1, column: 0 },
          generated: { line: index + 2, column: 0 }
        })
      }
    })
  }

  code += `
  export default __vue_normalize__(
    ${
      code.indexOf('__vue_render__') > -1
        ? '{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ }'
        : '{}'
    },
    __vue_inject_styles__,
    ${code.indexOf('__vue_script__') > -1 ? '__vue_script__' : '{}'},
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    ${
      code.indexOf('__vue_create_injector__') > -1
        ? '__vue_create_injector__'
        : 'undefined'
    },
    ${
      code.indexOf('__vue_create_injector_ssr__') > -1
        ? '__vue_create_injector_ssr__'
        : 'undefined'
    }
  )`

  if (script.map) {
    map = merge(script.map, JSON.parse(mapGenerator.toString()))
  } else {
    map = JSON.parse(mapGenerator.toString())
  }

  return { code, map }
}
开发者ID:vuejs,项目名称:vue-component-compiler,代码行数:101,代码来源:assembler.ts


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