本文整理汇总了TypeScript中source-map.SourceMapConsumer.originalPositionFor方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SourceMapConsumer.originalPositionFor方法的具体用法?TypeScript SourceMapConsumer.originalPositionFor怎么用?TypeScript SourceMapConsumer.originalPositionFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类source-map.SourceMapConsumer
的用法示例。
在下文中一共展示了SourceMapConsumer.originalPositionFor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseInt
browser.manage().logs().get('browser').then(function(logs) {
var errorLine = null;
var errorColumn = null;
logs.forEach(function(log) {
var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
if (match) {
errorLine = parseInt(match[1]);
errorColumn = parseInt(match[2]);
}
});
expect(errorLine).not.toBeNull();
expect(errorColumn).not.toBeNull();
var sourceMapData = fs.readFileSync('dist/js/prod/es5/examples/src/sourcemap/index.js.map');
var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
var originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
var finalMapData = fs.readFileSync('dist/js/prod/es6/examples/src/sourcemap/index.js.map');
var finalDecoder = new sourceMap.SourceMapConsumer(JSON.parse(finalMapData));
var finalPosition = finalDecoder.originalPositionFor(originalPosition);
var sourceCodeLines =
fs.readFileSync('modules/examples/src/sourcemap/index.ts', {encoding: 'UTF-8'})
.split('\n');
expect(sourceCodeLines[finalPosition.line - 1])
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
});
示例2: _updateLocation
// Update a location object from a SourceMap. Will ignore the location if the sourcemap does
// not have a valid mapping.
private _updateLocation(consumer: SourceMapConsumer, location: CoverageLocation) {
const start = consumer.originalPositionFor(location.start);
const end = consumer.originalPositionFor(location.end);
// Filter invalid original positions.
if (start.line !== null && start.column !== null) {
// Filter unwanted properties.
location.start = { line: start.line, column: start.column };
}
if (end.line !== null && end.column !== null) {
location.end = { line: end.line, column: end.column };
}
}
示例3: parseInt
browser.manage().logs().get('browser').then(function(logs) {
var errorLine = null;
var errorColumn = null;
logs.forEach(function(log) {
var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
if (match) {
errorLine = parseInt(match[1]);
errorColumn = parseInt(match[2]);
}
});
expect(errorLine).not.toBeNull();
expect(errorColumn).not.toBeNull();
const content =
fs.readFileSync('dist/all/playground/src/sourcemap/index.js').toString("utf8");
const marker = "//# sourceMappingURL=data:application/json;base64,";
const index = content.indexOf(marker);
const sourceMapData =
new Buffer(content.substring(index + marker.length), 'base64').toString("utf8");
var decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
var originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
var sourceCodeLines =
fs.readFileSync('modules/playground/src/sourcemap/index.ts', {encoding: 'UTF-8'})
.split('\n');
expect(sourceCodeLines[originalPosition.line - 1])
.toMatch(/throw new BaseException\(\'Sourcemap test\'\)/);
});
示例4: parseInt
browser.manage().logs().get(logging.Type.BROWSER).then(function(logs: any) {
let errorLine: number = null;
let errorColumn: number = null;
logs.forEach(function(log: any) {
const match = log.message.match(/\.createError\s+\(.+:(\d+):(\d+)/m);
if (match) {
errorLine = parseInt(match[1]);
errorColumn = parseInt(match[2]);
}
});
expect(errorLine).not.toBeNull();
expect(errorColumn).not.toBeNull();
const content =
fs.readFileSync(require.resolve('../../src/sourcemap/index.js')).toString('utf8');
const marker = '//# sourceMappingURL=data:application/json;base64,';
const index = content.indexOf(marker);
const sourceMapData =
Buffer.from(content.substring(index + marker.length), 'base64').toString('utf8');
const decoder = new sourceMap.SourceMapConsumer(JSON.parse(sourceMapData));
const originalPosition = decoder.originalPositionFor({line: errorLine, column: errorColumn});
const sourceCodeLines = fs.readFileSync(require.resolve('../../src/sourcemap/index.ts'), {
encoding: 'UTF-8'
}).split('\n');
expect(sourceCodeLines[originalPosition.line - 1])
.toMatch(/throw new Error\(\'Sourcemap test\'\)/);
});
示例5: originalPositionFor
export function originalPositionFor(
sourceMap: SourceMap, genPosition: {line: number, column: number}): SourceLocation {
const smc = new SourceMapConsumer(sourceMap);
// Note: We don't return the original object as it also contains a `name` property
// which is always null and we don't want to include that in our assertions...
const {line, column, source} = smc.originalPositionFor(genPosition);
return {line, column, source};
}
示例6:
smc1.eachMapping(function(mapping) {
var pos = {
line: mapping.generatedLine,
column: mapping.generatedColumn
};
var orig1 = smc1.originalPositionFor(pos);
var orig2 = smc2.originalPositionFor(pos);
// The composition of the source maps generated separately from
// the two transforms should be equivalent to the source map
// generated from the composition of the two transforms.
assert.deepEqual(orig1, orig2);
// Make sure the two-step source map refers back to the original
// source instead of the intermediate source.
assert.strictEqual(orig2.source, "original.js");
});
示例7: getPosition
function getPosition() {
if (!position) {
position = consumer.originalPositionFor({
column: getColumnNumber.call(callsite) || -1,
line: getLineNumber.call(callsite) || -1,
});
}
return position;
}
示例8: expectMap
// All lines / columns indexes are 0-based
// Note: source-map line indexes are 1-based, column 0-based
function expectMap(
ctx: EmitterVisitorContext, genLine: number, genCol: number, source: string = null,
srcLine: number = null, srcCol: number = null) {
const sm = ctx.toSourceMapGenerator().toJSON();
const smc = new SourceMapConsumer(sm);
const genPosition = {line: genLine + 1, column: genCol};
const origPosition = smc.originalPositionFor(genPosition);
expect(origPosition.source).toEqual(source);
expect(origPosition.line).toEqual(srcLine === null ? null : srcLine + 1);
expect(origPosition.column).toEqual(srcCol);
}
示例9: it
it('should be able to shift the content', () => {
ctx.print(createSourceSpan(fileA, 0), 'fileA-0');
const sm = ctx.toSourceMapGenerator(null, 10).toJSON();
const smc = new SourceMapConsumer(sm);
expect(smc.originalPositionFor({line: 11, column: 0})).toEqual({
line: 1,
column: 0,
source: 'a.js',
name: null,
});
});
示例10: it
it('generates a source map', () => {
const sources = new Map<string, string>();
sources.set('input.ts', `
class X { field: number; }
class Y { field2: string; }`);
const program = createProgram(sources);
const sourceMapper = new DefaultSourceMapper('input.ts');
const annotated = annotate(
program.getTypeChecker(), program.getSourceFile('input.ts'),
{pathToModuleName: () => 'input'}, {}, undefined, undefined, sourceMapper);
const rawMap = sourceMapper.sourceMap.toJSON();
const consumer = new SourceMapConsumer(rawMap);
const lines = annotated.output.split('\n');
// Uncomment to debug contents:
// lines.forEach((v, i) => console.log(i + 1, v));
// Find class X and class Y in the output to make the test robust against code changes.
const firstClassLine = lines.findIndex(l => l.indexOf('class X') !== -1) + 1;
const secondClassLine = lines.findIndex(l => l.indexOf('class Y') !== -1) + 1;
expect(consumer.originalPositionFor({line: firstClassLine, column: 20}).line)
.to.equal(2, 'first class definition');
expect(consumer.originalPositionFor({line: secondClassLine, column: 20}).line)
.to.equal(3, 'second class definition');
});