How to use normalizeProperty method in wpt

Best JavaScript code snippet using wpt

index.js

Source:index.js Github

copy

Full Screen

...62}63function normalizeType(type, ...args) {64 return call(normalizers, `normalize_${type}`, ...args)65}66function normalizeProperty(type, property, propertyType, ...args) {67 return call(normalizers, `normalize_${type}_${property}_${propertyType}`, ...args)68}69const normalizers = {70 ...buildNormalizers(types),71 normalize_Identifier,72 normalize_Literal,73 normalize_Program,74 normalize_Super,75 normalize_ExpressionStatement,76 normalize_Directive,77 normalize_BlockStatement,78 normalize_FunctionBody,79 normalize_EmptyStatement,80 normalize_DebuggerStatement,81 normalize_WithStatement,82 normalize_ReturnStatement,83 normalize_LabeledStatement,84 normalize_BreakStatement,85 normalize_ContinueStatement,86 normalize_IfStatement,87 normalize_SwitchStatement,88 normalize_SwitchCase,89 normalize_ThrowStatement,90 normalize_TryStatement,91 normalize_CatchClause,92 normalize_BigIntLiteral,93 normalize_WhileStatement,94 normalize_DoWhileStatement,95 normalize_ForStatement,96 normalize_ForInStatement,97 normalize_ForOfStatement,98 normalize_FunctionDeclaration,99 normalize_VariableDeclaration,100 normalize_VariableDeclarator,101 normalize_ThisExpression,102 normalize_ArrayExpression,103 normalize_ObjectExpression,104 normalize_Property,105 normalize_FunctionExpression,106 normalize_ArrowFunctionExpression,107 normalize_YieldExpression,108 normalize_TemplateLiteral,109 normalize_TaggedTemplateExpression,110 normalize_TemplateElement,111 normalize_UnaryExpression,112 normalize_UpdateExpression,113 normalize_BinaryExpression,114 normalize_AssignmentExpression,115 normalize_LogicalExpression,116 normalize_MemberExpression,117 normalize_ConditionalExpression,118 normalize_CallExpression,119 normalize_NewExpression,120 normalize_SequenceExpression,121 normalize_SpreadElement,122 normalize_ArrayPattern,123 normalize_ObjectPattern,124 normalize_RestElement,125 normalize_AssignmentPattern,126 normalize_ClassBody,127 normalize_MethodDefinition,128 normalize_ClassDeclaration,129 normalize_ClassExpression,130 normalize_MetaProperty,131 normalize_ModuleDeclaration,132 normalize_ModuleSpecifier,133 normalize_ImportDeclaration,134 normalize_ImportSpecifier,135 normalize_ImportDefaultSpecifier,136 normalize_ImportNamespaceSpecifier,137 normalize_ExportNamedDeclaration,138 normalize_ExportSpecifier,139 normalize_ExportDefaultDeclaration,140 normalize_ExportAllDeclaration,141 normalize_AwaitExpression,142 normalize_ImportExpression,143 normalize_null,144}145function normalize_null() {146 return [null, []]147}148function normalize_Identifier(node, scope) {149 return [node, []]150}151function normalize_Literal(node, scope) {152 return [node, []]153}154function normalize_Program(node, scope) {155 const body = []156 node.body.forEach(n => {157 const [normalizedNode, normalizedExpressions]158 = normalizeProperty(node.type, 'body', n.type, n, scope)159 if (normalizedNode.type === 'EmptyStatement') return160 body.push(...normalizedExpressions)161 if (Array.isArray(normalizedNode)) {162 body.push(...normalizedNode)163 } else {164 body.push(normalizedNode)165 }166 })167 return createProgram(body)168}169function normalize_Super(node, scope) {170}171function normalize_ExpressionStatement(node, scope) {172 return normalizeProperty(node.type, 'expression', node.expression.type, node.expression, scope)173}174function normalize_Directive(node, scope) {175}176function normalize_BlockStatement(node, scope) {177 const body = []178 node.body.forEach(bd => {179 const [data, expressions] = normalizeProperty(node.type, 'body', bd.type, bd, scope)180 if (data.type === 'EmptyStatement') return181 body.push(...expressions)182 if (Array.isArray(data)) {183 body.push(...data)184 } else {185 body.push(data)186 }187 })188 return [189 createBlockStatement(body),190 []191 ]192}193function normalize_FunctionBody(node, scope) {194}195function normalize_EmptyStatement(node, scope) {196 return [node, []]197}198function normalize_DebuggerStatement(node, scope) {199 return [node, []]200}201function normalize_WithStatement(node, scope) {202}203function normalize_ReturnStatement(node, scope) {204 const exps = []205 const [argument, argumentExps]206 = normalizeProperty(node.type, 'argument', node.argument?.type ?? null, node.argument, scope, false)207 exps.push(...argumentExps)208 return [209 createReturnStatement(argument),210 exps211 ]212}213function normalize_LabeledStatement(node, scope) {214 const [body] = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)215 const [label] = normalizeProperty(node.type, 'label', node.label.type, node.label, scope)216 return [217 createLabeledStatement(label, body),218 []219 ]220}221function normalize_BreakStatement(node, scope) {222 return [223 node,224 []225 ]226}227function normalize_ContinueStatement(node, scope) {228 return [node, []]229}230function normalize_IfStatement(node, scope) {231 const top = []232 const [test, testExps] = normalizeProperty(node.type, 'test', node.test.type, node.test, scope, false)233 top.push(...testExps)234 let [consequent, consequentExps]235 = normalizeProperty(node.type, 'consequent', node.consequent.type, node.consequent, scope)236 if (consequent.type !== 'BlockStatement') {237 consequent = createBlockStatement([consequent])238 }239 let alternate = null240 let alternateExps241 if (node.alternate) {242 [alternate, alternateExps]243 = normalizeProperty(node.type, 'alternate', node.alternate.type, node.alternate, scope)244 if (alternate.type === 'IfStatement') {245 top.push(...alternateExps)246 } else if (alternate.type !== 'BlockStatement') {247 alternate = createBlockStatement([alternate])248 }249 }250 const ifStatement = createIfStatement(test, consequent, alternate)251 return [ifStatement, top]252}253function normalize_SwitchStatement(node, scope) {254 const exps = []255 const [discriminant, discriminantExps]256 = normalizeProperty(node.type, 'discriminant', node.discriminant.type, node.discriminant, scope)257 exps.push(...discriminantExps)258 const cases = []259 node.cases.forEach(cse => {260 const [c, caseExps] = normalizeProperty(node.type, 'cases', cse.type, cse, scope)261 cases.push(c)262 exps.push(...caseExps)263 })264 return [265 createSwitchStatement(discriminant, cases),266 exps267 ]268}269function normalize_SwitchCase(node, scope) {270 const exps = []271 const consequent = []272 node.consequent.forEach(c => {273 const [cons, consExps] = normalizeProperty(node.type, 'consequent', c.type, c, scope)274 if (Array.isArray(cons)) {275 consequent.push(...cons)276 } else {277 consequent.push(cons)278 }279 exps.push(...consExps)280 })281 const [test, testExps]282 = normalizeProperty(node.type, 'test', node.test?.type ?? null, node.test, scope)283 exps.push(...testExps)284 return [285 createSwitchCase(test, consequent),286 exps287 ]288}289function normalize_ThrowStatement(node, scope) {290 const [argument, argumentExps] = normalizeProperty(node.type, 'argument', node.argument.type, node.argument, scope)291 return [292 createThrowStatement(argument),293 argumentExps294 ]295}296function normalize_TryStatement(node, scope) {297 const exps = []298 const [block, blockExps]299 = normalizeProperty(node.type, 'block', node.block.type, node.block, scope)300 const [handler, handlerExps]301 = normalizeProperty(node.type, 'handler', node.handler.type, node.handler, scope)302 const [finalizer, finalizerExps]303 = normalizeProperty(node.type, 'finalizer', node.finalizer?.type ?? null, node.finalizer, scope)304 return [305 createTryStatement(block, handler, finalizer),306 exps307 ]308}309function normalize_CatchClause(node, scope) {310 const exps = []311 const [param]312 = normalizeProperty(node.type, 'param', node.param?.type ?? null, node.param, scope)313 const [body, bodyExps]314 = normalizeProperty(node.type, 'body', node.body?.type, node.body, scope)315 exps.push(...bodyExps)316 return [317 createCatchClause(param, body),318 exps319 ]320}321function normalize_BigIntLiteral(node, scope) {322}323function normalize_WhileStatement(node, scope) {324 const [test, testExps]325 = normalizeProperty(node.type, 'test', node.test.type, node.test, scope, false)326 let [body, bodyExps]327 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)328 if (body.type !== 'BlockStatement') {329 body = createBlockStatement([body])330 }331 body.body.unshift(...bodyExps)332 let newBody333 let simple = false334 if (test.type === 'Literal' && test.value === true) {335 newBody = body.body336 simple = true337 } else {338 newBody = [339 ...testExps,340 createIfStatement(341 test,342 body,343 createBlockStatement([344 createBreakStatement()345 ])346 )347 ]348 }349 const whileStatement = createWhileStatement(createLiteral(true), newBody)350 whileStatement.simple = simple351 return [whileStatement, []]352}353function normalize_DoWhileStatement(node, scope) {354 const [test, testExps]355 = normalizeProperty(node.type, 'test', node.test.type, node.test, scope, true)356 const [body, bodyExps]357 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)358 body.body.unshift(...bodyExps)359 const newBody = [360 ...testExps,361 createIfStatement(362 test,363 body,364 createBlockStatement([365 createBreakStatement()366 ])367 )368 ]369 const whileStatement = createWhileStatement(createLiteral(true), newBody)370 return [whileStatement, []]371}372function normalize_ForStatement(node, scope) {373 let [init, initExps] = normalizeProperty(node.type, 'init', node.init?.type ?? null, node.init, scope)374 const [test, testExps] = normalizeProperty(node.type, 'test', node.test?.type ?? null, node.test, scope, false)375 let [update, updateExps] = normalizeProperty(node.type, 'update', node.update?.type ?? null, node.update, scope)376 let [body, bodyExps] = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)377 if (init) {378 if (!Array.isArray(init)) init = [init]379 } else {380 init = []381 }382 if (update) {383 if (!Array.isArray(update)) update = [update]384 } else {385 update = []386 }387 if (body.type !== 'BlockStatement') {388 body = createBlockStatement(Array.isArray(body) ? body : [body])389 }390 const label = `fork${scope.index++}`391 const block = createBlockStatement([392 ...initExps,393 ...init,394 createLabeledStatement(label),395 createWhileStatement(396 createLiteral(true),397 [398 ...testExps,399 createIfStatement(test,400 createBlockStatement([401 ...body.body,402 ...updateExps,403 ...update404 ]),405 createBlockStatement([406 createBreakStatement(label)407 ])408 )409 ]410 )411 ])412 return [block, []]413}414function normalize_ForInStatement(node, scope) {415 const exps = []416 const [left, leftExps]417 = normalizeProperty(node.type, 'left', node.left.type, node.left, scope)418 const [right, rightExps]419 = normalizeProperty(node.type, 'right', node.right.type, node.right, scope)420 const [body, bodyExps]421 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)422 exps.push(...leftExps)423 exps.push(...rightExps)424 const forInStatement = createForInStatement(Array.isArray(left) ? left[0] : left, right, body)425 return [forInStatement, exps]426}427function normalize_ForOfStatement(node, scope) {428 const exps = []429 const [left, leftExps]430 = normalizeProperty(node.type, 'left', node.left.type, node.left, scope)431 const [right, rightExps]432 = normalizeProperty(node.type, 'right', node.right.type, node.right, scope)433 const [body, bodyExps]434 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)435 exps.push(...leftExps)436 exps.push(...rightExps)437 const forOfStatement = createForOfStatement(left, right, body)438 return [forOfStatement, exps]439}440function normalize_FunctionDeclaration(node, scope) {441 const exps = []442 const params = []443 node.params.forEach(param => {444 const [p, pExps]445 = normalizeProperty(node.type, 'params', param.type, param, scope)446 // TODO: move this inside the function.447 exps.push(...pExps)448 params.push(p)449 })450 const [body]451 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)452 return [453 createFunctionDeclaration(node.id, params, body),454 exps455 ]456}457function normalize_VariableDeclaration(node, scope) {458 const exps = []459 const declarations = []460 node.declarations.forEach(dec => {461 const [declarators, expressions] = normalize_VariableDeclarator(dec, scope)462 exps.push(...expressions)463 declarators.forEach(declarator => {464 declarations.push(createVariableDeclaration(node.kind, [declarator]))465 })466 })467 return [declarations, exps]468}469function normalize_VariableDeclarator(node, scope) {470 const exps = []471 const [id, idExps] = normalizeProperty(node.type, 'id', node.id.type, node.id, scope)472 const [init, initExps] = normalizeProperty(node.type, 'init', node.init?.type ?? null, node.init, scope, false)473 exps.push(...idExps)474 exps.push(...initExps)475 const declarators = []476 // TODO: handle nested of these more carefully.477 if (id.type === 'ArrayPattern') {478 id.elements.forEach((i, _i) => {479 declarators.push(480 createVariableDeclarator(i,481 createMemberExpression(init, createLiteral(_i), true)482 )483 )484 })485 // TODO: handle nested of these more carefully.486 } else if (id.type === 'ObjectPattern') {487 id.properties.forEach((i, _i) => {488 declarators.push(489 createVariableDeclarator(i.value,490 createMemberExpression(init, i.key)491 )492 )493 })494 } else {495 declarators.push(createVariableDeclarator(id, init))496 }497 return [498 declarators,499 exps500 ]501}502function normalize_ThisExpression(node, scope) {503 return [504 node,505 []506 ]507}508function normalize_ArrayExpression(node, scope, isolate) {509 const exps = []510 const array = []511 node.elements.forEach(element => {512 const [el, elExps] = normalizeProperty(node.type, 'elements', element.type, element, scope, false)513 array.push(el)514 exps.push(...elExps)515 })516 const arrayExp = createArrayExpression(array)517 if (isolate == 'hey') {518 const name = `tmp${scope.index++}`519 exps.push(520 createVariable('const',521 createIdentifier(name),522 arrayExp523 )524 )525 return [526 createIdentifier(name),527 exps528 ]529 } else {530 return [531 arrayExp,532 exps533 ]534 }535}536function normalize_ObjectExpression(node, scope, isolate) {537 const exps = []538 const array = []539 node.properties.forEach(prop => {540 const [el, elExps] = normalizeProperty(node.type, 'properties', prop.type, prop, scope, false)541 array.push(el)542 exps.push(...elExps)543 })544 const objectExp = createObjectExpression(array)545 if (isolate) {546 const name = `tmp${scope.index++}`547 exps.push(548 createVariable('const',549 createIdentifier(name),550 objectExp551 )552 )553 return [554 createIdentifier(name),555 exps556 ]557 } else {558 return [559 objectExp,560 exps561 ]562 }563}564function normalize_Property(node, scope) {565 if (node.type === 'SpreadElement') {566 return normalizeSpreadElement(node, scope)567 } else if (node.type === 'ObjectPattern') {568 throw new Error569 }570 const exps = []571 const [key, keyExps] = normalizeProperty(node.type, 'key', node.key.type, node.key, scope)572 const [value, valueExps] = normalizeProperty(node.type, 'value', node.value.type, node.value, scope)573 exps.push(...keyExps)574 exps.push(...valueExps)575 return [createProperty(key, value), exps]576}577function normalize_FunctionExpression(node, scope) {578 const exps = []579 const params = []580 node.params.forEach(param => {581 const [p, pExps] = normalizeProperty(node.type, 'params', param.type, param, scope)582 exps.push(...pExps)583 params.push(p)584 })585 const [body] = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)586 return [587 createFunctionExpression(node.id, params, body),588 exps589 ]590}591function normalize_ArrowFunctionExpression(node, scope) {592 const exps = []593 const params = []594 node.params.forEach(param => {595 const [p, pExps] = normalizeProperty(node.type, 'params', param.type, param, scope)596 exps.push(...pExps)597 params.push(p)598 })599 let [body, bodyExps]600 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)601 if (body.type !== 'BlockStatement') {602 body = createBlockStatement([...bodyExps, createReturnStatement(body)])603 }604 return [605 createArrowFunctionExpression(node.id, params, body),606 exps607 ]608}609function normalize_YieldExpression(node, scope) {610}611function normalize_TemplateLiteral(node, scope) {612 const exps = []613 const quasis = []614 const expressions = []615 node.expressions.forEach(expression => {616 const [exp, expExps] = normalizeProperty(node.type, 'expressions', expression.type, expression, scope, true)617 expressions.push(exp)618 exps.push(...expExps)619 })620 node.quasis.forEach(q => {621 const [el] = normalizeProperty(node.type, 'quasis', q.type, q, scope)622 quasis.push(el)623 })624 return [625 createTemplateLiteral(expressions, quasis),626 exps627 ]628}629function normalize_TaggedTemplateExpression(node, scope) {630 const [tag, tagExps]631 = normalizeProperty(node.type, 'tag', node.tag.type, node.tag, scope)632 const [template, templateExps]633 = normalizeProperty(node.type, 'quasi', node.quasi.type, node.quasi, scope)634 return [635 createTaggedTemplateExpression(tag, template),636 [...templateExps, ...tagExps]637 ]638}639function normalize_TemplateElement(node, scope) {640 return [node, []]641}642function normalize_UnaryExpression(node, scope, isolate) {643 const exps = []644 const [argument, argumentExps]645 = normalizeProperty(node.type, 'argument', node.argument.type, node.argument, scope, false)646 exps.push(...argumentExps)647 const unary = createUnaryExpression(argument, node.operator, node.prefix)648 if (isolate) {649 const name = `tmp${scope.index++}`650 exps.push(651 createVariable('const',652 createIdentifier(name),653 unary654 )655 )656 return [657 createIdentifier(name),658 exps659 ]660 } else {661 return [662 unary,663 exps664 ]665 }666}667function normalize_UpdateExpression(node, scope, isolate) {668 const [argument, argumentExps]669 = normalizeProperty(node.type, 'argument', node.argument.type, node.argument, scope, false)670 const update = createUpdateExpression(argument, node.operator, node.prefix)671 if (isolate) {672 const name = `tmp${scope.index++}`673 argumentExps.push(674 createVariable('const',675 createIdentifier(name),676 update677 )678 )679 return [680 createIdentifier(name),681 argumentExps682 ]683 } else {684 return [685 update,686 argumentExps687 ]688 }689}690function normalize_BinaryExpression(node, scope, isolate) {691 const exps = []692 const [left, leftExps]693 = normalizeProperty(node.type, 'left', node.left.type, node.left, scope, false)694 const [right, rightExps]695 = normalizeProperty(node.type, 'right', node.right.type, node.right, scope, false)696 exps.push(...leftExps)697 exps.push(...rightExps)698 const binary = createBinaryExpression(699 left,700 node.operator,701 right702 )703 if (isolate) {704 const name = `tmp${scope.index++}`705 exps.push(706 createVariable('const',707 createIdentifier(name),708 binary709 )710 )711 return [712 createIdentifier(name),713 exps714 ]715 } else {716 return [717 binary,718 exps719 ]720 }721}722function normalize_AssignmentExpression(node, scope, isolate) {723 const [left, leftExps] = normalizeProperty(node.type, 'left', node.left.type, node.left, scope)724 let values = [left]725 let operators = [node.operator]726 let right = node.right727 while (right.type === 'AssignmentExpression') {728 values.push(right.left)729 operators.push(right.operator)730 right = right.right731 }732 let [furthestRight, furthestRightExps] = normalizeProperty(node.type, 'right', right.type, right, scope, false)733 values.push(furthestRight)734 const exps = [735 ...leftExps,736 ...furthestRightExps737 ]738 if (left.type === 'ArrayPattern') {739 const assignments = []740 left.elements.forEach(el => {741 assignments.push(742 createAssignmentExpression(743 el,744 createMemberExpression(right, el),745 node.operator746 )747 )748 })749 return [750 assignments,751 exps752 ]753 } else {754 let assignments = []755 let i = 0756 let n = values.length - 1757 while (i < n) {758 let l = values[i]759 let r = values[i + 1]760 const assignment = createAssignmentExpression(l, r, operators[i])761 assignments.push(assignment)762 i++763 }764 assignments = assignments.reverse()765 let assignment766 if (isolate) {767 assignment = assignments[assignments.length - 1].left768 } else {769 assignment = assignments.pop()770 }771 return [772 assignment,773 exps.concat(assignments)774 ]775 }776}777function normalize_LogicalExpression(node, scope, isolate) {778 const exps = []779 const [left, leftExps]780 = normalizeProperty(node.type, 'left', node.left.type, node.left, scope, false)781 const [right, rightExps]782 = normalizeProperty(node.type, 'right', node.right.type, node.right, scope, false)783 exps.push(...leftExps)784 exps.push(...rightExps)785 const logicalExp = createLogicalExpression(786 left,787 node.operator,788 right789 )790 if (isolate) {791 const name = `tmp${scope.index++}`792 exps.push(793 createVariable('const',794 createIdentifier(name),795 logicalExp796 )797 )798 return [799 createIdentifier(name),800 exps801 ]802 } else {803 return [804 logicalExp,805 exps806 ]807 }808}809function normalize_MemberExpression(node, scope) {810 const exps = []811 const [object, objectStatements]812 = normalizeProperty(node.type, 'object', node.object.type, node.object, scope, true)813 const [property, propertyStatements]814 = normalizeProperty(node.type, 'property', node.property.type, node.property, scope, true)815 exps.push(...objectStatements)816 exps.push(...propertyStatements)817 return [818 createMemberExpression(819 object,820 property,821 node.computed822 ),823 exps824 ]825}826function normalize_ConditionalExpression(node, scope, isolate) {827 const exps = []828 const [test, testExps]829 = normalizeProperty(node.type, 'test', node.test.type, node.test, scope, true)830 const [consequent, consequentExps]831 = normalizeProperty(node.type, 'consequent', node.consequent.type, node.consequent, scope, true)832 const [alternate, alternateExps]833 = normalizeProperty(node.type, 'alternate', node.alternate.type, node.alternate, scope, true)834 exps.push(...testExps)835 exps.push(...consequentExps)836 exps.push(...alternateExps)837 const name = `tmp${scope.index++}`838 const conditional = createIfStatement(839 test,840 createBlockStatement([createAssignmentExpression(createIdentifier(name), consequent)]),841 createBlockStatement([createAssignmentExpression(createIdentifier(name), alternate)])842 )843 exps.push(844 createVariable('let',845 createIdentifier(name)846 ),847 conditional848 )849 return [850 createIdentifier(name),851 exps852 ]853}854function normalize_CallExpression(node, scope, isolate) {855 const [_callee, calleeExps]856 = normalizeProperty(node.type, 'callee', node.callee.type, node.callee, scope, true)857 const args = []858 const exps = []859 node.arguments.forEach(arg => {860 const [argument, argumentExps]861 = normalizeProperty(node.type, 'arguments', arg.type, arg, scope, false)862 exps.push(...argumentExps)863 args.push(argument)864 })865 exps.push(...calleeExps)866 if (isolate) {867 const name = `tmp${scope.index++}`868 exps.push(869 createVariableDeclaration('const', [870 createVariableDeclarator(871 createIdentifier(name),872 createCallExpression(_callee, args)873 )874 ])875 )876 return [877 createIdentifier(name),878 exps879 ]880 } else {881 return [882 createCallExpression(_callee, args),883 exps884 ]885 }886}887function normalize_NewExpression(node, scope) {888 const exps = []889 const [ctor, ctorExps]890 = normalizeProperty(node.type, 'callee', node.callee.type, node.callee, scope)891 const argExps = []892 const args = []893 node.arguments.forEach(arg => {894 const [argument, argumentExps]895 = normalizeProperty(node.type, 'arguments', arg.type, arg, scope, false)896 args.push(argument)897 argExps.push(...argumentExps)898 })899 exps.push(...ctorExps, ...argExps)900 return [901 createNewExpression(ctor, args),902 exps903 ]904}905function normalize_SequenceExpression(node, scope) {906 const expressions = []907 // this just flattens the list and gets rid of the node type908 // in the normalized output909 node.expressions.forEach(exp => {910 const exps = normalizeType(exp.type, exp, scope)911 expressions.push(...exps)912 })913 return expressions914}915function normalize_SpreadElement(node, scope) {916 const [arg, argExps]917 = normalizeProperty(node.type, 'argument', node.argument.type, node.argument, scope, true)918 return [919 createSpreadElement(arg),920 argExps921 ]922}923function normalize_ArrayPattern(node, scope) {924 const array = []925 const exps = []926 node.elements.forEach(element => {927 const [el, elExps] = normalizeProperty(node.type, 'elements', element.type, element, scope)928 array.push(el)929 exps.push(...elExps)930 })931 return [932 createArrayPattern(array),933 exps934 ]935}936function normalize_ObjectPattern(node, scope) {937 const exps = []938 const properties = []939 node.properties.forEach(p => {940 const [prop, propExps]941 = normalizeProperty(node.type, 'properties', p.type, p, scope)942 exps.push(...propExps)943 properties.push(prop)944 })945 return [946 createObjectPattern(properties),947 exps948 ]949}950function normalize_RestElement(node, scope) {951 const [arg, argExps]952 = normalizeProperty(node.type, 'argument', node.argument.type, node.argument, scope)953 return [954 createRestElement(arg),955 argExps956 ]957}958function normalize_AssignmentPattern(node, scope) {959 const exps = []960 const [left] = normalizeProperty(node.type, 'left', node.left.type, node.left, scope)961 const [right, rightExps] = normalizeProperty(node.type, 'right', node.right.type, node.right, scope, true)962 exps.push(...rightExps)963 return [964 createAssignmentPattern(left, right),965 exps966 ]967}968function normalize_ClassBody(node, scope) {969 const exps = []970 const body = []971 node.body.forEach(bd => {972 const [method, methodExps] = normalizeProperty(node.type, 'body', bd.type, bd, scope)973 exps.push(...methodExps)974 body.push(method)975 })976 return [createClassBody(body), exps]977}978function normalize_MethodDefinition(node, scope) {979 const [key, keyExps]980 = normalizeProperty(node.type, 'key', node.key.type, node.key, scope)981 const [value, valueExps]982 = normalizeProperty(node.type, 'value', node.value.type, node.value, scope)983 return [createMethodDefinition(key, value, node.kind, node.computed, node.static), keyExps]984}985function normalize_ClassDeclaration(node, scope) {986 const exps = []987 const [id, idExps]988 = normalizeProperty(node.type, 'id', node.id?.type ?? null, node.id, scope)989 const [superClass, superClassExps]990 = normalizeProperty(node.type, 'superClass', node.superClass?.type ?? null, node.superClass, scope)991 const [body, bodyExps]992 = normalizeProperty(node.type, 'body', node.body.type, node.body, scope)993 exps.push(...idExps)994 exps.push(...superClassExps)995 exps.push(...bodyExps)996 return [createClassDeclaration(id, superClass, body), exps]997}998function normalize_ClassExpression(node, scope) {999}1000function normalize_MetaProperty(node, scope) {1001}1002function normalize_ModuleDeclaration(node, scope) {1003}1004function normalize_ModuleSpecifier(node, scope) {1005}1006function normalize_ImportDeclaration(node, scope) {1007}1008function normalize_ImportSpecifier(node, scope) {1009}1010function normalize_ImportDefaultSpecifier(node, scope) {1011}1012function normalize_ImportNamespaceSpecifier(node, scope) {1013}1014function normalize_ExportNamedDeclaration(node, scope) {1015 const declaration = normalizeBodyNode(node.declaration, scope)1016 const specifiers = []1017}1018function normalize_ExportSpecifier(node, scope) {1019}1020function normalize_ExportDefaultDeclaration(node, scope) {1021}1022function normalize_ExportAllDeclaration(node, scope) {1023}1024function normalize_AwaitExpression(node, scope) {1025}1026function normalize_ImportExpression(node, scope) {1027}1028function call(obj, method, ...args) {1029 if (!obj.hasOwnProperty(method)) {1030 throw new Error(`Missing method ${method}`)1031 }1032 return obj[method](...args)1033}1034function buildNormalizers(types) {1035 const normalizers = {1036 normalize_null1037 }1038 Object.keys(types).forEach(type => {1039 const def = types[type]1040 normalizers[`normalize_${type}`] = buildNormalizeTypeFunction(type, def)1041 })1042 Object.keys(types).forEach(type => {1043 const def = types[type]1044 def.extends.type.forEach(extend => {1045 const parent = types[extend]1046 Object.keys(parent.properties).forEach(name => {1047 def.properties[name]1048 = def.properties[name]1049 || parent.properties[name]1050 })1051 Object.keys(def.properties).forEach(name => {1052 const searchableTypes = []1053 const stack = [...def.properties[name].type]1054 const processed = {}1055 while (stack.length) {1056 const propertyTypeName = stack.shift()1057 if (processed[propertyTypeName]) {1058 continue1059 }1060 processed[propertyTypeName] = true1061 searchableTypes.push(propertyTypeName)1062 const propertyType = types[propertyTypeName]1063 if (propertyType) {1064 propertyType.extends.type.forEach(ext => {1065 stack.push(ext)1066 })1067 }1068 Object.keys(types).forEach(childTypeName => {1069 const childType = types[childTypeName]1070 if (childType.extends.type.includes(propertyTypeName)) {1071 searchableTypes.push(childTypeName)1072 stack.push(childTypeName)1073 }1074 })1075 }1076 searchableTypes.forEach(searchedType => {1077 if (normalizers[`normalize_${searchedType}`]) {1078 normalizers[`normalize_${type}_${name}_${searchedType}`] = buildNormalizePropertyType(searchedType)1079 }1080 })1081 })1082 })1083 })1084 return normalizers1085}1086function buildNormalizePropertyType(propertyType) {1087 return function(node, scope, isolate) {1088 return normalizeType(propertyType, node, scope, isolate)1089 }1090}1091function buildNormalizeTypeFunction(type, def) {1092 return function(node, scope, isolate) {1093 const object = { type }1094 const expressions = []1095 Object.keys(def.properties).forEach(name => {1096 const property = def.properties[name]1097 if (property.list) {1098 const list = object[name] = []1099 const propertyNodes = node[name] ?? []1100 propertyNodes.forEach(propertyNode => {1101 const [normalizedPropertyNode, normalizedExpressions]1102 = normalizeProperty(type, name, propertyNode.type, propertyNode, scope, isolate)1103 list.push(normalizedPropertyNode)1104 expressions.push(...normalizedExpressions)1105 })1106 } else {1107 const propertyNode = node[name]1108 const [normalizedPropertyNode, normalizedExpressions]1109 = normalizeProperty(type, name, propertyNode?.type ?? null, propertyNode, scope, isolate)1110 object[name] = normalizedPropertyNode1111 expressions.push(...normalizedExpressions)1112 }1113 })1114 expressions.push(object)1115 return expressions1116 }...

Full Screen

Full Screen

restaurants.controller.ts

Source:restaurants.controller.ts Github

copy

Full Screen

...12 constructor(@inject(TYPES.RestaurantsService) private restaurantsService: RestaurantsService) {13 }14 @httpPost('/')15 public getRestaurants(request: Request): Promise<IRestaurant[]> {16 return this.restaurantsService.getRestaurants(RestaurantsController.normalizeProperty(request.body.name), RestaurantsController.normalizeProperty(request.body.openAt), RestaurantsController.normalizeProperty(request.body.day))17 }18 /**19 * nullize empty values20 * @param prop21 * @private22 */23 private static normalizeProperty(prop: any): any {24 return prop === '' ? null : prop;25 }26 @httpGet('/test')27 public testPath(): {} {28 return {'dupa': 'zbita'};29 }...

Full Screen

Full Screen

normalizeProperty-test.ts

Source:normalizeProperty-test.ts Github

copy

Full Screen

1import normalizeProperty from '../normalizeProperty'2describe('Normalizing properties', () => {3 it('should camel case hypenated properties', () => {4 expect(normalizeProperty('transition-delay')).toEqual('transitionDelay')5 })6 it('should unprefix properties', () => {7 expect(normalizeProperty('WebkitTransitionDelay')).toEqual(8 'transitionDelay'9 )10 })11 it('should unprefix and camel case properties', () => {12 expect(normalizeProperty('-webkit-transition-delay')).toEqual(13 'transitionDelay'14 )15 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = new wptools('Barack Obama');3wiki.normalizeProperty('birth_place').then(function(response){4 console.log(response);5});6{ birth_place: 'Hawaii' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.normalizeProperty('wiki', function(err, result) {4 console.log(result);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.getTemplate('Infobox politician', function(err, result) {9 console.log(result);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.getTemplates(function(err, result) {14 console.log(result);15});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2wptools.normalizeProperty('P17', 'Q30').then(result => {3 console.log(result);4});5{ property: 'P17', value: 'Q30', normalized: true }6const wptools = require('wptools');7wptools.normalizeProperty('P17', 'Q30').then(result => {8 console.log(result);9});10{ property: 'P17', value: 'Q30', normalized: true }11const wptools = require('wptools');12wptools.normalizeProperty('P17', 'Q30').then(result => {13 console.log(result);14});15{ property: 'P17', value: 'Q30', normalized: true }16const wptools = require('wptools');17wptools.normalizeProperty('P17', 'Q30').then(result => {18 console.log(result);19});20{ property: 'P17', value: 'Q30', normalized: true }21const wptools = require('wptools');22wptools.normalizeProperty('P17', 'Q30').then(result => {23 console.log(result);24});25{ property: 'P17', value: 'Q30', normalized: true }

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2wptools.normalizeProperty('P17', 'Q30').then(result => {3 console.log(result);4});5{ property: 'P17', value: 'Q30', normalized: true }6const wptools = require('wptools');7wptools.normalizeProperty('P17', 'Q30').then(result => {8 console.log(result);9});10{ property: 'P17', value: 'Q30', normalized: true }11const wptools = require('wptools');12wptools.normalizeProperty('P17', 'Q30').then(result => {13 console.log(result);14});15{ property: 'P17', value: 'Q30', normalized: true }16const wptools = require('wptools');17wptools.normalizeProperty('P17', 'Q30').then(result => {18 console.log(result);19});20{ property: 'P17', value: 'Q30', normalized: true }21const wptools = require('wptools');22wptools.normalizeProperty('P17', 'Q30').then(result => {23 console.log(result);24});25{ property: 'P17', value: 'Q30', normalized: true }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var property = "FirstView.SpeedIndex";3wpt.normalizeProperty(url, property, function(error, result){4 if(error) {5 console.log(error);6 }else {7 console.log(result);8 }9});10var wpt = require('./wpt.js');11var testId = "170123_0F_1";12wpt.getTestResults(testId, function(error, result){13 if(error) {14 console.log(error);15 }else {16 console.log(result);17 }18});19var wpt = require('./wpt.js');20var testId = "170123_0F_1";21var location = "Dulles:Chrome";22wpt.getTestResultsByLocation(testId, location, function(error, result){23 if(error) {24 console.log(error);25 }else {26 console.log(result);27 }28});29var wpt = require('./wpt.js');30var testId = "170123_0F_1";31var location = "Dulles:Chrome";32var connectivity = "Cable";33wpt.getTestResultsByLocationAndConnectivity(testId, location, connectivity, function(error, result){34 if(error) {35 console.log(error);36 }else {37 console.log(result);38 }39});40var wpt = require('./wpt.js');41wpt.getTestResultsByUrl(url, function(error, result){42 if(error)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const normalizeProperty = wptools.normalizeProperty;3const normalizedProperty = normalizeProperty('P31');4console.log(normalizedProperty);5## normalizeValue()6const wptools = require('wptools');7const normalizeValue = wptools.normalizeValue;8const normalizedValue = normalizeValue('Q5');9console.log(normalizedValue);10## normalizeQualifier()11const wptools = require('wptools');12const normalizeQualifier = wptools.normalizeQualifier;13const normalizedQualifier = normalizeQualifier('P580');14console.log(normalizedQualifier);15## normalizeReference()16const wptools = require('wptools');17const normalizeReference = wptools.normalizeReference;18const normalizedReference = normalizeReference('P248');19console.log(normalizedReference);20```tpattern');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = requir('wptools');2va wiki = wptools.page('Albert Eistein);3wiki.get(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9}10## normalizeSnak()11const wptools = require('wptools');12const normalizeSnak = wptools.normalizeSnak;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.get(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful