-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: component only edge case * test: update tests to hopefully catch more edge cases * chore: fix lint
- Loading branch information
1 parent
a1bdbf7
commit eb0d17f
Showing
6 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/compiler': patch | ||
--- | ||
|
||
Fix edge case with files that contain a single component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { transform } from '@astrojs/compiler'; | ||
import sass from 'sass'; | ||
|
||
function transformSass(value) { | ||
return new Promise((resolve, reject) => { | ||
sass.render({ data: value }, (err, result) => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve({ code: result.css.toString('utf8'), map: result.map }); | ||
return; | ||
}); | ||
}); | ||
} | ||
|
||
async function run() { | ||
const result = await transform( | ||
`--- | ||
import { Markdown } from 'astro/components'; | ||
import Layout from '../layouts/content.astro'; | ||
--- | ||
<style> | ||
#root { | ||
color: green; | ||
} | ||
</style> | ||
<Layout> | ||
<div id="root"> | ||
<Markdown> | ||
## Interesting Topic | ||
</Markdown> | ||
</div> | ||
</Layout>`, // NOTE: the lack of trailing space is important to this test! | ||
{ | ||
sourcemap: true, | ||
preprocessStyle: async (value, attrs) => { | ||
if (attrs.lang === 'scss') { | ||
try { | ||
return transformSass(value); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
return null; | ||
}, | ||
as: 'document', | ||
} | ||
); | ||
|
||
console.log(result.code); | ||
|
||
if (result.code.includes('html')) { | ||
throw new Error('Result did not remove <html>'); | ||
} | ||
} | ||
|
||
await run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './basic.test.mjs'; | ||
import './component-only.test.mjs'; | ||
import './empty-style.test.mjs'; | ||
import './output.test.mjs'; |