fix(js-parser): handle JSXEmptyExpression position
MODIFY
internal/compiler/lint/rules/jsx/noCommentText.test.md
internal/compiler/lint/rules/jsx/noCommentText.test.md
@@ -107,7 +107,7 @@ const a = <div>
```tsx
const a = <div>
- {} /* comment */
+ {/* comment */}
</div>;
```
@@ -122,7 +122,7 @@ const a = <div>
```tsx
const a = <div>
- {} /** comment*/
+ {/** comment*/}
</div>;
```

MODIFY
internal/js-parser/parser/jsx.ts
internal/js-parser/parser/jsx.ts
@@ -200,18 +200,6 @@ function parseJSXAttributeValue(
}
}
-// JSXEmptyExpression is unique type since it doesn't actually parse anything,
-// and so it should start at the end of last read token (left brace) and finish
-// at the beginning of the next one (right brace).
-function parseJSXEmptyExpression(parser: JSParser): JSXEmptyExpression {
- return parser.finishNode(
- parser.state.lastEndPos,
- {
- type: "JSXEmptyExpression",
- },
- );
-}
-
// Parse JSX spread child
function parseJSXSpreadChild(parser: JSParser): JSXSpreadChild {
const start = parser.getPosition();
@@ -244,8 +232,15 @@ function parseJSXExpressionContainer(parser: JSParser): JSXExpressionContainer {
"jsx expression container",
);
let expression;
+ const beforeBraceR = parser.getPosition();
if (match(parser, tt.braceR)) {
- expression = parseJSXEmptyExpression(parser);
+ expression = parser.finishNodeAt<JSXEmptyExpression>(
+ start,
+ beforeBraceR,
+ {
+ type: "JSXEmptyExpression",
+ },
+ );
} else {
expression = parseExpression(parser, "jsx inner expression container");
}

MODIFY
internal/js-parser/test-fixtures/jsx/basic/10/input.test.md
internal/js-parser/test-fixtures/jsx/basic/10/input.test.md
@@ -15,8 +15,9 @@ JSRoot {
children: [
JSXExpressionContainer {
expression: JSXEmptyExpression {
- trailingComments: ["1"]
- loc: SourceLocation jsx/basic/10/input.jsx 1:4-1:4
+ innerComments: ["1"]
+ trailingComments: []
+ loc: SourceLocation jsx/basic/10/input.jsx 1:3-1:27
}
loc: SourceLocation jsx/basic/10/input.jsx 1:3-1:28
}

MODIFY
internal/js-parser/test-fixtures/jsx/basic/empty-expression-container/input.test.md
internal/js-parser/test-fixtures/jsx/basic/empty-expression-container/input.test.md
@@ -15,7 +15,7 @@ JSRoot {
children: [
JSXExpressionContainer {
expression: JSXEmptyExpression {
- loc: SourceLocation jsx/basic/empty-expression-container/input.jsx 1:4-1:4
+ loc: SourceLocation jsx/basic/empty-expression-container/input.jsx 1:3-1:4
}
loc: SourceLocation jsx/basic/empty-expression-container/input.jsx 1:3-1:5
}

MODIFY
internal/js-parser/test-fixtures/jsx/errors/attribute-empty-expression/input.test.md
internal/js-parser/test-fixtures/jsx/errors/attribute-empty-expression/input.test.md
@@ -19,7 +19,7 @@ JSRoot {
}
value: JSXExpressionContainer {
expression: JSXEmptyExpression {
- loc: SourceLocation jsx/errors/attribute-empty-expression/input.jsx 1:10-1:10
+ loc: SourceLocation jsx/errors/attribute-empty-expression/input.jsx 1:9-1:10
}
loc: SourceLocation jsx/errors/attribute-empty-expression/input.jsx 1:9-1:11
}

MODIFY
internal/js-parser/test-fixtures/jsx/errors/unclosed-jsx-element/input.test.md
internal/js-parser/test-fixtures/jsx/errors/unclosed-jsx-element/input.test.md
@@ -19,7 +19,7 @@ JSRoot {
}
JSXExpressionContainer {
expression: JSXEmptyExpression {
- loc: SourceLocation jsx/errors/unclosed-jsx-element/input.jsx 1:12-1:12
+ loc: SourceLocation jsx/errors/unclosed-jsx-element/input.jsx 1:11-1:12
}
loc: SourceLocation jsx/errors/unclosed-jsx-element/input.jsx 1:11-1:13
}

fix(js-parser): handle JSXEmptyExpression position (#1501)