Skip to content

Commit 4506138

Browse files
fix: allow overlapping nested replacements. (#62)
1 parent 6873250 commit 4506138

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knighted/jsx",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "Runtime JSX tagged template that renders DOM or React trees anywhere without a build step.",
55
"keywords": [
66
"jsx runtime",

src/loader/helpers/materialize-slice.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export const materializeSlice = (
3131

3232
nested.forEach(entry => {
3333
if (entry.start < cursor) {
34-
throw new Error(
35-
`[jsx-loader] Overlapping replacement ranges detected (${entry.start}:${entry.end}) within ${start}:${end}. Nested replacements must not overlap.`,
36-
)
34+
return
3735
}
3836
output += source.slice(cursor, entry.start)
3937
output += entry.code

test/loader-internals.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ describe('loader internals', () => {
3131
expect(result).toBe('aXYf')
3232
})
3333

34-
it('throws on overlapping nested replacements', () => {
34+
it('skips overlapping nested replacements', () => {
3535
const replacements = new Map<string, string>([
3636
['1:4', 'X'],
3737
['3:5', 'Y'],
3838
])
39-
expect(() => materializeSlice(0, 6, 'abcdef', replacements)).toThrow(
40-
'Overlapping replacement ranges detected',
41-
)
39+
const result = materializeSlice(0, 6, 'abcdef', replacements)
40+
expect(result).toBe('aXef')
4241
})
4342

4443
it('returns exact replacement without scanning nested ranges', () => {

0 commit comments

Comments
 (0)