Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/better-tires-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codemod-utils/ast-template-tag": minor
---

Fixed lint errors
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { MARKER } from './marker.js';

export function getTemplate(expression: unknown): string | undefined {
Expand All @@ -9,14 +8,17 @@ export function getTemplate(expression: unknown): string | undefined {

if (
// @ts-expect-error: Incorrect type
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expression.callee.type !== 'Identifier' ||
// @ts-expect-error: Incorrect type
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expression.callee.name !== MARKER
) {
return;
}

// @ts-expect-error: Incorrect type
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const template = expression.arguments[0].quasis[0].value.raw as string;

return template;
Expand Down
44 changes: 23 additions & 21 deletions packages/ast/template-tag/src/-private/to-ecma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
import { AST } from '@codemod-utils/ast-javascript';

import { getTemplate, preprocessor } from './content-tag.js';
Expand All @@ -13,15 +12,6 @@ type Marker = {
};
};

function getMarker(nodeValue: unknown): Marker {
return {
// @ts-expect-error: Incorrect type
code: AST.print(nodeValue),
// @ts-expect-error: Incorrect type
end: nodeValue.loc.end,
};
}

function sortMarkers(a: Marker, b: Marker): number {
if (a.end.line > b.end.line) {
return -1;
Expand Down Expand Up @@ -49,36 +39,44 @@ export function findMarkers(file: string): Marker[] {
const markers: Marker[] = [];

traverse(code, {
visitCallExpression(node) {
const template = getTemplate(node.value);
visitCallExpression(path) {
const template = getTemplate(path.node);

if (template === undefined) {
this.traverse(node);
this.traverse(path);

return false;
}

markers.push(getMarker(node.value));
markers.push({
code: AST.print(path.node),
// @ts-expect-error: Incorrect type
end: path.node.loc!.end,
});

return false;
},

visitExportDefaultDeclaration(node) {
const template = getTemplate(node.value.declaration);
visitExportDefaultDeclaration(path) {
const template = getTemplate(path.node.declaration);

if (template === undefined) {
this.traverse(node);
this.traverse(path);

return false;
}

markers.push(getMarker(node.value));
markers.push({
code: AST.print(path.node),
// @ts-expect-error: Incorrect type
end: path.node.loc!.end,
});

return false;
},

visitStaticBlock(node) {
const bodyNode = node.value.body[0];
visitStaticBlock(path) {
const bodyNode = path.node.body[0]!;

if (bodyNode.type !== 'ExpressionStatement') {
return false;
Expand All @@ -90,7 +88,11 @@ export function findMarkers(file: string): Marker[] {
return false;
}

markers.push(getMarker(node.value));
markers.push({
code: AST.print(path.node),
// @ts-expect-error: Incorrect type
end: path.node.loc!.end,
});

return false;
},
Expand Down
23 changes: 11 additions & 12 deletions packages/ast/template-tag/src/-private/to-template-tag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
import { AST } from '@codemod-utils/ast-javascript';

import { getTemplate, MARKER } from './content-tag.js';
Expand All @@ -11,34 +10,34 @@ export function removeMarkers(file: string): string {
const traverse = AST.traverse(true);

const ast = traverse(file, {
visitCallExpression(node) {
const template = getTemplate(node.value);
visitCallExpression(path) {
const template = getTemplate(path.node);

if (template === undefined) {
this.traverse(node);
this.traverse(path);

return false;
}

return `<template>${template}</template>`;
},

visitExportDefaultDeclaration(node) {
const template = getTemplate(node.value.declaration);
visitExportDefaultDeclaration(path) {
const template = getTemplate(path.node.declaration);

if (template === undefined) {
this.traverse(node);
this.traverse(path);

return false;
}

return `<template>${template}</template>`;
},

visitImportDeclaration(node) {
visitImportDeclaration(path) {
if (
node.value.source.type !== 'StringLiteral' ||
node.value.source.value !== '@ember/template-compiler'
path.node.source.type !== 'StringLiteral' ||
path.node.source.value !== '@ember/template-compiler'
) {
return false;
}
Expand All @@ -47,8 +46,8 @@ export function removeMarkers(file: string): string {
return null;
},

visitStaticBlock(node) {
const bodyNode = node.value.body[0];
visitStaticBlock(path) {
const bodyNode = path.node.body[0]!;

if (bodyNode.type !== 'ExpressionStatement') {
return false;
Expand Down