Skip to content

Commit

Permalink
chore: apply eslint member-ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Aug 30, 2023
1 parent db39e98 commit 0126ec1
Show file tree
Hide file tree
Showing 37 changed files with 565 additions and 579 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ module.exports = {
'error',
{ prefer: 'type-imports' },
],
'@typescript-eslint/member-ordering': memberOrder,

// TODO
'@typescript-eslint/ban-ts-comment': 0,
Expand All @@ -251,9 +252,7 @@ module.exports = {
},
{
files: ['**/processors/**/*.ts'],
rules: {
'@typescript-eslint/member-ordering': memberOrder,
},
rules: {},
},
{
files: ['*.js', '*.jsx'],
Expand Down
74 changes: 37 additions & 37 deletions packages/babel/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,14 @@ const loggers = cacheNames.reduce(
);

export class TransformCacheCollection {
private contentHashes = new Map<string, string>();

protected readonly entrypoints: Map<string, Entrypoint | EvaluatedEntrypoint>;

private contentHashes = new Map<string, string>();

constructor(caches: Partial<ICaches> = {}) {
this.entrypoints = caches.entrypoints || new Map();
}

public invalidateForFile(filename: string) {
cacheNames.forEach((cacheName) => {
this.invalidate(cacheName, filename);
});
}

public invalidateIfChanged(filename: string, content: string) {
const hash = this.contentHashes.get(filename);
const newHash = hashContent(content);

if (hash !== newHash) {
cacheLogger('content has changed, invalidate all for %s', filename);
this.contentHashes.set(filename, newHash);
this.invalidateForFile(filename);

return true;
}

return false;
}

public add<
TCache extends CacheNames,
TValue extends MapValue<ICaches[TCache]>,
Expand All @@ -75,6 +54,25 @@ export class TransformCacheCollection {
cache.set(key, value);
}

public clear(cacheName: CacheNames | 'all'): void {
if (cacheName === 'all') {
cacheNames.forEach((name) => {
this.clear(name);
});

return;
}

loggers[cacheName]('clear');
const cache = this[cacheName] as Map<string, unknown>;

cache.clear();
}

public delete(cacheName: CacheNames, key: string): void {
this.invalidate(cacheName, key);
}

public get<
TCache extends CacheNames,
TValue extends MapValue<ICaches[TCache]>,
Expand All @@ -94,10 +92,6 @@ export class TransformCacheCollection {
return res;
}

public delete(cacheName: CacheNames, key: string): void {
this.invalidate(cacheName, key);
}

public invalidate(cacheName: CacheNames, key: string): void {
const cache = this[cacheName] as Map<string, unknown>;
if (!cache.has(key)) {
Expand All @@ -109,18 +103,24 @@ export class TransformCacheCollection {
cache.delete(key);
}

public clear(cacheName: CacheNames | 'all'): void {
if (cacheName === 'all') {
cacheNames.forEach((name) => {
this.clear(name);
});
public invalidateForFile(filename: string) {
cacheNames.forEach((cacheName) => {
this.invalidate(cacheName, filename);
});
}

return;
}
public invalidateIfChanged(filename: string, content: string) {
const hash = this.contentHashes.get(filename);
const newHash = hashContent(content);

loggers[cacheName]('clear');
const cache = this[cacheName] as Map<string, unknown>;
if (hash !== newHash) {
cacheLogger('content has changed, invalidate all for %s', filename);
this.contentHashes.set(filename, newHash);
this.invalidateForFile(filename);

cache.clear();
return true;
}

return false;
}
}
Loading

0 comments on commit 0126ec1

Please sign in to comment.