file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-object-spread/output.mjs
JavaScript
a = { b: b, ...c };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-old-core-js/input.mjs
JavaScript
"asad".at();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-old-core-js/output.mjs
JavaScript
"asad".at();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-all/input.mjs
JavaScript
var p = Promise.resolve(0); Promise.all([p]).then((outcome) => { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-all/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.promise.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/web.dom-collections.iterator.js"; var p = Promise.resolve(0); Promise.all([ p ]).then(function(outcome) { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-finally/input.mjs
JavaScript
var p = Promise.resolve(0); p.finally(() => { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-finally/output.mjs
JavaScript
import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.promise.finally.js"; import "core-js/modules/es.promise.js"; var p = Promise.resolve(0); p.finally(function() { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-race/input.mjs
JavaScript
var p = Promise.resolve(0); Promise.race([p]).then((outcome) => { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-promise-race/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.promise.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/web.dom-collections.iterator.js"; var p = Promise.resolve(0); Promise.race([ p ]).then(function(outcome) { alert("OK"); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-regexp/input.mjs
JavaScript
const a = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/u; const b = /./s; const c = /./imsuy; console.log(a.unicode); console.log(b.dotAll); console.log(c.sticky); console.log(c.ignoreCase);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-regexp/output.mjs
JavaScript
import "core-js/modules/es.regexp.constructor.js"; import "core-js/modules/es.regexp.exec.js"; import "core-js/modules/es.regexp.to-string.js"; var a = RegExp("(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})", "u"); var b = RegExp(".", "s"); var c = RegExp(".", "imsuy"); console.log(a.unicode); console.log(b.dotAll); console.log(c.sticky); console.log(c.ignoreCase);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-source-type-script-query/input.js
JavaScript
require("foo"); const x = new Promise((resolve) => { const p = []; if (p.includes("a")) { } });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-source-type-script-query/output.js
JavaScript
require("core-js/modules/es.array.includes"); require("core-js/modules/es.object.to-string"); require("core-js/modules/es.promise"); require("foo"); var x = new Promise(function (resolve) { var p = []; if (p.includes("a")) {} });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-source-type-script/input.js
JavaScript
require("foo"); const x = new Promise((resolve) => { const p = []; if (p.includes("a")) { } });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-source-type-script/output.js
JavaScript
require("core-js/modules/es.array.includes"); require("core-js/modules/es.object.to-string"); require("core-js/modules/es.promise"); require("foo"); var x = new Promise(function (resolve) { var p = []; if (p.includes("a")) {} });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-spread/input.mjs
JavaScript
a = [b, ...c];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-spread/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/web.dom-collections.iterator.js"; a = [ b, ...c ];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-static-methods-native-support/input.mjs
JavaScript
Object.keys(foo); const getOwnPropertySymbols = Object.getOwnPropertySymbols; const { assign } = Object; "defineProperty" in Object;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-static-methods-native-support/output.mjs
JavaScript
Object.keys(foo); const getOwnPropertySymbols = Object.getOwnPropertySymbols; const { assign } = Object; "defineProperty" in Object;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-static-methods/input.mjs
JavaScript
Object.keys(foo); const getOwnPropertySymbols = Object.getOwnPropertySymbols; const { assign } = Object; "defineProperty" in Object;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-static-methods/output.mjs
JavaScript
import "core-js/modules/es.object.assign.js"; import "core-js/modules/es.object.define-property.js"; import "core-js/modules/es.object.keys.js"; import "core-js/modules/es.symbol.js"; Object.keys(foo); var getOwnPropertySymbols = Object.getOwnPropertySymbols; var { assign } = Object; "defineProperty" in Object;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-symbol-iterator-in/input.mjs
JavaScript
Symbol.iterator in arr;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-symbol-iterator-in/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/es.symbol.description.js"; import "core-js/modules/es.symbol.iterator.js"; import "core-js/modules/es.symbol.js"; import "core-js/modules/web.dom-collections.iterator.js"; Symbol.iterator in arr;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-symbol-iterator/input.mjs
JavaScript
arr[Symbol.iterator]();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-symbol-iterator/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.string.iterator.js"; import "core-js/modules/es.symbol.description.js"; import "core-js/modules/es.symbol.iterator.js"; import "core-js/modules/es.symbol.js"; import "core-js/modules/web.dom-collections.iterator.js"; arr[Symbol.iterator]();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-timers/input.mjs
JavaScript
Promise.resolve().then((it) => { setTimeout(foo, 1, 2); setInterval(foo, 1, 2); setImmediate(foo, 1, 2); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-timers/output.mjs
JavaScript
import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.promise.js"; import "core-js/modules/web.immediate.js"; import "core-js/modules/web.timers.js"; Promise.resolve().then(function(it) { setTimeout(foo, 1, 2); setInterval(foo, 1, 2); setImmediate(foo, 1, 2); });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array-edge-13/input.mjs
JavaScript
new Int8Array(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array-edge-13/output.mjs
JavaScript
import "core-js/modules/es.array-buffer.constructor.js"; import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.fill.js"; import "core-js/modules/es.typed-array.includes.js"; import "core-js/modules/es.typed-array.int8-array.js"; import "core-js/modules/es.typed-array.set.js"; import "core-js/modules/es.typed-array.sort.js"; import "core-js/modules/es.typed-array.to-locale-string.js"; new Int8Array(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array-static/input.mjs
JavaScript
Int8Array.of();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array-static/output.mjs
JavaScript
import "core-js/modules/es.array-buffer.constructor.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.data-view.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; import "core-js/modules/es.typed-array.filter.js"; import "core-js/modules/es.typed-array.find-index.js"; import "core-js/modules/es.typed-array.find.js"; import "core-js/modules/es.typed-array.for-each.js"; import "core-js/modules/es.typed-array.includes.js"; import "core-js/modules/es.typed-array.index-of.js"; import "core-js/modules/es.typed-array.int8-array.js"; import "core-js/modules/es.typed-array.iterator.js"; import "core-js/modules/es.typed-array.join.js"; import "core-js/modules/es.typed-array.last-index-of.js"; import "core-js/modules/es.typed-array.map.js"; import "core-js/modules/es.typed-array.of.js"; import "core-js/modules/es.typed-array.reduce-right.js"; import "core-js/modules/es.typed-array.reduce.js"; import "core-js/modules/es.typed-array.reverse.js"; import "core-js/modules/es.typed-array.set.js"; import "core-js/modules/es.typed-array.slice.js"; import "core-js/modules/es.typed-array.some.js"; import "core-js/modules/es.typed-array.sort.js"; import "core-js/modules/es.typed-array.subarray.js"; import "core-js/modules/es.typed-array.to-locale-string.js"; import "core-js/modules/es.typed-array.to-string.js"; Int8Array.of();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array/input.mjs
JavaScript
new Int8Array(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-typed-array/output.mjs
JavaScript
import "core-js/modules/es.array-buffer.constructor.js"; import "core-js/modules/es.array-buffer.slice.js"; import "core-js/modules/es.array.iterator.js"; import "core-js/modules/es.data-view.js"; import "core-js/modules/es.object.to-string.js"; import "core-js/modules/es.typed-array.copy-within.js"; import "core-js/modules/es.typed-array.every.js"; import "core-js/modules/es.typed-array.fill.js"; import "core-js/modules/es.typed-array.filter.js"; import "core-js/modules/es.typed-array.find-index.js"; import "core-js/modules/es.typed-array.find.js"; import "core-js/modules/es.typed-array.for-each.js"; import "core-js/modules/es.typed-array.includes.js"; import "core-js/modules/es.typed-array.index-of.js"; import "core-js/modules/es.typed-array.int8-array.js"; import "core-js/modules/es.typed-array.iterator.js"; import "core-js/modules/es.typed-array.join.js"; import "core-js/modules/es.typed-array.last-index-of.js"; import "core-js/modules/es.typed-array.map.js"; import "core-js/modules/es.typed-array.reduce-right.js"; import "core-js/modules/es.typed-array.reduce.js"; import "core-js/modules/es.typed-array.reverse.js"; import "core-js/modules/es.typed-array.set.js"; import "core-js/modules/es.typed-array.slice.js"; import "core-js/modules/es.typed-array.some.js"; import "core-js/modules/es.typed-array.sort.js"; import "core-js/modules/es.typed-array.subarray.js"; import "core-js/modules/es.typed-array.to-locale-string.js"; import "core-js/modules/es.typed-array.to-string.js"; new Int8Array(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-yield-non-star/input.mjs
JavaScript
function* a() { yield 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-yield-non-star/output.mjs
JavaScript
function* a() { yield 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-yield-star/input.mjs
JavaScript
function* a() { yield* 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/corejs3/usage-yield-star/output.mjs
JavaScript
import "core-js/modules/es.array.iterator.js"; import "core-js/modules/web.dom-collections.iterator.js"; function* a() { yield* 1; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/input.mjs
JavaScript
class A { static { this.abc = 123; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/transform/static-block/output.mjs
JavaScript
class A { } A.abc = 123;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/input.mjs
JavaScript
class A { static { this.abc = 123; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/fixtures/transform/tp-version/output.mjs
JavaScript
class A { } A.abc = 123;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_preset_env/tests/test.rs
Rust
#![allow(dead_code)] use std::{ cmp::Ordering, env, fs::File, io, io::Read, path::{Path, PathBuf}, }; use pretty_assertions::assert_eq; use rustc_hash::FxHashMap; use serde::Deserialize; use serde_json::Value; use swc_common::{ comments::SingleThreadedComments, errors::HANDLER, input::StringInput, FromVariant, Mark, }; use swc_ecma_ast::*; use swc_ecma_codegen::Emitter; use swc_ecma_parser::{Parser, Syntax}; use swc_ecma_preset_env::{preset_env, Config, FeatureOrModule, Mode, Targets, Version}; use swc_ecma_transforms::{fixer, helpers}; use swc_ecma_utils::drop_span; use swc_ecma_visit::{visit_mut_pass, VisitMut}; use testing::{NormalizedOutput, Tester}; /// options.json file #[derive(Debug, Deserialize)] struct BabelOptions { presets: Vec<(String, PresetConfig)>, } #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] struct PresetConfig { #[serde(default)] pub use_built_ins: UseBuiltIns, #[serde(default)] pub corejs: CoreJs, #[serde(default)] pub modules: ModulesConfig, #[serde(default)] pub targets: Option<Targets>, #[serde(default)] pub include: Vec<FeatureOrModule>, #[serde(default)] pub exclude: Vec<FeatureOrModule>, #[serde(default)] pub force_all_transforms: bool, #[serde(default)] pub shipped_proposals: bool, #[serde(default)] pub config_path: String, #[serde(default)] pub debug: bool, } #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] #[serde(untagged)] pub enum CoreJs { Ver(Version), Val(FxHashMap<String, Value>), } impl Default for CoreJs { fn default() -> Self { Self::Ver(Version { major: 2, minor: 0, patch: 0, }) } } #[derive(Debug, Deserialize)] #[serde(untagged)] enum ModulesConfig { Bool(bool), } impl Default for ModulesConfig { fn default() -> Self { ModulesConfig::Bool(false) } } #[derive(Debug, Deserialize)] #[serde(untagged)] enum UseBuiltIns { Bool(bool), Str(String), } impl Default for UseBuiltIns { fn default() -> Self { UseBuiltIns::Bool(false) } } #[derive(Debug, FromVariant)] enum Error { Io(io::Error), Var(env::VarError), Json(serde_json::Error), Msg(String), } fn exec(c: PresetConfig, dir: PathBuf) -> Result<(), Error> { println!("Config: {:?}", c); Tester::new() .print_errors(|cm, handler| { let pass = ( preset_env( Mark::fresh(Mark::root()), Some(SingleThreadedComments::default()), Config { debug: c.debug, mode: match c.use_built_ins { UseBuiltIns::Bool(false) => None, UseBuiltIns::Str(ref s) if s == "usage" => Some(Mode::Usage), UseBuiltIns::Str(ref s) if s == "entry" => Some(Mode::Entry), v => unreachable!("invalid: {:?}", v), }, skip: Vec::new(), loose: true, // TODO dynamic_import: true, bugfixes: false, include: c.include, exclude: c.exclude, core_js: match c.corejs { CoreJs::Ver(v) => Some(v), ref s => unimplemented!("Unknown core js version: {:?}", s), }, force_all_transforms: c.force_all_transforms, shipped_proposals: c.shipped_proposals, targets: c.targets, path: std::env::current_dir().unwrap(), }, Default::default(), &mut Default::default(), ), fixer(None), ); let print = |m: &Program| { let mut buf = Vec::new(); { let mut emitter = Emitter { cfg: swc_ecma_codegen::Config::default(), comments: None, cm: cm.clone(), wr: Box::new(swc_ecma_codegen::text_writer::JsWriter::new( cm.clone(), "\n", &mut buf, None, )), }; emitter.emit_program(m).expect("failed to emit module"); } String::from_utf8(buf).expect("invalid utf8 character detected") }; let fm = cm .load_file(&dir.join("input.mjs")) .expect("failed to load file"); let mut p = Parser::new( Syntax::Es(Default::default()), StringInput::from(&*fm), None, ); let module = p .parse_module() .map_err(|e| e.into_diagnostic(&handler).emit())?; for e in p.take_errors() { e.into_diagnostic(&handler).emit() } let actual = helpers::HELPERS.set(&Default::default(), || { HANDLER.set(&handler, || Program::Module(module).apply(pass)) }); // debug mode? if dir.join("stdout.txt").exists() { let mut out = read(&dir.join("stdout.txt")); if dir.join("stderr.txt").exists() { out.push_str("\n\n"); out.push_str(&read(&dir.join("stderr.txt"))); } return Ok(()); }; let actual_src = print(&actual); if env::var("UPDATE").is_ok() { NormalizedOutput::from(actual_src.clone()) .compare_to_file(dir.join("output.mjs")) .unwrap(); } // It's normal transform test. let expected = { let fm = cm .load_file(&dir.join("output.mjs")) .expect("failed to load output file"); let mut p = Parser::new( Syntax::Es(Default::default()), StringInput::from(&*fm), None, ); let mut m = p .parse_module() .map_err(|e| e.into_diagnostic(&handler).emit())?; for e in p.take_errors() { e.into_diagnostic(&handler).emit() } m.body.sort_by(|a, b| match *a { ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { ref specifiers, ref src, .. })) if specifiers.is_empty() && src.value.starts_with("core-js/modules") => { match *b { ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { specifiers: ref rs, src: ref rsrc, .. })) if rs.is_empty() && rsrc.value.starts_with("core-js/modules") => { src.value.cmp(&rsrc.value) } _ => Ordering::Equal, } } _ => Ordering::Equal, }); Program::Module(m) }; let expected_src = print(&expected); if drop_span(actual.apply(&mut visit_mut_pass(Normalizer))) == drop_span(expected.apply(&mut visit_mut_pass(Normalizer))) { return Ok(()); } if actual_src != expected_src { panic!( r#"assertion failed: `(left == right)` {}"#, ::testing::diff(&actual_src, &expected_src), ); } Ok(()) }) .expect("failed to execute"); Ok(()) } fn read(p: &Path) -> String { let mut buf = String::new(); let mut f = File::open(p).expect("failed to open file"); f.read_to_string(&mut buf).expect("failed to read file"); buf } #[testing::fixture("tests/fixtures/**/input.mjs")] fn fixture(input: PathBuf) { let entry_dir = input.parent().unwrap().to_path_buf(); println!("File: {}", entry_dir.display()); let cfg: BabelOptions = serde_json::from_reader(File::open(entry_dir.join("options.json")).unwrap()) .map_err(|err| Error::Msg(format!("failed to parse options.json: {}", err))) .unwrap(); assert_eq!(cfg.presets.len(), 1); let cfg = cfg.presets.into_iter().map(|v| v.1).next().unwrap(); exec(cfg, entry_dir).expect("failed to run test") } struct Normalizer; impl VisitMut for Normalizer {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote/src/clone.rs
Rust
//! Module for implicitly copyable types. /// Noop pub trait ImplicitClone: Clone { fn clone_quote_var(&self) -> Self { self.clone() } } impl<T: Clone> ImplicitClone for T {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote/src/lib.rs
Rust
/// Not a public API. #[doc(hidden)] pub extern crate swc_common; /// Not a public API. #[doc(hidden)] pub extern crate swc_ecma_ast; /// Not a public API. #[doc(hidden)] pub extern crate swc_ecma_quote_macros; #[doc(hidden)] pub use self::clone::ImplicitClone; mod clone; /// # Supported output types /// /// - `Expr` /// - `Pat` /// - `AssignTarget` /// - `Stmt` /// - `ModuleItem` /// /// - Option<T> where T is supported type /// - Box<T> where T is supported type /// /// For example, `Box<Expr>` and `Option<Box<Expr>>` are supported. /// /// # Variable substitution /// /// If an identifier starts with `$`, it is substituted with the value of the /// parameter passed. /// /// e.g. /// /// ```rust /// use swc_common::DUMMY_SP; /// use swc_ecma_ast::Ident; /// use swc_ecma_quote::quote; /// /// // This will return ast for `const ref = 4;` /// let _stmt = quote!("const $name = 4;" as Stmt, name = Ident::new("ref".into(), DUMMY_SP)); /// /// // Tip: Use private_ident!("ref") for real identifiers. /// ``` /// /// ## Typed variables /// /// As this macro generates static AST, it can't substitute variables if an /// identifier is not allowed in such position. In other words, this macro only /// supports substituting /// /// - [swc_ecma_ast::Ident] /// - [swc_ecma_ast::Expr] /// - [swc_ecma_ast::Pat] /// - [swc_ecma_ast::Str] /// /// You can use it like /// /// ```rust /// use swc_common::DUMMY_SP; /// use swc_ecma_ast::Ident; /// use swc_ecma_quote::quote; /// /// // This will return ast for `const ref = 4;` /// let _stmt = quote!( /// "const $name = $val;" as Stmt, /// name = Ident::new("ref".into(), DUMMY_SP), /// val: Expr = 4.into(), /// ); /// ``` /// /// # Examples /// /// ## Quote a variable declaration /// ```rust /// use swc_common::DUMMY_SP; /// use swc_ecma_ast::Ident; /// use swc_ecma_quote::quote; /// /// // This will return ast for `const ref = 4;` /// let _stmt = quote!("const $name = 4;" as Stmt, name = /// Ident::new("ref".into(), DUMMY_SP)); /// /// // Tip: Use private_ident!("ref") for real identifiers. /// ``` /// /// ## Using `Str` /// /// The grammar is `"$var_name"`. /// /// ```rust /// use swc_common::DUMMY_SP; /// use swc_ecma_ast::Str; /// use swc_ecma_quote::quote; /// /// // This will return ast for `import thing from "foo";` /// let _stmt = quote!( /// "import thing from \"$thing\";" as ModuleItem, /// thing: Str = "foo".into(), /// ); /// ``` #[macro_export] macro_rules! quote { ($($tt:tt)*) => {{ $crate::swc_ecma_quote_macros::internal_quote!($($tt)*) }}; } /// Creates a `Box<Expr>` from the source code. /// /// This is an alias for [quote], but without `as Box<Expr>`. #[macro_export] macro_rules! quote_expr { ($src:tt) => {{ $crate::quote!($src as Box<Expr>) }}; ($src:tt, $($tt2:tt)*) => {{ $crate::quote!($src as Box<Expr>, $($tt2)*) }}; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/class.rs
Rust
use swc_ecma_ast::*; impl_struct!( Class, [ span, ctxt, decorators, body, super_class, is_abstract, type_params, super_type_params, implements ] ); impl_struct!( Constructor, [span, ctxt, key, params, body, accessibility, is_optional] ); impl_struct!( ClassMethod, [ span, key, function, kind, is_static, accessibility, is_abstract, is_optional, is_override ] ); impl_struct!( PrivateMethod, [ span, key, function, kind, is_static, accessibility, is_abstract, is_optional, is_override ] ); impl_struct!( ClassProp, [ span, key, value, type_ann, is_static, decorators, accessibility, is_abstract, is_optional, is_override, readonly, declare, definite ] ); impl_struct!(StaticBlock, [span, body]); impl_struct!( AutoAccessor, [ span, is_abstract, is_override, definite, key, value, type_ann, is_static, decorators, accessibility ] );
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/decl.rs
Rust
use swc_ecma_ast::*; impl_enum!( Decl, [ Class, Fn, Var, TsInterface, TsTypeAlias, TsEnum, TsModule, Using ] ); impl_struct!(ClassDecl, [ident, declare, class]); impl_struct!(FnDecl, [ident, declare, function]); impl_struct!(VarDecl, [span, ctxt, kind, declare, decls]); impl_struct!(VarDeclarator, [span, name, init, definite]); impl_struct!(UsingDecl, [span, is_await, decls]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/enums.rs
Rust
use swc_ecma_ast::*; use syn::parse_quote; macro_rules! impl_simple_enum { ($E:ident, [ $($v:ident),* ]) => { impl crate::ast::ToCode for $E { fn to_code(&self, _: &crate::ctxt::Ctx) -> syn::Expr { match self { $( $E::$v => parse_quote!( swc_core::ecma::ast::$E::$v ), )* } } } }; } impl_simple_enum!(VarDeclKind, [Var, Const, Let]); impl_simple_enum!(UnaryOp, [Minus, Plus, Bang, Tilde, TypeOf, Void, Delete]); impl_simple_enum!(UpdateOp, [PlusPlus, MinusMinus]); impl_simple_enum!( AssignOp, [ Assign, AddAssign, SubAssign, MulAssign, DivAssign, ModAssign, LShiftAssign, RShiftAssign, ZeroFillRShiftAssign, BitOrAssign, BitXorAssign, BitAndAssign, ExpAssign, AndAssign, OrAssign, NullishAssign ] ); impl_simple_enum!( BinaryOp, [ EqEq, NotEq, EqEqEq, NotEqEq, Lt, LtEq, Gt, GtEq, LShift, RShift, ZeroFillRShift, Add, Sub, Mul, Div, Mod, BitOr, BitXor, BitAnd, LogicalOr, LogicalAnd, In, InstanceOf, Exp, NullishCoalescing ] ); impl_simple_enum!(Accessibility, [Public, Protected, Private]); impl_simple_enum!(MethodKind, [Method, Getter, Setter]); impl_simple_enum!(MetaPropKind, [NewTarget, ImportMeta]); impl_simple_enum!(ImportPhase, [Defer, Source, Evaluation]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/expr.rs
Rust
use swc_ecma_ast::*; impl_enum!(AssignTarget, [Simple, Pat], true); impl_enum!( SimpleAssignTarget, [ Ident, Member, SuperProp, Paren, OptChain, TsAs, TsNonNull, TsSatisfies, TsTypeAssertion, TsInstantiation, Invalid ] ); impl_enum!(AssignTargetPat, [Array, Object, Invalid]); impl_enum!( Expr, [ This, Array, Object, Fn, Unary, Update, Bin, Assign, Member, SuperProp, Cond, Call, New, Seq, Ident, Lit, Tpl, TaggedTpl, Arrow, Class, Yield, MetaProp, Await, Paren, JSXMember, JSXNamespacedName, JSXEmpty, JSXElement, JSXFragment, TsTypeAssertion, TsConstAssertion, TsNonNull, TsAs, TsInstantiation, TsSatisfies, PrivateName, OptChain, Invalid ], true ); impl_struct!(ThisExpr, [span]); impl_struct!(ArrayLit, [span, elems]); impl_struct!(ObjectLit, [span, props]); impl_struct!(FnExpr, [ident, function]); impl_struct!( ArrowExpr, [ span, ctxt, params, body, is_async, is_generator, type_params, return_type ] ); impl_struct!(ClassExpr, [ident, class]); impl_struct!(Tpl, [span, exprs, quasis]); impl_struct!(UnaryExpr, [span, op, arg]); impl_struct!(UpdateExpr, [span, op, prefix, arg]); impl_struct!(BinExpr, [span, op, left, right]); impl_struct!(AssignExpr, [span, op, left, right]); impl_struct!(MemberExpr, [span, obj, prop]); impl_struct!(SuperPropExpr, [span, obj, prop]); impl_struct!(CondExpr, [span, test, cons, alt]); impl_struct!(CallExpr, [span, ctxt, callee, args, type_args]); impl_struct!(ExprOrSpread, [spread, expr]); impl_struct!(Super, [span]); impl_struct!(Import, [span, phase]); impl_struct!(NewExpr, [span, ctxt, callee, args, type_args]); impl_struct!(SeqExpr, [span, exprs]); impl_struct!(TaggedTpl, [span, ctxt, tag, type_params, tpl]); impl_struct!(YieldExpr, [span, arg, delegate]); impl_struct!(MetaPropExpr, [span, kind]); impl_struct!(AwaitExpr, [span, arg]); impl_struct!(JSXMemberExpr, [span, obj, prop]); impl_struct!(JSXNamespacedName, [span, ns, name]); impl_struct!(JSXEmptyExpr, [span]); impl_struct!(JSXElement, [span, opening, closing, children]); impl_struct!(JSXFragment, [span, opening, closing, children]); impl_struct!(OptChainExpr, [span, optional, base]); impl_struct!(ParenExpr, [span, expr]); impl_struct!( Function, [ ctxt, params, decorators, span, body, is_generator, is_async, type_params, return_type ] ); impl_struct!(Decorator, [span, expr]); impl_struct!(TplElement, [span, tail, cooked, raw]); impl_struct!( JSXOpeningElement, [name, span, attrs, self_closing, type_args] ); impl_struct!(JSXClosingElement, [name, span]); impl_struct!(JSXOpeningFragment, [span]); impl_struct!(JSXClosingFragment, [span]); impl_struct!(SpreadElement, [dot3_token, expr]); impl_struct!(JSXExprContainer, [span, expr]); impl_struct!(JSXSpreadChild, [span, expr]); impl_struct!(JSXAttr, [span, name, value]); impl_enum!( JSXAttrValue, [Lit, JSXExprContainer, JSXElement, JSXFragment] ); impl_enum!(JSXAttrName, [Ident, JSXNamespacedName]); impl_enum!(JSXExpr, [Expr, JSXEmptyExpr]); impl_struct!(OptCall, [span, ctxt, callee, args, type_args]); impl_enum!(Callee, [Super, Import, Expr]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/id.rs
Rust
use swc_ecma_ast::*; use syn::parse_quote; use super::ToCode; use crate::ctxt::Ctx; impl ToCode for swc_ecma_ast::Ident { fn to_code(&self, cx: &Ctx) -> syn::Expr { if let Some(var_name) = self.sym.strip_prefix('$') { if let Some(var) = cx.var(crate::ctxt::VarPos::Ident, var_name) { return var.get_expr(); } } let sym_value = self.sym.to_code(cx); parse_quote!(swc_core::ecma::ast::Ident::new_no_ctxt( #sym_value, swc_core::common::DUMMY_SP, )) } } impl_struct!(IdentName, [span, sym]); impl_struct!(PrivateName, [span, name]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/lit.rs
Rust
use proc_macro2::Span; use swc_atoms::Atom; use swc_ecma_ast::*; use syn::{parse_quote, ExprLit, LitBool, LitFloat}; use super::ToCode; use crate::{builder::Builder, ctxt::Ctx}; fail_todo!(BigInt); fail_todo!(JSXText); impl ToCode for Str { fn to_code(&self, cx: &crate::ctxt::Ctx) -> syn::Expr { if let Some(var_name) = self.value.strip_prefix('$') { if let Some(var) = cx.var(crate::ctxt::VarPos::Str, var_name) { return var.get_expr(); } } let mut builder = Builder::new("Str"); builder.add("span", ToCode::to_code(&self.span, cx)); builder.add("value", ToCode::to_code(&self.value, cx)); builder.add("raw", ToCode::to_code(&self.raw, cx)); syn::Expr::Struct(builder.build()) } } impl_struct!(Bool, [span, value]); impl_struct!(Null, [span]); impl_struct!(Number, [span, value, raw]); impl_struct!(Regex, [span, exp, flags]); impl ToCode for Atom { fn to_code(&self, _: &Ctx) -> syn::Expr { let val = &**self; parse_quote!(swc_core::atoms::atom!(#val)) } } impl ToCode for bool { fn to_code(&self, _: &Ctx) -> syn::Expr { syn::Expr::Lit(ExprLit { attrs: Default::default(), lit: syn::Lit::Bool(LitBool::new(*self, Span::call_site())), }) } } impl ToCode for f64 { fn to_code(&self, _: &Ctx) -> syn::Expr { syn::Expr::Lit(ExprLit { attrs: Default::default(), lit: syn::Lit::Float(LitFloat::new(&format!("{}f64", self), Span::call_site())), }) } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/mod.rs
Rust
use swc_common::{Span, SyntaxContext}; use swc_ecma_ast::*; use syn::{parse_quote, ExprBlock}; use crate::ctxt::Ctx; macro_rules! fail_todo { ($T:ty) => { impl crate::ast::ToCode for $T { fn to_code(&self, _: &crate::ctxt::Ctx) -> syn::Expr { todo!("ToCode for {}", stringify!($T)) } } }; } macro_rules! impl_enum_body { ($E:ident, $s:expr, $cx:expr,[ $($v:ident),* ]) => { match $s { $( $E::$v(inner) => { let val = crate::ast::ToCode::to_code(inner, $cx); syn::parse_quote!( swc_core::ecma::ast::$E::$v(#val) ) }, )* } }; } macro_rules! impl_enum { ($E:ident, [ $($v:ident),* ]) => { impl crate::ast::ToCode for $E { fn to_code(&self, cx: &crate::ctxt::Ctx) -> syn::Expr { impl_enum_body!($E, self, cx, [ $($v),* ]) } } }; ($E:ident, [ $($v:ident),* ], true) => { impl crate::ast::ToCode for $E { fn to_code(&self, cx: &crate::ctxt::Ctx) -> syn::Expr { if let Some(i) = self.as_ident() { if let Some(var_name) = i.sym.strip_prefix('$') { if let Some(var) = cx.var(crate::ctxt::VarPos::$E, var_name) { return var.get_expr(); } } } impl_enum_body!($E, self, cx, [ $($v),* ]) } } }; } macro_rules! impl_struct { ( $name:ident, [ $($v:ident),* ] ) => { impl crate::ast::ToCode for $name { fn to_code(&self, cx: &crate::ctxt::Ctx) -> syn::Expr { let mut builder = crate::builder::Builder::new(stringify!($name)); let Self { $($v,)* } = self; $( builder.add( stringify!($v), crate::ast::ToCode::to_code($v, cx), ); )* syn::Expr::Struct(builder.build()) } } }; } mod class; mod decl; mod enums; mod expr; mod id; mod lit; mod module_decl; mod pat; mod prop; mod stmt; mod typescript; pub(crate) trait ToCode: 'static { fn to_code(&self, cx: &Ctx) -> syn::Expr; } impl<T> ToCode for Box<T> where T: ?Sized + ToCode, { fn to_code(&self, cx: &Ctx) -> syn::Expr { let inner = (**self).to_code(cx); parse_quote!(Box::new(#inner)) } } /// TODO: Optimize impl<T> ToCode for Option<T> where T: ToCode, { fn to_code(&self, cx: &Ctx) -> syn::Expr { match self { Some(inner) => { let inner = inner.to_code(cx); parse_quote!(Some(#inner)) } None => parse_quote!(None), } } } impl_struct!(Invalid, [span]); impl ToCode for Span { fn to_code(&self, _: &Ctx) -> syn::Expr { parse_quote!(swc_core::common::DUMMY_SP) } } impl ToCode for SyntaxContext { fn to_code(&self, _: &Ctx) -> syn::Expr { parse_quote!(swc_core::common::SyntaxContext::empty()) } } impl_enum!(ModuleItem, [ModuleDecl, Stmt]); impl_enum!( Pat, [Ident, Array, Rest, Object, Assign, Invalid, Expr], true ); impl_enum!(Lit, [Str, Bool, Null, Num, BigInt, Regex, JSXText]); impl_enum!( ClassMember, [ Constructor, Method, PrivateMethod, ClassProp, PrivateProp, TsIndexSignature, Empty, StaticBlock, AutoAccessor ] ); impl_enum!(ObjectPatProp, [KeyValue, Assign, Rest]); impl_enum!(PropName, [Ident, Str, Num, Computed, BigInt]); impl_enum!(ParamOrTsParamProp, [TsParamProp, Param]); impl_enum!(PropOrSpread, [Spread, Prop]); impl_enum!(BlockStmtOrExpr, [BlockStmt, Expr]); impl_enum!(MemberProp, [Ident, PrivateName, Computed]); impl_enum!(SuperProp, [Ident, Computed]); impl_enum!(JSXObject, [Ident, JSXMemberExpr]); impl_enum!( JSXElementChild, [ JSXText, JSXElement, JSXExprContainer, JSXFragment, JSXSpreadChild ] ); impl_enum!(OptChainBase, [Member, Call]); impl_enum!(JSXElementName, [Ident, JSXMemberExpr, JSXNamespacedName]); impl_enum!(JSXAttrOrSpread, [JSXAttr, SpreadElement]); impl<T> ToCode for Vec<T> where T: ToCode, { fn to_code(&self, cx: &Ctx) -> syn::Expr { let len = self.len(); let var_stmt: syn::Stmt = parse_quote!(let mut items = Vec::with_capacity(#len);); let mut stmts = vec![var_stmt]; for item in self { let item = item.to_code(cx); stmts.push(syn::Stmt::Expr( parse_quote!(items.push(#item)), Some(Default::default()), )); } stmts.push(syn::Stmt::Expr(parse_quote!(items), None)); syn::Expr::Block(ExprBlock { attrs: Default::default(), label: Default::default(), block: syn::Block { brace_token: Default::default(), stmts, }, }) } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/module_decl.rs
Rust
use swc_ecma_ast::*; impl_enum!( ModuleDecl, [ Import, ExportDecl, ExportNamed, ExportDefaultDecl, ExportDefaultExpr, ExportAll, TsImportEquals, TsExportAssignment, TsNamespaceExport ] ); impl_struct!(ImportDecl, [span, specifiers, src, type_only, with, phase]); impl_struct!(ExportDecl, [span, decl]); impl_struct!(ExportDefaultDecl, [span, decl]); impl_struct!(ExportDefaultExpr, [span, expr]); impl_struct!(ExportAll, [span, type_only, src, with]); impl_struct!(NamedExport, [span, specifiers, src, type_only, with]); impl_enum!(ImportSpecifier, [Named, Default, Namespace]); impl_struct!(ImportNamedSpecifier, [span, local, imported, is_type_only]); impl_struct!(ImportDefaultSpecifier, [span, local]); impl_struct!(ImportStarAsSpecifier, [span, local]); impl_enum!(ExportSpecifier, [Named, Default, Namespace]); impl_enum!(DefaultDecl, [Class, Fn, TsInterfaceDecl]); impl_enum!(ModuleExportName, [Ident, Str]); impl_struct!(ExportNamedSpecifier, [span, orig, exported, is_type_only]); impl_struct!(ExportDefaultSpecifier, [exported]); impl_struct!(ExportNamespaceSpecifier, [span, name]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/pat.rs
Rust
use swc_ecma_ast::*; impl_struct!(BindingIdent, [id, type_ann]); impl_struct!(ArrayPat, [span, elems, optional, type_ann]); impl_struct!(ObjectPat, [span, props, optional, type_ann]); impl_struct!(RestPat, [span, dot3_token, arg, type_ann]); impl_struct!(AssignPat, [span, left, right]); impl_struct!(Param, [span, decorators, pat]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/prop.rs
Rust
use swc_ecma_ast::*; impl_enum!(Prop, [Shorthand, KeyValue, Assign, Getter, Setter, Method]); impl_struct!( PrivateProp, [ span, ctxt, definite, key, value, type_ann, is_static, decorators, accessibility, is_optional, is_override, readonly ] ); impl_struct!(KeyValueProp, [key, value]); impl_struct!(AssignProp, [span, key, value]); impl_struct!(GetterProp, [span, key, type_ann, body]); impl_struct!(SetterProp, [span, key, param, this_param, body]); impl_struct!(MethodProp, [key, function]); impl_struct!(KeyValuePatProp, [key, value]); impl_struct!(AssignPatProp, [span, key, value]); impl_struct!(ComputedPropName, [span, expr]); impl_enum!(Key, [Private, Public]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/stmt.rs
Rust
use swc_ecma_ast::*; impl_enum!( Stmt, [ Block, Empty, Debugger, With, Return, Labeled, Break, Continue, If, Switch, Throw, Try, While, DoWhile, For, ForIn, ForOf, Decl, Expr ] ); impl_struct!(EmptyStmt, [span]); impl_struct!(BlockStmt, [span, ctxt, stmts]); impl_struct!(DebuggerStmt, [span]); impl_struct!(WithStmt, [span, obj, body]); impl_struct!(LabeledStmt, [span, label, body]); impl_struct!(BreakStmt, [span, label]); impl_struct!(ContinueStmt, [span, label]); impl_struct!(IfStmt, [span, test, cons, alt]); impl_struct!(SwitchStmt, [span, discriminant, cases]); impl_struct!(ThrowStmt, [span, arg]); impl_struct!(TryStmt, [span, block, handler, finalizer]); impl_struct!(WhileStmt, [span, test, body]); impl_struct!(DoWhileStmt, [span, test, body]); impl_struct!(ForStmt, [span, init, test, update, body]); impl_struct!(ForInStmt, [span, left, right, body]); impl_struct!(ForOfStmt, [span, is_await, left, right, body]); impl_struct!(ReturnStmt, [span, arg]); impl_struct!(ExprStmt, [span, expr]); impl_enum!(VarDeclOrExpr, [VarDecl, Expr]); impl_enum!(ForHead, [VarDecl, UsingDecl, Pat]); impl_struct!(SwitchCase, [span, test, cons]); impl_struct!(CatchClause, [span, param, body]);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ast/typescript.rs
Rust
use swc_ecma_ast::*; fail_todo!(TsInterfaceDecl); fail_todo!(TsTypeAliasDecl); fail_todo!(TsEnumDecl); fail_todo!(TsModuleDecl); fail_todo!(TsImportEqualsDecl); fail_todo!(TsExportAssignment); fail_todo!(TsNamespaceExportDecl); fail_todo!(TsTypeAssertion); fail_todo!(TsConstAssertion); fail_todo!(TsNonNullExpr); fail_todo!(TsAsExpr); fail_todo!(TsInstantiation); fail_todo!(TsType); fail_todo!(TsTypeAnn); fail_todo!(TsTypeParamInstantiation); fail_todo!(TsTypeParamDecl); fail_todo!(TsExprWithTypeArgs); fail_todo!(TsIndexSignature); fail_todo!(TsParamProp); fail_todo!(TsSatisfiesExpr);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/builder.rs
Rust
use proc_macro2::Span; use syn::{punctuated::Punctuated, Expr, ExprStruct, FieldValue, Ident, Member, Token}; pub(crate) struct Builder { type_name: syn::Ident, fields: Punctuated<FieldValue, Token![,]>, } impl Builder { pub fn new(ident: &str) -> Self { Self { type_name: Ident::new(ident, Span::call_site()), fields: Default::default(), } } pub fn add(&mut self, name: &str, value: Expr) { self.fields.push(FieldValue { attrs: Default::default(), member: Member::Named(Ident::new(name, Span::call_site())), colon_token: Some(Default::default()), expr: value, }); } pub fn build(self) -> ExprStruct { let type_name = self.type_name; ExprStruct { attrs: Default::default(), brace_token: Default::default(), path: syn::parse_quote!(swc_core::ecma::ast::#type_name), fields: self.fields, dot2_token: Default::default(), rest: Default::default(), qself: None, } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ctxt.rs
Rust
#![allow(unused)] use std::cell::RefCell; use rustc_hash::FxHashMap; use swc_macros_common::call_site; use syn::{parse_quote, punctuated::Punctuated, ExprPath, ExprReference, Ident, Token}; use crate::{ast::ToCode, input::QuoteVar}; #[derive(Debug)] pub(crate) struct Ctx { pub(crate) vars: FxHashMap<VarPos, Vars>, } impl Ctx { pub fn var(&self, ty: VarPos, var_name: &str) -> Option<&VarData> { self.vars.get(&ty)?.get(var_name) } } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum VarPos { Ident, Expr, Pat, AssignTarget, Str, } #[derive(Debug)] pub struct VarData { pos: VarPos, is_counting: bool, /// How many times this variable should be cloned. 0 for variables used only /// once. clone: RefCell<usize>, ident: syn::Ident, } impl VarData { pub fn get_expr(&self) -> syn::Expr { if self.is_counting { *self.clone.borrow_mut() += 1; return self.expr_for_var_ref(); } let use_clone = { let mut b = self.clone.borrow_mut(); let val = *b; if val > 0 { *b -= 1; val != 1 } else { false } }; if use_clone { let var_ref_expr = self.expr_for_var_ref(); parse_quote!(swc_core::quote::ImplicitClone::clone_quote_var(&#var_ref_expr)) } else { self.expr_for_var_ref() } } fn expr_for_var_ref(&self) -> syn::Expr { syn::Expr::Path(ExprPath { attrs: Default::default(), qself: Default::default(), path: self.ident.clone().into(), }) } } pub type Vars = FxHashMap<String, VarData>; pub(super) fn prepare_vars( src: &dyn ToCode, vars: Punctuated<QuoteVar, Token![,]>, ) -> (Vec<syn::Stmt>, FxHashMap<VarPos, Vars>) { let mut stmts = Vec::new(); let mut init_map = FxHashMap::<_, Vars>::default(); for var in vars { let value = var.value; let ident = var.name.clone(); let ident_str = ident.to_string(); let pos = match var.ty { Some(syn::Type::Path(syn::TypePath { qself: None, path: syn::Path { leading_colon: None, segments, }, })) => { let segment = segments.first().unwrap(); match segment.ident.to_string().as_str() { "Ident" => VarPos::Ident, "Expr" => VarPos::Expr, "Pat" => VarPos::Pat, "Str" => VarPos::Str, "AssignTarget" => VarPos::AssignTarget, _ => panic!("Invalid type: {:?}", segment.ident), } } None => VarPos::Ident, _ => { panic!( "Var type should be one of: Ident, Expr, Pat; got {:?}", var.ty ) } }; let var_ident = syn::Ident::new(&format!("quote_var_{}", ident), ident.span()); let old = init_map.entry(pos).or_default().insert( ident_str.clone(), VarData { pos, is_counting: true, clone: Default::default(), ident: var_ident.clone(), }, ); if let Some(old) = old { panic!("Duplicate variable name: {}", ident_str); } let type_name = Ident::new( match pos { VarPos::Ident => "Ident", VarPos::Expr => "Expr", VarPos::Pat => "Pat", VarPos::AssignTarget => "AssignTarget", VarPos::Str => "Str", }, call_site(), ); stmts.push(parse_quote! { let #var_ident: swc_core::ecma::ast::#type_name = #value; }); } // Use `ToCode` to count how many times each variable is used. let mut cx = Ctx { vars: init_map }; src.to_code(&cx); // We are done cx.vars .iter_mut() .for_each(|(k, v)| v.iter_mut().for_each(|(_, v)| v.is_counting = false)); (stmts, cx.vars) }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/input.rs
Rust
use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, Token, }; pub(super) struct QuoteInput { pub src: syn::LitStr, #[allow(unused)] pub as_token: Token![as], pub output_type: syn::Type, pub vars: Option<(Token![,], Punctuated<QuoteVar, Token![,]>)>, } pub(super) struct QuoteVar { pub name: syn::Ident, /// Defaults to `swc_ecma_ast::Ident` pub ty: Option<syn::Type>, #[allow(unused)] pub eq_token: Token![=], pub value: syn::Expr, } impl Parse for QuoteInput { fn parse(input: ParseStream) -> syn::Result<Self> { let src = input.parse()?; let as_token = input.parse()?; let output_type = input.parse()?; let vars = if input.is_empty() { None } else { let comma_token = input.parse()?; let vars = Punctuated::parse_terminated(input)?; Some((comma_token, vars)) }; Ok(Self { src, as_token, output_type, vars, }) } } impl Parse for QuoteVar { fn parse(input: ParseStream) -> syn::Result<Self> { let name = input.parse()?; let ty = if input.peek(Token![:]) { let _: Token![:] = input.parse()?; Some(input.parse()?) } else { None }; Ok(Self { name, ty, eq_token: input.parse()?, value: input.parse()?, }) } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/lib.rs
Rust
extern crate proc_macro; use std::iter::once; use quote::ToTokens; use syn::{Block, ExprBlock}; use crate::{ ast::ToCode, ctxt::{prepare_vars, Ctx}, input::QuoteInput, ret_type::parse_input_type, }; mod ast; mod builder; mod ctxt; mod input; mod ret_type; /// Don't invoke this macro directly, use the `quote!` macro from /// `swc_ecma_quote` instead. #[proc_macro] pub fn internal_quote(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let QuoteInput { src, as_token: _, output_type, vars, } = syn::parse::<QuoteInput>(input).expect("failed to parse input to quote!()"); let ret_type = parse_input_type(&src.value(), &output_type).expect("failed to parse input type"); let vars = vars.map(|v| v.1); let (stmts, vars) = if let Some(vars) = vars { prepare_vars(&ret_type, vars) } else { Default::default() }; let cx = Ctx { vars }; let expr_for_ast_creation = ret_type.to_code(&cx); syn::Expr::Block(ExprBlock { attrs: Default::default(), label: Default::default(), block: Block { brace_token: Default::default(), stmts: stmts .into_iter() .chain(once(syn::Stmt::Expr(expr_for_ast_creation, None))) .collect(), }, }) .to_token_stream() .into() }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_quote_macros/src/ret_type.rs
Rust
use std::any::type_name; use anyhow::{anyhow, bail, Context, Error}; use swc_common::{sync::Lrc, FileName, SourceMap}; use swc_ecma_ast::{AssignTarget, EsVersion}; use swc_ecma_parser::{lexer::Lexer, PResult, Parser, StringInput}; use syn::{GenericArgument, PathArguments, Type}; use crate::{ast::ToCode, ctxt::Ctx}; /// Storage for `dyn ToCode`.The first `Box`, which is required to store `dyn /// ToCode`, is ignored. pub struct BoxWrapper(Box<dyn ToCode>); impl ToCode for BoxWrapper { fn to_code(&self, cx: &Ctx) -> syn::Expr { (*self.0).to_code(cx) } } pub(crate) fn parse_input_type(input_str: &str, ty: &Type) -> Result<BoxWrapper, Error> { if let Some(ty) = extract_generic("Box", ty) { let node = parse_input_type(input_str, ty).context("failed to parse `T` in Box<T>")?; return Ok(BoxWrapper(Box::new(Box::new(node)))); } if let Some(ty) = extract_generic("Option", ty) { if input_str.is_empty() { return Ok(BoxWrapper(Box::new(None::<swc_ecma_ast::Expr>))); } let node = parse_input_type(input_str, ty).context("failed to parse `T` in Option<T>")?; return Ok(BoxWrapper(Box::new(Some(node)))); } if let Type::Path(p) = ty { if let Some(ident) = p.path.get_ident() { match &*ident.to_string() { "Expr" => return parse(input_str, &mut |p| p.parse_expr().map(|v| *v)), "Pat" => return parse(input_str, &mut |p| p.parse_pat()), "Stmt" => return parse(input_str, &mut |p| p.parse_stmt_list_item(true)), "AssignTarget" => { return parse(input_str, &mut |p| { Ok(AssignTarget::try_from(p.parse_pat()?) .expect("failed to parse AssignTarget")) }) } "ModuleItem" => return parse(input_str, &mut |p| p.parse_module_item()), _ => {} } } } bail!("Unknown quote type: {:?}", ty); } fn parse<T>( input_str: &str, op: &mut dyn FnMut(&mut Parser<Lexer>) -> PResult<T>, ) -> Result<BoxWrapper, Error> where T: ToCode, { let cm = Lrc::new(SourceMap::default()); let fm = cm.new_source_file(FileName::Anon.into(), input_str.to_string()); let lexer = Lexer::new( Default::default(), EsVersion::Es2020, StringInput::from(&*fm), None, ); let mut parser = Parser::new_from(lexer); op(&mut parser) .map_err(|err| anyhow!("{:?}", err)) .with_context(|| format!("failed to parse input as `{}`", type_name::<T>())) .map(|val| BoxWrapper(Box::new(val))) } fn extract_generic<'a>(name: &str, ty: &'a Type) -> Option<&'a Type> { if let Type::Path(p) = ty { let last = p.path.segments.last().unwrap(); if !last.arguments.is_empty() && last.ident == name { match &last.arguments { PathArguments::AngleBracketed(tps) => { let arg = tps.args.first().unwrap(); match arg { GenericArgument::Type(arg) => return Some(arg), _ => unimplemented!("generic parameter other than type"), } } _ => unimplemented!("Box() -> T or Box without a type parameter"), } } } None }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_testing/src/lib.rs
Rust
use std::{env, fs, path::PathBuf, process::Command}; use anyhow::{bail, Context, Result}; use sha2::{Digest, Sha256}; use testing::CARGO_TARGET_DIR; use tracing::debug; #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct JsExecOptions { /// Cache the result of the execution. /// /// If `true`, the result of the execution will be cached. /// Cache is not removed and it will be reused if the source code is /// identical. /// /// Note that this cache is stored in cargo target directory and will be /// removed by `cargo clean`. /// /// You can change the cache directory name by setting the /// `SWC_ECMA_TESTING_CACHE_DIR` pub cache: bool, /// If true, `--input-type=module` will be added. pub module: bool, /// The arguments passed to the node.js process. pub args: Vec<String>, } fn cargo_cache_root() -> PathBuf { env::var("SWC_ECMA_TESTING_CACHE_DIR") .map(PathBuf::from) .unwrap_or_else(|_| CARGO_TARGET_DIR.clone()) } /// Executes `js_code` and capture thw output. pub fn exec_node_js(js_code: &str, opts: JsExecOptions) -> Result<String> { if opts.cache { let hash = calc_hash(&format!("{:?}:{}", opts.args, js_code)); let cache_dir = cargo_cache_root().join(".swc-node-exec-cache"); let cache_path = cache_dir.join(format!("{}.stdout", hash)); if let Ok(s) = fs::read_to_string(&cache_path) { return Ok(s); } let output = exec_node_js( js_code, JsExecOptions { cache: false, ..opts }, )?; fs::create_dir_all(&cache_dir).context("failed to create cache directory")?; fs::write(&cache_path, output.as_bytes()).context("failed to write cache")?; return Ok(output); } debug!("Executing nodejs:\n{}", js_code); let mut c = Command::new("node"); if opts.module { c.arg("--input-type=module"); } else { c.arg("--input-type=commonjs"); } c.arg("-e").arg(js_code); for arg in opts.args { c.arg(arg); } let output = c.output().context("failed to execute output of minifier")?; if !output.status.success() { bail!( "failed to execute:\n{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr) ) } String::from_utf8(output.stdout).context("output is not utf8") } fn calc_hash(s: &str) -> String { let mut hasher = Sha256::default(); hasher.update(s.as_bytes()); let sum = hasher.finalize(); hex::encode(sum) }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/scripts/del.py
Python
#!/usr/bin/python3 import shutil from os import listdir from os.path import isfile, join def search(dir): print('Searching ', dir) entries = listdir(dir) if len(entries) == 1 and 'fixtures' in dir: shutil.rmtree(dir, ignore_errors=True) return True if len(entries) == 2 and 'fixtures' in dir and 'options.json' in entries and 'input.js' in entries: shutil.rmtree(dir, ignore_errors=True) return True shouldDelete = True; for f in listdir(dir): p = join(dir, f); if isfile(p): if f == 'options.json': return False else: if not search(p): shouldDelete = False if isfile(join(dir, 'options.json')) and not isfile(join(p, 'options.json')): shutil.copyfile(join(dir, 'options.json'), join(p, 'options.json')) if shouldDelete and 'fixtures' in dir: shutil.rmtree(dir, ignore_errors=True) return True search('./')
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/scripts/del.sh
Shell
#!/usr/bin/env bash find ./fixtures -type d -empty -delete SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" python3 $SCRIPT_DIR/del.py
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/scripts/fixtures.py
Python
#!/usr/bin/env python3 from os import listdir from os.path import isfile, join files = [f for f in listdir('./fixtures') if isfile(join('./fixtures', f))] fm = {} for f in files: name = join('./fixtures', f) if '.DS_Store' in f: continue test_name, file_type = f.rsplit('_', 1) if file_type == 'input.mjs': file_type = 'input.js' if file_type == 'input.mjsz': file_type = 'input.js' if file_type == 'output.mjs': file_type = 'output.js' if file_type == 'output.mjsz': file_type = 'output.js' if file_type == 'exec.mjs': file_type = 'exec.js' if file_type == 'exec.mjsz': file_type = 'exec.js' if not test_name in fm: fm[test_name] = {} with open(name, "r") as f: fm[test_name][file_type] = f.read() for name in fm: m = fm[name] name = name.replace('-', '_') print() print('// {}'.format(name)) if 'exec.js' in m: if 'options.json' in m: print('test_exec!(syntax(), |_| tr(r#"{}"#), {}_exec, r#"\n{}\n"#);'.format( m['options.json'],name, m['exec.js'] )) else: print('test_exec!(syntax(), |_| tr(Default::default()), {}_exec, r#"\n{}\n"#);'.format( name, m['exec.js'] )) elif 'input.js' in m and 'output.js' in m: if 'options.json' in m: print('test!(syntax(),|_| tr(r#"{}"#), {}, r#"\n{}\n"#, r#"\n{}\n"#);'.format( m['options.json'], name, m['input.js'], m['output.js'] )) else: print('test!(syntax(),|_| tr(Default::default()), {}, r#"\n{}\n"#, r#"\n{}\n"#);'.format( name, m['input.js'], m['output.js'] )) elif 'stdout.txt' in m: pass else: print(m.keys()) raise Exception(name, m)
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/scripts/fixtures.sh
Shell
#!/bin/bash set -e rm -rf /tmp/.swc mkdir -p /tmp/.swc/fixtures (cd fixtures && find . -depth -exec sh -c ' for source; do case $source in ./*/*) target="$(printf %sz "${source#./}" | tr / _)"; cp -r -- "$source" "/tmp/.swc/fixtures/${target%z}";; esac done ' _ {} +) # (cd fixtures && for i in *-*;do mv $i ${i//"-"/"_"}; done) SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" (cd /tmp/.swc && python3 $SCRIPT_DIR/fixtures.py)
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/scripts/helpers.sh
Shell
#!/usr/bin/bash rm -f *.js cp ../../node_modules/@babel/runtime/helpers/*.js . # camelCase to snake case rename -f 's/([a-z])([A-Z])/$1_$2/g; y/A-Z/a-z/' *.js rename --prepend=_ *.js
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/src/lib.rs
Rust
#![deny(clippy::all)] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(unused)] pub use swc_ecma_transforms_base::{ assumptions::Assumptions, feature, fixer, helpers, hygiene, perf, resolver, }; // TODO: May remove these reexports once swc_core directly reexports all #[cfg(feature = "swc_ecma_transforms_compat")] #[cfg_attr(docsrs, doc(cfg(feature = "compat")))] pub use swc_ecma_transforms_compat as compat; #[cfg(feature = "swc_ecma_transforms_module")] #[cfg_attr(docsrs, doc(cfg(feature = "module")))] pub use swc_ecma_transforms_module as modules; #[cfg(feature = "swc_ecma_transforms_optimization")] #[cfg_attr(docsrs, doc(cfg(feature = "optimization")))] pub use swc_ecma_transforms_optimization as optimization; #[cfg(feature = "swc_ecma_transforms_optimization")] #[cfg_attr(docsrs, doc(cfg(feature = "optimization")))] pub use swc_ecma_transforms_optimization::const_modules; #[cfg(feature = "swc_ecma_transforms_proposal")] #[cfg_attr(docsrs, doc(cfg(feature = "proposal")))] pub use swc_ecma_transforms_proposal as proposals; #[cfg(feature = "swc_ecma_transforms_react")] pub use swc_ecma_transforms_react as react; #[cfg_attr(docsrs, doc(cfg(feature = "react")))] #[cfg(feature = "swc_ecma_transforms_typescript")] #[cfg_attr(docsrs, doc(cfg(feature = "typescript")))] pub use swc_ecma_transforms_typescript as typescript; pub use self::{fixer::fixer, hygiene::hygiene};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/duplicated_keys_computed_keys_same_ast.js
JavaScript
let Foo = _decorate([ (_)=>desc = _ ], function(_initialize) { class Foo { constructor(){ _initialize(this); } } return { F: Foo, d: [ { kind: "method", key: getKey(), value: function() { return 1; } }, { kind: "method", key: getKey(), value: function() { return 2; } } ] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/duplicated_keys_computed_keys_same_value.js
JavaScript
let Foo = _decorate([ (_)=>desc = _ ], function(_initialize) { class Foo { constructor(){ _initialize(this); } } return { F: Foo, d: [ { kind: "method", key: getKeyI(), value: function() { return 1; } }, { kind: "method", key: getKeyJ(), value: function() { return 2; } } ] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/function_name_eval.js
JavaScript
var a = { eval: function _eval() { return eval; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/function_name_modules.js
JavaScript
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _events = /*#__PURE__*/ _interop_require_default(require("events")); let Template = /*#__PURE__*/ function() { "use strict"; function Template() { _class_call_check(this, Template); } _create_class(Template, [ { key: "events", value: function events() { return _events.default; } } ]); return Template; }(); console.log(new Template().events());
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/issue_395_1.js
JavaScript
"use strict"; var _moduleA = require("./moduleA.js"); let Demo = _decorate([ (0, _moduleA.default)('0.0.1') ], function(_initialize) { class Demo { constructor(){ _initialize(this); this.author = 'alan'; } } return { F: Demo, d: [] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/issue_395_2.js
JavaScript
"use strict"; Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const Test = (version)=>{ return (target)=>{ target.version = version; }; }; var _default = Test;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/issue_846_1.js
JavaScript
let SomeClass = _decorate([], function(_initialize) { class SomeClass { constructor(){ _initialize(this); } } return { F: SomeClass, d: [ { kind: "method", decorators: [ dec ], key: "someMethod", value: function someMethod() {} } ] }; }); let OtherClass = _decorate([], function(_initialize, _SomeClass) { class OtherClass extends _SomeClass { constructor(...args){ super(...args); _initialize(this); } } return { F: OtherClass, d: [ { kind: "method", decorators: [ dec ], key: "anotherMethod", value: function anotherMethod() { _get(_get_prototype_of(OtherClass.prototype), "someMethod", this).call(this); } } ] }; }, SomeClass);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/misc_method_name_not_shadow.js
JavaScript
var method = 1; let Foo = _decorate([ decorator ], function(_initialize) { class Foo { constructor(){ _initialize(this); } } return { F: Foo, d: [ { kind: "method", key: "method", value: function method1() { return method; } } ] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_arguments.js
JavaScript
let A = _decorate([ dec(a, b, ...c) ], function(_initialize) { class A { constructor(){ _initialize(this); } } return { F: A, d: [ { kind: "method", decorators: [ dec(a, b, ...c) ], key: "method", value: function method() {} } ] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_declaration.js
JavaScript
let A = _decorate([ dec() ], function(_initialize) { class A { constructor(){ _initialize(this); } } return { F: A, d: [] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_export_default_anonymous.js
JavaScript
export default _decorate([ dec() ], function(_initialize) { class _class { constructor(){ _initialize(this); } } return { F: _class, d: [] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_export_default_named.js
JavaScript
let Foo = _decorate([ dec() ], function(_initialize) { class Foo { constructor(){ _initialize(this); } } return { F: Foo, d: [] }; }); export { Foo as default };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_expression.js
JavaScript
_decorate([ dec() ], function(_initialize) { class _class { constructor(){ _initialize(this); } } return { F: _class, d: [] }; });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_extends.js
JavaScript
let A = _decorate([ dec ], function(_initialize, _B) { class A extends _B { constructor(...args){ super(...args); _initialize(this); } } return { F: A, d: [] }; }, B);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_extends_await.js
JavaScript
async function g() { let A = _decorate([ dec ], function(_initialize, _super) { class A extends _super { constructor(...args){ super(...args); _initialize(this); } } return { F: A, d: [] }; }, await B); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_extends_yield.js
JavaScript
function* g() { let A = _decorate([ dec ], function(_initialize, _super) { class A extends _super { constructor(...args){ super(...args); _initialize(this); } } return { F: A, d: [] }; }, (yield B)); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_initiailzer_after_super_bug_8808.js
JavaScript
let Sub = _decorate([ decorator(parameter) ], function(_initialize, _Super) { class Sub extends _Super { constructor(){ [ super(), _initialize(this) ][0].method(); } } return { F: Sub, d: [] }; }, Super);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_initialize_after_super_bug_8931.js
JavaScript
let B = _decorate([ dec ], function(_initialize, _A) { class B extends _A { constructor(){ super(), _initialize(this); []; } } return { F: B, d: [] }; }, A);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_initialize_after_super_expression.js
JavaScript
let B = _decorate([ dec ], function(_initialize, _A) { class B extends _A { constructor(){ super(), _initialize(this); } } return { F: B, d: [] }; }, A);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_initialize_after_super_multiple.js
JavaScript
let B = _decorate([ dec ], function(_initialize, _A) { class B extends _A { constructor(){ const foo = ()=>{ super(), _initialize(this); }; if (a) { super(), _initialize(this); } else { foo(); } while(0){ super(), _initialize(this); } super(), _initialize(this); } } return { F: B, d: [] }; }, A);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_initialize_after_super_statement.js
JavaScript
let B = _decorate([ dec ], function(_initialize, _A) { class B extends _A { constructor(){ super(), _initialize(this); } } return { F: B, d: [] }; }, A);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/decorators.rs/transformation_only_decorated.js
JavaScript
class B { bar() {} constructor(){ this.foo = 2; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/assign.js
JavaScript
number = function number1(x) { return x; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/basic.js
JavaScript
var number = function number(x) { return x; };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/class_simple.js
JavaScript
var Foo = function() { var Foo = function Foo1() { _class_call_check(this, Foo); }; _define_property(Foo, 'num', 0); return Foo; }(); expect(Foo.num).toBe(0); expect(Foo.num = 1).toBe(1); expect(Foo.name).toBe('Foo');
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/function_name_await.js
JavaScript
export { }; var obj = { await: function _await() {} };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/function_name_basic.js
JavaScript
var g = function g() { doSmth(); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/function_name_collisions.js
JavaScript
var obj = { search: function search({ search }) { console.log(search); } }; function search({ search }) { console.log(search); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/function_name_method_definition.js
JavaScript
({ x () {} });
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/function_name_modules_3.js
JavaScript
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return Login; } }); var _store = require("./store"); let Login = /*#__PURE__*/ function(_React_Component) { "use strict"; _inherits(Login, _React_Component); function Login() { _class_call_check(this, Login); return _call_super(this, Login, arguments); } _create_class(Login, [ { key: "getForm", value: function getForm() { return (0, _store.getForm)().toJS(); } } ]); return Login; }(React.Component);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/issue_288_01.js
JavaScript
var extendStatics = function extendStatics1(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] }) instanceof Array && function(d, b) { d.__proto__ = b; } || function(d, b) { for(var p in b)if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms/tests/__swc_snapshots__/tests/es2015_function_name.rs/issues_5004.js
JavaScript
export const x = ({ x })=>x; export const y = function y() {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University