{"id":15637584,"url":"https://github.com/zkat/proposal-as-patterns","last_synced_at":"2025-09-23T15:17:13.376Z","repository":{"id":65998198,"uuid":"127966173","full_name":"zkat/proposal-as-patterns","owner":"zkat","description":"`as` destructuring patterns","archived":false,"fork":false,"pushed_at":"2018-05-10T04:01:42.000Z","size":3,"stargazers_count":110,"open_issues_count":8,"forks_count":2,"subscribers_count":12,"default_branch":"latest","last_synced_at":"2025-04-23T01:33:16.244Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"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/zkat.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":"2018-04-03T20:38:55.000Z","updated_at":"2025-04-15T15:12:39.000Z","dependencies_parsed_at":"2023-03-13T20:31:24.181Z","dependency_job_id":null,"html_url":"https://github.com/zkat/proposal-as-patterns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zkat/proposal-as-patterns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fproposal-as-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fproposal-as-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fproposal-as-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fproposal-as-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zkat","download_url":"https://codeload.github.com/zkat/proposal-as-patterns/tar.gz/refs/heads/latest","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zkat%2Fproposal-as-patterns/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276596848,"owners_count":25670463,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-03T11:12:12.292Z","updated_at":"2025-09-23T15:17:13.332Z","avatar_url":"https://github.com/zkat.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ECMAScript As-Patterns for Matching and Destructuring\n\n## [Status](https://tc39.github.io/process-document/)\n\n**Stage**: 0\n\n**Author**: Kat Marchán (npm, [@maybekatz](https://twitter.com/maybekatz))\n\n**Champions**: Kat Marchán (npm, [@maybekatz](https://twitter.com/maybekatz))\n\n## Introduction\n\nWhen matching non-Identifier values, it's often the case that users might want\nto also bind that value to an Identifier while doing the matching. For this\nreason, it's proposed that destructuring be extended with the ability to do\nthis sort of binding. Furthermore, the separate [pattern matching\nproposal](https://github.com/tc39/proposal-pattern-matching) will benefit from\nthis change by allowing matching operations against values that are also put\ninto identifiers, since identifiers are irrefutable patterns.\n\nThe syntax uses an `as` keyword, and looks as follows:\n\n```js\nconst {x: {y} as x} = {x: {y: 1}}\n// x is {y: 1}\n// y is 1\n```\n\nOr:\n```js\nfunction foo ([{y} as x, [z] as zed = [1]]) {\n  // x is {y: ...}\n  // y is x.y\n  // z is runs an initializer if arguments[0][1] is undefined\n}\n```\n\nThis applies similarly to `match`:\n```js\nmatch (x) {\n  when {x: {y: 1} as x} ~\u003e console.log(x.y === 1)\n}\n```\n\nNote: This syntax is [used by\nF#](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching).\nIt's also reminiscent of `as` syntax in `import` statements, so there's some\nprecedent in the language for this sort of binding (`import * as bar from\n'./x.js'`)\n\n## The Big Picture\n\n### Related Active Proposals\n\n* [Pattern matching](https://github.com/tc39/proposal-pattern-matching)\n* [Collection literals](https://github.com/zkat/proposal-collection-literals)\n\n## As-Patterns\n\n### Syntax\n\n**12.15.5 Destructuring Assignment Changes**:\n```\nAssignmentRebinding :\n  `as` IdentifierReference\n\nAssignmentElement :\n  DestructuringAssignmentTarget\n  DestructuringAssignmentTarget AssignmentRebinding\n  DestructuringAssignmentTarget Initializer\n  DestructuringAssignmentTarget AssignmentRebinding Initializer\n```\n\n**13.3.3 Destructuring Binding Patterns Changes**:\n```\nBindingRebinding :\n  `as` IdentifierReference\n\nBindingElement :\n  SingleNameBinding\n  BindingPattern\n  BindingPattern BindingRebinding\n  BindingPattern Initializer\n  BindingPattern BindingRebinding Initializer\n```\n\n**[Match Operator](https://github.com/tc39/proposal-pattern-matching) Syntax Changes**:\n```\nMatchRebinding :\n  `as` IdentifierReference\n\nMatchElement :\n  SingleNameBinding\n  MatchPattern\n  MatchPattern MatchRebinding\n  MatchPattern Initializer\n  MatchPattern MatchRebinding Initializer\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fproposal-as-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzkat%2Fproposal-as-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzkat%2Fproposal-as-patterns/lists"}