jetc 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +10 -10
  2. package/license.txt +1 -1
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -2,14 +2,14 @@
2
2
  function z(...a){a=a.join("/").split("/");let b=a.length;for(let c=1;c<b;c++)0<c&&c<b-1&&!a[c]?(a.splice(c,1),--b,--c):0<c&&"."===a[c]?(a.splice(c,1),--b,--c):1===c&&".."===a[c]&&"."===a[c-1]?(a.splice(c-1,1),--b,--c):0<c&&".."===a[c]&&"."!==a[c-1]&&".."!==a[c-1]&&(a.splice(c-1,2),b-=2,c-=2);return a.join("/")}function A(a,b){try{return require.resolve(a,b).replace(/\\/g,"/")}catch(c){}return null}function B(a){return 0<a.a.length&&""===a.a[0]}
3
3
  class C{constructor(a){this.path=a;this.a=this.path.split("/");this.filename=this.a.pop();this.folder=this.a.join("/");this.ext=this.name=null;a=this.filename.split(".");this.ext=1<a.length&&(a[0]||2<a.length)?a.pop():"";this.name=a.join(".")}mimeType(){return{css:"text/css",htm:"text/html",html:"text/html",js:"application/javascript",json:"application/json",scss:"text/scss",txt:"text/plain",xml:"text/xml"}[this.ext]||""}toString(){return this.path}}
4
4
  function D(a,b,c){({name:b}=new C(b));a=y(a,b,"css");b=z(".",a);c.name=b;return{href:a,filename:b}}function E(a){return a&&"'jet module';"===a.slice(0,13)}function F(a){return"application/javascript"===a}var G={"single-comment":"slash slash *!end-line end-line","multi-comment":"slash star *!(star slash) star slash",comment:"single-comment | multi-comment"},H={"single-string":"single-quote *((escape any) | !single-quote) single-quote"},I={"double-string":"double-quote *((escape any) | !double-quote) double-quote"};
5
- const J={...G,...H,...I,string:"single-string | double-string",bracket:"lbrace | rbrace | lparen | rparen | lbracket | rbracket","base-symbol":"+symbol","extended-symbol":"base-symbol | punctuation | bracket",delimiter:"comment | string | extended-symbol",compress:"*space +delimiter *space",grammar:"*(compress | any)"},K={...J,"base-symbol":": | ="},L={comment:"less exclamation dash dash *!(dash dash more) dash dash more",...H,...I,"attribute-name":"letter *(letter | digit | dash)","attribute-value":"single-string | double-string",
6
- attribute:"attribute-name ?(equal attribute-value)","tag-name":"letter *(letter | digit | dash)","tag-body":"*(space | attribute)","any-tag":"less ?slash tag-name tag-body more",head:"(H | h) (E | e) (A | a) (D | d)",script:"(S | s) (C | c) (R | r) (I | i) (P | p) (T | t)","start-head":"less head tag-body more","end-head":"less slash head more","content-head":"*(tag-script | !end-head)","start-script":"less script tag-body more","end-script":"less slash script more","content-script":"*!end-script",
7
- "tag-head":"start-head content-head end-head","tag-script":"start-script content-script end-script",tag:"tag-head | tag-script | any-tag",grammar:"*(tag | comment | any)"},M={...G,...H,...I,"back-string":"back-quote *((escape any) | (dollar context) | !back-quote) back-quote",string:"single-string | double-string | back-string",context:"lbrace *(code | !rbrace) rbrace","import-source":"single-string | double-string","module-require":"require *space lparen import-source rparen",code:"module-require | comment | string | context",
8
- grammar:"*(code | any)"},P={comment:N,compress:O,delimiter:null},S={attribute:null,"content-head":null,"content-script":null,"end-head":null,"start-head":null,"tag-head":Q,"tag-script":R},U={"import-source":null,"module-require":T};function N(a){return[a,""]}function O(a,b){const c=b.length;let d="";for(let e=0;e<c;e+=2){const f=b[e+1];"space"!==b[e]&&(d+=f)}return[a,d]}
9
- function Q(a,b){var c=t(),{path:d}=c||{};c=' <link href="'+z("/",d)+'" rel="stylesheet">\n ';const e=b.length;let f="",g="",h="";if(d){for(d=0;d<e;d+=2){const l=b[d],m=b[d+1];"start-head"===l?g=m:"end-head"===l?h=m:"content-head"===l&&(f=m)}return[a,g+f+c+h]}return[a,b.filter((l,m)=>1===m%2).join("")]}
5
+ const J={...G,...H,...I,string:"single-string | double-string",whitespace:"+(space | comment)",bracket:"lbrace | rbrace | lparen | rparen | lbracket | rbracket","extended-symbol":"symbol | punctuation | bracket",delimiter:"extended-symbol | string",compress:"*whitespace +delimiter *whitespace",grammar:"*(compress | whitespace | any)"},K={...G,...H,...I,string:"single-string | double-string",whitespace:"+(space | comment)",delimiter:"comma | colon | semicolon | lbrace | rbrace",compress:"*whitespace +delimiter *whitespace",
6
+ grammar:"*(compress | string | whitespace | any)"},L={comment:"less exclamation dash dash *!(dash dash more) dash dash more",...H,...I,"attribute-name":"letter *(letter | digit | dash)","attribute-value":"single-string | double-string",attribute:"attribute-name ?(equal attribute-value)","tag-name":"letter *(letter | digit | dash)","tag-body":"*(space | attribute)","any-tag":"less ?slash tag-name tag-body more",head:"(H | h) (E | e) (A | a) (D | d)",script:"(S | s) (C | c) (R | r) (I | i) (P | p) (T | t)",
7
+ "start-head":"less head tag-body more","end-head":"less slash head more","content-head":"*(tag-script | !end-head)","start-script":"less script tag-body more","end-script":"less slash script more","content-script":"*!end-script","tag-head":"start-head content-head end-head","tag-script":"start-script content-script end-script",tag:"tag-head | tag-script | any-tag",grammar:"*(tag | comment | any)"},M={...G,...H,...I,"back-string":"back-quote *((escape any) | (dollar context) | !back-quote) back-quote",
8
+ string:"single-string | double-string | back-string",context:"lbrace *(code | !rbrace) rbrace","import-source":"single-string | double-string","module-require":"require *space lparen import-source rparen",code:"module-require | comment | string | context",grammar:"*(code | any)"},P={comment:N,compress:O,delimiter:null,whitespace:N},S={attribute:null,"content-head":null,"content-script":null,"end-head":null,"start-head":null,"tag-head":Q,"tag-script":R},U={"import-source":null,"module-require":T};
9
+ function O(a,b){const c=b.length;let d="";for(let e=0;e<c;e+=2){const f=b[e+1];"whitespace"!==b[e]&&(d+=f)}return[a,d]}function Q(a,b){var c=t(),{path:d}=c||{};c=' <link href="'+z("/",d)+'" rel="stylesheet">\n ';const e=b.length;let f="",g="",h="";if(d){for(d=0;d<e;d+=2){const l=b[d],m=b[d+1];"start-head"===l?g=m:"end-head"===l?h=m:"content-head"===l&&(f=m)}return[a,g+f+c+h]}return[a,b.filter((l,m)=>1===m%2).join("")]}
10
10
  function T(a,b){const c=t(),{aliases:d}=c||{},e=b.length;let f=null;for(let g=0;g<e;g+=2){const h=b[g+1];"import-source"===b[g]&&(c?(f=h.slice(1,-1),f=d[f]||f,f=h[0]+f+h[h.length-1]):f=h)}return[a,"require("+f+")"]}
11
11
  function R(a,b){const c=t(),{folder:d,name:e}=c||{},f=b.length;let g="",h="",l="",m=!1;c&&!c.deps&&(c.deps=[]);for(let n=0;n<f;n+=2){const k=b[n],p=b[n+1];"attribute"===k?"src="===p.slice(0,4).toLowerCase()?(h=p.slice(5,-1),m="jeti"===h.slice(-4)||"jeti/index.js"===h.slice(-13)):"type="===p.slice(0,5).toLowerCase()&&(l=p.slice(6,-1).toLowerCase()):"content-script"===k&&(g=p)}if("application/jet"===l){if(!h&&!g)return[a,""];c&&(!h&&e&&(b=c.deps.map(n=>n.path),h=y(d,e,"js",b)),c.deps.push({content:g,
12
- path:h}));return[a,'<script src="'+z("/",h)+'">\x3c/script>']}return m?[a,""]:[a,b.filter((n,k)=>1===k%2).join("")]}function V(a,b){u({path:b});a=v(a,L,S);r();return a}class W extends Promise{config(a){return this.then(b=>{Object.assign(b.config,a);return b})}save(a,b){return this.then(c=>X(a,c,b))}}
12
+ path:h}));return[a,'<script src="'+z("/",h)+'">\x3c/script>']}return m?[a,""]:[a,b.filter((n,k)=>1===k%2).join("")]}function N(a){return[a," "]}function V(a,b){u({path:b});a=v(a,L,S);r();return a}class W extends Promise{config(a){return this.then(b=>{Object.assign(b.config,a);return b})}save(a,b){return this.then(c=>X(a,c,b))}}
13
13
  function X(a,b,c){const d=b.fragments;(c||{}).remove&&w(a)&&q.rmSync(a,{recursive:!0});Object.keys(d).forEach(e=>{const f=d[e].content;e=z(a,e);const g=(new C(e)).folder;w(g)||q.mkdirSync(g,{recursive:!0});q.writeFileSync(e,f)});return b}
14
14
  class aa{constructor(a,b,c,d){({resolve:d}=d||{});this.content=c||"";this.deps=[];this.root=this.path=this.name=this.module=this.mimeType=this.location=null;if(d)if(c=a.root,d=new C(b),B(d)||0<d.a.length&&("."===d.a[0]||".."===d.a[0])){d=z(c,b);d=x(d)?b.slice(1):null;if(!d){{d=c;const f=B(new C(d));var e=z(f?"":".",d,b);if(e=A(e)){const g=process.cwd().replace(/\\/g,"/");d=f?d:z(g,d);d=e.slice(d.length)}else d=null}}if(this.path=d)this.root=c}else{a:{if(c=A(b,{paths:[c]})){const [f,g]=ba(c);if(g){d=
15
15
  require(g);c=[d.name+"@"+d.version,f,c.slice(f.length)];break a}}c=null}c&&([this.module,this.root,this.path]=c)}else this.path="/"+b,this.root=a.root;if(this.path)this.name=z(this.module||a.name,this.path),this.location=z(this.root,this.path),this.path="."+this.path,a=new C(this.path),this.folder=a.folder,this.mimeType=a.mimeType();else throw Error("Cannot find "+b);}load(){this.content||(this.content=q.readFileSync(this.location,"utf8"))}parse(){if("text/html"===this.mimeType){var a=this.content;
@@ -19,8 +19,8 @@ function Y(a,b,c,d,e){const f=a.config,g=a.fragments,h=a.modules,l=a.namespaces;
19
19
  {};const n=[];d.deps.length&&(m=!0,d.deps.forEach(k=>{if(!(f&&f.externs&&-1<f.externs.indexOf(k))||f&&f["include-externs"]){var p=null;"string"===typeof k?(p=b.get(k))||(p=Y(a,b,k,"",{resolve:!0})):k&&k.path&&(p=Y(a,b,k.path,k.content));n.push(p)}}),d.deps=n);m&&d.translate(b.aliases);-1<d.root.indexOf("node_modules/")?h[e]=d.b():g[e]=d.b()}return e}
20
20
  class ea{constructor(a,b,c){this.content=[];this.deps=c;this.name=a;this.mimeType=b}b(){const a=this.deps,b=this.mimeType;return{content:this.content.join(""),deps:a,mimeType:b}}}class fa{constructor(){this.all=[]}close(a){this[a]&&delete this[a]}create(a,b,c){this[b]=new ea(a,b,c);this.all.push(this[b]);return this[b]}get(a){return this[a]}getAll(){return this.all}}
21
21
  class ha{close(a){this[a]&&delete this[a]}get(a){this[a]||(this[a]={});return this[a]}has(a,b){return(this[a]||{})[b]}put(a,b){this.get(a)[b]=!0}}
22
- function Z(a,b){var c=a.config;const d=a.c;var e=a.modules;const f=a.register,g=c.root;e=a.fragments[b]||e[b];if(!e)throw Error("Fragment not found "+b);var h=e.deps;const l=e.mimeType;if(!f.has(l,b)){const m=d.get(l)||d.create(b,l,"text/html"===l?h:[]),n=m.name===b&&F(l);c=c&&c["module-name"];if(F(l)){const k=n&&c?c:b;e.content=E(e.content)?e.content.slice(13):"require('"+k+"', function(module, exports) {\n"+e.content+"});\n"}n&&!c&&m.content.push("(function(){function e(b,a){if('function'===typeof a)b=d[b]=a;else{a=d[b];if('function'===typeof a){{const c={exports:{}};a(c,c.exports);a=c}a=d[b]=a}b=a?a.exports:null}return b}const d={};e.load=function(b){const a=b.indexOf('.css')===b.length-4?'style':'script';return fetch(b).then(c=>c.text()).then(c=>{{const f=document.createElement(a);f.appendChild(document.createTextNode(c));document.head.appendChild(f)}})};'object'!==typeof window||window.require||(window.require=e)})();\n");
22
+ function Z(a,b){var c=a.config;const d=a.c;var e=a.modules;const f=a.register,g=c.root;e=a.fragments[b]||e[b];if(!e)throw Error("Fragment not found "+b);var h=e.deps;const l=e.mimeType;if(!f.has(l,b)){const m=d.get(l)||d.create(b,l,"text/html"===l?h:[]),n=m.name===b&&F(l);c=c&&c["module-name"];if(F(l)){const k=n&&c?c:b;e.content=E(e.content)?e.content.slice(13):"require('"+k+"', function(module, exports) {\n"+e.content+"});\n"}n&&!c&&m.content.push("(function(){function e(b,a){if('function'===typeof a)b=d[b]=a;else{a=d[b];if('function'===typeof a){{const c={exports:{}};a(c,c.exports);a=c}a=d[b]=a}b=a?a.exports:null}return b}const d={};e.load=function(b){const a=b.indexOf('.css')===b.length-4?'style':'script';return fetch(b).then(c=>200===c.status?c.text():'').then(c=>{if(c){const f=document.createElement(a);f.appendChild(document.createTextNode(c));document.head.appendChild(f)}})};'object'!==typeof window||window.require||(window.require=e)})();\n");
23
23
  f.put(l,b);h.forEach(k=>{"text/html"===l&&(f.close("application/javascript"),d.close("application/javascript"));Z(a,k)});F(l)&&n&&0===Object.keys(f["text/html"]||{}).length&&(h=d.get("text/css"))&&D(g,b,h);if("text/html"===l&&(h=d.get("text/css"))){const {href:k,filename:p}=D(g,b,h);e.content=V(e.content,k);m.deps.push(p)}m.content.push(e.content);n&&!c&&m.content.push("'object'===typeof window&&window.addEventListener('DOMContentLoaded',function(){require('"+b+"')});\n")}}
24
- function ia(a,b){const c=b[a];if(!F(c.mimeType))throw Error("Entry must be a JavaScript to make module");Object.keys(b).forEach(d=>{const e=b[d],f=e.content;"text/css"===e.mimeType&&(c.content="if('object'===typeof document){const a=document.createElement('style');a.appendChild(document.createTextNode('"+f.replace(/\\/g,"\\\\").replace(/[']/g,"\\'")+"'));document.head.appendChild(a);}"+c.content,delete b[d])});c.content="'jet module';"+c.content}
25
- module.exports={compress:function(a){const b=a.fragments;Object.keys(b).forEach(c=>{c=b[c];const d=c.content,e=c.mimeType;if(F(e)||"text/css"===e)c.content=v(d,"text/css"===e?K:J,P)});return a},entry:function(a){return new W((b,c)=>{try{const {filename:d,folder:e}=new C(a),f={config:{root:z(process.cwd(),e),entries:[d]},fragments:{},modules:{}};b(f)}catch(d){c(d)}})},makemod:function(a){const b=a.fragments;a.config.entries.map(c=>ia(c,b));return a},pack:function(a){const b=a.config.entries,c=new fa,
26
- d=new ha;a.c=c;a.register=d;b.forEach(f=>Z(a,f));const e={};c.getAll().forEach(f=>{const g=f.name;g&&(e[g]=f.b())});a.fragments=e;a.modules={};delete a.c;delete a.register;return a},parse:function(a){const b=a.config,c=b.entries,d=new da,e=d.create(".",b.root);a.namespaces=d;b.entries=c.map(f=>Y(a,e,f));delete a.namespaces;return a}};
24
+ function ia(a,b,c){const d=c[b];if(!F(d.mimeType))throw Error("Entry must be a JavaScript to make a module");Object.keys(c).forEach(e=>{const f=c[e],g=f.content;"text/css"===f.mimeType&&(d.content="if('object'===typeof document){const a=document.createElement('style');"+(a?"a.id='"+a+"';":"")+"a.appendChild(document.createTextNode('"+g.replace(/\\/g,"\\\\").replace(/[']/g,"\\'")+"'));document.head.appendChild(a);}"+d.content,delete c[e])});d.content="'jet module';"+d.content}
25
+ module.exports={compress:function(a){const b=a.fragments;Object.keys(b).forEach(c=>{c=b[c];const d=c.content,e=c.mimeType;if(F(e)||"text/css"===e)c.content=v(d,"text/css"===e?K:J,P).trim()});return a},entry:function(a){return new W((b,c)=>{try{const {filename:d,folder:e}=new C(a),f={config:{root:z(process.cwd(),e),entries:[d]},fragments:{},modules:{}};b(f)}catch(d){c(d)}})},makemod:function(a){const b=a.config,c=a.fragments,d=b.entries,e=b&&b["module-name"];if(!e)throw Error("Config must include 'module-name' to make a module");
26
+ d.map(f=>ia(e,f,c));return a},pack:function(a){const b=a.config.entries,c=new fa,d=new ha;a.c=c;a.register=d;b.forEach(f=>Z(a,f));const e={};c.getAll().forEach(f=>{const g=f.name;g&&(e[g]=f.b())});a.fragments=e;a.modules={};delete a.c;delete a.register;return a},parse:function(a){const b=a.config,c=b.entries,d=new da,e=d.create(".",b.root);a.namespaces=d;b.entries=c.map(f=>Y(a,e,f));delete a.namespaces;return a}};
package/license.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  License
2
2
 
3
- Copyright © 2020-2022 by Oleksandr Krayilo
3
+ Copyright © 2020-2023 by Oleksandr Krayilo
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jetc",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Jet.js Compiler and Server.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,6 +22,6 @@
22
22
  "author": "Oleksandr Krayilo",
23
23
  "license": "ISC",
24
24
  "dependencies": {
25
- "jeti": "^0.8.1"
25
+ "jeti": "^0.8.3"
26
26
  }
27
27
  }