Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/issue 69 jsx transformations #73

Merged
merged 41 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
83f3d31
basic proof of concept transforming JSX
thescientist13 Jul 2, 2022
52fc5d1
small refactor
thescientist13 Jul 2, 2022
391d3ef
basic JSX transform working
thescientist13 Jul 3, 2022
128d95d
sandbox dev workflow and counter control example
thescientist13 Jul 4, 2022
10ac1f4
hardcoded reference transformation working
thescientist13 Jul 4, 2022
8490477
manual event handling commented code
thescientist13 Jul 4, 2022
5c28814
shadow dom examples for control and transform groups
thescientist13 Jul 4, 2022
f0824b1
comments and minor refactor
thescientist13 Jul 8, 2022
012341e
basic JSX to HTML string transformation working with attributes
thescientist13 Jul 8, 2022
2fdb08f
convert expression containers to template literal
thescientist13 Jul 8, 2022
7ea9151
convert parsed JSX to HTML AST and apply initial DOM depth __this__ s…
thescientist13 Jul 8, 2022
ac0d4fa
recrusively detect and replace depthful __this__
thescientist13 Jul 8, 2022
b009eff
connect JSX transform to sandbox output and it works, woohoo
thescientist13 Jul 8, 2022
050f931
shadow dom and relative __this__ depth support
thescientist13 Jul 9, 2022
db63a51
very naive reactivity on JSX assignment expressions in events
thescientist13 Jul 9, 2022
d11edd5
nodejs and compiler based JSX tranforms and ESM support to produce SS…
thescientist13 Jul 14, 2022
743be15
return JSX sources from compiler
thescientist13 Jul 15, 2022
4721753
de async acorn walk and implement a basic TODO app component with nes…
thescientist13 Jul 16, 2022
8c136c8
fix todo app build
thescientist13 Jul 17, 2022
6bd3468
improve member expression support for JSX
thescientist13 Jul 17, 2022
b7ae28b
handle attributes with only names
thescientist13 Jul 20, 2022
21235c3
addTodo
thescientist13 Jul 20, 2022
a790dc4
fix todo nodemon for develop
thescientist13 Jul 20, 2022
781195a
pass data and display list of TODOs
thescientist13 Jul 20, 2022
f8d2785
WIP deleteTodo event handling
thescientist13 Jul 21, 2022
6099044
post rebase fixes
thescientist13 Jul 27, 2022
3587984
delete TODO
thescientist13 Jul 27, 2022
39e3c40
complete TODO
thescientist13 Jul 27, 2022
bc66fde
add badge component and improve JSX attribute transoformation for non…
thescientist13 Jul 28, 2022
c769767
enable testing with JSX loader and add spec coverage
thescientist13 Jul 29, 2022
8a185ad
fix errors in spec file
thescientist13 Jul 29, 2022
647ebf4
configure CI for Node 16 min version
thescientist13 Jul 29, 2022
c6f621c
refactor npm script
thescientist13 Jul 30, 2022
db88b70
cross platform testing working
thescientist13 Jul 31, 2022
427000d
clean up demo and prototyping code
thescientist13 Aug 9, 2022
e8f8238
document JSX
thescientist13 Aug 9, 2022
990d8f3
support dual testing for JSX
thescientist13 Aug 10, 2022
6584e29
disable coverage for non JSX specs
thescientist13 Aug 10, 2022
46ae7ea
update docs example
thescientist13 Aug 10, 2022
63ef1f2
clean up and track TODOs
thescientist13 Aug 13, 2022
6cf48ba
clean up and track TODOs
thescientist13 Aug 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"checkCoverage": true,

"statements": 90,
"branches": 90,
"branches": 85,
"functions": 90,
"lines": 90,

Expand Down
5 changes: 4 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module.exports = {
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
env: {
browser: false,
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/ci-jsx-win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Continuous Integration Windows JSX

on: [pull_request]

jobs:

build:
runs-on: windows-latest

strategy:
matrix:
node: [16]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Installing project dependencies
run: |
npm ci
- name: Lint
run: |
npm run lint
- name: Test
run: |
npm run test:jsx
- name: Build
run: |
npm run build
31 changes: 31 additions & 0 deletions .github/workflows/ci-jsx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Continuous Integration JSX

on: [pull_request]

jobs:

build:
runs-on: ubuntu-18.04

strategy:
matrix:
node: [16]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- name: Installing project dependencies
run: |
npm ci
- name: Lint
run: |
npm run lint
- name: Test
run: |
npm run test:jsx
- name: Build
run: |
npm run build
2 changes: 1 addition & 1 deletion .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
npm run lint
- name: Test
run: |
npm run test
npm test
- name: Build
run: |
npm run build
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
npm run lint
- name: Test
run: |
npm run test
npm test
- name: Build
run: |
npm run build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.vscode/
coverage/
dist/
node_modules/
node_modules/
sandbox/
5 changes: 0 additions & 5 deletions .mocharc.cjs

This file was deleted.

53 changes: 52 additions & 1 deletion docs/pages/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,55 @@ export async function getData() {

- Make sure to define your custom elements with `customElements.define`
- Make sure to include a `export default` for your custom element base class
- Avoid [touching the DOM in `constructor` methods](https://twitter.com/techytacos/status/1514029967981494280)
- Avoid [touching the DOM in `constructor` methods](https://twitter.com/techytacos/status/1514029967981494280)


## JSX

> ⚠️ _Very Experimental!_

Even more experimental than WCC is the option to author a rendering function for native `HTMLElements`, that can compile down to a zero run time, web ready custom element! It handles resolving event handling and `this` references and can manage some basic re-rendering lifecycles.

### Example

Below is an example of what is possible right now [demonstrated](https://github.com/thescientist13/greenwood-counter-jsx) through a Counter component.
```jsx
export default class Counter extends HTMLElement {
constructor() {
super();
this.count = 0;
}

connectedCallback() {
this.render();
}

render() {
const { count } = this;

return (
<div>
<button onclick={this.count -= 1}> -</button>
<span>You have clicked <span class="red">{count}</span> times</span>
<button onclick={this.count += 1}> +</button>
</div>
);
}
}

customElements.define('wcc-counter', Counter);
```

There is an [active discussion tracking features](https://github.com/ProjectEvergreen/wcc/discussions/84) and [issues in progress](https://github.com/ProjectEvergreen/wcc/issues?q=is%3Aopen+is%3Aissue+label%3AJSX) to continue iterating on this, so please feel free to try it out and give us your feedback!

### Prerequisites

There are of couple things you will need to do to use WCC with JSX:
1. NodeJS version needs to be `16.x`
1. You will need to use the _.jsx_ extension
1. Requires the `--experimental-loaders` flag when invoking NodeJS
```js
$ node --experimental-loader ./node_modules/wc-compiler/src/jsx-loader.js server.js
```

> _See our [example's page](/examples#jsx) for some usages of WCC + JSX._ 👀
6 changes: 5 additions & 1 deletion docs/pages/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,8 @@ export async function handler() {
`;
};
}
```
```

## JSX

A current example of a Todo App can be seen in [this repo](https://github.com/thescientist13/todo-app), which is a fork of [this Greenwood based Todo App which uses LitElement](https://github.com/ProjectEvergreen/todo-app). It can compile JSX for _**the client or the server**_ using [Greenwood](https://www.greenwoodjs.io/), and can even be used with the same unit testing tools! 💪
Loading