wc-compiler 0.7.0 → 0.9.0
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 +11 -9
- package/package.json +5 -2
- package/src/jsx-loader.js +4 -4
- package/src/wcc.js +10 -6
package/dist/wcc.dist.cjs
CHANGED
|
@@ -27629,8 +27629,6 @@ var serialize = function(node, options) {
|
|
|
27629
27629
|
|
|
27630
27630
|
/* eslint-disable max-depth, complexity */
|
|
27631
27631
|
|
|
27632
|
-
new URL(`file://${process.cwd()}/`);
|
|
27633
|
-
|
|
27634
27632
|
// TODO same hack as definitions
|
|
27635
27633
|
// https://github.com/ProjectEvergreen/wcc/discussions/74
|
|
27636
27634
|
let string;
|
|
@@ -27833,7 +27831,7 @@ function findThisReferences(context, statement) {
|
|
|
27833
27831
|
} else if (isRenderFunctionContext && type === 'VariableDeclaration') {
|
|
27834
27832
|
statement.declarations.forEach(declaration => {
|
|
27835
27833
|
const { init, id } = declaration;
|
|
27836
|
-
|
|
27834
|
+
|
|
27837
27835
|
if (init.object && init.object.type === 'ThisExpression') {
|
|
27838
27836
|
// const { description } = this.todo;
|
|
27839
27837
|
references.push(init.property.name);
|
|
@@ -28100,7 +28098,7 @@ async function getTagName(moduleURL) {
|
|
|
28100
28098
|
return tagName;
|
|
28101
28099
|
}
|
|
28102
28100
|
|
|
28103
|
-
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry) {
|
|
28101
|
+
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry, props = {}) {
|
|
28104
28102
|
if (!tagName) {
|
|
28105
28103
|
const depth = isEntry ? 1 : 0;
|
|
28106
28104
|
registerDependencies(elementURL, definitions, depth);
|
|
@@ -28112,7 +28110,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
28112
28110
|
? customElements.get(tagName)
|
|
28113
28111
|
: (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).default;
|
|
28114
28112
|
const dataLoader = (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).getData;
|
|
28115
|
-
const data =
|
|
28113
|
+
const data = props
|
|
28114
|
+
? props
|
|
28115
|
+
: dataLoader
|
|
28116
|
+
? await dataLoader(props)
|
|
28117
|
+
: {};
|
|
28116
28118
|
|
|
28117
28119
|
if (element) {
|
|
28118
28120
|
const elementInstance = new element(data); // eslint-disable-line new-cap
|
|
@@ -28134,18 +28136,18 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
28134
28136
|
}
|
|
28135
28137
|
}
|
|
28136
28138
|
|
|
28137
|
-
async function renderToString(elementURL) {
|
|
28139
|
+
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
|
|
28138
28140
|
const definitions = [];
|
|
28139
|
-
const elementTagName = await getTagName(elementURL);
|
|
28141
|
+
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
|
|
28140
28142
|
const isEntry = !!elementTagName;
|
|
28141
|
-
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry);
|
|
28143
|
+
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);
|
|
28142
28144
|
|
|
28143
28145
|
const elementHtml = elementInstance.shadowRoot
|
|
28144
28146
|
? elementInstance.getInnerHTML({ includeShadowRoots: true })
|
|
28145
28147
|
: elementInstance.innerHTML;
|
|
28146
28148
|
const elementTree = getParse(elementHtml)(elementHtml);
|
|
28147
28149
|
const finalTree = await renderComponentRoots(elementTree, definitions);
|
|
28148
|
-
const html = elementTagName ? `
|
|
28150
|
+
const html = wrappingEntryTag && elementTagName ? `
|
|
28149
28151
|
<${elementTagName}>
|
|
28150
28152
|
${serialize(finalTree)}
|
|
28151
28153
|
</${elementTagName}>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wc-compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Experimental native Web Components compiler.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"clean": "rimraf ./dist",
|
|
30
|
-
"lint": "eslint \"*.*js\" \"./src/**/**/*.js*\" \"./test/**/**/*.js*\"",
|
|
30
|
+
"lint": "ls-lint && eslint \"*.*js\" \"./src/**/**/*.js*\" \"./docs/**/*.md\" \"./test/**/**/*.js*\"",
|
|
31
31
|
"develop": "concurrently \"nodemon --watch src --watch docs -e js,md,css,html,jsx ./build.js\" \"http-server ./dist --open\"",
|
|
32
32
|
"build": "node ./build.js",
|
|
33
33
|
"serve": "node ./build.js && http-server ./dist --open",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"parse5": "^6.0.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"@ls-lint/ls-lint": "^1.10.0",
|
|
50
51
|
"@mapbox/rehype-prism": "^0.8.0",
|
|
51
52
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
52
53
|
"@rollup/plugin-json": "^4.1.0",
|
|
@@ -55,6 +56,8 @@
|
|
|
55
56
|
"chai": "^4.3.6",
|
|
56
57
|
"concurrently": "^7.1.0",
|
|
57
58
|
"eslint": "^8.14.0",
|
|
59
|
+
"eslint-plugin-markdown": "^3.0.0",
|
|
60
|
+
"eslint-plugin-no-only-tests": "^2.6.0",
|
|
58
61
|
"http-server": "^14.1.0",
|
|
59
62
|
"jsdom": "^19.0.0",
|
|
60
63
|
"mocha": "^9.2.2",
|
package/src/jsx-loader.js
CHANGED
|
@@ -7,7 +7,6 @@ import fs from 'fs';
|
|
|
7
7
|
import jsx from 'acorn-jsx';
|
|
8
8
|
import { parse, parseFragment, serialize } from 'parse5';
|
|
9
9
|
|
|
10
|
-
const baseURL = new URL(`file://${process.cwd()}/`);
|
|
11
10
|
const jsxRegex = /\.(jsx)$/;
|
|
12
11
|
|
|
13
12
|
// TODO same hack as definitions
|
|
@@ -212,7 +211,7 @@ function findThisReferences(context, statement) {
|
|
|
212
211
|
} else if (isRenderFunctionContext && type === 'VariableDeclaration') {
|
|
213
212
|
statement.declarations.forEach(declaration => {
|
|
214
213
|
const { init, id } = declaration;
|
|
215
|
-
|
|
214
|
+
|
|
216
215
|
if (init.object && init.object.type === 'ThisExpression') {
|
|
217
216
|
// const { description } = this.todo;
|
|
218
217
|
references.push(init.property.name);
|
|
@@ -363,11 +362,12 @@ export function parseJsx(moduleURL) {
|
|
|
363
362
|
// --------------
|
|
364
363
|
|
|
365
364
|
export function resolve(specifier, context, defaultResolve) {
|
|
366
|
-
const { parentURL
|
|
365
|
+
const { parentURL } = context;
|
|
367
366
|
|
|
368
367
|
if (jsxRegex.test(specifier)) {
|
|
369
368
|
return {
|
|
370
|
-
url: new URL(specifier, parentURL).href
|
|
369
|
+
url: new URL(specifier, parentURL).href,
|
|
370
|
+
shortCircuit: true
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
373
|
|
package/src/wcc.js
CHANGED
|
@@ -126,7 +126,7 @@ async function getTagName(moduleURL) {
|
|
|
126
126
|
return tagName;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry) {
|
|
129
|
+
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry, props = {}) {
|
|
130
130
|
if (!tagName) {
|
|
131
131
|
const depth = isEntry ? 1 : 0;
|
|
132
132
|
registerDependencies(elementURL, definitions, depth);
|
|
@@ -138,7 +138,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
138
138
|
? customElements.get(tagName)
|
|
139
139
|
: (await import(pathname)).default;
|
|
140
140
|
const dataLoader = (await import(pathname)).getData;
|
|
141
|
-
const data =
|
|
141
|
+
const data = props
|
|
142
|
+
? props
|
|
143
|
+
: dataLoader
|
|
144
|
+
? await dataLoader(props)
|
|
145
|
+
: {};
|
|
142
146
|
|
|
143
147
|
if (element) {
|
|
144
148
|
const elementInstance = new element(data); // eslint-disable-line new-cap
|
|
@@ -160,18 +164,18 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
async function renderToString(elementURL) {
|
|
167
|
+
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
|
|
164
168
|
const definitions = [];
|
|
165
|
-
const elementTagName = await getTagName(elementURL);
|
|
169
|
+
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
|
|
166
170
|
const isEntry = !!elementTagName;
|
|
167
|
-
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry);
|
|
171
|
+
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);
|
|
168
172
|
|
|
169
173
|
const elementHtml = elementInstance.shadowRoot
|
|
170
174
|
? elementInstance.getInnerHTML({ includeShadowRoots: true })
|
|
171
175
|
: elementInstance.innerHTML;
|
|
172
176
|
const elementTree = getParse(elementHtml)(elementHtml);
|
|
173
177
|
const finalTree = await renderComponentRoots(elementTree, definitions);
|
|
174
|
-
const html = elementTagName ? `
|
|
178
|
+
const html = wrappingEntryTag && elementTagName ? `
|
|
175
179
|
<${elementTagName}>
|
|
176
180
|
${serialize(finalTree)}
|
|
177
181
|
</${elementTagName}>
|