Browse Source

Dependencies update #4

sanex3339 5 years ago
parent
commit
811debed96

File diff suppressed because it is too large
+ 0 - 0
dist/index.browser.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.cli.js


File diff suppressed because it is too large
+ 0 - 0
dist/index.js


+ 1 - 1
package.json

@@ -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",

+ 0 - 4
src/declarations/ESTree.d.ts

@@ -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;
     }

+ 6 - 3
src/node-transformers/obfuscating-transformers/ClassDeclarationTransformer.ts

@@ -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 =

+ 6 - 3
src/node-transformers/obfuscating-transformers/FunctionDeclarationTransformer.ts

@@ -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 =

+ 17 - 0
src/node/NodeFactory.ts

@@ -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
src/node/NodeGuards.ts

@@ -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
test/unit-tests/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.spec.ts

@@ -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 });
 

File diff suppressed because it is too large
+ 228 - 190
yarn.lock


Some files were not shown because too many files changed in this diff