source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/babel/plugins/pure-toplevel-functions.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: 3.4 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};
28var __importDefault = (this && this.__importDefault) || function (mod) {
29 return (mod && mod.__esModule) ? mod : { "default": mod };
30};
31Object.defineProperty(exports, "__esModule", { value: true });
32const core_1 = require("@babel/core");
33const helper_annotate_as_pure_1 = __importDefault(require("@babel/helper-annotate-as-pure"));
34const tslib = __importStar(require("tslib"));
35/**
36 * A cached set of TypeScript helper function names used by the helper name matcher utility function.
37 */
38const tslibHelpers = new Set(Object.keys(tslib).filter((h) => h.startsWith('__')));
39/**
40 * Determinates whether an identifier name matches one of the TypeScript helper function names.
41 *
42 * @param name The identifier name to check.
43 * @returns True, if the name matches a TypeScript helper name; otherwise, false.
44 */
45function isTslibHelperName(name) {
46 const nameParts = name.split('$');
47 const originalName = nameParts[0];
48 if (nameParts.length > 2 || (nameParts.length === 2 && isNaN(+nameParts[1]))) {
49 return false;
50 }
51 return tslibHelpers.has(originalName);
52}
53/**
54 * A babel plugin factory function for adding the PURE annotation to top-level new and call expressions.
55 *
56 * @returns A babel plugin object instance.
57 */
58function default_1() {
59 return {
60 visitor: {
61 CallExpression(path) {
62 // If the expression has a function parent, it is not top-level
63 if (path.getFunctionParent()) {
64 return;
65 }
66 const callee = path.node.callee;
67 if (core_1.types.isFunctionExpression(callee) && path.node.arguments.length !== 0) {
68 return;
69 }
70 // Do not annotate TypeScript helpers emitted by the TypeScript compiler.
71 // TypeScript helpers are intended to cause side effects.
72 if (core_1.types.isIdentifier(callee) && isTslibHelperName(callee.name)) {
73 return;
74 }
75 helper_annotate_as_pure_1.default(path);
76 },
77 NewExpression(path) {
78 // If the expression has a function parent, it is not top-level
79 if (!path.getFunctionParent()) {
80 helper_annotate_as_pure_1.default(path);
81 }
82 },
83 },
84 };
85}
86exports.default = default_1;
Note: See TracBrowser for help on using the repository browser.