本文整理匯總了TypeScript中source-map.SourceMapGenerator.fromSourceMap方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SourceMapGenerator.fromSourceMap方法的具體用法?TypeScript SourceMapGenerator.fromSourceMap怎麽用?TypeScript SourceMapGenerator.fromSourceMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類source-map.SourceMapGenerator
的用法示例。
在下文中一共展示了SourceMapGenerator.fromSourceMap方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: buildOptimizer
export default function buildOptimizerLoader
(this: webpack.loader.LoaderContext, content: string, previousSourceMap: RawSourceMap) {
this.cacheable();
const options: BuildOptimizerLoaderOptions = loaderUtils.getOptions(this) || {};
// Make up names of the intermediate files so we can chain the sourcemaps.
const inputFilePath = this.resourcePath + '.pre-build-optimizer.js';
const outputFilePath = this.resourcePath + '.post-build-optimizer.js';
const boOutput = buildOptimizer({
content,
originalFilePath: this.resourcePath,
inputFilePath,
outputFilePath,
emitSourceMap: options.sourceMap,
isSideEffectFree: this._module
&& this._module.factoryMeta
&& this._module.factoryMeta.sideEffectFree,
});
if (boOutput.emitSkipped || boOutput.content === null) {
// Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
// tslint:disable-next-line:no-any
this.callback(null, content, previousSourceMap as any);
return;
}
const intermediateSourceMap = boOutput.sourceMap;
let newContent = boOutput.content;
let newSourceMap;
if (options.sourceMap && intermediateSourceMap) {
// Webpack doesn't need sourceMappingURL since we pass them on explicitely.
newContent = newContent.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
if (previousSourceMap) {
// If there's a previous sourcemap, we have to chain them.
// See https://github.com/mozilla/source-map/issues/216#issuecomment-150839869 for a simple
// source map chaining example.
// Use http://sokra.github.io/source-map-visualization/ to validate sourcemaps make sense.
// Force the previous sourcemap to use the filename we made up for it.
// In order for source maps to be chained, the consumed source map `file` needs to be in the
// consumers source map `sources` array.
previousSourceMap.file = inputFilePath;
// Chain the sourcemaps.
const consumer = new SourceMapConsumer(intermediateSourceMap);
const generator = SourceMapGenerator.fromSourceMap(consumer);
generator.applySourceMap(new SourceMapConsumer(previousSourceMap));
newSourceMap = generator.toJSON();
} else {
// Otherwise just return our generated sourcemap.
newSourceMap = intermediateSourceMap;
}
}
// Webpack typings for previousSourceMap are wrong, they are JSON objects and not strings.
// tslint:disable-next-line:no-any
this.callback(null, newContent, newSourceMap as any);
}
示例4: sourceMapTextToGenerator
export function sourceMapTextToGenerator(sourceMapText: string): SourceMapGenerator {
const sourceMapJson: any = sourceMapText;
return SourceMapGenerator.fromSourceMap(sourceMapTextToConsumer(sourceMapJson));
}
示例5: sourceMapConsumerToGenerator
export function sourceMapConsumerToGenerator(sourceMapConsumer: SourceMapConsumer):
SourceMapGenerator {
return SourceMapGenerator.fromSourceMap(sourceMapConsumer);
}