developit / developit/microbundle

[Transpiling] Rest parameters with async bug

未关闭
#1,001 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
8.1k
派生
358
PR 合并指标
30 天内没有已合并 PR

描述

Minimal test case:

```javascript
export const brokenArgsRest = async (...props) => {
await someAsyncFunction(async () => {
console.log(props)
})
}

export const someAsyncFunction = async callback => {
await callback()
}
```

generates

```javascript
var brokenArgsRest = function brokenArgsRest() {
return Promise.resolve(someAsyncFunction(function () {
try {
var _arguments2 = arguments;
console.log([].slice.call(_arguments2));
return Promise.resolve();
} catch (e) {
return Promise.reject(e);
}
})).then(function () {});
};
var someAsyncFunction = function someAsyncFunction(callback) {
try {
return Promise.resolve(callback()).then(function () {});
} catch (e) {
return Promise.reject(e);
}
};
```

` var _arguments2 = arguments;` should be one more level up

Context:
We hit this bug on fcl-js lib : https://github.com/onflow/flow-js-testing/issues/182

PS: my js knowledge is limited, but seems related to inlining somehow.

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start by reproducing the minimal JavaScript case and comparing the generated output with the reported expectation. Trace the async and rest-parameter transpilation, especially how inlining affects the scope used for `arguments`; done means the generated `_arguments2` reference is captured from the outer function rather than the nested callback.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
build-system
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。