Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(es/compat): Implement auto accessors fully #7370

Merged
merged 37 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1d5d184
Enable
kdy1 May 9, 2023
c9b1729
Merge fields
kdy1 May 10, 2023
5c8cf79
Prevent duplicate constructor
kdy1 May 10, 2023
317d014
Revert "Merge fields"
kdy1 May 10, 2023
9fe8ebf
Merge for_static
kdy1 May 10, 2023
ce5ac3b
WIP: Auto accessor first
kdy1 May 10, 2023
daa9cf9
Print file name on failure
kdy1 May 10, 2023
2d783bf
`is_init_proto_called`
kdy1 May 10, 2023
20e10b9
initProto
kdy1 May 10, 2023
7e6679b
Order
kdy1 May 10, 2023
fcf0ddc
`process_prop_name`
kdy1 May 10, 2023
cb526d2
Optimize
kdy1 May 10, 2023
eb47e5c
accessor.is_static
kdy1 May 10, 2023
dfa5d36
Update test refs
kdy1 May 10, 2023
9a90061
Remove useless code
kdy1 May 11, 2023
56c6cc0
Comment
kdy1 May 11, 2023
a1236b8
WIP: Managed to convert exception to test failure
kdy1 May 11, 2023
f3b8ec3
is_static
kdy1 May 11, 2023
759b110
`is_init_proto_called`
kdy1 May 11, 2023
3fade60
`process_decorators_of_class_members`
kdy1 May 11, 2023
4a7bd4a
pre-process decorators
kdy1 May 11, 2023
e314ef4
Add a test using babel
kdy1 May 13, 2023
686884f
Remove code
kdy1 May 14, 2023
d737bfa
Return
kdy1 May 14, 2023
c592f5d
visit first
kdy1 May 14, 2023
15db6bc
VIsit as class
kdy1 May 14, 2023
b969f01
Add a test using babel
kdy1 May 14, 2023
dfdbe32
remove wrong code
kdy1 May 14, 2023
20f5c2b
static blocks
kdy1 May 14, 2023
d1c228b
constructor
kdy1 May 14, 2023
ec12dc3
initClass
kdy1 May 14, 2023
31f2fc2
clippy
kdy1 May 14, 2023
38b0a12
scope of vars
kdy1 May 14, 2023
cb12ec7
private method
kdy1 May 14, 2023
6bd908c
`ensure_identity_constructor`
kdy1 May 14, 2023
4a565e2
Update test refs
kdy1 May 14, 2023
b068062
Merge branch 'main' into dec-auto
swc-bot May 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
481 changes: 317 additions & 164 deletions crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions crates/swc_ecma_transforms_proposal/tests/decorators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ fn exec(input: PathBuf) {
fn exec_inner(input: PathBuf) {
let code = std::fs::read_to_string(&input).unwrap();

if code.contains("accessor ") {
return;
}

swc_ecma_transforms_testing::exec_tr(
"decorator",
Syntax::Typescript(TsConfig {
Expand All @@ -53,9 +49,6 @@ fn fixture(input: PathBuf) {

fn fixture_inner(input: PathBuf) {
let src = std::fs::read_to_string(&input).unwrap();
if src.contains("accessor ") {
return;
}

let output = input.with_file_name("output.js");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto;
const dec = () => { };
var _A = /*#__PURE__*/new WeakMap();
var _a = /*#__PURE__*/new WeakMap();
var _B = /*#__PURE__*/new WeakMap();
var _b = /*#__PURE__*/new WeakMap();
var _init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto;
const dec = ()=>{};
var ___a = /*#__PURE__*/ new WeakMap(), _a = /*#__PURE__*/ new WeakMap(), ___b = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap();
class Foo {
constructor() {
classPrivateFieldInitSpec(this, _b, {
get: _get_b2,
set: _set_b2
});
classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
classPrivateFieldInitSpec(this, _A, {
writable: true,
value: (_initProto(this), _init_a(this))
});
classPrivateFieldInitSpec(this, _B, {
writable: true,
value: _init_b(this, 123)
});
}
constructor(){
_class_private_field_init(this, _a, {
get: get_a,
set: set_a
});
_class_private_field_init(this, _b, {
get: get_b,
set: set_b
});
_class_private_field_init(this, ___a, {
writable: true,
value: (_initProto(this), _init_a(this))
});
_class_private_field_init(this, ___b, {
writable: true,
value: _init_b(this, 123)
});
}
}
function _set_a2(v) {
_set_a(this, v);
var __ = {
writable: true,
value: (()=>{
({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(Foo, [
[
dec,
1,
"a",
function() {
return _class_private_field_get(this, ___a);
},
function(_v) {
_class_private_field_set(this, ___a, _v);
}
],
[
dec,
1,
"b",
function() {
return _class_private_field_get(this, ___b);
},
function(_v) {
_class_private_field_set(this, ___b, _v);
}
]
], []));
})()
};
function get_a() {
return _get___a(this);
}
function _get_a2() {
return _get_a(this);
function set_a(_v) {
_set___a(this, _v);
}
function _set_b2(v) {
_set_b(this, v);
function get_b() {
return _get___b(this);
}
function _get_b2() {
return _get_b(this);
function set_b(_v) {
_set___b(this, _v);
}
[_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initProto] = _applyDecs2203R(Foo, [[dec, 1, "a", function () {
return classPrivateFieldGet(this, _A);
}, function (value) {
classPrivateFieldSet(this, _A, value);
}], [dec, 1, "b", function () {
return classPrivateFieldGet(this, _B);
}, function (value) {
classPrivateFieldSet(this, _B, value);
}]], []).e;
Original file line number Diff line number Diff line change
@@ -1,41 +1,61 @@
var _init_a, _init_b, _computedKey, _init_computedKey, _initProto;
const dec = () => { };
const dec = ()=>{};
_computedKey = 'c';
var _A = /*#__PURE__*/new WeakMap();
var _B = /*#__PURE__*/new WeakMap();
var _C = /*#__PURE__*/new WeakMap();
var ____private_a = /*#__PURE__*/ new WeakMap(), ____private_b = /*#__PURE__*/ new WeakMap(), ____private_computedKey = /*#__PURE__*/ new WeakMap();
let _computedKey1 = _computedKey, _computedKey2 = _computedKey;
class Foo {
constructor() {
classPrivateFieldInitSpec(this, _A, {
writable: true,
value: (_initProto(this), _init_a(this))
});
classPrivateFieldInitSpec(this, _B, {
writable: true,
value: _init_b(this, 123)
});
classPrivateFieldInitSpec(this, _C, {
writable: true,
value: _init_computedKey(this, 456)
});
}
get a() {
return classPrivateFieldGet(this, _A);
}
set a(v) {
classPrivateFieldSet(this, _A, v);
}
get b() {
return classPrivateFieldGet(this, _B);
}
set b(v) {
classPrivateFieldSet(this, _B, v);
}
get [_computedKey]() {
return classPrivateFieldGet(this, _C);
}
set [_computedKey](v) {
classPrivateFieldSet(this, _C, v);
}
get a() {
return _class_private_field_get(this, ____private_a);
}
set a(_v) {
_class_private_field_set(this, ____private_a, _v);
}
get b() {
return _class_private_field_get(this, ____private_b);
}
set b(_v) {
_class_private_field_set(this, ____private_b, _v);
}
get [_computedKey1]() {
return _class_private_field_get(this, ____private_computedKey);
}
set [_computedKey2](_v) {
_class_private_field_set(this, ____private_computedKey, _v);
}
constructor(){
_class_private_field_init(this, ____private_a, {
writable: true,
value: (_initProto(this), _init_a(this))
});
_class_private_field_init(this, ____private_b, {
writable: true,
value: _init_b(this, 123)
});
_class_private_field_init(this, ____private_computedKey, {
writable: true,
value: _init_computedKey(this, 456)
});
}
}
[_init_a, _init_b, _init_computedKey, _initProto] = _applyDecs2203R(Foo, [[dec, 1, "a"], [dec, 1, "b"], [dec, 1, _computedKey]], []).e;
var __ = {
writable: true,
value: (()=>{
({ e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(Foo, [
[
dec,
1,
"a"
],
[
dec,
1,
"b"
],
[
dec,
1,
_computedKey
]
], []));
})()
};
Original file line number Diff line number Diff line change
@@ -1,48 +1,62 @@
var _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic;
const dec = () => { };
var _a = /*#__PURE__*/new WeakMap();
var _b = /*#__PURE__*/new WeakMap();
var _init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic;
const dec = ()=>{};
class Foo {
constructor() {
classPrivateFieldInitSpec(this, _b, {
get: _get_b2,
set: _set_b2
});
classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
}
function _set_a2(v) {
_set_a(this, v);
var _a = {
get: get_a,
set: set_a
};
var _b = {
get: get_b,
set: set_b
};
var __ = {
writable: true,
value: (()=>{
({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initStatic] } = _apply_decs_2203_r(Foo, [
[
dec,
6,
"a",
function() {
return _class_static_private_field_spec_get(this, Foo, ___a);
},
function(_v) {
_class_static_private_field_spec_set(this, Foo, ___a, _v);
}
],
[
dec,
6,
"b",
function() {
return _class_static_private_field_spec_get(this, Foo, ___b);
},
function(_v) {
_class_static_private_field_spec_set(this, Foo, ___b, _v);
}
]
], []));
_initStatic(Foo);
})()
};
var ___a = {
writable: true,
value: _init_a(Foo)
};
var ___b = {
writable: true,
value: _init_b(Foo, 123)
};
function get_a() {
return _get___a(this);
}
function _get_a2() {
return _get_a(this);
function set_a(_v) {
_set___a(this, _v);
}
function _set_b2(v) {
_set_b(this, v);
function get_b() {
return _get___b(this);
}
function _get_b2() {
return _get_b(this);
function set_b(_v) {
_set___b(this, _v);
}
(() => {
[_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = _applyDecs2203R(Foo, [[dec, 6, "a", function () {
return classStaticPrivateFieldSpecGet(this, Foo, _A);
}, function (value) {
classStaticPrivateFieldSpecSet(this, Foo, _A, value);
}], [dec, 6, "b", function () {
return classStaticPrivateFieldSpecGet(this, Foo, _B);
}, function (value) {
classStaticPrivateFieldSpecSet(this, Foo, _B, value);
}]], []).e;
_initStatic(Foo);
})();
var _A = {
writable: true,
value: _init_a(Foo)
};
var _B = {
writable: true,
value: _init_b(Foo, 123)
};