瀏覽代碼

Added method isComparisonExpressionStringLiteralNode to the StringArrayRotateFunctionTransformer

sanex 4 年之前
父節點
當前提交
159b5e85ac

+ 1 - 1
.eslintrc.js

@@ -344,7 +344,7 @@ module.exports = {
         "unicorn/prefer-starts-ends-with": "error",
         "unicorn/prefer-set-has": "error",
         "unicorn/prefer-string-slice": "error",
-        "unicorn/prefer-trim-start-end": "error",
+        "unicorn/prefer-string-trim-start-end": "error",
         "use-isnan": "error",
         "valid-typeof": "error",
         "yoda": "error"

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


+ 2 - 2
package.json

@@ -57,7 +57,7 @@
     "@types/mkdirp": "1.0.1",
     "@types/mocha": "8.2.0",
     "@types/multimatch": "4.0.0",
-    "@types/node": "14.14.16",
+    "@types/node": "14.14.17",
     "@types/rimraf": "3.0.0",
     "@types/sinon": "9.0.10",
     "@types/string-template": "1.0.2",
@@ -72,7 +72,7 @@
     "eslint-plugin-jsdoc": "30.7.9",
     "eslint-plugin-no-null": "1.0.2",
     "eslint-plugin-prefer-arrow": "1.2.2",
-    "eslint-plugin-unicorn": "24.0.0",
+    "eslint-plugin-unicorn": "25.0.1",
     "fork-ts-checker-notifier-webpack-plugin": "3.0.0",
     "fork-ts-checker-webpack-plugin": "6.0.8",
     "mocha": "8.2.1",

+ 11 - 1
src/node-transformers/string-array-transformers/StringArrayRotateFunctionTransformer.ts

@@ -199,7 +199,9 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme
                    return;
                 }
 
-                if (/\d/.test(node.value)) {
+                // force add item data for string literal nodes of comparison expressions
+                // set all other nodes as ignored to prevent them from obfuscation
+                if (this.isComparisonExpressionStringLiteralNode(node)) {
                     this.stringArrayStorageAnalyzer.addItemDataForLiteralNode(node);
                 } else {
                     NodeMetadata.set(node, {ignoredNode: true});
@@ -254,4 +256,12 @@ export class StringArrayRotateFunctionTransformer extends AbstractNodeTransforme
 
         return stringArrayRotateFunctionCodeHelper.getNode()[0];
     }
+
+    /**
+     * @param {Literal} stringLiteralNode
+     * @returns {boolean}
+     */
+    private isComparisonExpressionStringLiteralNode (stringLiteralNode: ESTree.Literal & {value: string}): boolean {
+        return /\d/.test(stringLiteralNode.value);
+    }
 }

+ 8 - 8
yarn.lock

@@ -535,10 +535,10 @@
   resolved "https://registry.yarnpkg.com/@types/node/-/node-13.9.3.tgz#6356df2647de9eac569f9a52eda3480fa9e70b4d"
   integrity sha512-01s+ac4qerwd6RHD+mVbOEsraDHSgUaefQlEdBbUolnQFjKwCr7luvAlEwW1RFojh67u0z4OUTjPn9LEl4zIkA==
 
-"@types/[email protected]6":
-  version "14.14.16"
-  resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.16.tgz#3cc351f8d48101deadfed4c9e4f116048d437b4b"
-  integrity sha512-naXYePhweTi+BMv11TgioE2/FXU4fSl29HAH1ffxVciNsH3rYXjNP2yM8wqmSm7jS20gM8TIklKiTen+1iVncw==
+"@types/[email protected]7":
+  version "14.14.17"
+  resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.17.tgz#29fab92f3986c0e379968ad3c2043683d8020dbb"
+  integrity sha512-G0lD1/7qD60TJ/mZmhog76k7NcpLWkPVGgzkRy3CTlnFu4LUQh5v2Wa661z6vnXmD8EQrnALUyf0VRtrACYztw==
 
 "@types/normalize-package-data@^2.4.0":
   version "2.4.0"
@@ -1766,10 +1766,10 @@ [email protected]:
   resolved "https://registry.yarnpkg.com/eslint-plugin-prefer-arrow/-/eslint-plugin-prefer-arrow-1.2.2.tgz#0c6d25a6b94cb3e0110a23d129760af5860edb6e"
   integrity sha512-C8YMhL+r8RMeMdYAw/rQtE6xNdMulj+zGWud/qIGnlmomiPRaLDGLMeskZ3alN6uMBojmooRimtdrXebLN4svQ==
 
-eslint-plugin-unicorn@24.0.0:
-  version "24.0.0"
-  resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-24.0.0.tgz#08017ccd7ac704777d459cff6e13a35f54cbcab1"
-  integrity sha512-NfLjIZas/ZUwc3S+pUtbTRqgCkODxPEkJBJ5ZR8wIu90BmX4jmXp10hoOZMScR2CR1NYTtrx0OX4BQvBnbzZzA==
+eslint-plugin-unicorn@25.0.1:
+  version "25.0.1"
+  resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-25.0.1.tgz#bedcbc9b817042a44f6501584e8266741120f023"
+  integrity sha512-MEyEWoyou/qhJH6rEER9YHACtCsQT+eewc6Fdxbi2eiTvsGrBR8JZMA6qaeof3oMQeRxOpaERoBKzU7R5c4A/w==
   dependencies:
     ci-info "^2.0.0"
     clean-regexp "^1.0.0"

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