mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
some optimisations and new tests
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
var object = {
|
||||
foo: {
|
||||
bar: function () {
|
||||
|
||||
},
|
||||
},
|
||||
1: {
|
||||
baz: function () {
|
||||
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var object1 = {
|
||||
foo: {
|
||||
1: function () {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var foo = 'foo';
|
||||
|
||||
object[foo].bar();
|
||||
object[1].baz();
|
||||
|
||||
object1['foo'][1]();
|
||||
@@ -99,7 +99,7 @@ function getFunctionExpressionById (astTree: ESTree.Node, id: string): ESTree.Fu
|
||||
* @param name
|
||||
* @returns {ESTree.FunctionExpression|null}
|
||||
*/
|
||||
function getObjectFunctionExpressionByName (astTree: ESTree.Node, objectName: string, name: string): ESTree.FunctionExpression|null {
|
||||
function getObjectFunctionExpressionByName (astTree: ESTree.Node, objectName: string, name: string|number): ESTree.FunctionExpression|null {
|
||||
let functionExpressionNode: ESTree.FunctionExpression|null = null,
|
||||
targetObjectExpressionNode: ESTree.ObjectExpression|null = null;
|
||||
|
||||
@@ -288,10 +288,10 @@ describe('StackTraceAnalyzer', () => {
|
||||
assert.deepEqual(stackTraceData, expectedStackTraceData);
|
||||
});
|
||||
|
||||
it('should returns correct BlockScopeTraceData - variant #5: call expression of object member', () => {
|
||||
it('should returns correct BlockScopeTraceData - variant #5: call expression of object member #1', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member.js')
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-1.js')
|
||||
)
|
||||
);
|
||||
|
||||
@@ -344,6 +344,31 @@ describe('StackTraceAnalyzer', () => {
|
||||
assert.deepEqual(stackTraceData, expectedStackTraceData);
|
||||
});
|
||||
|
||||
it('should returns correct BlockScopeTraceData - variant #5: call expression of object member #2', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
readFileAsString('./test/fixtures/stack-trace-analyzer/call-expression-of-object-member-2.js')
|
||||
)
|
||||
);
|
||||
|
||||
expectedStackTraceData = [
|
||||
{
|
||||
name: 'baz',
|
||||
callee: (<ESTree.FunctionExpression>getObjectFunctionExpressionByName(astTree, 'object', 'baz')).body,
|
||||
stackTrace: []
|
||||
},
|
||||
{
|
||||
name: 1,
|
||||
callee: (<ESTree.FunctionExpression>getObjectFunctionExpressionByName(astTree, 'object1', 1)).body,
|
||||
stackTrace: []
|
||||
},
|
||||
];
|
||||
|
||||
stackTraceData = new StackTraceAnalyzer(astTree.body).analyze();
|
||||
|
||||
assert.deepEqual(stackTraceData, expectedStackTraceData);
|
||||
});
|
||||
|
||||
it('should returns correct BlockScopeTraceData - variant #6: no call expressions', () => {
|
||||
astTree = NodeMocks.getProgramNode(
|
||||
NodeUtils.convertCodeToStructure(
|
||||
|
||||
Reference in New Issue
Block a user