Sublime Forum

Sublime snippet failing

#1

The following snippet for inserting the cash library (it’s a jquery replacement) as a snippet isn’t working when I type the tabTrigger and then press tab.

It seems to not be an issue of size (they are over 16000 characters), but an issue related to a character in the code of the snippet preventing this snippet from working properly, because it worked when I removed the first few blocks of code from the library. Since basically all of the library is compressed and in one line, I also tried splitting the code of the library into multiple lines by adding a line break after every “;”, and it also didn’t work. Also tried inserting the unminified lib, minified and super minified lib, none worked. Beyond this, I don’t know what causes this issue.

How to replicate the issue:
On MacOS Catalina Sublime Text build 4113, add the following snippet for javascript, then type in the keyTrigger cashlib and press tab. The snippet isn’t inserted, instead the typed keyTrigger simply disappears.

Care to take a look? Should I be using a different solution to insert long strings or pieces of code, such as libraries directly in the body of a javascript file without using imports or copy pasting from a file? I know there are more organized ways to insert javascript in production, but I do this for very simple javascript injections that I use for my own web navigation or when building web plugins quickly.

Thank you, I love you.

<snippet>
  <content><![CDATA[
/* cash lib */
  !function(){
  "use strict";var i={class:"className",contenteditable:"contentEditable",for:"htmlFor",readonly:"readOnly",maxlength:"maxLength",tabindex:"tabIndex",colspan:"colSpan",rowspan:"rowSpan",usemap:"useMap"};function o(t,n){try{return t(n)}catch(t){return n}}var s=document,u=window,a=s.documentElement,f=s.createElement.bind(s),t=f("div"),n=f("table"),e=f("tbody"),r=f("tr"),c=Array.isArray,l=Array.prototype,h=l.concat,d=l.filter,p=l.indexOf,g=l.map,v=l.push,m=l.slice,y=l.some,b=l.splice,_=/^#(?:[\w-]|\\.|[^\x00-\xa0])*$/,x=/^\.(?:[\w-]|\\.|[^\x00-\xa0])*$/,C=/<.+>/,w=/^\w+$/;function E(t,n){return t&&(P(n)||R(n))?x.test(t)?n.getElementsByClassName(t.slice(1)):w.test(t)?n.getElementsByTagName(t):n.querySelectorAll(t):[]}var N=(A.prototype.init=function(t,n){return new A(t,n)},A),T=N.prototype,S=T.init;function A(t,n){if(t){if(t instanceof N)return t;var e=t;if(k(t)){if(e=(n instanceof N?n[0]:n)||s,!(e=_.test(t)?e.getElementById(t.slice(1)):C.test(t)?_t(t):E(t,e)))return}else if(I(t))return this.ready(t);for(!e.nodeType&&e!==u||(e=[e]),this.length=e.length,t=0,n=this.length;t<n;t++)this[t]=e[t]}}(S.fn=S.prototype=T).length=0,T.splice=b,"function"==typeof Symbol&&(T[Symbol.iterator]=l[Symbol.iterator]),T.map=function(e){return S(h.apply([],g.call(this,function(t,n){return e.call(t,n,t)})))},T.slice=function(t,n){return S(m.call(this,t,n))};var L=/-([a-z])/g;function O(t){return t.replace(L,function(t,n){return n.toUpperCase()})}function B(t,n){var e=t&&(t.matches||t.webkitMatchesSelector||t.msMatchesSelector);return!!e&&!!n&&e.call(t,n)}function M(t){return!!t&&t===t.window}function P(t){return t&&9===t.nodeType}function R(t){return!!t&&1===t.nodeType}function I(t){return"function"==typeof t}function k(t){return"string"==typeof t}function W(t){return!isNaN(parseFloat(t))&&isFinite(t)}function $(t){return"object"==typeof t&&null!==t&&(null===(t=Object.getPrototypeOf(t))||t===Object.prototype)}function j(t,n,e){if(e)for(e=t.length;e--&&!1!==n.call(t[e],e,t[e]););else if($(t)){var r=Object.keys(t);e=0;for(var i=r.length;e<i;e++){var o=r[e];if(!1===n.call(t[o],o,t[o]))break}}else for(e=0,i=t.length;e<i&&!1!==n.call(t[e],e,t[e]);e++);return t}function D(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];n="boolean"==typeof t[0]&&t.shift();var e=t.shift(),r=t.length;if(!e)return{};if(!r)return D(n,S,e);for(var i=0;i<r;i++){var o,u=t[i];for(o in u)n&&(c(u[o])||$(u[o]))?(e[o]&&e[o].constructor===u[o].constructor||(e[o]=new u[o].constructor),D(n,e[o],u[o])):e[o]=u[o]}return e}function H(e){return k(e)?function(t,n){return B(n,e)}:I(e)?e:e instanceof N?function(t,n){return e.is(n)}:e?function(t,n){return n===e}:function(){return!1}}function U(t,n){return n?t.filter(n):t}S.guid=1,S.isWindow=M,S.isFunction=I,S.isArray=c,S.isNumeric=W,S.isPlainObject=$,T.get=function(t){return void 0===t?m.call(this):this[(t=Number(t))<0?t+this.length:t]},T.eq=function(t){return S(this.get(t))},T.first=function(){return this.eq(0)},T.last=function(){return this.eq(-1)},S.each=j,T.each=function(t){return j(this,t)},T.prop=function(e,r){if(e){if(k(e))return e=i[e]||e,arguments.length<2?this[0]&&this[0][e]:this.each(function(t,n){n[e]=r});for(var t in e)this.prop(t,e[t]);return this}},T.removeProp=function(e){return this.each(function(t,n){delete n[i[e]||e]})},S.extend=D,T.extend=function(t){return D(T,t)},T.filter=function(t){var e=H(t);return S(d.call(this,function(t,n){return e.call(t,n,t)}))};var F=/\S+/g;function q(t){return k(t)&&t.match(F)||[]}function z(t,n,e,r){for(var i=[],o=I(n),u=r&&H(r),s=0,c=t.length;s<c;s++)if(o){var a=n(t[s]);a.length&&v.apply(i,a)}else for(a=t[s][n];!(null==a||r&&u(-1,a));)i.push(a),a=e?a[n]:null;return i}function J(t){return 1<t.length?d.call(t,function(t,n,e){return p.call(e,t)===n}):t}function Y(t,n,e){if(R(t)){var r=u.getComputedStyle(t,null);return e?r.getPropertyValue(n)||void 0:r[n]||t.style[n]}}function G(t,n){return parseInt(Y(t,n),10)||0}T.hasClass=function(n){return!!n&&y.call(this,function(t){return R(t)&&t.classList.contains(n)})},T.removeAttr=function(t){var n=q(t);return this.each(function(t,e){R(e)&&j(n,function(t,n){e.removeAttribute(n)})})},T.attr=function(e,r){if(e){if(k(e)){if(arguments.length<2){if(!this[0]||!R(this[0]))return;var t=this[0].getAttribute(e);return null===t?void 0:t}return void 0===r?this:null===r?this.removeAttr(e):this.each(function(t,n){R(n)&&n.setAttribute(e,r)})}for(t in e)this.attr(t,e[t]);return this}},T.toggleClass=function(t,r){var n=q(t),i=void 0!==r;return this.each(function(t,e){R(e)&&j(n,function(t,n){i?r?e.classList.add(n):e.classList.remove(n):e.classList.toggle(n)})})},T.addClass=function(t){return this.toggleClass(t,!0)},T.removeClass=function(t){return arguments.length?this.toggleClass(t,!1):this.attr("class","")},S.unique=J,T.add=function(t,n){return S(J(this.get().concat(S(t,n).get())))};var V=/^--/,X={},K=t.style,Q=["webkit","moz","ms"],Z={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,gridArea:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnStart:!0,gridRow:!0,gridRowEnd:!0,gridRowStart:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};function tt(t,n,e){return void 0===e&&(e=V.test(t)),e||Z[t]||!W(n)?n:n+"px"}T.css=function(e,r){if(k(e)){var i=V.test(e);return(o=e,void 0===(t=i)&&(t=V.test(o)),e=t?o:(X[o]||(n=""+(t=O(o))[0].toUpperCase()+t.slice(1),j(t=(t+" "+Q.join(n+" ")+n).split(" "),function(t,n){if(n in K)return X[o]=n,!1})),X[o]),arguments.length<2)?this[0]&&Y(this[0],e,i):e?(r=tt(e,r,i),this.each(function(t,n){R(n)&&(i?n.style.setProperty(e,r):n.style[e]=r)})):this}var o,t,n,u;for(u in e)this.css(u,e[u]);return this};var nt=/^\s+|\s+$/;function et(t,n){return t=t.dataset[n]||t.dataset[O(n)],nt.test(t)?t:o(JSON.parse,t)}function rt(t,n){var e=t.documentElement;return Math.max(t.body["scroll"+n],e["scroll"+n],t.body["offset"+n],e["offset"+n],e["client"+n])}function it(t,n){return G(t,"border"+(n?"Left":"Top")+"Width")+G(t,"padding"+(n?"Left":"Top"))+G(t,"padding"+(n?"Right":"Bottom"))+G(t,"border"+(n?"Right":"Bottom")+"Width")}j([!0,!(T.data=function(e,r){if(!e){if(!this[0])return;var t,n={};for(t in this[0].dataset)n[t]=et(this[0],t);return n}if(k(e))return arguments.length<2?this[0]&&et(this[0],e):void 0===r?this:this.each(function(t,n){t=r,t=o(JSON.stringify,t),n.dataset[O(e)]=t});for(t in e)this.data(t,e[t]);return this})],function(t,r){j(["Width","Height"],function(n,e){T[(r?"outer":"inner")+e]=function(t){if(this[0])return M(this[0])?r?this[0]["inner"+e]:this[0].document.documentElement["client"+e]:P(this[0])?rt(this[0],e):this[0][(r?"offset":"client")+e]+(t&&r?G(this[0],"margin"+(n?"Top":"Left"))+G(this[0],"margin"+(n?"Bottom":"Right")):0)}})}),j(["Width","Height"],function(r,n){var i=n.toLowerCase();T[i]=function(t){if(!this[0])return void 0===t?void 0:this;if(!arguments.length)return M(this[0])?this[0].document.documentElement["client"+n]:P(this[0])?rt(this[0],n):this[0].getBoundingClientRect()[i]-it(this[0],!r);var e=parseInt(t,10);return this.each(function(t,n){R(n)&&(t=Y(n,"boxSizing"),n.style[i]=tt(i,e+("border-box"===t?it(n,!r):0)))})}});var ot={};function ut(n,t){return!t||!y.call(t,function(t){return n.indexOf(t)<0})}T.toggle=function(i){return this.each(function(t,n){var e,r;R(n)&&((void 0===i?"none"===Y(n,"display"):i)?(n.style.display=n.___cd||"","none"===Y(n,"display")&&(t=n.style,n=n.tagName,n=ot[n]||(e=f(n),s.body.insertBefore(e,null),r=Y(e,"display"),s.body.removeChild(e),ot[n]="none"!==r?r:"block"),t.display=n)):(n.___cd=Y(n,"display"),n.style.display="none"))})},T.hide=function(){return this.toggle(!1)},T.show=function(){return this.toggle(!0)};var st={focus:"focusin",blur:"focusout"},ct={mouseenter:"mouseover",mouseleave:"mouseout"},at=/^(mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function ft(t){return[(t=t.split("."))[0],t.slice(1).sort()]}function lt(r,i,o,u,s){var t=r.___ce=r.___ce||{};if(i)t[i]&&(t[i]=t[i].filter(function(t){var n=t[0],e=t[1];if(t=t[2],s&&t.guid!==s.guid||!ut(n,o)||u&&u!==e)return!0;r.removeEventListener(i,t)}));else for(i in t)lt(r,i,o,u,s)}function ht(t){return t.multiple&&t.options?z(d.call(t.options,function(t){return t.selected&&!t.disabled&&!t.parentNode.disabled}),"value"):t.value||""}T.off=function(t,i,o){var u=this;if(void 0===t)this.each(function(t,n){(R(n)||P(n)||M(n))&&lt(n)});else if(k(t))I(i)&&(o=i,i=""),j(q(t),function(t,n){n=(t=ft(n))[0];var e=t[1],r=ct[n]||st[n]||n;u.each(function(t,n){(R(n)||P(n)||M(n))&&lt(n,r,e,i,o)})});else for(var n in t)this.off(n,t[n]);return this},T.on=function(t,l,h,d,p){var n,e=this;if(k(t))return k(l)||(null!=l&&(void 0!==h&&(d=h),h=l),l=""),I(d)||(d=h,h=void 0),d&&j(q(t),function(t,n){n=(t=ft(n))[0];var s=t[1],c=ct[n]||st[n]||n,a=n in ct,f=n in st;c&&e.each(function(t,i){var n,e,r,o,u;(R(i)||P(i)||M(i))&&((t=function t(n){if(n.target["___i"+n.type])return n.stopImmediatePropagation();if((!n.namespace||ut(s,n.namespace.split(".")))&&(l||!(f&&(n.target!==i||n.___ot===c)||a&&n.relatedTarget&&i.contains(n.relatedTarget)))){var e=i;if(l){for(var r=n.target;!B(r,l);){if(r===i)return;if(!(r=r.parentNode))return}e=r,n.___cd=!0}n.___cd&&Object.defineProperty(n,"currentTarget",{configurable:!0,get:function(){return e}}),Object.defineProperty(n,"data",{configurable:!0,get:function(){return h}}),r=d.call(e,n,n.___td),p&&lt(i,c,s,l,t),!1===r&&(n.preventDefault(),n.stopPropagation())}}).guid=d.guid=d.guid||S.guid++,e=c,r=s,o=l,u=t,(t=(n=i).___ce=n.___ce||{})[e]=t[e]||[],t[e].push([r,o,u]),n.addEventListener(e,u))})}),this;for(n in t)this.on(n,l,h,t[n],p);return this},T.one=function(t,n,e,r){return this.on(t,n,e,r,!0)},T.ready=function(t){function n(){return setTimeout(t,0,S)}return"loading"!==s.readyState?n():s.addEventListener("DOMContentLoaded",n),this},T.trigger=function(e,t){if(k(e)){var n=(r=ft(e))[0],r=r[1],i=ct[n]||st[n]||n;if(!i)return this;var o=at.test(i)?"MouseEvents":"HTMLEvents";(e=s.createEvent(o)).initEvent(i,!0,!0),e.namespace=r.join("."),e.___ot=n}e.___td=t;var u=e.___ot in st;return this.each(function(t,n){u&&I(n[e.___ot])&&(n["___i"+e.type]=!0,n[e.___ot](),n["___i"+e.type]=!1),n.dispatchEvent(e)})};var dt=/%20/g,pt=/\r?\n/g,gt=/file|reset|submit|button|image/i,vt=/radio|checkbox/i;T.serialize=function(){var r="";return this.each(function(t,n){j(n.elements||[n],function(t,e){e.disabled||!e.name||"FIELDSET"===e.tagName||gt.test(e.type)||vt.test(e.type)&&!e.checked||void 0!==(t=ht(e))&&j(t=c(t)?t:[t],function(t,n){t=r,n="&"+encodeURIComponent(e.name)+"="+encodeURIComponent(n.replace(pt,"\r\n")).replace(dt,"+"),r=t+n})})}),r.slice(1)},T.val=function(r){return arguments.length?this.each(function(t,n){var e;(t=n.multiple&&n.options)||vt.test(n.type)?(e=c(r)?g.call(r,String):null===r?[]:[String(r)],t?j(n.options,function(t,n){n.selected=0<=e.indexOf(n.value)},!0):n.checked=0<=e.indexOf(n.value)):n.value=null==r?"":r}):this[0]&&ht(this[0])},T.clone=function(){return this.map(function(t,n){return n.cloneNode(!0)})},T.detach=function(t){return U(this,t).each(function(t,n){n.parentNode&&n.parentNode.removeChild(n)}),this};var mt=/^\s*<(\w+)[^>]*>/,yt=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,bt={"*":t,tr:e,td:r,th:r,thead:n,tbody:n,tfoot:n};function _t(t){if(!k(t))return[];if(yt.test(t))return[f(RegExp.$1)];var n=mt.test(t)&&RegExp.$1;return(n=bt[n]||bt["*"]).innerHTML=t,S(n.childNodes).detach().get()}S.parseHTML=_t,T.empty=function(){return this.each(function(t,n){for(;n.firstChild;)n.removeChild(n.firstChild)})},T.html=function(e){return arguments.length?void 0===e?this:this.each(function(t,n){R(n)&&(n.innerHTML=e)}):this[0]&&this[0].innerHTML},T.remove=function(t){return U(this,t).detach().off(),this},T.text=function(e){return void 0===e?this[0]?this[0].textContent:"":this.each(function(t,n){R(n)&&(n.textContent=e)})},T.unwrap=function(){return this.parent().each(function(t,n){"BODY"!==n.tagName&&(t=S(n)).replaceWith(t.children())}),this},T.offset=function(){var t=this[0];if(t)return{top:(t=t.getBoundingClientRect()).top+u.pageYOffset,left:t.left+u.pageXOffset}},T.offsetParent=function(){return this.map(function(t,n){for(t=n.offsetParent;t&&"static"===Y(t,"position");)t=t.offsetParent;return t||a})},T.position=function(){var t=this[0];if(t){var n=(r="fixed"===Y(t,"position"))?t.getBoundingClientRect():this.offset();if(!r){for(var e=t.ownerDocument,r=t.offsetParent||e.documentElement;(r===e.body||r===e.documentElement)&&"static"===Y(r,"position");)r=r.parentNode;r!==t&&R(r)&&(e=S(r).offset(),n.top-=e.top+G(r,"borderTopWidth"),n.left-=e.left+G(r,"borderLeftWidth"))}return{top:n.top-G(t,"marginTop"),left:n.left-G(t,"marginLeft")}}},T.children=function(t){return U(S(J(z(this,function(t){return t.children}))),t)},T.contents=function(){return S(J(z(this,function(t){return"IFRAME"===t.tagName?[t.contentDocument]:("TEMPLATE"===t.tagName?t.content:t).childNodes})))},T.find=function(n){return S(J(z(this,function(t){return E(n,t)})))};var xt=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,Ct=/^$|^module$|\/(java|ecma)script/i,wt=["type","src","nonce","noModule"];function Et(t,e,u,s,c,n,r,i){return j(t,function(t,n){j(S(n),function(r,o){j(S(e),function(t,n){var i,e=u?n:o;n=u?o:n,e=(t=u?r:t)?e.cloneNode(!0):e,t=!t,c?n.insertBefore(e,s?n.firstChild:null):n.parentNode.insertBefore(e,s?n:n.nextSibling),t&&(e=e,i=n.ownerDocument,(e=S(e)).filter("script").add(e.find("script")).each(function(t,e){var r;Ct.test(e.type)&&a.contains(e)&&((r=f("script")).text=e.textContent.replace(xt,""),j(wt,function(t,n){e[n]&&(r[n]=e[n])}),i.head.insertBefore(r,null),i.head.removeChild(r))}))},i)},r)},n),e}T.after=function(){return Et(arguments,this,!1,!1,!1,!0,!0)},T.append=function(){return Et(arguments,this,!1,!1,!0)},T.appendTo=function(t){return Et(arguments,this,!0,!1,!0)},T.before=function(){return Et(arguments,this,!1,!0)},T.insertAfter=function(t){return Et(arguments,this,!0,!1,!1,!1,!1,!0)},T.insertBefore=function(t){return Et(arguments,this,!0,!0)},T.prepend=function(){return Et(arguments,this,!1,!0,!0,!0,!0)},T.prependTo=function(t){return Et(arguments,this,!0,!0,!0,!1,!1,!0)},T.replaceWith=function(t){return this.before(t).remove()},T.replaceAll=function(t){return S(t).replaceWith(this),this},T.wrapAll=function(t){for(var n=(t=S(t))[0];n.children.length;)n=n.firstElementChild;return this.first().before(t),this.appendTo(n)},T.wrap=function(r){return this.each(function(t,n){var e=S(r)[0];S(n).wrapAll(t?e.cloneNode(!0):e)})},T.wrapInner=function(e){return this.each(function(t,n){(n=(t=S(n)).contents()).length?n.wrapAll(e):t.append(e)})},T.has=function(e){var t=k(e)?function(t,n){return E(e,n).length}:function(t,n){return n.contains(e)};return this.filter(t)},T.is=function(t){var e=H(t);return y.call(this,function(t,n){return e.call(t,n,t)})},T.next=function(t,n,e){return U(S(J(z(this,"nextElementSibling",n,e))),t)},T.nextAll=function(t){return this.next(t,!0)},T.nextUntil=function(t,n){return this.next(n,!0,t)},T.not=function(e){var r=H(e);return this.filter(function(t,n){return(!k(e)||R(n))&&!r.call(n,t,n)})},T.parent=function(t){return U(S(J(z(this,"parentNode"))),t)},T.index=function(t){var n=(t?S(t):this)[0];return t=t?this:S(n).parent().children(),p.call(t,n)},T.closest=function(t){var n=this.filter(t);if(n.length)return n;var e=this.parent();return e.length?e.closest(t):n},T.parents=function(t,n){return U(S(J(z(this,"parentElement",!0,n))),t)},T.parentsUntil=function(t,n){return this.parents(n,t)},T.prev=function(t,n,e){return U(S(J(z(this,"previousElementSibling",n,e))),t)},T.prevAll=function(t){return this.prev(t,!0)},T.prevUntil=function(t,n){return this.prev(n,!0,t)},T.siblings=function(t){return U(S(J(z(this,function(t){return S(t).parent().children().not(t)}))),t)},"undefined"!=typeof exports?module.exports=S:u.cash=u.$=S
}();
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <tabTrigger>cashlib</tabTrigger>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.js</scope>
</snippet>
0 Likes

#2

You may want to escape all $ in the content. Otherwise those are interpreted as beginning of variables/placeholders, which results in invalid snippet content.

<snippet>
  <content><![CDATA[
/* cash lib */
  !function(){
  "use strict";var i={class:"className",contenteditable:"contentEditable",for:"htmlFor",readonly:"readOnly",maxlength:"maxLength",tabindex:"tabIndex",colspan:"colSpan",rowspan:"rowSpan",usemap:"useMap"};function o(t,n){try{return t(n)}catch(t){return n}}var s=document,u=window,a=s.documentElement,f=s.createElement.bind(s),t=f("div"),n=f("table"),e=f("tbody"),r=f("tr"),c=Array.isArray,l=Array.prototype,h=l.concat,d=l.filter,p=l.indexOf,g=l.map,v=l.push,m=l.slice,y=l.some,b=l.splice,_=/^#(?:[\w-]|\\.|[^\x00-\xa0])*\$/,x=/^\.(?:[\w-]|\\.|[^\x00-\xa0])*\$/,C=/<.+>/,w=/^\w+\$/;function E(t,n){return t&&(P(n)||R(n))?x.test(t)?n.getElementsByClassName(t.slice(1)):w.test(t)?n.getElementsByTagName(t):n.querySelectorAll(t):[]}var N=(A.prototype.init=function(t,n){return new A(t,n)},A),T=N.prototype,S=T.init;function A(t,n){if(t){if(t instanceof N)return t;var e=t;if(k(t)){if(e=(n instanceof N?n[0]:n)||s,!(e=_.test(t)?e.getElementById(t.slice(1)):C.test(t)?_t(t):E(t,e)))return}else if(I(t))return this.ready(t);for(!e.nodeType&&e!==u||(e=[e]),this.length=e.length,t=0,n=this.length;t<n;t++)this[t]=e[t]}}(S.fn=S.prototype=T).length=0,T.splice=b,"function"==typeof Symbol&&(T[Symbol.iterator]=l[Symbol.iterator]),T.map=function(e){return S(h.apply([],g.call(this,function(t,n){return e.call(t,n,t)})))},T.slice=function(t,n){return S(m.call(this,t,n))};var L=/-([a-z])/g;function O(t){return t.replace(L,function(t,n){return n.toUpperCase()})}function B(t,n){var e=t&&(t.matches||t.webkitMatchesSelector||t.msMatchesSelector);return!!e&&!!n&&e.call(t,n)}function M(t){return!!t&&t===t.window}function P(t){return t&&9===t.nodeType}function R(t){return!!t&&1===t.nodeType}function I(t){return"function"==typeof t}function k(t){return"string"==typeof t}function W(t){return!isNaN(parseFloat(t))&&isFinite(t)}function \$(t){return"object"==typeof t&&null!==t&&(null===(t=Object.getPrototypeOf(t))||t===Object.prototype)}function j(t,n,e){if(e)for(e=t.length;e--&&!1!==n.call(t[e],e,t[e]););else if(\$(t)){var r=Object.keys(t);e=0;for(var i=r.length;e<i;e++){var o=r[e];if(!1===n.call(t[o],o,t[o]))break}}else for(e=0,i=t.length;e<i&&!1!==n.call(t[e],e,t[e]);e++);return t}function D(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];n="boolean"==typeof t[0]&&t.shift();var e=t.shift(),r=t.length;if(!e)return{};if(!r)return D(n,S,e);for(var i=0;i<r;i++){var o,u=t[i];for(o in u)n&&(c(u[o])||\$(u[o]))?(e[o]&&e[o].constructor===u[o].constructor||(e[o]=new u[o].constructor),D(n,e[o],u[o])):e[o]=u[o]}return e}function H(e){return k(e)?function(t,n){return B(n,e)}:I(e)?e:e instanceof N?function(t,n){return e.is(n)}:e?function(t,n){return n===e}:function(){return!1}}function U(t,n){return n?t.filter(n):t}S.guid=1,S.isWindow=M,S.isFunction=I,S.isArray=c,S.isNumeric=W,S.isPlainObject=\$,T.get=function(t){return void 0===t?m.call(this):this[(t=Number(t))<0?t+this.length:t]},T.eq=function(t){return S(this.get(t))},T.first=function(){return this.eq(0)},T.last=function(){return this.eq(-1)},S.each=j,T.each=function(t){return j(this,t)},T.prop=function(e,r){if(e){if(k(e))return e=i[e]||e,arguments.length<2?this[0]&&this[0][e]:this.each(function(t,n){n[e]=r});for(var t in e)this.prop(t,e[t]);return this}},T.removeProp=function(e){return this.each(function(t,n){delete n[i[e]||e]})},S.extend=D,T.extend=function(t){return D(T,t)},T.filter=function(t){var e=H(t);return S(d.call(this,function(t,n){return e.call(t,n,t)}))};var F=/\S+/g;function q(t){return k(t)&&t.match(F)||[]}function z(t,n,e,r){for(var i=[],o=I(n),u=r&&H(r),s=0,c=t.length;s<c;s++)if(o){var a=n(t[s]);a.length&&v.apply(i,a)}else for(a=t[s][n];!(null==a||r&&u(-1,a));)i.push(a),a=e?a[n]:null;return i}function J(t){return 1<t.length?d.call(t,function(t,n,e){return p.call(e,t)===n}):t}function Y(t,n,e){if(R(t)){var r=u.getComputedStyle(t,null);return e?r.getPropertyValue(n)||void 0:r[n]||t.style[n]}}function G(t,n){return parseInt(Y(t,n),10)||0}T.hasClass=function(n){return!!n&&y.call(this,function(t){return R(t)&&t.classList.contains(n)})},T.removeAttr=function(t){var n=q(t);return this.each(function(t,e){R(e)&&j(n,function(t,n){e.removeAttribute(n)})})},T.attr=function(e,r){if(e){if(k(e)){if(arguments.length<2){if(!this[0]||!R(this[0]))return;var t=this[0].getAttribute(e);return null===t?void 0:t}return void 0===r?this:null===r?this.removeAttr(e):this.each(function(t,n){R(n)&&n.setAttribute(e,r)})}for(t in e)this.attr(t,e[t]);return this}},T.toggleClass=function(t,r){var n=q(t),i=void 0!==r;return this.each(function(t,e){R(e)&&j(n,function(t,n){i?r?e.classList.add(n):e.classList.remove(n):e.classList.toggle(n)})})},T.addClass=function(t){return this.toggleClass(t,!0)},T.removeClass=function(t){return arguments.length?this.toggleClass(t,!1):this.attr("class","")},S.unique=J,T.add=function(t,n){return S(J(this.get().concat(S(t,n).get())))};var V=/^--/,X={},K=t.style,Q=["webkit","moz","ms"],Z={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,gridArea:!0,gridColumn:!0,gridColumnEnd:!0,gridColumnStart:!0,gridRow:!0,gridRowEnd:!0,gridRowStart:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};function tt(t,n,e){return void 0===e&&(e=V.test(t)),e||Z[t]||!W(n)?n:n+"px"}T.css=function(e,r){if(k(e)){var i=V.test(e);return(o=e,void 0===(t=i)&&(t=V.test(o)),e=t?o:(X[o]||(n=""+(t=O(o))[0].toUpperCase()+t.slice(1),j(t=(t+" "+Q.join(n+" ")+n).split(" "),function(t,n){if(n in K)return X[o]=n,!1})),X[o]),arguments.length<2)?this[0]&&Y(this[0],e,i):e?(r=tt(e,r,i),this.each(function(t,n){R(n)&&(i?n.style.setProperty(e,r):n.style[e]=r)})):this}var o,t,n,u;for(u in e)this.css(u,e[u]);return this};var nt=/^\s+|\s+\$/;function et(t,n){return t=t.dataset[n]||t.dataset[O(n)],nt.test(t)?t:o(JSON.parse,t)}function rt(t,n){var e=t.documentElement;return Math.max(t.body["scroll"+n],e["scroll"+n],t.body["offset"+n],e["offset"+n],e["client"+n])}function it(t,n){return G(t,"border"+(n?"Left":"Top")+"Width")+G(t,"padding"+(n?"Left":"Top"))+G(t,"padding"+(n?"Right":"Bottom"))+G(t,"border"+(n?"Right":"Bottom")+"Width")}j([!0,!(T.data=function(e,r){if(!e){if(!this[0])return;var t,n={};for(t in this[0].dataset)n[t]=et(this[0],t);return n}if(k(e))return arguments.length<2?this[0]&&et(this[0],e):void 0===r?this:this.each(function(t,n){t=r,t=o(JSON.stringify,t),n.dataset[O(e)]=t});for(t in e)this.data(t,e[t]);return this})],function(t,r){j(["Width","Height"],function(n,e){T[(r?"outer":"inner")+e]=function(t){if(this[0])return M(this[0])?r?this[0]["inner"+e]:this[0].document.documentElement["client"+e]:P(this[0])?rt(this[0],e):this[0][(r?"offset":"client")+e]+(t&&r?G(this[0],"margin"+(n?"Top":"Left"))+G(this[0],"margin"+(n?"Bottom":"Right")):0)}})}),j(["Width","Height"],function(r,n){var i=n.toLowerCase();T[i]=function(t){if(!this[0])return void 0===t?void 0:this;if(!arguments.length)return M(this[0])?this[0].document.documentElement["client"+n]:P(this[0])?rt(this[0],n):this[0].getBoundingClientRect()[i]-it(this[0],!r);var e=parseInt(t,10);return this.each(function(t,n){R(n)&&(t=Y(n,"boxSizing"),n.style[i]=tt(i,e+("border-box"===t?it(n,!r):0)))})}});var ot={};function ut(n,t){return!t||!y.call(t,function(t){return n.indexOf(t)<0})}T.toggle=function(i){return this.each(function(t,n){var e,r;R(n)&&((void 0===i?"none"===Y(n,"display"):i)?(n.style.display=n.___cd||"","none"===Y(n,"display")&&(t=n.style,n=n.tagName,n=ot[n]||(e=f(n),s.body.insertBefore(e,null),r=Y(e,"display"),s.body.removeChild(e),ot[n]="none"!==r?r:"block"),t.display=n)):(n.___cd=Y(n,"display"),n.style.display="none"))})},T.hide=function(){return this.toggle(!1)},T.show=function(){return this.toggle(!0)};var st={focus:"focusin",blur:"focusout"},ct={mouseenter:"mouseover",mouseleave:"mouseout"},at=/^(mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function ft(t){return[(t=t.split("."))[0],t.slice(1).sort()]}function lt(r,i,o,u,s){var t=r.___ce=r.___ce||{};if(i)t[i]&&(t[i]=t[i].filter(function(t){var n=t[0],e=t[1];if(t=t[2],s&&t.guid!==s.guid||!ut(n,o)||u&&u!==e)return!0;r.removeEventListener(i,t)}));else for(i in t)lt(r,i,o,u,s)}function ht(t){return t.multiple&&t.options?z(d.call(t.options,function(t){return t.selected&&!t.disabled&&!t.parentNode.disabled}),"value"):t.value||""}T.off=function(t,i,o){var u=this;if(void 0===t)this.each(function(t,n){(R(n)||P(n)||M(n))&&lt(n)});else if(k(t))I(i)&&(o=i,i=""),j(q(t),function(t,n){n=(t=ft(n))[0];var e=t[1],r=ct[n]||st[n]||n;u.each(function(t,n){(R(n)||P(n)||M(n))&&lt(n,r,e,i,o)})});else for(var n in t)this.off(n,t[n]);return this},T.on=function(t,l,h,d,p){var n,e=this;if(k(t))return k(l)||(null!=l&&(void 0!==h&&(d=h),h=l),l=""),I(d)||(d=h,h=void 0),d&&j(q(t),function(t,n){n=(t=ft(n))[0];var s=t[1],c=ct[n]||st[n]||n,a=n in ct,f=n in st;c&&e.each(function(t,i){var n,e,r,o,u;(R(i)||P(i)||M(i))&&((t=function t(n){if(n.target["___i"+n.type])return n.stopImmediatePropagation();if((!n.namespace||ut(s,n.namespace.split(".")))&&(l||!(f&&(n.target!==i||n.___ot===c)||a&&n.relatedTarget&&i.contains(n.relatedTarget)))){var e=i;if(l){for(var r=n.target;!B(r,l);){if(r===i)return;if(!(r=r.parentNode))return}e=r,n.___cd=!0}n.___cd&&Object.defineProperty(n,"currentTarget",{configurable:!0,get:function(){return e}}),Object.defineProperty(n,"data",{configurable:!0,get:function(){return h}}),r=d.call(e,n,n.___td),p&&lt(i,c,s,l,t),!1===r&&(n.preventDefault(),n.stopPropagation())}}).guid=d.guid=d.guid||S.guid++,e=c,r=s,o=l,u=t,(t=(n=i).___ce=n.___ce||{})[e]=t[e]||[],t[e].push([r,o,u]),n.addEventListener(e,u))})}),this;for(n in t)this.on(n,l,h,t[n],p);return this},T.one=function(t,n,e,r){return this.on(t,n,e,r,!0)},T.ready=function(t){function n(){return setTimeout(t,0,S)}return"loading"!==s.readyState?n():s.addEventListener("DOMContentLoaded",n),this},T.trigger=function(e,t){if(k(e)){var n=(r=ft(e))[0],r=r[1],i=ct[n]||st[n]||n;if(!i)return this;var o=at.test(i)?"MouseEvents":"HTMLEvents";(e=s.createEvent(o)).initEvent(i,!0,!0),e.namespace=r.join("."),e.___ot=n}e.___td=t;var u=e.___ot in st;return this.each(function(t,n){u&&I(n[e.___ot])&&(n["___i"+e.type]=!0,n[e.___ot](),n["___i"+e.type]=!1),n.dispatchEvent(e)})};var dt=/%20/g,pt=/\r?\n/g,gt=/file|reset|submit|button|image/i,vt=/radio|checkbox/i;T.serialize=function(){var r="";return this.each(function(t,n){j(n.elements||[n],function(t,e){e.disabled||!e.name||"FIELDSET"===e.tagName||gt.test(e.type)||vt.test(e.type)&&!e.checked||void 0!==(t=ht(e))&&j(t=c(t)?t:[t],function(t,n){t=r,n="&"+encodeURIComponent(e.name)+"="+encodeURIComponent(n.replace(pt,"\r\n")).replace(dt,"+"),r=t+n})})}),r.slice(1)},T.val=function(r){return arguments.length?this.each(function(t,n){var e;(t=n.multiple&&n.options)||vt.test(n.type)?(e=c(r)?g.call(r,String):null===r?[]:[String(r)],t?j(n.options,function(t,n){n.selected=0<=e.indexOf(n.value)},!0):n.checked=0<=e.indexOf(n.value)):n.value=null==r?"":r}):this[0]&&ht(this[0])},T.clone=function(){return this.map(function(t,n){return n.cloneNode(!0)})},T.detach=function(t){return U(this,t).each(function(t,n){n.parentNode&&n.parentNode.removeChild(n)}),this};var mt=/^\s*<(\w+)[^>]*>/,yt=/^<(\w+)\s*\/?>(?:<\/\1>)?\$/,bt={"*":t,tr:e,td:r,th:r,thead:n,tbody:n,tfoot:n};function _t(t){if(!k(t))return[];if(yt.test(t))return[f(RegExp.\$1)];var n=mt.test(t)&&RegExp.\$1;return(n=bt[n]||bt["*"]).innerHTML=t,S(n.childNodes).detach().get()}S.parseHTML=_t,T.empty=function(){return this.each(function(t,n){for(;n.firstChild;)n.removeChild(n.firstChild)})},T.html=function(e){return arguments.length?void 0===e?this:this.each(function(t,n){R(n)&&(n.innerHTML=e)}):this[0]&&this[0].innerHTML},T.remove=function(t){return U(this,t).detach().off(),this},T.text=function(e){return void 0===e?this[0]?this[0].textContent:"":this.each(function(t,n){R(n)&&(n.textContent=e)})},T.unwrap=function(){return this.parent().each(function(t,n){"BODY"!==n.tagName&&(t=S(n)).replaceWith(t.children())}),this},T.offset=function(){var t=this[0];if(t)return{top:(t=t.getBoundingClientRect()).top+u.pageYOffset,left:t.left+u.pageXOffset}},T.offsetParent=function(){return this.map(function(t,n){for(t=n.offsetParent;t&&"static"===Y(t,"position");)t=t.offsetParent;return t||a})},T.position=function(){var t=this[0];if(t){var n=(r="fixed"===Y(t,"position"))?t.getBoundingClientRect():this.offset();if(!r){for(var e=t.ownerDocument,r=t.offsetParent||e.documentElement;(r===e.body||r===e.documentElement)&&"static"===Y(r,"position");)r=r.parentNode;r!==t&&R(r)&&(e=S(r).offset(),n.top-=e.top+G(r,"borderTopWidth"),n.left-=e.left+G(r,"borderLeftWidth"))}return{top:n.top-G(t,"marginTop"),left:n.left-G(t,"marginLeft")}}},T.children=function(t){return U(S(J(z(this,function(t){return t.children}))),t)},T.contents=function(){return S(J(z(this,function(t){return"IFRAME"===t.tagName?[t.contentDocument]:("TEMPLATE"===t.tagName?t.content:t).childNodes})))},T.find=function(n){return S(J(z(this,function(t){return E(n,t)})))};var xt=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*\$/g,Ct=/^\$|^module\$|\/(java|ecma)script/i,wt=["type","src","nonce","noModule"];function Et(t,e,u,s,c,n,r,i){return j(t,function(t,n){j(S(n),function(r,o){j(S(e),function(t,n){var i,e=u?n:o;n=u?o:n,e=(t=u?r:t)?e.cloneNode(!0):e,t=!t,c?n.insertBefore(e,s?n.firstChild:null):n.parentNode.insertBefore(e,s?n:n.nextSibling),t&&(e=e,i=n.ownerDocument,(e=S(e)).filter("script").add(e.find("script")).each(function(t,e){var r;Ct.test(e.type)&&a.contains(e)&&((r=f("script")).text=e.textContent.replace(xt,""),j(wt,function(t,n){e[n]&&(r[n]=e[n])}),i.head.insertBefore(r,null),i.head.removeChild(r))}))},i)},r)},n),e}T.after=function(){return Et(arguments,this,!1,!1,!1,!0,!0)},T.append=function(){return Et(arguments,this,!1,!1,!0)},T.appendTo=function(t){return Et(arguments,this,!0,!1,!0)},T.before=function(){return Et(arguments,this,!1,!0)},T.insertAfter=function(t){return Et(arguments,this,!0,!1,!1,!1,!1,!0)},T.insertBefore=function(t){return Et(arguments,this,!0,!0)},T.prepend=function(){return Et(arguments,this,!1,!0,!0,!0,!0)},T.prependTo=function(t){return Et(arguments,this,!0,!0,!0,!1,!1,!0)},T.replaceWith=function(t){return this.before(t).remove()},T.replaceAll=function(t){return S(t).replaceWith(this),this},T.wrapAll=function(t){for(var n=(t=S(t))[0];n.children.length;)n=n.firstElementChild;return this.first().before(t),this.appendTo(n)},T.wrap=function(r){return this.each(function(t,n){var e=S(r)[0];S(n).wrapAll(t?e.cloneNode(!0):e)})},T.wrapInner=function(e){return this.each(function(t,n){(n=(t=S(n)).contents()).length?n.wrapAll(e):t.append(e)})},T.has=function(e){var t=k(e)?function(t,n){return E(e,n).length}:function(t,n){return n.contains(e)};return this.filter(t)},T.is=function(t){var e=H(t);return y.call(this,function(t,n){return e.call(t,n,t)})},T.next=function(t,n,e){return U(S(J(z(this,"nextElementSibling",n,e))),t)},T.nextAll=function(t){return this.next(t,!0)},T.nextUntil=function(t,n){return this.next(n,!0,t)},T.not=function(e){var r=H(e);return this.filter(function(t,n){return(!k(e)||R(n))&&!r.call(n,t,n)})},T.parent=function(t){return U(S(J(z(this,"parentNode"))),t)},T.index=function(t){var n=(t?S(t):this)[0];return t=t?this:S(n).parent().children(),p.call(t,n)},T.closest=function(t){var n=this.filter(t);if(n.length)return n;var e=this.parent();return e.length?e.closest(t):n},T.parents=function(t,n){return U(S(J(z(this,"parentElement",!0,n))),t)},T.parentsUntil=function(t,n){return this.parents(n,t)},T.prev=function(t,n,e){return U(S(J(z(this,"previousElementSibling",n,e))),t)},T.prevAll=function(t){return this.prev(t,!0)},T.prevUntil=function(t,n){return this.prev(n,!0,t)},T.siblings=function(t){return U(S(J(z(this,function(t){return S(t).parent().children().not(t)}))),t)},"undefined"!=typeof exports?module.exports=S:u.cash=u.\$=S
}();
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <tabTrigger>cashlib</tabTrigger>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.js</scope>
</snippet>
1 Like

#3

Yep thank you, this was the issue and the solution that I realized as well.

I escaped the $s. I think the parser should look for “${” instead of just $ signs, since those are very common in javascript.

The code you pasted also might not work either because there are 2 instances in the cash library where

[\w-]|\\

appears, and the parser thinks that we are escaping \ , so when I use the tab trigger, it only writes

[\w-]|\

making the library malfunction (potentially).

I had to write

[\w-]|\\\

in the .sublime-snippet. Note that it has 3 backwards slashes instead of the original 2 to get the cashlib written without any modification from the parser.

This ended up being a little too involved for such a simple thing if you ask me… :sweat_smile:

0 Likes

#4

IMHO adding such a huge library inline is insane and not a “simple thing”. I don’t think snippets were designed with such a use case in mind.

Whatever syntax rules a snippet engine uses, some of them will always conflict/interfere with at least one of the existing syntaxes out in the wild, requiering some “escapes”.

It’s not more complicated than correctly escaping such content in a json file correctly.

0 Likes