Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle @jsx pragmas for TypeScript #3560

Closed
overlookmotel opened this issue Jun 6, 2024 · 9 comments
Closed

Handle @jsx pragmas for TypeScript #3560

overlookmotel opened this issue Jun 6, 2024 · 9 comments
Assignees

Comments

@overlookmotel
Copy link
Collaborator

overlookmotel commented Jun 6, 2024

We recently added more support for @jsx pragmas in conformance suite (#3553).

I believe some of these should be handled in parser/semantic/transformer (not sure which) instead for TS/TSX files. According to TS docs, they're valid:

https://www.typescriptlang.org/docs/handbook/jsx.html#configuring-jsx

@overlookmotel overlookmotel added the C-bug Category - Bug label Jun 6, 2024
@Boshen
Copy link
Member

Boshen commented Jun 6, 2024

It should be analyzed in the transformer.

@overlookmotel
Copy link
Collaborator Author

Would it not be useful to add a pragmas field to Program and populate it in the parser, like with Hashbang? I imagine other tools might find this info useful as its meaningful information for interpreting the AST (broadly equivalent to an import React from "whatever"; statement).

@Boshen
Copy link
Member

Boshen commented Jun 6, 2024

Nope, it's not part of the spec so it can't go into the AST.

@overlookmotel
Copy link
Collaborator Author

But it is part of the TS spec, no? https://www.typescriptlang.org/docs/handbook/jsx.html#configuring-jsx

@Boshen
Copy link
Member

Boshen commented Jun 6, 2024

That's not an AST spec, it's just documentation 😅

@overlookmotel
Copy link
Collaborator Author

overlookmotel commented Jun 6, 2024

OK, true! But what's the difference? Spec and config are both things which are present in the source text, and alter the meaning of the code.

Therefore I feel it's better to store that useful info in AST. And we have to parse it somewhere, so might as well parse it in the parser. But I don't feel strongly about it - say no one more time, and I'll shut up!

@overlookmotel
Copy link
Collaborator Author

PS It'd also be faster to find these comments in parser while parsing comments anyway, rather than searching through all comments again later.

@Boshen
Copy link
Member

Boshen commented Jun 6, 2024

You can save them into Trivias if you really want to parse them from the parser.

@Boshen Boshen self-assigned this Jun 11, 2024
@Boshen Boshen removed the C-bug Category - Bug label Jun 11, 2024
@Boshen
Copy link
Member

Boshen commented Jun 14, 2024

In #3553

The lines in https://github.com/microsoft/TypeScript/blob/main/tests/cases/compiler/jsxComplexSignatureHasApplicabilityError.tsx

// @strict: true
// @jsx: react
// @skipLibCheck: true

are compiler settings for the test file, they aren't pragmas.


In tsx files, the prgrama

/** @jsxImportSource preact */

<Foo />

produces

import {jsx as _jsx} from 'preact/jsx-runtime';
_jsx(Foo, {});

which is working as intended.

@Boshen Boshen closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants