Skip to content

Commit 7d0f8a6

Browse files
authored
fix missing spaces in jsx (#125)
1 parent 1b88b6e commit 7d0f8a6

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

lib/index.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,6 @@ function tokenize(code, options) {
304304
* @param {string} token_
305305
*/
306306
const append = (type_, token_) => {
307-
if (type_ || token_) {
308-
const nType = TokenTypes[type_]
309-
}
310307
if (token_) {
311308
current = token_
312309
}
@@ -460,26 +457,26 @@ function tokenize(code, options) {
460457
if (next === '-' && !inStringContent() && !inJsxLiterals()) {
461458
if (current) {
462459
append(T_PROPERTY, current + curr + next)
463-
i += 1
460+
i++
464461
continue
465462
}
466463
}
467464
// `=` in property=<value>
468465
if (next === '=' && !inStringContent()) {
469466
// if current is not a space, ensure `prop` is a property
470-
if (isSpaces(current)) {
471-
append(T_SPACE, current)
472-
current = ''
467+
if (!isSpaces(curr)) {
468+
// If there're leading spaces, append them first
469+
if (isSpaces(current)) {
470+
append()
471+
}
472+
473+
// Now check if the accumulated token is a property
474+
const prop = current + curr
475+
if (isIdentifier(prop)) {
476+
append(T_PROPERTY, prop)
477+
continue
478+
}
473479
}
474-
const prop = current ? (current + curr) : curr
475-
if (isIdentifier(prop)) {
476-
current = prop
477-
append(T_PROPERTY)
478-
} else if (prop === ' ') {
479-
current = prop
480-
append(T_SPACE)
481-
}
482-
continue
483480
}
484481
}
485482
}

test/ast.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ describe('jsx', () => {
385385
"( => sign",
386386
"v => identifier",
387387
") => sign",
388+
" => space",
388389
"= => sign",
389390
"> => sign",
390391
" => space",

0 commit comments

Comments
 (0)