{"id":17974423,"url":"https://github.com/clemmy/babel-plugin-transform-generator-expression","last_synced_at":"2025-04-03T23:41:35.626Z","repository":{"id":68362826,"uuid":"114317190","full_name":"clemmy/babel-plugin-transform-generator-expression","owner":"clemmy","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-15T02:20:03.000Z","size":5,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T11:29:46.597Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clemmy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2017-12-15T02:18:37.000Z","updated_at":"2017-12-15T18:10:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5141bc9-5f36-455b-9857-871241daa0bc","html_url":"https://github.com/clemmy/babel-plugin-transform-generator-expression","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/clemmy%2Fbabel-plugin-transform-generator-expression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemmy%2Fbabel-plugin-transform-generator-expression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemmy%2Fbabel-plugin-transform-generator-expression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clemmy%2Fbabel-plugin-transform-generator-expression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clemmy","download_url":"https://codeload.github.com/clemmy/babel-plugin-transform-generator-expression/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247097969,"owners_count":20883127,"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-10-29T17:08:06.920Z","updated_at":"2025-04-03T23:41:35.604Z","avatar_url":"https://github.com/clemmy.png","language":"JavaScript","readme":"# babel-plugin-transform-generator-expression\n\n\u003e Supports [ECMAScript Generator Expressions](https://github.com/sebmarkbage/ecmascript-generator-expression)\n\n## Detail\n\n\u003e A convenient way of generating arrays/sets/maps of values in a contained expression. It's an alternative to array comprehensions and designed to pair well with do expressions. I think of it as the multi-value form of do-expressions.\n\nfrom [ECMAScript Generator Expressions Proposal](https://github.com/sebmarkbage/ecmascript-generator-expression)\n\nIn order to use this API, you must also be using a version of Babylon that supports GeneratorExpression nodes, such as the one found [here](https://github.com/clemmy/babylon/tree/general-gexp-6.18).\n\nYou can alternatively experiment with the syntax on this [CodePen](https://codepen.io/clemmy/pen/zpGaNv?editors=1000).\n\n### Examples\n\n```js\nvar odds = *{\n  for (var i = 1; i \u003c 10; i += 2) {\n    yield i;\n  }\n}; // =\u003e 1, 3, 5, 7, 9 \n```\n\n```js\nvar THRESHOLD = 5;\nvar under = *{\n  for (var i = 0; i \u003c 10; ++i) {\n    if (i === THRESHOLD) {\n      break;\n    }\n    yield i;\n  }\n} // =\u003e 0, 1, 2, 3, 4\n```\n\n## Installation\n\n```sh\nnpm install --save-dev babel-plugin-transform-generator-expressions babel-plugin-transform-do-expressions\n```\n\n## Usage\n\n### Via `.babelrc` (Recommended)\n\n**.babelrc**\n\n```json\n{\n  \"plugins\": [\"transform-do-expressions\", [\"transform-generator-expressions\", { \"enableCompletionValue\": false }]]\n}\n```\n\n### Via CLI\n\n```sh\nbabel --plugins transform-do-expressions,transform-generator-expressions script.js\n```\n\n### Via Node API\n\n```javascript\nrequire(\"babel-core\").transform(\"code\", {\n  plugins: [\"transform-do-expressions\", [\"transform-generator-expression\", { enableCompletionValue: false }]]\n});\n```\n\n## Options\n\n### `enableCompletionValue`\n\n`boolean`, defaults to `false`.\n\nThis option makes the generator expression implicitly complete with the completion value of its contained statements, as defined by the proposal. However, this is a bit buggy right now. See [note](notes).\n\n## Notes\n\nBecause it's not yet clear whether [do expressions work like IFFE's or blocks](https://github.com/tc39/proposal-do-expressions/issues/5#issuecomment-351860849), [Babel's do expression transform](https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-do-expressions) is not particularly consistent about this behavior, which we rely on.\n\n## Related Work\n\nI made a proposal to use this in JSX as an alternative to the usual `JSXExpressions`. You can check out some CodePen examples [here](https://github.com/facebook/jsx/pull/99). It uses an optimized version with `Array.push()` instead of generators.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclemmy%2Fbabel-plugin-transform-generator-expression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclemmy%2Fbabel-plugin-transform-generator-expression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclemmy%2Fbabel-plugin-transform-generator-expression/lists"}