Skip to content

Parser splits JSX from a following computed property access, call, or template literal #65724

Backlog

Description

@magic-akari

🔎 Search Terms

JSX automatic semicolon insertion, JSX element access, JSX call expression, TSX tagged template

🕗 Version & Regression Information

Reproduces in both .jsx and .tsx with TypeScript 7.0.2, 6.0.3, 5.9.3, and nightly 7.1.0-dev.20261129.1.

⏯ Playground Link

https://www.typescriptlang.org/play/v2/?ts=6.0.3#code/v2/N4IghgxgLglgbgUwGIwDYJALhAegO4D2ATgNYDOADpAjmURDjAHYAmCAHgHRRnsgA0IAGZoEZLKHzFyVCDToNmbLjz7YcAKg0ACAAIArXtoAW2jTgA6TIQFcm0GASYmAFAEptwbUQRQbRZ2AAXwBubSCrW3tYJ20ASSgEAFt3T29ff2cmG1RUMIimK3QobRIEAE9tAF5tAAYQqwgnMhK4MFQbMWrtAG0AdgBdBvtmkp8yHJKagB4E5O0cAD4rHrLyge62jrFhxuaCdE5UAgBzFzX+bQBBIiIwcs4YMhu78pdxybc3YYFcQlJKNQcDwmtYYCdOIYnFgQMArNptBYQE0khRREQAPIUGJMMhIzCeeEIxEgKBgIgnXz4kliJgcKBI-hEhFIpIEFg5BDUpG0+mM5kkwzsbkgHyQBkCAVIlpEGDQalQIidJnOYlIqDlChiak9AZEoIqlnCUR4rC9KUgBSMVgcbi8JFEvVMAogA2WhDoBzQzCgCgEMgwHEAYQONiSTCwAEZBH6AziADLMBAAOTDACMEEQo4IyB6EF6mABlMlEKAhjrh7Puz044vkqCJumppIZrOYSNuxBEAPegBMQSAA

💻 Code

/** @jsx h */
function h() { return {}; }
function Item() { return null; }

let key = 0;
const values = [7];
const result = <Item />
[key] = values;

console.log(key, Array.isArray(result));

🙁 Actual behavior

tsc accepts the example and emits two statements.

const result = h(Item, null);
[key] = values;

The program prints 7 false. result holds the object returned by h, and the destructuring assignment sets key to 7.

When the next line is (arg); or `q`;, TypeScript likewise parses it as a standalone expression. Paired elements and fragments behave the same way. On one line, <Item />[key] = values; produces TS1005.

🙂 Expected behavior

[key] should index the JSX value in both .jsx and .tsx. Parenthesizing just <Item /> already makes TypeScript compile the initializer as a single assignment.

const result = (h(Item, null)[key] = values);

The program should print 0 true. key keeps its value, and result receives the array assigned to property 0.

Additional information about the issue

The JSX draft defines elements and fragments as primary expressions. ECMAScript allows computed property access, calls, and tagged templates to continue a primary expression across a line break, so automatic semicolon insertion should leave the expression intact. JSX grammar · ECMAScript left-hand-side expressions · ASI rules

In parseUpdateExpression, the JSX branch returns before parseLeftHandSideExpressionOrHigher handles these continuations. TypeScript 7.0.2 parser

Babel and esbuild parse all three forms as one expression in both modes. Examples and parser results in swc-project/swc-next-issues#574

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions