wc-compiler 0.12.0 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wc-compiler",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Experimental native Web Components compiler.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,14 +28,14 @@
28
28
  },
29
29
  "scripts": {
30
30
  "clean": "rimraf ./dist",
31
- "lint": "ls-lint && eslint \"*.*js\" \"./src/**/**/*.js*\" \"./sandbox/**/**/*.js*\" \"./docs/**/*.md\" \"./test/**/**/*.js*\"",
31
+ "lint": "eslint --ignore-pattern \"*.json\" \"*.*js\" \"./src/**/**/*.js*\" \"./sandbox/**/**/*.js*\" \"./docs/**/*.md\" \"./test/**/**/*.js*\"",
32
32
  "docs:dev": "concurrently \"nodemon --watch src --watch docs -e js,md,css,html,jsx ./build.js\" \"http-server ./dist --open\"",
33
33
  "docs:build": "node ./build.js",
34
34
  "docs:serve": "npm run clean && npm run docs:build && http-server ./dist --open",
35
- "sandbox": "npm run clean && concurrently \"nodemon --experimental-loader ./test-exp-loader.js --watch src --watch sandbox -e js,md,css,html,jsx ./sandbox.js\" \"http-server ./dist --open\" \"livereload ./dist\"",
35
+ "sandbox": "npm run clean && concurrently \"nodemon --loader ./test-exp-loader.js --watch src --watch sandbox -e js,md,css,html,jsx ./sandbox.js\" \"http-server ./dist --open\" \"livereload ./dist\"",
36
36
  "start": "npm run docs:serve",
37
37
  "test": "mocha --exclude \"./test/cases/jsx*/**\" --exclude \"./test/cases/custom-extension/**\" \"./test/**/**/*.spec.js\"",
38
- "test:exp": "c8 node --experimental-loader ./test-exp-loader.js ./node_modules/mocha/bin/mocha \"./test/**/**/*.spec.js\"",
38
+ "test:exp": "c8 node --loader ./test-exp-loader.js ./node_modules/mocha/bin/mocha \"./test/**/**/*.spec.js\"",
39
39
  "test:tdd": "npm run test -- --watch",
40
40
  "test:tdd:exp": "npm run test:exp -- --watch",
41
41
  "dist": "rollup -c rollup.config.js",
@@ -45,10 +45,15 @@
45
45
  "@projectevergreen/acorn-jsx-esm": "~0.1.0",
46
46
  "@projectevergreen/escodegen-esm": "~0.1.0",
47
47
  "acorn": "^8.7.0",
48
+ "acorn-import-attributes": "^1.9.5",
48
49
  "acorn-walk": "^8.2.0",
49
50
  "parse5": "^6.0.1"
50
51
  },
51
52
  "devDependencies": {
53
+ "@babel/core": "^7.24.4",
54
+ "@babel/eslint-parser": "^7.24.1",
55
+ "@babel/plugin-syntax-import-assertions": "^7.24.1",
56
+ "@babel/preset-react": "^7.24.1",
52
57
  "@ls-lint/ls-lint": "^1.10.0",
53
58
  "@mapbox/rehype-prism": "^0.8.0",
54
59
  "@rollup/plugin-commonjs": "^25.0.7",
package/src/dom-shim.js CHANGED
@@ -1,5 +1,13 @@
1
1
  function noop() { }
2
2
 
3
+ // https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet
4
+ class CSSStyleSheet {
5
+ insertRule() { }
6
+ deleteRule() { }
7
+ replace() { }
8
+ replaceSync() { }
9
+ }
10
+
3
11
  // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
4
12
  class EventTarget {
5
13
  constructor() {
@@ -93,6 +101,7 @@ class ShadowRoot extends DocumentFragment {
93
101
  constructor(options) {
94
102
  super();
95
103
  this.mode = options.mode || 'closed';
104
+ this.adoptedStyleSheets = [];
96
105
  }
97
106
  }
98
107
 
@@ -146,4 +155,5 @@ class CustomElementsRegistry {
146
155
  globalThis.addEventListener = globalThis.addEventListener ?? noop;
147
156
  globalThis.document = globalThis.document ?? new Document();
148
157
  globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry();
149
- globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
158
+ globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement;
159
+ globalThis.CSSStyleSheet = globalThis.CSSStyleSheet ?? CSSStyleSheet;
package/src/jsx-loader.js CHANGED
@@ -4,8 +4,10 @@ import * as acorn from 'acorn';
4
4
  import * as walk from 'acorn-walk';
5
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
+ // Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
10
+ import { importAttributes } from 'acorn-import-attributes';
9
11
 
10
12
  const jsxRegex = /\.(jsx)$/;
11
13
 
@@ -29,7 +31,7 @@ export function getParser(moduleURL) {
29
31
  }
30
32
 
31
33
  return {
32
- parser: acorn.Parser.extend(jsx()),
34
+ parser: acorn.Parser.extend(jsx(), importAttributes),
33
35
  config: {
34
36
  // https://github.com/acornjs/acorn/issues/829#issuecomment-1172586171
35
37
  ...walk.base,
@@ -236,7 +238,7 @@ export function parseJsx(moduleURL) {
236
238
  const hasOwnObservedAttributes = undefined;
237
239
  let inferredObservability = false;
238
240
  let observedAttributes = [];
239
- let tree = acorn.Parser.extend(jsx()).parse(moduleContents, {
241
+ let tree = acorn.Parser.extend(jsx(), importAttributes).parse(moduleContents, {
240
242
  ecmaVersion: 'latest',
241
243
  sourceType: 'module'
242
244
  });
package/src/wcc.js CHANGED
@@ -7,6 +7,8 @@ import * as walk from 'acorn-walk';
7
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
+ // Need an acorn plugin for now - https://github.com/ProjectEvergreen/greenwood/issues/1218
11
+ import { importAttributes } from 'acorn-import-attributes';
10
12
  import fs from 'fs';
11
13
 
12
14
  function getParse(html) {
@@ -61,12 +63,12 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
61
63
  const moduleContents = fs.readFileSync(moduleURL, 'utf-8');
62
64
  const nextDepth = depth += 1;
63
65
  const customParser = getParser(moduleURL);
64
- const parser = customParser ? customParser.parser : acorn;
66
+ const parser = customParser ? customParser.parser : acorn.Parser;
65
67
  const config = customParser ? customParser.config : {
66
68
  ...walk.base
67
69
  };
68
70
 
69
- walk.simple(parser.parse(moduleContents, {
71
+ walk.simple(parser.extend(importAttributes).parse(moduleContents, {
70
72
  ecmaVersion: 'latest',
71
73
  sourceType: 'module'
72
74
  }), {
@@ -106,13 +108,13 @@ function registerDependencies(moduleURL, definitions, depth = 0) {
106
108
  async function getTagName(moduleURL) {
107
109
  const moduleContents = await fs.promises.readFile(moduleURL, 'utf-8');
108
110
  const customParser = getParser(moduleURL);
109
- const parser = customParser ? customParser.parser : acorn;
111
+ const parser = customParser ? customParser.parser : acorn.Parser;
110
112
  const config = customParser ? customParser.config : {
111
113
  ...walk.base
112
114
  };
113
115
  let tagName;
114
116
 
115
- walk.simple(parser.parse(moduleContents, {
117
+ walk.simple(parser.extend(importAttributes).parse(moduleContents, {
116
118
  ecmaVersion: 'latest',
117
119
  sourceType: 'module'
118
120
  }), {
@@ -133,9 +135,10 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
133
135
  }
134
136
 
135
137
  // https://github.com/ProjectEvergreen/wcc/pull/67/files#r902061804
136
- const { pathname } = elementURL;
137
- const element = customElements.get(tagName) ?? (await import(pathname)).default;
138
- const dataLoader = (await import(pathname)).getData;
138
+ // https://github.com/ProjectEvergreen/wcc/pull/159
139
+ const { href } = elementURL;
140
+ const element = customElements.get(tagName) ?? (await import(href)).default;
141
+ const dataLoader = (await import(href)).getData;
139
142
  const data = props
140
143
  ? props
141
144
  : dataLoader