Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node | undefined>;

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

async parse(code: string, options: Options): Promise<Node> {
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,
};
13 changes: 4 additions & 9 deletions src/parse/preprocess.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Options } from '../options.js';
import {
getBuffer,
parse,
Expand Down Expand Up @@ -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;
}
Loading