From 18400088375866b8b2c0aeec4508ba9c0a1fbd02 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 23 Aug 2018 22:28:10 +0200 Subject: [PATCH] refactor(schematics): cleanup input and output name rules (#12800) * Cleans up the update rules for `@Input()` and `@Output()` names. * Adds thorough test cases for input and output names. --- src/lib/schematics/update/html/angular.ts | 32 ++++--- .../update/material/data/input-names.ts | 8 +- .../update/material/data/output-names.ts | 2 - .../input-names/inputNamesStylesheetRule.ts | 86 ++++++++++++++++++ .../input-names/inputNamesTemplateRule.ts | 76 ++++++++++++++++ .../output-names/outputNamesTemplateRule.ts | 76 ++++++++++++++++ .../rules/switchStylesheetInputNamesRule.ts | 90 ------------------- .../rules/switchStylesheetOutputNamesRule.ts | 90 ------------------- .../rules/switchTemplateInputNamesRule.ts | 85 ------------------ .../rules/switchTemplateOutputNamesRule.ts | 85 ------------------ .../update/test-cases/index.spec.ts | 4 +- ...tput.ts => class-names_expected_output.ts} | 0 ...ss-names_input.ts => class-names_input.ts} | 0 .../v5/input-names_expected_output.ts | 62 +++++++++++++ .../update/test-cases/v5/input-names_input.ts | 62 +++++++++++++ .../v5/output-names_expected_output.ts | 29 ++++++ .../test-cases/v5/output-names_input.ts | 29 ++++++ src/lib/schematics/update/update.ts | 13 ++- 18 files changed, 458 insertions(+), 371 deletions(-) create mode 100644 src/lib/schematics/update/rules/input-names/inputNamesStylesheetRule.ts create mode 100644 src/lib/schematics/update/rules/input-names/inputNamesTemplateRule.ts create mode 100644 src/lib/schematics/update/rules/output-names/outputNamesTemplateRule.ts delete mode 100644 src/lib/schematics/update/rules/switchStylesheetInputNamesRule.ts delete mode 100644 src/lib/schematics/update/rules/switchStylesheetOutputNamesRule.ts delete mode 100644 src/lib/schematics/update/rules/switchTemplateInputNamesRule.ts delete mode 100644 src/lib/schematics/update/rules/switchTemplateOutputNamesRule.ts rename src/lib/schematics/update/test-cases/v5/{ts-class-names_expected_output.ts => class-names_expected_output.ts} (100%) rename src/lib/schematics/update/test-cases/v5/{ts-class-names_input.ts => class-names_input.ts} (100%) create mode 100644 src/lib/schematics/update/test-cases/v5/input-names_expected_output.ts create mode 100644 src/lib/schematics/update/test-cases/v5/input-names_input.ts create mode 100644 src/lib/schematics/update/test-cases/v5/output-names_expected_output.ts create mode 100644 src/lib/schematics/update/test-cases/v5/output-names_input.ts diff --git a/src/lib/schematics/update/html/angular.ts b/src/lib/schematics/update/html/angular.ts index c7ed1f5f801..6823f229674 100644 --- a/src/lib/schematics/update/html/angular.ts +++ b/src/lib/schematics/update/html/angular.ts @@ -10,10 +10,26 @@ import {findAttributeOnElementWithAttrs, findAttributeOnElementWithTag} from './ /** Finds the specified Angular @Input in the given elements with tag name. */ export function findInputsOnElementWithTag(html: string, inputName: string, tagNames: string[]) { - // Add one column to the mapped offset because the first bracket for the @Input - // is part of the attribute and therefore also part of the offset. We only want to return - // the offset for the inner name of the input. - return findAttributeOnElementWithTag(html, `[${inputName}]`, tagNames).map(offset => offset + 1); + return [ + // Inputs can be also used without brackets (e.g. ``) + ...findAttributeOnElementWithTag(html, inputName, tagNames), + // Add one column to the mapped offset because the first bracket for the @Input + // is part of the attribute and therefore also part of the offset. We only want to return + // the offset for the inner name of the bracketed input. + ...findAttributeOnElementWithTag(html, `[${inputName}]`, tagNames).map(offset => offset + 1), + ]; +} + +/** Finds the specified Angular @Input in elements that have one of the specified attributes. */ +export function findInputsOnElementWithAttr(html: string, inputName: string, attrs: string[]) { + return [ + // Inputs can be also used without brackets (e.g. `