Fixed runtime error Uncaught SyntaxError: yield is a reserved identifier when deadCodeInjection is enabled

This commit is contained in:
sanex3339
2020-07-27 23:19:53 +03:00
parent 27a9e18a46
commit 5a666436f1
13 changed files with 141 additions and 47 deletions
@@ -6,6 +6,8 @@ import * as ESTree from 'estree';
import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
import { TStatement } from '../../types/node/TStatement';
import { StringSeparator } from '../../enums/StringSeparator';
import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
import { IOptions } from '../../interfaces/options/IOptions';
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
@@ -79,6 +81,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
protected getNodeStructure (): TStatement[] {
const controllerIdentifierName: string = this.randomGenerator.getRandomString(6);
const indexIdentifierName: string = this.randomGenerator.getRandomString(6);
const structure: ESTree.BlockStatement = NodeFactory.blockStatementNode([
NodeFactory.variableDeclarationNode(
[
@@ -87,12 +90,12 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
NodeFactory.callExpressionNode(
NodeFactory.memberExpressionNode(
NodeFactory.literalNode(
this.originalKeysIndexesInShuffledArray.join('|')
this.originalKeysIndexesInShuffledArray.join(StringSeparator.VerticalLine)
),
NodeFactory.identifierNode('split')
),
[
NodeFactory.literalNode('|')
NodeFactory.literalNode(StringSeparator.VerticalLine)
]
)
)
+2 -1
View File
@@ -1,4 +1,5 @@
export enum StringSeparator {
Dot = '.',
Comma = ',',
Dot = '.',
VerticalLine = '|'
}
+2 -1
View File
@@ -49,5 +49,6 @@ export enum NodeType {
UpdateExpression = 'UpdateExpression',
VariableDeclaration = 'VariableDeclaration',
VariableDeclarator = 'VariableDeclarator',
WhileStatement = 'WhileStatement'
WhileStatement = 'WhileStatement',
YieldExpression = 'YieldExpression'
}
@@ -104,6 +104,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|| NodeGuards.isBreakStatementNode(targetNode)
|| NodeGuards.isContinueStatementNode(targetNode)
|| NodeGuards.isAwaitExpressionNode(targetNode)
|| NodeGuards.isYieldExpressionNode(targetNode)
|| NodeGuards.isSuperNode(targetNode);
}
+8
View File
@@ -421,4 +421,12 @@ export class NodeGuards {
public static isWhileStatementNode (node: ESTree.Node): node is ESTree.WhileStatement {
return node.type === NodeType.WhileStatement;
}
/**
* @param {Node} node
* @returns {boolean}
*/
public static isYieldExpressionNode (node: ESTree.Node): node is ESTree.YieldExpression {
return node.type === NodeType.YieldExpression;
}
}