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

fix(es/generator): Object in generator #5861

Merged
merged 5 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions crates/swc/tests/exec/issues-5xxx/5859/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const result = [];
async function* foo() {
const input = ["hello", "swc"];

for (i of input) {
result.push({ x: i });
result.push({ y: await i });
result.push({
a: 1,
b: yield i,
});
}
}

const iter = foo();

async function main() {
let state;
for (let x = await iter.next(); !x.done; x = await iter.next(state)) {
state = `[${x.value}]`;
}
console.log(result);
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function _request() {
return _request.apply(this, arguments);
}
_async_to_generator(function() {
var obj, _tmp, _tmp1;
var obj, _tmp;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
Expand All @@ -42,8 +42,9 @@ _async_to_generator(function() {
_state.label = 3;
case 3:
obj = _tmp;
_tmp1 = {};
console.log((_tmp1.obj = obj, _tmp1));
console.log({
obj: obj
});
return [
2
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function _request() {
return _request.apply(this, arguments);
}
_async_to_generator(function() {
var obj, _tmp, _tmp1;
var obj, _tmp;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
Expand All @@ -42,8 +42,9 @@ _async_to_generator(function() {
_state.label = 3;
case 3:
obj = _tmp;
_tmp1 = {};
console.log((_tmp1.obj = obj, _tmp1));
console.log({
obj: obj
});
return [
2
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
function foo() {
var val, _tmp, _tmp1;
var val, _tmp;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
Expand All @@ -23,8 +23,9 @@ function foo() {
_state.label = 3;
case 3:
val = _tmp;
_tmp1 = {};
console.log((_tmp1.val = val, _tmp1));
console.log({
val: val
});
return [
2
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ function foo() {
}
function _foo() {
_foo = _async_to_generator(function() {
var tmp, ref, ref, _tmp;
var tmp, ref, ref;
return _ts_generator(this, function(_state) {
_tmp = {};
tmp = baz.bar, ref = tmp === void 0 ? _tmp : tmp, ref = ref !== null ? ref : _throw(new TypeError("Cannot destructure undefined"));
tmp = baz.bar, ref = tmp === void 0 ? {} : tmp, ref = ref !== null ? ref : _throw(new TypeError("Cannot destructure undefined"));
return [
2
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ var obj = {
},
byPlatform: function() {
var _ref = _async_to_generator(function(platform) {
var result, _tmp;
var result;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
_tmp = {};
return [
4,
this.find((_tmp.platform = {
$eq: platform
}, _tmp))
this.find({
platform: {
$eq: platform
}
})
];
case 1:
result = _state.sent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ function _asyncToGenerator(fn) {
};
}
_asyncToGenerator(function() {
var counter, resolve, promise, iterable, _tmp, res, _i, _iter, v, oldresolve, _tmp1, _tmp2;
var counter, resolve, promise, iterable, res, _i, _iter, v, oldresolve;
return _tsGenerator(this, function(_state) {
switch(_state.label){
case 0:
counter = 0;
promise = new Promise(function(r) {
return resolve = r;
});
_tmp = {};
iterable = _defineProperty(_tmp, Symbol.asyncIterator, function() {
iterable = _defineProperty({}, Symbol.asyncIterator, function() {
return {
next: function next() {
return promise;
Expand Down Expand Up @@ -179,8 +178,10 @@ _asyncToGenerator(function() {
promise = new Promise(function(r) {
return resolve = r;
});
_tmp1 = {};
oldresolve((_tmp1.value = v, _tmp1.done = false, _tmp1));
oldresolve({
value: v,
done: false
});
_state.label = 3;
case 3:
_i++;
Expand All @@ -189,8 +190,10 @@ _asyncToGenerator(function() {
1
];
case 4:
_tmp2 = {};
resolve((_tmp2.value = undefined, _tmp2.done = true, _tmp2));
resolve({
value: undefined,
done: true
});
return [
4,
res
Expand Down
17 changes: 10 additions & 7 deletions crates/swc/tests/fixture/issues-1xxx/1918/es5/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").defau
var _defineProperty = require("@swc/helpers/lib/_define_property.js").default;
var _tsGenerator = require("@swc/helpers/lib/_ts_generator.js").default;
_asyncToGenerator(function() {
var counter, resolve, promise, iterable, _tmp, res, _i, _iter, v, oldresolve, _tmp1, _tmp2;
var counter, resolve, promise, iterable, res, _i, _iter, v, oldresolve;
return _tsGenerator(this, function(_state) {
switch(_state.label){
case 0:
counter = 0;
promise = new Promise(function(r) {
return resolve = r;
});
_tmp = {};
iterable = _defineProperty(_tmp, Symbol.asyncIterator, function() {
iterable = _defineProperty({}, Symbol.asyncIterator, function() {
return {
next: function next() {
return promise;
Expand Down Expand Up @@ -138,8 +137,10 @@ _asyncToGenerator(function() {
promise = new Promise(function(r) {
return resolve = r;
});
_tmp1 = {};
oldresolve((_tmp1.value = v, _tmp1.done = false, _tmp1));
oldresolve({
value: v,
done: false
});
_state.label = 3;
case 3:
_i++;
Expand All @@ -148,8 +149,10 @@ _asyncToGenerator(function() {
1
];
case 4:
_tmp2 = {};
resolve((_tmp2.value = undefined, _tmp2.done = true, _tmp2));
resolve({
value: undefined,
done: true
});
return [
4,
res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ function fn() {
}
function _fn() {
_fn = _async_to_generator(function() {
var key, _tmp;
var key;
return _ts_generator(this, function(_state) {
_tmp = {};
for(var key in _tmp);
for(var key in {});
return [
2
];
Expand Down
7 changes: 4 additions & 3 deletions crates/swc/tests/fixture/issues-2xxx/2413/1/output/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
var handleSubmit = useMutation(/*#__PURE__*/ _async_to_generator(function() {
var res, _tmp, param, errors;
var res, param, errors;
return _ts_generator(this, function(_state) {
switch(_state.label){
case 0:
Expand All @@ -11,10 +11,11 @@ var handleSubmit = useMutation(/*#__PURE__*/ _async_to_generator(function() {
,
3
]);
_tmp = {};
return [
4,
gate.register((_tmp.username = phoneNumber, _tmp))
gate.register({
username: phoneNumber
})
];
case 1:
res = _state.sent();
Expand Down
8 changes: 6 additions & 2 deletions crates/swc/tests/fixture/issues-2xxx/2717/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export var selectThemeObject = function(e) {
return e.theme;
};
export function saveTheme(t) {
var s, o, n, a;
var s, o, n;
return e(this, function(e) {
switch(e.label){
case 0:
Expand All @@ -14,7 +14,11 @@ export function saveTheme(t) {
r(selectThemeObject)
];
case 1:
return o = e.sent(), n = {}, window.localStorage.setItem("theme", JSON.stringify((n.theme = o.theme, n.mode = o.mode, n.palette = o.palette, n))), s === c && (a = window.document.querySelector("body")) && (a.classList.add("light" === o.mode ? "light" : "dark"), a.classList.remove("light" === o.mode ? "dark" : "light")), [
return o = e.sent(), window.localStorage.setItem("theme", JSON.stringify({
theme: o.theme,
mode: o.mode,
palette: o.palette
})), s === c && (n = window.document.querySelector("body")) && (n.classList.add("light" === o.mode ? "light" : "dark"), n.classList.remove("light" === o.mode ? "dark" : "light")), [
2
];
}
Expand Down