mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Disabled obfuscation of tagged template literals.
Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/243
This commit is contained in:
@@ -3,6 +3,7 @@ Change Log
|
||||
v0.16.0
|
||||
---
|
||||
* Correct obfuscation of object rest and spread properties
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/243
|
||||
|
||||
v0.15.0
|
||||
---
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -36,6 +36,7 @@ export enum NodeType {
|
||||
Super = 'Super',
|
||||
SwitchCase = 'SwitchCase',
|
||||
SwitchStatement = 'SwitchStatement',
|
||||
TaggedTemplateExpression = 'TaggedTemplateExpression',
|
||||
TemplateLiteral = 'TemplateLiteral',
|
||||
TryStatement = 'TryStatement',
|
||||
UnaryExpression = 'UnaryExpression',
|
||||
|
||||
@@ -38,6 +38,15 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer {
|
||||
return node && NodeGuards.isLiteralNode(node) && typeof node.value === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @param {Node | null} parentNode
|
||||
* @returns {boolean}
|
||||
*/
|
||||
private static isValidTemplateLiteralNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.TemplateLiteral {
|
||||
return NodeGuards.isTemplateLiteralNode(node) && !NodeGuards.isTaggedTemplateExpressionNode(parentNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TransformationStage} transformationStage
|
||||
* @returns {IVisitor | null}
|
||||
@@ -47,7 +56,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer {
|
||||
case TransformationStage.Converting:
|
||||
return {
|
||||
leave: (node: ESTree.Node, parentNode: ESTree.Node | null) => {
|
||||
if (parentNode && NodeGuards.isTemplateLiteralNode(node)) {
|
||||
if (parentNode && TemplateLiteralTransformer.isValidTemplateLiteralNode(node, parentNode)) {
|
||||
return this.transformNode(node, parentNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,6 +351,14 @@ export class NodeGuards {
|
||||
return node.type === NodeType.SwitchCase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isTaggedTemplateExpressionNode (node: ESTree.Node): node is ESTree.TaggedTemplateExpression {
|
||||
return node.type === NodeType.TaggedTemplateExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
|
||||
+22
-1
@@ -132,7 +132,28 @@ describe('TemplateLiteralTransformer', () => {
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(obfuscationResult.getObfuscatedCode(), /^var *test *= *0x1 *\+ *0x1 *\+ *'\\x20abc\\x20' *\+ *\(0x1 *\+ *0x1\);$/);
|
||||
assert.match(
|
||||
obfuscationResult.getObfuscatedCode(),
|
||||
/^var *test *= *0x1 *\+ *0x1 *\+ *'\\x20abc\\x20' *\+ *\(0x1 *\+ *0x1\);$/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #6: tagged template literal', () => {
|
||||
it('shouldn\'t transform es6 tagged template literal to es5', () => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/tagged-template-literal.js');
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
unicodeEscapeSequence: false
|
||||
}
|
||||
);
|
||||
|
||||
assert.match(
|
||||
obfuscationResult.getObfuscatedCode(),
|
||||
/tag`foo *\${0x1 *\+ *0x1} *bar`;/
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function tag(strings) {
|
||||
console.log(strings.raw[0]);
|
||||
}
|
||||
|
||||
tag`foo ${1 + 1} bar`;
|
||||
Reference in New Issue
Block a user