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_proposal/src/export_default_from.rs
Rust
use swc_common::DUMMY_SP; use swc_ecma_ast::*; use swc_ecma_utils::quote_ident; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; /// `@babel/plugin-proposal-export-default-from` pub fn export_default_from() -> impl Pass { visit_mut_pass(ExportDefaultFrom) } struct ExportDefaultFrom; impl VisitMut for ExportDefaultFrom { noop_visit_mut_type!(); fn visit_mut_module_items(&mut self, items: &mut Vec<ModuleItem>) { let count = items .iter() .filter(|m| { matches!(m, ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { specifiers, src: Some(..), type_only: false, .. })) if specifiers.iter().any(|s| s.is_default())) }) .count(); if count == 0 { return; } let mut stmts = Vec::<ModuleItem>::with_capacity(items.len() + count); for item in items.drain(..) { match item { ModuleItem::ModuleDecl(ModuleDecl::ExportNamed(NamedExport { span, specifiers, src: Some(src), type_only: false, with, })) if specifiers.iter().any(|s| s.is_default()) => { let mut origin_specifiers = Vec::new(); let mut export_specifiers = Vec::new(); let mut has_namespace = false; for s in specifiers.into_iter() { match s { ExportSpecifier::Default(ExportDefaultSpecifier { exported }) => { export_specifiers.push(ExportSpecifier::Named( ExportNamedSpecifier { span: DUMMY_SP, orig: quote_ident!(exported.ctxt, exported.span, "default") .into(), exported: Some(exported.into()), is_type_only: false, }, )); } ExportSpecifier::Namespace(..) => { has_namespace = true; origin_specifiers.push(s); } ExportSpecifier::Named(..) => { if has_namespace { origin_specifiers.push(s); } else { export_specifiers.push(s); } } } } stmts.push( NamedExport { span, specifiers: export_specifiers, src: Some(src.clone()), type_only: false, with: None, } .into(), ); if !origin_specifiers.is_empty() { stmts.push( NamedExport { span, specifiers: origin_specifiers, src: Some(src), type_only: false, with, } .into(), ); } } _ => { stmts.push(item); } } } *items = stmts; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/src/import_attributes.rs
Rust
use swc_ecma_ast::{ExportAll, ImportDecl, NamedExport, Pass}; use swc_ecma_visit::{noop_visit_mut_type, visit_mut_pass, VisitMut}; pub fn import_attributes() -> impl Pass { visit_mut_pass(ImportAssertions) } struct ImportAssertions; impl VisitMut for ImportAssertions { noop_visit_mut_type!(); fn visit_mut_import_decl(&mut self, n: &mut ImportDecl) { n.with = None; } fn visit_mut_export_all(&mut self, n: &mut ExportAll) { n.with = None; } fn visit_mut_named_export(&mut self, n: &mut NamedExport) { n.with = None; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/src/lib.rs
Rust
#![deny(clippy::all)] #![allow(clippy::vec_box)] use serde::{Deserialize, Serialize}; pub use self::{ decorators::decorators, export_default_from::export_default_from, import_attributes::import_attributes, }; #[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] #[serde(deny_unknown_fields, rename_all = "camelCase")] pub enum DecoratorVersion { #[default] #[serde(rename = "2021-12")] V202112, #[serde(rename = "2022-03")] V202203, #[serde(rename = "2023-11")] V202311, } pub mod decorator_2022_03; mod decorator_impl; pub mod decorators; pub mod explicit_resource_management; mod export_default_from; mod import_attributes;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/export.rs/default_compounded_es6.js
JavaScript
export { default as v, x, y as w } from "mod";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/export.rs/default_es6.js
JavaScript
export { default as foo } from "bar";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/export.rs/namespace_compound_es6.js
JavaScript
import * as _foo from 'bar'; export { _foo as foo }; export { bar } from 'bar';
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/export.rs/namespace_default.js
JavaScript
import * as _default from 'foo'; export { _default as default };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/export.rs/namespace_es6.js
JavaScript
import * as _foo from 'bar'; export { _foo as foo };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/import_assertions.rs/export_all_with_assertions.js
JavaScript
export * from "./test.json";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/import_assertions.rs/import_with_assertions.js
JavaScript
import test from "./test.json";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/import_assertions.rs/named_export_with_assertions.js
JavaScript
export { default as test } from "./test.json";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/__swc_snapshots__/tests/import_assertions.rs/side_effect_import_with_assertions.js
JavaScript
import "./test.json";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Basic-instance-auto-accessor.js
JavaScript
(() => { const dec = (key, getName, setName) => (target, ctx) => { assertEq(() => typeof target.get, 'function'); assertEq(() => typeof target.set, 'function'); assertEq(() => target.get.name, getName); assertEq(() => target.set.name, setName); assertEq(() => ctx.kind, 'accessor'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, false); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => { const obj = {}; ctx.access.set(obj, 123); return obj[key]; }, 123); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { @dec('foo', 'get foo', 'set foo') accessor foo = 0; @dec(bar, 'get [bar]', 'set [bar]') accessor [bar] = 0; @dec(baz, 'get ', 'set ') accessor [baz] = 0; } var obj = new Foo; obj.foo = 321; assertEq(() => obj.foo, 321); obj[bar] = 4321; assertEq(() => obj[bar], 4321); obj[baz] = 54321; assertEq(() => obj[baz], 54321); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Basic-private-instance-auto-accessor.js
JavaScript
(() => { let lateAsserts; const dec = (target, ctx) => { assertEq(() => typeof target.get, 'function'); assertEq(() => typeof target.set, 'function'); assertEq(() => target.get.name, 'get #foo'); assertEq(() => target.set.name, 'set #foo'); assertEq(() => ctx.kind, 'accessor'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, false); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(new Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(new Foo), 0); assertEq(() => { const obj = new Foo; ctx.access.set(obj, 123); return get$foo(obj); }, 123); }; }; let get$foo; let set$foo; class Foo { @dec accessor #foo = 0; static { get$foo = x => x.#foo; set$foo = (x, y) => { x.#foo = y; }; } } lateAsserts(); var obj = new Foo; assertEq(() => set$foo(obj, 321), undefined); assertEq(() => get$foo(obj), 321); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Basic-private-static-auto-accessor.js
JavaScript
(() => { let lateAsserts; const dec = (target, ctx) => { assertEq(() => typeof target.get, 'function'); assertEq(() => typeof target.set, 'function'); assertEq(() => target.get.name, 'get #foo'); assertEq(() => target.set.name, 'set #foo'); assertEq(() => ctx.kind, 'accessor'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, true); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(Foo), 0); assertEq(() => { ctx.access.set(Foo, 123); return get$foo(Foo); }, 123); }; }; let get$foo; let set$foo; class Foo { @dec static accessor #foo = 0; static { get$foo = x => x.#foo; set$foo = (x, y) => { x.#foo = y; }; } } lateAsserts(); assertEq(() => set$foo(Foo, 321), undefined); assertEq(() => get$foo(Foo), 321); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Basic-static-auto-accessor.js
JavaScript
(() => { const dec = (key, getName, setName) => (target, ctx) => { assertEq(() => typeof target.get, 'function'); assertEq(() => typeof target.set, 'function'); assertEq(() => target.get.name, getName); assertEq(() => target.set.name, setName); assertEq(() => ctx.kind, 'accessor'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, true); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => { const obj = {}; ctx.access.set(obj, 123); return obj[key]; }, 123); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { @dec('foo', 'get foo', 'set foo') static accessor foo = 0; @dec(bar, 'get [bar]', 'set [bar]') static accessor [bar] = 0; @dec(baz, 'get ', 'set ') static accessor [baz] = 0; } Foo.foo = 321; assertEq(() => Foo.foo, 321); Foo[bar] = 4321; assertEq(() => Foo[bar], 4321); Foo[baz] = 54321; assertEq(() => Foo[baz], 54321); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Extra-initializer-instance-auto-accessor.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (target, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec accessor foo; } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Extra-initializer-private-instance-auto-accessor.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (target, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec accessor #foo; } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Extra-initializer-private-static-auto-accessor.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (target, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static accessor #foo; } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Extra-initializer-static-auto-accessor.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (target, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static accessor foo; } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Return-null-instance-auto-accessor.js
JavaScript
(() => { assertThrows(() => { const dec = (target, ctx) => { return null; }; class Foo { @dec accessor foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Return-null-private-instance-auto-accessor.js
JavaScript
(() => { assertThrows(() => { const dec = (target, ctx) => { return null; }; class Foo { @dec accessor #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Return-null-private-static-auto-accessor.js
JavaScript
(() => { assertThrows(() => { const dec = (target, ctx) => { return null; }; class Foo { @dec static accessor #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Return-null-static-auto-accessor.js
JavaScript
(() => { assertThrows(() => { const dec = (target, ctx) => { return null; }; class Foo { @dec static accessor foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Shim-instance-auto-accessor.js
JavaScript
(() => { let get; let set; const dec = (target, ctx) => { function init(x) { assertEq(() => this instanceof Foo, true); return x + 1; } get = function () { return target.get.call(this) * 10; }; set = function (x) { target.set.call(this, x * 2); }; return { get, set, init }; }; class Foo { @dec accessor foo = 123; } assertEq(() => Object.getOwnPropertyDescriptor(Foo.prototype, 'foo').get, get); assertEq(() => Object.getOwnPropertyDescriptor(Foo.prototype, 'foo').set, set); var obj = new Foo; assertEq(() => obj.foo, (123 + 1) * 10); obj.foo = 321; assertEq(() => obj.foo, (321 * 2) * 10); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Shim-private-instance-auto-accessor.js
JavaScript
(() => { let get; let set; const dec = (target, ctx) => { function init(x) { assertEq(() => this instanceof Foo, true); return x + 1; } get = function () { return target.get.call(this) * 10; }; set = function (x) { target.set.call(this, x * 2); }; return { get, set, init }; }; let get$foo; let set$foo; class Foo { @dec accessor #foo = 123; static { get$foo = x => x.#foo; set$foo = (x, y) => { x.#foo = y; }; } } var obj = new Foo; assertEq(() => get$foo(obj), (123 + 1) * 10); assertEq(() => set$foo(obj, 321), undefined); assertEq(() => get$foo(obj), (321 * 2) * 10); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Shim-private-static-auto-accessor.js
JavaScript
(() => { let foo; let get; let set; const dec = (target, ctx) => { function init(x) { assertEq(() => this, foo); return x + 1; } get = function () { return target.get.call(this) * 10; }; set = function (x) { target.set.call(this, x * 2); }; return { get, set, init }; }; let get$foo; let set$foo; class Foo { static { foo = Foo; get$foo = x => x.#foo; set$foo = (x, y) => { x.#foo = y; }; } @dec static accessor #foo = 123; } assertEq(() => get$foo(Foo), (123 + 1) * 10); assertEq(() => set$foo(Foo, 321), undefined); assertEq(() => get$foo(Foo), (321 * 2) * 10); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Auto-accessor-decorators-Shim-static-auto-accessor.js
JavaScript
(() => { let foo; let get; let set; const dec = (target, ctx) => { function init(x) { assertEq(() => this, foo); return x + 1; } get = function () { return target.get.call(this) * 10; }; set = function (x) { target.set.call(this, x * 2); }; return { get, set, init }; }; class Foo { static { foo = Foo; } @dec static accessor foo = 123; } assertEq(() => Object.getOwnPropertyDescriptor(Foo, 'foo').get, get); assertEq(() => Object.getOwnPropertyDescriptor(Foo, 'foo').set, set); assertEq(() => Foo.foo, (123 + 1) * 10); Foo.foo = 321; assertEq(() => Foo.foo, (321 * 2) * 10); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Anonymous.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; const Foo = (x => x)( @dec('') class { }); assertEq(() => Foo, old); const Bar = (x => x)( @dec('Baz') class Baz { }); assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Array-binding.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; const [Foo = @dec('Foo') class { }] = []; assertEq(() => Foo, old); const [Bar = @dec('Baz') class Baz { }] = []; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Assignment-array-binding.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; let Foo; [Foo = @dec('Foo') class { }] = []; assertEq(() => Foo, old); let Bar; [Bar = @dec('Baz') class Baz { }] = []; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Assignment-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; let Foo; Foo = @dec('Foo') class { }; assertEq(() => Foo, old); let Bar; Bar = @dec('Baz') class Baz { }; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Assignment-object-binding.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; let Foo; ({ Foo = @dec('Foo') class { } } = {}); assertEq(() => Foo, old); let Bar; ({ Bar = @dec('Baz') class Baz { } } = {}); assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Instance-auto-accessor-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; class Class { accessor Foo = @dec('Foo') class { }; } const Foo = new Class().Foo; assertEq(() => Foo, old); class Class2 { accessor Bar = @dec('Baz') class Baz { }; } const Bar = new Class2().Bar; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Instance-field-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; class Class { Foo = @dec('Foo') class { }; } const Foo = new Class().Foo; assertEq(() => Foo, old); class Class2 { Bar = @dec('Baz') class Baz { }; } const Bar = new Class2().Bar; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Object-binding.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; const { Foo = @dec('Foo') class { } } = {}; assertEq(() => Foo, old); const { Bar = @dec('Baz') class Baz { } } = {}; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Property-value.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; const obj = { Foo: @dec('Foo') class { }, }; assertEq(() => obj.Foo, old); const obj2 = { Bar: @dec('Baz') class Baz { }, }; assertEq(() => obj2.Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Static-auto-accessor-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; class Class { static accessor Foo = @dec('Foo') class { }; } assertEq(() => Class.Foo, old); class Class2 { static accessor Bar = @dec('Baz') class Baz { }; } assertEq(() => Class2.Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Static-field-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; class Class { static Foo = @dec('Foo') class { }; } assertEq(() => Class.Foo, old); class Class2 { static Bar = @dec('Baz') class Baz { }; } assertEq(() => Class2.Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-expression-Variable-initializer.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; const Foo = @dec('Foo') class { }; assertEq(() => Foo, old); const Bar = @dec('Baz') class Baz { }; assertEq(() => Bar, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Basic-statement.js
JavaScript
(() => { let old; const dec = (name) => (cls, ctx) => { assertEq(() => typeof cls, 'function'); assertEq(() => cls.name, name); assertEq(() => ctx.kind, 'class'); assertEq(() => ctx.name, name); assertEq(() => 'static' in ctx, false); assertEq(() => 'private' in ctx, false); assertEq(() => 'access' in ctx, false); old = cls; }; @dec('Foo') class Foo { } assertEq(() => Foo, old); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-expression.js
JavaScript
(() => { let old; let block; class Bar { } const dec = (cls, ctx) => { old = cls; return Bar; }; const Foo = @dec class Foo { static { block = Foo; } method() { return Foo; } static method() { return Foo; } field = Foo; static field = Foo; get getter() { return Foo; } static get getter() { return Foo; } set setter(x) { x.foo = Foo; } static set setter(x) { x.foo = Foo; } accessor accessor = Foo; static accessor accessor = Foo; }; const foo = new old; let obj; assertEq(() => Foo !== old, true); assertEq(() => Foo, Bar); assertEq(() => block, Bar); assertEq(() => Foo.field, Bar); assertEq(() => foo.field, Bar); assertEq(() => old.getter, Bar); assertEq(() => foo.getter, Bar); assertEq(() => (obj = { foo: null }, old.setter = obj, obj.foo), Bar); assertEq(() => (obj = { foo: null }, foo.setter = obj, obj.foo), Bar); // The specification for accessors is potentially wrong at the moment: https://github.com/tc39/proposal-decorators/issues/529 // assertEq(() => old.accessor, Bar) // assertEq(() => foo.accessor, Bar) })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Binding-initialization-class-statement.js
JavaScript
(() => { let old; let block; class Bar { } const dec = (cls, ctx) => { old = cls; return Bar; }; @dec class Foo { static { block = Foo; } method() { return Foo; } static method() { return Foo; } field = Foo; static field = Foo; get getter() { return Foo; } static get getter() { return Foo; } set setter(x) { x.foo = Foo; } static set setter(x) { x.foo = Foo; } accessor accessor = Foo; static accessor accessor = Foo; } const foo = new old; let obj; assertEq(() => Foo !== old, true); assertEq(() => Foo, Bar); assertEq(() => block, Bar); assertEq(() => Foo.field, Bar); assertEq(() => foo.field, Bar); assertEq(() => old.getter, Bar); assertEq(() => foo.getter, Bar); assertEq(() => (obj = { foo: null }, old.setter = obj, obj.foo), Bar); assertEq(() => (obj = { foo: null }, foo.setter = obj, obj.foo), Bar); // The specification for accessors is potentially wrong at the moment: https://github.com/tc39/proposal-decorators/issues/529 // assertEq(() => old.accessor, Bar) // assertEq(() => foo.accessor, Bar) })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Extra-initializer.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (cls, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; @dec @dec class Foo { } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Order.js
JavaScript
(() => { const log = []; let Bar; let Baz; const dec1 = (cls, ctx) => { log.push(2); Bar = function () { log.push(4); return new cls; }; return Bar; }; const dec2 = (cls, ctx) => { log.push(1); Baz = function () { log.push(5); return new cls; }; return Baz; }; log.push(0); @dec1 @dec2 class Foo { constructor() { log.push(6); } } log.push(3); new Foo; log.push(7); assertEq(() => Foo, Bar); assertEq(() => log + '', '0,1,2,3,4,5,6,7'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Return-null.js
JavaScript
(() => { assertThrows(() => { const dec = (cls, ctx) => { return null; }; @dec class Foo { } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Class-decorators-Return-object.js
JavaScript
(() => { assertThrows(() => { const dec = (cls, ctx) => { return {}; }; @dec class Foo { } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Class-binding-class-expression.js
JavaScript
(() => { const fns = []; const capture = (fn) => { fns.push(fn); return () => { }; }; const originalFoo = ( @(capture(() => Foo)) class Foo { @(capture(() => Foo)) method() { } @(capture(() => Foo)) static method() { } @(capture(() => Foo)) field; @(capture(() => Foo)) static field; @(capture(() => Foo)) get getter() { return; } @(capture(() => Foo)) static get getter() { return; } @(capture(() => Foo)) set setter(x) { } @(capture(() => Foo)) static set setter(x) { } @(capture(() => Foo)) accessor accessor; @(capture(() => Foo)) static accessor accessor; }); // Decorators on the class itself should reference a global called "Foo", // which should still be a reference error. This is because a class // expression runs "DecoratorListEvaluation" in the outer environment and // then passes the evaluated decorators to "ClassDefinitionEvaluation". const firstFn = fns.shift(); assertThrows(() => firstFn(), ReferenceError); // All other decorators should reference the classBinding called "Foo", // which should now be initialized. This is because all other decorators // are evaluated within "ClassDefinitionEvaluation" while the running // execution context's environment is the nested class environment. for (const fn of fns) { assertEq(() => fn(), originalFoo); } })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Class-binding-class-statement.js
JavaScript
(() => { const fns = []; const capture = (fn) => { fns.push(fn); // Note: As far as I can tell, early reference to the class name should // throw a reference error because: // // 1. Class decorators run first in the top-level scope before entering // BindingClassDeclarationEvaluation. // // 2. Class element decorators run in ClassDefinitionEvaluation, which // runs ClassElementEvaluation for each class element before eventually // running classEnv.InitializeBinding(classBinding, F). // assertThrows(() => fn(), ReferenceError); return () => { }; }; @(capture(() => Foo)) class Foo { @(capture(() => Foo)) method() { } @(capture(() => Foo)) static method() { } @(capture(() => Foo)) field; @(capture(() => Foo)) static field; @(capture(() => Foo)) get getter() { return; } @(capture(() => Foo)) static get getter() { return; } @(capture(() => Foo)) set setter(x) { } @(capture(() => Foo)) static set setter(x) { } @(capture(() => Foo)) accessor accessor; @(capture(() => Foo)) static accessor accessor; } const originalFoo = Foo; // Once we get here, these should all reference the now-initialized class, // either through classBinding (for class element decorators) or through // className (for decorators on the class itself). for (const fn of fns) { assertEq(() => fn(), originalFoo); } // Mutating a class binding is allowed in JavaScript. Let's test what // happens when we do this. Foo = null; // As far as I can tell, class decorators should observe this change because // they are evaluated in the top-level scope. const firstFn = fns.shift(); assertEq(() => firstFn(), null); // But I believe class element decorators should not observe this change // because they are evaluated in the environment that exists for the // duration of ClassDefinitionEvaluation (i.e. classEnv, not env). for (const fn of fns) { assertEq(() => fn(), originalFoo); } })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Computed-names-class-expression.js
JavaScript
(() => { const log = []; const foo = (n) => { log.push(n); return () => { }; }; const computed = { get method() { log.push(log.length); return Symbol('method'); }, get field() { log.push(log.length); return Symbol('field'); }, get getter() { log.push(log.length); return Symbol('getter'); }, get setter() { log.push(log.length); return Symbol('setter'); }, get accessor() { log.push(log.length); return Symbol('accessor'); }, }; ( @foo(0) class extends (foo(1), Object) { @foo(2) [computed.method]() { } @foo(4) static [computed.method]() { } @foo(6) [computed.field]; @foo(8) static [computed.field]; @foo(10) get [computed.getter]() { return; } @foo(12) static get [computed.getter]() { return; } @foo(14) set [computed.setter](x) { } @foo(16) static set [computed.setter](x) { } @foo(18) accessor [computed.accessor]; @foo(20) static accessor [computed.accessor]; }); assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Computed-names-class-statement.js
JavaScript
(() => { const log = []; const foo = (n) => { log.push(n); return () => { }; }; const computed = { get method() { log.push(log.length); return Symbol('method'); }, get field() { log.push(log.length); return Symbol('field'); }, get getter() { log.push(log.length); return Symbol('getter'); }, get setter() { log.push(log.length); return Symbol('setter'); }, get accessor() { log.push(log.length); return Symbol('accessor'); }, }; @foo(0) class Foo extends (foo(1), Object) { @foo(2) [computed.method]() { } @foo(4) static [computed.method]() { } @foo(6) [computed.field]; @foo(8) static [computed.field]; @foo(10) get [computed.getter]() { return; } @foo(12) static get [computed.getter]() { return; } @foo(14) set [computed.setter](x) { } @foo(16) static set [computed.setter](x) { } @foo(18) accessor [computed.accessor]; @foo(20) static accessor [computed.accessor]; } assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Inner-private-name-class-expression.js
JavaScript
(() => { const fns = []; const capture = (fn) => { fns.push(fn); return () => { }; }; class Outer { static #foo = 0; static { ( @(capture(() => Outer.#foo + 0)) class Foo { #foo = 10; @(capture(() => new Foo().#foo + 1)) method() { } @(capture(() => new Foo().#foo + 2)) static method() { } @(capture(() => new Foo().#foo + 3)) field; @(capture(() => new Foo().#foo + 4)) static field; @(capture(() => new Foo().#foo + 5)) get getter() { return; } @(capture(() => new Foo().#foo + 6)) static get getter() { return; } @(capture(() => new Foo().#foo + 7)) set setter(x) { } @(capture(() => new Foo().#foo + 8)) static set setter(x) { } @(capture(() => new Foo().#foo + 9)) accessor accessor; @(capture(() => new Foo().#foo + 10)) static accessor accessor; }); } } // Accessing the outer "#foo" on "Outer" from within the class decorator // should succeed. Class decorators are evaluated in the outer private // environment before entering "ClassDefinitionEvaluation". // // Accessing the inner "#foo" on "Foo" from within any of the class element // decorators should also succeed. Class element decorators are evaluated // in the inner private environment inside "ClassDefinitionEvaluation". const log = []; for (const fn of fns) log.push(fn()); assertEq(() => '' + log, '0,11,12,13,14,15,16,17,18,19,20'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Inner-private-name-class-statement.js
JavaScript
(() => { const fns = []; const capture = (fn) => { fns.push(fn); return () => { }; }; class Dummy { static #foo = NaN; static { @(capture(() => new Foo().#foo + 0)) class Foo { #foo = 10; @(capture(() => new Foo().#foo + 1)) method() { } @(capture(() => new Foo().#foo + 2)) static method() { } @(capture(() => new Foo().#foo + 3)) field; @(capture(() => new Foo().#foo + 4)) static field; @(capture(() => new Foo().#foo + 5)) get getter() { return; } @(capture(() => new Foo().#foo + 6)) static get getter() { return; } @(capture(() => new Foo().#foo + 7)) set setter(x) { } @(capture(() => new Foo().#foo + 8)) static set setter(x) { } @(capture(() => new Foo().#foo + 9)) accessor accessor; @(capture(() => new Foo().#foo + 10)) static accessor accessor; } } } // Accessing "#foo" in the class decorator should fail. The "#foo" should // refer to the outer "#foo", not the inner "#foo". const firstFn = fns.shift(); assertEq(() => { try { firstFn(); throw new Error('Expected a TypeError to be thrown'); } catch (err) { if (err instanceof TypeError) return true; throw err; } }, true); // Accessing "#foo" from any of the class element decorators should succeed. // Each "#foo" should refer to the inner "#foo", not the outer "#foo". const log = []; for (const fn of fns) log.push(fn()); assertEq(() => '' + log, '11,12,13,14,15,16,17,18,19,20'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Outer-private-name-class-expression.js
JavaScript
(() => { const log = []; class Dummy { static #foo(n) { log.push(n); return () => { }; } static { const dummy = this; ( @(dummy.#foo(0)) class extends (dummy.#foo(1), Object) { @(dummy.#foo(2)) method() { } @(dummy.#foo(3)) static method() { } @(dummy.#foo(4)) field; @(dummy.#foo(5)) static field; @(dummy.#foo(6)) get getter() { return; } @(dummy.#foo(7)) static get getter() { return; } @(dummy.#foo(8)) set setter(x) { } @(dummy.#foo(9)) static set setter(x) { } @(dummy.#foo(10)) accessor accessor; @(dummy.#foo(11)) static accessor accessor; }); } } assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-Outer-private-name-class-statement.js
JavaScript
(() => { const log = []; class Dummy { static #foo(n) { log.push(n); return () => { }; } static { const dummy = this; @(dummy.#foo(0)) class Foo extends (dummy.#foo(1), Object) { @(dummy.#foo(2)) method() { } @(dummy.#foo(3)) static method() { } @(dummy.#foo(4)) field; @(dummy.#foo(5)) static field; @(dummy.#foo(6)) get getter() { return; } @(dummy.#foo(7)) static get getter() { return; } @(dummy.#foo(8)) set setter(x) { } @(dummy.#foo(9)) static set setter(x) { } @(dummy.#foo(10)) accessor accessor; @(dummy.#foo(11)) static accessor accessor; } } } assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-await-class-expression.js
JavaScript
(async () => { const log = []; const dummy = () => { }; async function wrapper() { ( @(log.push(await Promise.resolve(0)), dummy) class extends (log.push(await Promise.resolve(1)), Object) { @(log.push(await Promise.resolve(2)), dummy) method() { } @(log.push(await Promise.resolve(3)), dummy) static method() { } @(log.push(await Promise.resolve(4)), dummy) field; @(log.push(await Promise.resolve(5)), dummy) static field; @(log.push(await Promise.resolve(6)), dummy) get getter() { return; } @(log.push(await Promise.resolve(7)), dummy) static get getter() { return; } @(log.push(await Promise.resolve(8)), dummy) set setter(x) { } @(log.push(await Promise.resolve(9)), dummy) static set setter(x) { } @(log.push(await Promise.resolve(10)), dummy) accessor accessor; @(log.push(await Promise.resolve(11)), dummy) static accessor accessor; }); } await wrapper(); assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-await-class-statement.js
JavaScript
(async () => { const log = []; const dummy = () => { }; async function wrapper() { @(log.push(await Promise.resolve(0)), dummy) class Foo extends (log.push(await Promise.resolve(1)), Object) { @(log.push(await Promise.resolve(2)), dummy) method() { } @(log.push(await Promise.resolve(3)), dummy) static method() { } @(log.push(await Promise.resolve(4)), dummy) field; @(log.push(await Promise.resolve(5)), dummy) static field; @(log.push(await Promise.resolve(6)), dummy) get getter() { return; } @(log.push(await Promise.resolve(7)), dummy) static get getter() { return; } @(log.push(await Promise.resolve(8)), dummy) set setter(x) { } @(log.push(await Promise.resolve(9)), dummy) static set setter(x) { } @(log.push(await Promise.resolve(10)), dummy) accessor accessor; @(log.push(await Promise.resolve(11)), dummy) static accessor accessor; } } await wrapper(); assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-this-class-expression.js
JavaScript
(() => { const log = []; const dummy = () => { }; const ctx = { foo(n) { log.push(n); } }; function wrapper() { ( @(assertEq(() => this.foo(0), undefined), dummy) class extends (assertEq(() => this.foo(1), undefined), Object) { @(assertEq(() => this.foo(2), undefined), dummy) method() { } @(assertEq(() => this.foo(3), undefined), dummy) static method() { } @(assertEq(() => this.foo(4), undefined), dummy) field; @(assertEq(() => this.foo(5), undefined), dummy) static field; @(assertEq(() => this.foo(6), undefined), dummy) get getter() { return; } @(assertEq(() => this.foo(7), undefined), dummy) static get getter() { return; } @(assertEq(() => this.foo(8), undefined), dummy) set setter(x) { } @(assertEq(() => this.foo(9), undefined), dummy) static set setter(x) { } @(assertEq(() => this.foo(10), undefined), dummy) accessor accessor; @(assertEq(() => this.foo(11), undefined), dummy) static accessor accessor; }); } wrapper.call(ctx); assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-list-evaluation-this-class-statement.js
JavaScript
(() => { const log = []; const dummy = () => { }; const ctx = { foo(n) { log.push(n); } }; function wrapper() { @(assertEq(() => this.foo(0), undefined), dummy) class Foo extends (assertEq(() => this.foo(1), undefined), Object) { @(assertEq(() => this.foo(2), undefined), dummy) method() { } @(assertEq(() => this.foo(3), undefined), dummy) static method() { } @(assertEq(() => this.foo(4), undefined), dummy) field; @(assertEq(() => this.foo(5), undefined), dummy) static field; @(assertEq(() => this.foo(6), undefined), dummy) get getter() { return; } @(assertEq(() => this.foo(7), undefined), dummy) static get getter() { return; } @(assertEq(() => this.foo(8), undefined), dummy) set setter(x) { } @(assertEq(() => this.foo(9), undefined), dummy) static set setter(x) { } @(assertEq(() => this.foo(10), undefined), dummy) accessor accessor; @(assertEq(() => this.foo(11), undefined), dummy) static accessor accessor; } } wrapper.call(ctx); assertEq(() => '' + log, '0,1,2,3,4,5,6,7,8,9,10,11'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-expression.js
JavaScript
(() => { let counter = 0; const dec = (_, ctx) => { ctx.metadata[ctx.name] = counter++; }; const Foo = @dec class { @dec instanceField; @dec accessor instanceAccessor; @dec instanceMethod() { } @dec get instanceGetter() { return; } @dec set instanceSetter(_) { } @dec static staticField; @dec static accessor staticAccessor; @dec static staticMethod() { } @dec static get staticGetter() { return; } @dec static set staticSetter(_) { } }, Bar = @dec class extends Foo { @dec #instanceField; @dec accessor #instanceAccessor; @dec #instanceMethod() { } @dec get #instanceGetter() { return; } @dec set #instanceSetter(_) { } @dec static #staticField; @dec static accessor #staticAccessor; @dec static #staticMethod() { } @dec static get #staticGetter() { return; } @dec static set #staticSetter(_) { } }; const order = (meta) => '' + [ meta['staticAccessor'], meta['staticMethod'], meta['staticGetter'], meta['staticSetter'], meta['#staticAccessor'], meta['#staticMethod'], meta['#staticGetter'], meta['#staticSetter'], meta['instanceAccessor'], meta['instanceMethod'], meta['instanceGetter'], meta['instanceSetter'], meta['#instanceAccessor'], meta['#instanceMethod'], meta['#instanceGetter'], meta['#instanceSetter'], meta['staticField'], meta['#staticField'], meta['instanceField'], meta['#instanceField'], meta['Foo'], meta['Bar'], ]; const foo = Foo[Symbol.metadata]; const bar = Bar[Symbol.metadata]; assertEq(() => order(foo), '0,1,2,3,,,,,4,5,6,7,,,,,8,,9,,10,'); assertEq(() => Object.getPrototypeOf(foo), null); assertEq(() => order(bar), '0,1,2,3,11,12,13,14,4,5,6,7,15,16,17,18,8,19,9,20,10,21'); assertEq(() => Object.getPrototypeOf(bar), foo); // Test an undecorated class const FooNoDec = class { }; const BarNoDec = class extends FooNoDec { }; assertEq(() => FooNoDec[Symbol.metadata], null); assertEq(() => BarNoDec[Symbol.metadata], null); // Test a class with no class decorator const FooOneDec = class { @dec x; }; const BarOneDec = class extends FooOneDec { @dec y; }; assertEq(() => JSON.stringify(FooOneDec[Symbol.metadata]), JSON.stringify({ x: 22 })); assertEq(() => JSON.stringify(BarOneDec[Symbol.metadata]), JSON.stringify({ y: 23 })); assertEq(() => Object.getPrototypeOf(BarOneDec[Symbol.metadata]), FooOneDec[Symbol.metadata]); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Decorator-metadata-class-statement.js
JavaScript
(() => { let counter = 0; const dec = (_, ctx) => { ctx.metadata[ctx.name] = counter++; }; @dec class Foo { @dec instanceField; @dec accessor instanceAccessor; @dec instanceMethod() { } @dec get instanceGetter() { return; } @dec set instanceSetter(_) { } @dec static staticField; @dec static accessor staticAccessor; @dec static staticMethod() { } @dec static get staticGetter() { return; } @dec static set staticSetter(_) { } } @dec class Bar extends Foo { @dec #instanceField; @dec accessor #instanceAccessor; @dec #instanceMethod() { } @dec get #instanceGetter() { return; } @dec set #instanceSetter(_) { } @dec static #staticField; @dec static accessor #staticAccessor; @dec static #staticMethod() { } @dec static get #staticGetter() { return; } @dec static set #staticSetter(_) { } } const order = (meta) => '' + [ meta['staticAccessor'], meta['staticMethod'], meta['staticGetter'], meta['staticSetter'], meta['#staticAccessor'], meta['#staticMethod'], meta['#staticGetter'], meta['#staticSetter'], meta['instanceAccessor'], meta['instanceMethod'], meta['instanceGetter'], meta['instanceSetter'], meta['#instanceAccessor'], meta['#instanceMethod'], meta['#instanceGetter'], meta['#instanceSetter'], meta['staticField'], meta['#staticField'], meta['instanceField'], meta['#instanceField'], meta['Foo'], meta['Bar'], ]; const foo = Foo[Symbol.metadata]; const bar = Bar[Symbol.metadata]; assertEq(() => order(foo), '0,1,2,3,,,,,4,5,6,7,,,,,8,,9,,10,'); assertEq(() => Object.getPrototypeOf(foo), null); assertEq(() => order(bar), '0,1,2,3,11,12,13,14,4,5,6,7,15,16,17,18,8,19,9,20,10,21'); assertEq(() => Object.getPrototypeOf(bar), foo); // Test an undecorated class class FooNoDec { } class BarNoDec extends FooNoDec { } assertEq(() => FooNoDec[Symbol.metadata], null); assertEq(() => BarNoDec[Symbol.metadata], null); // Test a class with no class decorator class FooOneDec { @dec x; } class BarOneDec extends FooOneDec { @dec y; } assertEq(() => JSON.stringify(FooOneDec[Symbol.metadata]), JSON.stringify({ x: 22 })); assertEq(() => JSON.stringify(BarOneDec[Symbol.metadata]), JSON.stringify({ y: 23 })); assertEq(() => Object.getPrototypeOf(BarOneDec[Symbol.metadata]), FooOneDec[Symbol.metadata]); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Basic-instance-field.js
JavaScript
(() => { const dec = (key) => (value, ctx) => { assertEq(() => value, undefined); assertEq(() => ctx.kind, 'field'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, false); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => { const obj = {}; ctx.access.set(obj, 321); return obj[key]; }, 321); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { @dec('foo') foo = 123; @dec(bar) [bar] = 123; @dec(baz) [baz] = 123; } assertEq(() => new Foo().foo, 123); assertEq(() => new Foo()[bar], 123); assertEq(() => new Foo()[baz], 123); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Basic-private-instance-field.js
JavaScript
(() => { let lateAsserts; const dec = (value, ctx) => { assertEq(() => value, undefined); assertEq(() => ctx.kind, 'field'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, false); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(new Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(new Foo), 123); assertEq(() => { const obj = new Foo; ctx.access.set(obj, 321); return get$foo(obj); }, 321); }; }; let get$foo; class Foo { @dec #foo = 123; static { get$foo = x => x.#foo; } } assertEq(() => get$foo(new Foo()), 123); lateAsserts(); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Basic-private-static-field.js
JavaScript
(() => { let lateAsserts; const dec = (value, ctx) => { assertEq(() => value, undefined); assertEq(() => ctx.kind, 'field'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, true); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(Foo), 123); assertEq(() => { ctx.access.set(Foo, 321); return get$foo(Foo); }, 321); }; }; let get$foo; class Foo { @dec static #foo = 123; static { get$foo = x => x.#foo; } } assertEq(() => get$foo(Foo), 123); lateAsserts(); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Basic-static-field.js
JavaScript
(() => { const dec = (key) => (value, ctx) => { assertEq(() => value, undefined); assertEq(() => ctx.kind, 'field'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, true); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => { const obj = {}; ctx.access.set(obj, 321); return obj[key]; }, 321); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { @dec('foo') static foo = 123; @dec(bar) static [bar] = 123; @dec(baz) static [baz] = 123; } assertEq(() => Foo.foo, 123); assertEq(() => Foo[bar], 123); assertEq(() => Foo[baz], 123); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Extra-initializer-instance-field.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (value, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec foo; } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Extra-initializer-private-instance-field.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (value, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec #foo; } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Extra-initializer-private-static-field.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (value, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static #foo; } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Extra-initializer-static-field.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (value, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static foo; } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Order-instance-field.js
JavaScript
(() => { const log = []; const dec1 = (value, ctx) => { log.push(2); return () => log.push(4); }; const dec2 = (value, ctx) => { log.push(1); return () => log.push(5); }; log.push(0); class Foo { @dec1 @dec2 foo = 123; } log.push(3); var obj = new Foo(); log.push(6); assertEq(() => obj.foo, 6); assertEq(() => log + '', '0,1,2,3,4,5,6'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Order-private-instance-field.js
JavaScript
(() => { const log = []; const dec1 = (value, ctx) => { log.push(2); return () => log.push(4); }; const dec2 = (value, ctx) => { log.push(1); return () => log.push(5); }; log.push(0); let get$foo; class Foo { @dec1 @dec2 #foo = 123; static { get$foo = x => x.#foo; } } log.push(3); var obj = new Foo(); log.push(6); assertEq(() => get$foo(obj), 6); assertEq(() => log + '', '0,1,2,3,4,5,6'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Order-private-static-field.js
JavaScript
(() => { const log = []; const dec1 = (value, ctx) => { log.push(2); return () => log.push(3); }; const dec2 = (value, ctx) => { log.push(1); return () => log.push(4); }; log.push(0); let get$foo; class Foo { @dec1 @dec2 static #foo = 123; static { get$foo = x => x.#foo; } } log.push(5); assertEq(() => get$foo(Foo), 5); assertEq(() => log + '', '0,1,2,3,4,5'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Order-static-field.js
JavaScript
(() => { const log = []; const dec1 = (value, ctx) => { log.push(2); return () => log.push(3); }; const dec2 = (value, ctx) => { log.push(1); return () => log.push(4); }; log.push(0); class Foo { @dec1 @dec2 static foo = 123; } log.push(5); assertEq(() => Foo.foo, 5); assertEq(() => log + '', '0,1,2,3,4,5'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-null-instance-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return null; }; class Foo { @dec foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-null-private-instance-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return null; }; class Foo { @dec #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-null-private-static-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return null; }; class Foo { @dec static #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-null-static-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return null; }; class Foo { @dec static foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-object-instance-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return {}; }; class Foo { @dec foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-object-private-instance-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return {}; }; class Foo { @dec #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-object-private-static-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return {}; }; class Foo { @dec static #foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Return-object-static-field.js
JavaScript
(() => { assertThrows(() => { const dec = (value, ctx) => { return {}; }; class Foo { @dec static foo; } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Shim-instance-field.js
JavaScript
(() => { let log = []; const dec = (value, ctx) => { return function (x) { assertEq(() => this instanceof Foo, true); return log.push('foo' in this, 'bar' in this, x); }; }; class Foo { @dec foo = 123; @dec bar; } assertEq(() => log + '', ''); var obj = new Foo; assertEq(() => obj.foo, 3); assertEq(() => obj.bar, 6); assertEq(() => log + '', 'false,false,123,true,false,'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Shim-private-instance-field.js
JavaScript
(() => { let log = []; const dec = (value, ctx) => { return function (x) { assertEq(() => this instanceof Foo, true); return log.push(has$foo(this), has$bar(this), x); }; }; let has$foo; let has$bar; let get$foo; let get$bar; class Foo { @dec #foo = 123; @dec #bar; static { has$foo = x => #foo in x; has$bar = x => #bar in x; get$foo = x => x.#foo; get$bar = x => x.#bar; } } assertEq(() => log + '', ''); var obj = new Foo; assertEq(() => get$foo(obj), 3); assertEq(() => get$bar(obj), 6); assertEq(() => log + '', 'false,false,123,true,false,'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Shim-private-static-field.js
JavaScript
(() => { let foo; let log = []; const dec = (value, ctx) => { return function (x) { assertEq(() => this, foo); return log.push(has$foo(this), has$bar(this), x); }; }; assertEq(() => log + '', ''); let has$foo; let has$bar; let get$foo; let get$bar; class Foo { static { foo = Foo; has$foo = x => #foo in x; has$bar = x => #bar in x; get$foo = x => x.#foo; get$bar = x => x.#bar; } @dec static #foo = 123; @dec static #bar; } assertEq(() => get$foo(Foo), 3); assertEq(() => get$bar(Foo), 6); assertEq(() => log + '', 'false,false,123,true,false,'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Field-decorators-Shim-static-field.js
JavaScript
(() => { let foo; let log = []; const dec = (value, ctx) => { return function (x) { assertEq(() => this, foo); return log.push('foo' in this, 'bar' in this, x); }; }; assertEq(() => log + '', ''); class Foo { static { foo = Foo; } @dec static foo = 123; @dec static bar; } assertEq(() => Foo.foo, 3); assertEq(() => Foo.bar, 6); assertEq(() => log + '', 'false,false,123,true,false,'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Basic-instance-getter.js
JavaScript
(() => { const dec = (key, name) => (fn, ctx) => { assertEq(() => typeof fn, 'function'); assertEq(() => fn.name, name); assertEq(() => ctx.kind, 'getter'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, false); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => 'set' in ctx.access, false); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { bar = 123; @dec('foo', 'get foo') get foo() { return this.bar; } @dec(bar, 'get [bar]') get [bar]() { return this.bar; } @dec(baz, 'get ') get [baz]() { return this.bar; } } assertEq(() => new Foo().foo, 123); assertEq(() => new Foo()[bar], 123); assertEq(() => new Foo()[baz], 123); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Basic-private-instance-getter.js
JavaScript
(() => { let lateAsserts; const dec = (fn, ctx) => { assertEq(() => typeof fn, 'function'); assertEq(() => fn.name, 'get #foo'); assertEq(() => ctx.kind, 'getter'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, false); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(new Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(new Foo), 123); assertEq(() => 'set' in ctx.access, false); }; }; let get$foo; class Foo { #bar = 123; @dec get #foo() { return this.#bar; } static { get$foo = x => x.#foo; } } assertEq(() => get$foo(new Foo), 123); lateAsserts(); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Basic-private-static-getter.js
JavaScript
(() => { let lateAsserts; const dec = (fn, ctx) => { assertEq(() => typeof fn, 'function'); assertEq(() => fn.name, 'get #foo'); assertEq(() => ctx.kind, 'getter'); assertEq(() => ctx.name, '#foo'); assertEq(() => ctx.static, true); assertEq(() => ctx.private, true); lateAsserts = () => { assertEq(() => ctx.access.has(Foo), true); assertEq(() => ctx.access.has({}), false); assertEq(() => ctx.access.get(Foo), 123); assertEq(() => 'set' in ctx.access, false); }; }; let get$foo; class Foo { static #bar = 123; @dec static get #foo() { return this.#bar; } static { get$foo = x => x.#foo; } } assertEq(() => get$foo(Foo), 123); lateAsserts(); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Basic-static-getter.js
JavaScript
(() => { const dec = (key, name) => (fn, ctx) => { assertEq(() => typeof fn, 'function'); assertEq(() => fn.name, name); assertEq(() => ctx.kind, 'getter'); assertEq(() => ctx.name, key); assertEq(() => ctx.static, true); assertEq(() => ctx.private, false); assertEq(() => ctx.access.has({ [key]: false }), true); assertEq(() => ctx.access.has({ bar: true }), false); assertEq(() => ctx.access.get({ [key]: 123 }), 123); assertEq(() => 'set' in ctx.access, false); }; const bar = Symbol('bar'); const baz = Symbol(); class Foo { static bar = 123; @dec('foo', 'get foo') static get foo() { return this.bar; } @dec(bar, 'get [bar]') static get [bar]() { return this.bar; } @dec(baz, 'get ') static get [baz]() { return this.bar; } } assertEq(() => Foo.foo, 123); assertEq(() => Foo[bar], 123); assertEq(() => Foo[baz], 123); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Extra-initializer-instance-getter.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (fn, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec get foo() { return; } } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Extra-initializer-private-instance-getter.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (fn, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec get #foo() { return; } } assertEq(() => got, undefined); const instance = new Foo; assertEq(() => got.this, instance); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Extra-initializer-private-static-getter.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (fn, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static get #foo() { return; } } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Extra-initializer-static-getter.js
JavaScript
(() => { let oldAddInitializer; let got; const dec = (fn, ctx) => { ctx.addInitializer(function (...args) { got = { this: this, args }; }); if (oldAddInitializer) assertThrows(() => oldAddInitializer(() => { }), TypeError); assertThrows(() => ctx.addInitializer({}), TypeError); oldAddInitializer = ctx.addInitializer; }; class Foo { @dec @dec static get foo() { return; } } assertEq(() => got.this, Foo); assertEq(() => got.args.length, 0); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Order-instance-getter.js
JavaScript
(() => { const log = []; let bar; let baz; const dec1 = (fn, ctx) => { log.push(2); bar = function () { log.push(4); return fn.call(this); }; return bar; }; const dec2 = (fn, ctx) => { log.push(1); baz = function () { log.push(5); return fn.call(this); }; return baz; }; log.push(0); class Foo { @dec1 @dec2 get foo() { return log.push(6); } } log.push(3); new Foo().foo; log.push(7); assertEq(() => Object.getOwnPropertyDescriptor(Foo.prototype, 'foo').get, bar); assertEq(() => log + '', '0,1,2,3,4,5,6,7'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Order-private-instance-getter.js
JavaScript
(() => { const log = []; let bar; let baz; const dec1 = (fn, ctx) => { log.push(2); bar = function () { log.push(4); return fn.call(this); }; return bar; }; const dec2 = (fn, ctx) => { log.push(1); baz = function () { log.push(5); return fn.call(this); }; return baz; }; log.push(0); let get$foo; class Foo { @dec1 @dec2 get #foo() { return log.push(6); } static { get$foo = x => x.#foo; } } log.push(3); assertEq(() => get$foo(new Foo), 7); log.push(7); assertEq(() => log + '', '0,1,2,3,4,5,6,7'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Order-private-static-getter.js
JavaScript
(() => { const log = []; let bar; let baz; const dec1 = (fn, ctx) => { log.push(2); bar = function () { log.push(4); return fn.call(this); }; return bar; }; const dec2 = (fn, ctx) => { log.push(1); baz = function () { log.push(5); return fn.call(this); }; return baz; }; log.push(0); let get$foo; class Foo { @dec1 @dec2 static get #foo() { return log.push(6); } static { get$foo = x => x.#foo; } } log.push(3); assertEq(() => get$foo(Foo), 7); log.push(7); assertEq(() => log + '', '0,1,2,3,4,5,6,7'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Order-static-getter.js
JavaScript
(() => { const log = []; let bar; let baz; const dec1 = (fn, ctx) => { log.push(2); bar = function () { log.push(4); return fn.call(this); }; return bar; }; const dec2 = (fn, ctx) => { log.push(1); baz = function () { log.push(5); return fn.call(this); }; return baz; }; log.push(0); class Foo { @dec1 @dec2 static get foo() { return log.push(6); } } log.push(3); Foo.foo; log.push(7); assertEq(() => Object.getOwnPropertyDescriptor(Foo, 'foo').get, bar); assertEq(() => log + '', '0,1,2,3,4,5,6,7'); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Return-null-instance-getter.js
JavaScript
(() => { assertThrows(() => { const dec = (fn, ctx) => { return null; }; class Foo { @dec get foo() { return; } } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Return-null-private-instance-getter.js
JavaScript
(() => { assertThrows(() => { const dec = (fn, ctx) => { return null; }; class Foo { @dec get #foo() { return; } } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_transforms_proposal/tests/decorator-evanw-split/Getter-decorators-Return-null-private-static-getter.js
JavaScript
(() => { assertThrows(() => { const dec = (fn, ctx) => { return null; }; class Foo { @dec static get #foo() { return; } } }, TypeError); })();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University