d12cdb5019
As of v10, the `undecorated-classes-with-decorated-fields` migration generally deals with undecorated classes using Angular features. We intended to run this migation as part of v10 again as undecorated classes with Angular features are no longer supported in planned v11. The migration currently behaves incorrectly in some cases where an `@Injectable` or `@Pipe` decorated classes uses the `ngOnDestroy` lifecycle hook. We incorrectly add a TODO for those classes. This commit fixes that. Additionally, this change makes the migration more robust to not migrate a class if it inherits from a component, pipe injectable or non-abstract directive. We previously did not need this as the undecorated-classes-with-di migration ran before, but this is no longer the case. Last, this commit fixes an issue where multiple TODO's could be added. This happens when multiple Angular CLI build targets have an overlap in source files. Multiple programs then capture the same source file, causing the migration to detect an undecorated class multiple times (i.e. adding a TODO twice). Fixes #37726. PR Close #37732
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
/**
|
|
* Template string function that can be used to dedent the resulting
|
|
* string literal. The smallest common indentation will be omitted.
|
|
* Additionally, whitespace in empty lines is removed.
|
|
*/
|
|
export function dedent(strings: TemplateStringsArray, ...values: any[]) {
|
|
let joinedString = '';
|
|
for (let i = 0; i < values.length; i++) {
|
|
joinedString += `${strings[i]}${values[i]}`;
|
|
}
|
|
joinedString += strings[strings.length - 1];
|
|
|
|
const matches = joinedString.match(/^[ \t]*(?=\S)/gm);
|
|
if (matches === null) {
|
|
return joinedString;
|
|
}
|
|
|
|
const minLineIndent = Math.min(...matches.map(el => el.length));
|
|
const omitMinIndentRegex = new RegExp(`^[ \\t]{${minLineIndent}}`, 'gm');
|
|
const omitEmptyLineWhitespaceRegex = /^[ \t]+$/gm;
|
|
const result = minLineIndent > 0 ? joinedString.replace(omitMinIndentRegex, '') : joinedString;
|
|
return result.replace(omitEmptyLineWhitespaceRegex, '');
|
|
}
|