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/move-document/move-import", ["require", "exports", "typescript"], factory);
|
---|
8 | }
|
---|
9 | })(function (require, exports) {
|
---|
10 | "use strict";
|
---|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
12 | exports.createImport = exports.addToImport = exports.removeFromImport = 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 | function removeFromImport(importNode, sourceFile, importName) {
|
---|
22 | const printer = ts.createPrinter();
|
---|
23 | const elements = importNode.elements.filter(el => String((el.propertyName || el.name).escapedText) !== importName);
|
---|
24 | if (!elements.length) {
|
---|
25 | return '';
|
---|
26 | }
|
---|
27 | const oldDeclaration = importNode.parent.parent;
|
---|
28 | const newImport = ts.createNamedImports(elements);
|
---|
29 | const importClause = ts.createImportClause(undefined, newImport);
|
---|
30 | const newDeclaration = ts.createImportDeclaration(undefined, undefined, importClause, oldDeclaration.moduleSpecifier);
|
---|
31 | return printer.printNode(ts.EmitHint.Unspecified, newDeclaration, sourceFile);
|
---|
32 | }
|
---|
33 | exports.removeFromImport = removeFromImport;
|
---|
34 | function addToImport(importNode, sourceFile, name, propertyName) {
|
---|
35 | const printer = ts.createPrinter();
|
---|
36 | const propertyNameIdentifier = propertyName ? ts.createIdentifier(String(propertyName.escapedText)) : undefined;
|
---|
37 | const nameIdentifier = ts.createIdentifier(String(name.escapedText));
|
---|
38 | const newSpecfier = ts.createImportSpecifier(propertyNameIdentifier, nameIdentifier);
|
---|
39 | const elements = [...importNode.elements];
|
---|
40 | elements.push(newSpecfier);
|
---|
41 | const oldDeclaration = importNode.parent.parent;
|
---|
42 | const newImport = ts.createNamedImports(elements);
|
---|
43 | const importClause = ts.createImportClause(undefined, newImport);
|
---|
44 | const newDeclaration = ts.createImportDeclaration(undefined, undefined, importClause, oldDeclaration.moduleSpecifier);
|
---|
45 | return printer.printNode(ts.EmitHint.Unspecified, newDeclaration, sourceFile);
|
---|
46 | }
|
---|
47 | exports.addToImport = addToImport;
|
---|
48 | function createImport(importSource, sourceFile, name, propertyName) {
|
---|
49 | const printer = ts.createPrinter();
|
---|
50 | const propertyNameIdentifier = propertyName ? ts.createIdentifier(String(propertyName.escapedText)) : undefined;
|
---|
51 | const nameIdentifier = ts.createIdentifier(String(name.escapedText));
|
---|
52 | const newSpecfier = ts.createImportSpecifier(propertyNameIdentifier, nameIdentifier);
|
---|
53 | const newNamedImports = ts.createNamedImports([newSpecfier]);
|
---|
54 | const importClause = ts.createImportClause(undefined, newNamedImports);
|
---|
55 | const moduleSpecifier = ts.createStringLiteral(importSource);
|
---|
56 | const newImport = ts.createImportDeclaration(undefined, undefined, importClause, moduleSpecifier);
|
---|
57 | return printer.printNode(ts.EmitHint.Unspecified, newImport, sourceFile);
|
---|
58 | }
|
---|
59 | exports.createImport = createImport;
|
---|
60 | });
|
---|
61 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibW92ZS1pbXBvcnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb3JlL3NjaGVtYXRpY3MvbWlncmF0aW9ucy9tb3ZlLWRvY3VtZW50L21vdmUtaW1wb3J0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7OztJQUFBOzs7Ozs7T0FNRztJQUNILGlDQUFpQztJQUVqQyxTQUFnQixnQkFBZ0IsQ0FDNUIsVUFBMkIsRUFBRSxVQ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