Releases: rusty-ecma/resast
Releases · rusty-ecma/resast
v0.6.0-alpha.5
- Remove
SourceText
wrapper aroundT
in favor of justT
- Define/implement
IntoAllocated
to convert Node into Node - remove the old esprima feature
- Fix a misalignment with the
serde
andserialization
feature moving all toserde
- Add clippy and fmt checks to CI
v0.6.0-alpha.3: Merge pull request #10 from rusty-ecma/fix/import_all_as
Changes
NamespaceImportSpec::keyword
was incorrectly set toFrom
when it should beAs
v0.6.0-alpha.2
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 aPosition
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 anyT
. - The
source
property of aSlice
is now represented by aSourceText
new type wrapper aroundT
, helpers have been provided for this type withT
of&str
,String
andCow<str>
.
- All constant size tokens were converted from being represented as a
- 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
andExportSpecifier
, now has anOption
for the local value which was renamedalias
TemplateElement
is no longer represented as bothcooked
andraw
but instead matches theStringLit
pattern, that is the propertiesopen_quote
,close_quote
,content
RegEx::flags
is now anOption
- Position was updated to hold
u32
values instead ofusize
meaning any 64 bit architectures should see this type reduced to half its previous size. - A new
spanned::Boolean
is provided instead ofspanned::Lit::Boolean
holding aSlice
- 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 endPosition
values. Any type that implementsToken
should also implementNode
- These new types implement a new trait
- 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
0.5.0
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);
}