Skip to content

Commit 68083ae

Browse files
committed
refactor: Added new lines for readability
1 parent aa860e2 commit 68083ae

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/parse/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function convertAst(ast: File, templates: Template[]): void {
3333
traverse(ast, {
3434
enter(path) {
3535
const { node } = path;
36+
3637
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
3738
switch (node.type) {
3839
case 'BlockStatement':
@@ -54,21 +55,27 @@ function convertAst(ast: File, templates: Template[]): void {
5455
utf16Range.end === end + 1
5556
);
5657
});
58+
5759
if (templateIndex === -1) {
5860
return null;
5961
}
62+
6063
const rawTemplate = templates.splice(templateIndex, 1)[0];
64+
6165
if (!rawTemplate) {
6266
throw new Error(
6367
'expected raw template because splice index came from findIndex',
6468
);
6569
}
70+
6671
const index =
6772
node.innerComments?.[0] &&
6873
ast.comments?.indexOf(node.innerComments[0]);
74+
6975
if (ast.comments && index !== undefined && index >= 0) {
7076
ast.comments.splice(index, 1);
7177
}
78+
7279
convertNode(node, rawTemplate);
7380
}
7481
}
@@ -90,9 +97,11 @@ export const parser: Parser<Node | undefined> = {
9097

9198
async parse(code: string, options: Options): Promise<Node> {
9299
const preprocessed = preprocess(code, options.filepath);
100+
93101
const ast = await typescript.parse(preprocessed.code, options);
94102
assert('expected ast', ast);
95103
convertAst(ast as File, preprocessed.templates);
104+
96105
return ast;
97106
},
98107
};

src/parse/preprocess.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export function preprocessTemplateRange(
7373
suffix = '*/}';
7474

7575
const nextToken = code.slice(template.range.end).toString().match(/\S+/);
76+
7677
if (nextToken && (nextToken[0] === 'as' || nextToken[0] === 'satisfies')) {
7778
// Replace with parenthesized ObjectExpression
7879
prefix = '(' + prefix;
@@ -83,10 +84,12 @@ export function preprocessTemplateRange(
8384
// We need to replace forward slash with _something else_, because
8485
// forward slash breaks the parsed templates.
8586
const content = template.contents.replaceAll('/', PLACEHOLDER);
87+
8688
const tplLength = template.range.end - template.range.start;
8789
const spaces =
8890
tplLength - byteLength(content) - prefix.length - suffix.length;
8991
const total = prefix + content + ' '.repeat(spaces) + suffix;
92+
9093
return replaceRange(code, template.range.start, template.range.end, total);
9194
}
9295

@@ -95,6 +98,7 @@ const p = new Preprocessor();
9598
/** Pre-processes the template info, parsing the template content to Glimmer AST. */
9699
export function codeToGlimmerAst(code: string, filename: string): Template[] {
97100
const rawTemplates = p.parse(code, { filename });
101+
98102
const templates: Template[] = rawTemplates.map((r) => ({
99103
type: r.type,
100104
range: r.range,

0 commit comments

Comments
 (0)