I’m using Laravel-mix/webpack to generate my JS code, but it generates _asyncToGenerator, although my system/browsers support async functions out of the box.
What do I do to prevent the codding from being converted to a (very clumsy) function called _asyncToGenerator instead of just keep it as it is – a simple async function?
I’ve tried putting “target: es2017′” in webpack.mix.js file, but it throws an erro that “configuration object that does not match the API schema”.
I’ve searched a lot through the Internet and no success so far…
I’m using:
For example, this clear and fine code:
async saveFileToDisk(blob, fileName) {
try {
const fileHandle = await self.showSaveFilePicker({
suggestedName: fileName,
types: [
{
description: "File",
// ...
},
],
});
const writeFile = async (fileHandle, contents) => {
// Create a FileSystemWritableFileStream to write to.
const writable = await fileHandle.createWritable();
// Write the contents of the file to the stream.
await writable.write(contents);
// Close the file and write the contents to disk.
await writable.close();
};
// write file
writeFile(fileHandle, blob).then(() => console.log("FILE DOWNLOADED!!!"));
} catch (error) {
console.log(error);
}
}
is being converted into this:
saveFileToDisk: function saveFileToDisk(blob, fileName) {
return _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee2() {
var fileHandle, writeFile;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return self.showSaveFilePicker({
suggestedName: fileName,
types: [{
description: "File" // ...
}]
});
case 3:
fileHandle = _context2.sent;
writeFile = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function _callee(fileHandle, contents) {
var writable;
return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return fileHandle.createWritable();
case 2:
writable = _context.sent;
_context.next = 5;
return writable.write(contents);
case 5:
_context.next = 7;
return writable.close();
case 7:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function writeFile(_x, _x2) {
return _ref3.apply(this, arguments);
};
}(); // write file
writeFile(fileHandle, blob).then(function () {
return console.log("FILE DOWNLOADED!!!");
});
_context2.next = 11;
break;
case 8:
_context2.prev = 8;
_context2.t0 = _context2["catch"](0);
console.log(_context2.t0);
case 11:
case "end":
return _context2.stop();
}
}
}, _callee2, null, [[0, 8]]);
}))();
},
I just want it to keep the original code. No transformations!