@cashscript/utils
Advanced tools
Comparing version 0.10.0-next.2 to 0.10.0-next.3
@@ -12,2 +12,8 @@ /// <reference types="node" /> | ||
} | ||
export interface DebugInformation { | ||
bytecode: string; | ||
sourceMap: string; | ||
logs: LogEntry[]; | ||
requireMessages: RequireMessage[]; | ||
} | ||
export interface LogEntry { | ||
@@ -32,8 +38,3 @@ ip: number; | ||
source: string; | ||
debug?: { | ||
bytecode: string; | ||
sourceMap: string; | ||
logs: LogEntry[]; | ||
requireMessages: RequireMessage[]; | ||
}; | ||
debug?: DebugInformation; | ||
compiler: { | ||
@@ -40,0 +41,0 @@ name: string; |
import { Script } from './script.js'; | ||
export declare type LineToOpcodesMap = Record<string, Script>; | ||
export declare type LineToAsmMap = Record<string, string>; | ||
export declare function buildLineToOpcodesMap(bytecode: Script, souceMap: string): LineToOpcodesMap; | ||
export declare function buildLineToAsmMap(bytecode: Script, souceMap: string): LineToAsmMap; | ||
export declare function formatBitAuthScript(bytecode: Script, souceMap: string, sourceCode: string): string; | ||
export declare function buildLineToOpcodesMap(bytecode: Script, sourceMap: string): LineToOpcodesMap; | ||
export declare function buildLineToAsmMap(bytecode: Script, sourceMap: string): LineToAsmMap; | ||
export declare function formatBitAuthScript(bytecode: Script, sourceMap: string, sourceCode: string): string; |
import { scriptToBitAuthAsm } from './script.js'; | ||
import { sourceMapToLocationData } from './source-map.js'; | ||
export function buildLineToOpcodesMap(bytecode, souceMap) { | ||
const locationData = sourceMapToLocationData(souceMap); | ||
return locationData.reduce((lineToOpcodeMap, [location, positionHint], index) => { | ||
import { PositionHint } from './types.js'; | ||
export function buildLineToOpcodesMap(bytecode, sourceMap) { | ||
const locationData = sourceMapToLocationData(sourceMap); | ||
return locationData.reduce((lineToOpcodeMap, { location, positionHint }, index) => { | ||
const opcode = bytecode[index]; | ||
const line = positionHint ? location?.end.line : location?.start.line; | ||
const line = positionHint === PositionHint.END ? location?.end.line : location?.start.line; | ||
return { | ||
@@ -14,9 +15,10 @@ ...lineToOpcodeMap, | ||
} | ||
export function buildLineToAsmMap(bytecode, souceMap) { | ||
const lineToOpcodesMap = buildLineToOpcodesMap(bytecode, souceMap); | ||
export function buildLineToAsmMap(bytecode, sourceMap) { | ||
const lineToOpcodesMap = buildLineToOpcodesMap(bytecode, sourceMap); | ||
return Object.fromEntries(Object.entries(lineToOpcodesMap).map(([lineNumber, opcodeList]) => [lineNumber, scriptToBitAuthAsm(opcodeList)])); | ||
} | ||
export function formatBitAuthScript(bytecode, souceMap, sourceCode) { | ||
const lineToAsmMap = buildLineToAsmMap(bytecode, souceMap); | ||
const sourceCodeLines = sourceCode.split('\n'); | ||
export function formatBitAuthScript(bytecode, sourceMap, sourceCode) { | ||
const lineToAsmMap = buildLineToAsmMap(bytecode, sourceMap); | ||
const escapedSourceCode = sourceCode.replaceAll('/*', '\\/*').replaceAll('*/', '*\\/'); | ||
const sourceCodeLines = escapedSourceCode.split('\n'); | ||
const sourceCodeLineLengths = sourceCodeLines.map((line) => line.length); | ||
@@ -23,0 +25,0 @@ const bytecodeLineLengths = Object.values(lineToAsmMap).map((line) => line.length); |
@@ -1,13 +0,3 @@ | ||
export interface LocationI { | ||
start: { | ||
line: number; | ||
column: number; | ||
}; | ||
end: { | ||
line: number; | ||
column: number; | ||
}; | ||
} | ||
export declare type LocationData = Array<[location: LocationI, positionHint?: number]>; | ||
export declare function generateSourceMap(locationData: LocationData): string; | ||
export declare const sourceMapToLocationData: (sourceMap: string) => LocationData; | ||
import { FullLocationData } from './types.js'; | ||
export declare function generateSourceMap(locationData: FullLocationData): string; | ||
export declare const sourceMapToLocationData: (sourceMap: string) => FullLocationData; |
@@ -0,1 +1,2 @@ | ||
import { PositionHint } from './types.js'; | ||
/* | ||
@@ -31,13 +32,13 @@ * The source mappings for the bytecode use the following notation (similar to Solidity): | ||
let prevEndColumn = 0; | ||
let prevHint = 0; | ||
return locationData.map((row) => { | ||
const prevStartLineString = prevStartLine === row[0].start.line ? '' : String(row[0].start.line); | ||
prevStartLine = row[0].start.line; | ||
const prevStartColumnString = prevStartColumn === row[0].start.column ? '' : String(row[0].start.column); | ||
prevStartColumn = row[0].start.column; | ||
const prevEndLineString = prevEndLine === row[0].end.line ? '' : String(row[0].end.line); | ||
prevEndLine = row[0].end.line; | ||
const prevEndColumnString = prevEndColumn === row[0].end.column ? '' : String(row[0].end.column); | ||
prevEndColumn = row[0].end.column; | ||
const hint = row[1] ?? 0; | ||
let prevHint = PositionHint.START; | ||
return locationData.map(({ location, positionHint }) => { | ||
const prevStartLineString = prevStartLine === location.start.line ? '' : String(location.start.line); | ||
prevStartLine = location.start.line; | ||
const prevStartColumnString = prevStartColumn === location.start.column ? '' : String(location.start.column); | ||
prevStartColumn = location.start.column; | ||
const prevEndLineString = prevEndLine === location.end.line ? '' : String(location.end.line); | ||
prevEndLine = location.end.line; | ||
const prevEndColumnString = prevEndColumn === location.end.column ? '' : String(location.end.column); | ||
prevEndColumn = location.end.column; | ||
const hint = positionHint ?? PositionHint.START; | ||
const prevHintString = prevHint === hint ? '' : String(hint); | ||
@@ -76,22 +77,29 @@ prevHint = hint; | ||
return sourceMap.split(';').map((entry) => { | ||
const val = entry.split(':'); | ||
const startLine = val[0] ? Number(val[0]) : prevStartLine; | ||
const [startLineStr, startColumnStr, endLineStr, endColumnStr, positionHintStr] = entry.split(':'); | ||
const startLine = startLineStr ? Number(startLineStr) : prevStartLine; | ||
prevStartLine = startLine; | ||
const startColumn = val[1] ? Number(val[1]) : prevStartColumn; | ||
const startColumn = startColumnStr ? Number(startColumnStr) : prevStartColumn; | ||
prevStartColumn = startColumn; | ||
const endLine = val[2] ? Number(val[2]) : prevEndLine; | ||
const endLine = endLineStr ? Number(endLineStr) : prevEndLine; | ||
prevEndLine = endLine; | ||
const endColumn = val[3] ? Number(val[3]) : prevEndColumn; | ||
const endColumn = endColumnStr ? Number(endColumnStr) : prevEndColumn; | ||
prevEndColumn = endColumn; | ||
const hint = val[4] ? Number(val[4]) : prevHint; | ||
const hint = parsePositionHint(positionHintStr) ?? prevHint; | ||
prevHint = hint; | ||
return [ | ||
{ | ||
return { | ||
location: { | ||
start: { line: startLine, column: startColumn }, | ||
end: { line: endLine, column: endColumn }, | ||
}, | ||
...(hint ? [hint] : []), | ||
]; | ||
...(hint ? { positionHint: hint } : {}), | ||
}; | ||
}); | ||
}; | ||
const parsePositionHint = (hint) => { | ||
if (hint === '1') | ||
return PositionHint.END; | ||
if (hint === '0') | ||
return PositionHint.START; | ||
return undefined; | ||
}; | ||
//# sourceMappingURL=source-map.js.map |
@@ -35,1 +35,20 @@ export declare type Type = PrimitiveType | ArrayType | TupleType | BytesType; | ||
export declare function isPrimitive(type: Type): type is PrimitiveType; | ||
export interface LocationI { | ||
start: { | ||
line: number; | ||
column: number; | ||
}; | ||
end: { | ||
line: number; | ||
column: number; | ||
}; | ||
} | ||
export declare type SingleLocationData = { | ||
location: LocationI; | ||
positionHint?: PositionHint; | ||
}; | ||
export declare type FullLocationData = Array<SingleLocationData>; | ||
export declare enum PositionHint { | ||
START = 0, | ||
END = 1 | ||
} |
@@ -175,2 +175,8 @@ export class ArrayType { | ||
} | ||
// Denotes whether an opcode belongs to the "start" or "end" of the statement it's in (defaults to "start") | ||
export var PositionHint; | ||
(function (PositionHint) { | ||
PositionHint[PositionHint["START"] = 0] = "START"; | ||
PositionHint[PositionHint["END"] = 1] = "END"; | ||
})(PositionHint || (PositionHint = {})); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@cashscript/utils", | ||
"version": "0.10.0-next.2", | ||
"version": "0.10.0-next.3", | ||
"description": "CashScript utilities and types", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@bitauth/libauth": "^2.0.0-alpha.8", | ||
"@bitauth/libauth": "^2.0.0", | ||
"hash.js": "^1.1.7" | ||
@@ -53,3 +53,3 @@ }, | ||
}, | ||
"gitHead": "23f2f6fc78f6a911dfe559404be7741aa824e791" | ||
"gitHead": "1b66bdb92f972d311d968667290e96085d7fcdc7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43941
853
Updated@bitauth/libauth@^2.0.0