wc-compiler 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/wcc.dist.cjs +2881 -12177
- package/package.json +6 -7
- package/src/dom-shim.js +13 -7
- package/src/jsx-loader.js +4 -4
- package/src/wcc.js +3 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc-compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Experimental native Web Components compiler.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,18 +42,17 @@
|
|
|
42
42
|
"prepublishOnly": "npm run clean && npm run dist"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"@projectevergreen/acorn-jsx-esm": "~0.1.0",
|
|
46
|
+
"@projectevergreen/escodegen-esm": "~0.1.0",
|
|
45
47
|
"acorn": "^8.7.0",
|
|
46
|
-
"acorn-jsx": "^5.3.2",
|
|
47
48
|
"acorn-walk": "^8.2.0",
|
|
48
|
-
"escodegen": "^2.0.0",
|
|
49
49
|
"parse5": "^6.0.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@ls-lint/ls-lint": "^1.10.0",
|
|
53
53
|
"@mapbox/rehype-prism": "^0.8.0",
|
|
54
|
-
"@rollup/plugin-commonjs": "^
|
|
55
|
-
"@rollup/plugin-
|
|
56
|
-
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
54
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
55
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
57
56
|
"c8": "^7.11.2",
|
|
58
57
|
"chai": "^4.3.6",
|
|
59
58
|
"concurrently": "^7.1.0",
|
|
@@ -74,7 +73,7 @@
|
|
|
74
73
|
"remark-rehype": "^10.1.0",
|
|
75
74
|
"remark-toc": "^8.0.1",
|
|
76
75
|
"rimraf": "^3.0.2",
|
|
77
|
-
"rollup": "^
|
|
76
|
+
"rollup": "^3.29.3",
|
|
78
77
|
"simple.css": "^0.1.3",
|
|
79
78
|
"unified": "^10.1.2"
|
|
80
79
|
}
|
package/src/dom-shim.js
CHANGED
|
@@ -123,21 +123,27 @@ class HTMLTemplateElement extends HTMLElement {
|
|
|
123
123
|
// https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry
|
|
124
124
|
class CustomElementsRegistry {
|
|
125
125
|
constructor() {
|
|
126
|
-
this
|
|
126
|
+
// TODO this should probably be a set or otherwise follow the spec?
|
|
127
|
+
// https://github.com/ProjectEvergreen/wcc/discussions/145
|
|
128
|
+
this.customElementsRegistry = new Map();
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
define(tagName, BaseClass) {
|
|
130
|
-
this
|
|
132
|
+
// TODO this should probably fail as per the spec...
|
|
133
|
+
// e.g. if(this.customElementsRegistry.get(tagName))
|
|
134
|
+
// https://github.com/ProjectEvergreen/wcc/discussions/145
|
|
135
|
+
this.customElementsRegistry.set(tagName, BaseClass);
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
get(tagName) {
|
|
134
|
-
return this.customElementsRegistry
|
|
139
|
+
return this.customElementsRegistry.get(tagName);
|
|
135
140
|
}
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
// mock top level aliases (globalThis === window)
|
|
139
144
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window
|
|
140
|
-
|
|
141
|
-
globalThis.
|
|
142
|
-
globalThis.
|
|
143
|
-
globalThis.
|
|
145
|
+
// make this "idempotent" for now until a better idea comes along - https://github.com/ProjectEvergreen/wcc/discussions/145
|
|
146
|
+
globalThis.addEventListener = globalThis.addEventListener ?? noop;
|
|
147
|
+
globalThis.document = globalThis.document ?? new Document();
|
|
148
|
+
globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry();
|
|
149
|
+
globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
|
package/src/jsx-loader.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// https://nodejs.org/api/esm.html#esm_loaders
|
|
3
3
|
import * as acorn from 'acorn';
|
|
4
4
|
import * as walk from 'acorn-walk';
|
|
5
|
-
import
|
|
5
|
+
import { generate } from '@projectevergreen/escodegen-esm';
|
|
6
6
|
import fs from 'fs';
|
|
7
|
-
import jsx from 'acorn-jsx';
|
|
7
|
+
import jsx from '@projectevergreen/acorn-jsx-esm';
|
|
8
8
|
import { parse, parseFragment, serialize } from 'parse5';
|
|
9
9
|
|
|
10
10
|
const jsxRegex = /\.(jsx)$/;
|
|
@@ -323,7 +323,7 @@ export function parseJsx(moduleURL) {
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
let newModuleContents =
|
|
326
|
+
let newModuleContents = generate(tree);
|
|
327
327
|
|
|
328
328
|
// TODO better way to determine value type?
|
|
329
329
|
/* eslint-disable indent */
|
|
@@ -391,7 +391,7 @@ export async function load(url, context, defaultLoad) {
|
|
|
391
391
|
|
|
392
392
|
return {
|
|
393
393
|
format: 'module',
|
|
394
|
-
source:
|
|
394
|
+
source: generate(jsFromJsx),
|
|
395
395
|
shortCircuit: true
|
|
396
396
|
};
|
|
397
397
|
}
|
package/src/wcc.js
CHANGED
|
@@ -4,7 +4,7 @@ import './dom-shim.js';
|
|
|
4
4
|
|
|
5
5
|
import * as acorn from 'acorn';
|
|
6
6
|
import * as walk from 'acorn-walk';
|
|
7
|
-
import
|
|
7
|
+
import { generate } from '@projectevergreen/escodegen-esm';
|
|
8
8
|
import { getParser, parseJsx } from './jsx-loader.js';
|
|
9
9
|
import { parse, parseFragment, serialize } from 'parse5';
|
|
10
10
|
import fs from 'fs';
|
|
@@ -94,7 +94,7 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
|
|
|
94
94
|
definitions[tagName] = {
|
|
95
95
|
instanceName: args[1].name,
|
|
96
96
|
moduleURL,
|
|
97
|
-
source:
|
|
97
|
+
source: generate(tree),
|
|
98
98
|
url: moduleURL,
|
|
99
99
|
isEntry
|
|
100
100
|
};
|
|
@@ -134,9 +134,7 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
134
134
|
|
|
135
135
|
// https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
|
|
136
136
|
const { pathname } = elementURL;
|
|
137
|
-
const element = tagName
|
|
138
|
-
? customElements.get(tagName)
|
|
139
|
-
: (await import(pathname)).default;
|
|
137
|
+
const element = customElements.get(tagName) ?? (await import(pathname)).default;
|
|
140
138
|
const dataLoader = (await import(pathname)).getData;
|
|
141
139
|
const data = props
|
|
142
140
|
? props
|