Crate swc[−][src]
Expand description
The main crate of the swc project.
Cutomizing
This is documentation for building custom build tools on top of swc.
Dependency version management
swc
has swc_emcascript and swc_css, which re-exports required modules.
Teating
See [testing] and swc_ecmc_transform_testing.
Custom javascript transforms
What is JsWord?
It’s basically an interned string. See swc_atoms.
Choosing between JsWord vs String
You should prefer JsWord over String if it’s going to be stored in an AST node.
See swc_atoms for detailed description.
Fold vs VisitMut vs
See swc_visit for detailed description.
Variable management (Scoping)
See swc_ecma_transforms_base::resolver::resolver_with_mark.
Comparing two identifiers
See swc_ecma_utils::Id. You can use [swc_ecma_utils::IdentLike::to_id] to extract important parts of an swc_ecma_ast::Ident.
Creating a unique identifier
See swc_ecma_utils::private_ident.
Prepending statements
If you want to prepend statements to the beginning of a file, you can use
swc_ecma_utils::prepend_stmts or swc_ecma_utils::prepend if len == 1
.
These methods are aware of the fact that "use strict"
directive should be
first in a file, and insert statements after directives.
Improving readability
Each stuffs are documented at itself.
-
If you are creating or binding an swc_ecma_ast::Expr with operator, you can use swc_ecma_ast::op.
-
If you want to create swc_ecma_ast::CallExpr, you can use swc_ecma_utils::ExprFactory::as_callee to create
callee
. -
If you want to create swc_ecma_ast::CallExpr or swc_ecma_ast::NewExpr, you can use swc_ecma_utils::ExprFactory::as_arg to create arguments.
-
If you want to create swc_ecma_ast::MemberExpr where all identifiers are static (e.g.
Object.prototype.hasOwnProperty
), you can use swc_ecma_utils::member_expr. -
If you want to create swc_ecma_ast::MemberExpr, you can use swc_ecma_utils::ExprFactory::as_obj to create object field.
Re-exports
pub extern crate swc_atoms as atoms;
pub extern crate swc_common as common;
pub extern crate swc_ecmascript as ecmascript;
pub use sourcemap;
Modules
Structs
All methods accept Handler, which is a storage for errors.
Builder is used to create a high performance Compiler
.
Multi-threaded implementation of Comments