ampproject / ampproject/amphtml

Use namespace other than `Preact` with `#core/dom/jsx`

Open
#36,680 3 comments 0 reactions 1 assignee Claimed by @alanorozco View on GitHub
Stale WG: infra
Dominant language
JavaScript
Stars
14.9k
Forks
4.1k
PR merge metrics
No merged PRs in 30d

Description

We import `#core/dom/jsx` under the `Preact` namespace:

```js
import * as Preact from '#core/dom/jsx';
```

We should use `@jsx` with a namespace other than `Preact` since it's misleading:

> https://github.com/ampproject/amphtml/pull/36640#discussion_r739534313
> Nit: I'm a bit worried we'll confuse this with actual Preact (and the ability to diff). Can we use a different name and `@jsxPragma`?
>
> ```js
> // input
> /** @jsx StaticTree.createElement */
>
>


>
>
>
> // output
> StaticTree.createElement("div");
> ```

Closure does not play nice with the `@jsx` annotation:

```
WARNING - [JSC_BAD_JSDOC_ANNOTATION] Parse error. illegal use of unknown JSDoc tag "jsx"; ignoring it.
Place another character before the @ to stop JSCompiler from parsing it as an annotation.
```

If we ever figure this out, or move away from Closure (#35264), we should:

- Replace all uses with `JsxStaticTree`
- Update `local/preact` lint rule so that it allows namespaces other than `Preact`. (It would be convenient if namespace has to start with`Jsx`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.