{"id":18524794,"url":"https://github.com/iminside/babel-bug","last_synced_at":"2025-10-31T23:30:26.889Z","repository":{"id":85562744,"uuid":"298540618","full_name":"iminside/babel-bug","owner":"iminside","description":null,"archived":false,"fork":false,"pushed_at":"2020-09-28T10:19:00.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-26T00:40:42.148Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iminside.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-25T10:25:22.000Z","updated_at":"2024-12-18T23:24:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"443266ed-dcee-4efc-80dd-19e9320c667e","html_url":"https://github.com/iminside/babel-bug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iminside%2Fbabel-bug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iminside%2Fbabel-bug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iminside%2Fbabel-bug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iminside%2Fbabel-bug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iminside","download_url":"https://codeload.github.com/iminside/babel-bug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239242066,"owners_count":19605946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T17:43:20.253Z","updated_at":"2025-10-31T23:30:26.863Z","avatar_url":"https://github.com/iminside.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"This repo describes [Babel.js](https://github.com/babel/babel) bug for distinguishing between Arrow Functions, Classes and Regular Functions.\n\n# Installation\n\n```bash\ngit clone\nnpm i\n```\n\nAnd after installation, for dealing with **bug**:\n\n```bash\nnpm run bug\n```\n\nfor dealing with **original** JavaScript behaviour:\n```bash\nnpm run original\n```\n\n\n# Description\n\nAccordingly with the following gis: https://gist.github.com/wentout/ea3afe9c822a6b6ef32f9e4f3e98b1ba\n\nWe might have difference between Functions, Regular Functions or Arrow Functions:\n\n```javascript\n'use strict';\n\nconst myArrow = () =\u003e {};\nconst myFn = function () {};\n\nclass MyClass {};\n```\n\nAnd if we might be willing to check what sort of function we are dealing with, we have the ability to check the difference with the following steps:\n\n```javascript\nconst isArrowFunction = (fn) =\u003e {\n\tif (typeof fn !== 'function') {\n\t\treturn false;\n\t}\n\tif (fn.prototype !== undefined) {\n\t\treturn false;\n\t}\n\treturn true;\n};\n\nconst isRegularFunction = (fn) =\u003e {\n\tif (typeof fn !== 'function') {\n\t\treturn false;\n\t}\n\tif (typeof fn.prototype !== 'object') {\n\t\treturn false;\n\t}\n\tif (fn.prototype.constructor !== fn) {\n\t\treturn false;\n\t}\n\treturn Object.getOwnPropertyDescriptor(fn, 'prototype').writable === true;\n};\n\nconst isClass = (fn) =\u003e {\n\tif (typeof fn !== 'function') {\n\t\treturn false;\n\t}\n\tif (typeof fn.prototype !== 'object') {\n\t\treturn false;\n\t}\n\tif (fn.prototype.constructor !== fn) {\n\t\treturn false;\n\t}\n\treturn Object.getOwnPropertyDescriptor(fn, 'prototype').writable === false;\n};\n```\n\nAnd that is how babel transforms functions:\n\n```javascript\nvar myArrow = function myArrow() {};\n\nvar myFn = function myFn() {};\n\nvar MyClass = function MyClass() {\n  _classCallCheck(this, MyClass);\n};\n```\n\nTherefore regular checking via JavaScript runtime wouldn't work anymore, because everything becomes functions.\n\n# Screenshots\n\nBefore babel transforms\n\n![](https://habrastorage.org/webt/iu/4j/zt/iu4jztsnvsstnaedrr3wdmcjvxw.png)\n\nAfter\n\n![](https://habrastorage.org/webt/bb/he/u2/bbheu29ij5lh7fcayp31mg9cvyc.png)\n\n# How to implement correct behaviour?\n\n### for Arrow Functions\n\n```javascript\nconst workingArrow = () =\u003e {};\n// right after arrow function definition\nObject.defineProperty(workingArrow, 'prototype', {\n    value: undefined\n});\n```\n\n### for Classes\n\n```javascript\nclass WorkingClass {}\n// right after class definition\nObject.defineProperty(WorkingClass, 'prototype', {\n    writable: false\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiminside%2Fbabel-bug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiminside%2Fbabel-bug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiminside%2Fbabel-bug/lists"}