Skip to content

Commit

Permalink
fix(component-parser): remove carriage return for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Apr 6, 2024
1 parent a73dffb commit 1492b1a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/ComponentParser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// TODO: upgrading to Svelte 4 shows a lot of TS errors. Ignore for now but resolve.
// @ts-nocheck
import { compile, walk, parse } from "svelte/compiler";
import * as commentParser from "comment-parser";
import type { VariableDeclaration } from "estree";
import { Node } from "estree-walker";
import { compile, parse, walk } from "svelte/compiler";
import { Ast, TemplateNode, Var } from "svelte/types/compiler/interfaces";
import { getElementByTag } from "./element-tag-map";
import { Node } from "estree-walker";
import type { VariableDeclaration } from "estree";

interface CompiledSvelteCode {
vars: Var[];
Expand Down Expand Up @@ -134,7 +134,7 @@ export default class ComponentParser {
this.options = options;
}

private static mapToArray(map: Map<any, any>) {
private static mapToArray<T>(map: Map<any, T>) {
return Array.from(map, ([key, value]) => value);
}

Expand Down Expand Up @@ -370,7 +370,7 @@ export default class ComponentParser {
init.type === "ArrayExpression" ||
init.type === "ArrowFunctionExpression"
) {
value = this.sourceAtPos(init.start, init.end)?.replace(/\n/g, " ");
value = this.sourceAtPos(init.start, init.end)?.replace(/[\r\n]+/g, " ");
type = value;
isFunction = init.type === "ArrowFunctionExpression";

Expand All @@ -391,7 +391,7 @@ export default class ComponentParser {
}

if (declaration_type === "FunctionDeclaration") {
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/\n/g, " ");
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/[\r\n]+/g, " ");
type = "() => any";
kind = "function";
isFunction = true;
Expand Down Expand Up @@ -506,7 +506,7 @@ export default class ComponentParser {
init.type === "ArrayExpression" ||
init.type === "ArrowFunctionExpression"
) {
value = this.sourceAtPos(init.start, init.end)?.replace(/\n/g, " ");
value = this.sourceAtPos(init.start, init.end)?.replace(/[\r\n]+/g, " ");
type = value;
isFunction = init.type === "ArrowFunctionExpression";

Expand All @@ -527,7 +527,7 @@ export default class ComponentParser {
}

if (declaration_type === "FunctionDeclaration") {
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/\n/g, " ");
value = "() => " + this.sourceAtPos(body.start, body.end)?.replace(/[\r\n]+/g, " ");
type = "() => any";
kind = "function";
isFunction = true;
Expand Down Expand Up @@ -582,7 +582,7 @@ export default class ComponentParser {
let data: string = node?.data?.trim() ?? "";

if (/^@component/.test(data)) {
this.componentComment = data.replace(/^@component/, "");
this.componentComment = data.replace(/^@component/, "").replace(/\r/g, "");
}
}

Expand Down

0 comments on commit 1492b1a

Please sign in to comment.