mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed parsing error when await is used as an identifier in non-async context (#1376)
This commit is contained in:
@@ -3,6 +3,7 @@ Change Log
|
||||
v5.2.1
|
||||
---
|
||||
* Fixed `transformObjectKeys` incorrectly hoisting object literal outside of loop when loop body is a single statement without braces, causing all iterations to share the same object reference. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1300
|
||||
* Fixed parsing error when `await` is used as an identifier in non-async context. Fixes https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127
|
||||
|
||||
v5.2.0
|
||||
---
|
||||
|
||||
@@ -58,7 +58,11 @@ export class ASTParserFacade {
|
||||
const comments: ESTree.Comment[] = [];
|
||||
const config: acorn.Options = {
|
||||
...inputConfig,
|
||||
allowAwaitOutsideFunction: true,
|
||||
allowAwaitOutsideFunction: false,
|
||||
allowReserved: true,
|
||||
allowImportExportEverywhere: true,
|
||||
allowReturnOutsideFunction: true,
|
||||
allowSuperOutsideMethod: true,
|
||||
onComment: comments,
|
||||
sourceType
|
||||
};
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
const x = await Promise.resolve(1);
|
||||
console.log(x);
|
||||
@@ -0,0 +1 @@
|
||||
try { await; } catch { console.log('caught'); }
|
||||
@@ -0,0 +1,43 @@
|
||||
import { assert } from 'chai';
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../../src/options/presets/NoCustomNodes';
|
||||
import { readFileAsString } from '../../helpers/readFileAsString';
|
||||
import { JavaScriptObfuscator } from '../../../src/JavaScriptObfuscatorFacade';
|
||||
|
||||
//
|
||||
// https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1127
|
||||
//
|
||||
describe('Issue #1127', () => {
|
||||
describe('`await` used as identifier should not crash', () => {
|
||||
let testFunc: () => string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/issue1127.js');
|
||||
|
||||
testFunc = () =>
|
||||
JavaScriptObfuscator.obfuscate(code, {
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('does not crash on obfuscating', () => {
|
||||
assert.doesNotThrow(testFunc);
|
||||
});
|
||||
});
|
||||
|
||||
describe('top-level await should still work', () => {
|
||||
let testFunc: () => string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/issue1127-top-level-await.js');
|
||||
|
||||
testFunc = () =>
|
||||
JavaScriptObfuscator.obfuscate(code, {
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('does not crash on obfuscating', () => {
|
||||
assert.doesNotThrow(testFunc);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user