-
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: handle empty preprocessed style (#166)
- Loading branch information
1 parent
44ee189
commit 9557113
Showing
4 changed files
with
59 additions
and
0 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 panic when preprocessed style is empty |
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,50 @@ | ||
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( | ||
`--- | ||
let value = 'world'; | ||
--- | ||
<style lang="scss"></style> | ||
<div>Hello world!</div> | ||
<div>Ahhh</div> | ||
`, | ||
{ | ||
sourcemap: true, | ||
preprocessStyle: async (value, attrs) => { | ||
if (!attrs.lang) { | ||
return null; | ||
} | ||
if (attrs.lang === 'scss') { | ||
try { | ||
return transformSass(value); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
return null; | ||
}, | ||
} | ||
); | ||
|
||
console.log(result); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import './basic.test.mjs'; | ||
import './empty-style.test.mjs'; | ||
import './output.test.mjs'; |