mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Dependencies update #4
This commit is contained in:
Vendored
+5
-5
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -45,7 +45,7 @@
|
||||
"@types/chance": "1.0.8",
|
||||
"@types/escodegen": "0.0.6",
|
||||
"@types/estraverse": "0.0.6",
|
||||
"@types/estree": "0.0.38",
|
||||
"@types/estree": "0.0.41",
|
||||
"@types/md5": "2.1.33",
|
||||
"@types/mkdirp": "0.5.2",
|
||||
"@types/mocha": "5.2.7",
|
||||
|
||||
Vendored
-4
@@ -32,10 +32,6 @@ declare module 'estree' {
|
||||
metadata?: LiteralNodeMetadata;
|
||||
}
|
||||
|
||||
interface ExpressionStatement extends BaseNode {
|
||||
directive?: 'use strict';
|
||||
}
|
||||
|
||||
interface SimpleLiteral extends BaseNode {
|
||||
'x-verbatim-property'?: escodegen.XVerbatimProperty;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,10 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {NodeGuards} parentNode
|
||||
* @returns {NodeGuards}
|
||||
*/
|
||||
public transformNode (classDeclarationNode: ESTree.ClassDeclaration, parentNode: ESTree.Node): ESTree.Node {
|
||||
public transformNode (
|
||||
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
|
||||
parentNode: ESTree.Node
|
||||
): ESTree.Node {
|
||||
const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(classDeclarationNode);
|
||||
|
||||
if (!lexicalScopeNode) {
|
||||
@@ -122,7 +125,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {boolean} isGlobalDeclaration
|
||||
*/
|
||||
private storeClassName (
|
||||
classDeclarationNode: ESTree.ClassDeclaration,
|
||||
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
|
||||
lexicalScopeNode: TNodeWithLexicalScope,
|
||||
isGlobalDeclaration: boolean
|
||||
): void {
|
||||
@@ -138,7 +141,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
*/
|
||||
private replaceScopeCachedIdentifiers (
|
||||
classDeclarationNode: ESTree.ClassDeclaration,
|
||||
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
|
||||
lexicalScopeNode: TNodeWithLexicalScope
|
||||
): void {
|
||||
const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =
|
||||
|
||||
@@ -91,7 +91,10 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {NodeGuards} parentNode
|
||||
* @returns {NodeGuards}
|
||||
*/
|
||||
public transformNode (functionDeclarationNode: ESTree.FunctionDeclaration, parentNode: ESTree.Node): ESTree.Node {
|
||||
public transformNode (
|
||||
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
|
||||
parentNode: ESTree.Node
|
||||
): ESTree.Node {
|
||||
const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(parentNode);
|
||||
|
||||
if (!lexicalScopeNode) {
|
||||
@@ -122,7 +125,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {boolean} isGlobalDeclaration
|
||||
*/
|
||||
private storeFunctionName (
|
||||
functionDeclarationNode: ESTree.FunctionDeclaration,
|
||||
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
|
||||
lexicalScopeNode: TNodeWithLexicalScope,
|
||||
isGlobalDeclaration: boolean
|
||||
): void {
|
||||
@@ -138,7 +141,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
|
||||
* @param {TNodeWithLexicalScope} lexicalScopeNode
|
||||
*/
|
||||
private replaceScopeCachedIdentifiers (
|
||||
functionDeclarationNode: ESTree.FunctionDeclaration,
|
||||
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
|
||||
lexicalScopeNode: TNodeWithLexicalScope
|
||||
): void {
|
||||
const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =
|
||||
|
||||
@@ -128,6 +128,23 @@ export class NodeFactory {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Literal} expression
|
||||
* @param {string} directive
|
||||
* @returns {Directive}
|
||||
*/
|
||||
public static directiveNode (
|
||||
expression: ESTree.Literal,
|
||||
directive: string
|
||||
): ESTree.Directive {
|
||||
return {
|
||||
type: NodeType.ExpressionStatement,
|
||||
expression,
|
||||
directive,
|
||||
metadata: { ignoredNode: false }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Expression} expression
|
||||
* @returns {ExpressionStatement}
|
||||
|
||||
+22
-7
@@ -84,8 +84,10 @@ export class NodeGuards {
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isClassDeclarationNode (node: ESTree.Node): node is ESTree.ClassDeclaration {
|
||||
return node.type === NodeType.ClassDeclaration;
|
||||
public static isClassDeclarationNode (
|
||||
node: ESTree.Node
|
||||
): node is ESTree.ClassDeclaration & { id: ESTree.Identifier } {
|
||||
return node.type === NodeType.ClassDeclaration && node.id !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +98,15 @@ export class NodeGuards {
|
||||
return node.type === NodeType.ContinueStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isDirectiveNode (node: ESTree.Node): node is ESTree.Directive {
|
||||
return node.type === NodeType.ExpressionStatement
|
||||
&& 'directive' in node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
@@ -109,7 +120,8 @@ export class NodeGuards {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isExpressionStatementNode (node: ESTree.Node): node is ESTree.ExpressionStatement {
|
||||
return node.type === NodeType.ExpressionStatement;
|
||||
return node.type === NodeType.ExpressionStatement
|
||||
&& !('directive' in node);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +138,10 @@ export class NodeGuards {
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isFunctionDeclarationNode (node: ESTree.Node): node is ESTree.FunctionDeclaration {
|
||||
return node.type === NodeType.FunctionDeclaration;
|
||||
public static isFunctionDeclarationNode (
|
||||
node: ESTree.Node
|
||||
): node is ESTree.FunctionDeclaration & { id: ESTree.Identifier } {
|
||||
return node.type === NodeType.FunctionDeclaration && node.id !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,8 +415,9 @@ export class NodeGuards {
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isUseStrictOperator (node: ESTree.Node): node is ESTree.ExpressionStatement {
|
||||
return node.type === NodeType.ExpressionStatement && node.directive === 'use strict';
|
||||
public static isUseStrictOperator (node: ESTree.Node): node is ESTree.Directive {
|
||||
return NodeGuards.isDirectiveNode(node)
|
||||
&& node.directive === 'use strict';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-4
@@ -49,8 +49,9 @@ describe('ObfuscatingGuardsTransformer', () => {
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid node', () => {
|
||||
const expressionStatement: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(
|
||||
NodeFactory.identifierNode('foo')
|
||||
const expressionStatement: ESTree.ExpressionStatement = NodeFactory.directiveNode(
|
||||
NodeFactory.literalNode('use strict'),
|
||||
'use strict'
|
||||
);
|
||||
|
||||
const expectedResult: ESTree.ExpressionStatement = NodeUtils.clone(expressionStatement);
|
||||
@@ -58,11 +59,9 @@ describe('ObfuscatingGuardsTransformer', () => {
|
||||
let result: ESTree.ExpressionStatement;
|
||||
|
||||
before(() => {
|
||||
expressionStatement.directive = 'use strict';
|
||||
expressionStatement.parentNode = expressionStatement;
|
||||
expressionStatement.expression.parentNode = expressionStatement;
|
||||
|
||||
expectedResult.directive = 'use strict';
|
||||
expectedResult.parentNode = expectedResult;
|
||||
NodeMetadata.set(expectedResult, { ignoredNode: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user