@dugararchit/cdk 0.0.0-dugararchit
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_index.scss +8 -0
- package/a11y/_index.import.scss +2 -0
- package/a11y/_index.scss +102 -0
- package/a11y/a11y-prebuilt.scss +3 -0
- package/fesm2022/stagefright5-cdk-a11y.mjs +2381 -0
- package/fesm2022/stagefright5-cdk-a11y.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-accordion.mjs +267 -0
- package/fesm2022/stagefright5-cdk-accordion.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-bidi.mjs +185 -0
- package/fesm2022/stagefright5-cdk-bidi.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-clipboard.mjs +250 -0
- package/fesm2022/stagefright5-cdk-clipboard.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-coercion.mjs +128 -0
- package/fesm2022/stagefright5-cdk-coercion.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-collections.mjs +472 -0
- package/fesm2022/stagefright5-cdk-collections.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-drag-drop.mjs +3690 -0
- package/fesm2022/stagefright5-cdk-drag-drop.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-keycodes.mjs +159 -0
- package/fesm2022/stagefright5-cdk-keycodes.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-layout.mjs +246 -0
- package/fesm2022/stagefright5-cdk-layout.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-observers.mjs +203 -0
- package/fesm2022/stagefright5-cdk-observers.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-overlay.mjs +3033 -0
- package/fesm2022/stagefright5-cdk-overlay.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-platform.mjs +375 -0
- package/fesm2022/stagefright5-cdk-platform.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-portal.mjs +672 -0
- package/fesm2022/stagefright5-cdk-portal.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-scrolling.mjs +1399 -0
- package/fesm2022/stagefright5-cdk-scrolling.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-stepper.mjs +624 -0
- package/fesm2022/stagefright5-cdk-stepper.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-table.mjs +2346 -0
- package/fesm2022/stagefright5-cdk-table.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-protractor.mjs +324 -0
- package/fesm2022/stagefright5-cdk-testing-protractor.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs +364 -0
- package/fesm2022/stagefright5-cdk-testing-selenium-webdriver.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing-testbed.mjs +806 -0
- package/fesm2022/stagefright5-cdk-testing-testbed.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-testing.mjs +740 -0
- package/fesm2022/stagefright5-cdk-testing.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-text-field.mjs +453 -0
- package/fesm2022/stagefright5-cdk-text-field.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk-tree.mjs +945 -0
- package/fesm2022/stagefright5-cdk-tree.mjs.map +1 -0
- package/fesm2022/stagefright5-cdk.mjs +26 -0
- package/fesm2022/stagefright5-cdk.mjs.map +1 -0
- package/overlay/_index-deprecated.scss +13 -0
- package/overlay/_index.import.scss +13 -0
- package/overlay/_index.scss +148 -0
- package/overlay/overlay-prebuilt.scss +3 -0
- package/package.json +159 -0
- package/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
- package/schematics/schematics/BUILD.bazel +104 -0
- package/schematics/schematics/README.md +4 -0
- package/schematics/schematics/collection.json +18 -0
- package/schematics/schematics/index.ts +22 -0
- package/schematics/schematics/migration.json +50 -0
- package/schematics/schematics/ng-add/index.spec.ts +50 -0
- package/schematics/schematics/ng-add/index.ts +39 -0
- package/schematics/schematics/ng-add/package-config.ts +62 -0
- package/schematics/schematics/ng-add/schema.json +16 -0
- package/schematics/schematics/ng-add/schema.ts +12 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.__style__.template +53 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html.template +17 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.spec.ts.template +29 -0
- package/schematics/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template +43 -0
- package/schematics/schematics/ng-generate/drag-drop/index.spec.ts +205 -0
- package/schematics/schematics/ng-generate/drag-drop/index.ts +35 -0
- package/schematics/schematics/ng-generate/drag-drop/schema.json +93 -0
- package/schematics/schematics/ng-generate/drag-drop/schema.ts +11 -0
- package/schematics/schematics/ng-update/data/attribute-selectors.ts +29 -0
- package/schematics/schematics/ng-update/data/class-names.ts +50 -0
- package/schematics/schematics/ng-update/data/constructor-checks.ts +75 -0
- package/schematics/schematics/ng-update/data/css-selectors.ts +33 -0
- package/schematics/schematics/ng-update/data/element-selectors.ts +21 -0
- package/schematics/schematics/ng-update/data/index.ts +18 -0
- package/schematics/schematics/ng-update/data/input-names.ts +118 -0
- package/schematics/schematics/ng-update/data/method-call-checks.ts +63 -0
- package/schematics/schematics/ng-update/data/output-names.ts +42 -0
- package/schematics/schematics/ng-update/data/property-names.ts +151 -0
- package/schematics/schematics/ng-update/data/symbol-removal.ts +22 -0
- package/schematics/schematics/ng-update/devkit-file-system.ts +87 -0
- package/schematics/schematics/ng-update/devkit-migration-rule.ts +185 -0
- package/schematics/schematics/ng-update/devkit-migration.ts +47 -0
- package/schematics/schematics/ng-update/find-stylesheets.ts +43 -0
- package/schematics/schematics/ng-update/html-parsing/angular.ts +49 -0
- package/schematics/schematics/ng-update/html-parsing/elements.ts +66 -0
- package/schematics/schematics/ng-update/index.ts +113 -0
- package/schematics/schematics/ng-update/migrations/attribute-selectors.ts +83 -0
- package/schematics/schematics/ng-update/migrations/class-inheritance.ts +63 -0
- package/schematics/schematics/ng-update/migrations/class-names.ts +107 -0
- package/schematics/schematics/ng-update/migrations/constructor-signature.ts +170 -0
- package/schematics/schematics/ng-update/migrations/css-selectors.ts +83 -0
- package/schematics/schematics/ng-update/migrations/element-selectors.ts +75 -0
- package/schematics/schematics/ng-update/migrations/input-names.ts +83 -0
- package/schematics/schematics/ng-update/migrations/method-call-arguments.ts +70 -0
- package/schematics/schematics/ng-update/migrations/misc-template.ts +36 -0
- package/schematics/schematics/ng-update/migrations/output-names.ts +61 -0
- package/schematics/schematics/ng-update/migrations/property-names.ts +61 -0
- package/schematics/schematics/ng-update/migrations/symbol-removal.ts +51 -0
- package/schematics/schematics/ng-update/migrations/tilde-import-v13/tilde-import-migration.ts +40 -0
- package/schematics/schematics/ng-update/public-api.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/index.spec.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution.spec.ts +32 -0
- package/schematics/schematics/ng-update/test-cases/misc/external-resource-resolution_input.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets-test.scss +3 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets.spec.ts +50 -0
- package/schematics/schematics/ng-update/test-cases/misc/global-stylesheets_input.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts +20 -0
- package/schematics/schematics/ng-update/test-cases/misc/method-call-checks_input.ts +18 -0
- package/schematics/schematics/ng-update/test-cases/misc/module-resolution.spec.ts +27 -0
- package/schematics/schematics/ng-update/test-cases/v13/misc/tilde-import-v13.spec.ts +149 -0
- package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_expected_output.ts +36 -0
- package/schematics/schematics/ng-update/test-cases/v6/attribute-selectors_input.ts +36 -0
- package/schematics/schematics/ng-update/test-cases/v6/class-names_expected_output.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/v6/class-names_input.ts +8 -0
- package/schematics/schematics/ng-update/test-cases/v6/input-names_expected_output.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/v6/input-names_input.ts +22 -0
- package/schematics/schematics/ng-update/test-cases/v6/property-names_expected_output.ts +64 -0
- package/schematics/schematics/ng-update/test-cases/v6/property-names_input.ts +64 -0
- package/schematics/schematics/ng-update/test-cases/v7/property-names_expected_output.ts +28 -0
- package/schematics/schematics/ng-update/test-cases/v7/property-names_input.ts +28 -0
- package/schematics/schematics/ng-update/typescript/base-types.ts +22 -0
- package/schematics/schematics/ng-update/typescript/imports.ts +54 -0
- package/schematics/schematics/ng-update/typescript/literal.ts +32 -0
- package/schematics/schematics/ng-update/typescript/module-specifiers.ts +39 -0
- package/schematics/schematics/ng-update/update-schematic.md +209 -0
- package/schematics/schematics/ng-update/upgrade-data.ts +79 -0
- package/schematics/schematics/paths.ts +15 -0
- package/schematics/schematics/testing/BUILD.bazel +27 -0
- package/schematics/schematics/testing/file-content.ts +20 -0
- package/schematics/schematics/testing/index.ts +14 -0
- package/schematics/schematics/testing/post-scheduled-tasks.ts +45 -0
- package/schematics/schematics/testing/resolve-bazel-path.ts +46 -0
- package/schematics/schematics/testing/test-app.ts +21 -0
- package/schematics/schematics/testing/test-case-setup.ts +236 -0
- package/schematics/schematics/testing/test-library.ts +21 -0
- package/schematics/schematics/testing/test-project.ts +40 -0
- package/schematics/schematics/testing/tsconfig.json +7 -0
- package/schematics/schematics/tsconfig.json +28 -0
- package/schematics/schematics/update-tool/BUILD.bazel +19 -0
- package/schematics/schematics/update-tool/component-resource-collector.ts +195 -0
- package/schematics/schematics/update-tool/file-system.ts +78 -0
- package/schematics/schematics/update-tool/index.ts +191 -0
- package/schematics/schematics/update-tool/logger.ts +23 -0
- package/schematics/schematics/update-tool/migration.ts +88 -0
- package/schematics/schematics/update-tool/public-api.ts +16 -0
- package/schematics/schematics/update-tool/target-version.ts +31 -0
- package/schematics/schematics/update-tool/tsconfig.json +7 -0
- package/schematics/schematics/update-tool/update-recorder.ts +14 -0
- package/schematics/schematics/update-tool/utils/decorators.ts +54 -0
- package/schematics/schematics/update-tool/utils/functions.ts +18 -0
- package/schematics/schematics/update-tool/utils/imports.ts +128 -0
- package/schematics/schematics/update-tool/utils/line-mappings.ts +84 -0
- package/schematics/schematics/update-tool/utils/parse-tsconfig.ts +25 -0
- package/schematics/schematics/update-tool/utils/property-name.ts +28 -0
- package/schematics/schematics/update-tool/utils/virtual-host.ts +116 -0
- package/schematics/schematics/update-tool/version-changes.ts +49 -0
- package/schematics/schematics/utils/ast/ng-module-imports.spec.ts +43 -0
- package/schematics/schematics/utils/ast/ng-module-imports.ts +102 -0
- package/schematics/schematics/utils/ast.ts +88 -0
- package/schematics/schematics/utils/build-component.ts +252 -0
- package/schematics/schematics/utils/get-project.ts +27 -0
- package/schematics/schematics/utils/html-manipulation.ts +105 -0
- package/schematics/schematics/utils/index.ts +19 -0
- package/schematics/schematics/utils/parse5-element.ts +34 -0
- package/schematics/schematics/utils/project-index-file.ts +21 -0
- package/schematics/schematics/utils/project-main-file.ts +26 -0
- package/schematics/schematics/utils/project-style-file.ts +53 -0
- package/schematics/schematics/utils/project-targets.ts +43 -0
- package/schematics/schematics/utils/project-tsconfig-paths.spec.ts +91 -0
- package/schematics/schematics/utils/project-tsconfig-paths.ts +49 -0
- package/schematics/schematics/utils/schematic-options.ts +65 -0
- package/schematics/schematics/utils/vendored-ast-utils/index.ts +599 -0
- package/scrolling/virtual-scroll-viewport.scss +87 -0
- package/table/table.scss +3 -0
- package/text-field/_index.import.scss +2 -0
- package/text-field/_index.scss +89 -0
- package/text-field/text-field-prebuilt.scss +4 -0
- package/types/stagefright5-cdk-a11y.d.ts +1160 -0
- package/types/stagefright5-cdk-accordion.d.ts +95 -0
- package/types/stagefright5-cdk-bidi.d.ts +95 -0
- package/types/stagefright5-cdk-clipboard.d.ts +116 -0
- package/types/stagefright5-cdk-coercion.d.ts +101 -0
- package/types/stagefright5-cdk-collections.d.ts +405 -0
- package/types/stagefright5-cdk-drag-drop.d.ts +1471 -0
- package/types/stagefright5-cdk-keycodes.d.ts +142 -0
- package/types/stagefright5-cdk-layout.d.ts +96 -0
- package/types/stagefright5-cdk-observers.d.ts +91 -0
- package/types/stagefright5-cdk-overlay.d.ts +1258 -0
- package/types/stagefright5-cdk-platform.d.ts +130 -0
- package/types/stagefright5-cdk-portal.d.ts +327 -0
- package/types/stagefright5-cdk-scrolling.d.ts +631 -0
- package/types/stagefright5-cdk-stepper.d.ts +302 -0
- package/types/stagefright5-cdk-table.d.ts +1128 -0
- package/types/stagefright5-cdk-testing-protractor.d.ts +146 -0
- package/types/stagefright5-cdk-testing-selenium-webdriver.d.ts +161 -0
- package/types/stagefright5-cdk-testing-testbed.d.ts +168 -0
- package/types/stagefright5-cdk-testing.d.ts +735 -0
- package/types/stagefright5-cdk-text-field.d.ts +171 -0
- package/types/stagefright5-cdk-tree.d.ts +522 -0
- package/types/stagefright5-cdk.d.ts +14 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {Rule, SchematicContext} from '@angular-devkit/schematics';
|
|
10
|
+
import {TargetVersion} from '../update-tool/target-version';
|
|
11
|
+
import {cdkUpgradeData} from './upgrade-data';
|
|
12
|
+
import {createMigrationSchematicRule, NullableDevkitMigration} from './devkit-migration-rule';
|
|
13
|
+
import {TildeImportMigration} from './migrations/tilde-import-v13/tilde-import-migration';
|
|
14
|
+
|
|
15
|
+
const cdkMigrations: NullableDevkitMigration[] = [TildeImportMigration];
|
|
16
|
+
|
|
17
|
+
/** Entry point for the migration schematics with target of Angular CDK 6.0.0 */
|
|
18
|
+
export function updateToV6(): Rule {
|
|
19
|
+
return createMigrationSchematicRule(
|
|
20
|
+
TargetVersion.V6,
|
|
21
|
+
cdkMigrations,
|
|
22
|
+
cdkUpgradeData,
|
|
23
|
+
onMigrationComplete,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Entry point for the migration schematics with target of Angular CDK 7.0.0 */
|
|
28
|
+
export function updateToV7(): Rule {
|
|
29
|
+
return createMigrationSchematicRule(
|
|
30
|
+
TargetVersion.V7,
|
|
31
|
+
cdkMigrations,
|
|
32
|
+
cdkUpgradeData,
|
|
33
|
+
onMigrationComplete,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Entry point for the migration schematics with target of Angular CDK 8.0.0 */
|
|
38
|
+
export function updateToV8(): Rule {
|
|
39
|
+
return createMigrationSchematicRule(
|
|
40
|
+
TargetVersion.V8,
|
|
41
|
+
cdkMigrations,
|
|
42
|
+
cdkUpgradeData,
|
|
43
|
+
onMigrationComplete,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Entry point for the migration schematics with target of Angular CDK 9.0.0 */
|
|
48
|
+
export function updateToV9(): Rule {
|
|
49
|
+
return createMigrationSchematicRule(
|
|
50
|
+
TargetVersion.V9,
|
|
51
|
+
cdkMigrations,
|
|
52
|
+
cdkUpgradeData,
|
|
53
|
+
onMigrationComplete,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Entry point for the migration schematics with target of Angular CDK 10.0.0 */
|
|
58
|
+
export function updateToV10(): Rule {
|
|
59
|
+
return createMigrationSchematicRule(
|
|
60
|
+
TargetVersion.V10,
|
|
61
|
+
cdkMigrations,
|
|
62
|
+
cdkUpgradeData,
|
|
63
|
+
onMigrationComplete,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Entry point for the migration schematics with target of Angular CDK 11.0.0 */
|
|
68
|
+
export function updateToV11(): Rule {
|
|
69
|
+
return createMigrationSchematicRule(
|
|
70
|
+
TargetVersion.V11,
|
|
71
|
+
cdkMigrations,
|
|
72
|
+
cdkUpgradeData,
|
|
73
|
+
onMigrationComplete,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Entry point for the migration schematics with target of Angular CDK 12.0.0 */
|
|
78
|
+
export function updateToV12(): Rule {
|
|
79
|
+
return createMigrationSchematicRule(
|
|
80
|
+
TargetVersion.V12,
|
|
81
|
+
cdkMigrations,
|
|
82
|
+
cdkUpgradeData,
|
|
83
|
+
onMigrationComplete,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Entry point for the migration schematics with target of Angular CDK 13.0.0 */
|
|
88
|
+
export function updateToV13(): Rule {
|
|
89
|
+
return createMigrationSchematicRule(
|
|
90
|
+
TargetVersion.V13,
|
|
91
|
+
cdkMigrations,
|
|
92
|
+
cdkUpgradeData,
|
|
93
|
+
onMigrationComplete,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Function that will be called when the migration completed. */
|
|
98
|
+
function onMigrationComplete(
|
|
99
|
+
context: SchematicContext,
|
|
100
|
+
targetVersion: TargetVersion,
|
|
101
|
+
hasFailures: boolean,
|
|
102
|
+
) {
|
|
103
|
+
context.logger.info('');
|
|
104
|
+
context.logger.info(` ✓ Updated Angular CDK to ${targetVersion}`);
|
|
105
|
+
context.logger.info('');
|
|
106
|
+
|
|
107
|
+
if (hasFailures) {
|
|
108
|
+
context.logger.warn(
|
|
109
|
+
' ⚠ Some issues were detected but could not be fixed automatically. Please check the ' +
|
|
110
|
+
'output above and fix these issues manually.',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {WorkspacePath} from '../../update-tool/file-system';
|
|
11
|
+
import {ResolvedResource} from '../../update-tool/component-resource-collector';
|
|
12
|
+
import {Migration} from '../../update-tool/migration';
|
|
13
|
+
import {AttributeSelectorUpgradeData} from '../data/attribute-selectors';
|
|
14
|
+
import {findAllSubstringIndices} from '../typescript/literal';
|
|
15
|
+
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Migration that walks through every string literal, template and stylesheet
|
|
19
|
+
* in order to switch deprecated attribute selectors to the updated selector.
|
|
20
|
+
*/
|
|
21
|
+
export class AttributeSelectorsMigration extends Migration<UpgradeData> {
|
|
22
|
+
/** Required upgrade changes for specified target version. */
|
|
23
|
+
data = getVersionUpgradeData(this, 'attributeSelectors');
|
|
24
|
+
|
|
25
|
+
// Only enable the migration rule if there is upgrade data.
|
|
26
|
+
enabled: boolean = this.data.length !== 0;
|
|
27
|
+
|
|
28
|
+
override visitNode(node: ts.Node) {
|
|
29
|
+
if (ts.isStringLiteralLike(node)) {
|
|
30
|
+
this._visitStringLiteralLike(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override visitTemplate(template: ResolvedResource) {
|
|
35
|
+
this.data.forEach(selector => {
|
|
36
|
+
findAllSubstringIndices(template.content, selector.replace)
|
|
37
|
+
.map(offset => template.start + offset)
|
|
38
|
+
.forEach(start => this._replaceSelector(template.filePath, start, selector));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override visitStylesheet(stylesheet: ResolvedResource): void {
|
|
43
|
+
this.data.forEach(selector => {
|
|
44
|
+
const currentSelector = `[${selector.replace}]`;
|
|
45
|
+
const updatedSelector = `[${selector.replaceWith}]`;
|
|
46
|
+
|
|
47
|
+
findAllSubstringIndices(stylesheet.content, currentSelector)
|
|
48
|
+
.map(offset => stylesheet.start + offset)
|
|
49
|
+
.forEach(start =>
|
|
50
|
+
this._replaceSelector(stylesheet.filePath, start, {
|
|
51
|
+
replace: currentSelector,
|
|
52
|
+
replaceWith: updatedSelector,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _visitStringLiteralLike(literal: ts.StringLiteralLike) {
|
|
59
|
+
if (literal.parent && literal.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const literalText = literal.getText();
|
|
64
|
+
const filePath = this.fileSystem.resolve(literal.getSourceFile().fileName);
|
|
65
|
+
|
|
66
|
+
this.data.forEach(selector => {
|
|
67
|
+
findAllSubstringIndices(literalText, selector.replace)
|
|
68
|
+
.map(offset => literal.getStart() + offset)
|
|
69
|
+
.forEach(start => this._replaceSelector(filePath, start, selector));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private _replaceSelector(
|
|
74
|
+
filePath: WorkspacePath,
|
|
75
|
+
start: number,
|
|
76
|
+
data: AttributeSelectorUpgradeData,
|
|
77
|
+
) {
|
|
78
|
+
this.fileSystem
|
|
79
|
+
.edit(filePath)
|
|
80
|
+
.remove(start, data.replace.length)
|
|
81
|
+
.insertRight(start, data.replaceWith);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {Migration} from '../../update-tool/migration';
|
|
11
|
+
import {PropertyNameUpgradeData} from '../data/property-names';
|
|
12
|
+
import {determineBaseTypes} from '../typescript/base-types';
|
|
13
|
+
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Migration that identifies class declarations that extend CDK or Material classes
|
|
17
|
+
* which had a public property change.
|
|
18
|
+
*/
|
|
19
|
+
export class ClassInheritanceMigration extends Migration<UpgradeData> {
|
|
20
|
+
/**
|
|
21
|
+
* Map of classes that have been updated. Each class name maps to the according property
|
|
22
|
+
* change data.
|
|
23
|
+
*/
|
|
24
|
+
propertyNames = new Map<string, PropertyNameUpgradeData>();
|
|
25
|
+
|
|
26
|
+
// Only enable the migration rule if there is upgrade data.
|
|
27
|
+
enabled = this.propertyNames.size !== 0;
|
|
28
|
+
|
|
29
|
+
override init(): void {
|
|
30
|
+
getVersionUpgradeData(this, 'propertyNames')
|
|
31
|
+
.filter(data => data.limitedTo && data.limitedTo.classes)
|
|
32
|
+
.forEach(data => data.limitedTo.classes.forEach(name => this.propertyNames.set(name, data)));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override visitNode(node: ts.Node): void {
|
|
36
|
+
if (ts.isClassDeclaration(node)) {
|
|
37
|
+
this._visitClassDeclaration(node);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private _visitClassDeclaration(node: ts.ClassDeclaration) {
|
|
42
|
+
const baseTypes = determineBaseTypes(node);
|
|
43
|
+
const className = node.name ? node.name.text : '{unknown-name}';
|
|
44
|
+
|
|
45
|
+
if (!baseTypes) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
baseTypes.forEach(typeName => {
|
|
50
|
+
const data = this.propertyNames.get(typeName);
|
|
51
|
+
|
|
52
|
+
if (data) {
|
|
53
|
+
this.createFailureAtNode(
|
|
54
|
+
node,
|
|
55
|
+
`Found class "${className}" which extends class ` +
|
|
56
|
+
`"${typeName}". Please note that the base class property ` +
|
|
57
|
+
`"${data.replace}" has changed to "${data.replaceWith}". ` +
|
|
58
|
+
`You may need to update your class as well.`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {Migration} from '../../update-tool/migration';
|
|
11
|
+
|
|
12
|
+
import {ClassNameUpgradeData} from '../data';
|
|
13
|
+
import {
|
|
14
|
+
isExportSpecifierNode,
|
|
15
|
+
isImportSpecifierNode,
|
|
16
|
+
isNamespaceImportNode,
|
|
17
|
+
} from '../typescript/imports';
|
|
18
|
+
import {
|
|
19
|
+
isMaterialExportDeclaration,
|
|
20
|
+
isMaterialImportDeclaration,
|
|
21
|
+
} from '../typescript/module-specifiers';
|
|
22
|
+
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Migration that walks through every identifier that is part of Angular Material or thr CDK
|
|
26
|
+
* and replaces the outdated name with the new one if specified in the upgrade data.
|
|
27
|
+
*/
|
|
28
|
+
// TODO: rework this rule to identify symbols using the import identifier resolver. This
|
|
29
|
+
// makes it more robust, less AST convoluted and is more TypeScript AST idiomatic. COMP-300.
|
|
30
|
+
export class ClassNamesMigration extends Migration<UpgradeData> {
|
|
31
|
+
/** Change data that upgrades to the specified target version. */
|
|
32
|
+
data: ClassNameUpgradeData[] = getVersionUpgradeData(this, 'classNames');
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* List of identifier names that have been imported from `@dugararchit/material` or `@dugararchit/cdk`
|
|
36
|
+
* in the current source file and therefore can be considered trusted.
|
|
37
|
+
*/
|
|
38
|
+
trustedIdentifiers: Set<string> = new Set();
|
|
39
|
+
|
|
40
|
+
/** List of namespaces that have been imported from `@dugararchit/material` or `@dugararchit/cdk`. */
|
|
41
|
+
trustedNamespaces: Set<string> = new Set();
|
|
42
|
+
|
|
43
|
+
// Only enable the migration rule if there is upgrade data.
|
|
44
|
+
enabled = this.data.length !== 0;
|
|
45
|
+
|
|
46
|
+
override visitNode(node: ts.Node): void {
|
|
47
|
+
if (ts.isIdentifier(node)) {
|
|
48
|
+
this._visitIdentifier(node);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Method that is called for every identifier inside of the specified project. */
|
|
53
|
+
private _visitIdentifier(identifier: ts.Identifier) {
|
|
54
|
+
// For identifiers that aren't listed in the className data, the whole check can be
|
|
55
|
+
// skipped safely.
|
|
56
|
+
if (!this.data.some(data => data.replace === identifier.text)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// For namespace imports that are referring to Angular Material or the CDK, we store the
|
|
61
|
+
// namespace name in order to be able to safely find identifiers that don't belong to the
|
|
62
|
+
// developer's application.
|
|
63
|
+
if (isNamespaceImportNode(identifier) && isMaterialImportDeclaration(identifier)) {
|
|
64
|
+
this.trustedNamespaces.add(identifier.text);
|
|
65
|
+
|
|
66
|
+
return this._createFailureWithReplacement(identifier);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// For export declarations that are referring to Angular Material or the CDK, the identifier
|
|
70
|
+
// can be immediately updated to the new name.
|
|
71
|
+
if (isExportSpecifierNode(identifier) && isMaterialExportDeclaration(identifier)) {
|
|
72
|
+
return this._createFailureWithReplacement(identifier);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// For import declarations that are referring to Angular Material or the CDK, the name of
|
|
76
|
+
// the import identifiers. This allows us to identify identifiers that belong to Material and
|
|
77
|
+
// the CDK, and we won't accidentally touch a developer's identifier.
|
|
78
|
+
if (isImportSpecifierNode(identifier) && isMaterialImportDeclaration(identifier)) {
|
|
79
|
+
this.trustedIdentifiers.add(identifier.text);
|
|
80
|
+
|
|
81
|
+
return this._createFailureWithReplacement(identifier);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// In case the identifier is part of a property access expression, we need to verify that the
|
|
85
|
+
// property access originates from a namespace that has been imported from Material or the CDK.
|
|
86
|
+
if (ts.isPropertyAccessExpression(identifier.parent)) {
|
|
87
|
+
const expression = identifier.parent.expression;
|
|
88
|
+
|
|
89
|
+
if (ts.isIdentifier(expression) && this.trustedNamespaces.has(expression.text)) {
|
|
90
|
+
return this._createFailureWithReplacement(identifier);
|
|
91
|
+
}
|
|
92
|
+
} else if (this.trustedIdentifiers.has(identifier.text)) {
|
|
93
|
+
return this._createFailureWithReplacement(identifier);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Creates a failure and replacement for the specified identifier. */
|
|
98
|
+
private _createFailureWithReplacement(identifier: ts.Identifier) {
|
|
99
|
+
const classData = this.data.find(data => data.replace === identifier.text)!;
|
|
100
|
+
const filePath = this.fileSystem.resolve(identifier.getSourceFile().fileName);
|
|
101
|
+
|
|
102
|
+
this.fileSystem
|
|
103
|
+
.edit(filePath)
|
|
104
|
+
.remove(identifier.getStart(), identifier.getWidth())
|
|
105
|
+
.insertRight(identifier.getStart(), classData.replaceWith);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {Migration} from '../../update-tool/migration';
|
|
11
|
+
import {getAllChanges} from '../../update-tool/version-changes';
|
|
12
|
+
import {UpgradeData} from '../upgrade-data';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* List of diagnostic codes that refer to pre-emit diagnostics which indicate invalid
|
|
16
|
+
* new expression or super call signatures. See the list of diagnostics here:
|
|
17
|
+
*
|
|
18
|
+
* https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
|
|
19
|
+
*/
|
|
20
|
+
const signatureErrorDiagnostics = [
|
|
21
|
+
// Type not assignable error diagnostic.
|
|
22
|
+
2345,
|
|
23
|
+
// Constructor argument length invalid diagnostics
|
|
24
|
+
2554, 2555, 2556, 2557,
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Migration that visits every TypeScript new expression or super call and checks if
|
|
29
|
+
* the parameter type signature is invalid and needs to be updated manually.
|
|
30
|
+
*/
|
|
31
|
+
export class ConstructorSignatureMigration extends Migration<UpgradeData> {
|
|
32
|
+
// Note that the data for this rule is not distinguished based on the target version because
|
|
33
|
+
// we don't keep track of the new signature and don't want to update incrementally.
|
|
34
|
+
// See: https://github.com/angular/components/pull/12970#issuecomment-418337566
|
|
35
|
+
data = getAllChanges(this.upgradeData.constructorChecks);
|
|
36
|
+
|
|
37
|
+
// Only enable the migration rule if there is upgrade data.
|
|
38
|
+
enabled = this.data.length !== 0;
|
|
39
|
+
|
|
40
|
+
override visitNode(node: ts.Node): void {
|
|
41
|
+
if (ts.isSourceFile(node)) {
|
|
42
|
+
this._visitSourceFile(node);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Method that will be called for each source file of the upgrade project. In order to
|
|
48
|
+
* properly determine invalid constructor signatures, we take advantage of the pre-emit
|
|
49
|
+
* diagnostics from TypeScript.
|
|
50
|
+
*
|
|
51
|
+
* By using the diagnostics, the migration can handle type assignability. Not using
|
|
52
|
+
* diagnostics would mean that we need to use simple type equality checking which is
|
|
53
|
+
* too strict. See related issue: https://github.com/Microsoft/TypeScript/issues/9879
|
|
54
|
+
*/
|
|
55
|
+
private _visitSourceFile(sourceFile: ts.SourceFile) {
|
|
56
|
+
// List of classes of which the constructor signature has changed.
|
|
57
|
+
const diagnostics = ts
|
|
58
|
+
.getPreEmitDiagnostics(this.program, sourceFile)
|
|
59
|
+
.filter(diagnostic => signatureErrorDiagnostics.includes(diagnostic.code))
|
|
60
|
+
.filter(diagnostic => diagnostic.start !== undefined);
|
|
61
|
+
|
|
62
|
+
for (const diagnostic of diagnostics) {
|
|
63
|
+
const node = findConstructorNode(diagnostic, sourceFile);
|
|
64
|
+
|
|
65
|
+
if (!node) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const classType = this.typeChecker.getTypeAtLocation(node.expression);
|
|
70
|
+
const className = classType.symbol && classType.symbol.name;
|
|
71
|
+
const isNewExpression = ts.isNewExpression(node);
|
|
72
|
+
|
|
73
|
+
// Determine the class names of the actual construct signatures because we cannot assume that
|
|
74
|
+
// the diagnostic refers to a constructor of the actual expression. In case the constructor
|
|
75
|
+
// is inherited, we need to detect that the owner-class of the constructor is added to the
|
|
76
|
+
// constructor checks upgrade data. e.g. `class CustomCalendar extends MatCalendar {}`.
|
|
77
|
+
const signatureClassNames = classType
|
|
78
|
+
.getConstructSignatures()
|
|
79
|
+
.map(signature => getClassDeclarationOfSignature(signature))
|
|
80
|
+
.map(declaration => (declaration && declaration.name ? declaration.name.text : null))
|
|
81
|
+
.filter(Boolean);
|
|
82
|
+
|
|
83
|
+
// Besides checking the signature class names, we need to check the actual class name because
|
|
84
|
+
// there can be classes without an explicit constructor.
|
|
85
|
+
if (
|
|
86
|
+
!this.data.includes(className) &&
|
|
87
|
+
!signatureClassNames.some(name => this.data.includes(name!))
|
|
88
|
+
) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const classSignatures = classType
|
|
93
|
+
.getConstructSignatures()
|
|
94
|
+
.map(signature => getParameterTypesFromSignature(signature, this.typeChecker));
|
|
95
|
+
|
|
96
|
+
const expressionName = isNewExpression ? `new ${className}` : 'super';
|
|
97
|
+
const signatures = classSignatures
|
|
98
|
+
.map(signature =>
|
|
99
|
+
signature.map(t => (t === null ? 'any' : this.typeChecker.typeToString(t))),
|
|
100
|
+
)
|
|
101
|
+
.map(signature => `${expressionName}(${signature.join(', ')})`)
|
|
102
|
+
.join(' or ');
|
|
103
|
+
|
|
104
|
+
this.createFailureAtNode(
|
|
105
|
+
node,
|
|
106
|
+
`Found "${className}" constructed with ` +
|
|
107
|
+
`an invalid signature. Please manually update the ${expressionName} expression to ` +
|
|
108
|
+
`match the new signature${classSignatures.length > 1 ? 's' : ''}: ${signatures}`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Resolves the type for each parameter in the specified signature. */
|
|
115
|
+
function getParameterTypesFromSignature(
|
|
116
|
+
signature: ts.Signature,
|
|
117
|
+
typeChecker: ts.TypeChecker,
|
|
118
|
+
): (ts.Type | null)[] {
|
|
119
|
+
return signature
|
|
120
|
+
.getParameters()
|
|
121
|
+
.map(param =>
|
|
122
|
+
param.declarations ? typeChecker.getTypeAtLocation(param.declarations[0]) : null,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Walks through each node of a source file in order to find a new-expression node or super-call
|
|
128
|
+
* expression node that is captured by the specified diagnostic.
|
|
129
|
+
*/
|
|
130
|
+
function findConstructorNode(
|
|
131
|
+
diagnostic: ts.Diagnostic,
|
|
132
|
+
sourceFile: ts.SourceFile,
|
|
133
|
+
): ts.CallExpression | ts.NewExpression | null {
|
|
134
|
+
let resolvedNode: ts.Node | null = null;
|
|
135
|
+
|
|
136
|
+
const _visitNode = (node: ts.Node) => {
|
|
137
|
+
// Check whether the current node contains the diagnostic. If the node contains the diagnostic,
|
|
138
|
+
// walk deeper in order to find all constructor expression nodes.
|
|
139
|
+
if (node.getStart() <= diagnostic.start! && node.getEnd() >= diagnostic.start!) {
|
|
140
|
+
if (
|
|
141
|
+
ts.isNewExpression(node) ||
|
|
142
|
+
(ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.SuperKeyword)
|
|
143
|
+
) {
|
|
144
|
+
resolvedNode = node;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
ts.forEachChild(node, _visitNode);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
ts.forEachChild(sourceFile, _visitNode);
|
|
152
|
+
|
|
153
|
+
return resolvedNode;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Determines the class declaration of the specified construct signature. */
|
|
157
|
+
function getClassDeclarationOfSignature(signature: ts.Signature): ts.ClassDeclaration | null {
|
|
158
|
+
let node: ts.Node = signature.getDeclaration();
|
|
159
|
+
// Handle signatures which don't have an actual declaration. This happens if a class
|
|
160
|
+
// does not have an explicitly written constructor.
|
|
161
|
+
if (!node) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
while (!ts.isSourceFile((node = node.parent))) {
|
|
165
|
+
if (ts.isClassDeclaration(node)) {
|
|
166
|
+
return node;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {WorkspacePath} from '../../update-tool/file-system';
|
|
11
|
+
import {ResolvedResource} from '../../update-tool/component-resource-collector';
|
|
12
|
+
import {Migration} from '../../update-tool/migration';
|
|
13
|
+
import {CssSelectorUpgradeData} from '../data/css-selectors';
|
|
14
|
+
import {findAllSubstringIndices} from '../typescript/literal';
|
|
15
|
+
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Migration that walks through every string literal, template and stylesheet in
|
|
19
|
+
* order to migrate outdated CSS selectors to the new selector.
|
|
20
|
+
*/
|
|
21
|
+
export class CssSelectorsMigration extends Migration<UpgradeData> {
|
|
22
|
+
/** Change data that upgrades to the specified target version. */
|
|
23
|
+
data: CssSelectorUpgradeData[] = getVersionUpgradeData(this, 'cssSelectors');
|
|
24
|
+
|
|
25
|
+
// Only enable the migration rule if there is upgrade data.
|
|
26
|
+
enabled = this.data.length !== 0;
|
|
27
|
+
|
|
28
|
+
override visitNode(node: ts.Node): void {
|
|
29
|
+
if (ts.isStringLiteralLike(node)) {
|
|
30
|
+
this._visitStringLiteralLike(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override visitTemplate(template: ResolvedResource): void {
|
|
35
|
+
this.data.forEach(data => {
|
|
36
|
+
if (data.replaceIn && !data.replaceIn.html) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
findAllSubstringIndices(template.content, data.replace)
|
|
41
|
+
.map(offset => template.start + offset)
|
|
42
|
+
.forEach(start => this._replaceSelector(template.filePath, start, data));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override visitStylesheet(stylesheet: ResolvedResource): void {
|
|
47
|
+
this.data.forEach(data => {
|
|
48
|
+
if (data.replaceIn && !data.replaceIn.stylesheet) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
findAllSubstringIndices(stylesheet.content, data.replace)
|
|
53
|
+
.map(offset => stylesheet.start + offset)
|
|
54
|
+
.forEach(start => this._replaceSelector(stylesheet.filePath, start, data));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _visitStringLiteralLike(node: ts.StringLiteralLike) {
|
|
59
|
+
if (node.parent && node.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const textContent = node.getText();
|
|
64
|
+
const filePath = this.fileSystem.resolve(node.getSourceFile().fileName);
|
|
65
|
+
|
|
66
|
+
this.data.forEach(data => {
|
|
67
|
+
if (data.replaceIn && !data.replaceIn.tsStringLiterals) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
findAllSubstringIndices(textContent, data.replace)
|
|
72
|
+
.map(offset => node.getStart() + offset)
|
|
73
|
+
.forEach(start => this._replaceSelector(filePath, start, data));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private _replaceSelector(filePath: WorkspacePath, start: number, data: CssSelectorUpgradeData) {
|
|
78
|
+
this.fileSystem
|
|
79
|
+
.edit(filePath)
|
|
80
|
+
.remove(start, data.replace.length)
|
|
81
|
+
.insertRight(start, data.replaceWith);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
import {ResolvedResource} from '../../update-tool/component-resource-collector';
|
|
11
|
+
import {WorkspacePath} from '../../update-tool/file-system';
|
|
12
|
+
import {Migration} from '../../update-tool/migration';
|
|
13
|
+
import {ElementSelectorUpgradeData} from '../data/element-selectors';
|
|
14
|
+
import {findAllSubstringIndices} from '../typescript/literal';
|
|
15
|
+
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Migration that walks through every string literal, template and stylesheet in order
|
|
19
|
+
* to migrate outdated element selectors to the new one.
|
|
20
|
+
*/
|
|
21
|
+
export class ElementSelectorsMigration extends Migration<UpgradeData> {
|
|
22
|
+
/** Change data that upgrades to the specified target version. */
|
|
23
|
+
data = getVersionUpgradeData(this, 'elementSelectors');
|
|
24
|
+
|
|
25
|
+
// Only enable the migration rule if there is upgrade data.
|
|
26
|
+
enabled: boolean = this.data.length !== 0;
|
|
27
|
+
|
|
28
|
+
override visitNode(node: ts.Node): void {
|
|
29
|
+
if (ts.isStringLiteralLike(node)) {
|
|
30
|
+
this._visitStringLiteralLike(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override visitTemplate(template: ResolvedResource): void {
|
|
35
|
+
this.data.forEach(selector => {
|
|
36
|
+
findAllSubstringIndices(template.content, selector.replace)
|
|
37
|
+
.map(offset => template.start + offset)
|
|
38
|
+
.forEach(start => this._replaceSelector(template.filePath, start, selector));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override visitStylesheet(stylesheet: ResolvedResource): void {
|
|
43
|
+
this.data.forEach(selector => {
|
|
44
|
+
findAllSubstringIndices(stylesheet.content, selector.replace)
|
|
45
|
+
.map(offset => stylesheet.start + offset)
|
|
46
|
+
.forEach(start => this._replaceSelector(stylesheet.filePath, start, selector));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private _visitStringLiteralLike(node: ts.StringLiteralLike) {
|
|
51
|
+
if (node.parent && node.parent.kind !== ts.SyntaxKind.CallExpression) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const textContent = node.getText();
|
|
56
|
+
const filePath = this.fileSystem.resolve(node.getSourceFile().fileName);
|
|
57
|
+
|
|
58
|
+
this.data.forEach(selector => {
|
|
59
|
+
findAllSubstringIndices(textContent, selector.replace)
|
|
60
|
+
.map(offset => node.getStart() + offset)
|
|
61
|
+
.forEach(start => this._replaceSelector(filePath, start, selector));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private _replaceSelector(
|
|
66
|
+
filePath: WorkspacePath,
|
|
67
|
+
start: number,
|
|
68
|
+
data: ElementSelectorUpgradeData,
|
|
69
|
+
) {
|
|
70
|
+
this.fileSystem
|
|
71
|
+
.edit(filePath)
|
|
72
|
+
.remove(start, data.replace.length)
|
|
73
|
+
.insertRight(start, data.replaceWith);
|
|
74
|
+
}
|
|
75
|
+
}
|