summaryrefslogtreecommitdiff
path: root/packages/astro-parser/src/utils/get_code_frame.ts
diff options
context:
space:
mode:
authorGravatar Juan Martín Seery <me@juanm04.com> 2022-03-21 14:30:23 -0300
committerGravatar GitHub <noreply@github.com> 2022-03-21 12:30:23 -0500
commit41110ebe729d088a3f6b8ea1e42103a171e36a22 (patch)
tree969f985e89f6c739d00471ed8dfa68412595a1a9 /packages/astro-parser/src/utils/get_code_frame.ts
parent0c5378b8cf4fcf4a7b4e6c9e33f0ba9c370990f3 (diff)
downloadastro-41110ebe729d088a3f6b8ea1e42103a171e36a22.tar.gz
astro-41110ebe729d088a3f6b8ea1e42103a171e36a22.tar.zst
astro-41110ebe729d088a3f6b8ea1e42103a171e36a22.zip
chore: remove `@astrojs/parser` (#2845)
* Removed parser from astro * Removed parser files * Updated changeset config * Removed from license
Diffstat (limited to 'packages/astro-parser/src/utils/get_code_frame.ts')
-rw-r--r--packages/astro-parser/src/utils/get_code_frame.ts29
1 files changed, 0 insertions, 29 deletions
diff --git a/packages/astro-parser/src/utils/get_code_frame.ts b/packages/astro-parser/src/utils/get_code_frame.ts
deleted file mode 100644
index 098d5ad77..000000000
--- a/packages/astro-parser/src/utils/get_code_frame.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/** Die you stupid tabs */
-function tabs_to_spaces(str: string) {
- return str.replace(/^\t+/, (match) => match.split('\t').join(' '));
-}
-
-/** Display syntax error in pretty format in logs */
-export default function get_code_frame(source: string, line: number, column: number) {
- const lines = source.split('\n');
-
- const frame_start = Math.max(0, line - 2);
- const frame_end = Math.min(line + 3, lines.length);
-
- const digits = String(frame_end + 1).length;
-
- return lines
- .slice(frame_start, frame_end)
- .map((str, i) => {
- const isErrorLine = frame_start + i === line;
- const line_num = String(i + frame_start + 1).padStart(digits, ' ');
-
- if (isErrorLine) {
- const indicator = ' '.repeat(digits + 2 + tabs_to_spaces(str.slice(0, column)).length) + '^';
- return `${line_num}: ${tabs_to_spaces(str)}\n${indicator}`;
- }
-
- return `${line_num}: ${tabs_to_spaces(str)}`;
- })
- .join('\n');
-}