-
Notifications
You must be signed in to change notification settings - Fork 3
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
svelte template syntax support #101
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for g-next ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Code Coverage ReportCoverage after merging svelte-template-syntax-support into master
Coverage Report
|
da863e3
to
f68074e
Compare
duration phase no difference [-126ms to 119ms] [22:15:25] Generating Benchmark Reports [started]
JSON: /home/runner/work/glimmer-next/glimmer-next/tracerbench-results/compare.json PDF: /home/runner/work/glimmer-next/glimmer-next/tracerbench-results/artifact-1.pdf HTML: /home/runner/work/glimmer-next/glimmer-next/tracerbench-results/artifact-1.html |
7538240
to
0d20552
Compare
856dcd2
to
aa2545d
Compare
Resolves: #100
check:
node plugins/svelte-compiler.js
// https://gist.github.com/lifeart/133d679f18a9340fa4f190bcd7caed06
Todo:
Plugin description
This Babel Abstract Syntax Tree (AST) plugin is designed for processing JavaScript code, particularly targeting the transformation of class components and variable declarations within a specific framework or library context. The plugin seems to be part of a larger build system or compiler aimed at enhancing state management and reactivity in JavaScript applications. Here's a breakdown of its functionalities and some input-output code examples to illustrate its actions.Main Features
ClassBody Transformation: It handles class properties, distinguishing between public and private properties, and processes properties initialized with special call expressions (
$state
,$state.frozen
,$derived
,$derived.by
). It modifies these properties based on their initialization, generating backing private fields, getters, setters, and ensuring immutability or reactivity where necessary.VariableDeclaration Transformation: It processes variable declarations, looking for specific call expressions that indicate special state or derived state creation (
$state
,$state.frozen
,$derived
,$derived.by
), and transforms them accordingly. It also handles$props
for destructuring component props and$effect
for effect management.ExpressionStatement & CallExpression Transformation: It identifies and transforms specific call expressions related to effects (
$effect
,$effect.root
,$effect.active
) and inspection utilities ($inspect
).Code Transformations Examples
Before - Class Component with State and Derived Properties
After - Transformed Class Component
This transformed code introduces private backing fields for stateful properties, wraps initial state values with proxy or freeze functions for reactivity or immutability, and generates getters (and setters where applicable) for accessing and updating state.
Before - Variable Declaration with State
After - Transformed Variable Declaration
The transformation wraps the state initialization in a call to create a reactive source and wraps derived state in a derived function call, ensuring the derived state updates in response to the original state changes.
Summary
This plugin is a sophisticated tool designed to work with a specific state management and reactivity model, transforming class properties and variable declarations to introduce reactivity, immutability, and efficient updates in a JavaScript application's components. The transformations ensure the application's state is managed in a predictable and optimized manner, enhancing the development experience and runtime efficiency.
let { width, height } = $props(); // instead of
export let` ?bind:
support ?...attributes
({...$$restProps}
) on elementseems
magic.update(node.start, node.end, result);
should be replaced withmagic.appendLeft(node.start, result);