feat(compiler): basic codegen with source map support

This commit is contained in:
Evan You
2019-09-19 23:05:51 -04:00
parent 98571ab496
commit 9b1a548c6b
15 changed files with 235 additions and 41 deletions

View File

@@ -5,21 +5,27 @@ export function getInnerRange(
offset: number,
length?: number
): SourceLocation {
__DEV__ && assert(offset <= loc.source.length)
const source = loc.source.substr(offset, length)
const newLoc: SourceLocation = {
source,
start: advancePositionBy(loc.start, loc.source, offset),
start: advancePositionWithClone(loc.start, loc.source, offset),
end: loc.end
}
if (length != null) {
newLoc.end = advancePositionBy(loc.start, loc.source, offset + length)
__DEV__ && assert(offset + length <= loc.source.length)
newLoc.end = advancePositionWithClone(
loc.start,
loc.source,
offset + length
)
}
return newLoc
}
export function advancePositionBy(
export function advancePositionWithClone(
pos: Position,
source: string,
numberOfCharacters: number
@@ -34,8 +40,6 @@ export function advancePositionWithMutation(
source: string,
numberOfCharacters: number
): Position {
__DEV__ && assert(numberOfCharacters <= source.length)
let linesCount = 0
let lastNewLinePos = -1
for (let i = 0; i < numberOfCharacters; i++) {