8000 Merge pull request #469 from javascript-obfuscator/dependencies-updat… · sec-js/javascript-obfuscator@b969afe · GitHub
[go: up one dir, main page]

Skip to content

Commit b969afe

Browse files
authored
Merge pull request javascript-obfuscator#469 from javascript-obfuscator/dependencies-update-02.01.2020
Dependencies update #4
2 parents 6d04f1b + 811debe commit b969afe

File tree

11 files changed

+829
-734
lines changed

11 files changed

+829
-734
lines changed

dist/index.browser.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cli.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@types/chance": "1.0.8",
4646
"@types/escodegen": "0.0.6",
4747
"@types/estraverse": "0.0.6",
48-
"@types/estree": "0.0.38",
48+
"@types/estree": "0.0.41",
4949
"@types/md5": "2.1.33",
5050
"@types/mkdirp": "0.5.2",
5151
"@types/mocha": "5.2.7",

src/declarations/ESTree.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ declare module 'estree' {
3232
metadata?: LiteralNodeMetadata;
3333
}
3434

35-
interface ExpressionStatement extends BaseNode {
36-
directive?: 'use strict';
37-
}
38-
3935
interface SimpleLiteral extends BaseNode {
4036
'x-verbatim-property'?: escodegen.XVerbatimProperty;
4137
}

src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
9191
* @param {NodeGuards} parentNode
9292
* @returns {NodeGuards}
9393
*/
94-
public transformNode (classDeclarationNode: ESTree.ClassDeclaration, parentNode: ESTree.Node): ESTree.Node {
94+
public transformNode (
95+
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
96+
parentNode: ESTree.Node
97+
): ESTree.Node {
9598
const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(classDeclarationNode);
9699

97100
if (!lexicalScopeNode) {
@@ -122,7 +125,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
122125
* @param {boolean} isGlobalDeclaration
123126
*/
124127
private storeClassName (
125-
classDeclarationNode: ESTree.ClassDeclaration,
128+
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
126129
lexicalScopeNode: TNodeWithLexicalScope,
127130
isGlobalDeclaration: boolean
128131
): void {
@@ -138,7 +141,7 @@ export class ClassDeclarationTransformer extends AbstractNodeTransformer {
138141
* @param {TNodeWithLexicalScope} lexicalScopeNode
139142
*/
140143
private replaceScopeCachedIdentifiers (
141-
classDeclarationNode: ESTree.ClassDeclaration,
144+
classDeclarationNode: ESTree.ClassDeclaration & { id: ESTree.Identifier },
142145
lexicalScopeNode: TNodeWithLexicalScope
143146
): void {
144147
const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =

src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
9191
* @param {NodeGuards} parentNode
9292
* @returns {NodeGuards}
9393
*/
94-
public transformNode (functionDeclarationNode: ESTree.FunctionDeclaration, parentNode: ESTree.Node): ESTree.Node {
94+
public transformNode (
95+
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
96+
parentNode: ESTree.Node
97+
): ESTree.Node {
9598
const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScope(parentNode);
9699

97100
if (!lexicalScopeNode) {
@@ -122,7 +125,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
122125
* @param {boolean} isGlobalDeclaration
123126
*/
124127
private storeFunctionName (
125-
functionDeclarationNode: ESTree.FunctionDeclaration,
128+
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
126129
lexicalScopeNode: TNodeWithLexicalScope,
127130
isGlobalDeclaration: boolean
128131
): void {
@@ -138,7 +141,7 @@ export class FunctionDeclarationTransformer extends AbstractNodeTransformer {
138141
* @param {TNodeWithLexicalScope} lexicalScopeNode
139142
*/
140143
private replaceScopeCachedIdentifiers (
141-
functionDeclarationNode: ESTree.FunctionDeclaration,
144+
functionDeclarationNode: ESTree.FunctionDeclaration & { id: ESTree.Identifier },
142145
lexicalScopeNode: TNodeWithLexicalScope
143146
): void {
144147
const cachedReplaceableIdentifiersNamesMap: TReplaceableIdentifiersNames =

src/node/NodeFactory.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ export class NodeFactory {
128128
};
129129
}
130130

131+
/**
132+
* @param {Literal} expression
133+
* @param {string} directive
134+
* @returns {Directive}
135+
*/
136+
public static directiveNode (
137+
expression: ESTree.Literal,
138+
directive: string
139+
): ESTree.Directive {
140+
return {
141+
type: NodeType.ExpressionStatement,
142+
expression,
143+
directive,
144+
metadata: { ignoredNode: false }
145+
};
146+
}
147+
131148
/**
132149
* @param {Expression} expression
133150
* @returns {ExpressionStatement}

src/node/NodeGuards.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ export class NodeGuards {
8484
* @param {Node} node
8585
* @returns {boolean}
8686
*/
87-
public static isClassDeclarationNode (node: ESTree.Node): node is ESTree.ClassDeclaration {
88-
return node.type === NodeType.ClassDeclaration;
87+
public static isClassDeclarationNode (
88+
node: ESTree.Node
89+
): node is ESTree.ClassDeclaration & { id: ESTree.Identifier } {
90+
return node.type === NodeType.ClassDeclaration && node.id !== null;
8991
}
9092

9193
/**
@@ -96,6 +98,15 @@ export class NodeGuards {
9698
return node.type === NodeType.ContinueStatement;
9799
}
98100

101+
/**
102+
* @param {Node} node
103+
* @returns {boolean}
104+
*/
105+
public static isDirectiveNode (node: ESTree.Node): node is ESTree.Directive {
106+
return node.type === NodeType.ExpressionStatement
107+
&& 'directive' in node;
108+
}
109+
99110
/**
100111
* @param {Node} node
101112
* @returns {boolean}
@@ -109,7 +120,8 @@ export class NodeGuards {
109120
* @returns {boolean}
110121
*/
111122
public static isExpressionStatementNode (node: ESTree.Node): node is ESTree.ExpressionStatement {
112-
return node.type === NodeType.ExpressionStatement;
123+
return node.type === NodeType.ExpressionStatement
124+
&& !('directive' in node);
113125
}
114126

115127
/**
@@ -126,8 +138,10 @@ export class NodeGuards {
126138
* @param {Node} node
127139
* @returns {boolean}
128140
*/
129-
public static isFunctionDeclarationNode (node: ESTree.Node): node is ESTree.FunctionDeclaration {
130-
return node.type === NodeType.FunctionDeclaration;
141+
public static isFunctionDeclarationNode (
142+
node: ESTree.Node
143+
): node is ESTree.FunctionDeclaration & { id: ESTree.Identifier } {
144+
return node.type === NodeType.FunctionDeclaration && node.id !== null;
131145
}
132146

133147
/**
@@ -401,8 +415,9 @@ export class NodeGuards {
401415
* @param {Node} node
402416
* @returns {boolean}
403417
*/
404-
public static isUseStrictOperator (node: ESTree.Node): node is ESTree.ExpressionStatement {
405-
return node.type === NodeType.ExpressionStatement && node.directive === 'use strict';
418+
public static isUseStrictOperator (node: ESTree.Node): node is ESTree.Directive {
419+
return NodeGuards.isDirectiveNode(node)
420+
&& node.directive === 'use strict';
406421
}
407422

408423
/**

test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,19 @@ describe('ObfuscatingGuardsTransformer', () => {
4949
});
5050

5151
describe('Variant #2: invalid node', () => {
52-
const expressionStatement: ESTree.ExpressionStatement = NodeFactory.expressionStatementNode(
53-
NodeFactory.identifierNode('foo')
52+
const expressionStatement: ESTree.ExpressionStatement = NodeFactory.directiveNode(
53+
NodeFactory.literalNode('use strict'),
54+
'use strict'
5455
);
5556

5657
const expectedResult: ESTree.ExpressionStatement = NodeUtils.clone(expressionStatement);
5758

5859
let result: ESTree.ExpressionStatement;
5960

6061
before(() => {
61-
expressionStatement.directive = 'use strict';
6262
expressionStatement.parentNode = expressionStatement;
6363
expressionStatement.expression.parentNode = expressionStatement;
6464

65-
expectedResult.directive = 'use strict';
6665
expectedResult.parentNode = expectedResult;
6766
NodeMetadata.set(expectedResult, { ignoredNode: true });
6867

0 commit comments

Comments
 (0)
0