Skip to content

Commit

Permalink
fix: treat offset as bytes (withastro#324)
Browse files Browse the repository at this point in the history
* fix: treat offset as bytes

* chore: changeset

---------

Co-authored-by: Princesseuh <[email protected]>
  • Loading branch information
lsdsjy and Princesseuh authored Feb 6, 2023
1 parent 8345010 commit e5cf99d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-apricots-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prettier-plugin-astro': patch
---

Fix style tags using Stylus being truncated under certain circumstances
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.ts',
plugins: [commonjs(), typescript()],
external: ['prettier', 'prettier/doc', 'synckit', 'sass-formatter', 'node:module'],
external: ['prettier', 'prettier/doc', 'synckit', 'sass-formatter', 'node:module', 'node:buffer'],
output: {
dir: 'dist',
format: 'cjs',
Expand Down
5 changes: 4 additions & 1 deletion src/printer/embed.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'node:buffer';
import { BuiltInParsers, Doc, ParserOptions } from 'prettier';
import _doc from 'prettier/doc';
import { SassFormatter, SassFormatterConfig } from 'sass-formatter';
Expand Down Expand Up @@ -336,7 +337,9 @@ function embedStyle(
const node = path.getNode();

if (node) {
return options.originalText.slice(options.locStart(node), options.locEnd(node));
return Buffer.from(options.originalText)
.subarray(options.locStart(node), options.locEnd(node))
.toString();
}

return null;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/styles/with-unknown/input.astro
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<b>❤️</b>

<style lang="wacky-new-css">
%var: width: 10px;
%var: height: @width + 10px;
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/styles/with-unknown/output.astro
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<b>❤️</b>

<style lang="wacky-new-css">
%var: width: 10px;
%var: height: @width + 10px;
Expand Down

0 comments on commit e5cf99d

Please sign in to comment.