|
|
@ -5,28 +5,8 @@ const util = remixLib.util |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Decompress the source mapping given by solc-bin.js |
|
|
|
* Decompress the source mapping given by solc-bin.js |
|
|
|
|
|
|
|
* s:l:f:j |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function SourceMappingDecoder () { |
|
|
|
|
|
|
|
// s:l:f:j
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* get a list of nodes that are at the given @arg position |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} astNodeType - type of node to return |
|
|
|
|
|
|
|
* @param {Int} position - cursor position |
|
|
|
|
|
|
|
* @return {Object} ast object given by the compiler |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
SourceMappingDecoder.prototype.nodesAtPosition = nodesAtPosition |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Decode the source mapping for the given @arg index |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Integer} index - source mapping index to decode |
|
|
|
|
|
|
|
* @param {String} mapping - compressed source mapping given by solc-bin |
|
|
|
|
|
|
|
* @return {Object} returns the decompressed source mapping for the given index {start, length, file, jump} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
SourceMappingDecoder.prototype.atIndex = atIndex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Decode the given @arg value |
|
|
|
* Decode the given @arg value |
|
|
@ -34,7 +14,7 @@ SourceMappingDecoder.prototype.atIndex = atIndex |
|
|
|
* @param {string} value - source location to decode ( should be start:length:file ) |
|
|
|
* @param {string} value - source location to decode ( should be start:length:file ) |
|
|
|
* @return {Object} returns the decompressed source mapping {start, length, file} |
|
|
|
* @return {Object} returns the decompressed source mapping {start, length, file} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
SourceMappingDecoder.prototype.decode = function (value) { |
|
|
|
export function decode (value) { |
|
|
|
if (value) { |
|
|
|
if (value) { |
|
|
|
value = value.split(':') |
|
|
|
value = value.split(':') |
|
|
|
return { |
|
|
|
return { |
|
|
@ -51,7 +31,7 @@ SourceMappingDecoder.prototype.decode = function (value) { |
|
|
|
* @param {String} mapping - compressed source mapping given by solc-bin |
|
|
|
* @param {String} mapping - compressed source mapping given by solc-bin |
|
|
|
* @return {Array} returns the decompressed source mapping. Array of {start, length, file, jump} |
|
|
|
* @return {Array} returns the decompressed source mapping. Array of {start, length, file, jump} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
SourceMappingDecoder.prototype.decompressAll = function (mapping) { |
|
|
|
export function decompressAll (mapping) { |
|
|
|
const map = mapping.split(';') |
|
|
|
const map = mapping.split(';') |
|
|
|
const ret = [] |
|
|
|
const ret = [] |
|
|
|
for (let k in map) { |
|
|
|
for (let k in map) { |
|
|
@ -73,7 +53,7 @@ SourceMappingDecoder.prototype.decompressAll = function (mapping) { |
|
|
|
* @param {String} source - contract source code |
|
|
|
* @param {String} source - contract source code |
|
|
|
* @return {Array} returns an array containing offset of line breaks |
|
|
|
* @return {Array} returns an array containing offset of line breaks |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
SourceMappingDecoder.prototype.getLinebreakPositions = function (source) { |
|
|
|
export function getLinebreakPositions (source) { |
|
|
|
const ret = [] |
|
|
|
const ret = [] |
|
|
|
for (let pos = source.indexOf('\n'); pos >= 0; pos = source.indexOf('\n', pos + 1)) { |
|
|
|
for (let pos = source.indexOf('\n'); pos >= 0; pos = source.indexOf('\n', pos + 1)) { |
|
|
|
ret.push(pos) |
|
|
|
ret.push(pos) |
|
|
@ -88,7 +68,7 @@ SourceMappingDecoder.prototype.getLinebreakPositions = function (source) { |
|
|
|
* @param {Array} lineBreakPositions - array returned by the function 'getLinebreakPositions' |
|
|
|
* @param {Array} lineBreakPositions - array returned by the function 'getLinebreakPositions' |
|
|
|
* @return {Object} returns an object {start: {line, column}, end: {line, column}} (line/column count start at 0) |
|
|
|
* @return {Object} returns an object {start: {line, column}, end: {line, column}} (line/column count start at 0) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
SourceMappingDecoder.prototype.convertOffsetToLineColumn = function (sourceLocation, lineBreakPositions) { |
|
|
|
export function convertOffsetToLineColumn (sourceLocation, lineBreakPositions) { |
|
|
|
if (sourceLocation.start >= 0 && sourceLocation.length >= 0) { |
|
|
|
if (sourceLocation.start >= 0 && sourceLocation.length >= 0) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
start: convertFromCharPosition(sourceLocation.start, lineBreakPositions), |
|
|
|
start: convertFromCharPosition(sourceLocation.start, lineBreakPositions), |
|
|
@ -98,15 +78,6 @@ SourceMappingDecoder.prototype.convertOffsetToLineColumn = function (sourceLocat |
|
|
|
return {start: null, end: null} |
|
|
|
return {start: null, end: null} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Retrieve the first @arg astNodeType that include the source map at arg instIndex |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} astNodeType - node type that include the source map instIndex |
|
|
|
|
|
|
|
* @param {String} instIndex - instruction index used to retrieve the source map |
|
|
|
|
|
|
|
* @param {String} sourceMap - source map given by the compilation result |
|
|
|
|
|
|
|
* @param {Object} ast - ast given by the compilation result |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
SourceMappingDecoder.prototype.findNodeAtInstructionIndex = findNodeAtInstructionIndex |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function convertFromCharPosition (pos, lineBreakPositions) { |
|
|
|
function convertFromCharPosition (pos, lineBreakPositions) { |
|
|
|
let line = util.findLowerBound(pos, lineBreakPositions) |
|
|
|
let line = util.findLowerBound(pos, lineBreakPositions) |
|
|
@ -130,8 +101,16 @@ function sourceLocationFromAstNode (astNode) { |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function findNodeAtInstructionIndex (astNodeType, instIndex, sourceMap, ast) { |
|
|
|
/** |
|
|
|
const sourceLocation = atIndex(instIndex, sourceMap) |
|
|
|
* Retrieve the first @arg astNodeType that include the source map at arg instIndex |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} astNodeType - node type that include the source map instIndex |
|
|
|
|
|
|
|
* @param {String} instIndex - instruction index used to retrieve the source map |
|
|
|
|
|
|
|
* @param {String} sourceMap - source map given by the compilation result |
|
|
|
|
|
|
|
* @param {Object} ast - ast given by the compilation result |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
export function findNodeAtInstructionIndex (astNodeType, instIndex, sourceMap, ast) { |
|
|
|
|
|
|
|
const sourceLocation = this.atIndex(instIndex, sourceMap) |
|
|
|
return findNodeAtSourceLocation(astNodeType, sourceLocation, ast) |
|
|
|
return findNodeAtSourceLocation(astNodeType, sourceLocation, ast) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -153,7 +132,15 @@ function findNodeAtSourceLocation (astNodeType, sourceLocation, ast) { |
|
|
|
return found |
|
|
|
return found |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function nodesAtPosition (astNodeType, position, ast) { |
|
|
|
/** |
|
|
|
|
|
|
|
* get a list of nodes that are at the given @arg position |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String} astNodeType - type of node to return |
|
|
|
|
|
|
|
* @param {Int} position - cursor position |
|
|
|
|
|
|
|
* @return {Object} ast object given by the compiler |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function nodesAtPosition (astNodeType, position, ast) { |
|
|
|
const astWalker = new AstWalker() |
|
|
|
const astWalker = new AstWalker() |
|
|
|
const found = [] |
|
|
|
const found = [] |
|
|
|
const callback = function (node) { |
|
|
|
const callback = function (node) { |
|
|
@ -186,7 +173,7 @@ function nodesAtPosition (astNodeType, position, ast) { |
|
|
|
* @param Array mapping - source maps returned by the compiler. e.g 121:3741:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;121:3741:0;;;;;;; |
|
|
|
* @param Array mapping - source maps returned by the compiler. e.g 121:3741:0:-:0;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;121:3741:0;;;;;;; |
|
|
|
* @return Object { start, length, file, jump } |
|
|
|
* @return Object { start, length, file, jump } |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function atIndex (index, mapping) { |
|
|
|
export function atIndex (index, mapping) { |
|
|
|
let ret = {} |
|
|
|
let ret = {} |
|
|
|
const map = mapping.split(';') |
|
|
|
const map = mapping.split(';') |
|
|
|
if (index >= map.length) { |
|
|
|
if (index >= map.length) { |
|
|
@ -198,23 +185,21 @@ function atIndex (index, mapping) { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
current = current.split(':') |
|
|
|
current = current.split(':') |
|
|
|
if (ret.start === undefined && current[0] && current[0] !== '-1' && current[0].length) { |
|
|
|
if (ret['start'] === undefined && current[0] && current[0] !== '-1' && current[0].length) { |
|
|
|
ret.start = parseInt(current[0]) |
|
|
|
ret['start'] = parseInt(current[0]) |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret.length === undefined && current[1] && current[1] !== '-1' && current[1].length) { |
|
|
|
if (ret['length'] === undefined && current[1] && current[1] !== '-1' && current[1].length) { |
|
|
|
ret.length = parseInt(current[1]) |
|
|
|
ret['length'] = parseInt(current[1]) |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret.file === undefined && current[2] && current[2].length) { |
|
|
|
if (ret['file'] === undefined && current[2] && current[2].length) { |
|
|
|
ret.file = parseInt(current[2]) |
|
|
|
ret['file'] = parseInt(current[2]) |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret.jump === undefined && current[3] && current[3].length) { |
|
|
|
if (ret['jump'] === undefined && current[3] && current[3].length) { |
|
|
|
ret.jump = current[3] |
|
|
|
ret['jump'] = current[3] |
|
|
|
} |
|
|
|
} |
|
|
|
if (ret.start !== undefined && ret.length !== undefined && ret.file !== undefined && ret.jump !== undefined) { |
|
|
|
if (ret['start'] !== undefined && ret['length'] !== undefined && ret['file'] !== undefined && ret['jump'] !== undefined) { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return ret |
|
|
|
return ret |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = SourceMappingDecoder |
|
|
|
|
|
|
|