Skip to content

Commit

Permalink
Ignore angular component selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
MillerSvt committed Apr 2, 2024
1 parent c0d4f79 commit b4c7204
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/is-allowed-literal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { AstPath } from 'prettier';

import isAngularComponentSelector from './is-angular-component-selector.js';
import isDynamicImport from './is-dynamic-import.js';
import isImportExport from './is-import-export.js';
import isProperty from './is-property.js';

export default function (path: AstPath): boolean {
return !isImportExport(path) && !isProperty(path) && !isDynamicImport(path);
return (
!isImportExport(path) &&
!isProperty(path) &&
!isDynamicImport(path) &&
!isAngularComponentSelector(path)
);
}
44 changes: 44 additions & 0 deletions src/is-angular-component-selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { AstPath } from 'prettier';

// TODO https://youtrack.jetbrains.com/issue/WEB-56900/Angular-doesnt-parse-plain-backticks-in-decorators#focus=Comments-27-6392379.0-0
export default function (path: AstPath): boolean {
const [
propertyNode,
objectExpressionNode,
callExpressionNode,
decoratorNode,
classDeclarationNode,
] = path.ancestors;

if (
propertyNode?.type !== 'Property' ||
objectExpressionNode?.type !== 'ObjectExpression' ||
callExpressionNode?.type !== 'CallExpression' ||
decoratorNode?.type !== 'Decorator' ||
classDeclarationNode?.type !== 'ClassDeclaration'
) {
return false;
}

{
const {
key: { type, name },
} = propertyNode;

if (type !== 'Identifier' || name !== 'selector') {
return false;
}
}

{
const {
callee: { type, name },
} = callExpressionNode;

if (type !== 'Identifier' || name !== 'Component') {
return false;
}
}

return true;
}
7 changes: 7 additions & 0 deletions test/fixtures/angular-component-selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Component} from '@angular/core';

@Component({
selector: 'test',
templateUrl: 'test.html',
})
export class TestComponent {}
7 changes: 7 additions & 0 deletions test/snapshots/fixture.angular-component-selector.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Component } from "@angular/core";

@Component({
selector: "test",
templateUrl: `test.html`,
})
export class TestComponent {}
1 change: 0 additions & 1 deletion test/utils/get-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default async function* (): AsyncGenerator<{
content: string;
}> {
for (const item of await readdir(fixturesDir)) {
// for (const item of ['objects.js']) {
const itemUrl = new URL(item, fixturesDir);

const itemStat = await stat(itemUrl);
Expand Down

0 comments on commit b4c7204

Please sign in to comment.