From 557c0c91164e197ce2719f34fc681c68533ab371 Mon Sep 17 00:00:00 2001 From: Benjamin Gwynn Date: Tue, 27 Sep 2022 10:29:57 +0100 Subject: [PATCH 1/2] Add support for printing Literal nodes Fixes "Error: unknown node type: Literal" when using _prettier.__debug.formatAST with an AST from svelte.parse. --- src/print/index.ts | 2 ++ src/print/nodes.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/print/index.ts b/src/print/index.ts index b5915ba1..64a14c29 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -392,6 +392,8 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D ]); case 'Identifier': return node.name; + case 'Literal': + return ' ' + node.raw; case 'AttributeShorthand': { return (node.expression as any).name; } diff --git a/src/print/nodes.ts b/src/print/nodes.ts index cbdea261..6ca5c93d 100644 --- a/src/print/nodes.ts +++ b/src/print/nodes.ts @@ -45,6 +45,12 @@ export interface IdentifierNode extends BaseNode { name: string; } +export interface LiteralNode extends BaseNode { + type: 'Literal'; + data: string; + raw: string; +} + export interface AttributeShorthandNode extends BaseNode { type: 'AttributeShorthand'; name: string; @@ -283,6 +289,7 @@ export type Node = | MustacheTagNode | AttributeNode | IdentifierNode + | LiteralNode | AttributeShorthandNode | IfBlockNode | ElseBlockNode From 1ae886c69f440aaddac5f2fa1a4c71833b113516 Mon Sep 17 00:00:00 2001 From: Benjamin Gwynn Date: Wed, 28 Sep 2022 11:38:12 +0100 Subject: [PATCH 2/2] Remove invalid space character --- src/print/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/print/index.ts b/src/print/index.ts index 64a14c29..c013d9c9 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -393,7 +393,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D case 'Identifier': return node.name; case 'Literal': - return ' ' + node.raw; + return '' + node.raw; case 'AttributeShorthand': { return (node.expression as any).name; }