mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #211 from javascript-obfuscator/esprima-parse-module
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/…
This commit is contained in:
@@ -4,6 +4,7 @@ v0.15.0
|
||||
---
|
||||
* **Breaking change:** dropped `node@4` and `node@5` support.
|
||||
* **New CLI option:** `exclude` allows to exclude specific files or directories from obfuscation.
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/210
|
||||
|
||||
v0.14.3
|
||||
---
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+5
-5
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.15.0-dev.1",
|
||||
"version": "0.15.0-dev.2",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -24,7 +24,7 @@
|
||||
"chance": "1.0.13",
|
||||
"class-validator": "0.8.1",
|
||||
"commander": "2.14.1",
|
||||
"escodegen-wallaby": "1.6.17",
|
||||
"escodegen-wallaby": "1.6.18",
|
||||
"esprima": "4.0.0",
|
||||
"estraverse": "4.2.0",
|
||||
"inversify": "4.11.1",
|
||||
@@ -55,7 +55,7 @@
|
||||
"@types/multimatch": "2.1.2",
|
||||
"@types/node": "9.4.6",
|
||||
"@types/rimraf": "2.0.2",
|
||||
"@types/sinon": "4.1.3",
|
||||
"@types/sinon": "4.3.0",
|
||||
"@types/string-template": "1.0.2",
|
||||
"@types/webpack-env": "1.13.5",
|
||||
"awesome-typescript-loader": "4.0.0-0",
|
||||
@@ -69,11 +69,11 @@
|
||||
"rimraf": "2.6.2",
|
||||
"sinon": "4.4.2",
|
||||
"threads": "0.10.1",
|
||||
"ts-node": "5.0.0",
|
||||
"ts-node": "5.0.1",
|
||||
"tslint": "5.9.1",
|
||||
"tslint-eslint-rules": "5.1.0",
|
||||
"tslint-language-service": "0.9.8",
|
||||
"tslint-webpack-plugin": "1.1.1",
|
||||
"tslint-webpack-plugin": "1.2.0",
|
||||
"typescript": "2.7.2",
|
||||
"webpack": "3.11.0",
|
||||
"webpack-node-externals": "1.6.0"
|
||||
|
||||
@@ -22,11 +22,15 @@ export class EsprimaFacade {
|
||||
* @param {ParseOptions} config
|
||||
* @returns {Program}
|
||||
*/
|
||||
public static parseScript (input: string, config: esprima.ParseOptions): ESTree.Program {
|
||||
public static parse (input: string, config: esprima.ParseOptions): ESTree.Program {
|
||||
let lastMeta: esprima.NodeMeta | null = null;
|
||||
|
||||
try {
|
||||
return esprima.parseScript(input, config, (node: ESTree.Node, meta: any) => lastMeta = meta);
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
return esprima.parseModule(input, config, (node: ESTree.Node, meta: any) => lastMeta = meta);
|
||||
} catch (error) {
|
||||
return EsprimaFacade.processParsingError(input, error.message, lastMeta);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
|
||||
* @returns {Program}
|
||||
*/
|
||||
private parseCode (sourceCode: string): ESTree.Program {
|
||||
return EsprimaFacade.parseScript(sourceCode, {
|
||||
return EsprimaFacade.parse(sourceCode, {
|
||||
attachComment: true,
|
||||
loc: this.options.sourceMap
|
||||
});
|
||||
|
||||
@@ -593,6 +593,23 @@ describe('JavaScriptObfuscator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parse module', () => {
|
||||
const regExp: RegExp = /var *test *= *0x1/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
beforeEach(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parse-module.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(code);
|
||||
|
||||
obfuscatedCode = obfuscationResult.getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('should correctly obfuscate a module', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('3.5k variables', function () {
|
||||
this.timeout(200000);
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import {foo} from "./foo";
|
||||
|
||||
var test = 1;
|
||||
@@ -16,7 +16,7 @@ describe('EsprimaFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => EsprimaFacade.parseScript(sourceCode, {});
|
||||
testFunc = () => EsprimaFacade.parse(sourceCode, {});
|
||||
});
|
||||
|
||||
it('should output code preview when `esprima` throws a parse error', () => {
|
||||
@@ -45,7 +45,7 @@ describe('EsprimaFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => EsprimaFacade.parseScript(sourceCode, {});
|
||||
testFunc = () => EsprimaFacade.parse(sourceCode, {});
|
||||
});
|
||||
|
||||
it('should output code preview when `esprima` throws a parse error', () => {
|
||||
@@ -69,7 +69,7 @@ describe('EsprimaFacade', () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => EsprimaFacade.parseScript(sourceCode, {});
|
||||
testFunc = () => EsprimaFacade.parse(sourceCode, {});
|
||||
});
|
||||
|
||||
it('should output code preview when `esprima` throws a parse error', () => {
|
||||
|
||||
@@ -533,9 +533,9 @@
|
||||
"@types/glob" "*"
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/sinon@4.1.3":
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-4.1.3.tgz#2ee25e0e302f31e78a945650a60029e08878eaf8"
|
||||
"@types/sinon@4.3.0":
|
||||
version "4.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-4.3.0.tgz#7f53915994a00ccea24f4e0c24709822ed11a3b1"
|
||||
|
||||
"@types/string-template@1.0.2":
|
||||
version "1.0.2"
|
||||
@@ -1684,9 +1684,9 @@ escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
|
||||
escodegen-wallaby@1.6.17:
|
||||
version "1.6.17"
|
||||
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.17.tgz#3e1f334884d4214c94309cf734ec7cfa0b3d438d"
|
||||
escodegen-wallaby@1.6.18:
|
||||
version "1.6.18"
|
||||
resolved "https://registry.yarnpkg.com/escodegen-wallaby/-/escodegen-wallaby-1.6.18.tgz#95a41e2fdc88687466e43550c7bf136386fd4363"
|
||||
dependencies:
|
||||
esprima "^2.7.1"
|
||||
estraverse "^1.9.1"
|
||||
@@ -3954,9 +3954,9 @@ trim-right@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
|
||||
|
||||
ts-node@5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-5.0.0.tgz#9aa573889ad7949411f972981c209e064705e36f"
|
||||
ts-node@5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-5.0.1.tgz#78e5d1cb3f704de1b641e43b76be2d4094f06f81"
|
||||
dependencies:
|
||||
arrify "^1.0.0"
|
||||
chalk "^2.3.0"
|
||||
@@ -3987,9 +3987,9 @@ tslint-language-service@0.9.8:
|
||||
version "0.9.8"
|
||||
resolved "https://registry.yarnpkg.com/tslint-language-service/-/tslint-language-service-0.9.8.tgz#22a6f2f926b7c0a4cafed3ae1f65021e8008dc96"
|
||||
|
||||
tslint-webpack-plugin@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/tslint-webpack-plugin/-/tslint-webpack-plugin-1.1.1.tgz#cd6a436395a73554530a7a2966ba57bc4f9e2d76"
|
||||
tslint-webpack-plugin@1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/tslint-webpack-plugin/-/tslint-webpack-plugin-1.2.0.tgz#b7ee325ca2fd020c621f1f123268ea674a49070e"
|
||||
dependencies:
|
||||
chalk "^2.1.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user