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