Skip to content

Releases: rusty-ecma/resast

v0.6.0-alpha.5

12 Jun 18:51
5811733
Compare
Choose a tag to compare
v0.6.0-alpha.5 Pre-release
Pre-release
  • Remove SourceText wrapper around T in favor of just T
  • Define/implement IntoAllocated to convert Node into Node
  • remove the old esprima feature
  • Fix a misalignment with the serde and serialization feature moving all to serde
  • Add clippy and fmt checks to CI

v0.6.0-alpha.3: Merge pull request #10 from rusty-ecma/fix/import_all_as

03 Jun 21:02
034fa3b
Compare
Choose a tag to compare

Changes

  • NamespaceImportSpec::keyword was incorrectly set to From when it should be As

v0.6.0-alpha.2

03 Jun 15:31
Compare
Choose a tag to compare
v0.6.0-alpha.2 Pre-release
Pre-release

Changes

  • Smaller AST
    • The main goal of this release was to reduce the overall size of the spanned AST nodes. To achieve this a few optimizations were made
      • All constant size tokens were converted from being represented as a Slice to now only being represented as a Position marking the start of that token. The end can easily be calculated since the token is a constant size.
      • The requirement to use Cow<str> has been removed and now the AST nodes are generic over any T.
      • The source property of a Slice is now represented by a SourceText new type wrapper around T, helpers have been provided for this type with T of &str, String and Cow<str>.
    • To make these changes slightly easier to manage, all the conversion from spanned to non-spanned nodes was moved to its own module resast::spanned::convert
    • Nodes with duplicated data were re-structured to reduce that duplication
      • NormalImportSpec and ExportSpecifier, now has an Option for the local value which was renamed alias
      • TemplateElement is no longer represented as both cooked and raw but instead matches the StringLit pattern, that is the properties open_quote, close_quote, content
      • RegEx::flags is now an Option
    • Position was updated to hold u32 values instead of usize meaning any 64 bit architectures should see this type reduced to half its previous size.
    • A new spanned::Boolean is provided instead of spanned::Lit::Boolean holding a Slice
    • A new module was added containing new-type wrappers around Position for all fixed-sized nodes called spanned::tokens
      • These new types implement a new trait Token that provides an interface to get the &'static str for the token along with the start and end Position values. Any type that implements Token should also implement Node

0.5.0

09 Sep 13:57
Compare
Choose a tag to compare

This release fixes a few bugs in the structure of the module import and export nodes. This also introduces a spanned module which requires the user to provide a human friendly start and end position for each element of each node. For example, an empty object literal would now be defined as below.

Expr::Obj(ObjExpr {
    open_brace: Slice {
        source: Cow::Borrowed("{"),
        loc: SourceLocation {
            start: Position { line: 1, column: 1 },
            end: Position { line: 1, column: 2 },
        },
    },
    props: Vec::new(),
    close_brace: Slice {
        source: Cow::Borrowed("}"),
        loc: SourceLocation {
            start: Position { line: 1, column: 2 },
            end: Position { line: 1, column: 3 },
        },
    },
});

While that is pretty verbose, it provides all of the context needed for performing things like source maps with 100% accuracy.

This release also introduces the Node trait which has 2 methods, loc which will provide the SourceLocation and also source for accessing the string slice for that node. Using the above Expr we can see how this can see how this could be useful.

let obj = Expr::Obj(/*see above*/);
let full_loc = obj.loc();
assert_eq!(full_loc.start.line, 1);
assert_eq!(full_loc.start.column, 1);
assert_eq!(full_loc.end.line, 1);
assert_eq!(full_loc.end.column, 2);
if let Expr::Obj(inner) = &obj {
    let start_loc = inner.open_brace.loc();
    assert_eq!(start_loc.start, full_loc.start);
    let end_loc = inner.close_brace.loc();
    assert_eq!(end_loc.end, full_loc.end);
}