Git Product home page Git Product logo

rustle's People

Contributors

alfiedotwtf avatar fawaz-alesayi avatar linh-1 avatar linrium avatar pintariching avatar qwertydelle avatar themixu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rustle's Issues

Rustle output

I was going through the output of the svelte compiler vs rustle and I realized it wasn't one to one is this by design or is it something we are gonna have to work on?

Estree AST or SWC AST

Ok so we might have a problem the AST swc_ecma_parser produces is very different from the EStree compatible AST that acorn uses. The swc_estree_compat library provides a way to transform SWC AST to an EStree compatible AST but it makes overall parsing much slower than just using the SWC AST and it also requires the nightly compiler which is unstable. Should we use the nightly compiler and risk some features being removed, build our own AST transformer or just use the SWC AST?

missing support for native attribute?

hi there! it is great to see your great work!
BTW, I try rustle around and find out it cannot parse the HTML DOM attribute

<button on:click={increment}>Increment</button>
<span>
<!-- this ok -->
  <div bind:class={'q'}>{counter}</div>

<!-- this fail -->
  <div class="q">{counter}</div>
</span>
<button on:click={decrement}>Decrement</button>

hope this help you, thank

Implement functions in compiler::parse::state::tag

A few helper functions need to be translated in compiler::parse::state::tag, mainly

  • read_sequence
  • read_attribute_value
  • read_attribute
  • read_tag_name
    Some of them are half way written, some are not, check for functions that have a todo!().

Roadmap to 0.0.1 prerelease

I think we can have a pre release when we get the parsing working. Also perhaps implementing a basic CLI with a few commands that you can point to a .svelte file and it prints out the AST?

Assignment inside function call?

What is this line here doing?

const identifier = this.template.slice(this.index, this.index = i);

I can't figure out what the this.index = 1 means. Does it assign i to this.index?

Replacement for Node

The type Node is used by rustle interfaces for the compile step and also in the code-red package in handlers.js The type definition is pulled from @types/estree however from an old version 0.0.50 which defined Node as

export type Node =
    Identifier | Literal | Program | Function | SwitchCase | CatchClause |
    VariableDeclarator | Statement | Expression | PrivateIdentifier | Property | PropertyDefinition |
    AssignmentProperty | Super | TemplateElement | SpreadElement | Pattern |
    ClassBody | Class | MethodDefinition | ModuleDeclaration | ModuleSpecifier;

The new version defines Node as this

The problem is that in swc_estree_ast the Node enum has been commented out and I'm not sure where to pull the right type definitions.

Discussion sourcesmap library for mapped_code util

I checked this file https://github.com/sveltejs/svelte/blob/master/src/compiler/utils/mapped_code.ts.
As I see in this file, it imports three libraries.

import { DecodedSourceMap, RawSourceMap, SourceMapLoader } from '@ampproject/remapping/dist/types/types';
import remapping from '@ampproject/remapping';
import { SourceMap } from 'magic-string';

We can use https://github.com/h-a-n-a/magic-string-rs for magic-string. With @ampproject/remapping we can use https://github.com/getsentry/rust-sourcemap or https://www.npmjs.com/package/@swc-node/sourcemap-support.

I haven't checked it carefully. Feel free to help.

Add more tests

More tests would probably be a good idea. Maybe making a folder structure and having different files like input.svelte, expected.js and output.js in a folder for every test, then use walkdir to traverse all the folders and compile the files and check if they're the same as the expected.js. Also adding test for checking if the AST has been parse correctly for a variety of different situations would probably be nice.

Implement a CLI

I think a simple CLI is the last piece missing before doing a prerelease. I think it should just accept a file or a directory and call the rustle::compile_file_to_js function. For now I think if anything goes wrong it should just panic.

Does anybody want to work on it or has any other suggestions?

How to test?

Awesome project, thanks for taking this on 🎉

I assumed I could create an app.rustle file with the following contents:

<script>
  let test = "test";
</script>

<h1>{test}</h1>

Then run rustle_cli app.rustle to create a compiled app.js file, but that throws:

thread 'main' panicked at 'Parse error: expecting ={', /home/jimafisk/.cargo/registry/src/github.com-1ecc6299db9ec823/rustle_lib-0.0.1-alpha/src/compiler/parse/parser.rs:120:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Suggestions on what to improve

The latest library release adds support for nested component and passing properties to them. A lot of functionality still has to be tested by expanding the tests.

Feel free to try out the compiler with everything you can throw at it so we can see what still has to be fixed!

Compile rewrite

  • css
  • nodes
  • render_dom
  • render_ssr
  • utils
  • compiler_errors.ts
  • compiler_warnings.ts
  • component.ts
  • create_module.ts
  • index.ts

Naming suggestions

Something that combines rust and svelte in some form?
For some ideas, rust could be substituted with something to do with oxidation or perhaps the various types of rust: hematite, magnetite, wüstite
Svelte in English is used to describe a slender - thin appearance

Compiler rewrite

For the first thing, I think translating the compiler first would be a good idea. The original version can be found here. I think for now I'll write some steps for starting here:

Entities util duplicates in from_code

In src/compiler/parse/utils/entities.rs. from_code method matches duplicate two codes to both Entity::nbsp and Entity::NonBreakingSpace. It will cause the second statement to be never reached.

160 => Entity::NonBreakingSpace,
160 => Entity::nbsp,

[Docs Request] add web demo

This will be useful in the future for bug hunters to be able to create simple reproducible examples of unexpected behavior in rustle.

Fix boolean_attributes.rs

pub const boolean_attributes: HashSet<&str> = HashSet::from([
    "allowfullscreen",
    "allowpaymentrequest",
    "async",
    "autofocus",
    "autoplay",
    "checked",
    "controls",
    "default",
    "defer",
    "disabled",
    "formnovalidate",
    "hidden",
    "ismap",
    "loop",
    "multiple",
    "muted",
    "nomodule",
    "novalidate",
    "open",
    "playsinline",
    "readonly",
    "required",
    "reversed",
    "selected",
]);

causes the error

cannot call non-const fn `<HashSet<&str> as From<[&str; 24]>>::from` in constants
calls in constants are limited to constant functions, tuple structs and tuple variants

My suggestion for a fix is to make boolean_attributes a static

src/compiler/parse/index.ts check

If anybody wants to check out the compiler::parse::index::Parser struct and impl and possibly write some tests if everything works as it should.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.