Best JavaScript code snippet using ts-auto-mock
factory.ts
Source:factory.ts
...4 offset: number;5};6export function createStructReadOffsetNode(structSize: number, elementIndxExp: ts.Expression, fieldOffset: number) {7 const structOffsetNode = ts.factory.createBinaryExpression(8 ts.factory.createNumericLiteral(structSize),9 ts.factory.createToken(ts.SyntaxKind.AsteriskToken),10 elementIndxExp11 );12 return ts.factory.createBinaryExpression(13 structOffsetNode,14 ts.factory.createToken(ts.SyntaxKind.PlusToken),15 ts.factory.createNumericLiteral(fieldOffset)16 );17}18export function createBufferAccessFrom1ByteNode(bufferExp: ts.Expression, structSize: number, elementIndxExp: ts.Expression, fieldOffset: number) {19 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);20 return ts.factory.createElementAccessExpression(21 bufferExp,22 structOffsetNode23 );24}25export function createBufferAccessFrom2ByteNode(bufferExp: ts.Expression, structSize: number, elementIndxExp: ts.Expression, fieldOffset: number) {26 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);27 return ts.factory.createElementAccessExpression(28 bufferExp,29 createRightShiftedExpression(30 ts.factory.createParenthesizedExpression(structOffsetNode),31 ts.factory.createNumericLiteral(1),32 ),33 );34}35export function createBufferAccessFrom4ByteNode(bufferExp: ts.Expression, structSize: number, elementIndxExp: ts.Expression, fieldOffset: number) {36 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);37 return ts.factory.createElementAccessExpression(38 bufferExp,39 createRightShiftedExpression(40 ts.factory.createParenthesizedExpression(structOffsetNode),41 ts.factory.createNumericLiteral(2),42 ),43 );44}45export function createLeftShiftedExpression(expToShift: ts.Expression, shiftExp: ts.Expression) {46 return ts.factory.createParenthesizedExpression(47 ts.factory.createBinaryExpression(48 expToShift,49 ts.factory.createToken(ts.SyntaxKind.LessThanLessThanToken),50 shiftExp,51 )52 );53}54export function createRightShiftedExpression(expToShift: ts.Expression, shiftExp: ts.Expression) {55 return ts.factory.createBinaryExpression(56 expToShift,57 ts.factory.createToken(ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken),58 shiftExp,59 );60}61export function createLogicalAnd(expToAnd: ts.Expression, andExp: ts.Expression) {62 return ts.factory.createBinaryExpression(63 expToAnd,64 ts.factory.createToken(ts.SyntaxKind.AmpersandToken),65 andExp,66 );67}68export function createCommanNode(firstExp: ts.Expression, secondExp: ts.Expression) {69 return ts.factory.createBinaryExpression(70 firstExp,71 ts.factory.createToken(ts.SyntaxKind.CommaToken),72 secondExp,73 );74}75export function createReadBy1Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData) {76 if (fieldData.size === 1) {77 return createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset);78 } else if (fieldData.size === 2) {79 return ts.factory.createParenthesizedExpression(80 ts.factory.createBinaryExpression(81 createLeftShiftedExpression(82 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1),83 ts.factory.createNumericLiteral(8),84 ),85 ts.factory.createToken(ts.SyntaxKind.BarToken),86 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),87 )88 );89 } else if (fieldData.size === 4) {90 return ts.factory.createParenthesizedExpression(91 ts.factory.createBinaryExpression(92 createLeftShiftedExpression(93 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 3),94 ts.factory.createNumericLiteral(24),95 ),96 ts.factory.createToken(ts.SyntaxKind.BarToken),97 ts.factory.createBinaryExpression(98 createLeftShiftedExpression(99 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2),100 ts.factory.createNumericLiteral(16),101 ),102 ts.factory.createToken(ts.SyntaxKind.BarToken),103 ts.factory.createBinaryExpression(104 createLeftShiftedExpression(105 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1),106 ts.factory.createNumericLiteral(8),107 ),108 ts.factory.createToken(ts.SyntaxKind.BarToken),109 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),110 )111 )112 )113 );114 }115 return undefined;116}117export function createReadBy2Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData) {118 if (fieldData.size === 1) {119 return createLogicalAnd(120 createBufferAccessFrom2ByteNode(121 bufferExp,122 structSize,123 elementIndxExp,124 fieldData.offset125 ),126 ts.factory.createNumericLiteral('0xFF'),127 );128 } else if (fieldData.size === 2) {129 return createBufferAccessFrom2ByteNode(130 bufferExp,131 structSize,132 elementIndxExp,133 fieldData.offset134 );135 } else if (fieldData.size === 4) {136 return ts.factory.createParenthesizedExpression(137 ts.factory.createBinaryExpression(138 createLeftShiftedExpression(139 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2),140 ts.factory.createNumericLiteral(16),141 ),142 ts.factory.createToken(ts.SyntaxKind.BarToken),143 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),144 )145 );146 }147 return undefined;148}149export function createReadBy4Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData) {150 if (fieldData.size === 1) {151 return createLogicalAnd(152 createBufferAccessFrom4ByteNode(153 bufferExp,154 structSize,155 elementIndxExp,156 fieldData.offset157 ),158 ts.factory.createNumericLiteral('0xFF'),159 );160 } else if (fieldData.size === 2) {161 return createLogicalAnd(162 createBufferAccessFrom4ByteNode(163 bufferExp,164 structSize,165 elementIndxExp,166 fieldData.offset167 ),168 ts.factory.createNumericLiteral('0xFFFF'),169 );170 } else if (fieldData.size === 4) {171 return createBufferAccessFrom4ByteNode(172 bufferExp,173 structSize,174 elementIndxExp,175 fieldData.offset176 );177 }178 return undefined;179}180// Little-endian181export function createWriteBy1Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData, valueExp: ts.Expression) {182 if (fieldData.size === 1) {183 return ts.factory.createParenthesizedExpression(184 ts.factory.createBinaryExpression(185 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),186 ts.factory.createToken(ts.SyntaxKind.EqualsToken),187 ts.factory.createParenthesizedExpression(188 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))189 )190 )191 );192 } else if (fieldData.size === 2) {193 return createCommanNode(194 ts.factory.createParenthesizedExpression(195 ts.factory.createBinaryExpression(196 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),197 ts.factory.createToken(ts.SyntaxKind.EqualsToken),198 ts.factory.createParenthesizedExpression(199 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))200 )201 )202 ),203 ts.factory.createParenthesizedExpression(204 ts.factory.createBinaryExpression(205 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1),206 ts.factory.createToken(ts.SyntaxKind.EqualsToken),207 ts.factory.createParenthesizedExpression(208 createLogicalAnd(209 ts.factory.createParenthesizedExpression(210 createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('8'))211 ),212 ts.factory.createNumericLiteral('0xFF')213 )214 )215 )216 ),217 );218 } else if (fieldData.size === 4) {219 return createCommanNode(220 ts.factory.createParenthesizedExpression(221 ts.factory.createBinaryExpression(222 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),223 ts.factory.createToken(ts.SyntaxKind.EqualsToken),224 ts.factory.createParenthesizedExpression(225 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))226 )227 )228 ),229 createCommanNode(230 ts.factory.createParenthesizedExpression(231 ts.factory.createBinaryExpression(232 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1),233 ts.factory.createToken(ts.SyntaxKind.EqualsToken),234 // create separete func getNByteFromExp235 ts.factory.createParenthesizedExpression(236 createLogicalAnd(237 ts.factory.createParenthesizedExpression(238 createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('8'))239 ),240 ts.factory.createNumericLiteral('0xFF')241 )242 )243 )244 ),245 createCommanNode(246 ts.factory.createParenthesizedExpression(247 ts.factory.createBinaryExpression(248 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2),249 ts.factory.createToken(ts.SyntaxKind.EqualsToken),250 ts.factory.createParenthesizedExpression(251 createLogicalAnd(252 ts.factory.createParenthesizedExpression(253 createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('16'))254 ),255 ts.factory.createNumericLiteral('0xFF')256 )257 )258 )259 ),260 ts.factory.createParenthesizedExpression(261 ts.factory.createBinaryExpression(262 createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 3),263 ts.factory.createToken(ts.SyntaxKind.EqualsToken),264 ts.factory.createParenthesizedExpression(265 createLogicalAnd(266 ts.factory.createParenthesizedExpression(267 createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('24'))268 ),269 ts.factory.createNumericLiteral('0xFF')270 )271 )272 )273 ),274 )275 )276 );277 }278 return undefined;279}280// Little-endian281export function createWriteBy2Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData, valueExp: ts.Expression) {282 if (fieldData.size === 1) {283 return ts.factory.createParenthesizedExpression(284 ts.factory.createBinaryExpression(285 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),286 ts.factory.createToken(ts.SyntaxKind.EqualsToken),287 ts.factory.createParenthesizedExpression(288 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))289 )290 )291 );292 } else if (fieldData.size === 2) {293 return ts.factory.createParenthesizedExpression(294 ts.factory.createBinaryExpression(295 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),296 ts.factory.createToken(ts.SyntaxKind.EqualsToken),297 ts.factory.createParenthesizedExpression(298 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF'))299 )300 )301 );302 } else if (fieldData.size === 4) {303 return createCommanNode(304 ts.factory.createParenthesizedExpression(305 ts.factory.createBinaryExpression(306 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),307 ts.factory.createToken(ts.SyntaxKind.EqualsToken),308 ts.factory.createParenthesizedExpression(309 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF'))310 )311 )312 ),313 ts.factory.createParenthesizedExpression(314 ts.factory.createBinaryExpression(315 createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2),316 ts.factory.createToken(ts.SyntaxKind.EqualsToken),317 ts.factory.createParenthesizedExpression(318 createLogicalAnd(319 ts.factory.createParenthesizedExpression(320 createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('16'))321 ),322 ts.factory.createNumericLiteral('0xFFFF')323 )324 )325 )326 ),327 );328 }329 return undefined;330}331// Little-endian332export function createWriteBy4Byte(bufferExp: ts.Expression, elementIndxExp: ts.Expression, structSize: number, fieldData: FieldData, valueExp: ts.Expression) {333 if (fieldData.size === 1) {334 return ts.factory.createParenthesizedExpression(335 ts.factory.createBinaryExpression(336 createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),337 ts.factory.createToken(ts.SyntaxKind.EqualsToken),338 ts.factory.createParenthesizedExpression(339 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))340 )341 )342 );343 } else if (fieldData.size === 2) {344 return ts.factory.createParenthesizedExpression(345 ts.factory.createBinaryExpression(346 createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),347 ts.factory.createToken(ts.SyntaxKind.EqualsToken),348 ts.factory.createParenthesizedExpression(349 createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF'))350 )351 )352 );353 } else if (fieldData.size === 4) {354 return ts.factory.createParenthesizedExpression(355 ts.factory.createBinaryExpression(356 createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset),357 ts.factory.createToken(ts.SyntaxKind.EqualsToken),358 valueExp359 )360 );361 }362 return undefined;363}
factory.js
Source:factory.js
2Object.defineProperty(exports, "__esModule", { value: true });3exports.createWriteBy4Byte = exports.createWriteBy2Byte = exports.createWriteBy1Byte = exports.createReadBy4Byte = exports.createReadBy2Byte = exports.createReadBy1Byte = exports.createCommanNode = exports.createLogicalAnd = exports.createRightShiftedExpression = exports.createLeftShiftedExpression = exports.createBufferAccessFrom4ByteNode = exports.createBufferAccessFrom2ByteNode = exports.createBufferAccessFrom1ByteNode = exports.createStructReadOffsetNode = void 0;4const ts = require("typescript");5function createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset) {6 const structOffsetNode = ts.factory.createBinaryExpression(ts.factory.createNumericLiteral(structSize), ts.factory.createToken(ts.SyntaxKind.AsteriskToken), elementIndxExp);7 return ts.factory.createBinaryExpression(structOffsetNode, ts.factory.createToken(ts.SyntaxKind.PlusToken), ts.factory.createNumericLiteral(fieldOffset));8}9exports.createStructReadOffsetNode = createStructReadOffsetNode;10function createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldOffset) {11 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);12 return ts.factory.createElementAccessExpression(bufferExp, structOffsetNode);13}14exports.createBufferAccessFrom1ByteNode = createBufferAccessFrom1ByteNode;15function createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldOffset) {16 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);17 return ts.factory.createElementAccessExpression(bufferExp, createRightShiftedExpression(ts.factory.createParenthesizedExpression(structOffsetNode), ts.factory.createNumericLiteral(1)));18}19exports.createBufferAccessFrom2ByteNode = createBufferAccessFrom2ByteNode;20function createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldOffset) {21 const structOffsetNode = createStructReadOffsetNode(structSize, elementIndxExp, fieldOffset);22 return ts.factory.createElementAccessExpression(bufferExp, createRightShiftedExpression(ts.factory.createParenthesizedExpression(structOffsetNode), ts.factory.createNumericLiteral(2)));23}24exports.createBufferAccessFrom4ByteNode = createBufferAccessFrom4ByteNode;25function createLeftShiftedExpression(expToShift, shiftExp) {26 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(expToShift, ts.factory.createToken(ts.SyntaxKind.LessThanLessThanToken), shiftExp));27}28exports.createLeftShiftedExpression = createLeftShiftedExpression;29function createRightShiftedExpression(expToShift, shiftExp) {30 return ts.factory.createBinaryExpression(expToShift, ts.factory.createToken(ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken), shiftExp);31}32exports.createRightShiftedExpression = createRightShiftedExpression;33function createLogicalAnd(expToAnd, andExp) {34 return ts.factory.createBinaryExpression(expToAnd, ts.factory.createToken(ts.SyntaxKind.AmpersandToken), andExp);35}36exports.createLogicalAnd = createLogicalAnd;37function createCommanNode(firstExp, secondExp) {38 return ts.factory.createBinaryExpression(firstExp, ts.factory.createToken(ts.SyntaxKind.CommaToken), secondExp);39}40exports.createCommanNode = createCommanNode;41function createReadBy1Byte(bufferExp, elementIndxExp, structSize, fieldData) {42 if (fieldData.size === 1) {43 return createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset);44 }45 else if (fieldData.size === 2) {46 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createLeftShiftedExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1), ts.factory.createNumericLiteral(8)), ts.factory.createToken(ts.SyntaxKind.BarToken), createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset)));47 }48 else if (fieldData.size === 4) {49 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createLeftShiftedExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 3), ts.factory.createNumericLiteral(24)), ts.factory.createToken(ts.SyntaxKind.BarToken), ts.factory.createBinaryExpression(createLeftShiftedExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2), ts.factory.createNumericLiteral(16)), ts.factory.createToken(ts.SyntaxKind.BarToken), ts.factory.createBinaryExpression(createLeftShiftedExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1), ts.factory.createNumericLiteral(8)), ts.factory.createToken(ts.SyntaxKind.BarToken), createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset)))));50 }51 return undefined;52}53exports.createReadBy1Byte = createReadBy1Byte;54function createReadBy2Byte(bufferExp, elementIndxExp, structSize, fieldData) {55 if (fieldData.size === 1) {56 return createLogicalAnd(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createNumericLiteral('0xFF'));57 }58 else if (fieldData.size === 2) {59 return createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset);60 }61 else if (fieldData.size === 4) {62 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createLeftShiftedExpression(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2), ts.factory.createNumericLiteral(16)), ts.factory.createToken(ts.SyntaxKind.BarToken), createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset)));63 }64 return undefined;65}66exports.createReadBy2Byte = createReadBy2Byte;67function createReadBy4Byte(bufferExp, elementIndxExp, structSize, fieldData) {68 if (fieldData.size === 1) {69 return createLogicalAnd(createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createNumericLiteral('0xFF'));70 }71 else if (fieldData.size === 2) {72 return createLogicalAnd(createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createNumericLiteral('0xFFFF'));73 }74 else if (fieldData.size === 4) {75 return createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset);76 }77 return undefined;78}79exports.createReadBy4Byte = createReadBy4Byte;80// Little-endian81function createWriteBy1Byte(bufferExp, elementIndxExp, structSize, fieldData, valueExp) {82 if (fieldData.size === 1) {83 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF')))));84 }85 else if (fieldData.size === 2) {86 return createCommanNode(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))))), ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(ts.factory.createParenthesizedExpression(createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('8'))), ts.factory.createNumericLiteral('0xFF'))))));87 }88 else if (fieldData.size === 4) {89 return createCommanNode(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF'))))), createCommanNode(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 1), ts.factory.createToken(ts.SyntaxKind.EqualsToken), 90 // create separete func getNByteFromExp91 ts.factory.createParenthesizedExpression(createLogicalAnd(ts.factory.createParenthesizedExpression(createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('8'))), ts.factory.createNumericLiteral('0xFF'))))), createCommanNode(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(ts.factory.createParenthesizedExpression(createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('16'))), ts.factory.createNumericLiteral('0xFF'))))), ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom1ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 3), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(ts.factory.createParenthesizedExpression(createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('24'))), ts.factory.createNumericLiteral('0xFF'))))))));92 }93 return undefined;94}95exports.createWriteBy1Byte = createWriteBy1Byte;96// Little-endian97function createWriteBy2Byte(bufferExp, elementIndxExp, structSize, fieldData, valueExp) {98 if (fieldData.size === 1) {99 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF')))));100 }101 else if (fieldData.size === 2) {102 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF')))));103 }104 else if (fieldData.size === 4) {105 return createCommanNode(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF'))))), ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom2ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset + 2), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(ts.factory.createParenthesizedExpression(createRightShiftedExpression(valueExp, ts.factory.createNumericLiteral('16'))), ts.factory.createNumericLiteral('0xFFFF'))))));106 }107 return undefined;108}109exports.createWriteBy2Byte = createWriteBy2Byte;110// Little-endian111function createWriteBy4Byte(bufferExp, elementIndxExp, structSize, fieldData, valueExp) {112 if (fieldData.size === 1) {113 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFF')))));114 }115 else if (fieldData.size === 2) {116 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createParenthesizedExpression(createLogicalAnd(valueExp, ts.factory.createNumericLiteral('0xFFFF')))));117 }118 else if (fieldData.size === 4) {119 return ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(createBufferAccessFrom4ByteNode(bufferExp, structSize, elementIndxExp, fieldData.offset), ts.factory.createToken(ts.SyntaxKind.EqualsToken), valueExp));120 }121 return undefined;122}...
replacer.ts
Source:replacer.ts
...26 adds(27 address,28 arrayJoin(29 ts.createAdd(30 ts.createSubtract(ts.createNumericLiteral('40'), ts.createPropertyAccess(address, 'length')),31 ts.createNumericLiteral('1'),32 ),33 '0',34 ),35 ),36 ),37 ),38 DeclareConstant(39 truncated,40 CreateCall(41 ts.createPropertyAccess(name, 'slice'),42 [43 ts.createNumericLiteral('0'),44 ts.createNumericLiteral('36'),45 ]46 )47 ),48 DeclareConstant(49 label,50 adds(51 ts.createAdd(52 ts.createStringLiteral('__'),53 truncated,54 ),55 arrayJoin(56 ts.createSubtract(57 ts.createNumericLiteral('37'),58 ts.createPropertyAccess(truncated, 'length'),59 ),60 '_',61 ),62 ts.createStringLiteral('__'),63 ),64 ), 65 ts.createWhile(66 ts.createBinary(67 CreateCall(ts.createPropertyAccess(bytecode, 'indexOf'), [label]), 68 ts.SyntaxKind.GreaterThanEqualsToken, 69 ts.createNumericLiteral('0'),70 ),71 ts.createExpressionStatement(ts.createAssignment(72 bytecode,73 CreateCall(74 ts.createPropertyAccess(bytecode, 'replace'),75 [label, address]76 ),77 ))78 ),79 ts.createReturn(bytecode)80 ], true),81 )82}83function adds(...exp: ts.Expression[]) {...
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock';2import { createIdentifier } from 'ts-auto-mock';3import { createCall } from 'ts-auto-mock';4import { createPropertyAccess } from 'ts-auto-mock';5import { createFunctionDeclaration } from 'ts-auto-mock';6import { createParameter } from 'ts-auto-mock';7import { createBlock } from 'ts-auto-mock';8import { createReturn } from 'ts-auto-mock';9import { createVariableStatement } from 'ts-auto-mock';10import { createVariableDeclarationList } from 'ts-auto-mock';11import { createVariableDeclaration } from 'ts-auto-mock';12import { createStringLiteral } from 'ts-auto-mock';13import { createArrayLiteral } from 'ts-auto-mock';14import { createObjectLiteral } from 'ts-auto-mock';15import { createPropertyAssignment } from 'ts-auto-mock';16import { createTypeReferenceNode } from 'ts-auto-mock';17import { createFunctionExpression } from 'ts-auto-mock';18import { createArrowFunction } from 'ts-auto-mock';19import { createThis } from 'ts-auto-mock';
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock/extension';2describe('createNumericLiteral', () => {3 it('should create a numeric literal', () => {4 expect(createNumericLiteral(1)).toEqual(1);5 });6});7import { createObjectLiteral } from 'ts-auto-mock/extension';8describe('createObjectLiteral', () => {9 it('should create an object literal', () => {10 expect(createObjectLiteral({ a: 1 })).toEqual({ a: 1 });11 });12});13import { createParenthesizedExpression } from 'ts-auto-mock/extension';14describe('createParenthesizedExpression', () => {15 it('should create a parenthesized expression', () => {16 expect(createParenthesizedExpression(1)).toEqual(1);17 });18});19import { createPropertyAccessExpression } from 'ts-auto-mock/extension';20describe('createPropertyAccessExpression', () => {21 it('should create a property access expression', () => {22 expect(createPropertyAccessExpression('a')).toEqual('a');23 });24});25import { createPropertyAssignment } from 'ts-auto-mock/extension';26describe('createPropertyAssignment', () => {27 it('should create a property assignment', () => {28 expect(createPropertyAssignment('a', 1)).toEqual({ a: 1 });29 });30});31import { createPropertySignature } from 'ts-auto-mock/extension';32describe('createPropertySignature', () => {33 it('should create a property signature', () => {34 expect(createPropertySignature('a', 1)).toEqual({ a: 1 });35 });36});
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock';2export const test1 = createNumericLiteral(1);3export const test2 = createNumericLiteral(1.1);4export const test3 = createNumericLiteral(1.1e10);5export const test4 = createNumericLiteral(1.1e-10);6export const test5 = createNumericLiteral(1.1e+10);7export const test6 = createNumericLiteral(0x1);8export const test7 = createNumericLiteral(0o1);9export const test8 = createNumericLiteral(0b1);10export const test9 = createNumericLiteral(0x1.1);11export const test10 = createNumericLiteral(0o1.1);12export const test11 = createNumericLiteral(0b1.1);13export const test12 = createNumericLiteral(0x1e10);14export const test13 = createNumericLiteral(0o1e10);15export const test14 = createNumericLiteral(0b1e10);16export const test15 = createNumericLiteral(0x1e-10);17export const test16 = createNumericLiteral(0o1e-10);18export const test17 = createNumericLiteral(0b1e-10);19export const test18 = createNumericLiteral(0x1e+10);20export const test19 = createNumericLiteral(0o1e+10);21export const test20 = createNumericLiteral(0b1e+10);22export const test21 = createNumericLiteral(0x1.1e10);23export const test22 = createNumericLiteral(0o1.1e10);24export const test23 = createNumericLiteral(0b1.1e10);25export const test24 = createNumericLiteral(0x1.1e-10);26export const test25 = createNumericLiteral(0o1.1e-10);27export const test26 = createNumericLiteral(0b1.1e-10);28export const test27 = createNumericLiteral(0x1.1e+10);29export const test28 = createNumericLiteral(0o1.1e+10);30export const test29 = createNumericLiteral(0b1.1e+10);31export const test30 = createNumericLiteral(0x1.1p10);
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock';2const numericLiteral = createNumericLiteral(10);3console.log(numericLiteral);4import { createNumericLiteral } from 'ts-auto-mock';5const numericLiteral = createNumericLiteral('10');6console.log(numericLiteral);7import { createNumericLiteral } from 'ts-auto-mock';8const numericLiteral = createNumericLiteral('10.1');9console.log(numericLiteral);10import { createNumericLiteral } from 'ts-auto-mock';11const numericLiteral = createNumericLiteral('10.1.1');12console.log(numericLiteral);13import { createNumericLiteral } from 'ts-auto-mock';14const numericLiteral = createNumericLiteral('
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock';2const myNumericLiteral = createNumericLiteral(42);3import { createStringLiteral } from 'ts-auto-mock';4const myStringLiteral = createStringLiteral('Hello World');5import { createTrue } from 'ts-auto-mock';6const myTrue = createTrue();7import { createFalse } from 'ts-auto-mock';8const myFalse = createFalse();9import { createNull } from 'ts-auto-mock';10const myNull = createNull();11import { createUndefined } from 'ts-auto-mock';12const myUndefined = createUndefined();13import { createThis } from 'ts-auto-mock';14const myThis = createThis();15import { createArray } from 'ts-auto-mock';16const myArray = createArray();17import { createArrayWith } from 'ts-auto-mock';18const myArray = createArrayWith(1, 2, 3, 4, 5);19import { createTypeLiteral } from 'ts-auto-mock';20const myTypeLiteral = createTypeLiteral();
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock/extension';2export const test1: number = createNumericLiteral();3import { createNumericLiteral } from 'ts-auto-mock/extension';4export const test2: number = createNumericLiteral(1);5import { createNumericLiteral } from 'ts-auto-mock/extension';6export const test3: number = createNumericLiteral(1, 2);7import { createNumericLiteral } from 'ts-auto-mock/extension';8export const test4: number = createNumericLiteral(1, 2, 3);9import { createNumericLiteral } from 'ts-auto-mock/extension';10export const test5: number = createNumericLiteral(1, 2, 3, 4);11import { createNumericLiteral } from 'ts-auto-mock/extension';12export const test6: number = createNumericLiteral(1, 2, 3, 4, 5);13import { createNumericLiteral } from 'ts-auto-mock/extension';14export const test7: number = createNumericLiteral(1, 2, 3, 4, 5, 6);
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock/extension';2const mock = createNumericLiteral(1);3import { createObjectLiteral } from 'ts-auto-mock/extension';4const mock = createObjectLiteral({ name: 'test' });5import { createPropertyAssignment } from 'ts-auto-mock/extension';6const mock = createPropertyAssignment('name', 'test');7import { createPropertySignature } from 'ts-auto-mock/extension';8const mock = createPropertySignature('name', 'string');9import { createQualifiedName } from 'ts-auto-mock/extension';10const mock = createQualifiedName('name', 'test');11import { createShorthandPropertyAssignment } from 'ts-auto-mock/extension';12const mock = createShorthandPropertyAssignment('name');13import { createStringLiteral } from 'ts-auto-mock/extension';14const mock = createStringLiteral('test');15import { createTypeAliasDeclaration } from 'ts-auto-mock/extension';16const mock = createTypeAliasDeclaration('name', 'type');
Using AI Code Generation
1import { createNumericLiteral } from 'ts-auto-mock/extension';2export const testValue = createNumericLiteral(10);3import { createStringLiteral } from 'ts-auto-mock/extension';4export const testValue = createStringLiteral('test');5import { createBooleanLiteral } from 'ts-auto-mock/extension';6export const testValue = createBooleanLiteral(true);7import { createNullLiteral } from 'ts-auto-mock/extension';8export const testValue = createNullLiteral();9import { createUndefinedLiteral } from 'ts-auto-mock/extension';10export const testValue = createUndefinedLiteral();11import { createSymbolLiteral } from 'ts-auto-mock/extension';12export const testValue = createSymbolLiteral('test');13import { createObjectLiteral } from 'ts-auto-mock/extension';14export const testValue = createObjectLiteral({15});16import { createArrayLiteral } from 'ts-auto-mock/extension';
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!