Forráskód Böngészése

Slightly optimized `setNodeMetadata` for basic cases with `isTransformNode` flag

sanex 4 éve
szülő
commit
1e9c031e7a

+ 2 - 0
README.md

@@ -665,6 +665,8 @@ Enables force transformation of string literals, which being matched by passed R
 
 ##### :warning: This option affects only strings that shouldn't be transformed by [`stringArrayThreshold`](#stringArrayThreshold) (or possible other thresholds in the future)
 
+The option has a priority over `reservedStrings` option but hasn't a priority over `conditional comments`.
+
 Example:
 ```ts
 	{

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/index.browser.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/index.cli.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 0 - 0
dist/index.js


+ 18 - 6
src/node-transformers/preparing-transformers/ObfuscatingGuardsTransformer.ts

@@ -99,14 +99,26 @@ export class ObfuscatingGuardsTransformer extends AbstractNodeTransformer {
      * @param {ObfuscatingGuardResult[]} obfuscatingGuardResults
      */
     private setNodeMetadata (node: ESTree.Node, obfuscatingGuardResults: ObfuscatingGuardResult[]): void {
-        const forceTransformNode: boolean = obfuscatingGuardResults
-            .some((obfuscatingGuardResult: ObfuscatingGuardResult) => obfuscatingGuardResult === ObfuscatingGuardResult.ForceTransform);
-        const ignoredNode: boolean = !forceTransformNode && obfuscatingGuardResults
-            .some((obfuscatingGuardResult: ObfuscatingGuardResult) => obfuscatingGuardResult === ObfuscatingGuardResult.Ignore);
+        const isTransformNode: boolean = obfuscatingGuardResults
+            .every((obfuscatingGuardResult: ObfuscatingGuardResult) => obfuscatingGuardResult === ObfuscatingGuardResult.Transform);
+
+        let isForceTransformNode: boolean = false;
+        let isIgnoredNode: boolean = false;
+
+        if (!isTransformNode) {
+            isForceTransformNode = obfuscatingGuardResults
+                .some((obfuscatingGuardResult: ObfuscatingGuardResult) =>
+                    obfuscatingGuardResult === ObfuscatingGuardResult.ForceTransform
+                );
+            isIgnoredNode = !isForceTransformNode && obfuscatingGuardResults
+                .some((obfuscatingGuardResult: ObfuscatingGuardResult) =>
+                    obfuscatingGuardResult === ObfuscatingGuardResult.Ignore
+                );
+        }
 
         NodeMetadata.set(node, {
-            forceTransformNode: forceTransformNode && !NodeGuards.isProgramNode(node),
-            ignoredNode: ignoredNode && !NodeGuards.isProgramNode(node)
+            forceTransformNode: isForceTransformNode && !NodeGuards.isProgramNode(node),
+            ignoredNode: isIgnoredNode && !NodeGuards.isProgramNode(node)
         });
     }
 }

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

@@ -39,7 +39,7 @@ describe('ObfuscatingGuardsTransformer', () => {
                 .getNamed(ServiceIdentifiers.INodeTransformer, NodeTransformer.ObfuscatingGuardsTransformer);
         });
 
-        describe('Variant #1: allowed node', () => {
+        describe('Variant #1: transform node', () => {
             const identifier: ESTree.Identifier = NodeFactory.identifierNode('foo');
 
             const expectedResult: ESTree.Identifier = NodeUtils.clone(identifier);

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott