@react-pug/typescript-plugin-react-pug 0.1.2 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin.js +147 -171
- package/dist/plugin.js.map +3 -3
- package/package.json +3 -3
package/dist/plugin.js
CHANGED
|
@@ -23816,9 +23816,9 @@ function findProgramInsertionOffset(text, program) {
|
|
|
23816
23816
|
}
|
|
23817
23817
|
return lastLeading ? getOffsetAfterTrailingLineBreak(text, lastLeading.end ?? 0) : 0;
|
|
23818
23818
|
}
|
|
23819
|
-
function findBlockInsertionOffset(block) {
|
|
23819
|
+
function findBlockInsertionOffset(text, block) {
|
|
23820
23820
|
const firstNonDirective = block.body.find((statement) => !isDirectiveStatement(statement));
|
|
23821
|
-
if (firstNonDirective) return firstNonDirective.start ?? (block.start ?? 0) + 1;
|
|
23821
|
+
if (firstNonDirective) return getLineStartOffset(text, firstNonDirective.start ?? (block.start ?? 0) + 1);
|
|
23822
23822
|
return Math.max(0, (block.end ?? 0) - 1);
|
|
23823
23823
|
}
|
|
23824
23824
|
function buildArrowExpressionScopeTarget(text, node) {
|
|
@@ -23838,7 +23838,7 @@ function buildBlockScopeTarget(text, block) {
|
|
|
23838
23838
|
const blockIndent = getLineIndent(text, block.start ?? 0);
|
|
23839
23839
|
return {
|
|
23840
23840
|
kind: "block",
|
|
23841
|
-
insertionOffset: findBlockInsertionOffset(block),
|
|
23841
|
+
insertionOffset: findBlockInsertionOffset(text, block),
|
|
23842
23842
|
statementIndent: `${blockIndent} `,
|
|
23843
23843
|
closingIndent: blockIndent
|
|
23844
23844
|
};
|
|
@@ -24788,14 +24788,14 @@ function emitMergedClassShorthandAttribute(targetAttr, mergeMode, classNames, ex
|
|
|
24788
24788
|
emitter.emitSynthetic("={[");
|
|
24789
24789
|
for (let i = 0; i < classNames.length; i += 1) {
|
|
24790
24790
|
if (i > 0) emitter.emitSynthetic(", ");
|
|
24791
|
-
emitter.emitSynthetic('"
|
|
24791
|
+
emitter.emitSynthetic("'");
|
|
24792
24792
|
emitter.emitDerived(
|
|
24793
24793
|
classNames[i].name,
|
|
24794
24794
|
classNames[i].offset,
|
|
24795
24795
|
Math.max(1, classNames[i].sourceLength),
|
|
24796
24796
|
CSS_CLASS
|
|
24797
24797
|
);
|
|
24798
|
-
emitter.emitSynthetic('"
|
|
24798
|
+
emitter.emitSynthetic("'");
|
|
24799
24799
|
}
|
|
24800
24800
|
if (existingAttr) {
|
|
24801
24801
|
if (classNames.length > 0) emitter.emitSynthetic(", ");
|
|
@@ -25440,123 +25440,6 @@ function compilePugToTsx(pugText, options = {}) {
|
|
|
25440
25440
|
}
|
|
25441
25441
|
}
|
|
25442
25442
|
|
|
25443
|
-
// ../react-pug-core/src/language/positionMapping.ts
|
|
25444
|
-
var import_source_map = __toESM(require_source_map());
|
|
25445
|
-
var sourceMapCache = /* @__PURE__ */ new WeakMap();
|
|
25446
|
-
function getSourceMap(region) {
|
|
25447
|
-
let sm = sourceMapCache.get(region);
|
|
25448
|
-
if (!sm) {
|
|
25449
|
-
sm = new import_source_map.SourceMap(region.mappings);
|
|
25450
|
-
sourceMapCache.set(region, sm);
|
|
25451
|
-
}
|
|
25452
|
-
return sm;
|
|
25453
|
-
}
|
|
25454
|
-
function rawToStrippedOffset(rawText, rawOffset, commonIndent) {
|
|
25455
|
-
if (commonIndent === 0) return rawOffset;
|
|
25456
|
-
let stripped = 0;
|
|
25457
|
-
let raw = 0;
|
|
25458
|
-
const lines = rawText.split("\n");
|
|
25459
|
-
for (let i = 0; i < lines.length; i++) {
|
|
25460
|
-
const line = lines[i];
|
|
25461
|
-
const lineEnd = raw + line.length;
|
|
25462
|
-
if (rawOffset <= lineEnd) {
|
|
25463
|
-
const colInRaw = rawOffset - raw;
|
|
25464
|
-
const indentToRemove2 = line.trim().length === 0 ? line.length : commonIndent;
|
|
25465
|
-
if (indentToRemove2 > 0 && colInRaw < indentToRemove2) return null;
|
|
25466
|
-
return stripped + Math.max(0, colInRaw - indentToRemove2);
|
|
25467
|
-
}
|
|
25468
|
-
const indentToRemove = line.trim().length === 0 ? line.length : commonIndent;
|
|
25469
|
-
stripped += Math.max(0, line.length - indentToRemove) + 1;
|
|
25470
|
-
raw = lineEnd + 1;
|
|
25471
|
-
}
|
|
25472
|
-
return stripped;
|
|
25473
|
-
}
|
|
25474
|
-
function strippedToRawOffset2(rawText, strippedOffset, commonIndent) {
|
|
25475
|
-
if (commonIndent === 0) return strippedOffset;
|
|
25476
|
-
let stripped = 0;
|
|
25477
|
-
let raw = 0;
|
|
25478
|
-
const lines = rawText.split("\n");
|
|
25479
|
-
for (let i = 0; i < lines.length; i++) {
|
|
25480
|
-
const line = lines[i];
|
|
25481
|
-
const indentToRemove = line.trim().length === 0 ? line.length : commonIndent;
|
|
25482
|
-
const strippedLineLen = Math.max(0, line.length - indentToRemove);
|
|
25483
|
-
if (strippedOffset <= stripped + strippedLineLen) {
|
|
25484
|
-
return raw + indentToRemove + (strippedOffset - stripped);
|
|
25485
|
-
}
|
|
25486
|
-
stripped += strippedLineLen + 1;
|
|
25487
|
-
raw += line.length + 1;
|
|
25488
|
-
}
|
|
25489
|
-
return raw;
|
|
25490
|
-
}
|
|
25491
|
-
function findSegmentAtOffset(segments, offset, getStart, getEnd) {
|
|
25492
|
-
let lo = 0;
|
|
25493
|
-
let hi = segments.length - 1;
|
|
25494
|
-
while (lo <= hi) {
|
|
25495
|
-
const mid = lo + hi >>> 1;
|
|
25496
|
-
const segment = segments[mid];
|
|
25497
|
-
if (offset < getStart(segment)) {
|
|
25498
|
-
hi = mid - 1;
|
|
25499
|
-
} else if (offset >= getEnd(segment)) {
|
|
25500
|
-
lo = mid + 1;
|
|
25501
|
-
} else {
|
|
25502
|
-
return segment;
|
|
25503
|
-
}
|
|
25504
|
-
}
|
|
25505
|
-
return null;
|
|
25506
|
-
}
|
|
25507
|
-
function getMappedRegionsForRegion(doc, regionIndex) {
|
|
25508
|
-
return doc.mappedRegions.filter((region) => region.regionIndex === regionIndex);
|
|
25509
|
-
}
|
|
25510
|
-
function findRegionAtOriginalOffset(doc, offset) {
|
|
25511
|
-
return findSegmentAtOffset(doc.regions, offset, (region) => region.originalStart, (region) => region.originalEnd);
|
|
25512
|
-
}
|
|
25513
|
-
function findCopySegmentAtOriginalOffset(doc, offset) {
|
|
25514
|
-
return findSegmentAtOffset(doc.copySegments, offset, (segment) => segment.originalStart, (segment) => segment.originalEnd);
|
|
25515
|
-
}
|
|
25516
|
-
function findCopySegmentAtShadowOffset(doc, offset) {
|
|
25517
|
-
return findSegmentAtOffset(doc.copySegments, offset, (segment) => segment.shadowStart, (segment) => segment.shadowEnd);
|
|
25518
|
-
}
|
|
25519
|
-
function originalToShadow(doc, originalOffset) {
|
|
25520
|
-
if (originalOffset === doc.originalText.length) return doc.shadowText.length;
|
|
25521
|
-
const region = findRegionAtOriginalOffset(doc, originalOffset);
|
|
25522
|
-
if (region) {
|
|
25523
|
-
const regionIndex = doc.regions.indexOf(region);
|
|
25524
|
-
const rawOffset = originalOffset - region.pugTextStart;
|
|
25525
|
-
if (rawOffset < 0) return null;
|
|
25526
|
-
const rawText = doc.originalText.slice(region.pugTextStart, region.pugTextEnd);
|
|
25527
|
-
const strippedOffset = rawToStrippedOffset(rawText, rawOffset, region.commonIndent);
|
|
25528
|
-
if (strippedOffset == null) return null;
|
|
25529
|
-
for (const mappedRegion of getMappedRegionsForRegion(doc, regionIndex)) {
|
|
25530
|
-
if (strippedOffset < mappedRegion.sourceStart || strippedOffset >= mappedRegion.sourceEnd) continue;
|
|
25531
|
-
const sm = getSourceMap(mappedRegion);
|
|
25532
|
-
for (const [generatedOffset] of sm.toGeneratedLocation(strippedOffset)) {
|
|
25533
|
-
return mappedRegion.shadowStart + generatedOffset;
|
|
25534
|
-
}
|
|
25535
|
-
}
|
|
25536
|
-
return null;
|
|
25537
|
-
}
|
|
25538
|
-
const copySegment = findCopySegmentAtOriginalOffset(doc, originalOffset);
|
|
25539
|
-
if (!copySegment) return null;
|
|
25540
|
-
return copySegment.shadowStart + (originalOffset - copySegment.originalStart);
|
|
25541
|
-
}
|
|
25542
|
-
function shadowToOriginal(doc, shadowOffset) {
|
|
25543
|
-
if (shadowOffset === doc.shadowText.length) return doc.originalText.length;
|
|
25544
|
-
for (const mappedRegion of doc.mappedRegions) {
|
|
25545
|
-
if (shadowOffset < mappedRegion.shadowStart || shadowOffset >= mappedRegion.shadowEnd) continue;
|
|
25546
|
-
const localOffset = shadowOffset - mappedRegion.shadowStart;
|
|
25547
|
-
const sm = getSourceMap(mappedRegion);
|
|
25548
|
-
for (const [sourceOffset] of sm.toSourceLocation(localOffset)) {
|
|
25549
|
-
const region = doc.regions[mappedRegion.regionIndex];
|
|
25550
|
-
const rawText = doc.originalText.slice(region.pugTextStart, region.pugTextEnd);
|
|
25551
|
-
const rawOffset = strippedToRawOffset2(rawText, sourceOffset, region.commonIndent);
|
|
25552
|
-
return region.pugTextStart + rawOffset;
|
|
25553
|
-
}
|
|
25554
|
-
}
|
|
25555
|
-
const copySegment = findCopySegmentAtShadowOffset(doc, shadowOffset);
|
|
25556
|
-
if (!copySegment) return null;
|
|
25557
|
-
return copySegment.originalStart + (shadowOffset - copySegment.shadowStart);
|
|
25558
|
-
}
|
|
25559
|
-
|
|
25560
25443
|
// ../react-pug-core/src/language/shadowDocument.ts
|
|
25561
25444
|
var STARTUPJS_OR_CSSXJS_RE = /['"](?:startupjs|cssxjs)['"]/;
|
|
25562
25445
|
function resolveCompileOptions(originalText, compileOptions) {
|
|
@@ -25619,7 +25502,7 @@ function buildStyleCallText(region, styleBlock, helper, statementIndent) {
|
|
|
25619
25502
|
text += "\n";
|
|
25620
25503
|
generatedOffset += 1;
|
|
25621
25504
|
}
|
|
25622
|
-
text += `${statementIndent}
|
|
25505
|
+
text += `${statementIndent}\`
|
|
25623
25506
|
`;
|
|
25624
25507
|
return {
|
|
25625
25508
|
text,
|
|
@@ -25652,7 +25535,7 @@ function buildStyleInsertions(originalText, regions, plans) {
|
|
|
25652
25535
|
const mappedRegions = [];
|
|
25653
25536
|
if (target.kind === "arrow-expression" || target.kind === "statement-body") {
|
|
25654
25537
|
text += "{\n";
|
|
25655
|
-
} else if (target.insertionOffset > 0) {
|
|
25538
|
+
} else if (target.insertionOffset > 0 && originalText[target.insertionOffset - 1] !== "\n" && originalText[target.insertionOffset - 1] !== "\r" && originalText[target.insertionOffset] !== "\n" && originalText[target.insertionOffset] !== "\r") {
|
|
25656
25539
|
const prevChar = originalText[target.insertionOffset - 1];
|
|
25657
25540
|
if (prevChar !== "\n" && prevChar !== "\r") text += "\n";
|
|
25658
25541
|
}
|
|
@@ -25718,30 +25601,11 @@ ${target.closingIndent}}`,
|
|
|
25718
25601
|
}
|
|
25719
25602
|
return insertions;
|
|
25720
25603
|
}
|
|
25721
|
-
function applyImportCleanups(doc, cleanups) {
|
|
25722
|
-
if (cleanups.length === 0) return doc.shadowText;
|
|
25723
|
-
const chars2 = doc.shadowText.split("");
|
|
25724
|
-
for (const cleanup of cleanups) {
|
|
25725
|
-
const shadowStart = originalToShadow(doc, cleanup.originalStart);
|
|
25726
|
-
if (shadowStart == null) continue;
|
|
25727
|
-
const shadowEnd = shadowStart + (cleanup.originalEnd - cleanup.originalStart);
|
|
25728
|
-
for (let i = shadowStart; i < shadowEnd; i += 1) {
|
|
25729
|
-
chars2[i] = "";
|
|
25730
|
-
}
|
|
25731
|
-
chars2[shadowStart] = cleanup.replacementText;
|
|
25732
|
-
}
|
|
25733
|
-
return chars2.join("");
|
|
25734
|
-
}
|
|
25735
|
-
function padToLength2(text, targetLength) {
|
|
25736
|
-
if (text.length > targetLength) return null;
|
|
25737
|
-
return text + " ".repeat(targetLength - text.length);
|
|
25738
|
-
}
|
|
25739
25604
|
function buildImportCleanupWithHelpers(originalText, entry, helpersToAdd, removeTagImport) {
|
|
25740
25605
|
const declaration = entry.declaration;
|
|
25741
25606
|
const originalStart = declaration.start ?? 0;
|
|
25742
25607
|
const originalEnd = declaration.end ?? originalStart;
|
|
25743
25608
|
const originalImportText = originalText.slice(originalStart, originalEnd);
|
|
25744
|
-
const originalLength = originalEnd - originalStart;
|
|
25745
25609
|
const hasSemicolon = originalImportText.trimEnd().endsWith(";");
|
|
25746
25610
|
const sourceText = entry.sourceText;
|
|
25747
25611
|
const matchedSpecifiers = removeTagImport ? entry.matchedSpecifiers : [];
|
|
@@ -25771,27 +25635,11 @@ function buildImportCleanupWithHelpers(originalText, entry, helpersToAdd, remove
|
|
|
25771
25635
|
const importPrefix = declaration.importKind === "type" ? "import type " : "import ";
|
|
25772
25636
|
replacement = `${importPrefix}${parts.join(", ")} from ${sourceText}${hasSemicolon ? ";" : ""}`;
|
|
25773
25637
|
}
|
|
25774
|
-
let replacementText = padToLength2(replacement, originalLength);
|
|
25775
|
-
if (replacementText == null) {
|
|
25776
|
-
const compactParts = [];
|
|
25777
|
-
if (defaultSpecifier) compactParts.push(originalText.slice(defaultSpecifier.start ?? 0, defaultSpecifier.end ?? 0));
|
|
25778
|
-
if (namespaceSpecifier) compactParts.push(originalText.slice(namespaceSpecifier.start ?? 0, namespaceSpecifier.end ?? 0));
|
|
25779
|
-
if (namedPieces.length > 0) compactParts.push(`{${namedPieces.join(",")}}`);
|
|
25780
|
-
const importPrefix = declaration.importKind === "type" ? "import type " : "import ";
|
|
25781
|
-
const compactReplacement = compactParts.length === 0 ? declaration.importKind === "type" ? "" : `import ${sourceText}${hasSemicolon ? ";" : ""}` : `${importPrefix}${compactParts.join(",")} from ${sourceText}${hasSemicolon ? ";" : ""}`;
|
|
25782
|
-
replacementText = padToLength2(compactReplacement, originalLength);
|
|
25783
|
-
}
|
|
25784
|
-
if (replacementText == null) {
|
|
25785
|
-
return {
|
|
25786
|
-
cleanup: removeTagImport ? entry.cleanup : null,
|
|
25787
|
-
mergedHelpers: /* @__PURE__ */ new Set()
|
|
25788
|
-
};
|
|
25789
|
-
}
|
|
25790
25638
|
return {
|
|
25791
25639
|
cleanup: {
|
|
25792
25640
|
originalStart,
|
|
25793
25641
|
originalEnd,
|
|
25794
|
-
replacementText
|
|
25642
|
+
replacementText: replacement
|
|
25795
25643
|
},
|
|
25796
25644
|
mergedHelpers
|
|
25797
25645
|
};
|
|
@@ -25888,6 +25736,13 @@ function buildShadowDocument(originalText, uri, version = 1, tagName = "pug", co
|
|
|
25888
25736
|
}
|
|
25889
25737
|
}
|
|
25890
25738
|
pendingInsertions.push(...buildStyleInsertions(originalText, regions, stylePlans));
|
|
25739
|
+
const pendingImportCleanups = importCleanups.map((cleanup) => ({
|
|
25740
|
+
kind: "import-cleanup",
|
|
25741
|
+
originalStart: cleanup.originalStart,
|
|
25742
|
+
originalEnd: cleanup.originalEnd,
|
|
25743
|
+
text: cleanup.replacementText,
|
|
25744
|
+
priority: -2
|
|
25745
|
+
}));
|
|
25891
25746
|
const pendingReplacements = regions.map((region, regionIndex) => ({
|
|
25892
25747
|
kind: "replace",
|
|
25893
25748
|
originalStart: region.originalStart,
|
|
@@ -25903,6 +25758,11 @@ function buildShadowDocument(originalText, uri, version = 1, tagName = "pug", co
|
|
|
25903
25758
|
} : null
|
|
25904
25759
|
}));
|
|
25905
25760
|
const edits = [
|
|
25761
|
+
...pendingImportCleanups.map((replacement) => ({
|
|
25762
|
+
sortStart: replacement.originalStart,
|
|
25763
|
+
priority: replacement.priority,
|
|
25764
|
+
edit: replacement
|
|
25765
|
+
})),
|
|
25906
25766
|
...pendingInsertions.map((insertion) => ({
|
|
25907
25767
|
sortStart: insertion.originalOffset,
|
|
25908
25768
|
priority: insertion.priority,
|
|
@@ -25937,14 +25797,16 @@ function buildShadowDocument(originalText, uri, version = 1, tagName = "pug", co
|
|
|
25937
25797
|
}
|
|
25938
25798
|
const shadowStart2 = shadowText.length;
|
|
25939
25799
|
edit.text && (shadowText += edit.text);
|
|
25940
|
-
|
|
25941
|
-
|
|
25942
|
-
|
|
25943
|
-
|
|
25944
|
-
|
|
25945
|
-
|
|
25946
|
-
|
|
25947
|
-
|
|
25800
|
+
if ("regionIndex" in edit) {
|
|
25801
|
+
regions[edit.regionIndex].shadowStart = shadowStart2;
|
|
25802
|
+
regions[edit.regionIndex].shadowEnd = shadowText.length;
|
|
25803
|
+
if (edit.mappedRegion) {
|
|
25804
|
+
mappedRegions.push({
|
|
25805
|
+
...edit.mappedRegion,
|
|
25806
|
+
shadowStart: shadowStart2,
|
|
25807
|
+
shadowEnd: shadowText.length
|
|
25808
|
+
});
|
|
25809
|
+
}
|
|
25948
25810
|
}
|
|
25949
25811
|
cursor = edit.originalEnd;
|
|
25950
25812
|
continue;
|
|
@@ -26003,12 +25865,126 @@ function buildShadowDocument(originalText, uri, version = 1, tagName = "pug", co
|
|
|
26003
25865
|
hasTagImport: analysis.hasTagImport,
|
|
26004
25866
|
missingTagImport
|
|
26005
25867
|
};
|
|
26006
|
-
if (importCleanups.length > 0) {
|
|
26007
|
-
document.shadowText = applyImportCleanups(document, importCleanups);
|
|
26008
|
-
}
|
|
26009
25868
|
return document;
|
|
26010
25869
|
}
|
|
26011
25870
|
|
|
25871
|
+
// ../react-pug-core/src/language/positionMapping.ts
|
|
25872
|
+
var import_source_map = __toESM(require_source_map());
|
|
25873
|
+
var sourceMapCache = /* @__PURE__ */ new WeakMap();
|
|
25874
|
+
function getSourceMap(region) {
|
|
25875
|
+
let sm = sourceMapCache.get(region);
|
|
25876
|
+
if (!sm) {
|
|
25877
|
+
sm = new import_source_map.SourceMap(region.mappings);
|
|
25878
|
+
sourceMapCache.set(region, sm);
|
|
25879
|
+
}
|
|
25880
|
+
return sm;
|
|
25881
|
+
}
|
|
25882
|
+
function rawToStrippedOffset(rawText, rawOffset, commonIndent) {
|
|
25883
|
+
if (commonIndent === 0) return rawOffset;
|
|
25884
|
+
let stripped = 0;
|
|
25885
|
+
let raw = 0;
|
|
25886
|
+
const lines = rawText.split("\n");
|
|
25887
|
+
for (let i = 0; i < lines.length; i++) {
|
|
25888
|
+
const line = lines[i];
|
|
25889
|
+
const lineEnd = raw + line.length;
|
|
25890
|
+
if (rawOffset <= lineEnd) {
|
|
25891
|
+
const colInRaw = rawOffset - raw;
|
|
25892
|
+
const indentToRemove2 = line.trim().length === 0 ? line.length : commonIndent;
|
|
25893
|
+
if (indentToRemove2 > 0 && colInRaw < indentToRemove2) return null;
|
|
25894
|
+
return stripped + Math.max(0, colInRaw - indentToRemove2);
|
|
25895
|
+
}
|
|
25896
|
+
const indentToRemove = line.trim().length === 0 ? line.length : commonIndent;
|
|
25897
|
+
stripped += Math.max(0, line.length - indentToRemove) + 1;
|
|
25898
|
+
raw = lineEnd + 1;
|
|
25899
|
+
}
|
|
25900
|
+
return stripped;
|
|
25901
|
+
}
|
|
25902
|
+
function strippedToRawOffset2(rawText, strippedOffset, commonIndent) {
|
|
25903
|
+
if (commonIndent === 0) return strippedOffset;
|
|
25904
|
+
let stripped = 0;
|
|
25905
|
+
let raw = 0;
|
|
25906
|
+
const lines = rawText.split("\n");
|
|
25907
|
+
for (let i = 0; i < lines.length; i++) {
|
|
25908
|
+
const line = lines[i];
|
|
25909
|
+
const indentToRemove = line.trim().length === 0 ? line.length : commonIndent;
|
|
25910
|
+
const strippedLineLen = Math.max(0, line.length - indentToRemove);
|
|
25911
|
+
if (strippedOffset <= stripped + strippedLineLen) {
|
|
25912
|
+
return raw + indentToRemove + (strippedOffset - stripped);
|
|
25913
|
+
}
|
|
25914
|
+
stripped += strippedLineLen + 1;
|
|
25915
|
+
raw += line.length + 1;
|
|
25916
|
+
}
|
|
25917
|
+
return raw;
|
|
25918
|
+
}
|
|
25919
|
+
function findSegmentAtOffset(segments, offset, getStart, getEnd) {
|
|
25920
|
+
let lo = 0;
|
|
25921
|
+
let hi = segments.length - 1;
|
|
25922
|
+
while (lo <= hi) {
|
|
25923
|
+
const mid = lo + hi >>> 1;
|
|
25924
|
+
const segment = segments[mid];
|
|
25925
|
+
if (offset < getStart(segment)) {
|
|
25926
|
+
hi = mid - 1;
|
|
25927
|
+
} else if (offset >= getEnd(segment)) {
|
|
25928
|
+
lo = mid + 1;
|
|
25929
|
+
} else {
|
|
25930
|
+
return segment;
|
|
25931
|
+
}
|
|
25932
|
+
}
|
|
25933
|
+
return null;
|
|
25934
|
+
}
|
|
25935
|
+
function getMappedRegionsForRegion(doc, regionIndex) {
|
|
25936
|
+
return doc.mappedRegions.filter((region) => region.regionIndex === regionIndex);
|
|
25937
|
+
}
|
|
25938
|
+
function findRegionAtOriginalOffset(doc, offset) {
|
|
25939
|
+
return findSegmentAtOffset(doc.regions, offset, (region) => region.originalStart, (region) => region.originalEnd);
|
|
25940
|
+
}
|
|
25941
|
+
function findCopySegmentAtOriginalOffset(doc, offset) {
|
|
25942
|
+
return findSegmentAtOffset(doc.copySegments, offset, (segment) => segment.originalStart, (segment) => segment.originalEnd);
|
|
25943
|
+
}
|
|
25944
|
+
function findCopySegmentAtShadowOffset(doc, offset) {
|
|
25945
|
+
return findSegmentAtOffset(doc.copySegments, offset, (segment) => segment.shadowStart, (segment) => segment.shadowEnd);
|
|
25946
|
+
}
|
|
25947
|
+
function originalToShadow(doc, originalOffset) {
|
|
25948
|
+
if (originalOffset === doc.originalText.length) return doc.shadowText.length;
|
|
25949
|
+
const region = findRegionAtOriginalOffset(doc, originalOffset);
|
|
25950
|
+
if (region) {
|
|
25951
|
+
const regionIndex = doc.regions.indexOf(region);
|
|
25952
|
+
const rawOffset = originalOffset - region.pugTextStart;
|
|
25953
|
+
if (rawOffset < 0) return null;
|
|
25954
|
+
const rawText = doc.originalText.slice(region.pugTextStart, region.pugTextEnd);
|
|
25955
|
+
const strippedOffset = rawToStrippedOffset(rawText, rawOffset, region.commonIndent);
|
|
25956
|
+
if (strippedOffset == null) return null;
|
|
25957
|
+
for (const mappedRegion of getMappedRegionsForRegion(doc, regionIndex)) {
|
|
25958
|
+
if (strippedOffset < mappedRegion.sourceStart || strippedOffset >= mappedRegion.sourceEnd) continue;
|
|
25959
|
+
const sm = getSourceMap(mappedRegion);
|
|
25960
|
+
for (const [generatedOffset] of sm.toGeneratedLocation(strippedOffset)) {
|
|
25961
|
+
return mappedRegion.shadowStart + generatedOffset;
|
|
25962
|
+
}
|
|
25963
|
+
}
|
|
25964
|
+
return null;
|
|
25965
|
+
}
|
|
25966
|
+
const copySegment = findCopySegmentAtOriginalOffset(doc, originalOffset);
|
|
25967
|
+
if (!copySegment) return null;
|
|
25968
|
+
return copySegment.shadowStart + (originalOffset - copySegment.originalStart);
|
|
25969
|
+
}
|
|
25970
|
+
function shadowToOriginal(doc, shadowOffset) {
|
|
25971
|
+
if (shadowOffset === doc.shadowText.length) return doc.originalText.length;
|
|
25972
|
+
for (const mappedRegion of doc.mappedRegions) {
|
|
25973
|
+
if (shadowOffset < mappedRegion.shadowStart || shadowOffset >= mappedRegion.shadowEnd) continue;
|
|
25974
|
+
const localOffset = shadowOffset - mappedRegion.shadowStart;
|
|
25975
|
+
const sm = getSourceMap(mappedRegion);
|
|
25976
|
+
for (const [sourceOffset] of sm.toSourceLocation(localOffset)) {
|
|
25977
|
+
const region = doc.regions[mappedRegion.regionIndex];
|
|
25978
|
+
const rawText = doc.originalText.slice(region.pugTextStart, region.pugTextEnd);
|
|
25979
|
+
const rawOffset = strippedToRawOffset2(rawText, sourceOffset, region.commonIndent);
|
|
25980
|
+
return region.pugTextStart + rawOffset;
|
|
25981
|
+
}
|
|
25982
|
+
}
|
|
25983
|
+
const copySegment = findCopySegmentAtShadowOffset(doc, shadowOffset);
|
|
25984
|
+
if (!copySegment) return null;
|
|
25985
|
+
return copySegment.originalStart + (shadowOffset - copySegment.shadowStart);
|
|
25986
|
+
}
|
|
25987
|
+
|
|
26012
25988
|
// ../../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
26013
25989
|
var comma = ",".charCodeAt(0);
|
|
26014
25990
|
var semicolon = ";".charCodeAt(0);
|