Skip to content

Commit e56ceab

Browse files
committed
plus and minus
1 parent 0b8c038 commit e56ceab

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

packages/svelte2tsx/src/utils/htmlxparser.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ const possibleOperatorOrPropertyAccess = [
128128
'&',
129129
'^',
130130
'|',
131-
','
131+
',',
132+
'+',
133+
'-'
132134
];
133135

134136
function blankPossiblyErrorOperatorOrPropertyAccess(htmlx: string) {
@@ -141,8 +143,18 @@ function blankPossiblyErrorOperatorOrPropertyAccess(htmlx: string) {
141143
while (backwardIndex > lastIndex) {
142144
const char = htmlx.charAt(backwardIndex);
143145
if (possibleOperatorOrPropertyAccess.includes(char)) {
144-
htmlx =
145-
htmlx.substring(0, backwardIndex) + ' ' + htmlx.substring(backwardIndex + 1);
146+
const previous = backwardIndex - 1;
147+
const isPlusOrMinus = char === '+' || char === '-';
148+
const isIncrementOrDecrement = isPlusOrMinus && htmlx.charAt(previous) === char;
149+
const start = isIncrementOrDecrement ? previous : backwardIndex;
150+
const replacement = isIncrementOrDecrement ? ' ' : ' ';
151+
152+
if (!isPlusOrMinus) {
153+
htmlx =
154+
htmlx.substring(0, start) +
155+
replacement +
156+
htmlx.substring(backwardIndex + 1);
157+
}
146158
} else if (!/\s/.test(char)) {
147159
break;
148160
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<>{abc. }
22
{abc?. }
3-
{abc ?}</>
3+
{abc ?}
4+
{a+}</>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{abc. }
22
{abc?. }
33
{abc ?}
4+
{a+}

0 commit comments

Comments
 (0)