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 db24097 commit 90145ba
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 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 @@ -687,6 +687,9 @@ export default class ComponentParser {

return {
props: ComponentParser.mapToArray(this.props).map((prop) => {
// Remove carriage returns for Windows
prop.value = prop.value?.replace(/\r/g, " ");

if (this.bindings.has(prop.name)) {
return {
...prop,
Expand Down Expand Up @@ -734,7 +737,8 @@ export default class ComponentParser {
typedefs: ComponentParser.mapToArray(this.typedefs),
rest_props: this.rest_props,
extends: this.extends,
componentComment: this.componentComment,
// Remove carriage returns for Windows
componentComment: this.componentComment?.replace(/\r/g, ''),
};
}
}

0 comments on commit 90145ba

Please sign in to comment.