Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsep-plugin/ternary

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsep-plugin/ternary - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

types/tsd.d.ts

63

dist/cjs/index.cjs.js

@@ -37,9 +37,42 @@ 'use strict';

// if binary operator is custom-added (i.e. object plugin), then correct it to a ternary node:
// Note: BinaryExpressions can be stacked (similar to 1 + 1 + 1), so we have to collapse the stack
// Only do one level at a time so we can unroll as we pop the ternary stack
else if (test.operator === ':') {
// this happens when the alternate is a ternary
if (!consequent.right) {
this.throwError('Expected :');
}
const node = findLastBinaryNode(consequent);
test.right = {
type: CONDITIONAL_EXP,
test: test.right,
consequent: node.left,
alternate: node === consequent ? node.right : {
// temporary values because we still have to wait to pop the consequent...
operator: ':',
left: node.right,
right: consequent.right,
},
};
env.node = test;
}
else if (consequent.operator === ':') {
convertBinaryToConditional(findLastBinaryNode(consequent), test);
env.node = consequent;
}
else if (consequent.alternate) {
// cleanup the temporary placeholder we made, now that we have the consequent
let alternate = consequent.alternate;
while (alternate.alternate) {
alternate = alternate.alternate;
}
env.node = {
type: CONDITIONAL_EXP,
test,
consequent: consequent.left,
alternate: consequent.right,
consequent,
alternate: alternate.right,
};
delete alternate.operator;
delete alternate.right;
Object.assign(alternate, alternate.left);
}

@@ -51,2 +84,28 @@ else {

});
/**
* @param {jsep.Expression} node
* @returns {jsep.Expression}
*/
function findLastBinaryNode(node) {
while (node.left && node.left.operator === ':') {
node = node.left;
}
return node;
}
/**
* @param {jsep.BinaryExpression} node
* @param {jsep.Expression} test
* @returns {jsep.ConditionalExpression}
*/
function convertBinaryToConditional(node, test) {
node.type = CONDITIONAL_EXP;
node.test = test;
node.consequent = node.left;
node.alternate = node.right;
delete node.operator;
delete node.left;
delete node.right;
}
},

@@ -53,0 +112,0 @@ };

2

dist/cjs/index.cjs.min.js

@@ -1,2 +0,2 @@

"use strict";var e={name:"ternary",init(e){e.hooks.add("after-expression",(function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;const o=t.node,s=this.gobbleExpression();if(s||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:o,consequent:s,alternate:e}}else":"===s.operator?t.node={type:"ConditionalExpression",test:o,consequent:s.left,alternate:s.right}:this.throwError("Expected :")}}))}};module.exports=e;
"use strict";var e={name:"ternary",init(e){function t(e){for(;e.left&&":"===e.left.operator;)e=e.left;return e}e.hooks.add("after-expression",(function(r){if(r.node&&this.code===e.QUMARK_CODE){this.index++;const o=r.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),r.node={type:"ConditionalExpression",test:o,consequent:n,alternate:e}}else if(":"===o.operator){n.right||this.throwError("Expected :");const e=t(n);o.right={type:"ConditionalExpression",test:o.right,consequent:e.left,alternate:e===n?e.right:{operator:":",left:e.right,right:n.right}},r.node=o}else if(":"===n.operator)!function(e,t){e.type="ConditionalExpression",e.test=t,e.consequent=e.left,e.alternate=e.right,delete e.operator,delete e.left,delete e.right}(t(n),o),r.node=n;else if(n.alternate){let e=n.alternate;for(;e.alternate;)e=e.alternate;r.node={type:"ConditionalExpression",test:o,consequent:n,alternate:e.right},delete e.operator,delete e.right,Object.assign(e,e.left)}else this.throwError("Expected :")}}))}};module.exports=e;
//# sourceMappingURL=index.cjs.min.js.map
{
"type": "commonjs"
}

@@ -38,9 +38,42 @@ var index = (function () {

// if binary operator is custom-added (i.e. object plugin), then correct it to a ternary node:
// Note: BinaryExpressions can be stacked (similar to 1 + 1 + 1), so we have to collapse the stack
// Only do one level at a time so we can unroll as we pop the ternary stack
else if (test.operator === ':') {
// this happens when the alternate is a ternary
if (!consequent.right) {
this.throwError('Expected :');
}
const node = findLastBinaryNode(consequent);
test.right = {
type: CONDITIONAL_EXP,
test: test.right,
consequent: node.left,
alternate: node === consequent ? node.right : {
// temporary values because we still have to wait to pop the consequent...
operator: ':',
left: node.right,
right: consequent.right,
},
};
env.node = test;
}
else if (consequent.operator === ':') {
convertBinaryToConditional(findLastBinaryNode(consequent), test);
env.node = consequent;
}
else if (consequent.alternate) {
// cleanup the temporary placeholder we made, now that we have the consequent
let alternate = consequent.alternate;
while (alternate.alternate) {
alternate = alternate.alternate;
}
env.node = {
type: CONDITIONAL_EXP,
test,
consequent: consequent.left,
alternate: consequent.right,
consequent,
alternate: alternate.right,
};
delete alternate.operator;
delete alternate.right;
Object.assign(alternate, alternate.left);
}

@@ -52,2 +85,28 @@ else {

});
/**
* @param {jsep.Expression} node
* @returns {jsep.Expression}
*/
function findLastBinaryNode(node) {
while (node.left && node.left.operator === ':') {
node = node.left;
}
return node;
}
/**
* @param {jsep.BinaryExpression} node
* @param {jsep.Expression} test
* @returns {jsep.ConditionalExpression}
*/
function convertBinaryToConditional(node, test) {
node.type = CONDITIONAL_EXP;
node.test = test;
node.consequent = node.left;
node.alternate = node.right;
delete node.operator;
delete node.left;
delete node.right;
}
},

@@ -54,0 +113,0 @@ };

@@ -1,2 +0,2 @@

var index=function(){"use strict";const e="ConditionalExpression";return{name:"ternary",init(t){t.hooks.add("after-expression",(function(o){if(o.node&&this.code===t.QUMARK_CODE){this.index++;const s=o.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===t.COLON_CODE){this.index++;const t=this.gobbleExpression();t||this.throwError("Expected expression"),o.node={type:e,test:s,consequent:n,alternate:t}}else":"===n.operator?o.node={type:e,test:s,consequent:n.left,alternate:n.right}:this.throwError("Expected :")}}))}}}();
var index=function(){"use strict";const e="ConditionalExpression";return{name:"ternary",init(t){function r(e){for(;e.left&&":"===e.left.operator;)e=e.left;return e}t.hooks.add("after-expression",(function(o){if(o.node&&this.code===t.QUMARK_CODE){this.index++;const n=o.node,i=this.gobbleExpression();if(i||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===t.COLON_CODE){this.index++;const t=this.gobbleExpression();t||this.throwError("Expected expression"),o.node={type:e,test:n,consequent:i,alternate:t}}else if(":"===n.operator){i.right||this.throwError("Expected :");const t=r(i);n.right={type:e,test:n.right,consequent:t.left,alternate:t===i?t.right:{operator:":",left:t.right,right:i.right}},o.node=n}else if(":"===i.operator)!function(t,r){t.type=e,t.test=r,t.consequent=t.left,t.alternate=t.right,delete t.operator,delete t.left,delete t.right}(r(i),n),o.node=i;else if(i.alternate){let t=i.alternate;for(;t.alternate;)t=t.alternate;o.node={type:e,test:n,consequent:i,alternate:t.right},delete t.operator,delete t.right,Object.assign(t,t.left)}else this.throwError("Expected :")}}))}}}();
//# sourceMappingURL=index.iife.min.js.map

@@ -35,9 +35,42 @@ const CONDITIONAL_EXP = 'ConditionalExpression';

// if binary operator is custom-added (i.e. object plugin), then correct it to a ternary node:
// Note: BinaryExpressions can be stacked (similar to 1 + 1 + 1), so we have to collapse the stack
// Only do one level at a time so we can unroll as we pop the ternary stack
else if (test.operator === ':') {
// this happens when the alternate is a ternary
if (!consequent.right) {
this.throwError('Expected :');
}
const node = findLastBinaryNode(consequent);
test.right = {
type: CONDITIONAL_EXP,
test: test.right,
consequent: node.left,
alternate: node === consequent ? node.right : {
// temporary values because we still have to wait to pop the consequent...
operator: ':',
left: node.right,
right: consequent.right,
},
};
env.node = test;
}
else if (consequent.operator === ':') {
convertBinaryToConditional(findLastBinaryNode(consequent), test);
env.node = consequent;
}
else if (consequent.alternate) {
// cleanup the temporary placeholder we made, now that we have the consequent
let alternate = consequent.alternate;
while (alternate.alternate) {
alternate = alternate.alternate;
}
env.node = {
type: CONDITIONAL_EXP,
test,
consequent: consequent.left,
alternate: consequent.right,
consequent,
alternate: alternate.right,
};
delete alternate.operator;
delete alternate.right;
Object.assign(alternate, alternate.left);
}

@@ -49,2 +82,28 @@ else {

});
/**
* @param {jsep.Expression} node
* @returns {jsep.Expression}
*/
function findLastBinaryNode(node) {
while (node.left && node.left.operator === ':') {
node = node.left;
}
return node;
}
/**
* @param {jsep.BinaryExpression} node
* @param {jsep.Expression} test
* @returns {jsep.ConditionalExpression}
*/
function convertBinaryToConditional(node, test) {
node.type = CONDITIONAL_EXP;
node.test = test;
node.consequent = node.left;
node.alternate = node.right;
delete node.operator;
delete node.left;
delete node.right;
}
},

@@ -51,0 +110,0 @@ };

@@ -1,2 +0,2 @@

var e={name:"ternary",init(e){e.hooks.add("after-expression",(function(t){if(t.node&&this.code===e.QUMARK_CODE){this.index++;const o=t.node,s=this.gobbleExpression();if(s||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),t.node={type:"ConditionalExpression",test:o,consequent:s,alternate:e}}else":"===s.operator?t.node={type:"ConditionalExpression",test:o,consequent:s.left,alternate:s.right}:this.throwError("Expected :")}}))}};export{e as default};
var e={name:"ternary",init(e){function t(e){for(;e.left&&":"===e.left.operator;)e=e.left;return e}e.hooks.add("after-expression",(function(r){if(r.node&&this.code===e.QUMARK_CODE){this.index++;const o=r.node,n=this.gobbleExpression();if(n||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===e.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),r.node={type:"ConditionalExpression",test:o,consequent:n,alternate:e}}else if(":"===o.operator){n.right||this.throwError("Expected :");const e=t(n);o.right={type:"ConditionalExpression",test:o.right,consequent:e.left,alternate:e===n?e.right:{operator:":",left:e.right,right:n.right}},r.node=o}else if(":"===n.operator)!function(e,t){e.type="ConditionalExpression",e.test=t,e.consequent=e.left,e.alternate=e.right,delete e.operator,delete e.left,delete e.right}(t(n),o),r.node=n;else if(n.alternate){let e=n.alternate;for(;e.alternate;)e=e.alternate;r.node={type:"ConditionalExpression",test:o,consequent:n,alternate:e.right},delete e.operator,delete e.right,Object.assign(e,e.left)}else this.throwError("Expected :")}}))}};export{e as default};
//# sourceMappingURL=index.min.js.map
{
"name": "@jsep-plugin/ternary",
"version": "1.0.0",
"version": "1.0.1",
"description": "Adds ternary expression support",

@@ -5,0 +5,0 @@ "author": "Shelly (https://github.com/6utt3rfly)",

@@ -0,0 +0,0 @@ [npm]: https://img.shields.io/npm/v/@jsep-plugin/ternary

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc