@@ -6,21 +6,15 @@ import type {
66 ObjectExpression ,
77 StaticBlock ,
88} from '@babel/types' ;
9- import { Preprocessor } from 'content-tag' ;
109import type { Parser } from 'prettier' ;
1110import { parsers as babelParsers } from 'prettier/plugins/babel.js' ;
1211
1312import { PRINTER_NAME } from '../config.js' ;
1413import type { Options } from '../options.js' ;
1514import { assert } from '../utils/assert.js' ;
16- import {
17- byteToCharIndex ,
18- preprocessTemplateRange ,
19- type Template ,
20- } from './preprocess.js' ;
15+ import { preprocess , type Template } from './preprocess.js' ;
2116
2217const typescript = babelParsers [ 'babel-ts' ] as Parser < Node | undefined > ;
23- const p = new Preprocessor ( ) ;
2418
2519/** Converts a node into a GlimmerTemplate node */
2620function convertNode (
@@ -87,27 +81,6 @@ function convertAst(ast: File, templates: Template[]): void {
8781 }
8882}
8983
90- /**
91- * Pre-processes the template info, parsing the template content to Glimmer AST,
92- * fixing the offsets and locations of all nodes also calculates the block
93- * params locations & ranges and adding it to the info
94- */
95- export function preprocess (
96- code : string ,
97- fileName : string ,
98- ) : {
99- code : string ;
100- templates : Template [ ] ;
101- } {
102- const templates = codeToGlimmerAst ( code , fileName ) ;
103-
104- for ( const template of templates ) {
105- code = preprocessTemplateRange ( template , code ) ;
106- }
107-
108- return { templates, code } ;
109- }
110-
11184export const parser : Parser < Node | undefined > = {
11285 ...typescript ,
11386 astFormat : PRINTER_NAME ,
@@ -120,20 +93,3 @@ export const parser: Parser<Node | undefined> = {
12093 return ast ;
12194 } ,
12295} ;
123-
124- /** Pre-processes the template info, parsing the template content to Glimmer AST. */
125- export function codeToGlimmerAst ( code : string , filename : string ) : Template [ ] {
126- const rawTemplates = p . parse ( code , { filename } ) ;
127- const templates : Template [ ] = rawTemplates . map ( ( r ) => ( {
128- type : r . type ,
129- range : r . range ,
130- contentRange : r . contentRange ,
131- contents : r . contents ,
132- utf16Range : {
133- start : byteToCharIndex ( code , r . range . start ) ,
134- end : byteToCharIndex ( code , r . range . end ) ,
135- } ,
136- } ) ) ;
137-
138- return templates ;
139- }
0 commit comments