{"id":13671430,"url":"https://github.com/gwmccull/babel-plugin-transform-optional-chaining","last_synced_at":"2026-03-11T05:12:23.141Z","repository":{"id":139890220,"uuid":"108340082","full_name":"gwmccull/babel-plugin-transform-optional-chaining","owner":"gwmccull","description":"Manual copy of the babel-plugin-transform-optional-chaining sub-module","archived":false,"fork":false,"pushed_at":"2017-10-26T16:53:13.000Z","size":2,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-11T09:43:42.672Z","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/gwmccull.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}},"created_at":"2017-10-26T00:08:57.000Z","updated_at":"2020-08-09T16:16:55.000Z","dependencies_parsed_at":"2024-01-14T17:04:05.113Z","dependency_job_id":"948c7062-dc5f-469e-9493-7ad1d41ce1f2","html_url":"https://github.com/gwmccull/babel-plugin-transform-optional-chaining","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/gwmccull%2Fbabel-plugin-transform-optional-chaining","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwmccull%2Fbabel-plugin-transform-optional-chaining/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwmccull%2Fbabel-plugin-transform-optional-chaining/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gwmccull%2Fbabel-plugin-transform-optional-chaining/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gwmccull","download_url":"https://codeload.github.com/gwmccull/babel-plugin-transform-optional-chaining/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251187106,"owners_count":21549583,"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-08-02T09:01:09.552Z","updated_at":"2025-04-27T18:31:15.663Z","avatar_url":"https://github.com/gwmccull.png","language":"JavaScript","readme":"# @babel/plugin-transform-optional-chaining\n\nThe Optional Chaining Operator allows you to handle properties of deeply nested\nobjects without worrying about undefined intermediate objects.\n\n## Example\n\n### Accessing deeply nested properties\n\n```js\nconst obj = {\n  foo: {\n    bar: {\n      baz: 42,\n    },\n  },\n};\n\nconst baz = obj?.foo?.bar?.baz; // 42\n\nconst safe = obj?.qux?.baz; // undefined\n\n// Optional chaining and normal chaining can be intermixed\nobj?.foo.bar?.baz; // Only access `foo` if `obj` exists, and `baz` if\n                   // `bar` exists\n```\n\n### Calling deeply nested functions\n\n```js\nconst obj = {\n  foo: {\n    bar: {\n      baz() {\n        return 42;\n      },\n    },\n  },\n};\n\nconst baz = obj?.foo?.bar?.baz(); // 42\n\nconst safe = obj?.qux?.baz(); // undefined\nconst safe2 = obj?.foo.bar.qux?.(); // undefined\n\nconst willThrow = obj?.foo.bar.qux(); // Error: not a function\n\n// Top function can be called directly, too.\nfunction test() {\n  return 42;\n}\ntest?.(); // 42\n\nexists?.(); // undefined\n```\n\n### Constructing deeply nested classes\n\n```js\nconst obj = {\n  foo: {\n    bar: {\n      baz: class {\n      },\n    },\n  },\n};\n\nconst baz = new obj?.foo?.bar?.baz(); // baz instance\n\nconst safe = new obj?.qux?.baz(); // undefined\nconst safe2 = new obj?.foo.bar.qux?.(); // undefined\n\nconst willThrow = new obj?.foo.bar.qux(); // Error: not a constructor\n\n// Top classes can be called directly, too.\nclass Test {\n}\nnew Test?.(); // test instance\n\nnew exists?.(); // undefined\n```\n\n## Installation\n\n```sh\nnpm install --save-dev @babel/plugin-transform-optional-chaining\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\"transform-optional-chaining\"]\n}\n```\n\n### Via CLI\n\n```sh\nbabel --plugins transform-optional-chaining script.js\n```\n\n### Via Node API\n\n```javascript\nrequire(\"@babel/core\").transform(\"code\", {\n  plugins: [\"transform-optional-chaining\"]\n});\n```\n\n## Options\n\n### `loose`\n\n`boolean`, defaults to `false`.\n\nWhen `true`, this transform will pretend `document.all` does not exist,\nand perform loose equality checks with `null` instead of string equality checks\nagainst both `null` and `undefined`.\n\n#### Example\n\nIn\n\n```javascript\nfoo?.bar;\n```\n\nOut (`loose === true`)\n\n```javascript\nfoo == null ? void 0 : foo.bar;\n```\n\nOut (`loose === false`)\n\n```javascript\nfoo === null || foo === void 0 ? void 0 : foo.bar;\n```\n\n## References\n\n* [Proposal: Optional Chaining](https://github.com/tc39/proposal-optional-chaining)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwmccull%2Fbabel-plugin-transform-optional-chaining","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgwmccull%2Fbabel-plugin-transform-optional-chaining","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgwmccull%2Fbabel-plugin-transform-optional-chaining/lists"}