-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more tests about
v-on
handler
- Loading branch information
1 parent
aeecf3a
commit 1615463
Showing
6 changed files
with
263 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
mod js_stringify; | ||
pub mod parser; | ||
|
||
pub use js_stringify::to_str; | ||
use swc_core::common::{sync::Lrc, SourceMap}; | ||
use swc_core::ecma::ast::Expr; | ||
use swc_ecma_codegen::{text_writer::JsWriter, Emitter, Node}; | ||
|
||
use self::parser::{parse_javascript_expr, parse_typescript_expr}; | ||
|
||
pub fn js(raw: &str) -> Box<Expr> { | ||
parse_javascript_expr(raw, 0, Default::default()).unwrap().0 | ||
} | ||
|
||
pub fn ts(raw: &str) -> Box<Expr> { | ||
parse_typescript_expr(raw, 0, Default::default()).unwrap().0 | ||
} | ||
|
||
pub fn to_str(swc_node: &impl Node) -> String { | ||
// Emitting the result requires some setup with SWC | ||
let cm: Lrc<SourceMap> = Default::default(); | ||
let mut buff: Vec<u8> = Vec::with_capacity(128); | ||
let writer: JsWriter<&mut Vec<u8>> = JsWriter::new(cm.clone(), "\n", &mut buff, None); | ||
|
||
let mut emitter_cfg = swc_ecma_codegen::Config::default(); | ||
emitter_cfg.minify = true; | ||
|
||
let mut emitter = Emitter { | ||
cfg: emitter_cfg, | ||
comments: None, | ||
wr: writer, | ||
cm, | ||
}; | ||
|
||
let _ = swc_node.emit_with(&mut emitter); | ||
|
||
String::from_utf8(buff).unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters