wc-compiler 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -88,4 +88,4 @@ See our [website](https://merry-caramel-524e61.netlify.app/) for API docs and ex
88
88
 
89
89
  **WCC** is not a static site generator, framework or bundler. It is focused on producing raw HTML from Web Components with the intent of being easily integrated into a site generator or framework, like [**Greenwood**](https://github.com/ProjectEvergreen/greenwood/) or [**Eleventy**](https://github.com/ProjectEvergreen/eleventy-plugin-wcc/), the original motivation for creating [this project](https://github.com/ProjectEvergreen/greenwood/issues/935).
90
90
 
91
- In addition, **WCC** hopes to provide a surface area to explore patterns around [streaming](https://github.com/ProjectEvergreen/wcc/issues/5) and serverless rendering, as well as acting as a test bed for the [Web Components Community Groups](https://github.com/webcomponents-cg) discussions around community protocols, like [hydration](https://github.com/ProjectEvergreen/wcc/issues/3).
91
+ In addition, **WCC** hopes to provide a surface area to explore patterns around [streaming](https://github.com/ProjectEvergreen/wcc/issues/5), [serverless and edge rendering](https://github.com/thescientist13/web-components-at-the-edge), and as acting as a test bed for the [Web Components Community Groups](https://github.com/webcomponents-cg)'s discussions around community protocols, like [hydration](https://github.com/ProjectEvergreen/wcc/issues/3).
package/dist/wcc.dist.cjs CHANGED
@@ -86,7 +86,7 @@ class Document extends Node$1 {
86
86
  return new HTMLTemplateElement();
87
87
 
88
88
  default:
89
- return new HTMLElement();
89
+ return new HTMLElement$1();
90
90
 
91
91
  }
92
92
  }
@@ -98,7 +98,7 @@ class Document extends Node$1 {
98
98
 
99
99
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
100
100
  // EventTarget <- Node <- Element <- HTMLElement
101
- class HTMLElement extends Element {
101
+ class HTMLElement$1 extends Element {
102
102
  attachShadow(options) {
103
103
  this.shadowRoot = new ShadowRoot(options);
104
104
 
@@ -129,7 +129,7 @@ class ShadowRoot extends DocumentFragment {
129
129
 
130
130
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement
131
131
  // EventTarget <- Node <- Element <- HTMLElement <- HTMLTemplateElement
132
- class HTMLTemplateElement extends HTMLElement {
132
+ class HTMLTemplateElement extends HTMLElement$1 {
133
133
  constructor() {
134
134
  super();
135
135
  this.content = new DocumentFragment();
@@ -171,7 +171,7 @@ class CustomElementsRegistry {
171
171
  globalThis.addEventListener = noop;
172
172
  globalThis.document = new Document();
173
173
  globalThis.customElements = new CustomElementsRegistry();
174
- globalThis.HTMLElement = HTMLElement;
174
+ globalThis.HTMLElement = HTMLElement$1;
175
175
 
176
176
  // Reserved word lists for various dialects of the language
177
177
 
@@ -27934,7 +27934,8 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
27934
27934
  const specifier = node.source.value;
27935
27935
  const isBareSpecifier = specifier.indexOf('.') !== 0 && specifier.indexOf('/') !== 0;
27936
27936
 
27937
- if (!isBareSpecifier) {
27937
+ // TODO would like to decouple .jsx from the core, ideally
27938
+ if (!isBareSpecifier && ['.js', '.jsx'].includes(path__default["default"].extname(specifier))) {
27938
27939
  const dependencyModuleURL = new URL(node.source.value, moduleURL);
27939
27940
 
27940
27941
  registerDependencies(dependencyModuleURL, definitions, nextDepth);
@@ -27943,7 +27944,9 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
27943
27944
  ExpressionStatement(node) {
27944
27945
  if (isCustomElementDefinitionNode(node)) {
27945
27946
  const { arguments: args } = node.expression;
27946
- const tagName = args[0].value;
27947
+ const tagName = args[0].type === 'Literal'
27948
+ ? args[0].value // single and double quotes
27949
+ : args[0].quasis[0].value.raw; // template literal
27947
27950
  const tree = parseJsx(moduleURL);
27948
27951
  const isEntry = nextDepth - 1 === 1;
27949
27952
 
@@ -27995,19 +27998,25 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
27995
27998
  : (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).default;
27996
27999
  const dataLoader = (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).getData;
27997
28000
  const data = dataLoader ? await dataLoader() : {};
27998
- const elementInstance = new element(data); // eslint-disable-line new-cap
27999
28001
 
28000
- attrs.forEach((attr) => {
28001
- elementInstance.setAttribute(attr.name, attr.value);
28002
+ if (element) {
28003
+ const elementInstance = new element(data); // eslint-disable-line new-cap
28002
28004
 
28003
- if (attr.name === 'hydrate') {
28004
- definitions[tagName].hydrate = attr.value;
28005
- }
28006
- });
28007
-
28008
- await elementInstance.connectedCallback();
28009
-
28010
- return elementInstance;
28005
+ attrs.forEach((attr) => {
28006
+ elementInstance.setAttribute(attr.name, attr.value);
28007
+
28008
+ if (attr.name === 'hydrate') {
28009
+ definitions[tagName].hydrate = attr.value;
28010
+ }
28011
+ });
28012
+
28013
+ await elementInstance.connectedCallback();
28014
+
28015
+ return elementInstance;
28016
+ } else {
28017
+ console.debug('No custom element class found for this file');
28018
+ return new HTMLElement();
28019
+ }
28011
28020
  }
28012
28021
 
28013
28022
  async function renderToString(elementURL) {
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "wc-compiler",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Experimental native Web Components compiler.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/ProjectEvergreen/wcc.git"
8
+ },
5
9
  "main": "src/wcc.js",
6
10
  "type": "module",
7
11
  "author": "Owen Buckley <owen@thegreenhouse.io>",
@@ -23,10 +27,10 @@
23
27
  "build": "node ./build.js",
24
28
  "serve": "node ./build.js && http-server ./dist --open",
25
29
  "start": "npm run develop",
26
- "test": "mocha --exclude \"./test/cases/jsx/**\" \"./test/**/**/*.spec.js\"",
27
- "test:jsx": "c8 node --experimental-loader ./test-jsx-loader.js ./node_modules/mocha/bin/mocha \"./test/**/**/*.spec.js\"",
30
+ "test": "mocha --exclude \"./test/cases/jsx/**\" --exclude \"./test/cases/custom-extension/**\" \"./test/**/**/*.spec.js\"",
31
+ "test:exp": "c8 node --experimental-loader ./test-exp-loader.js ./node_modules/mocha/bin/mocha \"./test/**/**/*.spec.js\"",
28
32
  "test:tdd": "npm run test -- --watch",
29
- "test:tdd:jsx": "npm run test:jsx -- --watch",
33
+ "test:tdd:exp": "npm run test:exp -- --watch",
30
34
  "dist": "rollup -c rollup.config.js",
31
35
  "prepublishOnly": "npm run clean && npm run dist"
32
36
  },
package/src/wcc.js CHANGED
@@ -8,6 +8,7 @@ import escodegen from 'escodegen';
8
8
  import { getParser, parseJsx } from './jsx-loader.js';
9
9
  import { parse, parseFragment, serialize } from 'parse5';
10
10
  import fs from 'fs';
11
+ import path from 'path';
11
12
 
12
13
  function getParse(html) {
13
14
  return html.indexOf('<html>') >= 0 || html.indexOf('<body>') >= 0 || html.indexOf('<head>') >= 0
@@ -74,7 +75,8 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
74
75
  const specifier = node.source.value;
75
76
  const isBareSpecifier = specifier.indexOf('.') !== 0 && specifier.indexOf('/') !== 0;
76
77
 
77
- if (!isBareSpecifier) {
78
+ // TODO would like to decouple .jsx from the core, ideally
79
+ if (!isBareSpecifier && ['.js', '.jsx'].includes(path.extname(specifier))) {
78
80
  const dependencyModuleURL = new URL(node.source.value, moduleURL);
79
81
 
80
82
  registerDependencies(dependencyModuleURL, definitions, nextDepth);
@@ -83,7 +85,9 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
83
85
  ExpressionStatement(node) {
84
86
  if (isCustomElementDefinitionNode(node)) {
85
87
  const { arguments: args } = node.expression;
86
- const tagName = args[0].value;
88
+ const tagName = args[0].type === 'Literal'
89
+ ? args[0].value // single and double quotes
90
+ : args[0].quasis[0].value.raw; // template literal
87
91
  const tree = parseJsx(moduleURL);
88
92
  const isEntry = nextDepth - 1 === 1;
89
93
 
@@ -135,19 +139,25 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
135
139
  : (await import(pathname)).default;
136
140
  const dataLoader = (await import(pathname)).getData;
137
141
  const data = dataLoader ? await dataLoader() : {};
138
- const elementInstance = new element(data); // eslint-disable-line new-cap
139
142
 
140
- attrs.forEach((attr) => {
141
- elementInstance.setAttribute(attr.name, attr.value);
143
+ if (element) {
144
+ const elementInstance = new element(data); // eslint-disable-line new-cap
142
145
 
143
- if (attr.name === 'hydrate') {
144
- definitions[tagName].hydrate = attr.value;
145
- }
146
- });
147
-
148
- await elementInstance.connectedCallback();
149
-
150
- return elementInstance;
146
+ attrs.forEach((attr) => {
147
+ elementInstance.setAttribute(attr.name, attr.value);
148
+
149
+ if (attr.name === 'hydrate') {
150
+ definitions[tagName].hydrate = attr.value;
151
+ }
152
+ });
153
+
154
+ await elementInstance.connectedCallback();
155
+
156
+ return elementInstance;
157
+ } else {
158
+ console.debug('No custom element class found for this file');
159
+ return new HTMLElement();
160
+ }
151
161
  }
152
162
 
153
163
  async function renderToString(elementURL) {