`) > -1)
126 | t.true(html.indexOf(`
Chandler
`) > -1)
127 | t.true(html.indexOf(`border: 1px solid green;`) > -1)
128 |
129 | })
130 |
--------------------------------------------------------------------------------
/test/moduleResolutionTest.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 |
3 | import { ModuleResolution } from "../src/moduleResolution.js";
4 |
5 | test("Resolve component path in dependency", async t => {
6 | let m = new ModuleResolution();
7 | m.setTagName("my-tag");
8 |
9 | t.is(m.resolve("npm:pretend"), "./node_modules/pretend/my-tag.webc");
10 | t.is(m.resolve("npm:pretend/real.webc"), "./node_modules/pretend/real.webc");
11 | t.is(m.resolve("npm:pretend/pretend"), "./node_modules/pretend/pretend/my-tag.webc");
12 | t.is(m.resolve("npm:pretend/pretend/real.webc"), "./node_modules/pretend/pretend/real.webc");
13 | t.is(m.resolve("npm:@11ty/pretend"), "./node_modules/@11ty/pretend/my-tag.webc");
14 | t.is(m.resolve("npm:@11ty/pretend/real"), "./node_modules/@11ty/pretend/real/my-tag.webc");
15 | t.is(m.resolve("npm:@11ty/pretend/real/real.webc"), "./node_modules/@11ty/pretend/real/real.webc");
16 | });
17 |
18 | test("Resolve component path in dependency with aliases", async t => {
19 | let m = new ModuleResolution();
20 | m.setTagName("my-tag");
21 | m.setAliases({
22 | "npm": "./test/fake_modules/"
23 | });
24 |
25 | t.is(m.resolve("npm:pretend"), "./test/fake_modules/pretend/my-tag.webc");
26 | t.is(m.resolve("npm:pretend/real.webc"), "./test/fake_modules/pretend/real.webc");
27 | t.is(m.resolve("npm:pretend/pretend"), "./test/fake_modules/pretend/pretend/my-tag.webc");
28 | t.is(m.resolve("npm:pretend/pretend/real.webc"), "./test/fake_modules/pretend/pretend/real.webc");
29 | t.is(m.resolve("npm:@11ty/pretend"), "./test/fake_modules/@11ty/pretend/my-tag.webc");
30 | t.is(m.resolve("npm:@11ty/pretend/real"), "./test/fake_modules/@11ty/pretend/real/my-tag.webc");
31 | t.is(m.resolve("npm:@11ty/pretend/real.webc"), "./test/fake_modules/@11ty/pretend/real.webc");
32 | t.is(m.resolve("npm:@11ty/pretend/pretend/real.webc"), "./test/fake_modules/@11ty/pretend/pretend/real.webc");
33 | });
34 |
35 | test("Resolve component path in dependency with aliases and a tagName", async t => {
36 | let m = new ModuleResolution();
37 | m.setTagName("syntax-highlight");
38 | m.setAliases({
39 | "npm": "./test/fake_modules/"
40 | });
41 |
42 | t.is(m.resolve("npm:pretend"), "./test/fake_modules/pretend/syntax-highlight.webc");
43 | t.is(m.resolve("npm:pretend/pretend"), "./test/fake_modules/pretend/pretend/syntax-highlight.webc");
44 | t.is(m.resolve("npm:pretend/pretend/real.webc"), "./test/fake_modules/pretend/pretend/real.webc");
45 | t.is(m.resolve("npm:@11ty/pretend"), "./test/fake_modules/@11ty/pretend/syntax-highlight.webc");
46 | t.is(m.resolve("npm:@11ty/pretend/real"), "./test/fake_modules/@11ty/pretend/real/syntax-highlight.webc");
47 | t.is(m.resolve("npm:@11ty/pretend/real/real.webc"), "./test/fake_modules/@11ty/pretend/real/real.webc");
48 | });
49 |
50 |
51 | test("Alias outside of the project throws error", async t => {
52 | let m = new ModuleResolution();
53 | m.setAliases({
54 | "npm": "../test/"
55 | });
56 |
57 | t.throws(() => {
58 | m.resolve("npm:pretend")
59 | }, {
60 | message: "Invalid import reference (must be in the project root), received: ../test/pretend"
61 | });
62 | });
63 |
64 | test("Import outside of the project throws error", async t => {
65 | let m = new ModuleResolution();
66 |
67 | t.throws(() => {
68 | m.resolve("../pretend.webc")
69 | }, {
70 | message: "Invalid import reference (must be in the project root), received: ../pretend.webc"
71 | });
72 | });
73 |
--------------------------------------------------------------------------------
/test/props-versus-text-test.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { WebC } from "../webc.js";
3 |
4 | test("Props versus @text", async t => {
5 | let component = new WebC();
6 |
7 | component.setInputPath("./test/stubs/props-versus-text/page.webc");
8 |
9 | let { html } = await component.compile({
10 | data: {
11 | pdf: "hello"
12 | }
13 | });
14 |
15 | t.is(html.trim(), `
hello `);
16 | });
17 |
--------------------------------------------------------------------------------
/test/proxyDataTest.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { ProxyData } from "../src/proxyData.cjs";
3 |
4 | test("Data is proxied", t => {
5 | let p = new ProxyData();
6 | p.addTarget({
7 | global1: 1,
8 | global2: 2,
9 | });
10 |
11 | let data = p.getData();
12 |
13 | t.is(data.global1, 1);
14 | t.is(data.global2, 2);
15 | });
16 |
17 | test("Data is cascaded", t => {
18 | let p = new ProxyData();
19 | p.addTarget({
20 | global1: 3,
21 | global2: 4,
22 | global3: 5,
23 | });
24 | // later additions override previous additions
25 | p.addTarget({
26 | global1: 1,
27 | global2: 2,
28 | });
29 |
30 | let data = p.getData();
31 |
32 | t.is(data.global1, 1);
33 | t.is(data.global2, 2);
34 | t.is(data.global3, 5);
35 | });
--------------------------------------------------------------------------------
/test/renderFunctionJsTest.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { WebC } from "../webc.js";
3 |
4 | test("Using webc:type=js", async t => {
5 | let component = new WebC();
6 |
7 | // identical to
8 | component.setContent(`
9 |
10 |
11 | `);
12 |
13 | let { html, css, js, components } = await component.compile({
14 | data: {
15 | myArray: [1,2,3,4]
16 | }
17 | });
18 |
19 | t.deepEqual(js, []);
20 | t.deepEqual(css, []);
21 | t.deepEqual(components, []);
22 |
23 | t.is(html, `
24 |
25 | 1/2/3/4
26 |
27 | `);
28 | });
29 |
30 | test("Using webc:type=js with require", async t => {
31 | let component = new WebC();
32 |
33 | // identical to
34 | component.setContent(`
35 |
36 |
37 |
41 |
42 | `);
43 |
44 | let { html, css, js, components } = await component.compile();
45 |
46 | t.deepEqual(js, []);
47 | t.deepEqual(css, []);
48 | t.deepEqual(components, []);
49 |
50 | t.is(html, `
51 |
52 |
53 | Imported
54 |
55 |
56 | `);
57 | });
58 |
59 | // Seems like this ignores webc:type and outputs the
66 | `);
67 |
68 | let { html, css, js, components } = await component.compile({
69 | data: {
70 | myArray: [1,2,3,4]
71 | }
72 | });
73 |
74 | t.deepEqual(js, []);
75 | t.deepEqual(css, []);
76 | t.deepEqual(components, []);
77 |
78 | t.is(html, `
79 |
80 | 1/2/3/4
81 |
82 | `);
83 | });
84 |
85 | test("Using webc:type=js and promises", async t => {
86 | let component = new WebC();
87 |
88 | component.setContent(`
89 |
90 |
91 |
98 |
99 | `);
100 |
101 | let { html, css, js, components } = await component.compile({
102 | data: {
103 | myArray: [1,2,3,4]
104 | }
105 | });
106 |
107 | t.deepEqual(js, []);
108 | t.deepEqual(css, []);
109 | t.deepEqual(components, []);
110 |
111 | t.is(html, `
112 |
113 |
114 | 1,2,3,4
115 |
116 |
117 | `);
118 | });
119 |
120 | test("Using webc:type=js and async function", async t => {
121 | let component = new WebC();
122 |
123 | component.setContent(`
124 |
125 |
126 |
137 |
138 | `);
139 |
140 | let { html, css, js, components } = await component.compile({
141 | data: {
142 | myArray: [1,2,3,4]
143 | }
144 | });
145 |
146 | t.deepEqual(js, []);
147 | t.deepEqual(css, []);
148 | t.deepEqual(components, []);
149 |
150 | t.is(html, `
151 |
152 |
153 | 1,2,3,4
154 |
155 |
156 | `);
157 | });
158 |
159 |
160 | test("Using webc:type=js and if true", async t => {
161 | let component = new WebC();
162 |
163 | component.setContent(`
164 |
165 |
166 |
173 |
174 | `);
175 |
176 | let { html, css, js, components } = await component.compile();
177 |
178 | t.deepEqual(js, []);
179 | t.deepEqual(css, []);
180 | t.deepEqual(components, []);
181 |
182 | t.is(html, `
183 |
184 |
185 | true
186 |
187 |
188 | `);
189 | });
190 |
191 | test("Using webc:type=js and if false", async t => {
192 | let component = new WebC();
193 |
194 | component.setContent(`
195 |
196 |
197 |
204 |
205 | `);
206 |
207 | let { html, css, js, components } = await component.compile();
208 |
209 | t.deepEqual(js, []);
210 | t.deepEqual(css, []);
211 | t.deepEqual(components, []);
212 |
213 | t.is(html, `
214 |
215 |
216 | false
217 |
218 |
219 | `);
220 | });
221 |
--------------------------------------------------------------------------------
/test/scoped-type-js-test.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { WebC } from "../webc.js";
3 |
4 | test("webc:scoped with webc:type=js", async t => {
5 | let component = new WebC();
6 | component.setBundlerMode(true);
7 | component.setContent(``);
10 |
11 | let { html, css } = await component.compile();
12 |
13 | t.is(html.trim(), "");
14 | t.deepEqual(css, [".wybdy2xfp div{color:red}"]);
15 | });
16 |
17 |
18 | test("webc:scoped webc:keep with webc:type=js", async t => {
19 | let component = new WebC();
20 | component.setBundlerMode(true);
21 | component.setContent(``);
24 |
25 | let { html, css } = await component.compile();
26 |
27 | t.is(html.trim(), ``);
28 | t.deepEqual(css, []);
29 | });
30 |
31 | test("webc:scoped webc:keep with webc:type=js with wrapper element", async t => {
32 | let component = new WebC();
33 | component.setBundlerMode(true);
34 | component.setContent(`
35 |
38 |
`);
39 |
40 | await t.throwsAsync(async () => component.compile(), {
41 | message: "Could not find any top level \`;
50 | `);
51 |
52 | let { html, css } = await component.compile();
53 |
54 | t.is(html.trim(), ``);
55 | t.deepEqual(css, ["div { color: red; }"]);
56 | });
57 |
58 | test("nested content, style webc:scoped from a webc:type=js", async t => {
59 | let component = new WebC();
60 | component.setBundlerMode(true);
61 | component.setContent(``);
64 |
65 | await t.throwsAsync(async () => component.compile(), {
66 | message: "Could not find any top level
35 | Hello
World !
36 |
37 | After`);
38 | });
39 |
40 | test("Using a web component with a declarative shadow root using shadowrootmode", async t => {
41 | let { html, css, js, components } = await testGetResultFor("./test/stubs/nested.webc", {
42 | "web-component": "./test/stubs/components/shadowrootmode.webc"
43 | }, {}, { globalData: "World" });
44 |
45 | t.deepEqual(js, []);
46 | t.deepEqual(css, []);
47 | t.deepEqual(components, [
48 | "./test/stubs/nested.webc",
49 | "./test/stubs/components/shadowrootmode.webc"
50 | ]);
51 | t.is(html, `Before
52 |
53 |
56 | Hello World !
57 |
58 | After`);
59 | });
--------------------------------------------------------------------------------
/test/stubs/alias-paragraph.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
This is a paragraph—we still cool?
3 | After
--------------------------------------------------------------------------------
/test/stubs/asset-buckets.webc:
--------------------------------------------------------------------------------
1 |
Hi
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/stubs/attribute-quotes.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/stubs/bucket-inherit-attrs/component.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/bucket-inherit-attrs/index.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/stubs/bucket-inherit/child.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/bucket-inherit/component.webc:
--------------------------------------------------------------------------------
1 |
Hi
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/stubs/bucket-inherit/index.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/bucket-noinherit/component.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/bucket-noinherit/index.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/class-mixins.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/comment.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/component-html-assets.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/component-html-resolve.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/component-in-page-mode.webc:
--------------------------------------------------------------------------------
1 |
Test
--------------------------------------------------------------------------------
/test/stubs/component-script-html.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components-list.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CHILD CONTENT
5 |
6 |
7 | AUNT CONTENT
8 |
9 |
10 |
--------------------------------------------------------------------------------
/test/stubs/components-order.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CHILD CONTENT
5 |
6 | SIBLING CONTENT
7 |
8 | AUNT CONTENT
9 |
--------------------------------------------------------------------------------
/test/stubs/components/assets.webc:
--------------------------------------------------------------------------------
1 | HTML
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/stubs/components/child-circular.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/child-circular2.webc:
--------------------------------------------------------------------------------
1 |
test
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-a.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-b.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-c.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-d.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-e.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-css-js-f.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/child-root-empty-class.webc:
--------------------------------------------------------------------------------
1 |
SSR content
--------------------------------------------------------------------------------
/test/stubs/components/child-root.webc:
--------------------------------------------------------------------------------
1 |
2 | SSR content
3 |
--------------------------------------------------------------------------------
/test/stubs/components/clientside.webc:
--------------------------------------------------------------------------------
1 | This is the web component content.
2 |
--------------------------------------------------------------------------------
/test/stubs/components/component-data.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/html-evaluating-props-nothis.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/components/html-evaluating-props.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/components/img-as-root.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/img-plain.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/img-props.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-empty.webc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/11ty/webc/a2f548c23490929aa8c9cd25159549eba3e869c7/test/stubs/components/nested-child-empty.webc
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-namedslot-style.webc:
--------------------------------------------------------------------------------
1 | SSR content
After slot content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-namedslot.webc:
--------------------------------------------------------------------------------
1 | SSR content
After slot content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-script.webc:
--------------------------------------------------------------------------------
1 | SSR content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-slot-before-after.webc:
--------------------------------------------------------------------------------
1 | Before
After
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-slot-style.webc:
--------------------------------------------------------------------------------
1 | SSR content
After slot content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-slot.webc:
--------------------------------------------------------------------------------
1 | SSR content
After slot content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-style-keep.webc:
--------------------------------------------------------------------------------
1 | SSR content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-style-only.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-style-script-both-empty.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/nested-child-style.webc:
--------------------------------------------------------------------------------
1 | SSR content
--------------------------------------------------------------------------------
/test/stubs/components/nested-child.webc:
--------------------------------------------------------------------------------
1 | SSR content
--------------------------------------------------------------------------------
/test/stubs/components/override-parent-scoped.webc:
--------------------------------------------------------------------------------
1 |
SSR content
2 |
--------------------------------------------------------------------------------
/test/stubs/components/override-parent.webc:
--------------------------------------------------------------------------------
1 |
SSR content
2 |
--------------------------------------------------------------------------------
/test/stubs/components/render-css-keep.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/render-css-root-override.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/render-css-root.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/render-css.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/render-slots-raw.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/render-slots.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/root-style.webc:
--------------------------------------------------------------------------------
1 |
2 | SSR content
3 |
--------------------------------------------------------------------------------
/test/stubs/components/scoped-override-collision-a.webc:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/test/stubs/components/scoped-override-collision-b.webc:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/test/stubs/components/scoped-override.webc:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/test/stubs/components/scoped-style.webc:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/test/stubs/components/script-html.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/shadowroot.webc:
--------------------------------------------------------------------------------
1 |
2 |
5 | Hello !
6 |
--------------------------------------------------------------------------------
/test/stubs/components/shadowrootmode.webc:
--------------------------------------------------------------------------------
1 |
2 |
5 | Hello !
6 |
--------------------------------------------------------------------------------
/test/stubs/components/text-link-slot.webc:
--------------------------------------------------------------------------------
1 |
Default link text
2 |
--------------------------------------------------------------------------------
/test/stubs/components/with-uid-root.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/components/with-uid.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/deep-root/component.webc:
--------------------------------------------------------------------------------
1 |
Some component content
--------------------------------------------------------------------------------
/test/stubs/defined-style-noroot.webc:
--------------------------------------------------------------------------------
1 |
9 | This will be green at first and then switch to red when JS has registered the component.
--------------------------------------------------------------------------------
/test/stubs/defined-style.webc:
--------------------------------------------------------------------------------
1 |
9 |
This will be green at first and then switch to red when JS has registered the component.
--------------------------------------------------------------------------------
/test/stubs/dynamic-attributes-host-component-data/lol.webc:
--------------------------------------------------------------------------------
1 |
Test
--------------------------------------------------------------------------------
/test/stubs/dynamic-attributes-host-component-data/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/dynamic-bucket/component.webc:
--------------------------------------------------------------------------------
1 |
Hi
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/dynamic-bucket/index.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/empty-class.webc:
--------------------------------------------------------------------------------
1 |
Light dom
--------------------------------------------------------------------------------
/test/stubs/empty.webc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/11ty/webc/a2f548c23490929aa8c9cd25159549eba3e869c7/test/stubs/empty.webc
--------------------------------------------------------------------------------
/test/stubs/externals/externals-dynamic.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/externals/externals-keep.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/externals/externals-scoped.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
--------------------------------------------------------------------------------
/test/stubs/externals/externals-urls-keep.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/externals/externals-urls.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/externals/externals.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/externals/my-script.js:
--------------------------------------------------------------------------------
1 | /* This is the external script */
--------------------------------------------------------------------------------
/test/stubs/externals/my-style-scoped.css:
--------------------------------------------------------------------------------
1 | :host { color: red; }
--------------------------------------------------------------------------------
/test/stubs/externals/my-style.css:
--------------------------------------------------------------------------------
1 | /* This is some CSS */
--------------------------------------------------------------------------------
/test/stubs/fake_node_modules/@11ty/test/syntax-highlighter.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/global-components/my-custom-element.webc:
--------------------------------------------------------------------------------
1 | This is a global component.
--------------------------------------------------------------------------------
/test/stubs/global-components/other-custom-element.webc:
--------------------------------------------------------------------------------
1 |
This is another global component.
2 |
5 |
--------------------------------------------------------------------------------
/test/stubs/global-components/subfolder/my-custom-element.webc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/11ty/webc/a2f548c23490929aa8c9cd25159549eba3e869c7/test/stubs/global-components/subfolder/my-custom-element.webc
--------------------------------------------------------------------------------
/test/stubs/global-data.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/head/custom-head.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/stubs/head/head-is-component.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
This is a title
6 |
--------------------------------------------------------------------------------
/test/stubs/head/head.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
This is a title
5 |
--------------------------------------------------------------------------------
/test/stubs/head/meta.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/stubs/html-number.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/html.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/test/stubs/if-component-style.webc:
--------------------------------------------------------------------------------
1 | Test
--------------------------------------------------------------------------------
/test/stubs/img-to-img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/import-alias-suffix.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
This is a paragraph—we still cool?
3 | After
--------------------------------------------------------------------------------
/test/stubs/import-alias.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
This is a paragraph—we still cool?
3 | After
--------------------------------------------------------------------------------
/test/stubs/import-keep.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/import-twice.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
Light dom content
3 |
Light dom content
4 | After
--------------------------------------------------------------------------------
/test/stubs/issue-104/attrs-component.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/attrs-object.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/root-attrs-component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/root-component.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/root-override-attrs-component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-104/setup-component.webc:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/stubs/issue-105/test-p.webc:
--------------------------------------------------------------------------------
1 |
I am an HTML-only component
--------------------------------------------------------------------------------
/test/stubs/issue-105/test.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { WebC } from "../../../webc.js";
3 |
4 | test("Template content issue #105", async t => {
5 | let component = new WebC();
6 |
7 | component.defineComponents("./test/stubs/issue-105/test-p.webc");
8 |
9 | component.setContent(`
`);
10 |
11 | let { html } = await component.compile();
12 |
13 | t.is(html.trim(), `
I am an HTML-only component
`);
14 | });
--------------------------------------------------------------------------------
/test/stubs/issue-115/page.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
Test
9 |
10 |
11 |
Hi, this is a test
12 |
13 |
14 |
--------------------------------------------------------------------------------
/test/stubs/issue-118/oh-no.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-118/page.webc:
--------------------------------------------------------------------------------
1 |
Testing.
--------------------------------------------------------------------------------
/test/stubs/issue-135/component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-135/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-138/img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-138/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-152/child.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-152/parent-nohtml.webc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/11ty/webc/a2f548c23490929aa8c9cd25159549eba3e869c7/test/stubs/issue-152/parent-nohtml.webc
--------------------------------------------------------------------------------
/test/stubs/issue-152/parent.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-154/c-blue.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/issue-154/c-red.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/issue-154/page.webc:
--------------------------------------------------------------------------------
1 |
Hi I am red
2 |
Hi I am blue
3 |
4 |
5 | I am red.
6 | Hi I am blue
7 | still red
8 |
9 |
10 |
11 | I am blue.
12 | Hi I am red
13 | still blue
14 |
--------------------------------------------------------------------------------
/test/stubs/issue-3/my-article.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Shadow dom slot
7 |
8 |
--------------------------------------------------------------------------------
/test/stubs/issue-3/page.webc:
--------------------------------------------------------------------------------
1 |
2 | Article Title
3 | Subtitle
4 | Content
5 |
--------------------------------------------------------------------------------
/test/stubs/issue-67/meta-social.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-67/page.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
My First Heading
8 |
My first paragraph.
9 |
10 |
--------------------------------------------------------------------------------
/test/stubs/issue-78/a-component.webc:
--------------------------------------------------------------------------------
1 | woah i am component. i do things.
--------------------------------------------------------------------------------
/test/stubs/issue-78/add-banner-to-css-render.webc:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/test/stubs/issue-78/add-banner-to-css-root.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/test/stubs/issue-78/add-banner-to-css.webc:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/test/stubs/issue-78/img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-78/page.webc:
--------------------------------------------------------------------------------
1 |
normal component
2 |
3 |
4 |
js
5 |
8 |
9 |
js with component
10 |
--------------------------------------------------------------------------------
/test/stubs/issue-79/components/my-component.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/issue-79/components/other-component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-79/pages/articles/my-page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-80-b/b.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/issue-80-b/c.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-80-b/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-80/b.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/issue-80/c.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-80/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-85/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-91/img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-91/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-94/component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-98/component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/issue-98/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/array-object-keys.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/array-object-values.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/array-value.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/array.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/complex/data.js:
--------------------------------------------------------------------------------
1 | export const contacts = [
2 | {
3 | "name":"Joey",
4 | "color":"blue",
5 | "numbers":[1,2,3]
6 | },
7 | {
8 | "name":"Phoebe",
9 | "color":"pink",
10 | "numbers":[1,2,3]
11 | },
12 | {
13 | "name":"Chandler",
14 | "color":"orange",
15 | "numbers":[1,2,3]
16 | },
17 | {
18 | "name":"Rachel",
19 | "color":"violet",
20 | "numbers":[1,2,3]
21 | },
22 | {
23 | "name":"Monica",
24 | "color":"green",
25 | "numbers":[1,2,3]
26 | },
27 | {
28 | "name":"Ross",
29 | "color":"red",
30 | "numbers":[1,2,3]
31 | }
32 | ]
--------------------------------------------------------------------------------
/test/stubs/looping/complex/entry-point.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/stubs/looping/components/card-actions.webc:
--------------------------------------------------------------------------------
1 |
Say hello
--------------------------------------------------------------------------------
/test/stubs/looping/components/card-content.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/looping/components/card-header.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/components/card-thing.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/test/stubs/looping/components/component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/issue-139.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/looping/object-key.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/object.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/scoped-data.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/looping/script-setup-data.webc:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/test/stubs/nested-alias-reference.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-alias.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-content-with-attr.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
Child content
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-content.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
Child content
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-link.webc:
--------------------------------------------------------------------------------
1 |
Parent Child
--------------------------------------------------------------------------------
/test/stubs/nested-multiple-slots-raw.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | Before slot content!
4 |
5 |
6 |
7 |
Slot 2 content
8 |
9 | After slot content!
10 |
11 | After
--------------------------------------------------------------------------------
/test/stubs/nested-multiple-slots.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | Before slot content!
4 |
5 |
6 |
7 |
Slot 2 content
8 |
9 | After slot content!
10 |
11 | After
--------------------------------------------------------------------------------
/test/stubs/nested-no-shadowdom.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | Child content
4 |
5 |
6 | After
--------------------------------------------------------------------------------
/test/stubs/nested-reference.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-twice.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | Child content
4 |
5 |
6 | After
--------------------------------------------------------------------------------
/test/stubs/nested-webc-keep.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested-webc-raw.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/nested.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/no-template.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/page-capital-doctype-issue-24.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/stubs/page.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/test/stubs/plaintext-transform.webc:
--------------------------------------------------------------------------------
1 |
Testing
--------------------------------------------------------------------------------
/test/stubs/props-missing-nothis.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/props-missing.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/props-no-this.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/stubs/props-versus-text/page.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/props.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/render-async.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render-async2.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render-child-component.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/render-raw-nokeep.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render-raw.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render-require.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/render-slots-parent.webc:
--------------------------------------------------------------------------------
1 |
2 |
This is content that I want to be raw in JS
--------------------------------------------------------------------------------
/test/stubs/render.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render2.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/render3.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
--------------------------------------------------------------------------------
/test/stubs/sample-require.cjs:
--------------------------------------------------------------------------------
1 | module.exports = "Imported";
--------------------------------------------------------------------------------
/test/stubs/scoped-override-collisions.webc:
--------------------------------------------------------------------------------
1 |
Light dom content
2 |
Light dom content
--------------------------------------------------------------------------------
/test/stubs/scoped-override.webc:
--------------------------------------------------------------------------------
1 |
Light dom content
--------------------------------------------------------------------------------
/test/stubs/scoped-top.webc:
--------------------------------------------------------------------------------
1 |
13 |
Testing testing
--------------------------------------------------------------------------------
/test/stubs/scoped.webc:
--------------------------------------------------------------------------------
1 |
Light dom content
--------------------------------------------------------------------------------
/test/stubs/script-type.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/setup-script/component.webc:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/test/stubs/setup-script/test.js:
--------------------------------------------------------------------------------
1 | import test from "ava";
2 | import { WebC } from "../../../webc.js";
3 |
4 | test("webc:setup #87", async t => {
5 | let component = new WebC();
6 |
7 | component.setContent(`
8 |
15 |
`);
16 |
17 | let { html } = await component.compile();
18 |
19 | t.is(html.trim(), `
1
20 |
21 |
blue
`);
22 | });
23 |
24 | test("webc:setup with a helper #87", async t => {
25 | let component = new WebC();
26 |
27 | component.setHelper("alwaysYellow", () => "yellow");
28 |
29 | component.setContent(`
34 |
`);
35 |
36 | let { html } = await component.compile();
37 |
38 | t.is(html.trim(), `
yellow
`);
39 | });
40 |
41 | test("webc:setup with global data #87", async t => {
42 | let component = new WebC();
43 |
44 | component.setHelper("alwaysYellow", () => "yellow");
45 |
46 | component.setContent(`
51 |
`);
52 |
53 | let { html } = await component.compile({
54 | data: {
55 | globalDataValue: "hello"
56 | }
57 | });
58 |
59 | t.is(html.trim(), `
hello
`);
60 | });
61 |
62 |
63 | test("webc:setup with child component #87", async t => {
64 | let component = new WebC();
65 | component.setHelper("globalFunction", (a) => a);
66 |
67 | component.defineComponents("./test/stubs/setup-script/component.webc");
68 |
69 | component.setContent(`
70 |
77 |
78 |
`);
79 |
80 | let { html } = await component.compile();
81 |
82 | t.is(html.trim(), `
1
83 |
84 |
2
85 |
86 |
red
87 |
blue
`);
88 | });
--------------------------------------------------------------------------------
/test/stubs/slot-fallback-content.webc:
--------------------------------------------------------------------------------
1 |
Fallback content
--------------------------------------------------------------------------------
/test/stubs/slot-keep.webc:
--------------------------------------------------------------------------------
1 |
Fallback content
--------------------------------------------------------------------------------
/test/stubs/slot-named-fallback.webc:
--------------------------------------------------------------------------------
1 |
Fallback content
--------------------------------------------------------------------------------
/test/stubs/slot-named.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/slot-nested-2.webc:
--------------------------------------------------------------------------------
1 |
TextText
--------------------------------------------------------------------------------
/test/stubs/slot-nested-3.webc:
--------------------------------------------------------------------------------
1 |
TextText
--------------------------------------------------------------------------------
/test/stubs/slot-nested.webc:
--------------------------------------------------------------------------------
1 |
TextText
--------------------------------------------------------------------------------
/test/stubs/slot-raw.webc:
--------------------------------------------------------------------------------
1 |
Fallback content
--------------------------------------------------------------------------------
/test/stubs/slot-unused-2.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/slot-unused-default.webc:
--------------------------------------------------------------------------------
1 |
Text
--------------------------------------------------------------------------------
/test/stubs/slot-unused.webc:
--------------------------------------------------------------------------------
1 |
Text
--------------------------------------------------------------------------------
/test/stubs/slot.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/style-merge.webc:
--------------------------------------------------------------------------------
1 | Before
2 |
3 | After
--------------------------------------------------------------------------------
/test/stubs/style-override.webc:
--------------------------------------------------------------------------------
1 |
13 |
Testing testing
--------------------------------------------------------------------------------
/test/stubs/style.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/template-custom-keep.webc:
--------------------------------------------------------------------------------
1 |
2 | # Header
3 |
--------------------------------------------------------------------------------
/test/stubs/template-custom-nested.webc:
--------------------------------------------------------------------------------
1 |
2 | # Header
3 |
4 | # Header Test
5 |
--------------------------------------------------------------------------------
/test/stubs/template-custom-notype.webc:
--------------------------------------------------------------------------------
1 |
2 | No content
.
3 |
--------------------------------------------------------------------------------
/test/stubs/template-custom.webc:
--------------------------------------------------------------------------------
1 |
2 | # Header
3 |
--------------------------------------------------------------------------------
/test/stubs/template.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/two-style.webc:
--------------------------------------------------------------------------------
1 |
Light dom content
2 |
Light dom content
--------------------------------------------------------------------------------
/test/stubs/using-css-keep.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-css-root-override.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-css-root.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-css.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-img-plain.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-img.webc:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stubs/using-uid.webc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/test/stubs/webc-raw-html-prop.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/stubs/webc-raw-prop.webc:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/webc.js:
--------------------------------------------------------------------------------
1 | import fs from "fs";
2 | import fastglob from "fast-glob";
3 | import isGlob from "is-glob";
4 | import path from "path";
5 |
6 | import { Path } from "./src/path.js";
7 | import { AstSerializer } from "./src/ast.js";
8 | import { ModuleScript } from "./src/moduleScript.cjs";
9 | import { AstCache } from "./src/astCache.js";
10 | import { ModuleResolution } from "./src/moduleResolution.js";
11 | import { ComponentManager } from "./src/componentManager.js";
12 |
13 | const localAstCache = new AstCache();
14 |
15 | class WebC {
16 | constructor(options = {}) {
17 | let { file, input } = options;
18 |
19 | this.customTransforms = {};
20 | this.customHelpers = {};
21 | this.customScopedHelpers = {};
22 | this.globalComponents = {};
23 | this.astOptions = {};
24 | this.bundlerMode = false;
25 | this.ignores = options.ignores || [];
26 |
27 | if(input || input === "") {
28 | this.rawInput = input;
29 | }
30 | if(file) {
31 | this.setInputPath(file);
32 | }
33 | }
34 |
35 | setInputPath(file) {
36 | file = Path.normalizePath(file);
37 | this.filePath = file;
38 | this.astOptions.filePath = file;
39 | }
40 |
41 | setContent(input, filePath) {
42 | this.rawInput = input;
43 |
44 | if(filePath) {
45 | this.astOptions.filePath = filePath;
46 | }
47 | }
48 |
49 | setGlobalComponentManager(manager) {
50 | this.globalComponentManager = manager;
51 | }
52 |
53 | getRenderingMode(content) {
54 | if(!content.startsWith(")
82 | if(mode === "component" || !content.startsWith("${content}`;
84 | }
85 |
86 | return {
87 | content,
88 | mode,
89 | };
90 | }
91 |
92 | static async getASTFromString(string) {
93 | let wc = new WebC({
94 | input: string
95 | });
96 | let { content } = wc.getContent();
97 | return wc.getAST(content);
98 | }
99 |
100 | // @deprecated for getFromFilePath
101 | static async getASTFromFilePath(filePath) {
102 | let wc = new WebC({
103 | file: filePath
104 | });
105 | let { content } = wc.getContent();
106 | return wc.getAST(content);
107 | }
108 |
109 | static async getFromFilePath(filePath) {
110 | let wc = new WebC({
111 | file: filePath
112 | });
113 | let { content, mode } = wc.getContent();
114 |
115 | return {
116 | content,
117 | ast: await wc.getAST(content),
118 | mode,
119 | };
120 | }
121 |
122 | getAST(content) {
123 | if(!content) {
124 | throw new Error("WebC.getAST() expects a content argument.");
125 | }
126 |
127 | return localAstCache.get(content);
128 | }
129 |
130 | setTransform(key, callback) {
131 | this.customTransforms[key] = callback;
132 | }
133 |
134 | setHelper(key, callback, isScoped = false) {
135 | if(isScoped) {
136 | this.customScopedHelpers[key] = callback;
137 | } else {
138 | this.customHelpers[key] = callback;
139 | }
140 | }
141 |
142 | setAlias(key, folder) {
143 | if(!this.aliases) {
144 | this.aliases = {};
145 | }
146 |
147 | this.aliases[key] = folder;
148 | }
149 |
150 | async _defineComponentsObject(obj = {}) {
151 | for(let name in obj) {
152 | let file = obj[name];
153 | if(this.globalComponents[name]) {
154 | throw new Error(`Global component name collision on "${name}" between: ${this.globalComponents[name]} and ${file}`)
155 | }
156 | this.globalComponents[name] = file;
157 | }
158 | }
159 |
160 | static findGlob(glob, ignores = []) {
161 | return fastglob.sync(glob, {
162 | ignore: ignores,
163 | caseSensitiveMatch: false,
164 | dot: false,
165 | });
166 | }
167 |
168 | static getComponentsMap(globOrObject, ignores) {
169 | let rawFiles = globOrObject;
170 |
171 | // Passing in a single string is assumed to be a glob
172 | if(typeof rawFiles === "string") {
173 | rawFiles = WebC.findGlob(globOrObject, ignores);
174 | }
175 |
176 | if(Array.isArray(rawFiles)) {
177 | let moduleResolver = new ModuleResolution();
178 | let resolvedFiles = new Set();
179 | for(let file of rawFiles) {
180 | // Resolve `npm:` aliases
181 | let hasValidAlias = moduleResolver.hasValidAlias(file);
182 | if(hasValidAlias) {
183 | file = moduleResolver.resolveAliases(file);
184 | }
185 |
186 | // Multiple glob searches
187 | if(isGlob(file)) {
188 | let globResults = WebC.findGlob(file, ignores);
189 | for(let globFile of globResults) {
190 | resolvedFiles.add(globFile);
191 | }
192 | } else {
193 | resolvedFiles.add(file);
194 | }
195 | }
196 |
197 | let obj = {};
198 | for(let file of resolvedFiles) {
199 | let {name} = path.parse(file);
200 | if(obj[name]) {
201 | throw new Error(`Global component name collision on "${name}" between: ${obj[name]} and ${file}`)
202 | }
203 | obj[name] = file;
204 | }
205 |
206 | return obj;
207 | }
208 |
209 | return globOrObject;
210 | }
211 |
212 | defineComponents(globOrObject) {
213 | this._defineComponentsObject(WebC.getComponentsMap(globOrObject, this.ignores));
214 | }
215 |
216 | setUidFunction(fn) {
217 | this.uidFn = fn;
218 | }
219 |
220 | async setup(options = {}) {
221 | let { content, mode } = this.getContent();
222 | let rawAst = this.getAST(content);
223 |
224 | let ast = new AstSerializer(this.astOptions);
225 | ast.setComponentManager(this.globalComponentManager);
226 | ast.setBundlerMode(this.bundlerMode);
227 | ast.setMode(mode);
228 | ast.setContent(content);
229 | ast.setData(options.data);
230 |
231 | if(this.aliases && Object.keys(this.aliases).length) {
232 | ast.setAliases(this.aliases);
233 | }
234 |
235 | if(this.uidFn) {
236 | ast.setUidFunction(this.uidFn);
237 | }
238 |
239 | for(let name in this.customTransforms) {
240 | ast.setTransform(name, this.customTransforms[name]);
241 | }
242 |
243 | for(let name in this.customHelpers) {
244 | ast.setHelper(name, this.customHelpers[name], false);
245 | }
246 | for(let name in this.customScopedHelpers) {
247 | ast.setHelper(name, this.customScopedHelpers[name], true);
248 | }
249 |
250 | await ast.setComponentsByFilePath(this.globalComponents);
251 | await ast.setComponentsByFilePath(options.components);
252 |
253 | return {
254 | ast: rawAst,
255 | serializer: ast,
256 | };
257 | }
258 |
259 | getComponents(setup) {
260 | let { ast, serializer } = setup;
261 | let obj = serializer.getComponentList(ast);
262 | return Object.keys(obj);
263 | }
264 |
265 | setBundlerMode(mode) {
266 | this.bundlerMode = !!mode;
267 | }
268 |
269 | async stream(options = {}) {
270 | let { ast, serializer } = await this.setup(options);
271 |
272 | serializer.streams.start();
273 |
274 | serializer.compile(ast, options.slots).catch(() => {
275 | // Node requires this to avoid unhandled rejection errors (yes, even with `finally`)
276 | serializer.streams.end();
277 | }).finally(() => {
278 | serializer.streams.end();
279 | });
280 |
281 | return serializer.streams.get();
282 | }
283 |
284 | async compile(options = {}) {
285 | let { ast, serializer } = await this.setup(options);
286 |
287 | return serializer.compile(ast, options.slots);
288 | }
289 | }
290 |
291 | export { WebC, ModuleScript, ComponentManager };
--------------------------------------------------------------------------------