als-render-jsx
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "als-render-jsx", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -19,7 +19,9 @@ "directories": { | ||
"dependencies": { | ||
"als-remove-js-comments": "^1.0.0" | ||
"als-remove-js-comments": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"als-browser-test": "^1.1.0" | ||
"als-browser-test": "^1.1.0", | ||
"als-require": "^2.2.0", | ||
"uglify-js": "^3.19.3" | ||
} | ||
} |
const RenderJsx = (function(){ | ||
const singleProps = ["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"] | ||
function removeComments(code) { | ||
const stringPattern = /(['"`])(\\?.)*?\1/g; | ||
const commentPattern = /(^|[^\\])((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm; | ||
function removeComments(text) { | ||
const quotes = { '"': true, "'": true, '`': true }; | ||
let newText = '', quote = null; | ||
for (let i = 0; i < text.length; i++) { | ||
const char = text[i]; | ||
if (quotes[char] && text[i - 1] !== '\\') { | ||
quote = quote === char && text[i - 1] !== '\\' ? null : char; | ||
newText += text[i]; | ||
} else if (!quote && char === '/' && text[i + 1] === '/') { | ||
while(i < text.length && text[i] !== '\n') i++; | ||
if(text[i] === '\n') newText += text[i] | ||
} else if (!quote && char === '{' && text[i + 1] === '/' && text[i + 2] === '*') { | ||
while (i < text.length && !(text[i] === '*' && text[i + 1] === '/' && text[i + 2] === '}')) i++; | ||
i = i+2 | ||
} else if (!quote && char ==='/' && text[i + 1] === '*') { | ||
while(i < text.length && !(text[i] === '*' && text[i + 1] === '/')) i++; | ||
i++ | ||
} else newText += text[i] | ||
} | ||
const stringMatches = []; | ||
code = code.replace(stringPattern, (match) => { | ||
stringMatches.push(match); | ||
return `__STRING_PLACEHOLDER__`; | ||
}); | ||
code = code.replace(commentPattern, '$1'); | ||
return code.replace(/__STRING_PLACEHOLDER__/g, () => stringMatches.shift()); | ||
return newText | ||
} | ||
@@ -15,0 +25,0 @@ function getInsideBreckets(i, content) { |
@@ -1,1 +0,1 @@ | ||
let RenderJsx=(()=>{let f=["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"];function i(e,t,n,l){let a="",h="",o=!0,u=!1,c,i=0;function s(e,i,s="attributes"){var r=n;if(i){let[e,t]=i;"async"===(e="className"===e?"class":e)?r.async=!0:f.includes(e)?(t&&(e=`\${${t} ? '${e}' : ''}`),r.attributes.push([e])):"props"===s&&e.startsWith("on")?r.buildAction([e,t]):r[s].push([e,t])}for(o=!0,u=!1,a="",h="",c=null;0===l[e].trim().length;)e++;return e}for(;">"!==e&&!(t>=l.length);){if(o)if("{"===e){for(;t<l.length&&"}"!==(e=l[++t]);)n.rest+=e;s(t)}else if("="===e||0===e.trim().length)0<a.length&&(" "===e&&"="!==l[t+1]?(n.attributes.push([a]),a=""):(o=!1,u=!0));else{if(">"===l[t+1]){"/"===e?n.selfClosed=!0:""!==a&&n.attributes.push([a+e]),t++;break}a+=e}else u&&(c?"{"===c?(h+=e,"{"===e?i++:"}"===e&&(0<i?i--:t=s(t,[a,h.slice(0,-1)],"props"))):"\\"!==l[t-1]&&e===c?t=s(t,[a,h]):h+=e:/["'`{]/.test(e)?c=e:/[a-zA-Z]/.test(e)&&(""!==a&&n.attributes.push([a]),o=!0,u=!1,a=e));">"===(e=l[++t])&&u&&(h+=e,e=l[++t])}return++t}class c{static render(e){return c.jsxParser((e=>{let t=[];return(e=(e=e.replace(/(['"`])(\\?.)*?\1/g,e=>(t.push(e),"__STRING_PLACEHOLDER__"))).replace(/(^|[^\\])((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,"$1")).replace(/__STRING_PLACEHOLDER__/g,()=>t.shift())})(e))}static componentFn(e,t,i,s){return e+`(new ${t}(${i},\`${s}\`)).call()`}static buildAction([e,t]){e=e.split("on")[1].toLowerCase();return[e,t="$"+`{this.action('${e}',${t})}`]}static getOuter(h){{var o=c.componentFn;let{tagName:e,selfClosed:t,attributes:i,props:s,isComponent:r,rest:n,inner:l}=h,a="";if(r){var u=[...s,...i.map(([e,t])=>[e,'"'+t+'"'])].map(([e,t])=>e+":"+t),h=(n&&u.push(n),h.async?"await ":"");s="{"+u.join(",")+"}",a="${"+o(h,e,s,l)+"}"}else{if(""===e)return l||"";s=s.map(([e,t])=>[e,"${"+t+"}"]);u=[...i,...s].map(([e,t])=>t?`${e}="${t.replace(/\"/g,'\\"')}"`:e).join(" ");a=`<${e}${u.length?" "+u:""}>`,t||(a+=l+`</${e}>`)}return a}}static jsxParser(t){let i="";for(let e=0;e<t.length;e++)if("("===t[e]){var s=e;for(e++;0===t[e].trim().length;)e++;if("<"===t[e]){var r=new c(t,e);for(e=r.i,i+="`"+r.outer+"`";")"!==t[e];)e++}else i+=t.slice(s,e+1)}else i+=t[e];return i}tagName="";rest="";inner="";attributes=[];props=[];selfClosed=!1;constructor(e,t){if(">"===e[t+1])this.isComponent=!1,this.tagName="",this.i=t+2;else{for(this.isComponent=/[A-Z]/.test(e[t+1]);t<e.length&&!1!==/[A-Za-z0-9.]/.test(e[++t]);)this.tagName+=e[t];this.i=i(e[t],t,this,e)}!1===this.selfClosed&&this.getInner(e)}get outer(){return c.getOuter(this)}buildAction([e,t]){this.attributes.push(c.buildAction([e,t]))}getInner(e){var t=`</${this.tagName}>`;let i=0;for(var s="</>"==t?"<>":"<"+this.tagName;this.i<e.length;){if(this.inner+=e[this.i],this.inner.endsWith(s)&&i++,this.inner.endsWith(t)){if(!(0<i)){this.inner=this.inner.slice(0,-t.length).trim();break}i--}this.i++}this.buildInner()}buildInner(){let t="";if(!(this.inner.trim().length<2)&&(this.inner.includes("<")||this.inner.includes("{"))){for(let e=0;e<this.inner.length;e++){var i,s;"<"===this.inner[e]?(i=new c(this.inner,e),t+=i.outer,e=i.i):"{"===this.inner[e]?(e=((t,i)=>{let e=0,s={'"':[],"'":[],"`":[]};for(i.replace(/["'`]/g,(e,t)=>{"\\"!==i[t-1]&&s[e].push(t)});t<i.length;){var r=i[++t];if(s[r]&&s[r].length){let e;for(var n of s[r])if(n>t){e=n;break}e&&(t=e,s[r]=s[r].filter(e=>t<e))}else if("{"===r)e++;else if("}"===r){if(!(0<e))break;e--}}return t+1})(i=e,this.inner),s=this.inner.slice(i,e+1),t+="$"+c.jsxParser(s)):t+=this.inner[e]}this.inner=t}}}return c})(); | ||
let RenderJsx=(()=>{let c=["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"];function i(e,t,r,l){let a="",h="",o=!0,u=!1,f,i=0;function n(e,i,n="attributes"){var s=r;if(i){let[e,t]=i;"async"===(e="className"===e?"class":e)?s.async=!0:c.includes(e)?(t&&(e=`\${${t} ? '${e}' : ''}`),s.attributes.push([e])):"props"===n&&e.startsWith("on")?s.buildAction([e,t]):s[n].push([e,t])}for(o=!0,u=!1,a="",h="",f=null;0===l[e].trim().length;)e++;return e}for(;">"!==e&&!(t>=l.length);){if(o)if("{"===e){for(;t<l.length&&"}"!==(e=l[++t]);)r.rest+=e;n(t)}else if("="===e||0===e.trim().length)0<a.length&&(" "===e&&"="!==l[t+1]?(r.attributes.push([a]),a=""):(o=!1,u=!0));else{if(">"===l[t+1]){"/"===e?r.selfClosed=!0:""!==a&&r.attributes.push([a+e]),t++;break}a+=e}else u&&(f?"{"===f?(h+=e,"{"===e?i++:"}"===e&&(0<i?i--:t=n(t,[a,h.slice(0,-1)],"props"))):"\\"!==l[t-1]&&e===f?t=n(t,[a,h]):h+=e:/["'`{]/.test(e)?f=e:/[a-zA-Z]/.test(e)&&(""!==a&&r.attributes.push([a]),o=!0,u=!1,a=e));">"===(e=l[++t])&&u&&(h+=e,e=l[++t])}return++t}class f{static render(e){return f.jsxParser((t=>{var i={'"':!0,"'":!0,"`":!0};let n="",s=null;for(let e=0;e<t.length;e++){var r=t[e];if(i[r]&&"\\"!==t[e-1])s=s===r&&"\\"!==t[e-1]?null:r,n+=t[e];else if(s||"/"!==r||"/"!==t[e+1])if(s||"{"!==r||"/"!==t[e+1]||"*"!==t[e+2])if(s||"/"!==r||"*"!==t[e+1])n+=t[e];else{for(;e<t.length&&("*"!==t[e]||"/"!==t[e+1]);)e++;e++}else{for(;e<t.length&&("*"!==t[e]||"/"!==t[e+1]||"}"!==t[e+2]);)e++;e+=2}else{for(;e<t.length&&"\n"!==t[e];)e++;"\n"===t[e]&&(n+=t[e])}}return n})(e))}static componentFn(e,t,i,n){return e+`(new ${t}(${i},\`${n}\`)).call()`}static buildAction([e,t]){e=e.split("on")[1].toLowerCase();return[e,t="$"+`{this.action('${e}',${t})}`]}static getOuter(h){{var o=f.componentFn;let{tagName:e,selfClosed:t,attributes:i,props:n,isComponent:s,rest:r,inner:l}=h,a="";if(s){var u=[...n,...i.map(([e,t])=>[e,'"'+t+'"'])].map(([e,t])=>e+":"+t),h=(r&&u.push(r),h.async?"await ":"");n="{"+u.join(",")+"}",a="${"+o(h,e,n,l)+"}"}else{if(""===e)return l||"";n=n.map(([e,t])=>[e,"${"+t+"}"]);u=[...i,...n].map(([e,t])=>t?`${e}="${t.replace(/\"/g,'\\"')}"`:e).join(" ");a=`<${e}${u.length?" "+u:""}>`,t||(a+=l+`</${e}>`)}return a}}static jsxParser(t){let i="";for(let e=0;e<t.length;e++)if("("===t[e]){var n=e;for(e++;0===t[e].trim().length;)e++;if("<"===t[e]){var s=new f(t,e);for(e=s.i,i+="`"+s.outer+"`";")"!==t[e];)e++}else i+=t.slice(n,e+1)}else i+=t[e];return i}tagName="";rest="";inner="";attributes=[];props=[];selfClosed=!1;constructor(e,t){if(">"===e[t+1])this.isComponent=!1,this.tagName="",this.i=t+2;else{for(this.isComponent=/[A-Z]/.test(e[t+1]);t<e.length&&!1!==/[A-Za-z0-9.]/.test(e[++t]);)this.tagName+=e[t];this.i=i(e[t],t,this,e)}!1===this.selfClosed&&this.getInner(e)}get outer(){return f.getOuter(this)}buildAction([e,t]){this.attributes.push(f.buildAction([e,t]))}getInner(e){var t=`</${this.tagName}>`;let i=0;for(var n="</>"==t?"<>":"<"+this.tagName;this.i<e.length;){if(this.inner+=e[this.i],this.inner.endsWith(n)&&i++,this.inner.endsWith(t)){if(!(0<i)){this.inner=this.inner.slice(0,-t.length).trim();break}i--}this.i++}this.buildInner()}buildInner(){let t="";if(!(this.inner.trim().length<2)&&(this.inner.includes("<")||this.inner.includes("{"))){for(let e=0;e<this.inner.length;e++){var i,n;"<"===this.inner[e]?(i=new f(this.inner,e),t+=i.outer,e=i.i):"{"===this.inner[e]?(e=((t,i)=>{let e=0,n={'"':[],"'":[],"`":[]};for(i.replace(/["'`]/g,(e,t)=>{"\\"!==i[t-1]&&n[e].push(t)});t<i.length;){var s=i[++t];if(n[s]&&n[s].length){let e;for(var r of n[s])if(r>t){e=r;break}e&&(t=e,n[s]=n[s].filter(e=>t<e))}else if("{"===s)e++;else if("}"===s){if(!(0<e))break;e--}}return t+1})(i=e,this.inner),n=this.inner.slice(i,e+1),t+="$"+f.jsxParser(n)):t+=this.inner[e]}this.inner=t}}}return f})(); |
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
50094
852
3
+ Addedals-remove-js-comments@2.0.0(transitive)
- Removedals-remove-js-comments@1.0.0(transitive)