New option: stringArrayIndexShift enables additional index shift for all string array calls

This commit is contained in:
sanex
2020-11-14 10:15:42 +03:00
parent 44ac6c3ec8
commit 4f33c76da1
25 changed files with 297 additions and 82 deletions
@@ -20,6 +20,12 @@ import { NodeUtils } from '../../node/NodeUtils';
@injectable()
export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper {
/**
* @type {number}
*/
@initializable()
protected indexShiftAmount!: number;
/**
* @type {string}
*/
@@ -68,13 +74,16 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
/**
* @param {string} stringArrayName
* @param {string} stringArrayCallsWrapperName
* @param {number} indexShiftAmount
*/
public initialize (
stringArrayName: string,
stringArrayCallsWrapperName: string
stringArrayCallsWrapperName: string,
indexShiftAmount: number
): void {
this.stringArrayName = stringArrayName;
this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
this.indexShiftAmount = indexShiftAmount;
}
/**
@@ -97,7 +106,8 @@ export class StringArrayCallsWrapperCodeHelper extends AbstractCustomCodeHelper
this.customCodeHelperFormatter.formatTemplate(StringArrayCallsWrapperTemplate(), {
decodeCodeHelperTemplate,
stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
stringArrayName: this.stringArrayName
stringArrayName: this.stringArrayName,
indexShiftAmount: this.indexShiftAmount
}),
{
reservedNames: preservedNames
@@ -142,7 +142,8 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
stringArrayCallsWrapperCodeHelper.initialize(
stringArrayName,
stringArrayCallsWrapperName
stringArrayCallsWrapperName,
this.stringArrayStorage.getIndexShiftAmount()
);
this.customCodeHelpers.set(stringArrayCallsWrapperCodeHelperName, stringArrayCallsWrapperCodeHelper);
@@ -151,9 +152,11 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
// stringArrayRotateFunction helper initialize
const stringArrayRotateFunctionCodeHelper: ICustomCodeHelper<TInitialData<StringArrayRotateFunctionCodeHelper>> =
this.customCodeHelperFactory(CustomCodeHelper.StringArrayRotateFunction);
const stringArrayRotationAmount: number = this.stringArrayStorage.getRotationAmount();
stringArrayRotateFunctionCodeHelper.initialize(stringArrayName, stringArrayRotationAmount);
stringArrayRotateFunctionCodeHelper.initialize(
stringArrayName,
this.stringArrayStorage.getRotationAmount()
);
if (this.options.rotateStringArray) {
this.customCodeHelpers.set(CustomCodeHelper.StringArrayRotateFunction, stringArrayRotateFunctionCodeHelper);
@@ -4,7 +4,7 @@
export function StringArrayCallsWrapperTemplate (): string {
return `
const {stringArrayCallsWrapperName} = function (index, key) {
index = index - 0;
index = index - {indexShiftAmount};
let value = {stringArrayName}[index];