-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat: add print(...)
function
#16188
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
base: main
Are you sure you want to change the base?
Conversation
|
Nice! I'll be happy to sunset |
Over on sveltejs/esrap#68 we're working on making
esrap
pluggable, so that it can be used to print any AST composed of{ type: string, ... }
nodes rather than justestree
and its TypeScript extensions. That includes Svelte ASTs.The main motivation for exposing this is so that we can make it easier to write preprocessors. Historically, Svelte exposed a
preprocess
API, but it's all strings and duct tape, and it's difficult to integrate preprocessors cleanly with bundlers as we've seen withenhanced-img
.When the preprocessor API was introduced, things looked very different. Preprocessing was necessary to support things like TypeScript and Sass. Today, TypeScript is supported natively, and CSS is sufficiently capable that Sass is little more than a historical curiosity.
In the long term, we'd therefore like to move away from the preprocessor API in favour of providing more robust lower-level utilities. For example
enhanced-img
, which can only be used in a Vite context, really should just be a Vite plugin:There are other potential uses, such as migrations or
sv add
or having a 'format' button in the playground.As a side-effect, quality of compiler output will be slightly better in certain cases, such as when encountering comments inside nodes. (Today, we attach
leadingComments
andtrailingComments
to each node, but this is a brittle and not-very-widely-used convention. The newesrap
API expects an array ofcomments
to be passed instead.)This functionality already exists in
svelte-ast-print
(thank you @xeho91!), but having it in core means we can re-use theesrap
version that's already installed alongsidesvelte
, and will help ensure it stays current with new features.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint