From ce497738934cf67a11202bea56731eebe62271bb Mon Sep 17 00:00:00 2001 From: Robbie Wagner Date: Fri, 25 Jul 2025 18:03:07 -0400 Subject: [PATCH] Update preprocess to prettier spec --- src/parse/index.ts | 11 ++++++----- src/parse/preprocess.ts | 13 ++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/parse/index.ts b/src/parse/index.ts index 833aa683..d7549d97 100644 --- a/src/parse/index.ts +++ b/src/parse/index.ts @@ -12,7 +12,7 @@ import { parsers as babelParsers } from 'prettier/plugins/babel.js'; import { PRINTER_NAME } from '../config.js'; import type { Options } from '../options.js'; import { assert } from '../utils/assert.js'; -import { preprocess, type Template } from './preprocess.js'; +import { codeToGlimmerAst, preprocess, type Template } from './preprocess.js'; const typescript = babelParsers['babel-ts'] as Parser; @@ -95,12 +95,13 @@ export const parser: Parser = { astFormat: PRINTER_NAME, async parse(code: string, options: Options): Promise { - const preprocessed = preprocess(code, options.filepath); - - const ast = await typescript.parse(preprocessed.code, options); + const ast = await typescript.parse(code, options); + const templates = codeToGlimmerAst(code, options.filepath); assert('expected ast', ast); - convertAst(ast as File, preprocessed.templates); + convertAst(ast as File, templates); return ast; }, + + preprocess, }; diff --git a/src/parse/preprocess.ts b/src/parse/preprocess.ts index 6241f6e2..8b68841a 100644 --- a/src/parse/preprocess.ts +++ b/src/parse/preprocess.ts @@ -1,3 +1,4 @@ +import type { Options } from '../options.js'; import { getBuffer, parse, @@ -91,18 +92,12 @@ export function codeToGlimmerAst(code: string, filename: string): Template[] { * fixing the offsets and locations of all nodes also calculates the block * params locations & ranges and adding it to the info */ -export function preprocess( - code: string, - fileName: string, -): { - code: string; - templates: Template[]; -} { - const templates = codeToGlimmerAst(code, fileName); +export function preprocess(code: string, options: Options): string { + const templates = codeToGlimmerAst(code, options.filepath); for (const template of templates) { code = preprocessTemplateRange(template, code); } - return { code, templates }; + return code; }