diff --git a/src/lib/transpiler/babel.ts b/src/lib/transpiler/babel.ts index 119d4bb..0fd59d0 100644 --- a/src/lib/transpiler/babel.ts +++ b/src/lib/transpiler/babel.ts @@ -1,16 +1,18 @@ import { SourceMap } from "./map.ts"; -import { transform } from "@babel/standalone"; -// import presetEnv from "@babel/preset-env"; +import { transform, availablePresets } from "@babel/standalone"; export default function babel(next: Compiler): Compiler { print("Loaded babel!"); - + return (filename, code, prevMap) => { const res = transform(code, { filename, sourceMaps: true, + presets: [availablePresets.env], }); + print(res.map!.mappings); + const map = SourceMap.parse({ file: "babel-internal://" + filename, mappings: res.map!.mappings, diff --git a/src/lib/transpiler/map.ts b/src/lib/transpiler/map.ts index e30d39b..915cf66 100644 --- a/src/lib/transpiler/map.ts +++ b/src/lib/transpiler/map.ts @@ -11,10 +11,21 @@ export type Location = readonly [file: string, line: number, start: number]; export function decodeVLQ(val: string): number[][][] { const lines: number[][][] = []; - for (const line of val.split(";", -1)) { - const elements: number[][] = []; + const fileParts = val.split(";", -1); + + for (let i = 0; i < fileParts.length; i++) { + const line = fileParts[i]; + if (line.length === 0) { + lines.push([]); + continue; + } + + const elements: number[][] = []; + const lineParts = line.split(",", -1); + + for (let i = 0; i < lineParts.length; i++) { + const el = lineParts[i]; - for (const el of line.split(",", -1)) { if (el.length === 0) elements.push([]); else { const list: number[] = []; @@ -98,7 +109,7 @@ export class VLQSourceMap { const mid = (a + b) >> 1; const el = line[mid]; - const cmp = el[0] - src[1]; + const cmp = el[0] - src[2]; if (cmp < 0) { if (done) { @@ -132,10 +143,13 @@ export class VLQSourceMap { const lastCols = new Set(); for (let compiledRow = 0; compiledRow < mapping.length; compiledRow++) { - const line = file[compiledRow] ??= []; + const line: [start: number, dst: Location][] = file[compiledRow] = []; let compiledCol = 0; - for (const rawSeg of mapping[compiledRow]) { + const rowData = mapping[compiledRow]; + for (let i = 0; i < rowData.length; i++) { + const rawSeg = rowData[i]; + compiledCol += rawSeg.length > 0 ? rawSeg[0] : 0; originalFile += rawSeg.length > 1 ? rawSeg[1] : 0; originalRow += rawSeg.length > 2 ? rawSeg[2] : 0; diff --git a/src/main/tsconfig.json b/src/main/tsconfig.json new file mode 100644 index 0000000..d7d4524 --- /dev/null +++ b/src/main/tsconfig.json @@ -0,0 +1,17 @@ +{ + "include": ["resources/lib/**/*.ts", "resources/lib/values/.number.d.ts"], + "compilerOptions": { + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "moduleResolution": "Bundler", + "module": "ESNext", + "target": "ESNext", + "lib": [], + "forceConsistentCasingInFileNames": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowImportingTsExtensions": true, + "noEmit": true + } +}