Skip to content

Commit d4220b2

Browse files
committed
Keep track of characters needed to close the current props
1 parent 4760c17 commit d4220b2

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/index.mjs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ function build(statics) {
4545
let field = '';
4646
let hasChildren = 0;
4747
let props = '';
48+
let propsClose = '';
49+
let spreadClose = '';
4850
let quote = 0;
49-
let spread, slash, charCode, inTag, propName, propHasValue;
51+
let slash, charCode, inTag, propName, propHasValue;
5052

5153
function commit() {
5254
if (!inTag) {
@@ -62,19 +64,18 @@ function build(statics) {
6264
}
6365
else if (mode === MODE_ATTRIBUTE || (mode === MODE_WHITESPACE && buffer === '...')) {
6466
if (mode === MODE_WHITESPACE) {
65-
if (!spread) {
66-
spread = true;
67-
if (!props) props = 'Object.assign({},';
68-
else props = 'Object.assign({},' + props + '},';
67+
if (!spreadClose) {
68+
spreadClose = ')';
69+
if (!props) props = 'Object.assign({}';
70+
else props = 'Object.assign({},' + props;
6971
}
70-
else {
71-
props += '},';
72-
}
73-
props += field + ',{';
72+
props += propsClose + ',' + field;
73+
propsClose = '';
7474
}
7575
else if (propName) {
7676
if (!props) props += '{';
77-
else if (!props.endsWith('{')) props += ',';
77+
else props += ',' + (propsClose ? '' : '{');
78+
propsClose = '}';
7879
props += JSON.stringify(propName) + ':';
7980
props += field || ((propHasValue || buffer) && JSON.stringify(buffer)) || 'true';
8081
propName = '';
@@ -122,8 +123,8 @@ function build(statics) {
122123
// commit buffer
123124
commit();
124125
inTag = true;
125-
props = '';
126-
slash = spread = propHasValue = false;
126+
spreadClose = propsClose = props = '';
127+
slash = propHasValue = false;
127128
mode = MODE_TAGNAME;
128129
continue;
129130
}
@@ -136,13 +137,13 @@ function build(statics) {
136137
out += ',null';
137138
}
138139
else {
139-
out += ',' + props + '}' + (spread ? ')' : '');
140+
out += ',' + props + propsClose + spreadClose;
140141
}
141142
}
142143
if (slash) {
143144
out += ')';
144145
}
145-
spread = inTag = false;
146+
inTag = false;
146147
props = '';
147148
mode = MODE_TEXT;
148149
continue;

0 commit comments

Comments
 (0)