1 | (function (factory) {
|
---|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
---|
3 | var v = factory(require, exports);
|
---|
4 | if (v !== undefined) module.exports = v;
|
---|
5 | }
|
---|
6 | else if (typeof define === "function" && define.amd) {
|
---|
7 | define("@angular/core/schematics/migrations/initial-navigation/transform", ["require", "exports", "typescript"], factory);
|
---|
8 | }
|
---|
9 | })(function (require, exports) {
|
---|
10 | "use strict";
|
---|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
12 | exports.InitialNavigationTransform = void 0;
|
---|
13 | /**
|
---|
14 | * @license
|
---|
15 | * Copyright Google LLC All Rights Reserved.
|
---|
16 | *
|
---|
17 | * Use of this source code is governed by an MIT-style license that can be
|
---|
18 | * found in the LICENSE file at https://angular.io/license
|
---|
19 | */
|
---|
20 | const ts = require("typescript");
|
---|
21 | class InitialNavigationTransform {
|
---|
22 | constructor(getUpdateRecorder) {
|
---|
23 | this.getUpdateRecorder = getUpdateRecorder;
|
---|
24 | this.printer = ts.createPrinter();
|
---|
25 | }
|
---|
26 | /** Migrate the ExtraOptions#InitialNavigation property assignments. */
|
---|
27 | migrateInitialNavigationAssignments(literals) {
|
---|
28 | literals.forEach(l => this.migrateAssignment(l));
|
---|
29 | }
|
---|
30 | /** Migrate an ExtraOptions#InitialNavigation expression to use the new options format. */
|
---|
31 | migrateAssignment(assignment) {
|
---|
32 | const newInitializer = getUpdatedInitialNavigationValue(assignment.initializer);
|
---|
33 | if (newInitializer) {
|
---|
34 | const newAssignment = ts.updatePropertyAssignment(assignment, assignment.name, newInitializer);
|
---|
35 | this._updateNode(assignment, newAssignment);
|
---|
36 | }
|
---|
37 | }
|
---|
38 | _updateNode(node, newNode) {
|
---|
39 | const newText = this.printer.printNode(ts.EmitHint.Unspecified, newNode, node.getSourceFile());
|
---|
40 | const recorder = this.getUpdateRecorder(node.getSourceFile());
|
---|
41 | recorder.updateNode(node, newText);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | exports.InitialNavigationTransform = InitialNavigationTransform;
|
---|
45 | /**
|
---|
46 | * Updates the deprecated initialNavigation options to their v10 equivalents
|
---|
47 | * (or as close as we can get).
|
---|
48 | * @param initializer the old initializer to update
|
---|
49 | */
|
---|
50 | function getUpdatedInitialNavigationValue(initializer) {
|
---|
51 | const oldText = ts.isStringLiteralLike(initializer) ?
|
---|
52 | initializer.text :
|
---|
53 | initializer.kind === ts.SyntaxKind.TrueKeyword;
|
---|
54 | let newText;
|
---|
55 | switch (oldText) {
|
---|
56 | case false:
|
---|
57 | case 'legacy_disabled':
|
---|
58 | newText = 'disabled';
|
---|
59 | break;
|
---|
60 | case true:
|
---|
61 | case 'legacy_enabled':
|
---|
62 | newText = 'enabledNonBlocking';
|
---|
63 | break;
|
---|
64 | }
|
---|
65 | return !!newText ? ts.createIdentifier(`'${newText}'`) : null;
|
---|
66 | }
|
---|
67 | });
|
---|
68 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHJhbnNmb3JtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29yZS9zY2hlbWF0aWNzL21pZ3JhdGlvbnMvaW5pdGlhbC1uYXZpZ2F0aW9uL3RyYW5zZm9ybS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7SUFBQTs7Ozs7O09BTUc7SUFDSCxpQ0FBaUM7SUFLakMsTUFBYSwwQkFBMEI7UUFHckMsWUFBb0IsaUJBQXdEO1lBQXhELHNCQUFpQixHQUFqQixpQkFBaUIsQ0FBdUM7WUFGcEUsWUFBTyxHQUFHLEVBQUUsQ0FBQyxhQUFhLEVBQUUsQ0FBQztRQUUwQyxDQUFDO1FBRWhGLHVFQUF1RTtRQUN2RSxtQ0FBbUMsQ0FBQyxRQUFpQztZQUNuRSxRQUFRLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxF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