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: correct browser build and improve isAsyncFunction check for browser #12577

Merged
merged 1 commit into from Oct 21, 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
27 changes: 7 additions & 20 deletions lib/helpers/isAsyncFunction.js
@@ -1,22 +1,9 @@
'use strict';

let asyncFunctionPrototype = null;
// try/catch for Babel compatibility, because Babel preset-env requires
// regenerator-runtime for async/await and we don't want to include that
// for a simple check.
try {
asyncFunctionPrototype = Object.getPrototypeOf(async function() {});
} catch (err) {}

if (asyncFunctionPrototype == null) {
module.exports = function isAsyncFunction() {
return false;
};
} else {
module.exports = function isAsyncFunction(v) {
return (
typeof v === 'function' &&
Object.getPrototypeOf(v) === asyncFunctionPrototype
);
};
}
module.exports = function isAsyncFunction(v) {
return (
typeof v === 'function' &&
v.constructor &&
v.constructor.name === 'AsyncFunction'
);
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.3",
"@typescript-eslint/eslint-plugin": "5.38.1",
"@typescript-eslint/parser": "5.38.1",
"acquit": "1.2.1",
Expand Down Expand Up @@ -88,7 +89,7 @@
"lint": "eslint .",
"lint-js": "eslint . --ext .js",
"lint-ts": "eslint . --ext .ts",
"build-browser": "node ./scripts/build-browser.js",
"build-browser": "(rm ./dist/* || true) && node ./scripts/build-browser.js",
"prepublishOnly": "npm run build-browser",
"release": "git pull && git push origin master --tags && npm publish",
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
Expand Down