Skip to content

Commit 6e46682

Browse files
committed
Move keyword check to resolver
1 parent ea83aa8 commit 6e46682

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

transforms/no-implicit-this/helpers/known-helpers.ts renamed to transforms/no-implicit-this/helpers/keywords.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
const KNOWN_HELPERS = [
1+
import Debug from 'debug';
2+
3+
const debug = Debug('ember-no-implicit-this-codemod:keywords');
4+
5+
// FIXME: Check keywords based on type. E.g. some can only be used in component vs helper position.
6+
export function isKeyword(_type: 'component' | 'helper' | 'ambiguous', name: string): boolean {
7+
if (KNOWN_KEYWORDS.includes(name)) {
8+
debug(`Skipping \`%s\` because it is a known helper`, name);
9+
return true;
10+
} else {
11+
return false;
12+
}
13+
}
14+
15+
const KNOWN_KEYWORDS = [
216
// Ember.js
317
'action',
418
'array',
@@ -39,5 +53,3 @@ const KNOWN_HELPERS = [
3953
'render-inverse', // glimmer blocks
4054
'-get-dynamic-var', // glimmer internal helper
4155
];
42-
43-
export default KNOWN_HELPERS;

transforms/no-implicit-this/helpers/plugin.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Debug from 'debug';
22
import { AST, builders as b, traverse } from 'ember-template-recast';
3-
import KNOWN_HELPERS from './known-helpers';
43
import { Options } from './options';
54

65
const debug = Debug('ember-no-implicit-this-codemod:plugin');
@@ -75,15 +74,7 @@ export default function transform(root: AST.Node, { customHelpers, resolver }: O
7574
Object.assign(node, b.path(`this.${node.original}`));
7675
}
7776

78-
// app/components/foo.js
79-
// <div class={{foo}} />
80-
8177
function isHelper(name: string) {
82-
if (KNOWN_HELPERS.includes(name)) {
83-
debug(`Skipping \`%s\` because it is a known helper`, name);
84-
return true;
85-
}
86-
8778
if (customHelpers.includes(name)) {
8879
debug(`Skipping \`%s\` because it is a custom configured helper`, name);
8980
return true;

transforms/no-implicit-this/helpers/resolver.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { Telemetry, getTelemetry } from './telemetry';
33
import { Resolver as _EmbroiderResolver } from '@embroider/core';
44
import { readFileSync } from 'node:fs';
55
import { resolve } from 'node:path';
6+
import { isKeyword } from './keywords';
67

78
export default abstract class Resolver {
89
has(type: 'component' | 'helper' | 'ambiguous', name: string): boolean {
10+
if (isKeyword(type, name)) {
11+
return true;
12+
}
913
switch (type) {
1014
case 'component':
1115
return this.hasComponent(name);
@@ -16,10 +20,10 @@ export default abstract class Resolver {
1620
}
1721
}
1822

19-
abstract hasComponent(name: string): boolean;
20-
abstract hasHelper(name: string): boolean;
23+
protected abstract hasComponent(name: string): boolean;
24+
protected abstract hasHelper(name: string): boolean;
2125

22-
hasAmbiguous(name: string): boolean {
26+
protected hasAmbiguous(name: string): boolean {
2327
return this.hasComponent(name) || this.hasHelper(name);
2428
}
2529
}

0 commit comments

Comments
 (0)