UNPKG

2.07 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var ts = require("typescript");
4var namedDeclarationKinds = [
5 ts.SyntaxKind.InterfaceDeclaration,
6 ts.SyntaxKind.ClassDeclaration,
7 ts.SyntaxKind.EnumDeclaration,
8 ts.SyntaxKind.TypeAliasDeclaration,
9 ts.SyntaxKind.ModuleDeclaration,
10 ts.SyntaxKind.FunctionDeclaration,
11 ts.SyntaxKind.VariableDeclaration,
12];
13function isNodeNamedDeclaration(node) {
14 return namedDeclarationKinds.indexOf(node.kind) !== -1;
15}
16exports.isNodeNamedDeclaration = isNodeNamedDeclaration;
17function hasNodeModifier(node, modifier) {
18 return Boolean(node.modifiers && node.modifiers.some(function (nodeModifier) { return nodeModifier.kind === modifier; }));
19}
20exports.hasNodeModifier = hasNodeModifier;
21function getActualSymbol(symbol, typeChecker) {
22 if (symbol.flags & ts.SymbolFlags.Alias) {
23 symbol = typeChecker.getAliasedSymbol(symbol);
24 }
25 return symbol;
26}
27exports.getActualSymbol = getActualSymbol;
28/**
29 * Returns whether statement is `declare module` ModuleDeclaration (not `declare global` or `namespace`)
30 */
31function isDeclareModuleStatement(statement) {
32 // `declare module ""`, `declare global` and `namespace {}` are ModuleDeclaration
33 // but here we need to check only `declare module` statements
34 return ts.isModuleDeclaration(statement) && !(statement.flags & ts.NodeFlags.Namespace) && !(statement.flags & ts.NodeFlags.GlobalAugmentation);
35}
36exports.isDeclareModuleStatement = isDeclareModuleStatement;
37/**
38 * Returns whether statement is `declare global` ModuleDeclaration
39 */
40function isDeclareGlobalStatement(statement) {
41 return ts.isModuleDeclaration(statement) && Boolean(statement.flags & ts.NodeFlags.GlobalAugmentation);
42}
43exports.isDeclareGlobalStatement = isDeclareGlobalStatement;
44/**
45 * Returns whether node is `namespace` ModuleDeclaration
46 */
47function isNamespaceStatement(node) {
48 return ts.isModuleDeclaration(node) && Boolean(node.flags & ts.NodeFlags.Namespace);
49}
50exports.isNamespaceStatement = isNamespaceStatement;