{"id":13807893,"url":"https://github.com/lifeart/ember-cli-jsx-templates","last_synced_at":"2025-04-23T17:11:04.307Z","repository":{"id":35237812,"uuid":"193566304","full_name":"lifeart/ember-cli-jsx-templates","owner":"lifeart","description":"TSX/JSX support for ember templates","archived":false,"fork":false,"pushed_at":"2022-12-10T20:05:16.000Z","size":3410,"stargazers_count":16,"open_issues_count":20,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-02T12:20:48.644Z","etag":null,"topics":["addon","ember-cli","ember-components","ember-templates","hbs","jsx","jsx-compiler"],"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/lifeart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-24T19:28:06.000Z","updated_at":"2023-04-21T16:41:27.000Z","dependencies_parsed_at":"2023-01-15T17:01:04.488Z","dependency_job_id":null,"html_url":"https://github.com/lifeart/ember-cli-jsx-templates","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeart%2Fember-cli-jsx-templates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeart%2Fember-cli-jsx-templates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeart%2Fember-cli-jsx-templates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeart%2Fember-cli-jsx-templates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lifeart","download_url":"https://codeload.github.com/lifeart/ember-cli-jsx-templates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250477812,"owners_count":21437049,"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":["addon","ember-cli","ember-components","ember-templates","hbs","jsx","jsx-compiler"],"created_at":"2024-08-04T01:01:31.813Z","updated_at":"2025-04-23T17:11:04.286Z","avatar_url":"https://github.com/lifeart.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Templating"],"readme":"ember-cli-jsx-templates\n==============================================================================\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/lifeart/ember-cli-jsx-templates.svg)](https://greenkeeper.io/)\n\nThis addon allow use `.jsx/.tsx` syntaxis for templates.\n\n---\n\n__q__: _Why?_\n\n__a__: If you came from React, or want to \"touch\" JSX in Ember with an easy way, this is for you!\n\n---\n\n__q__: _Can I use typings? Component types for autocomplete?_\n\n__a__: Yes! You can create `.tsx` template and import any typings into it.\n\n---\n\n__q__: _How it's working?_\n\n__a__: Addon perform `.jsx` to `JSX-AST` transform, after we transform `JSX-AST` into `HBS-AST` and after we compile template from valid handlebars `AST`.\n\n---\n\n__q__: _Is it Turing complete  transpilation?_\n\n__a__: Nope, and never planned to be, all supported cases described in [jsx-caster tests](https://github.com/lifeart/ember-meta-explorer/blob/master/test/utils/jsx-caster.test.js) and [jsx-extractor tests](https://github.com/lifeart/ember-meta-explorer/blob/master/test/utils/jsx-extractor.test.js)\n\n---\n__q__: _If I spend some time, playing this addon, can I revert created `jsx` into `hbs`?_\n\n__a__: Yes, if you played enough with `jsx` you able to convert template to hbs using `ember-meta-explorer` __extractJSXComponents__ method.\n\n---\n\nCompatibility\n------------------------------------------------------------------------------\n\n* Ember.js v3.16 or above\n* Ember CLI v2.13 or above\n* Node.js v10 or above\n\n\nInstallation\n------------------------------------------------------------------------------\n\n```\nember install ember-cli-jsx-templates\n```\n\n\nUsage\n------------------------------------------------------------------------------\n\ntemplate-only usecase\n```jsx\n// app/templates/components/my-functional-component\nexport default function MyFunctionalComponent({name, onChange}) {\n const inputPrefix = 'New name:';\n return (\n   \u003c\u003e\n   \u003ch1\u003eJSX templates for Ember!\u003c/h1\u003e\n   \u003cp\u003eHello, {name}!\u003c/p\u003e\u003cbr /\u003e\n   {inputPrefix}: \u003cinput class=\"my-input\" value={name} onkeyup={onChange}/\u003e\n   \u003c/\u003e\n )\n}\n```\n\nany ember component + template usecase (with this):\n\n```js\n// app/components/my-functional-component\nimport Component from '@ember/component';\nexport default class MyComponent extends Component {\n    inputPrefix = \"Nemo\";\n    onChange(e) {\n        this.set('inputPrefix', e.target.value);\n    }    \n}\n```\nand\n```jsx\n// app/templates/components/my-functional-component\nexport default function MyFunctionalComponent() {\n    return (\n      \u003c\u003e\n      \u003ch1\u003eJSX templates for Ember!\u003c/h1\u003e\n      \u003cp\u003eHello, {this.inputPrefix}!\u003c/p\u003e\u003cbr /\u003e\n      Update: \u003cinput class=\"my-input\" value={name} onkeyup={action(this.onChange)}/\u003e\n      \u003c/\u003e\n    )\n}\n```\n\n------------------------------------------------------------------------------\n\nbasic usage:\n```jsx\n// app/templates/components/my-component.jsx\n\u003cdiv attributes\u003e{3 + 2} { props.children } { name } { props.external }\u003c/div\u003e\n```\nwill be compiled into:\n```hbs\n\u003cdiv ...attributes\u003e {{add 3 2}} {{yield}} {{this.name}} {{@external}}\u003e\u003c/div\u003e\n```\n---\njsx for ember components:\n```jsx\n\u003cMyComponent attr-name=\"foo\" value={42} data-test-name=\"item\" onChange={action(\"update\")} /\u003e\n```\nwill be compiled into:\n```hbs\n\u003cMyComponent name=\"foo\" @value={{42}} data-test-name=\"item\" @onChange={{action \"update\"}} /\u003e\n```\n---\njsx having modifier:\n```jsx\n\u003cdiv mod-style={{color:\"#face8d\", [\"font-size\"]: \"12px\"}}\u003e\u003c/div\u003e\n// named arguments for modifiers not supported\n```\nwill be compiled into:\n```hbs\n\u003cdiv {{style (hash color=\"#face8d\" font-size= \"12px\")}}\u003e\u003c/div\u003e\n```\n---\naccess to component's yielded context:\n```jsx\n\u003cMyComponent as={ctx, param}\u003e{ctx.name} {param}\u003c/MyComponent\u003e\n```\nwill be compiled into:\n```hbs\n\u003cMyComponent as |ctx param|\u003e{{ctx.name}} {{param}}\u003c/MyComponent\u003e\n```\n---\nyield with params:\n```jsx\n\u003cdiv\u003e{yield(name, {foo:1})}\u003c/div\u003e\n```\nwill be compiled into:\n```hbs\n\u003cdiv\u003e{{yield name (hash foo=1)}}\u003c/div\u003e\n```\n---\n`.tsx` template, with typings \u0026 autocomplete:\n```tsx\nimport { FooProp } from \"./../../typings\";\nexport default function TypedHello(props: FooProp) {\n    return \u003ch1\u003eThis is typed template! And name is: {props.name}\u003c/h1\u003e\n}\n```\nwill be compiled into:\n```hbs\n\u003ch1\u003eThis is typed template! And name is: {{@name}}\u003c/h1\u003e\n```\n---\nsubtemplates declaration:\n```jsx\nexport function MyComponent() {\n  const localTemplate = \u003ch1\u003eHello!\u003c/h1\u003e\n  return \u003cdiv\u003e{localTemplate}\u003c/div\u003e\n}\n```\nwill be compiled into:\n```hbs\n\u003cdiv\u003e\u003ch1\u003eHello!\u003c/h1\u003e\u003c/div\u003e\n```\n---\n\n### How convert JSX back to HBS and save it?\n\nFollowing blueprint created to convert any `.jsx/.tsx` file into `.hbs` template.\n\n```\nember g jsx-template-to-hbs app/templates/components/hello-world.jsx\n\noptions:\n   no-remove - no remove jsx/tsx source\n   no-write  - no wite converted output\n   no-rewrite - no rewrite template file if already exists\n   new-path:\"app/templates/components/original.hbs\" - new template file name\n```\n\n---\n\n### Can I convert HBS back to JSX? - nope\n\n---\nAll supported cases: [lifeart/ember-meta-explorer/test/utils/jsx-caster.test.js](https://github.com/lifeart/ember-meta-explorer/blob/master/test/utils/jsx-caster.test.js)\n\n\nContributing\n------------------------------------------------------------------------------\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n\nLicense\n------------------------------------------------------------------------------\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifeart%2Fember-cli-jsx-templates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flifeart%2Fember-cli-jsx-templates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifeart%2Fember-cli-jsx-templates/lists"}