New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

als-render

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

als-render - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

23

lib/build-content/build-component/get-function.js

@@ -0,24 +1,11 @@

const getInsideBreckets = require('../jsx/breckets')
function getFunction(content,componentName) {
const all = '[\\s\\S]*?',s = '\\s*?'
const r = new RegExp(`^\\s*?function${s}${componentName}${s}\\(${all}\\)${all}{`,'m')
const fnStart = content.match(r)
if(!fnStart) return null
let count = 0,end;
for(let i = fnStart.index+fnStart[0].length; i<content.length; i++) {
let char = content[i],prevChar = content[i-1]
if(char.match(/["'`]/) && prevChar !== '\\') {
do {
prevChar = content[i]
i++
} while(content[i] !== char && prevChar !== '\\')
}
if(char === '{') count++
else if(char === '}') {
if(count > 0) count --
else if(count === 0) {
end = i+1
break
}
}
}
const start = fnStart.index+fnStart[0].length
const end = getInsideBreckets(start,content)
return content.slice(fnStart.index,end)

@@ -25,0 +12,0 @@ }

const getFunction = require('./get-function')
function buildComponentFn(content,componentName) {
if(/[A-Z]/.test(componentName[0]) === false) return content
const originalFn = getFunction(content,componentName)
if(originalFn === null) return content

@@ -6,0 +8,0 @@ const newFunction = /*js*/`function ${componentName}(props={},inner) {

function getInsideBreckets(i, content) {
let count = 0;
const quotes = { '"':[],"'":[],"`":[] }
content.replace(/["'`]/g,(m,i) => {
if(content[i-1] !== '\\') quotes[m].push(i)
const quotes = { '"': [], "'": [], "`": [] }
content.replace(/["'`]/g, (m, i) => {
if (content[i - 1] !== '\\') quotes[m].push(i)
})
while (i < content.length) {
i++;
const char = content[i]
if(count && quotes[char] && quotes[char].length) {
if (quotes[char] && quotes[char].length) {
let next
for(const index of quotes[char]) {
if(index > i) {
for (const index of quotes[char]) {
if (index > i) {
next = index

@@ -17,3 +18,3 @@ break

}
if(next) {
if (next) {
i = next

@@ -27,7 +28,6 @@ quotes[char] = quotes[char].filter(index => index > i)

}
i++;
}
return i
return i + 1
}
module.exports = getInsideBreckets

@@ -25,3 +25,2 @@ const getAttributes = require('./attributes/get-attributes')

if (this.selfClosed === false) this.getInner(content)
}

@@ -28,0 +27,0 @@

function removeComments(code) {
const r = /`.*?\/\/.*?`|".*?\/\/.*?"|'.*?\/\/.*?'/
return code
.replace(/\/\/(?![^'"]*['"][^'"]*$).*$(?=\n|$)/gm,'')
.replace(/\{?\/\*[\s\S]*?\*\/\}?/g, '')
.replace(/^(.*)(\/\/.*)($|\n)/gm,(m,before,comment) => {
const stringResult = (before+comment).match(r)
if(stringResult && stringResult.index < before.length) return m // string starts before //
return before
})
.replace(/\{?\/\*[\s\S]*?\*\/\}?/gm, '')
}
module.exports = removeComments

@@ -18,3 +18,2 @@ const buildContent = require('./build-content/index')

}
return { resultFn, context, add }

@@ -21,0 +20,0 @@ }

{
"name": "als-render",
"version": "0.7.0",
"version": "0.8.0",
"main": "index.js",

@@ -28,3 +28,3 @@ "scripts": {

"dependencies": {
"als-require": "^1.3.1",
"als-require": "^1.4.0",
"uglify-js": "^3.18.0"

@@ -31,0 +31,0 @@ },

@@ -30,14 +30,15 @@ const Require = (function(){

let fullPath
let pkgJsonPath = `/node_modules/${modulePath}/package.json`
if(modulePath.includes('/')) {
fullPath = `/node_modules/${modulePath}`
if(!fullPath.endsWith('.js')) fullPath += '.js'
modulePath = modulePath.split('/').shift()
pkgJsonPath = `/node_modules/${modulePath.split('/').shift()}/package.json`
}
const pkgJsonPath = `/node_modules/${modulePath}/package.json`
const exists = await fetch(pkgJsonPath, { method: 'HEAD' })
if (exists.ok === false) {
const r = new RegExp(`require\\(["'\`]${modulePath}["'\`]\\)`)
content = content.replace(r, 'null')
console.warn(`The module "${modulePath}" can't be imported and will be replaced with null`)
content = content.replace(r, '{}')
console.warn(`The module "${modulePath}" can't be imported and will be replaced with {}`)
continue

@@ -110,3 +111,2 @@ }

}).join('\n')
const fn = new Function('modules', contextName, `function require(path) { return modules[path] || null };

@@ -336,5 +336,10 @@ ${fns}`)

function removeComments(code) {
const r = /`.*?\/\/.*?`|".*?\/\/.*?"|'.*?\/\/.*?'/
return code
.replace(/\/\/(?![^'"]*['"][^'"]*$).*$(?=\n|$)/gm,'')
.replace(/\{?\/\*[\s\S]*?\*\/\}?/g, '')
.replace(/^(.*)(\/\/.*)($|\n)/gm,(m,before,comment) => {
const stringResult = (before+comment).match(r)
if(stringResult && stringResult.index < before.length) return m // string starts before //
return before
})
.replace(/\{?\/\*[\s\S]*?\*\/\}?/gm, '')
}

@@ -345,28 +350,51 @@

})();
modules['/lib/build-content/jsx/breckets.js'] = (function (){
const module = { exports: {} }
const exports = module.exports
function getInsideBreckets(i, content) {
let count = 0;
const quotes = { '"': [], "'": [], "`": [] }
content.replace(/["'`]/g, (m, i) => {
if (content[i - 1] !== '\\') quotes[m].push(i)
})
while (i < content.length) {
i++;
const char = content[i]
if (quotes[char] && quotes[char].length) {
let next
for (const index of quotes[char]) {
if (index > i) {
next = index
break
}
}
if (next) {
i = next
quotes[char] = quotes[char].filter(index => index > i)
}
} else if (char === '{') count++
else if (char === '}') {
if (count > 0) count--
else break
}
}
return i + 1
}
module.exports = getInsideBreckets
return module.exports;
})();
modules['/lib/build-content/build-component/get-function.js'] = (function (){
const module = { exports: {} }
const exports = module.exports
const getInsideBreckets = require('/lib/build-content/jsx/breckets.js')
function getFunction(content,componentName) {
const all = '[\\s\\S]*?',s = '\\s*?'
const r = new RegExp(`^\\s*?function${s}${componentName}${s}\\(${all}\\)${all}{`,'m')
const fnStart = content.match(r)
if(!fnStart) return null
let count = 0,end;
for(let i = fnStart.index+fnStart[0].length; i<content.length; i++) {
let char = content[i],prevChar = content[i-1]
if(char.match(/["'`]/) && prevChar !== '\\') {
do {
prevChar = content[i]
i++
} while(content[i] !== char && prevChar !== '\\')
}
if(char === '{') count++
else if(char === '}') {
if(count > 0) count --
else if(count === 0) {
end = i+1
break
}
}
}
const start = fnStart.index+fnStart[0].length
const end = getInsideBreckets(start,content)
return content.slice(fnStart.index,end)

@@ -384,3 +412,5 @@ }

function buildComponentFn(content,componentName) {
if(/[A-Z]/.test(componentName[0]) === false) return content
const originalFn = getFunction(content,componentName)
if(originalFn === null) return content

@@ -431,57 +461,2 @@ const newFunction = /*js*/`function ${componentName}(props={},inner) {

})();
modules['/lib/build-content/jsx/breckets.js'] = (function (){
const module = { exports: {} }
const exports = module.exports
// function getInsideBreckets(i, content) {
// let count = 0, quote = null;
// while (i < content.length) {
// i++;
// if (quote === null && /["'`]/.test(content[i])) quote = content[i]; // начало строки в кавычках
// else if (quote) {
// if (content[i] === quote && content[i - 1] !== '\\') quote = null; // конец строки в кавычках
// } else {
// if (content[i] === '{') count++
// else if (content[i] === '}') {
// if (count > 0) count--
// else break
// }
// }
// }
// i++
// return i
// }
function getInsideBreckets(i, content) {
let count = 0;
const quotes = { '"':[],"'":[],"`":[] }
content.replace(/["'`]/g,(m,i) => {
if(content[i-1] !== '\\') quotes[m].push(i)
})
while (i < content.length) {
const char = content[i]
if(count && quotes[char] && quotes[char].length) {
let next
for(const index of quotes[char]) {
if(index > i) {
next = index
break
}
}
if(next) {
i = next
quotes[char] = quotes[char].filter(index => index > i)
}
} else if (char === '{') count++
else if (char === '}') {
if (count > 0) count--
else break
}
i++;
}
return i
}
module.exports = getInsideBreckets
return module.exports;
})();
modules['/lib/build-content/jsx/attributes/build-action.js'] = (function (){

@@ -620,3 +595,2 @@ const module = { exports: {} }

if (this.selfClosed === false) this.getInner(content)
}

@@ -733,3 +707,2 @@

}
return { resultFn, context, add }

@@ -773,4 +746,4 @@ }

} catch(error) {
parseError(error, {"/lib/context/component.js":{"from":4,"to":78},"/lib/context/context.js":{"from":79,"to":137},"/lib/build-content/remove-comments.js":{"from":138,"to":149},"/lib/build-content/build-component/get-function.js":{"from":150,"to":181},"/lib/build-content/build-component/index.js":{"from":182,"to":203},"/lib/build-content/jsx/outer.js":{"from":204,"to":233},"/lib/build-content/jsx/breckets.js":{"from":234,"to":288},"/lib/build-content/jsx/attributes/build-action.js":{"from":289,"to":301},"/lib/build-content/jsx/attributes/build-prop.js":{"from":302,"to":322},"/lib/build-content/jsx/attributes/get-attributes.js":{"from":323,"to":394},"/lib/build-content/jsx/element.js":{"from":395,"to":468},"/lib/build-content/jsx/jsx-parser.js":{"from":469,"to":496},"/lib/build-content/index.js":{"from":497,"to":513},"/lib/build.js":{"from":514,"to":540},"/lib/browser.js":{"from":541,"to":564}}, 564)
parseError(error, {"/lib/context/component.js":{"from":4,"to":78},"/lib/context/context.js":{"from":79,"to":137},"/lib/build-content/remove-comments.js":{"from":138,"to":154},"/lib/build-content/jsx/breckets.js":{"from":155,"to":190},"/lib/build-content/build-component/get-function.js":{"from":191,"to":209},"/lib/build-content/build-component/index.js":{"from":210,"to":233},"/lib/build-content/jsx/outer.js":{"from":234,"to":263},"/lib/build-content/jsx/attributes/build-action.js":{"from":264,"to":276},"/lib/build-content/jsx/attributes/build-prop.js":{"from":277,"to":297},"/lib/build-content/jsx/attributes/get-attributes.js":{"from":298,"to":369},"/lib/build-content/jsx/element.js":{"from":370,"to":442},"/lib/build-content/jsx/jsx-parser.js":{"from":443,"to":470},"/lib/build-content/index.js":{"from":471,"to":487},"/lib/build.js":{"from":488,"to":513},"/lib/browser.js":{"from":514,"to":537}}, 537)
}
})()

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

let Require=(()=>{function i(t,e){if(s.contents[t]&&s.contents[t].children.includes(e))throw`cyclic dependency between ${e} and `+t}function c(t,e){var n,t=t.split("/"),r=[];for(n of[...e.split("/").slice(0,-1),...t])".."===n?0<r.length&&".."!==r[r.length-1]?r.pop():r.push(n):"."!==n&&r.push(n);e=r.join("/");return e.endsWith(".js")?e:e+".js"}async function l(t,e="text"){t=await fetch(t);if(t.ok)return t[e]();throw new Error("HTTP error! status: "+t.status)}async function t({contents:n,fullPath:t},a){let r=async o=>{if(void 0===n[o]){if(!a.contents[o]){let t=await l(o),r=[],s=[];t=t.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm,(t,e)=>{var n;return e.startsWith(".")?(i(n=c(e,o),o),r.push(n),t.replace(e,n)):(s.push({match:t,modulePath:e}),t)}),t=await(async(t,e,n)=>{if(0!==t.length)for(var{match:r,modulePath:s}of t){let t;s.includes("/")&&((t="/node_modules/"+s).endsWith(".js")||(t+=".js"),s=s.split("/").shift());var o,a=`/node_modules/${s}/package.json`;!1===(await fetch(a,{method:"HEAD"})).ok?(o=new RegExp(`require\\(["'\`]${s}["'\`]\\)`),n=n.replace(o,"null"),console.warn(`The module "${s}" can't be imported and will be replaced with null`)):(t||({main:o="index.js"}=await l(a,"json"),t=`/node_modules/${s}/`+o),i(t,s),e.push(t),n=n.replace(r,r.replace(s,t)))}return n})(s,r,t),a.contents[o]={content:t,children:r}}let{content:t,children:e}=a.contents[o];n[o]=t,await Promise.all(e.map(t=>r(t)))}};await r(t)}class s{static contents={};static async getModule(t,e,n,r){t=new s(t);return await t.getContent(),t.build(r,e,n)}constructor(t){this.contents={},this.path=t,this.fullPath=c(t,location.pathname),this.contentReady=!1}async getContent(){return this.contentReady||(await t(this,s),this.keys=((e,n)=>{let r=new Set,s=t=>{t.forEach(t=>{e[t]&&(s(n.contents[t].children),r.add(t))})};return s(Object.keys(e).reverse()),Array.from(r)})(this.contents,s),this.contentReady=!0),this}build(t={},e={},r="context"){var{fn:r,modulesLines:s,curLastLine:o}=((t="context",r)=>{let s={},o=3;var e=r.keys.map((t,e)=>{let n=`modules['${t}'] = (function (){
let Require=(()=>{function i(t,e){if(s.contents[t]&&s.contents[t].children.includes(e))throw`cyclic dependency between ${e} and `+t}function c(t,e){var n,t=t.split("/"),r=[];for(n of[...e.split("/").slice(0,-1),...t])".."===n?0<r.length&&".."!==r[r.length-1]?r.pop():r.push(n):"."!==n&&r.push(n);e=r.join("/");return e.endsWith(".js")?e:e+".js"}async function l(t,e="text"){t=await fetch(t);if(t.ok)return t[e]();throw new Error("HTTP error! status: "+t.status)}async function t({contents:n,fullPath:t},a){let r=async o=>{if(void 0===n[o]){if(!a.contents[o]){let t=await l(o),r=[],s=[];t=t.replace(/^(?!\/\/|\/\*.*\*\/).*require\(["'`](.*)["'`]\)/gm,(t,e)=>{var n;return e.startsWith(".")?(i(n=c(e,o),o),r.push(n),t.replace(e,n)):(s.push({match:t,modulePath:e}),t)}),t=await(async(t,n,r)=>{if(0!==t.length)for(var{match:s,modulePath:o}of t){let t,e=`/node_modules/${o}/package.json`;var a;o.includes("/")&&((t="/node_modules/"+o).endsWith(".js")||(t+=".js"),e=`/node_modules/${o.split("/").shift()}/package.json`),!1===(await fetch(e,{method:"HEAD"})).ok?(a=new RegExp(`require\\(["'\`]${o}["'\`]\\)`),r=r.replace(a,"{}"),console.warn(`The module "${o}" can't be imported and will be replaced with {}`)):(t||({main:a="index.js"}=await l(e,"json"),t=`/node_modules/${o}/`+a),i(t,o),n.push(t),r=r.replace(s,s.replace(o,t)))}return r})(s,r,t),a.contents[o]={content:t,children:r}}let{content:t,children:e}=a.contents[o];n[o]=t,await Promise.all(e.map(t=>r(t)))}};await r(t)}class s{static contents={};static async getModule(t,e,n,r){t=new s(t);return await t.getContent(),t.build(r,e,n)}constructor(t){this.contents={},this.path=t,this.fullPath=c(t,location.pathname),this.contentReady=!1}async getContent(){return this.contentReady||(await t(this,s),this.keys=((e,n)=>{let r=new Set,s=t=>{t.forEach(t=>{e[t]&&(s(n.contents[t].children),r.add(t))})};return s(Object.keys(e).reverse()),Array.from(r)})(this.contents,s),this.contentReady=!0),this}build(t={},e={},r="context"){var{fn:r,modulesLines:s,curLastLine:o}=((t="context",r)=>{let s={},o=3;var e=r.keys.map((t,e)=>{let n=`modules['${t}'] = (function (){
const module = { exports: {} }

@@ -9,3 +9,3 @@ const exports = module.exports

`+e),modulesLines:s,curLastLine:o}})(r,this);try{return r(t,e)}catch(n){{r=n;var a=s;var i=o;let[t,...e]=r.stack.split("\n");throw e=e.map(t=>{var e=t.match(/<anonymous>:(\d*):(\d*)\)$/);if(e){let n=Number(e[1]);if(n+1!==i){var r,s,e=Number(e[2]),o=Object.entries(a).filter(([,{from:t,to:e}])=>n>=t&&n<=e);if(0!==o.length)return[o,{from:r,to:s}]=o[0],` at ${t.match(/at\s(.*?)\s/)[1]} ${o} (${n-r-2}:${e})`}}}).filter(Boolean),r.stack=t+"\n"+e.join("\n"),r;return}}}}return s})(),require=Require.getModule;
const render = (()=>{function t(e,t){function n(t){return e[t]||null}var s;return e["/lib/context/component.js"]=(()=>{var t={exports:{}};class i{static fns={};static components={};static componentsToUpdate={};static genHash(t){t=(new TextEncoder).encode(t);let e=0,n=0;var s,o=[t=>(e+=t,1),t=>(e-=t,0)];for(s of t)n=o[n](s);return e}constructor(t,e={},n){var s,{key:o=""}=e,o=t+o;if(i.components[o])return(s=i.components[o]).init(e,n),s;(i.components[o]=this).mounted=!1,this.name=o,this.selector=`[component=${this.name}]`,this.fn=i.fns[t],this.init()}init(t,e){this.actions=[],this.counter=0,this.props=t,this.inner=e,this.hooks={mount:[()=>this.mounted=!0],unmount:[]}}addAction(t,e){var n=this.name+this.counter++;return this.actions.push({event:t,id:n,fn:e}),n}on(t,e){this.hooks[t]&&this.hooks[t].push(e)}update(t=this.props,e=this.inner){this.props=t,this.inner=e;var n=document.querySelector(this.selector);n&&this.fn&&(t=this.fn(t,e,this),this.hash!==this.oldHash)&&(n.outerHTML=t,i.context.runActions())}genHash(t){var e=i.genHash(t+this.name);return this.oldHash=this.hash,(i.componentsToUpdate[this.name]=this).hash=e,t}}return t.exports=i,t.exports})(),e["/lib/context/context.js"]=(()=>{var t={exports:{}};let l=n("/lib/context/component.js");return t.exports=class{links=[];styles=[];counter=0;constructor(t=!0,e=!1){(l.context=this).browser=t,this.ssr=e}addComponentFn(t,e){l.fns[t]=e}component(t,e,n){return new l(t,e,n)}style(t){this.styles.push(t)}runActions(){for(var t in l.componentsToUpdate){var t=l.componentsToUpdate[t],{actions:n,hooks:o,selector:i}=t;let e=document.querySelector(i),s=e||document;o.mount.forEach(t=>t(e)),n.forEach(({event:t,fn:e,id:n})=>{n=s.querySelector(`[${t}="${n}"]`);n&&("load"===t?e(n):n.addEventListener(t,e))}),t.actions=[],o.mount=[]}for(var e in l.components){var{selector:s,hooks:r}=l.components[e];document.querySelector(s)||(r.unmount.forEach(t=>t()),delete l.components[e])}l.componentsToUpdate={}}link(t){let e=this.currentPath.split("/");e.pop(),t.split("/").forEach(t=>{".."===t?e.pop():"."!==t&&e.push(t)}),this.links.push(e.join("/"))}},t.exports})(),e["/lib/build-content/remove-comments.js"]=((s={exports:{}}).exports=function(t){return t.replace(/\/\/(?![^'"]*['"][^'"]*$).*$(?=\n|$)/gm,"").replace(/\{?\/\*[\s\S]*?\*\/\}?/g,"")},s.exports),e["/lib/build-content/build-component/get-function.js"]=((s={exports:{}}).exports=function(s,t){var e="[\\s\\S]*?",t=new RegExp(`^\\s*?function\\s*?${t}\\s*?\\(${e}\\)${e}{`,"m");if(!(e=s.match(t)))return null;let o=0,i;for(let n=e.index+e[0].length;n<s.length;n++){let t=s[n],e=s[n-1];if(t.match(/["'`]/)&&"\\"!==e)for(;e=s[n],s[++n]!==t&&"\\"!==e;);if("{"===t)o++;else if("}"===t)if(0<o)o--;else if(0===o){i=n+1;break}}return s.slice(e.index,i)},s.exports),e["/lib/build-content/build-component/index.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/build-component/get-function.js");return t.exports=function(t,e){var n=s(t,e);return null===n?t:t.replace(n,`function ${e}(props={},inner) {
const render = (()=>{function t(e,t){function n(t){return e[t]||null}var s;return e["/lib/context/component.js"]=(()=>{var t={exports:{}};class r{static fns={};static components={};static componentsToUpdate={};static genHash(t){t=(new TextEncoder).encode(t);let e=0,n=0;var s,o=[t=>(e+=t,1),t=>(e-=t,0)];for(s of t)n=o[n](s);return e}constructor(t,e={},n){var s,{key:o=""}=e,o=t+o;if(r.components[o])return(s=r.components[o]).init(e,n),s;(r.components[o]=this).mounted=!1,this.name=o,this.selector=`[component=${this.name}]`,this.fn=r.fns[t],this.init()}init(t,e){this.actions=[],this.counter=0,this.props=t,this.inner=e,this.hooks={mount:[()=>this.mounted=!0],unmount:[]}}addAction(t,e){var n=this.name+this.counter++;return this.actions.push({event:t,id:n,fn:e}),n}on(t,e){this.hooks[t]&&this.hooks[t].push(e)}update(t=this.props,e=this.inner){this.props=t,this.inner=e;var n=document.querySelector(this.selector);n&&this.fn&&(t=this.fn(t,e,this),this.hash!==this.oldHash)&&(n.outerHTML=t,r.context.runActions())}genHash(t){var e=r.genHash(t+this.name);return this.oldHash=this.hash,(r.componentsToUpdate[this.name]=this).hash=e,t}}return t.exports=r,t.exports})(),e["/lib/context/context.js"]=(()=>{var t={exports:{}};let l=n("/lib/context/component.js");return t.exports=class{links=[];styles=[];counter=0;constructor(t=!0,e=!1){(l.context=this).browser=t,this.ssr=e}addComponentFn(t,e){l.fns[t]=e}component(t,e,n){return new l(t,e,n)}style(t){this.styles.push(t)}runActions(){for(var t in l.componentsToUpdate){var t=l.componentsToUpdate[t],{actions:n,hooks:o,selector:r}=t;let e=document.querySelector(r),s=e||document;o.mount.forEach(t=>t(e)),n.forEach(({event:t,fn:e,id:n})=>{n=s.querySelector(`[${t}="${n}"]`);n&&("load"===t?e(n):n.addEventListener(t,e))}),t.actions=[],o.mount=[]}for(var e in l.components){var{selector:s,hooks:i}=l.components[e];document.querySelector(s)||(i.unmount.forEach(t=>t()),delete l.components[e])}l.componentsToUpdate={}}link(t){let e=this.currentPath.split("/");e.pop(),t.split("/").forEach(t=>{".."===t?e.pop():"."!==t&&e.push(t)}),this.links.push(e.join("/"))}},t.exports})(),e["/lib/build-content/remove-comments.js"]=((s={exports:{}}).exports=function(t){let s=/`.*?\/\/.*?`|".*?\/\/.*?"|'.*?\/\/.*?'/;return t.replace(/^(.*)(\/\/.*)($|\n)/gm,(t,e,n)=>{n=(e+n).match(s);return n&&n.index<e.length?t:e}).replace(/\{?\/\*[\s\S]*?\*\/\}?/gm,"")},s.exports),e["/lib/build-content/jsx/breckets.js"]=((s={exports:{}}).exports=function(e,n){let t=0,s={'"':[],"'":[],"`":[]};for(n.replace(/["'`]/g,(t,e)=>{"\\"!==n[e-1]&&s[t].push(e)});e<n.length;){var o=n[++e];if(s[o]&&s[o].length){let t;for(var r of s[o])if(r>e){t=r;break}t&&(e=t,s[o]=s[o].filter(t=>e<t))}else if("{"===o)t++;else if("}"===o){if(!(0<t))break;t--}}return e+1},s.exports),e["/lib/build-content/build-component/get-function.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/jsx/breckets.js");return t.exports=function(t,e){var n="[\\s\\S]*?",e=new RegExp(`^\\s*?function\\s*?${e}\\s*?\\(${n}\\)${n}{`,"m");return(n=t.match(e))?(e=n.index+n[0].length,e=s(e,t),t.slice(n.index,e)):null},t.exports})(),e["/lib/build-content/build-component/index.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/build-component/get-function.js");return t.exports=function(t,e){var n;return!1===/[A-Z]/.test(e[0])||null===(n=s(t,e))?t:t.replace(n,`function ${e}(props={},inner) {
let originalFn = ${n}

@@ -17,3 +17,3 @@ const component = context.component('${e}',props,inner)

context.addComponentFn('${e}',${e})
`)},t.exports})(),e["/lib/build-content/jsx/outer.js"]=((s={exports:{}}).exports=function(t){let{tagName:e,selfClosed:n,attributes:s,props:o,isComponent:i,rest:r,inner:l}=t,u="";if(i){t=[...o,...s.map(([t,e])=>[t,'"'+e+'"'])].map(([t,e])=>t+":"+e);r&&t.push(r),o="{"+t.join(",")+"}",u="${"+`${e}(${o},\`${l}\`)`+"}"}else{if(""===e)return l||"";o=o.map(([t,e])=>[t,"${"+e+"}"]);t=[...s,...o].map(([t,e])=>e?t+`="${e}"`:t).join(" ");u=`<${e}${t.length?" "+t:""}>`,n||(u+=l+`</${e}>`)}return u},s.exports),e["/lib/build-content/jsx/breckets.js"]=((s={exports:{}}).exports=function(e,n){let t=0,s={'"':[],"'":[],"`":[]};for(n.replace(/["'`]/g,(t,e)=>{"\\"!==n[e-1]&&s[t].push(e)});e<n.length;){var o=n[e];if(t&&s[o]&&s[o].length){let t;for(var i of s[o])if(i>e){t=i;break}t&&(e=t,s[o]=s[o].filter(t=>e<t))}else if("{"===o)t++;else if("}"===o){if(!(0<t))break;t--}e++}return e},s.exports),e["/lib/build-content/jsx/attributes/build-action.js"]=((s={exports:{}}).exports=function(t,e){var[t,n]=t,t=t.split("on")[1].toLowerCase();e.attributes.push([t,"$"+`{this.addAction('${t}',${n})}`])},s.exports),e["/lib/build-content/jsx/attributes/build-prop.js"]=(()=>{var t={exports:{}};let i=["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"],r=n("/lib/build-content/jsx/attributes/build-action.js");return t.exports=function(n,s,o){if(n){let[t,e]=n;"className"===t&&(t="class"),i.includes(t)?(t=`\${${e} ? '${t}' : ''}`,e=void 0,o.attributes.push([t])):"props"===s&&t.startsWith("on")?r(n,o):o[s].push([t,e])}},t.exports})(),e["/lib/build-content/jsx/attributes/get-attributes.js"]=(()=>{var t={exports:{}};let p=n("/lib/build-content/jsx/attributes/build-prop.js");return t.exports=function(t,e,s,o){let i="",r="",l=!0,u=!1,c,n=0;function a(t,e,n="attributes"){for(p(e,n,s),l=!0,u=!1,i="",r="",c=null;0===o[t].trim().length;)t++;return t}for(;">"!==t&&!(e>=o.length);){if(l)if("{"===t){for(;e<o.length&&"}"!==(t=o[++e]);)s.rest+=t;a(e)}else if("="===t||0===t.trim().length)0<i.length&&(l=!1,u=!0);else{if(">"===o[e+1]){"/"===t?s.selfClosed=!0:""!==i&&s.attributes.push([i+t]),e++;break}i+=t}else u&&(c?"{"===c?(r+=t,"{"===t?n++:"}"===t&&(0<n?n--:e=a(e,[i,r.slice(0,-1)],"props"))):"\\"!==o[e-1]&&t===c?e=a(e,[i,r]):r+=t:/["'`{]/.test(t)?c=t:/[a-zA-Z]/.test(t)&&(""!==i&&s.attributes.push([i]),l=!0,u=!1,i=t));">"===(t=o[++e])&&u&&(r+=t,t=o[++e])}return++e},t.exports})(),e["/lib/build-content/jsx/element.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/jsx/attributes/get-attributes.js"),o=n("/lib/build-content/jsx/breckets.js"),e=n("/lib/build-content/jsx/outer.js");class i{tagName="";rest="";inner="";attributes=[];props=[];selfClosed=!1;constructor(t,e,n){if(">"===t[e+1])this.isComponent=!1,this.tagName="",this.i=e+2;else{for(this.isComponent=/[A-Z]/.test(t[e+1]);e<t.length&&!1!==/[A-Za-z0-9.]/.test(t[++e]);)this.tagName+=t[e];n&&this.attributes.push(["component","${this.name}"]),this.i=s(t[e],e,this,t)}!1===this.selfClosed&&this.getInner(t)}get outer(){return e(this)}getInner(t){var e=`</${this.tagName}>`;let n=0;for(var s="</>"==e?"<>":"<"+this.tagName;this.i<t.length;){if(this.inner+=t[this.i],this.inner.endsWith(s)&&n++,this.inner.endsWith(e)){if(!(0<n)){this.inner=this.inner.slice(0,-e.length).trim();break}n--}this.i++}this.buildInner()}buildInner(){let e="";if(!(this.inner.trim().length<2)&&(this.inner.includes("<")||this.inner.includes("{"))){for(let t=0;t<this.inner.length;t++){var n,s;"<"===this.inner[t]?(n=new i(this.inner,t),e+=n.outer,t=n.i):"{"===this.inner[t]?(n=t,t=o(t,this.inner),s=this.inner.slice(n,t),e+="$"+i.jsxParser(s)):e+=this.inner[t]}this.inner=e}}}return t.exports=i,t.exports})(),e["/lib/build-content/jsx/jsx-parser.js"]=(()=>{var t={exports:{}};let r=n("/lib/build-content/jsx/element.js");function e(e,n){let s="";for(let t=0;t<e.length;t++)if("("===e[t]){var o=t;for(t++;0===e[t].trim().length;)t++;if("<"===e[t]){var i=new r(e,t,n);for(t=i.i,s+="`"+i.outer+"`";")"!==e[t];)t++}else s+=e.slice(o,t+1)}else s+=e[t];return s}return r.jsxParser=e,t.exports=e,t.exports})(),e["/lib/build-content/index.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/jsx/jsx-parser.js"),o=n("/lib/build-content/build-component/index.js"),i=n("/lib/build-content/remove-comments.js");return t.exports=function(t,e){var n=e.split("/").pop().replace(/\.js$/,""),e=`context.currentPath = '${e}';
`+s(i(t),n);return o(e,n)},t.exports})(),e["/lib/build.js"]=(()=>{var t={exports:{}};let c=n("/lib/build-content/index.js"),a=n("/lib/context/context.js");return t.exports=function(t,e="context",n,s){var o,i=new a(n,s);for(o in t.contents)t.contents[o]=c(t.contents[o],o);let r="";var{links:l,styles:u}=i;return{resultFn:t.build({},i,e),context:i,add:r=s&&!n||!s&&n?[...l.map(t=>`<link rel="stylesheet" href="${t}">`),u.length?`<style>${u.join("\n")}</style>`:""].filter(Boolean).join("\n")+"\n":r}},t.exports})(),e["/lib/browser.js"]=(()=>{var t={exports:{}};let i=n("/lib/build.js");return t.exports=async function(t,e="body",n={},s){await(t=new Require(t)).getContent();var{resultFn:t,context:s,add:o}=i(t,s,!0,!1);return s.data=n,e&&(e=document.querySelector(e))&&(e.innerHTML=o+t(n).trim(),s.runActions()),s},t.exports})(),e["/lib/browser.js"]}{var e;let s=new Function("return "+"{}")();(function t(e){for(var n in e)"function"==typeof e[n]&&e[n].name===Obj.recursiveName?e[n]=e[n](s):null!==e[n]&&"object"==typeof e[n]&&t(e[n])})(s),s}try{t({})}catch(n){{var s=n;var r={"/lib/context/component.js":{from:4,to:78},"/lib/context/context.js":{from:79,to:137},"/lib/build-content/remove-comments.js":{from:138,to:149},"/lib/build-content/build-component/get-function.js":{from:150,to:181},"/lib/build-content/build-component/index.js":{from:182,to:203},"/lib/build-content/jsx/outer.js":{from:204,to:233},"/lib/build-content/jsx/breckets.js":{from:234,to:288},"/lib/build-content/jsx/attributes/build-action.js":{from:289,to:301},"/lib/build-content/jsx/attributes/build-prop.js":{from:302,to:322},"/lib/build-content/jsx/attributes/get-attributes.js":{from:323,to:394},"/lib/build-content/jsx/element.js":{from:395,to:468},"/lib/build-content/jsx/jsx-parser.js":{from:469,to:496},"/lib/build-content/index.js":{from:497,to:513},"/lib/build.js":{from:514,to:540},"/lib/browser.js":{from:541,to:564}};var l=564;let[t,...e]=s.stack.split("\n");throw e=e.map(t=>{var e=t.match(/<anonymous>:(\d*):(\d*)\)$/);if(e){let n=Number(e[1]);if(n+1!==l){var s,o,e=Number(e[2]),i=Object.entries(r).filter(([,{from:t,to:e}])=>n>=t&&n<=e);if(0!==i.length)return[i,{from:s,to:o}]=i[0],` at ${t.match(/at\s(.*?)\s/)[1]} ${i} (${n-s-2}:${e})`}}}).filter(Boolean),s.stack=t+"\n"+e.join("\n"),s;return}}})();
`)},t.exports})(),e["/lib/build-content/jsx/outer.js"]=((s={exports:{}}).exports=function(t){let{tagName:e,selfClosed:n,attributes:s,props:o,isComponent:r,rest:i,inner:l}=t,u="";if(r){t=[...o,...s.map(([t,e])=>[t,'"'+e+'"'])].map(([t,e])=>t+":"+e);i&&t.push(i),o="{"+t.join(",")+"}",u="${"+`${e}(${o},\`${l}\`)`+"}"}else{if(""===e)return l||"";o=o.map(([t,e])=>[t,"${"+e+"}"]);t=[...s,...o].map(([t,e])=>e?t+`="${e}"`:t).join(" ");u=`<${e}${t.length?" "+t:""}>`,n||(u+=l+`</${e}>`)}return u},s.exports),e["/lib/build-content/jsx/attributes/build-action.js"]=((s={exports:{}}).exports=function(t,e){var[t,n]=t,t=t.split("on")[1].toLowerCase();e.attributes.push([t,"$"+`{this.addAction('${t}',${n})}`])},s.exports),e["/lib/build-content/jsx/attributes/build-prop.js"]=(()=>{var t={exports:{}};let r=["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"],i=n("/lib/build-content/jsx/attributes/build-action.js");return t.exports=function(n,s,o){if(n){let[t,e]=n;"className"===t&&(t="class"),r.includes(t)?(t=`\${${e} ? '${t}' : ''}`,e=void 0,o.attributes.push([t])):"props"===s&&t.startsWith("on")?i(n,o):o[s].push([t,e])}},t.exports})(),e["/lib/build-content/jsx/attributes/get-attributes.js"]=(()=>{var t={exports:{}};let p=n("/lib/build-content/jsx/attributes/build-prop.js");return t.exports=function(t,e,s,o){let r="",i="",l=!0,u=!1,c,n=0;function a(t,e,n="attributes"){for(p(e,n,s),l=!0,u=!1,r="",i="",c=null;0===o[t].trim().length;)t++;return t}for(;">"!==t&&!(e>=o.length);){if(l)if("{"===t){for(;e<o.length&&"}"!==(t=o[++e]);)s.rest+=t;a(e)}else if("="===t||0===t.trim().length)0<r.length&&(l=!1,u=!0);else{if(">"===o[e+1]){"/"===t?s.selfClosed=!0:""!==r&&s.attributes.push([r+t]),e++;break}r+=t}else u&&(c?"{"===c?(i+=t,"{"===t?n++:"}"===t&&(0<n?n--:e=a(e,[r,i.slice(0,-1)],"props"))):"\\"!==o[e-1]&&t===c?e=a(e,[r,i]):i+=t:/["'`{]/.test(t)?c=t:/[a-zA-Z]/.test(t)&&(""!==r&&s.attributes.push([r]),l=!0,u=!1,r=t));">"===(t=o[++e])&&u&&(i+=t,t=o[++e])}return++e},t.exports})(),e["/lib/build-content/jsx/element.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/jsx/attributes/get-attributes.js"),o=n("/lib/build-content/jsx/breckets.js"),e=n("/lib/build-content/jsx/outer.js");class r{tagName="";rest="";inner="";attributes=[];props=[];selfClosed=!1;constructor(t,e,n){if(">"===t[e+1])this.isComponent=!1,this.tagName="",this.i=e+2;else{for(this.isComponent=/[A-Z]/.test(t[e+1]);e<t.length&&!1!==/[A-Za-z0-9.]/.test(t[++e]);)this.tagName+=t[e];n&&this.attributes.push(["component","${this.name}"]),this.i=s(t[e],e,this,t)}!1===this.selfClosed&&this.getInner(t)}get outer(){return e(this)}getInner(t){var e=`</${this.tagName}>`;let n=0;for(var s="</>"==e?"<>":"<"+this.tagName;this.i<t.length;){if(this.inner+=t[this.i],this.inner.endsWith(s)&&n++,this.inner.endsWith(e)){if(!(0<n)){this.inner=this.inner.slice(0,-e.length).trim();break}n--}this.i++}this.buildInner()}buildInner(){let e="";if(!(this.inner.trim().length<2)&&(this.inner.includes("<")||this.inner.includes("{"))){for(let t=0;t<this.inner.length;t++){var n,s;"<"===this.inner[t]?(n=new r(this.inner,t),e+=n.outer,t=n.i):"{"===this.inner[t]?(n=t,t=o(t,this.inner),s=this.inner.slice(n,t),e+="$"+r.jsxParser(s)):e+=this.inner[t]}this.inner=e}}}return t.exports=r,t.exports})(),e["/lib/build-content/jsx/jsx-parser.js"]=(()=>{var t={exports:{}};let i=n("/lib/build-content/jsx/element.js");function e(e,n){let s="";for(let t=0;t<e.length;t++)if("("===e[t]){var o=t;for(t++;0===e[t].trim().length;)t++;if("<"===e[t]){var r=new i(e,t,n);for(t=r.i,s+="`"+r.outer+"`";")"!==e[t];)t++}else s+=e.slice(o,t+1)}else s+=e[t];return s}return i.jsxParser=e,t.exports=e,t.exports})(),e["/lib/build-content/index.js"]=(()=>{var t={exports:{}};let s=n("/lib/build-content/jsx/jsx-parser.js"),o=n("/lib/build-content/build-component/index.js"),r=n("/lib/build-content/remove-comments.js");return t.exports=function(t,e){var n=e.split("/").pop().replace(/\.js$/,""),e=`context.currentPath = '${e}';
`+s(r(t),n);return o(e,n)},t.exports})(),e["/lib/build.js"]=(()=>{var t={exports:{}};let c=n("/lib/build-content/index.js"),a=n("/lib/context/context.js");return t.exports=function(t,e="context",n,s){var o,r=new a(n,s);for(o in t.contents)t.contents[o]=c(t.contents[o],o);let i="";var{links:l,styles:u}=r;return{resultFn:t.build({},r,e),context:r,add:i=s&&!n||!s&&n?[...l.map(t=>`<link rel="stylesheet" href="${t}">`),u.length?`<style>${u.join("\n")}</style>`:""].filter(Boolean).join("\n")+"\n":i}},t.exports})(),e["/lib/browser.js"]=(()=>{var t={exports:{}};let r=n("/lib/build.js");return t.exports=async function(t,e="body",n={},s){await(t=new Require(t)).getContent();var{resultFn:t,context:s,add:o}=r(t,s,!0,!1);return s.data=n,e&&(e=document.querySelector(e))&&(e.innerHTML=o+t(n).trim(),s.runActions()),s},t.exports})(),e["/lib/browser.js"]}{var e;let s=new Function("return "+"{}")();(function t(e){for(var n in e)"function"==typeof e[n]&&e[n].name===Obj.recursiveName?e[n]=e[n](s):null!==e[n]&&"object"==typeof e[n]&&t(e[n])})(s),s}try{t({})}catch(n){{var s=n;var i={"/lib/context/component.js":{from:4,to:78},"/lib/context/context.js":{from:79,to:137},"/lib/build-content/remove-comments.js":{from:138,to:154},"/lib/build-content/jsx/breckets.js":{from:155,to:190},"/lib/build-content/build-component/get-function.js":{from:191,to:209},"/lib/build-content/build-component/index.js":{from:210,to:233},"/lib/build-content/jsx/outer.js":{from:234,to:263},"/lib/build-content/jsx/attributes/build-action.js":{from:264,to:276},"/lib/build-content/jsx/attributes/build-prop.js":{from:277,to:297},"/lib/build-content/jsx/attributes/get-attributes.js":{from:298,to:369},"/lib/build-content/jsx/element.js":{from:370,to:442},"/lib/build-content/jsx/jsx-parser.js":{from:443,to:470},"/lib/build-content/index.js":{from:471,to:487},"/lib/build.js":{from:488,to:513},"/lib/browser.js":{from:514,to:537}};var l=537;let[t,...e]=s.stack.split("\n");throw e=e.map(t=>{var e=t.match(/<anonymous>:(\d*):(\d*)\)$/);if(e){let n=Number(e[1]);if(n+1!==l){var s,o,e=Number(e[2]),r=Object.entries(i).filter(([,{from:t,to:e}])=>n>=t&&n<=e);if(0!==r.length)return[r,{from:s,to:o}]=r[0],` at ${t.match(/at\s(.*?)\s/)[1]} ${r} (${n-s-2}:${e})`}}}).filter(Boolean),s.stack=t+"\n"+e.join("\n"),s;return}}})();

@@ -48,5 +48,5 @@ try {

const i = getInsideBreckets(0, content);
assert.strictEqual(i, content.length);
assert.strictEqual(i, content.length+1);
});
});

@@ -46,2 +46,8 @@ try {

});
it('should remove single-line comment with // inside quotes', () => {
const input = `ic.outerHTML = ic.outerHTML + '<svg version="1.1" id="iconBigCursorSvg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" style="position: absolute;width: 19px;height: 19px;top: 9px; left: 9px;" xml:space="preserve"><path d="M 423.547 323.115 l -320 -320 c -3.051 -3.051 -7.637 -3.947 -11.627 -2.304 s -6.592 5.547 -6.592 9.856 V 480 c 0 4.501 2.837 8.533 7.083 10.048 c 4.224 1.536 8.981 0.192 11.84 -3.285 l 85.205 -104.128 l 56.853 123.179 c 1.792 3.883 5.653 6.187 9.685 6.187 c 1.408 0 2.837 -0.277 4.203 -0.875 l 74.667 -32 c 2.645 -1.131 4.736 -3.285 5.76 -5.973 c 1.024 -2.688 0.939 -5.675 -0.277 -8.299 l -57.024 -123.52 h 132.672 c 4.309 0 8.213 -2.603 9.856 -6.592 C 427.515 330.752 426.598 326.187 423.547 323.115 Z"/></svg>';`;
assert.strictEqual(removeComments(input), input);
});
});
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