source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/babel/plugins/elide-angular-metadata.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 2.6 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 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.getKeywords = void 0;
11const core_1 = require("@babel/core");
12/**
13 * The name of the Angular class metadata function created by the Angular compiler.
14 */
15const SET_CLASS_METADATA_NAME = 'ɵsetClassMetadata';
16/**
17 * Provides one or more keywords that if found within the content of a source file indicate
18 * that this plugin should be used with a source file.
19 *
20 * @returns An a string iterable containing one or more keywords.
21 */
22function getKeywords() {
23 return [SET_CLASS_METADATA_NAME];
24}
25exports.getKeywords = getKeywords;
26/**
27 * A babel plugin factory function for eliding the Angular class metadata function (`ɵsetClassMetadata`).
28 *
29 * @returns A babel plugin object instance.
30 */
31function default_1() {
32 return {
33 visitor: {
34 CallExpression(path) {
35 var _a;
36 const callee = path.node.callee;
37 // The function being called must be the metadata function name
38 let calleeName;
39 if (core_1.types.isMemberExpression(callee) && core_1.types.isIdentifier(callee.property)) {
40 calleeName = callee.property.name;
41 }
42 else if (core_1.types.isIdentifier(callee)) {
43 calleeName = callee.name;
44 }
45 if (calleeName !== SET_CLASS_METADATA_NAME) {
46 return;
47 }
48 // There must be four arguments that meet the following criteria:
49 // * First must be an identifier
50 // * Second must be an array literal
51 const callArguments = path.node.arguments;
52 if (callArguments.length !== 4 ||
53 !core_1.types.isIdentifier(callArguments[0]) ||
54 !core_1.types.isArrayExpression(callArguments[1])) {
55 return;
56 }
57 // The metadata function is always emitted inside a function expression
58 if (!((_a = path.getFunctionParent()) === null || _a === void 0 ? void 0 : _a.isFunctionExpression())) {
59 return;
60 }
61 // Replace the metadata function with `void 0` which is the equivalent return value
62 // of the metadata function.
63 path.replaceWith(path.scope.buildUndefinedNode());
64 },
65 },
66 };
67}
68exports.default = default_1;
Note: See TracBrowser for help on using the repository browser.