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

feat: support identifying jsxImportSource pragma dependencies #62

Merged
merged 4 commits into from
Nov 2, 2021

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Nov 1, 2021

Ref: denoland/deno#8440

This PR adds the following features:

  • parses out the @jsxImportSource pragma from a module
  • adds the emitted module specifier as a dependency to the module
  • Allows the loader trait to supply the specifier module, defaulting to jsx-runtime (this is needed because when specifying "dev" mode, the implicit module name changes to jsx-dev-runtime)

This, plus the concept of "imports" already in the graph should allow us to support the React 17 JSX transforms in CLI (and in theory Deploy) in the least "hacky" way possible.

For context, something like this:

/* @jsxImportSource https://esm.sh/preact */

export function A() {
  return <div>Hello Deno</div>;
}

will get emitted to something like this:

import { jsx as _jsx } from "https://esm.sh/preact/jsx-runtime";
/* @jsxImportSource https://esm.sh/preact */
export function A() {
    return _jsx("div", { children: "Hello Deno" }, void 0);
}

And the parsing of the module would identify that https://esm.sh/preact/jsx-runtime would be what would be a runtime dependency and adds it to the dependencies of the graph module.

@kitsonk kitsonk requested a review from dsherret November 1, 2021 03:31
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/source.rs Outdated Show resolved Hide resolved
@kitsonk kitsonk requested a review from dsherret November 2, 2021 06:10
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kitsonk kitsonk merged commit 9ce1792 into denoland:main Nov 2, 2021
@kitsonk kitsonk deleted the feat_jsx_import_source branch November 2, 2021 20:26
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

Successfully merging this pull request may close these issues.

2 participants