@astrojs/compiler 0.2.14 → 0.2.16

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @astrojs/compiler
2
2
 
3
+ ## 0.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 9ad8da7: Allows a data-astro-raw attr to parse children as raw text
8
+ - 61b77de: Bugfix: CSS and selector scoping
9
+
10
+ ## 0.2.15
11
+
12
+ ### Patch Changes
13
+
14
+ - 8fbae5e: Bugfix: fix component detection bug in parser
15
+ - 37b5b6e: Bugfix: wait to release processStyle() until after fn call
16
+
3
17
  ## 0.2.14
4
18
 
5
19
  ### Patch Changes
package/astro.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astrojs/compiler",
3
3
  "type": "module",
4
- "version": "0.2.14",
4
+ "version": "0.2.16",
5
5
  "scripts": {
6
6
  "build": "tsc -p ."
7
7
  },
@@ -1,20 +1,32 @@
1
1
  /* eslint-disable no-console */
2
2
 
3
3
  import { transform } from '@astrojs/compiler';
4
+ import sass from 'sass';
4
5
 
5
- const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
6
+ function transformSass(value) {
7
+ return new Promise((resolve, reject) => {
8
+ sass.render({ data: value }, (err, result) => {
9
+ if (err) {
10
+ reject(err);
11
+ return;
12
+ }
13
+ resolve({ code: result.css.toString('utf8'), map: result.map });
14
+ return;
15
+ });
16
+ });
17
+ }
6
18
 
7
19
  async function run() {
8
-
9
- let i = 0;
10
20
  const result = await transform(
11
21
  `---
12
22
  let value = 'world';
13
23
  ---
14
24
 
15
25
  <style lang="scss" define:vars={{ a: 0 }}>
26
+ $color: red;
27
+
16
28
  div {
17
- color: red;
29
+ color: $color;
18
30
  }
19
31
  </style>
20
32
 
@@ -23,8 +35,9 @@ div {
23
35
  <div>Ahhh</div>
24
36
 
25
37
  <style lang="scss">
38
+ $color: green;
26
39
  div {
27
- color: green;
40
+ color: $color;
28
41
  }
29
42
  </style>
30
43
  `,
@@ -32,34 +45,29 @@ div {
32
45
  sourcemap: true,
33
46
  // HOLY CRAP THIS ACTUALLY WORKS!
34
47
  preprocessStyle: async (value, attrs) => {
35
- let x = i++;
36
48
  if (!attrs.lang) {
37
49
  return null;
38
50
  }
39
- // console.log(`Starting to preprocess style ${x} as ${attrs.lang}`);
40
- // await sleep(3000);
41
- // console.log(`Finished preprocessing ${x}`);
42
- return { code: value.replace('color', 'background') };
51
+ if (attrs.lang === 'scss') {
52
+ try {
53
+ return transformSass(value);
54
+ } catch (err) {
55
+ console.error(err);
56
+ }
57
+ }
58
+ return null;
43
59
  },
44
60
  }
45
61
  );
46
- // console.log(result);
47
62
 
48
63
  // test
49
- if (!result.code.includes('background:red')) {
50
- throw new Error(`Styles didn’t transform as expected. Expected "background:red" to be present.`);
64
+ if (!result.code.includes('color:red')) {
65
+ throw new Error(`Styles didn’t transform as expected. Expected "color:red" to be present.`);
51
66
  }
52
67
 
53
- if (!result.code.includes('background:green')) {
54
- throw new Error(`Styles didn’t transform as expected. Expected "background:green" to be present.`);
68
+ if (!result.code.includes('color:green')) {
69
+ throw new Error(`Styles didn’t transform as expected. Expected "color:green" to be present.`);
55
70
  }
56
-
57
- // const start = performance.now()
58
- // const html = await compile(template);
59
- // const end = performance.now()
60
-
61
- // console.log('Compiled in ' + (start - end).toFixed(1) + 'ms');
62
- // console.log(html);
63
71
  }
64
72
 
65
73
  await run();
@@ -1,10 +1,7 @@
1
1
  /* eslint-disable no-console */
2
2
  import { transform } from '@astrojs/compiler';
3
3
 
4
- const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
5
-
6
4
  async function run() {
7
- let i = 0;
8
5
  const result = await transform(
9
6
  `<div xmlns:happy="https://example.com/schemas/happy">
10
7
  <img src="jolly.avif" happy:smile="sweet"/>
@@ -21,9 +18,12 @@ async function run() {
21
18
  }
22
19
  );
23
20
 
24
- if(result.code[0] === '\x00') {
21
+ if (result.code[0] === '\x00') {
25
22
  throw new Error('Corrupt output');
26
23
  }
27
24
  }
28
25
 
29
- await run().catch(err => { console.error(err); process.exit(1); });
26
+ await run().catch((err) => {
27
+ console.error(err);
28
+ process.exit(1);
29
+ });
package/test/test.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  import './basic.test.mjs';
2
- import './output.test.mjs';
2
+ import './output.test.mjs';
@@ -2,11 +2,7 @@
2
2
 
3
3
  import { transform } from '@astrojs/compiler';
4
4
 
5
- const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
6
-
7
5
  async function run() {
8
-
9
- let i = 0;
10
6
  const result = await transform(
11
7
  `---
12
8
  import ThemeToggleButton from './ThemeToggleButton.tsx';
@@ -33,7 +29,7 @@ async function run() {
33
29
  );
34
30
 
35
31
  // test
36
- if(!result.code.includes(`{ modules: [{ module: $$module1, specifier: './ThemeToggleButton.tsx' }], hydratedComponents: [ThemeToggleButton], hoisted: [] }`)) {
32
+ if (!result.code.includes(`{ modules: [{ module: $$module1, specifier: './ThemeToggleButton.tsx' }], hydratedComponents: [ThemeToggleButton], hoisted: [] }`)) {
37
33
  throw new Error('Hydrated components not included');
38
34
  }
39
35
  }