@jsep-plugin/ternary
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -81,2 +81,16 @@ 'use strict'; | ||
} | ||
// ? and : precedence are before '||' (which defaults to 1) | ||
// object plugin sets : precedence to 0.95, so check for less than that | ||
// (which would capture assignment operators, which the plugin sets at 0.9) | ||
if (env.node.test && env.node.test.operator && jsep.binary_ops[env.node.test.operator] < 0.95) { | ||
const node = env.node; | ||
env.node = node.test; | ||
env.node.right = { | ||
type: CONDITIONAL_EXP, | ||
test: node.test.right, | ||
consequent: node.consequent, | ||
alternate: node.alternate, | ||
}; | ||
} | ||
} | ||
@@ -83,0 +97,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
"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; | ||
"use strict";const e="ConditionalExpression";var t={name:"ternary",init(t){function o(e){for(;e.left&&":"===e.left.operator;)e=e.left;return e}t.hooks.add("after-expression",(function(r){if(r.node&&this.code===t.QUMARK_CODE){this.index++;const n=r.node,s=this.gobbleExpression();if(s||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===t.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),r.node={type:"ConditionalExpression",test:n,consequent:s,alternate:e}}else if(":"===n.operator){s.right||this.throwError("Expected :");const e=o(s);n.right={type:"ConditionalExpression",test:n.right,consequent:e.left,alternate:e===s?e.right:{operator:":",left:e.right,right:s.right}},r.node=n}else if(":"===s.operator)!function(t,o){t.type=e,t.test=o,t.consequent=t.left,t.alternate=t.right,delete t.operator,delete t.left,delete t.right}(o(s),n),r.node=s;else if(s.alternate){let t=s.alternate;for(;t.alternate;)t=t.alternate;r.node={type:e,test:n,consequent:s,alternate:t.right},delete t.operator,delete t.right,Object.assign(t,t.left)}else this.throwError("Expected :");if(r.node.test&&r.node.test.operator&&t.binary_ops[r.node.test.operator]<.95){const t=r.node;r.node=t.test,r.node.right={type:e,test:t.test.right,consequent:t.consequent,alternate:t.alternate}}}}))}};module.exports=t; | ||
//# sourceMappingURL=index.cjs.min.js.map |
@@ -82,2 +82,16 @@ var index = (function () { | ||
} | ||
// ? and : precedence are before '||' (which defaults to 1) | ||
// object plugin sets : precedence to 0.95, so check for less than that | ||
// (which would capture assignment operators, which the plugin sets at 0.9) | ||
if (env.node.test && env.node.test.operator && jsep.binary_ops[env.node.test.operator] < 0.95) { | ||
const node = env.node; | ||
env.node = node.test; | ||
env.node.right = { | ||
type: CONDITIONAL_EXP, | ||
test: node.test.right, | ||
consequent: node.consequent, | ||
alternate: node.alternate, | ||
}; | ||
} | ||
} | ||
@@ -84,0 +98,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
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 :")}}))}}}(); | ||
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,s=this.gobbleExpression();if(s||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:s,alternate:t}}else if(":"===n.operator){s.right||this.throwError("Expected :");const t=r(s);n.right={type:e,test:n.right,consequent:t.left,alternate:t===s?t.right:{operator:":",left:t.right,right:s.right}},o.node=n}else if(":"===s.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(s),n),o.node=s;else if(s.alternate){let t=s.alternate;for(;t.alternate;)t=t.alternate;o.node={type:e,test:n,consequent:s,alternate:t.right},delete t.operator,delete t.right,Object.assign(t,t.left)}else this.throwError("Expected :");if(o.node.test&&o.node.test.operator&&t.binary_ops[o.node.test.operator]<.95){const t=o.node;o.node=t.test,o.node.right={type:e,test:t.test.right,consequent:t.consequent,alternate:t.alternate}}}}))}}}(); | ||
//# sourceMappingURL=index.iife.min.js.map |
@@ -79,2 +79,16 @@ const CONDITIONAL_EXP = 'ConditionalExpression'; | ||
} | ||
// ? and : precedence are before '||' (which defaults to 1) | ||
// object plugin sets : precedence to 0.95, so check for less than that | ||
// (which would capture assignment operators, which the plugin sets at 0.9) | ||
if (env.node.test && env.node.test.operator && jsep.binary_ops[env.node.test.operator] < 0.95) { | ||
const node = env.node; | ||
env.node = node.test; | ||
env.node.right = { | ||
type: CONDITIONAL_EXP, | ||
test: node.test.right, | ||
consequent: node.consequent, | ||
alternate: node.alternate, | ||
}; | ||
} | ||
} | ||
@@ -81,0 +95,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
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}; | ||
const e="ConditionalExpression";var t={name:"ternary",init(t){function o(e){for(;e.left&&":"===e.left.operator;)e=e.left;return e}t.hooks.add("after-expression",(function(r){if(r.node&&this.code===t.QUMARK_CODE){this.index++;const n=r.node,s=this.gobbleExpression();if(s||this.throwError("Expected expression"),this.gobbleSpaces(),this.code===t.COLON_CODE){this.index++;const e=this.gobbleExpression();e||this.throwError("Expected expression"),r.node={type:"ConditionalExpression",test:n,consequent:s,alternate:e}}else if(":"===n.operator){s.right||this.throwError("Expected :");const e=o(s);n.right={type:"ConditionalExpression",test:n.right,consequent:e.left,alternate:e===s?e.right:{operator:":",left:e.right,right:s.right}},r.node=n}else if(":"===s.operator)!function(t,o){t.type=e,t.test=o,t.consequent=t.left,t.alternate=t.right,delete t.operator,delete t.left,delete t.right}(o(s),n),r.node=s;else if(s.alternate){let t=s.alternate;for(;t.alternate;)t=t.alternate;r.node={type:e,test:n,consequent:s,alternate:t.right},delete t.operator,delete t.right,Object.assign(t,t.left)}else this.throwError("Expected :");if(r.node.test&&r.node.test.operator&&t.binary_ops[r.node.test.operator]<.95){const t=r.node;r.node=t.test,r.node.right={type:e,test:t.test.right,consequent:t.consequent,alternate:t.alternate}}}}))}};export{t as default}; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@jsep-plugin/ternary", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Adds ternary expression support", | ||
@@ -5,0 +5,0 @@ "author": "Shelly (https://github.com/6utt3rfly)", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49516
372