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_transforms_base/tests/ts-resolver/type-alias/hoisting/1/input.ts | TypeScript | namespace Foo {
export type ServerHandle = HandleFunction | http.Server;
export class IncomingMessage extends http.IncomingMessage {
originalUrl?: http.IncomingMessage["url"] | undefined;
}
type NextFunction = (err?: any) => void;
export type SimpleHandleFunction = (
req: IncomingMessage,
res: http.ServerResponse
) => void;
export type NextHandleFunction = (
req: IncomingMessage,
res: http.ServerResponse,
next: NextFunction
) => void;
export type ErrorHandleFunction = (
err: any,
req: IncomingMessage,
res: http.ServerResponse,
next: NextFunction
) => void;
export type HandleFunction =
| SimpleHandleFunction
| NextHandleFunction
| ErrorHandleFunction;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type-alias/hoisting/1/output.ts | TypeScript | namespace Foo__2 {
export type ServerHandle__3 = HandleFunction__3 | http.Server;
export class IncomingMessage__3 extends http.IncomingMessage {
originalUrl?: http.IncomingMessage["url"] | undefined;
}
type NextFunction__3 = (err?: any) => void;
export type SimpleHandleFunction__3 = (req: IncomingMessage__3, res: http.ServerResponse) => void;
export type NextHandleFunction__3 = (req: IncomingMessage__3, res: http.ServerResponse, next: NextFunction__3) => void;
export type ErrorHandleFunction__3 = (err: any, req: IncomingMessage__3, res: http.ServerResponse, next: NextFunction__3) => void;
export type HandleFunction__3 = SimpleHandleFunction__3 | NextHandleFunction__3 | ErrorHandleFunction__3;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type/checker/001/input.ts | TypeScript | const assign =
<T, K1 extends keyof T, K2 extends keyof T[K1]>(
object: T,
key1: K1,
key2: K2
) =>
(value: T[K1][K2]) =>
(object[key1][key2] = value);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type/checker/001/output.ts | TypeScript | const assign__2 = <T__3, K1__3 extends keyof T__3, K2__3 extends keyof T__3[K1__3]>(object__3: T__3, key1__3: K1__3, key2__3: K2__3)=>(value__4: T__3[K1__3][K2__3])=>object__3[key1__3][key2__3] = value__4;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type/checker/002/input.ts | TypeScript | export declare function foo<T>(obj: T): T extends () => infer P ? P : never;
export function bar<T>(obj: T) {
return foo(obj);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type/checker/002/output.ts | TypeScript | export declare function foo__2<T__3>(obj__3: T__3): T__3 extends () => infer P ? P : never;
export function bar__2<T__4>(obj__4: T__4) {
return foo__2(obj__4);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain/input.ts | TypeScript | function foo<T, U extends T>(x: T, y: U): T {
x = y;
return y;
}
function foo2<U extends T, T>(x: T, y: U): T {
x = y;
return y;
}
var f = function <T, U extends T>(x: T, y: U): T {
x = y;
return y;
};
var f2 = function <U extends T, T>(x: T, y: U): T {
x = y;
return y;
};
var f3 = <T, U extends T>(x: T, y: U): T => {
x = y;
return y;
};
var f4 = <U extends T, T>(x: T, y: U): T => {
x = y;
return y;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain/output.ts | TypeScript | function foo__2<T__3, U__3 extends T__3>(x__3: T__3, y__3: U__3): T__3 {
x__3 = y__3;
return y__3;
}
function foo2__2<U__4 extends T__4, T__4>(x__4: T__4, y__4: U__4): T__4 {
x__4 = y__4;
return y__4;
}
var f__2 = function<T__5, U__5 extends T__5>(x__5: T__5, y__5: U__5): T__5 {
x__5 = y__5;
return y__5;
};
var f2__2 = function<U__6 extends T__6, T__6>(x__6: T__6, y__6: U__6): T__6 {
x__6 = y__6;
return y__6;
};
var f3__2 = <T__7, U__7 extends T__7>(x__7: T__7, y__7: U__7): T__7 =>{
x__7 = y__7;
return y__7;
};
var f4__2 = <U__8 extends T__8, T__8>(x__8: T__8, y__8: U__8): T__8 =>{
x__8 = y__8;
return y__8;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain_2/input.ts | TypeScript | var f3 = <T, U extends T>(x: T, y: U): T => {
x = y;
return y;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain_2/output.ts | TypeScript | var f3__2 = <T__3, U__3 extends T__3>(x__3: T__3, y__3: U__3): T__3 =>{
x__3 = y__3;
return y__3;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain_3/input.ts | TypeScript | var f4 = <U extends T, T>(x: T, y: U): T => {
x = y;
return y;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/type_parameter_used_as_type_parameter_contrain_3/output.ts | TypeScript | var f4__2 = <U__3 extends T__3, T__3>(x__3: T__3, y__3: U__3): T__3 =>{
x__3 = y__3;
return y__3;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/vercel/1/input.ts | TypeScript | var n = t(3957);
function o(e) {
const r = e.nextUrl;
if ("/log" !== r.pathname) {
if ("/throw-error-internal" === r.pathname) {
function r() {
return e();
}
try {
r();
} catch (o) {
console.error(o);
}
return new Promise((e, r) => r(new Error("oh no!")));
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts-resolver/vercel/1/output.ts | TypeScript | var n__2 = t(3957);
function o__2(e__3) {
const r__3 = e__3.nextUrl;
if ("/log" !== r__3.pathname) {
if ("/throw-error-internal" === r__3.pathname) {
function r__5() {
return e__3();
}
try {
r__5();
} catch (o__8) {
console.error(o__8);
}
return new Promise((e__9, r__9)=>r__9(new Error("oh no!")));
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_base/tests/ts_resolver.rs | Rust | #![deny(warnings)]
use std::path::PathBuf;
use swc_common::{Mark, SyntaxContext};
use swc_ecma_ast::*;
use swc_ecma_parser::{parse_file_as_module, Syntax, TsSyntax};
use swc_ecma_transforms_base::resolver;
use swc_ecma_visit::{Visit, VisitWith};
use testing::fixture;
#[fixture("../swc_ecma_parser/tests/**/*.ts")]
#[fixture("../swc_ecma_parser/tests/**/*.tsx")]
fn no_empty(input: PathBuf) {
eprintln!("{}", input.display());
testing::run_test2(false, |cm, _handler| {
let fm = cm.load_file(&input).expect("failed to load file");
let module = match parse_file_as_module(
&fm,
Syntax::Typescript(TsSyntax {
tsx: input.ends_with("tsx"),
decorators: true,
no_early_errors: true,
..Default::default()
}),
EsVersion::latest(),
None,
&mut Vec::new(),
) {
Ok(v) => v,
// We are not testing parser
Err(..) => return Ok(()),
};
let module = Program::Module(module).apply(resolver(Mark::new(), Mark::new(), true));
module.visit_with(&mut AssertNoEmptyCtxt);
Ok(())
})
.unwrap();
}
struct AssertNoEmptyCtxt;
impl Visit for AssertNoEmptyCtxt {
fn visit_expr(&mut self, n: &Expr) {
n.visit_children_with(self);
if let Expr::Ident(i) = n {
if i.ctxt == SyntaxContext::empty() {
unreachable!("ts_resolver has a bug")
}
}
}
fn visit_pat(&mut self, n: &Pat) {
n.visit_children_with(self);
if let Pat::Ident(i) = n {
if i.ctxt == SyntaxContext::empty() {
unreachable!("ts_resolver has a bug")
}
}
}
fn visit_ts_getter_signature(&mut self, n: &TsGetterSignature) {
if n.computed {
n.key.visit_with(self);
}
n.type_ann.visit_with(self);
}
fn visit_ts_method_signature(&mut self, n: &TsMethodSignature) {
if n.computed {
n.key.visit_with(self);
}
n.params.visit_with(self);
n.type_ann.visit_with(self);
n.type_params.visit_with(self);
}
fn visit_ts_property_signature(&mut self, n: &TsPropertySignature) {
if n.computed {
n.key.visit_with(self);
}
n.type_ann.visit_with(self);
}
fn visit_ts_setter_signature(&mut self, n: &TsSetterSignature) {
if n.computed {
n.key.visit_with(self);
}
n.param.visit_with(self);
}
fn visit_ts_tuple_element(&mut self, n: &TsTupleElement) {
n.ty.visit_with(self);
}
fn visit_var_decl(&mut self, node: &VarDecl) {
if node.declare {
return;
}
node.visit_children_with(self);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_classes/src/lib.rs | Rust | #![deny(clippy::all)]
use swc_common::DUMMY_SP;
use swc_ecma_ast::*;
use swc_ecma_transforms_base::helper;
use swc_ecma_utils::ExprFactory;
#[macro_use]
pub mod macros;
pub mod super_field;
/// Creates
///
/// ```js
/// Child.__proto__ || Object.getPrototypeOf(Child)
/// ```
pub fn get_prototype_of(obj: Box<Expr>) -> Box<Expr> {
CallExpr {
span: DUMMY_SP,
callee: helper!(get_prototype_of),
args: vec![obj.as_arg()],
..Default::default()
}
.into()
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_classes/src/macros.rs | Rust | /// Not intended for public use.
#[macro_export]
macro_rules! visit_mut_only_key {
() => {
fn visit_mut_class_member(&mut self, m: &mut ClassMember) {
match m {
ClassMember::Method(m) => m.key.visit_mut_with(self),
ClassMember::PrivateMethod(m) => m.key.visit_mut_with(self),
ClassMember::ClassProp(m) => m.key.visit_mut_with(self),
ClassMember::PrivateProp(m) => m.key.visit_mut_with(self),
_ => {}
}
}
};
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_classes/src/super_field.rs | Rust | use std::iter;
use swc_common::{util::take::Take, Mark, Span, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::helper;
use swc_ecma_utils::{is_rest_arguments, quote_ident, ExprFactory};
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
use super::get_prototype_of;
/// Process function body.
///
/// # In
///
/// ```js
/// super.foo(a)
/// ```
///
/// # Out
///
///
/// _get(Child.prototype.__proto__ || Object.getPrototypeOf(Child.prototype),
/// 'foo', this).call(this, a);
pub struct SuperFieldAccessFolder<'a> {
pub class_name: &'a Ident,
/// Mark for the `_this`. Used only when folding constructor.
pub constructor_this_mark: Option<Mark>,
pub is_static: bool,
pub folding_constructor: bool,
/// True while folding **injected** `_define_property` call
pub in_injected_define_property_call: bool,
/// True while folding a function / class.
pub in_nested_scope: bool,
/// `Some(mark)` if `var this2 = this`is required.
pub this_alias_mark: Option<Mark>,
/// assumes super is never changed, payload is the name of super class
pub constant_super: bool,
pub super_class: &'a Option<Ident>,
pub in_pat: bool,
}
macro_rules! mark_nested {
($name:ident, $T:tt) => {
fn $name(&mut self, n: &mut $T) {
// injected `_define_property` should be handled like method
if self.folding_constructor && !self.in_injected_define_property_call {
let old = self.in_nested_scope;
self.in_nested_scope = true;
n.visit_mut_children_with(self);
self.in_nested_scope = old;
} else {
n.visit_mut_children_with(self)
}
}
};
}
impl VisitMut for SuperFieldAccessFolder<'_> {
noop_visit_mut_type!();
// mark_nested!(fold_function, Function);
mark_nested!(visit_mut_class, Class);
visit_mut_only_key!();
fn visit_mut_expr(&mut self, n: &mut Expr) {
match n {
Expr::This(ThisExpr { span }) if self.in_nested_scope => {
*n = quote_ident!(
SyntaxContext::empty().apply_mark(
*self
.this_alias_mark
.get_or_insert_with(|| Mark::fresh(Mark::root()))
),
*span,
"_this"
)
.into();
}
// We pretend method folding mode for while folding injected `_define_property`
// calls.
Expr::Call(CallExpr {
callee: Callee::Expr(expr),
..
}) if expr.is_ident_ref_to("_define_property") => {
let old = self.in_injected_define_property_call;
self.in_injected_define_property_call = true;
n.visit_mut_children_with(self);
self.in_injected_define_property_call = old;
}
Expr::SuperProp(..) => {
self.visit_mut_super_member_get(n);
}
Expr::Update(UpdateExpr { arg, .. }) if arg.is_super_prop() => {
if let Expr::SuperProp(SuperPropExpr {
obj: Super {
span: super_token, ..
},
prop,
..
}) = &**arg
{
*arg = self.super_to_update_call(*super_token, prop.clone()).into();
}
}
Expr::Assign(AssignExpr {
ref left,
op: op!("="),
right,
..
}) if is_assign_to_super_prop(left) => {
right.visit_mut_with(self);
self.visit_mut_super_member_set(n)
}
Expr::Assign(AssignExpr { left, right, .. }) if is_assign_to_super_prop(left) => {
right.visit_mut_with(self);
self.visit_mut_super_member_update(n);
}
Expr::Call(CallExpr {
callee: Callee::Expr(callee_expr),
args,
..
}) if callee_expr.is_super_prop() => {
args.visit_mut_children_with(self);
self.visit_mut_super_member_call(n);
}
_ => {
n.visit_mut_children_with(self);
}
}
}
fn visit_mut_pat(&mut self, n: &mut Pat) {
let in_pat = self.in_pat;
self.in_pat = true;
n.visit_mut_children_with(self);
self.in_pat = in_pat;
}
fn visit_mut_function(&mut self, n: &mut Function) {
if self.folding_constructor {
return;
}
if self.folding_constructor && !self.in_injected_define_property_call {
let old = self.in_nested_scope;
self.in_nested_scope = true;
n.visit_mut_children_with(self);
self.in_nested_scope = old;
} else {
n.visit_mut_children_with(self);
}
}
}
impl SuperFieldAccessFolder<'_> {
/// # In
/// ```js
/// super.foo(a)
/// ```
/// # out
/// ```js
/// _get(_get_prototype_of(Clazz.prototype), 'foo', this).call(this, a)
/// ```
fn visit_mut_super_member_call(&mut self, n: &mut Expr) {
if let Expr::Call(CallExpr {
callee: Callee::Expr(callee_expr),
args,
..
}) = n
{
if let Expr::SuperProp(SuperPropExpr {
obj: Super {
span: super_token, ..
},
prop,
..
}) = &**callee_expr
{
let this = match self.this_alias_mark.or(self.constructor_this_mark) {
Some(mark) => {
let ident =
quote_ident!(SyntaxContext::empty().apply_mark(mark), "_this").as_arg();
// in constant super, call will be the only place where a assert is needed
if self.constant_super {
CallExpr {
span: DUMMY_SP,
callee: helper!(assert_this_initialized),
args: vec![ident],
..Default::default()
}
.as_arg()
} else {
ident
}
}
_ => ThisExpr { span: DUMMY_SP }.as_arg(),
};
let callee = self.super_to_get_call(*super_token, prop.clone());
let mut args = args.clone();
if args.len() == 1 && is_rest_arguments(&args[0]) {
*n = CallExpr {
span: DUMMY_SP,
callee: callee.make_member(quote_ident!("apply")).as_callee(),
args: iter::once(this)
.chain(iter::once({
let mut arg = args.pop().unwrap();
arg.spread = None;
arg
}))
.collect(),
..Default::default()
}
.into();
return;
}
*n = CallExpr {
span: DUMMY_SP,
callee: callee.make_member(quote_ident!("call")).as_callee(),
args: iter::once(this).chain(args).collect(),
..Default::default()
}
.into();
}
}
}
/// # In
/// ```js
/// super.foo = bar
/// # out
/// ```js
/// _set(_get_prototype_of(Clazz.prototype), "foo", bar, this, true)
/// ```
fn visit_mut_super_member_set(&mut self, n: &mut Expr) {
if let Expr::Assign(AssignExpr {
left:
AssignTarget::Simple(SimpleAssignTarget::SuperProp(SuperPropExpr {
obj: Super { span: super_token },
prop,
..
})),
op: op @ op!("="),
right,
..
}) = n
{
*n = self.super_to_set_call(*super_token, prop.take(), *op, right.take());
}
}
/// # In
/// ```js
/// super.foo
/// ```
/// # out
/// ```js
/// _get(_get_prototype_of(Clazz.prototype), 'foo', this)
/// ```
fn visit_mut_super_member_get(&mut self, n: &mut Expr) {
if let Expr::SuperProp(SuperPropExpr {
obj: Super { span: super_token },
prop,
..
}) = n
{
let super_token = *super_token;
prop.visit_mut_children_with(self);
let prop = prop.take();
*n = if self.in_pat {
self.super_to_update_call(super_token, prop).into()
} else {
*self.super_to_get_call(super_token, prop)
};
}
}
fn visit_mut_super_member_update(&mut self, n: &mut Expr) {
if let Expr::Assign(AssignExpr { left, op, .. }) = n {
debug_assert_ne!(*op, op!("="));
if let AssignTarget::Simple(expr) = left {
if let SimpleAssignTarget::SuperProp(SuperPropExpr {
obj: Super { span: super_token },
prop,
..
}) = expr.take()
{
*expr = self.super_to_update_call(super_token, prop).into();
}
}
}
}
fn super_to_get_call(&mut self, super_token: Span, prop: SuperProp) -> Box<Expr> {
if self.constant_super {
MemberExpr {
span: super_token,
obj: Box::new({
let name = self.super_class.clone().unwrap_or_else(|| {
quote_ident!(if self.is_static { "Function" } else { "Object" }).into()
});
// in static default super class is Function.prototype
if self.is_static && self.super_class.is_some() {
name.into()
} else {
name.make_member(quote_ident!("prototype")).into()
}
}),
prop: match prop {
SuperProp::Ident(i) => MemberProp::Ident(i),
SuperProp::Computed(c) => MemberProp::Computed(c),
},
}
.into()
} else {
let proto_arg = self.proto_arg();
let prop_arg = prop_arg(prop).as_arg();
let this_arg = self.this_arg(super_token).as_arg();
CallExpr {
span: super_token,
callee: helper!(get),
args: vec![proto_arg.as_arg(), prop_arg, this_arg],
..Default::default()
}
.into()
}
}
fn super_to_set_call(
&mut self,
super_token: Span,
prop: SuperProp,
op: AssignOp,
rhs: Box<Expr>,
) -> Expr {
debug_assert_eq!(op, op!("="));
let this_expr = Box::new(match self.constructor_this_mark {
Some(mark) => quote_ident!(
SyntaxContext::empty().apply_mark(mark),
super_token,
"_this"
)
.into(),
None => ThisExpr { span: super_token }.into(),
});
if self.constant_super {
let left = MemberExpr {
span: super_token,
obj: this_expr,
prop: match prop {
SuperProp::Ident(i) => MemberProp::Ident(i),
SuperProp::Computed(c) => MemberProp::Computed(c),
},
};
AssignExpr {
span: super_token,
left: left.into(),
op,
right: rhs,
}
.into()
} else {
let proto_arg = self.proto_arg();
let prop_arg = prop_arg(prop).as_arg();
CallExpr {
span: super_token,
callee: helper!(set),
args: vec![
proto_arg.as_arg(),
prop_arg,
rhs.as_arg(),
this_expr.as_arg(),
// strict
true.as_arg(),
],
..Default::default()
}
.into()
}
}
fn super_to_update_call(&mut self, super_token: Span, prop: SuperProp) -> MemberExpr {
let proto_arg = self.proto_arg();
let prop_arg = prop_arg(prop).as_arg();
let this_arg = self.this_arg(super_token).as_arg();
let expr: Expr = CallExpr {
span: super_token,
callee: helper!(update),
args: vec![
proto_arg.as_arg(),
prop_arg,
this_arg,
// strict
true.as_arg(),
],
..Default::default()
}
.into();
expr.make_member(quote_ident!("_"))
}
fn proto_arg(&mut self) -> Box<Expr> {
let expr = if self.is_static {
// Foo
self.class_name.clone().into()
} else {
// Foo.prototype
self.class_name
.clone()
.make_member(quote_ident!("prototype"))
.into()
};
if self.constant_super {
return expr;
}
let mut proto_arg = get_prototype_of(expr);
if let Some(mark) = self.constructor_this_mark {
let this = quote_ident!(SyntaxContext::empty().apply_mark(mark), "_this");
proto_arg = SeqExpr {
span: DUMMY_SP,
exprs: vec![
Expr::Call(CallExpr {
span: DUMMY_SP,
callee: helper!(assert_this_initialized),
args: vec![this.as_arg()],
..Default::default()
})
.into(),
proto_arg,
],
}
.into()
}
proto_arg
}
fn this_arg(&self, super_token: Span) -> Expr {
match self.constructor_this_mark {
Some(mark) => quote_ident!(
SyntaxContext::empty().apply_mark(mark),
super_token,
"_this"
)
.into(),
None => ThisExpr { span: super_token }.into(),
}
}
}
fn is_assign_to_super_prop(left: &AssignTarget) -> bool {
match left {
AssignTarget::Simple(expr) => expr.is_super_prop(),
_ => false,
}
}
fn prop_arg(prop: SuperProp) -> Expr {
match prop {
SuperProp::Ident(IdentName {
sym: value, span, ..
}) => Lit::Str(Str {
span,
raw: None,
value,
})
.into(),
SuperProp::Computed(c) => *c.expr,
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/src/class_fields_use_set.rs | Rust | use std::mem;
use swc_common::{util::take::Take, Span, Spanned, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{
constructor::inject_after_super, default_constructor_with_span, is_literal,
is_simple_pure_expr, private_ident, prop_name_to_member_prop, ExprFactory, ModuleItemLike,
StmtLike,
};
use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith};
/// # What does this module do?
///
/// This module will transpile the class semantics
/// from `[[Define]]` to `[[Set]]`.
///
///
/// Note: class's native field is `[[Define]]` semantics.
///
/// # Why is it needed?
/// The getter/setter from the super class won't be triggered in `[[Define]]`
/// semantics.
///
/// Some decorators depend on super class getter/setter.
/// Therefore, scenarios like this will require `[[Set]]` semantics.
///
/// ## Example
///
/// ```JavaScript
/// class Foo {
/// a = 1;
/// #b = 2;
/// static c = 3;
/// static #d = 4;
/// }
/// ```
///
/// result:
///
/// ```JavaScript
/// class Foo {
/// #b;
/// static {
/// this.c = 3;
/// }
/// static #d = 4;
/// constructor() {
/// this.a = 1;
/// this.#b = 2;
/// }
/// }
/// ```
///
/// The variable `a` will be relocated to the constructor. Although the variable
/// `#b` is not influenced by `[[Define]]` or `[[Set]]` semantics, its execution
/// order is associated with variable `a`, thus its initialization is moved into
/// the constructor.
///
/// The static variable `c` is moved to the static block for `[[Set]]` semantic
/// conversion. Whereas, variable `#d` remains completely unaffected and
/// conserved in its original location.
///
/// Furthermore, for class props that have side effects, an extraction and
/// conversion will be performed.
///
/// For example,
///
/// ```JavaScript
/// class Foo {
/// [foo()] = 1;
/// }
/// ```
///
/// result:
///
/// ```JavaScript
/// let prop;
/// class Foo{
/// static {
/// prop = foo();
/// }
/// constructor() {
/// this[prop] = 1;
/// }
/// }
/// ```
pub fn class_fields_use_set(pure_getters: bool) -> impl Pass {
visit_mut_pass(ClassFieldsUseSet { pure_getters })
}
#[derive(Debug)]
struct ClassFieldsUseSet {
pure_getters: bool,
}
impl VisitMut for ClassFieldsUseSet {
noop_visit_mut_type!(fail);
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
self.visit_mut_stmts_like(n);
}
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
self.visit_mut_stmts_like(n);
}
fn visit_mut_class(&mut self, n: &mut Class) {
// visit inner classes first
n.visit_mut_children_with(self);
let mut fields_handler: FieldsHandler = FieldsHandler {
super_call_span: n.super_class.as_ref().map(|_| n.span),
};
n.body.visit_mut_with(&mut fields_handler);
}
}
impl ClassFieldsUseSet {
fn visit_mut_stmts_like<T>(&mut self, n: &mut Vec<T>)
where
T: StmtLike
+ ModuleItemLike
+ VisitMutWith<Self>
+ VisitMutWith<ComputedFieldsHandler>
+ From<Stmt>,
{
let mut stmts = Vec::with_capacity(n.len());
let mut computed_fields_handler = ComputedFieldsHandler {
var_decls: Default::default(),
static_init_blocks: Default::default(),
pure_getters: self.pure_getters,
};
for mut stmt in n.drain(..) {
stmt.visit_mut_with(&mut computed_fields_handler);
let var_decls = computed_fields_handler.var_decls.take();
if !var_decls.is_empty() {
stmts.push(T::from(
VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Let,
declare: false,
decls: var_decls,
..Default::default()
}
.into(),
))
}
stmt.visit_mut_with(self);
stmts.push(stmt);
}
*n = stmts;
}
}
#[derive(Debug)]
struct FieldsHandler {
super_call_span: Option<Span>,
}
impl VisitMut for FieldsHandler {
noop_visit_mut_type!(fail);
fn visit_mut_class(&mut self, _: &mut Class) {
// skip inner classes
// In fact, FieldsHandler does not visit children recursively.
// We call FieldsHandler with the class.body as the only entry point.
// The FieldsHandler actually operates in a iterative way.
}
fn visit_mut_class_members(&mut self, n: &mut Vec<ClassMember>) {
let mut constructor_inits = Vec::new();
for member in n.iter_mut() {
match member {
ClassMember::ClassProp(ClassProp {
ref span,
ref is_static,
key,
value,
..
}) => {
if let Some(value) = value.take() {
let init_expr: Expr = AssignExpr {
span: *span,
op: op!("="),
left: MemberExpr {
span: DUMMY_SP,
obj: ThisExpr::dummy().into(),
prop: prop_name_to_member_prop(key.take()),
}
.into(),
right: value,
}
.into();
if *is_static {
*member = StaticBlock {
span: DUMMY_SP,
body: BlockStmt {
span: DUMMY_SP,
stmts: vec![init_expr.into_stmt()],
..Default::default()
},
}
.into();
continue;
} else {
constructor_inits.push(init_expr.into());
}
}
member.take();
}
ClassMember::PrivateProp(PrivateProp {
ref span,
is_static: false,
key,
value,
..
}) => {
if let Some(value) = value.take() {
let init_expr: Expr = AssignExpr {
span: *span,
op: op!("="),
left: MemberExpr {
span: DUMMY_SP,
obj: ThisExpr::dummy().into(),
prop: MemberProp::PrivateName(key.clone()),
}
.into(),
right: value,
}
.into();
constructor_inits.push(init_expr.into());
}
}
_ => {}
}
}
if constructor_inits.is_empty() {
return;
}
if let Some(c) = n.iter_mut().find_map(|m| m.as_mut_constructor()) {
inject_after_super(c, constructor_inits.take());
} else {
let mut c = default_constructor_with_span(
self.super_call_span.is_some(),
self.super_call_span.span(),
);
inject_after_super(&mut c, constructor_inits.take());
n.push(c.into());
}
}
}
#[derive(Debug)]
struct ComputedFieldsHandler {
var_decls: Vec<VarDeclarator>,
static_init_blocks: Vec<Stmt>,
pure_getters: bool,
}
impl VisitMut for ComputedFieldsHandler {
noop_visit_mut_type!(fail);
fn visit_mut_class_prop(&mut self, n: &mut ClassProp) {
match &mut n.key {
PropName::Computed(ComputedPropName { expr, .. })
if !is_literal(expr) && !is_simple_pure_expr(expr, self.pure_getters) =>
{
let ref_key = private_ident!("prop");
let mut computed_expr = ref_key.clone().into();
mem::swap(expr, &mut computed_expr);
self.var_decls.push(VarDeclarator {
span: DUMMY_SP,
name: ref_key.clone().into(),
init: None,
definite: false,
});
self.static_init_blocks.push({
let assign_expr = computed_expr.make_assign_to(op!("="), ref_key.into());
assign_expr.into_stmt()
});
}
_ => (),
}
}
fn visit_mut_class_member(&mut self, n: &mut ClassMember) {
if n.is_class_prop() {
n.visit_mut_children_with(self);
}
}
fn visit_mut_class_members(&mut self, n: &mut Vec<ClassMember>) {
n.visit_mut_children_with(self);
if !self.static_init_blocks.is_empty() {
n.insert(
0,
StaticBlock {
span: DUMMY_SP,
body: BlockStmt {
span: DUMMY_SP,
stmts: self.static_init_blocks.take(),
..Default::default()
},
}
.into(),
);
}
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/src/lib.rs | Rust | //! New-generation javascript to old-javascript compiler.
#![deny(clippy::all)]
#![allow(clippy::vec_box)]
#![allow(clippy::boxed_local)]
#![allow(clippy::mutable_key_type)]
#![allow(clippy::match_like_matches_macro)]
pub use swc_ecma_compat_bugfixes as bugfixes;
pub use swc_ecma_compat_common::regexp;
pub use swc_ecma_compat_es2015 as es2015;
pub use swc_ecma_compat_es2016 as es2016;
pub use swc_ecma_compat_es2017 as es2017;
pub use swc_ecma_compat_es2018 as es2018;
pub use swc_ecma_compat_es2019 as es2019;
pub use swc_ecma_compat_es2020 as es2020;
pub use swc_ecma_compat_es2021 as es2021;
pub use swc_ecma_compat_es2022 as es2022;
pub use swc_ecma_compat_es3 as es3;
pub use self::{
bugfixes::bugfixes, es2015::es2015, es2016::es2016, es2017::es2017, es2018::es2018,
es2019::es2019, es2020::es2020, es2021::es2021, es2022::es2022, es3::es3,
};
pub mod class_fields_use_set;
pub mod reserved_words;
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/src/reserved_words.rs | Rust | use swc_atoms::Atom;
use swc_ecma_ast::*;
use swc_ecma_transforms_base::perf::Parallel;
use swc_ecma_visit::{
noop_visit_mut_type, visit_mut_obj_and_computed, visit_mut_pass, VisitMut, VisitMutWith,
};
pub fn reserved_words() -> impl 'static + Pass + VisitMut {
visit_mut_pass(EsReservedWord)
}
#[derive(Clone, Copy)]
struct EsReservedWord;
impl Parallel for EsReservedWord {
fn create(&self) -> Self {
*self
}
fn merge(&mut self, _: Self) {}
}
impl VisitMut for EsReservedWord {
noop_visit_mut_type!(fail);
visit_mut_obj_and_computed!();
fn visit_mut_export_specifier(&mut self, _n: &mut ExportSpecifier) {}
fn visit_mut_ident(&mut self, i: &mut Ident) {
rename_ident(&mut i.sym, true);
}
fn visit_mut_import_named_specifier(&mut self, s: &mut ImportNamedSpecifier) {
s.local.visit_mut_with(self);
}
fn visit_mut_private_name(&mut self, _: &mut PrivateName) {}
fn visit_mut_prop_name(&mut self, _n: &mut PropName) {}
}
fn is_reserved(sym: &str) -> bool {
matches!(
sym,
"enum"
| "implements"
| "package"
| "protected"
| "interface"
| "private"
| "public"
| "await"
| "break"
| "case"
| "catch"
| "class"
| "const"
| "continue"
| "debugger"
| "default"
| "delete"
| "do"
| "else"
| "export"
| "extends"
| "finally"
| "for"
| "function"
| "if"
| "in"
| "instanceof"
| "new"
| "return"
| "super"
| "switch"
| "this"
| "throw"
| "try"
| "typeof"
| "var"
| "void"
| "while"
| "with"
| "yield"
)
}
fn rename_ident(sym: &mut Atom, _strict: bool) {
// Es
if is_reserved(&*sym) {
let s = format!("_{}", sym).into();
*sym = s;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/arguments_function.js | JavaScript | function test() {
for(var i = 0; i < arguments.length; i++){
console.log(function() {
return arguments[i];
}());
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/arguments_loop.js | JavaScript | function test() {
for(var i = 0; i < arguments.length; i++){
var arg = arguments[i];
console.log(function() {
return arg;
}());
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/arguments_loop_member.js | JavaScript | function test(a) {
for(var i = 0; i < a.arguments.length; i++){
var arg = a.arguments[i];
console.log(function() {
return arg;
}());
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/for_let_loop.js | JavaScript | var _loop = function(i) {
functions.push(function() {
console.log(i);
});
};
var functions = [];
for(var i = 0; i < 10; i++)_loop(i);
functions[0]();
functions[7]();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/for_loop.js | JavaScript | for(var key in obj){
var bar = obj[key];
var qux = void 0;
var fog = void 0;
if (Array.isArray(bar)) {
qux = bar[0];
fog = bar[1];
} else {
qux = bar;
}
baz(key, qux, fog);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1021_1.js | JavaScript | var C = /*#__PURE__*/ function() {
"use strict";
function C() {
_class_call_check(this, C);
}
_create_class(C, [
{
key: "m",
value: function m() {
var _this, _loop = function(x) {
console.log(_this, function(y) {
return y != x;
});
};
for(var x = 0; x < 10; x++)_this = this, _loop(x);
}
}
]);
return C;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1022_1.js | JavaScript | var _loop = function(i1) {
console.log(i1++, [
2
].every(function(x) {
return x != i1;
}));
i = i1, void 0;
};
for(var i = 0; i < 5; i++)_loop(i);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1022_2.js | JavaScript | var _loop = function(i1) {
console.log(i1++, [
2
].every(function(x) {
return x != i1;
}));
if (i1 % 2 === 0) return i = i1, "continue";
i = i1, void 0;
};
for(var i = 0; i < 5; i++)_loop(i);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1022_3.js | JavaScript | var _loop = function(i1) {
console.log(i1++, [
2
].every(function(x) {
return x != i1;
}));
if (i1 % 2 === 0) return i = i1, "break";
i = i1, void 0;
};
for(var i = 0; i < 5; i++){
var _ret = _loop(i);
if (_ret === "break") break;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1036_1.js | JavaScript | async function foo() {
await Promise.all([
[
1
],
[
2
],
[
3
]
].map(async function(param) {
var _param = _sliced_to_array(param, 1), a = _param[0];
return Promise.resolve().then(function() {
return a * 2;
});
}));
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1036_2.js | JavaScript | function foo() {
return _foo.apply(this, arguments);
}
function _foo() {
_foo = _async_to_generator(function() {
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
return [
4,
Promise.all([
[
1
],
[
2
],
[
3
]
].map(/*#__PURE__*/ function() {
var _ref = _async_to_generator(function(param) {
var _param, a;
return _ts_generator(this, function(_state) {
_param = _sliced_to_array(param, 1), a = _param[0];
return [
2,
Promise.resolve().then(function() {
return a * 2;
})
];
});
});
return function(_) {
return _ref.apply(this, arguments);
};
}()))
];
case 1:
_state.sent();
return [
2
];
}
});
});
return _foo.apply(this, arguments);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1231_1.js | JavaScript | function combineOverlappingMatches(matches) {
var _loop = function(i) {
var currentMatch = matches[i];
var overlap = matches.find((match)=>{
return match !== currentMatch && match.itemsType === currentMatch.itemsType;
});
if (overlap) {
hasOverlaps = true;
matches.splice(i, 1);
}
};
var hasOverlaps = false;
for(var i = matches.length - 1; i >= 0; i--)_loop(i);
if (hasOverlaps) {
combineOverlappingMatches(matches);
}
}
combineOverlappingMatches([
1
]);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1415_1.js | JavaScript | export function test(items) {
var _loop = function(i) {
var item = items[i];
var info = void 0;
switch(item.type){
case 'branch1':
info = item.method1();
break;
case 'branch2':
info = item.method2();
break;
case 'branch3':
info = item.method3(Object.fromEntries(item.subItems.map((t)=>[
item.alias ?? t.name,
getInfo(t)
])));
break;
default:
throw new Error('boom');
}
infoMap.set(item, info); // important
};
var infoMap = new WeakMap();
for(var i = 0; i < items.length; i += 1)_loop(i);
function getInfo(item) {
if (!infoMap.has(item)) {
throw new Error('no info yet');
}
return infoMap.get(item);
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_1462_1.js | JavaScript | export default function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
defineProperty(target, key, source[key]);
});
}
return target;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_2027_1.js | JavaScript | var _loop = function(key) {
controller[key] = (c, ...d)=>{
console.log(keys[key]);
};
};
var keys = {
a: 1,
b: 2
};
var controller = {};
for(var key in keys)_loop(key);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_2027_2.js | JavaScript | var _loop = function(key) {
controller[key] = function(c) {
for(var _len = arguments.length, d = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
d[_key - 1] = arguments[_key];
}
console.log(keys[key]);
};
};
var keys = {
a: 1,
b: 2
};
var controller = {};
for(var key in keys)_loop(key);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_2998_1.js | JavaScript | var a = 5;
for(var b = 0; b < a; b++){
var c = 0, b1 = 10, d = 100;
console.log(b1);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_2998_2.js | JavaScript | for(var a;;){}
for(var a = [
'a',
'b'
];;){}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_4196.js | JavaScript | var _loop = function(i) {
if (i === 0) return "continue";
if (i === 1) return "break";
[
1
].forEach((_)=>{
console.log(i);
});
};
for(var i = 0; i < 2; i++){
var _ret = _loop(i);
if (_ret === "break") break;
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_662.js | JavaScript | function foo(parts) {
var match = null;
for(var i = 1; i >= 0; i--){
for(var j = 0; j >= 0; j--){
match = parts[i][j];
if (match) {
break;
}
}
if (match) {
break;
}
}
return match;
}
foo();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/issue_686.js | JavaScript | module.exports = function(values) {
var vars = [];
var elem = null, name, val;
for(var i = 0; i < this.elements.length; i++){
elem = this.elements[i];
name = elem.name;
if (!name) continue;
val = values[name];
if (val == null) val = '';
switch(elem.type){
case 'submit':
break;
case 'radio':
case 'checkbox':
elem.checked = val.some(function(str) {
return str.toString() == elem.value;
});
break;
case 'select-multiple':
elem.fill(val);
break;
case 'textarea':
elem.innerText = val;
break;
case 'hidden':
break;
default:
if (elem.fill) {
elem.fill(val);
} else {
elem.value = val;
}
break;
}
}
return vars;
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_block_scoping.rs/labeled_break.js | JavaScript | var _loop = function(i) {
if (i === 0) return "continue|a";
if (i === 1) return "break|b";
[
1
].forEach((_)=>{
console.log(i);
});
};
a: b: for(var i = 0; i < 2; i++){
var _ret = _loop(i);
switch(_ret){
case "continue|a":
continue a;
case "break|b":
break b;
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/bigint_literial_methods.js | JavaScript | let Foo = /*#__PURE__*/ function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
_create_class(Foo, [
{
key: "1",
value: function() {}
},
{
key: "2",
get: function() {}
},
{
key: "3",
set: function(x) {}
}
]);
return Foo;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constant_super_call.js | JavaScript | let Test = /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Test, Foo);
function Test() {
_class_call_check(this, Test);
var _this;
_this = _call_super(this, Test);
Foo.prototype.test.whatever();
Foo.prototype.test.call(_assert_this_initialized(_this));
return _this;
}
_create_class(Test, null, [
{
key: "test",
value: function test() {
return Foo.wow.call(this);
}
}
]);
return Test;
}(Foo);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constant_super_class.js | JavaScript | let Test = /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Test, Foo);
function Test() {
_class_call_check(this, Test);
var _this;
woops.super.test();
_this = _call_super(this, Test);
Foo.prototype.test.call(_assert_this_initialized(_this));
_this = _call_super(this, Test, arguments);
_this = _call_super(this, Test, [
"test",
...arguments
]);
Foo.prototype.test.apply(_assert_this_initialized(_this), arguments);
Foo.prototype.test.call(_assert_this_initialized(_this), "test", ...arguments);
return _this;
}
return Test;
}(Foo);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constant_super_default.js | JavaScript | let Test = /*#__PURE__*/ function() {
"use strict";
function Test() {
_class_call_check(this, Test);
Object.prototype.hasOwnProperty.call(this, "test");
return Object.prototype.constructor;
}
_create_class(Test, null, [
{
key: "test",
value: function test() {
return Function.prototype.constructor;
}
}
]);
return Test;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constant_super_property.js | JavaScript | let Test = /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Test, Foo);
function Test() {
_class_call_check(this, Test);
var _this;
_this = _call_super(this, Test);
Foo.prototype.test;
Foo.prototype.test.whatever;
return _this;
}
return Test;
}(Foo);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constant_super_update.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
var _this;
_update(A.prototype, "foo", _this, true)._++;
_update(A.prototype, "bar", _this, true)._ += 123;
_update(A.prototype, baz, _this, true)._--;
_update(A.prototype, quz, _this, true)._ -= 456;
return _assert_this_initialized(_this);
}
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/constructor_super_update.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
var _this;
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), "foo", _this, true)._++;
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), "bar", _this, true)._ += 123;
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), baz, _this, true)._--;
_update((_assert_this_initialized(_this), _get_prototype_of(A.prototype)), quz, _this, true)._ -= 456;
return _assert_this_initialized(_this);
}
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/custom_native.js | JavaScript | let List = /*#__PURE__*/ function(Array) {
"use strict";
_inherits(List, Array);
function List() {
_class_call_check(this, List);
return _call_super(this, List, arguments);
}
return List;
}(_wrap_native_super(Array));
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/custom_singleton.js | JavaScript | let singleton;
let Sub = /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Sub, Foo);
function Sub() {
_class_call_check(this, Sub);
var _this;
if (singleton) {
return _possible_constructor_return(_this, singleton);
}
singleton = _this = _call_super(this, Sub);
return _this;
}
return Sub;
}(Foo);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/duplicate_ident.js | JavaScript | let Foo = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits(Foo, Bar1);
function Foo() {
_class_call_check(this, Foo);
var Foo1 = 123;
console.log(Foo1);
return _assert_this_initialized(void 0);
}
return Foo;
}(Bar);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_call_semantics_data_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
value: function test(...args) {
expect(this).toBe(obj);
expect(args).toEqual([
1,
2,
3
]);
return 1;
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "call",
value: function call() {
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, 1, 2, 3);
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, 1, ...[
2,
3
]);
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, ...[
1,
2,
3
]);
return _get(_get_prototype_of(Obj.prototype), "test", this).apply(this, arguments);
}
},
{
key: "test",
value: function test() {
throw new Error("called");
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(obj.call(1, 2, 3)).toBe(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_call_semantics_getter_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
get: function() {
expect(this).toBe(obj);
return function(...args) {
expect(this).toBe(obj);
expect(args).toEqual([
1,
2,
3
]);
return 1;
};
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "call",
value: function call() {
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, 1, 2, 3);
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, 1, ...[
2,
3
]);
_get(_get_prototype_of(Obj.prototype), "test", this).call(this, ...[
1,
2,
3
]);
return _get(_get_prototype_of(Obj.prototype), "test", this).apply(this, arguments);
}
},
{
key: "test",
value: function test() {
throw new Error("called");
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(obj.call(1, 2, 3)).toBe(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_call_semantics_not_defined_on_parent.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "call",
value: function call() {
return _get(_get_prototype_of(Obj.prototype), "test", this).call(this);
}
},
{
key: "test",
value: function test() {
throw new Error("gobbledygook");
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(()=>{
obj.call();
// Asser that this throws, but that it's not
// Obj.p.test's error that is thrown
}).toThrowError(TypeError);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_call_semantics_setter_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
set: function(v) {
throw new Error("gobbledygook");
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "call",
value: function call() {
return _get(_get_prototype_of(Obj.prototype), "test", this).call(this);
}
},
{
key: "test",
value: function test() {
throw new Error("gobbledygook");
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(()=>{
obj.call();
// Assert that this throws, but that it's not
// a gobbledygook error that is thrown
}).toThrowError(TypeError);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_get_semantics_data_defined_on_parent.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
Base.prototype.test = 1;
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "get",
value: function get() {
return _get(_get_prototype_of(Obj.prototype), "test", this);
}
}
]);
return Obj;
}(Base);
Obj.prototype.test = 2;
const obj = new Obj();
expect(obj.test).toBe(2);
expect(obj.get()).toBe(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_get_semantics_getter_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
get: function() {
expect(this).toBe(obj);
return 1;
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "get",
value: function get() {
return _get(_get_prototype_of(Obj.prototype), "test", this);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.test).toBe(2);
expect(obj.get()).toBe(1);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_get_semantics_not_defined_on_parent.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "get",
value: function get() {
return _get(_get_prototype_of(Obj.prototype), "test", this);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.test).toBe(2);
expect(obj.get()).toBeUndefined();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_get_semantics_setter_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
set: function(v) {
throw new Error("called");
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "get",
value: function get() {
return _get(_get_prototype_of(Obj.prototype), "test", this);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.test).toBe(2);
expect(obj.get()).toBeUndefined();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_memoized_assign.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
Object.defineProperty(Base.prototype, 0, {
value: 0,
writable: true,
configurable: true
});
Object.defineProperty(Base.prototype, 1, {
value: 1,
writable: true,
configurable: true
});
let i = 0;
const proper = {
get prop () {
return i++;
}
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "assign",
value: function assign() {
_update(_get_prototype_of(Obj.prototype), proper.prop, this, true)._ += 1;
}
},
{
key: "assign2",
value: function assign2() {
_update(_get_prototype_of(Obj.prototype), i, this, true)._ += 1;
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
obj.assign();
expect(i).toBe(1);
expect(obj[0]).toBe(1);
expect(obj[1]).toBe(1);
obj.assign2();
expect(i).toBe(1);
expect(obj[0]).toBe(1);
expect(obj[1]).toBe(2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_memoized_update.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
Object.defineProperty(Base.prototype, 0, {
value: 0,
writable: true,
configurable: true
});
Object.defineProperty(Base.prototype, 1, {
value: 1,
writable: true,
configurable: true
});
let i = 0;
const proper = {
get prop () {
return i++;
}
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "update",
value: function update() {
_update(_get_prototype_of(Obj.prototype), proper.prop, this, true)._++;
}
},
{
key: "update2",
value: function update2() {
_update(_get_prototype_of(Obj.prototype), i, this, true)._++;
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
obj.update();
expect(i).toBe(1);
expect(obj[0]).toBe(1);
expect(obj[1]).toBe(1);
obj.update2();
expect(i).toBe(1);
expect(obj[0]).toBe(1);
expect(obj[1]).toBe(2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_data_defined_on_parent.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
Object.defineProperty(Base.prototype, 'test', {
value: 1,
writable: true,
configurable: true
});
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(Base.prototype.test).toBe(1);
expect(Obj.prototype.test).toBe(2);
expect(obj.test).toBe(3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_getter_defined_on_parent.js | JavaScript | let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
get: function() {
return 1;
}
}
]);
return Base;
}();
;
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(()=>{
// this requires helpers to be in file (not external), so they
// are in "strict" mode code.
obj.set();
}).toThrow();
expect(Base.prototype.test).toBe(1);
expect(Obj.prototype.test).toBe(2);
expect(obj.test).toBe(2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_not_defined_on_parent_data_on_obj.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(Base.prototype.test).toBeUndefined();
expect(Obj.prototype.test).toBe(2);
expect(obj.test).toBe(3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_not_defined_on_parent_getter_on_obj.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "test",
get: function() {}
},
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(Base.prototype.test).toBeUndefined();
expect(Obj.prototype.test).toBeUndefined();
expect(obj.test).toBe(3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_not_defined_on_parent_not_on_obj.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(Base.prototype.test).toBeUndefined();
expect(Obj.prototype.test).toBeUndefined();
expect(obj.test).toBe(3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_not_defined_on_parent_setter_on_obj.js | JavaScript | let Base = function Base() {
"use strict";
_class_call_check(this, Base);
};
let value = 2;
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "test",
set: function(v) {
expect(this).toBe(obj);
value = v;
}
},
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(Base.prototype.test).toBeUndefined();
expect(Obj.prototype.test).toBeUndefined();
expect(value).toBe(2);
expect(obj.test).toBe(3);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/get_set_set_semantics_setter_defined_on_parent.js | JavaScript | let value = 1;
let Base = /*#__PURE__*/ function() {
"use strict";
function Base() {
_class_call_check(this, Base);
}
_create_class(Base, [
{
key: "test",
set: function(v) {
value = v;
}
}
]);
return Base;
}();
let Obj = /*#__PURE__*/ function(Base) {
"use strict";
_inherits(Obj, Base);
function Obj() {
_class_call_check(this, Obj);
return _call_super(this, Obj, arguments);
}
_create_class(Obj, [
{
key: "set",
value: function set() {
return _set(_get_prototype_of(Obj.prototype), "test", 3, this, true);
}
}
]);
return Obj;
}(Base);
Object.defineProperty(Obj.prototype, 'test', {
value: 2,
writable: true,
configurable: true
});
const obj = new Obj();
expect(obj.set()).toBe(3);
expect(value).toBe(3);
expect(Base.prototype.test).toBeUndefined();
expect(Obj.prototype.test).toBe(2);
expect(obj.test).toBe(2);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1490_1.js | JavaScript | let ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) {
"use strict";
_inherits(ColouredCanvasElement, CanvasElement);
function ColouredCanvasElement() {
_class_call_check(this, ColouredCanvasElement);
return _call_super(this, ColouredCanvasElement, arguments);
}
_create_class(ColouredCanvasElement, [
{
key: "createFacets",
value: function createFacets(hidden) {
hidden = _get(_get_prototype_of(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden);
}
}
]);
return ColouredCanvasElement;
}(CanvasElement);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1490_2.js | JavaScript | let ColouredCanvasElement = /*#__PURE__*/ function(CanvasElement) {
"use strict";
_inherits(ColouredCanvasElement, CanvasElement);
function ColouredCanvasElement() {
_class_call_check(this, ColouredCanvasElement);
return _call_super(this, ColouredCanvasElement, arguments);
}
_create_class(ColouredCanvasElement, [
{
key: "createFacets",
value: function createFacets(hidden) {
_get(_get_prototype_of(ColouredCanvasElement.prototype), "createFacets", this).call(this, hidden);
}
}
]);
return ColouredCanvasElement;
}(CanvasElement);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1617_1.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
return _call_super(this, A, arguments);
}
_create_class(A, [
{
key: "foo",
value: function foo() {
_get(_get_prototype_of(A.prototype), "foo", this).call(this), bar();
}
}
]);
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1617_2.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
return _call_super(this, A, arguments);
}
_create_class(A, [
{
key: "foo",
value: function foo() {
_get(_get_prototype_of(A.prototype), "foo", this).call(this);
}
}
]);
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1660_1.js | JavaScript | let A = function A() {
"use strict";
_class_call_check(this, A);
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1660_2.js | JavaScript | const foo = /*#__PURE__*/ function() {
"use strict";
function foo() {
_class_call_check(this, foo);
}
_create_class(foo, [
{
key: "run",
value: function run() {}
}
]);
return foo;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1660_3.js | JavaScript | console.log(/*#__PURE__*/ function() {
"use strict";
function _class() {
_class_call_check(this, _class);
}
_create_class(_class, [
{
key: "run",
value: function run() {}
}
]);
return _class;
}());
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1660_4.js | JavaScript | console.log(/*#__PURE__*/ function() {
"use strict";
function _class() {
_class_call_check(this, _class);
}
_create_class(_class, [
{
key: "run",
value: function run() {}
}
]);
return _class;
}());
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1660_5.js | JavaScript | console.log(/*#__PURE__*/ function() {
"use strict";
function _class() {
_class_call_check(this, _class);
}
_create_class(_class, [
{
key: "run",
value: function run() {}
}
]);
return _class;
}());
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1799_1.js | JavaScript | export default function Foo() {
return call(async (e)=>{
await doSomething();
});
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1838.js | JavaScript | let Foo = /*#__PURE__*/ function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
_create_class(Foo, [
{
key: "let",
value: function _let() {}
}
]);
return Foo;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_189.js | JavaScript | let HomePage = /*#__PURE__*/ function(_React_Component) {
"use strict";
_inherits(HomePage, _React_Component);
function HomePage() {
_class_call_check(this, HomePage);
return _call_super(this, HomePage, arguments);
}
return HomePage;
}(React.Component);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1959_1.js | JavaScript | var Extended = /*#__PURE__*/ function(Base1) {
"use strict";
_inherits(Extended, Base1);
function Extended() {
_class_call_check(this, Extended);
return _call_super(this, Extended, arguments);
}
_create_class(Extended, [
{
key: "getNext",
value: function getNext() {
return _get(_get_prototype_of(Extended.prototype), "getNext", this).call(this, 114514) + 114514;
}
}
]);
return Extended;
}(Base);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_1959_2.js | JavaScript | var Extended = /*#__PURE__*/ function(Base1) {
"use strict";
_inherits(Extended, Base1);
function Extended() {
_class_call_check(this, Extended);
return _call_super(this, Extended, arguments);
}
_create_class(Extended, [
{
key: "getNext",
value: function getNext() {
return _get(_get_prototype_of(Extended.prototype), "getNext", this).call(this, 114514);
}
}
]);
return Extended;
}(Base);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_3943.js | JavaScript | let Thing = /*#__PURE__*/ function(B) {
"use strict";
_inherits(Thing, B);
function Thing(n) {
_class_call_check(this, Thing);
var _this;
_this = B.call(this) || this;
_this.name = n;
return _this;
}
return Thing;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_454_followup.js | JavaScript | if (true) {
var Foo = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits(Foo, Bar1);
function Foo() {
_class_call_check(this, Foo);
return _call_super(this, Foo, arguments);
}
return Foo;
}(Bar);
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_454_followup_2.js | JavaScript | function broken(x, ...foo) {
if (true) {
var Foo = /*#__PURE__*/ function(Bar1) {
"use strict";
_inherits(Foo, Bar1);
function Foo() {
_class_call_check(this, Foo);
return _call_super(this, Foo, arguments);
}
return Foo;
}(Bar);
return hello.apply(void 0, _to_consumable_array(foo));
}
}
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/issue_5102.js | JavaScript | var C = function C() {
"use strict";
_class_call_check(this, C);
};
D = function D() {
"use strict";
_class_call_check(this, D);
};
C ||= function C() {
"use strict";
_class_call_check(this, C);
};
D ??= function D() {
"use strict";
_class_call_check(this, D);
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/nested_this_in_key.js | JavaScript | let Outer = /*#__PURE__*/ function(B) {
"use strict";
_inherits(Outer, B);
function Outer() {
_class_call_check(this, Outer);
var _this;
let Inner = /*#__PURE__*/ function() {
function Inner() {
_class_call_check(this, Inner);
}
_create_class(Inner, [
{
key: _assert_this_initialized(_this),
value: function() {
return 'hello';
}
}
]);
return Inner;
}();
function foo() {
return this;
}
return _possible_constructor_return(_this, new Inner());
}
return Outer;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/no_class_call.js | JavaScript | let A = function A() {
"use strict";
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/no_class_call_constructor.js | JavaScript | let A = function A() {
"use strict";
console.log('a');
};
let B = /*#__PURE__*/ function() {
"use strict";
function B() {}
_create_class(B, [
{
key: "b",
value: function b() {
console.log('b');
}
}
]);
return B;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/no_class_call_super.js | JavaScript | let B = function B() {
"use strict";
};
let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A(track) {
var _this;
if (track !== undefined) _this = _call_super(this, A, [
track
]);
else _this = _call_super(this, A);
return _assert_this_initialized(_this);
}
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/prefix_super_update.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
return _call_super(this, A, arguments);
}
_create_class(A, [
{
key: "foo",
value: function foo() {
--_update(_get_prototype_of(A.prototype), baz, this, true)._;
}
}
]);
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_5769.js | JavaScript | let Point = /*#__PURE__*/ function() {
"use strict";
function Point() {
_class_call_check(this, Point);
}
_create_class(Point, [
{
key: "getX",
value: function getX() {
expect(this.x).toBe(3); // C
}
}
]);
return Point;
}();
let ColorPoint = /*#__PURE__*/ function(Point) {
"use strict";
_inherits(ColorPoint, Point);
function ColorPoint() {
_class_call_check(this, ColorPoint);
var _this;
_this = _call_super(this, ColorPoint);
_this.x = 2;
_set((_assert_this_initialized(_this), _get_prototype_of(ColorPoint.prototype)), "x", 3, _this, true);
expect(_this.x).toBe(3); // A
expect(_get((_assert_this_initialized(_this), _get_prototype_of(ColorPoint.prototype)), "x", _this)).toBeUndefined(); // B
return _this;
}
_create_class(ColorPoint, [
{
key: "m",
value: function m() {
this.getX();
}
}
]);
return ColorPoint;
}(Point);
const cp = new ColorPoint();
cp.m();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_5817.js | JavaScript | let A = /*#__PURE__*/ function(B) {
"use strict";
_inherits(A, B);
function A() {
_class_call_check(this, A);
var _this;
_this = _call_super(this, A);
_this.arrow1 = function(x) {
return x;
};
_this.arrow2 = function(x) {
return x;
};
return _this;
}
return A;
}(B);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_8499.js | JavaScript | // Pretend that `Reflect.construct` isn't supported.
this.Reflect = undefined;
this.HTMLElement = function() {
// Here, `this.HTMLElement` is this function, not the original HTMLElement
// constructor. `this.constructor` should be this function too, but isn't.
constructor = this.constructor;
};
var constructor;
let CustomElement = /*#__PURE__*/ function(HTMLElement) {
"use strict";
_inherits(CustomElement, HTMLElement);
function CustomElement() {
_class_call_check(this, CustomElement);
return _call_super(this, CustomElement, arguments);
}
return CustomElement;
}(_wrap_native_super(HTMLElement));
;
new CustomElement();
expect(constructor).toBe(CustomElement);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_t2494.js | JavaScript | var x = {
Foo: /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Foo1, Foo);
function Foo1() {
_class_call_check(this, Foo1);
return _call_super(this, Foo1, arguments);
}
return Foo1;
}(Foo)
};
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_t2997.js | JavaScript | let A = function A() {
"use strict";
_class_call_check(this, A);
};
let B = /*#__PURE__*/ function(A) {
"use strict";
_inherits(B, A);
function B() {
_class_call_check(this, B);
var _this;
return _possible_constructor_return(_this, _this = _call_super(this, B));
}
return B;
}(A);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/regression_t6712.js | JavaScript | let A = /*#__PURE__*/ function() {
"use strict";
function A() {
_class_call_check(this, A);
}
_create_class(A, [
{
key: "foo",
value: function foo() {
const foo = 2;
}
}
]);
return A;
}();
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University | |
crates/swc_ecma_transforms_compat/tests/__swc_snapshots__/tests/es2015_classes.rs/set_method_getter_setter.js | JavaScript | let Test = /*#__PURE__*/ function(Foo) {
"use strict";
_inherits(Test, Foo);
function Test() {
_class_call_check(this, Test);
return _call_super(this, Test, arguments);
}
_create_class(Test, [
{
key: "foo",
get: function() {},
set: function(a) {}
}
]);
return Test;
}(Foo);
| willcrichton/ilc-swc | 1 | Rust | willcrichton | Will Crichton | Brown University |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.