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

bug/issue 174 swap escodegen with astring for modern JS syntax support #176

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 27 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
},
"dependencies": {
"@projectevergreen/acorn-jsx-esm": "~0.1.0",
"@projectevergreen/escodegen-esm": "~0.1.0",
"acorn": "^8.7.0",
"acorn-import-attributes": "^1.9.5",
"acorn-walk": "^8.2.0",
"astring": "^1.9.0",
"parse5": "^6.0.1",
"sucrase": "^3.35.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/jsx-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// https://nodejs.org/api/esm.html#esm_loaders
import * as acorn from 'acorn';
import * as walk from 'acorn-walk';
import { generate } from '@projectevergreen/escodegen-esm';
import { generate } from 'astring';
import fs from 'fs';
// ideally we can eventually adopt an ESM compatible version of this plugin
// https://github.com/acornjs/acorn-jsx/issues/112
import jsx from '@projectevergreen/acorn-jsx-esm';
import { parse, parseFragment, serialize } from 'parse5';
// Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
Expand All @@ -12,7 +14,7 @@

const jsxRegex = /\.(jsx)$/;

// TODO same hack as definitions

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (20)

Unexpected ' TODO' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected 'todo' comment: 'TODO same hack as definitions'

Check warning on line 17 in src/jsx-loader.js

View workflow job for this annotation

GitHub Actions / build (18)

Unexpected ' TODO' comment: 'TODO same hack as definitions'
// https://github.com/ProjectEvergreen/wcc/discussions/74
let string;

Expand Down
2 changes: 1 addition & 1 deletion src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './dom-shim.js';

import * as acorn from 'acorn';
import * as walk from 'acorn-walk';
import { generate } from '@projectevergreen/escodegen-esm';
import { generate } from 'astring';
import { getParser, parseJsx } from './jsx-loader.js';
import { parse, parseFragment, serialize } from 'parse5';
// Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
Expand Down
15 changes: 9 additions & 6 deletions test/cases/attributes/src/components/counter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
class Counter extends HTMLElement {
#count;

constructor(props = {}) {
super();

this.props = props;
this.#count = 0;

if (this.shadowRoot) {
this.hydrate();
Expand All @@ -18,20 +21,20 @@ class Counter extends HTMLElement {
}

setCount() {
this.count = this.hasAttribute('count')
this.#count = this.hasAttribute('count')
? parseInt(this.getAttribute('count'), 10)
: this.props.count
? this.props.count
: 0;
: this.#count;
}

inc() {
this.count += 1;
this.#count += 1;
this.update();
}

dec() {
this.count -= 1;
this.#count -= 1;
this.update();
}

Expand All @@ -46,15 +49,15 @@ class Counter extends HTMLElement {
}

update() {
this.shadowRoot.querySelector('span#count').textContent = this.count;
this.shadowRoot.querySelector('span#count').textContent = this.#count;
}

render() {
return `
<template shadowrootmode="open">
<div>
<button id="inc">Increment</button>
<span>Current Count: <span id="count">${this.count}</span></span>
<span>Current Count: <span id="count">${this.#count}</span></span>
<button id="dec">Decrement</button>
</div>
</template>
Expand Down
2 changes: 2 additions & 0 deletions test/cases/jsx/src/counter.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import './badge.jsx';

export default class Counter extends HTMLElement {
#count;

constructor() {
super();
this.count = 0;
Expand Down
Loading