forked from javascript-obfuscator/javascript-obfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeLiteralUtils.ts
More file actions
45 lines (37 loc) · 1.41 KB
/
Copy pathNodeLiteralUtils.ts
File metadata and controls
45 lines (37 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as ESTree from 'estree';
import { TNumberLiteralNode } from '../types/node/TNumberLiteralNode';
import { TStringLiteralNode } from '../types/node/TStringLiteralNode';
import { NodeGuards } from './NodeGuards';
export class NodeLiteralUtils {
/**
* @param {Literal} literalNode
* @returns {literalNode is TNumberLiteralNode}
*/
public static isNumberLiteralNode (literalNode: ESTree.Literal): literalNode is TNumberLiteralNode {
return typeof literalNode.value === 'number';
}
/**
* @param {Literal} literalNode
* @returns {literalNode is TStringLiteralNode}
*/
public static isStringLiteralNode (literalNode: ESTree.Literal): literalNode is TStringLiteralNode {
return typeof literalNode.value === 'string';
}
/**
* @param {Literal} literalNode
* @param {Node} parentNode
* @returns {boolean}
*/
public static isProhibitedLiteralNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): boolean {
if (NodeGuards.isPropertyNode(parentNode) && !parentNode.computed && parentNode.key === literalNode) {
return true;
}
if (NodeGuards.isImportDeclarationNode(parentNode)) {
return true;
}
if (NodeGuards.isExportAllDeclarationNode(parentNode) || NodeGuards.isExportNamedDeclarationNode(parentNode)) {
return true;
}
return false;
}
}