Skip to content

Commit ce49773

Browse files
Update preprocess to prettier spec
1 parent 0ceae89 commit ce49773

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/parse/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { parsers as babelParsers } from 'prettier/plugins/babel.js';
1212
import { PRINTER_NAME } from '../config.js';
1313
import type { Options } from '../options.js';
1414
import { assert } from '../utils/assert.js';
15-
import { preprocess, type Template } from './preprocess.js';
15+
import { codeToGlimmerAst, preprocess, type Template } from './preprocess.js';
1616

1717
const typescript = babelParsers['babel-ts'] as Parser<Node | undefined>;
1818

@@ -95,12 +95,13 @@ export const parser: Parser<Node | undefined> = {
9595
astFormat: PRINTER_NAME,
9696

9797
async parse(code: string, options: Options): Promise<Node> {
98-
const preprocessed = preprocess(code, options.filepath);
99-
100-
const ast = await typescript.parse(preprocessed.code, options);
98+
const ast = await typescript.parse(code, options);
99+
const templates = codeToGlimmerAst(code, options.filepath);
101100
assert('expected ast', ast);
102-
convertAst(ast as File, preprocessed.templates);
101+
convertAst(ast as File, templates);
103102

104103
return ast;
105104
},
105+
106+
preprocess,
106107
};

src/parse/preprocess.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Options } from '../options.js';
12
import {
23
getBuffer,
34
parse,
@@ -91,18 +92,12 @@ export function codeToGlimmerAst(code: string, filename: string): Template[] {
9192
* fixing the offsets and locations of all nodes also calculates the block
9293
* params locations & ranges and adding it to the info
9394
*/
94-
export function preprocess(
95-
code: string,
96-
fileName: string,
97-
): {
98-
code: string;
99-
templates: Template[];
100-
} {
101-
const templates = codeToGlimmerAst(code, fileName);
95+
export function preprocess(code: string, options: Options): string {
96+
const templates = codeToGlimmerAst(code, options.filepath);
10297

10398
for (const template of templates) {
10499
code = preprocessTemplateRange(template, code);
105100
}
106101

107-
return { code, templates };
102+
return code;
108103
}

0 commit comments

Comments
 (0)