source: trip-planner-front/node_modules/@ngtools/webpack/src/ivy/transformation.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.5 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.replaceBootstrap = exports.mergeTransformers = exports.createJitTransformers = exports.createAotTransformers = void 0;
30const compiler_cli_1 = require("@angular/compiler-cli");
31const ts = __importStar(require("typescript"));
32const elide_imports_1 = require("../transformers/elide_imports");
33const remove_ivy_jit_support_calls_1 = require("../transformers/remove-ivy-jit-support-calls");
34const replace_resources_1 = require("../transformers/replace_resources");
35function createAotTransformers(builder, options) {
36 const getTypeChecker = () => builder.getProgram().getTypeChecker();
37 const transformers = {
38 before: [replaceBootstrap(getTypeChecker)],
39 after: [],
40 };
41 const removeClassMetadata = !options.emitClassMetadata;
42 const removeNgModuleScope = !options.emitNgModuleScope;
43 if (removeClassMetadata || removeNgModuleScope) {
44 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
45 transformers.before.push(remove_ivy_jit_support_calls_1.removeIvyJitSupportCalls(removeClassMetadata, removeNgModuleScope, getTypeChecker));
46 }
47 return transformers;
48}
49exports.createAotTransformers = createAotTransformers;
50function createJitTransformers(builder, options) {
51 const getTypeChecker = () => builder.getProgram().getTypeChecker();
52 return {
53 before: [
54 replace_resources_1.replaceResources(() => true, getTypeChecker, options.directTemplateLoading, options.inlineStyleMimeType, options.inlineStyleFileExtension),
55 compiler_cli_1.constructorParametersDownlevelTransform(builder.getProgram()),
56 ],
57 };
58}
59exports.createJitTransformers = createJitTransformers;
60function mergeTransformers(first, second) {
61 const result = {};
62 if (first.before || second.before) {
63 result.before = [...(first.before || []), ...(second.before || [])];
64 }
65 if (first.after || second.after) {
66 result.after = [...(first.after || []), ...(second.after || [])];
67 }
68 if (first.afterDeclarations || second.afterDeclarations) {
69 result.afterDeclarations = [
70 ...(first.afterDeclarations || []),
71 ...(second.afterDeclarations || []),
72 ];
73 }
74 return result;
75}
76exports.mergeTransformers = mergeTransformers;
77function replaceBootstrap(getTypeChecker) {
78 return (context) => {
79 let bootstrapImport;
80 let bootstrapNamespace;
81 const replacedNodes = [];
82 const nodeFactory = context.factory;
83 const visitNode = (node) => {
84 if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
85 const target = node.expression;
86 if (target.text === 'platformBrowserDynamic') {
87 if (!bootstrapNamespace) {
88 bootstrapNamespace = nodeFactory.createUniqueName('__NgCli_bootstrap_');
89 bootstrapImport = nodeFactory.createImportDeclaration(undefined, undefined, nodeFactory.createImportClause(false, undefined, nodeFactory.createNamespaceImport(bootstrapNamespace)), nodeFactory.createStringLiteral('@angular/platform-browser'));
90 }
91 replacedNodes.push(target);
92 return nodeFactory.updateCallExpression(node, nodeFactory.createPropertyAccessExpression(bootstrapNamespace, 'platformBrowser'), node.typeArguments, node.arguments);
93 }
94 }
95 return ts.visitEachChild(node, visitNode, context);
96 };
97 return (sourceFile) => {
98 let updatedSourceFile = ts.visitEachChild(sourceFile, visitNode, context);
99 if (bootstrapImport) {
100 // Remove any unused platform browser dynamic imports
101 const removals = elide_imports_1.elideImports(updatedSourceFile, replacedNodes, getTypeChecker, context.getCompilerOptions());
102 if (removals.size > 0) {
103 updatedSourceFile = ts.visitEachChild(updatedSourceFile, (node) => (removals.has(node) ? undefined : node), context);
104 }
105 // Add new platform browser import
106 return nodeFactory.updateSourceFile(updatedSourceFile, ts.setTextRange(nodeFactory.createNodeArray([bootstrapImport, ...updatedSourceFile.statements]), sourceFile.statements));
107 }
108 else {
109 return updatedSourceFile;
110 }
111 };
112 };
113}
114exports.replaceBootstrap = replaceBootstrap;
Note: See TracBrowser for help on using the repository browser.