fix: some source mapping fixes
This commit is contained in:
parent
5c68c1717c
commit
de93adde8f
@ -1,16 +1,18 @@
|
|||||||
import { SourceMap } from "./map.ts";
|
import { SourceMap } from "./map.ts";
|
||||||
import { transform } from "@babel/standalone";
|
import { transform, availablePresets } from "@babel/standalone";
|
||||||
// import presetEnv from "@babel/preset-env";
|
|
||||||
|
|
||||||
export default function babel(next: Compiler): Compiler {
|
export default function babel(next: Compiler): Compiler {
|
||||||
print("Loaded babel!");
|
print("Loaded babel!");
|
||||||
|
|
||||||
return (filename, code, prevMap) => {
|
return (filename, code, prevMap) => {
|
||||||
const res = transform(code, {
|
const res = transform(code, {
|
||||||
filename,
|
filename,
|
||||||
sourceMaps: true,
|
sourceMaps: true,
|
||||||
|
presets: [availablePresets.env],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
print(res.map!.mappings);
|
||||||
|
|
||||||
const map = SourceMap.parse({
|
const map = SourceMap.parse({
|
||||||
file: "babel-internal://" + filename,
|
file: "babel-internal://" + filename,
|
||||||
mappings: res.map!.mappings,
|
mappings: res.map!.mappings,
|
||||||
|
@ -11,10 +11,21 @@ export type Location = readonly [file: string, line: number, start: number];
|
|||||||
export function decodeVLQ(val: string): number[][][] {
|
export function decodeVLQ(val: string): number[][][] {
|
||||||
const lines: number[][][] = [];
|
const lines: number[][][] = [];
|
||||||
|
|
||||||
for (const line of val.split(";", -1)) {
|
const fileParts = val.split(";", -1);
|
||||||
const elements: number[][] = [];
|
|
||||||
|
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([]);
|
if (el.length === 0) elements.push([]);
|
||||||
else {
|
else {
|
||||||
const list: number[] = [];
|
const list: number[] = [];
|
||||||
@ -98,7 +109,7 @@ export class VLQSourceMap {
|
|||||||
const mid = (a + b) >> 1;
|
const mid = (a + b) >> 1;
|
||||||
const el = line[mid];
|
const el = line[mid];
|
||||||
|
|
||||||
const cmp = el[0] - src[1];
|
const cmp = el[0] - src[2];
|
||||||
|
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
if (done) {
|
if (done) {
|
||||||
@ -132,10 +143,13 @@ export class VLQSourceMap {
|
|||||||
const lastCols = new Set<number>();
|
const lastCols = new Set<number>();
|
||||||
|
|
||||||
for (let compiledRow = 0; compiledRow < mapping.length; compiledRow++) {
|
for (let compiledRow = 0; compiledRow < mapping.length; compiledRow++) {
|
||||||
const line = file[compiledRow] ??= [];
|
const line: [start: number, dst: Location][] = file[compiledRow] = [];
|
||||||
let compiledCol = 0;
|
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;
|
compiledCol += rawSeg.length > 0 ? rawSeg[0] : 0;
|
||||||
originalFile += rawSeg.length > 1 ? rawSeg[1] : 0;
|
originalFile += rawSeg.length > 1 ? rawSeg[1] : 0;
|
||||||
originalRow += rawSeg.length > 2 ? rawSeg[2] : 0;
|
originalRow += rawSeg.length > 2 ? rawSeg[2] : 0;
|
||||||
|
17
src/main/tsconfig.json
Normal file
17
src/main/tsconfig.json
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user