@astrojs/compiler 0.2.16-rc.1 → 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 +7 -0
- package/astro.wasm +0 -0
- package/deno/README.md +5 -0
- package/package.json +1 -1
- package/test/basic.test.mjs +73 -0
- package/test/output.test.mjs +29 -0
- package/test/test.mjs +2 -0
- package/test/visible.test.mjs +37 -0
- package/tsconfig.json +14 -0
package/CHANGELOG.md
CHANGED
package/astro.wasm
CHANGED
|
Binary file
|
package/deno/README.md
ADDED
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { transform } from '@astrojs/compiler';
|
|
4
|
+
import sass from 'sass';
|
|
5
|
+
|
|
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
|
+
}
|
|
18
|
+
|
|
19
|
+
async function run() {
|
|
20
|
+
const result = await transform(
|
|
21
|
+
`---
|
|
22
|
+
let value = 'world';
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<style lang="scss" define:vars={{ a: 0 }}>
|
|
26
|
+
$color: red;
|
|
27
|
+
|
|
28
|
+
div {
|
|
29
|
+
color: $color;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
|
|
33
|
+
<div>Hello world!</div>
|
|
34
|
+
|
|
35
|
+
<div>Ahhh</div>
|
|
36
|
+
|
|
37
|
+
<style lang="scss">
|
|
38
|
+
$color: green;
|
|
39
|
+
div {
|
|
40
|
+
color: $color;
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
43
|
+
`,
|
|
44
|
+
{
|
|
45
|
+
sourcemap: true,
|
|
46
|
+
// HOLY CRAP THIS ACTUALLY WORKS!
|
|
47
|
+
preprocessStyle: async (value, attrs) => {
|
|
48
|
+
if (!attrs.lang) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (attrs.lang === 'scss') {
|
|
52
|
+
try {
|
|
53
|
+
return transformSass(value);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error(err);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// test
|
|
64
|
+
if (!result.code.includes('color:red')) {
|
|
65
|
+
throw new Error(`Styles didn’t transform as expected. Expected "color:red" to be present.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!result.code.includes('color:green')) {
|
|
69
|
+
throw new Error(`Styles didn’t transform as expected. Expected "color:green" to be present.`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await run();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { transform } from '@astrojs/compiler';
|
|
3
|
+
|
|
4
|
+
async function run() {
|
|
5
|
+
const result = await transform(
|
|
6
|
+
`<div xmlns:happy="https://example.com/schemas/happy">
|
|
7
|
+
<img src="jolly.avif" happy:smile="sweet"/>
|
|
8
|
+
</div>
|
|
9
|
+
`,
|
|
10
|
+
{
|
|
11
|
+
site: undefined,
|
|
12
|
+
sourcefile: '/Users/matthew/dev/astro/packages/astro/test/fixtures/astro-attrs/src/pages/namespaced.astro',
|
|
13
|
+
sourcemap: 'both',
|
|
14
|
+
internalURL: 'astro/internal',
|
|
15
|
+
preprocessStyle: async (value, attrs) => {
|
|
16
|
+
return null;
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (result.code[0] === '\x00') {
|
|
22
|
+
throw new Error('Corrupt output');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await run().catch((err) => {
|
|
27
|
+
console.error(err);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
package/test/test.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { transform } from '@astrojs/compiler';
|
|
4
|
+
|
|
5
|
+
async function run() {
|
|
6
|
+
const result = await transform(
|
|
7
|
+
`---
|
|
8
|
+
import ThemeToggleButton from './ThemeToggleButton.tsx';
|
|
9
|
+
---
|
|
10
|
+
<style>
|
|
11
|
+
body {
|
|
12
|
+
background: blue;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
<div>
|
|
16
|
+
<ThemeToggleButton client:visible />
|
|
17
|
+
</div>`,
|
|
18
|
+
{
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
as: 'fragment',
|
|
21
|
+
site: undefined,
|
|
22
|
+
sourcefile: 'MoreMenu.astro',
|
|
23
|
+
sourcemap: 'both',
|
|
24
|
+
internalURL: 'astro/internal',
|
|
25
|
+
preprocessStyle: async (value, attrs) => {
|
|
26
|
+
return null;
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// test
|
|
32
|
+
if (!result.code.includes(`{ modules: [{ module: $$module1, specifier: './ThemeToggleButton.tsx' }], hydratedComponents: [ThemeToggleButton], hoisted: [] }`)) {
|
|
33
|
+
throw new Error('Hydrated components not included');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await run();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noUnusedLocals": true,
|
|
10
|
+
"esModuleInterop": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["browser", "node", "shared"],
|
|
13
|
+
"exclude": ["node_modules"]
|
|
14
|
+
}
|