Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2131x 2131x 2131x 2132x 2132x 2132x 1x 1x 2132x 2131x 2131x 2131x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 105x 105x 17x 17x 105x 105x 105x 3x 3x 105x 105x 105x 105x 105x 105x 18x 18x 18x 18x 18x 491x 491x 491x 34x 34x 34x 457x 491x 98x 4x 4x 4x 98x 453x 491x 453x 491x 453x 491x 316x 316x 316x 316x 316x 1808x 1808x 1808x 1473x 1808x 48x 48x 48x 1808x 316x 316x 316x 48x 48x 48x 316x 405x 491x 370x 491x 35x 35x 18x 18x 18x 18x 18x 18x 18x 18x 491x 473x 473x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 491x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 40x 40x 40x 40x 40x 2x 2x 2x 200x 198x 198x 200x 200x 200x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 200x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x | import path from 'node:path';
const VLQ_BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
/**
* Encodes an integer value to a VLQ Base64 string.
* @param {number} value
* @returns {string}
*/
export function encodeVLQ(value) {
let vlq = value < 0 ? (-value << 1) | 1 : value << 1;
let encoded = '';
do {
let digit = vlq & 31;
vlq >>>= 5;
if (vlq > 0) {
digit |= 32;
}
encoded += VLQ_BASE64_CHARS[digit];
} while (vlq > 0);
return encoded;
}
/**
* Generates a Source Map v3 object mapping compiled JavaScript lines to original template source lines.
* @param {string} filePath - File path of the source template (.html, .avx, .component.js, .page.js).
* @param {string} originalCode - Raw template source code.
* @param {string} compiledCode - Compiled and wrapped ES module JavaScript code.
* @param {object} [options]
* @param {boolean} [options.sourcesContent]
* @returns {object} Source Map v3 compliant object.
*/
export function generateTemplateSourceMap(filePath, originalCode, compiledCode, options = {}) {
const includeContent = options.sourcesContent !== false;
const origLines = (originalCode || '').split(/\r?\n/);
const genLines = (compiledCode || '').split(/\r?\n/);
let stateLine = 0;
const actionLines = new Map();
const computedLines = new Map();
const resourceLines = new Map();
origLines.forEach((line, idx) => {
const trimmed = line.trim();
if (/<state\b/i.test(trimmed) && stateLine === 0) {
stateLine = idx;
}
const actionMatch = line.match(/<action\s+[^>]*name=["']([\w-]+)["']/i);
if (actionMatch) {
actionLines.set(actionMatch[1], idx);
}
const computedMatch = line.match(/<computed\s+[^>]*name=["']([\w-]+)["']/i);
if (computedMatch) {
computedLines.set(computedMatch[1], idx);
}
const resourceMatch = line.match(/<resource\s+[^>]*name=["']([\w-]+)["']/i);
if (resourceMatch) {
resourceLines.set(resourceMatch[1], idx);
}
});
const lineMappings = new Array(genLines.length).fill(null);
genLines.forEach((genLine, gIdx) => {
const trimmedGen = genLine.trim();
if (trimmedGen.startsWith('constructor(') || trimmedGen.startsWith('super(')) {
lineMappings[gIdx] = stateLine;
return;
}
for (const [actionName, startLine] of actionLines.entries()) {
if (genLine.includes(`${actionName}:`) || genLine.includes(`"${actionName}":`) || genLine.includes(`'${actionName}':`)) {
lineMappings[gIdx] = startLine;
return;
}
}
for (const [compName, startLine] of computedLines.entries()) {
if (genLine.includes(`${compName}:`) || genLine.includes(`"${compName}":`) || genLine.includes(`'${compName}':`)) {
lineMappings[gIdx] = startLine;
return;
}
}
for (const [resName, startLine] of resourceLines.entries()) {
if (genLine.includes(`${resName}:`) || genLine.includes(`"${resName}":`) || genLine.includes(`'${resName}':`)) {
lineMappings[gIdx] = startLine;
return;
}
}
if (trimmedGen.length > 0) {
let matchedOrigLine = -1;
const cleanGen = trimmedGen.replace(/^`|`\s*,?$|^`|`$/g, '').trim();
if (cleanGen.length > 0) {
for (let oIdx = 0; oIdx < origLines.length; oIdx++) {
const origTrimmed = origLines[oIdx].trim();
if (
origTrimmed.length > 0 &&
(origTrimmed === cleanGen || origTrimmed.includes(cleanGen) || cleanGen.includes(origTrimmed))
) {
matchedOrigLine = oIdx;
break;
}
}
}
if (matchedOrigLine !== -1) {
lineMappings[gIdx] = matchedOrigLine;
return;
}
}
if (gIdx > 0 && gIdx < genLines.length - 1) {
lineMappings[gIdx] = stateLine;
} else {
lineMappings[gIdx] = 0;
}
});
let mappings = '';
let prevSourceLine = 0;
let prevSourceCol = 0;
let prevSourceIdx = 0;
for (let g = 0; g < genLines.length; g++) {
if (g > 0) {
mappings += ';';
}
const origLine0 = lineMappings[g];
if (origLine0 !== null && origLine0 !== undefined) {
const genCol = 0;
const sourceIdx = 0;
const origCol0 = 0;
const dGenCol = genCol;
const dSourceIdx = sourceIdx - prevSourceIdx;
const dSourceLine = origLine0 - prevSourceLine;
const dSourceCol = origCol0 - prevSourceCol;
mappings += encodeVLQ(dGenCol) + encodeVLQ(dSourceIdx) + encodeVLQ(dSourceLine) + encodeVLQ(dSourceCol);
prevSourceIdx = sourceIdx;
prevSourceLine = origLine0;
prevSourceCol = origCol0;
}
}
const fileName = path.basename(filePath);
const mapResult = {
version: 3,
file: fileName,
sources: [filePath],
names: [],
mappings: mappings,
};
if (includeContent) {
mapResult.sourcesContent = [originalCode];
}
return mapResult;
}
/**
* Builds a bundle-level v3 source map given file sections and their position in the final bundle.
* @param {string} bundleFileName - e.g. 'bundle.js'
* @param {number} totalBundleLines - Total lines in bundle.js
* @param {Array<{ filePath: string, originalCode: string, startLine: number, lineCount: number }>} sections
* @param {object} [options]
* @param {boolean} [options.sourcesContent]
* @returns {object} Source Map v3 object.
*/
export function composeBundleSourceMap(bundleFileName, totalBundleLines, sections = [], options = {}) {
const includeContent = options.sourcesContent !== false;
const sources = [];
const sourcesContent = [];
const sourceIndexMap = new Map();
sections.forEach((section) => {
if (!sourceIndexMap.has(section.filePath)) {
sourceIndexMap.set(section.filePath, sources.length);
sources.push(section.filePath);
if (includeContent) {
sourcesContent.push(section.originalCode);
}
}
});
let mappings = '';
let prevSourceLine = 0;
let prevSourceCol = 0;
let prevSourceIdx = 0;
// Build lookup for each bundle line
const lineToSection = new Map();
sections.forEach((sec) => {
for (let i = 0; i < sec.lineCount; i++) {
lineToSection.set(sec.startLine + i, {
sourceIdx: sourceIndexMap.get(sec.filePath),
origLine: i,
});
}
});
for (let g = 0; g < totalBundleLines; g++) {
if (g > 0) {
mappings += ';';
}
const mapping = lineToSection.get(g);
if (mapping) {
const dGenCol = 0;
const dSourceIdx = mapping.sourceIdx - prevSourceIdx;
const dSourceLine = mapping.origLine - prevSourceLine;
const dSourceCol = 0 - prevSourceCol;
mappings += encodeVLQ(dGenCol) + encodeVLQ(dSourceIdx) + encodeVLQ(dSourceLine) + encodeVLQ(dSourceCol);
prevSourceIdx = mapping.sourceIdx;
prevSourceLine = mapping.origLine;
prevSourceCol = 0;
}
}
const bundleMap = {
version: 3,
file: bundleFileName,
sources,
names: [],
mappings,
};
if (includeContent) {
bundleMap.sourcesContent = sourcesContent;
}
return bundleMap;
} |