npm publish发布,会预先执行npm run prepare
编译前
async function fetchGet() {
const res = await fetch('https://httpbin.org/get').then(res => res.json());
return res;
}
编译后
async function fetchGet() {
try {
const res = await fetch('https://httpbin.org/get').then(res => res.json());
return res;
} catch (e) {
console.log('error', e);
}
}
编译前
const arrowFun = async () => {
const res = await fetch('https://httpbin.org/post').then(res => res.json());
return res;
}
编译后
const arrowFun = async () => {
try {
const res = await fetch('https://httpbin.org/post').then(res => res.json());
return res;
} catch (e) {
console.log('error', e);
}
};
编译前
const arrowFunWithoutBody = async () => await fetch('https://httpbin.org/get/arrow');
编译后
const arrowFunWithoutBody = async () => {
try {
return await fetch('https://httpbin.org/get/arrow');
} catch (e) {
console.log('error', e);
}
};
编译前
const wrapWithIfFun = async () => {
if ('True') {
const res = await fetch('https://httpbin.org/get/arrow');
return res;
}
};
编译后
const wrapWithIfFun = async () => {
try {
if ('True') {
const res = await fetch('https://httpbin.org/get/arrow');
return res;
}
} catch (e) {
console.log('error', e);
}
};
编译前
const awaitWrapByTryCatchFun = async () => {
try {
const res = await fetch('https://httpbin.org/post').then(res => res.json());
return res;
} catch (err) {
console.log('自定义捕捉错误');
}
}
编译后
const awaitWrapByTryCatchFun = async () => {
try {
const res = await fetch('https://httpbin.org/post').then(res => res.json());
return res;
} catch (err) {
console.log('自定义捕捉错误');
}
};