source: trip-planner-front/node_modules/@ngtools/webpack/src/transformers/remove-ivy-jit-support-calls.js

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

initial commit

  • Property mode set to 100644
File size: 4.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.removeIvyJitSupportCalls = void 0;
30const ts = __importStar(require("typescript"));
31const elide_imports_1 = require("./elide_imports");
32function removeIvyJitSupportCalls(classMetadata, ngModuleScope, getTypeChecker) {
33 return (context) => {
34 const removedNodes = [];
35 const visitNode = (node) => {
36 const innerStatement = ts.isExpressionStatement(node) && getIifeStatement(node);
37 if (innerStatement) {
38 if (ngModuleScope &&
39 ts.isBinaryExpression(innerStatement.expression) &&
40 isIvyPrivateCallExpression(innerStatement.expression.right, 'ɵɵsetNgModuleScope')) {
41 removedNodes.push(innerStatement);
42 return undefined;
43 }
44 if (classMetadata) {
45 const expression = ts.isBinaryExpression(innerStatement.expression)
46 ? innerStatement.expression.right
47 : innerStatement.expression;
48 if (isIvyPrivateCallExpression(expression, 'ɵsetClassMetadata')) {
49 removedNodes.push(innerStatement);
50 return undefined;
51 }
52 }
53 }
54 return ts.visitEachChild(node, visitNode, context);
55 };
56 return (sourceFile) => {
57 let updatedSourceFile = ts.visitEachChild(sourceFile, visitNode, context);
58 if (removedNodes.length > 0) {
59 // Remove any unused imports
60 const importRemovals = elide_imports_1.elideImports(updatedSourceFile, removedNodes, getTypeChecker, context.getCompilerOptions());
61 if (importRemovals.size > 0) {
62 updatedSourceFile = ts.visitEachChild(updatedSourceFile, function visitForRemoval(node) {
63 return importRemovals.has(node)
64 ? undefined
65 : ts.visitEachChild(node, visitForRemoval, context);
66 }, context);
67 }
68 }
69 return updatedSourceFile;
70 };
71 };
72}
73exports.removeIvyJitSupportCalls = removeIvyJitSupportCalls;
74// Each Ivy private call expression is inside an IIFE
75function getIifeStatement(exprStmt) {
76 const expression = exprStmt.expression;
77 if (!expression || !ts.isCallExpression(expression) || expression.arguments.length !== 0) {
78 return null;
79 }
80 const parenExpr = expression;
81 if (!ts.isParenthesizedExpression(parenExpr.expression)) {
82 return null;
83 }
84 const funExpr = parenExpr.expression.expression;
85 if (!ts.isFunctionExpression(funExpr)) {
86 return null;
87 }
88 const innerStmts = funExpr.body.statements;
89 if (innerStmts.length !== 1) {
90 return null;
91 }
92 const innerExprStmt = innerStmts[0];
93 if (!ts.isExpressionStatement(innerExprStmt)) {
94 return null;
95 }
96 return innerExprStmt;
97}
98function isIvyPrivateCallExpression(expression, name) {
99 // Now we're in the IIFE and have the inner expression statement. We can check if it matches
100 // a private Ivy call.
101 if (!ts.isCallExpression(expression)) {
102 return false;
103 }
104 const propAccExpr = expression.expression;
105 if (!ts.isPropertyAccessExpression(propAccExpr)) {
106 return false;
107 }
108 if (propAccExpr.name.text != name) {
109 return false;
110 }
111 return true;
112}
Note: See TracBrowser for help on using the repository browser.