Skip to content

Commit 1c042f3

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular-devkit/build-angular): remove deprecated usage of canParse
All parsers now implement `parser.analyze`.
1 parent 1cc2d65 commit 1c042f3

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

packages/angular_devkit/build_angular/src/utils/load-translations.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ export async function createTranslationLoader(): Promise<TranslationLoader> {
2626
const content = fs.readFileSync(path, 'utf8');
2727
const unusedParsers = new Map();
2828
for (const [format, parser] of Object.entries(parsers)) {
29-
const analysis = analyze(parser, path, content);
29+
const analysis = parser.analyze(path, content);
3030
if (analysis.canParse) {
31-
const { locale, translations } = parser.parse(path, content, analysis.hint);
31+
// Types don't overlap here so we need to use any.
32+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33+
const { locale, translations } = parser.parse(path, content, analysis.hint as any);
3234
const integrity = 'sha256-' + createHash('sha256').update(content).digest('base64');
3335

3436
return { format, locale, translations, diagnostics, integrity };
@@ -46,18 +48,6 @@ export async function createTranslationLoader(): Promise<TranslationLoader> {
4648
messages.join('\n'),
4749
);
4850
};
49-
50-
// TODO: `parser.canParse()` is deprecated; remove this polyfill once we are sure all parsers provide the `parser.analyze()` method.
51-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
52-
function analyze(parser: any, path: string, content: string) {
53-
if (parser.analyze !== undefined) {
54-
return parser.analyze(path, content);
55-
} else {
56-
const hint = parser.canParse(path, content);
57-
58-
return { canParse: hint !== false, hint, diagnostics };
59-
}
60-
}
6151
}
6252

6353
async function importParsers() {

0 commit comments

Comments
 (0)