[6a3a178] | 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 | */
|
---|
| 9 | var __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 | }));
|
---|
| 16 | var __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 | });
|
---|
| 21 | var __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 | };
|
---|
| 28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 29 | exports.getCleanHelperName = exports.isHelperName = exports.hasPureComment = exports.addPureComment = exports.collectDeepNodes = void 0;
|
---|
| 30 | const tslib = __importStar(require("tslib"));
|
---|
| 31 | const ts = __importStar(require("typescript"));
|
---|
| 32 | const pureFunctionComment = '@__PURE__';
|
---|
| 33 | // We include only exports that start with '__' because tslib helpers
|
---|
| 34 | // all start with a suffix of two underscores.
|
---|
| 35 | const tslibHelpers = new Set(Object.keys(tslib).filter((h) => h.startsWith('__')));
|
---|
| 36 | // Find all nodes from the AST in the subtree of node of SyntaxKind kind.
|
---|
| 37 | function collectDeepNodes(node, kind) {
|
---|
| 38 | const nodes = [];
|
---|
| 39 | const helper = (child) => {
|
---|
| 40 | if (child.kind === kind) {
|
---|
| 41 | nodes.push(child);
|
---|
| 42 | }
|
---|
| 43 | ts.forEachChild(child, helper);
|
---|
| 44 | };
|
---|
| 45 | ts.forEachChild(node, helper);
|
---|
| 46 | return nodes;
|
---|
| 47 | }
|
---|
| 48 | exports.collectDeepNodes = collectDeepNodes;
|
---|
| 49 | function addPureComment(node) {
|
---|
| 50 | return ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, pureFunctionComment, false);
|
---|
| 51 | }
|
---|
| 52 | exports.addPureComment = addPureComment;
|
---|
| 53 | function hasPureComment(node) {
|
---|
| 54 | if (!node) {
|
---|
| 55 | return false;
|
---|
| 56 | }
|
---|
| 57 | const leadingComment = ts.getSyntheticLeadingComments(node);
|
---|
| 58 | return !!leadingComment && leadingComment.some((comment) => comment.text === pureFunctionComment);
|
---|
| 59 | }
|
---|
| 60 | exports.hasPureComment = hasPureComment;
|
---|
| 61 | function isHelperName(name) {
|
---|
| 62 | return tslibHelpers.has(name);
|
---|
| 63 | }
|
---|
| 64 | exports.isHelperName = isHelperName;
|
---|
| 65 | /**
|
---|
| 66 | * In FESM's when not using `importHelpers` there might be multiple in the same file.
|
---|
| 67 | @example
|
---|
| 68 | ```
|
---|
| 69 | var __decorate$1 = '';
|
---|
| 70 | var __decorate$2 = '';
|
---|
| 71 | ```
|
---|
| 72 | * @returns Helper name without the '$' and number suffix or `undefined` if it's not a helper.
|
---|
| 73 | */
|
---|
| 74 | function getCleanHelperName(name) {
|
---|
| 75 | const parts = name.split('$');
|
---|
| 76 | const cleanName = parts[0];
|
---|
| 77 | if (parts.length > 2 || (parts.length === 2 && isNaN(+parts[1]))) {
|
---|
| 78 | return undefined;
|
---|
| 79 | }
|
---|
| 80 | return isHelperName(cleanName) ? cleanName : undefined;
|
---|
| 81 | }
|
---|
| 82 | exports.getCleanHelperName = getCleanHelperName;
|
---|