Skip to content

Commit e0411f6

Browse files
committed
this uncovered another case of how ridicoulus the old AST was
1 parent 1f9554a commit e0411f6

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

packages/svelte/src/compiler/legacy.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,37 @@ export function convert(source, ast) {
141141
};
142142

143143
if (node.pending) {
144-
const first = /** @type {import('#compiler').BaseNode} */ (node.pending.nodes.at(0));
145-
const last = /** @type {import('#compiler').BaseNode} */ (node.pending.nodes.at(-1));
144+
const first = node.pending.nodes.at(0);
145+
const last = node.pending.nodes.at(-1);
146146

147-
pendingblock.start = first.start;
148-
pendingblock.end = last.end;
147+
pendingblock.start = first?.start ?? source.indexOf('}', node.expression.end) + 1;
148+
pendingblock.end = last?.end ?? pendingblock.start;
149149
pendingblock.skip = false;
150150
}
151151

152152
if (node.then) {
153-
const first = /** @type {import('#compiler').BaseNode} */ (node.then.nodes.at(0));
154-
const last = /** @type {import('#compiler').BaseNode} */ (node.then.nodes.at(-1));
153+
const first = node.then.nodes.at(0);
154+
const last = node.then.nodes.at(-1);
155155

156-
thenblock.start = pendingblock.end ?? first.start;
157-
thenblock.end = last.end;
156+
thenblock.start =
157+
pendingblock.end ?? first?.start ?? source.indexOf('}', node.expression.end) + 1;
158+
thenblock.end =
159+
last?.end ?? source.lastIndexOf('}', pendingblock.end ?? node.expression.end) + 1;
158160
thenblock.skip = false;
159161
}
160162

161163
if (node.catch) {
162-
const first = /** @type {import('#compiler').BaseNode} */ (node.catch.nodes.at(0));
163-
const last = /** @type {import('#compiler').BaseNode} */ (node.catch.nodes.at(-1));
164-
165-
catchblock.start = thenblock.end ?? pendingblock.end ?? first.start;
166-
catchblock.end = last.end;
164+
const first = node.catch.nodes.at(0);
165+
const last = node.catch.nodes.at(-1);
166+
167+
catchblock.start =
168+
thenblock.end ??
169+
pendingblock.end ??
170+
first?.start ??
171+
source.indexOf('}', node.expression.end) + 1;
172+
catchblock.end =
173+
last?.end ??
174+
source.lastIndexOf('}', thenblock.end ?? pendingblock.end ?? node.expression.end) + 1;
167175
catchblock.skip = false;
168176
}
169177

0 commit comments

Comments
 (0)