Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@typescript/twoslash

Package Overview
Dependencies
Maintainers
9
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typescript/twoslash - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

13

dist/twoslash.cjs.development.js

@@ -504,4 +504,2 @@ 'use strict';

var _loop3 = function _loop3() {
var _highlights, _partialQueries;
var file = _step2.value;

@@ -522,6 +520,4 @@ var filename = file[0],

var updates = filterHighlightLines(codeLines);
highlights = highlights.concat(updates.highlights); // ------ Do the LSP lookup for the queries
(_highlights = highlights).push.apply(_highlights, updates.highlights); // ------ Do the LSP lookup for the queries
var lspedQueries = updates.queries.map(function (q, i) {

@@ -582,6 +578,4 @@ var sourceFile = env.getSourceFile(filename);

});
partialQueries = partialQueries.concat(lspedQueries); // Sets the file in the compiler as being without the comments
(_partialQueries = partialQueries).push.apply(_partialQueries, lspedQueries); // Sets the file in the compiler as being without the comments
var newEditedFileCode = codeLines.join("\n");

@@ -627,4 +621,3 @@ env.updateFile(filename, newEditedFileCode);

if (!handbookOptions.noErrors) {
errs.push.apply(errs, ls.getSemanticDiagnostics(file));
errs.push.apply(errs, ls.getSyntacticDiagnostics(file));
errs = errs.concat(ls.getSemanticDiagnostics(file), ls.getSyntacticDiagnostics(file));
}

@@ -631,0 +624,0 @@

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@typescript/vfs");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function r(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}function i(e,t){switch(t){case"number":return+e;case"string":return e;case"boolean":return"true"===e.toLowerCase()||0===e.length}throw new Error("Unknown primitive type "+t+" with - "+e)}var o=!1;try{o="undefined"!=typeof localStorage}catch(e){}var s="undefined"!=typeof process,a=o&&localStorage.getItem("DEBUG")||s&&process.env.DEBUG?console.log:function(e){return""};function l(e){for(var t=[],n=[],r=0,i=0,o=0,s=function(s){var c=e[s],u=function(){i=r,r+=c.length+1},f=function(t){a("Removing line "+s+" for "+t),o++,e.splice(s,1),s--};if(c.includes("//")){var p=/^\s*\/\/\s*\^+( .+)?$/.exec(c),d=/^\s*\/\/\s*\^\?\s*$/.exec(c),h=/^\s*\/\/ prettier-ignore$/.exec(c),g=/^\s*\/\/\s*\^\|$/.exec(c);if(null!==d){var v=c.indexOf("^");n.push({kind:"query",offset:v,text:void 0,docs:void 0,line:s+o-1}),f("having a query")}else if(null!==p){var m=c.indexOf("^"),x=c.lastIndexOf("^")-m+1,y=i+m,w=p[1]?p[1].trim():"";t.push({kind:"highlight",position:y,length:x,description:w,line:s}),f("having a highlight")}else if(null!==h)f("being a prettier ignore");else if(null!==g){var E=c.indexOf("^");n.push({kind:"completion",offset:E,text:void 0,docs:void 0,line:s+o-1}),f("having a completion query")}else u()}else u();l=s},l=0;l<e.length;l++)s(l);return{highlights:t,queries:n}}function c(e,t,n){var r=n.get(t.toLowerCase());if(a("Get "+e+" mapped option: "+t+" => "+r),void 0===r){var i=Array.from(n.keys());throw new Error("Invalid value "+t+" for "+e+". Allowed values: "+i.join(","))}return r}function u(e,t,n,o){a("Setting "+e+" to "+t);for(var s,l=function(){var r=s.value;if(r.name.toLowerCase()===e.toLowerCase()){switch(r.type){case"number":case"string":case"boolean":n[r.name]=i(t,r.type);break;case"list":var o=r.element.type,a=t.split(",");n[r.name]=a.map("string"==typeof o?function(e){return i(e,o)}:function(e){return c(r.name,e,o)});break;default:n[r.name]=c(r.name,t,r.type)}return{v:void 0}}},u=r(o.optionDeclarations);!(s=u()).done;){var f=l();if("object"==typeof f)return f.v}throw new Error("No compiler setting named '"+e+"' exists!")}var f=/^\/\/\s?@(\w+)$/,p=/^\/\/\s?@(\w+):\s?(.+)$/,d={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:void 0,noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(n,i,o){var s,c,h;void 0===o&&(o={});var g=null!=(s=o.tsModule)?s:require("typescript"),v=null!=(c=o.lzstringModule)?c:require("lz-string"),m=n,x=function(e){switch(e){case"js":case"javascript":return"js";case"ts":case"typescript":return"ts";case"tsx":return"tsx";case"jsx":return"jsx";case"jsn":return"json"}throw new Error("Cannot handle the file extension:"+e)}(i),y="index."+x;a("\n\nLooking at code: \n```"+x+"\n"+n+"\n```\n");var w=t({strict:!0,target:g.ScriptTarget.ES2016,allowJs:!0},null!=(h=o.defaultCompilerOptions)?h:{});!function(e){if(e.includes("// @errors "))throw new Error("You have '@errors ' - you're missing the colon after errors");if(e.includes("// @filename "))throw new Error("You have '@filename ' - you're missing the colon after filename")}(n);var E=(n=function(e){return(e=e.replace(/¨D/g,"$")).replace(/¨T/g,"~")}(n)).split(/\r\n?|\n/g),j=t({},function(e){for(var n=t({},d),r=0;r<e.length;r++){var i=void 0;(i=f.exec(e[r]))?i[1]in n&&(n[i[1]]=!0,a("Setting options."+i[1]+" to true"),e.splice(r,1),r--):(i=p.exec(e[r]))&&i[1]in n&&(n[i[1]]=i[2],a("Setting options."+i[1]+" to "+i[2]),e.splice(r,1),r--)}return"errors"in n&&"string"==typeof n.errors&&(n.errors=n.errors.split(" ").map(Number),a("Setting options.error to ",n.errors)),n}(E),o.defaultOptions),S=function(e,n,r){for(var i=t({},n),o=0;o<e.length;){var s=void 0;if(s=f.exec(e[o]))i[s[1]]=!0,u(s[1],"true",i,r);else{if(!(s=p.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}u(s[1],s[2],i,r)}e.splice(o,1)}return i}(E,w,g);j.showEmittedFile||(j.showEmittedFile=S.jsx&&S.jsx===g.JsxEmit.Preserve?"index.jsx":"index.js");var b=function(){var e=require("path");return(o.vfsRoot||process.cwd()).split(e.sep).join(e.posix.sep)},F=!!o.fsMap,O=F&&o.fsMap?o.fsMap:new Map,k=F?e.createSystem(O):e.createFSBackedSystem(O,b(),g),P=F?"/":b()+"/",C=e.createVirtualTypeScriptEnvironment(k,[],g,S,o.customTransformers),T=C.languageService;n=E.join("\n");for(var q,A=[],I=[],L=[],M=function(e,t,n){for(var i,o=e.split(/\r\n?|\n/g),s=e.includes("@filename: "+t)?"global.ts":t,a=[],l=[],c=r(o);!(i=c()).done;){var u=i.value;u.includes("// @filename: ")?(l.push([n+s,a]),s=u.split("// @filename: ")[1].trim(),a=[]):a.push(u)}return l.push([n+s,a]),l.filter((function(e){return e[1].length>0&&(e[1].length>1||""!==e[1][0])}))}(n,y,P),$=["js","jsx","ts","tsx"],D=M.map((function(e){return e[0]})),N=function(){var e,t,n=q.value,r=n[0],i=n[1],o=r.split(".").pop()||"",s=S.resolveJsonModule&&"json"===o;if(!$.includes(o)&&!s)return"continue";var a=i.join("\n");C.createFile(r,a);var c=l(i);(e=L).push.apply(e,c.highlights);var u=c.queries.map((function(e,t){var n,i,o=C.getSourceFile(r),s=g.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=T.getQuickInfoAtPosition(r,s),l="Could not get LSP result: "+[(n=C.getSourceFile(r).text)[(i=s)-3],n[i-2],n[i-1],">",n[i],"<",n[i+1],n[i+2],n[i+3]].filter(Boolean).join(""),c=void 0;return a&&a.displayParts&&(l=a.displayParts.map((function(e){return e.text})).join(""),c=a.documentation?a.documentation.map((function(e){return e.text})).join("<br/>"):void 0),{kind:"query",text:l,docs:c,line:e.line-t,offset:e.offset,file:r};case"completion":var u=T.getCompletionsAtPosition(r,s-1,{});if(!u&&!j.noErrorValidation)throw new Error("Twoslash: The ^| query at line "+e.line+" in "+r+" did not return any completions");var f=function(e,t){e=String(e),t=Number(t)>>>0;var n=e.slice(0,t+1).search(/\S+$/),r=e.slice(t).search(/\s/);return r<0?{word:e.slice(n),startPos:n}:{word:e.slice(n,r+t),startPos:n}}(o.text,s-1),p=o.text.slice(f.startPos,s).split(".").pop()||"";return{kind:"completions",completions:(null==u?void 0:u.entries)||[],completionPrefix:p,line:e.line-t,offset:e.offset,file:r}}}));(t=A).push.apply(t,u);var f=i.join("\n");C.updateFile(r,f)},U=r(M);!(q=U()).done;)N();var B=n.split(/\r\n?|\n/g);l(B),n=B.join("\n"),j.emit&&D.forEach((function(e){var t=e.split(".").pop()||"";$.includes(t)&&T.getEmitOutput(e).outputFiles.forEach((function(e){k.writeFile(e.name,e.text)}))}));var R=[],V=[];D.forEach((function(e){var t=e.split(".").pop()||"";if($.includes(t)){j.noErrors||(R.push.apply(R,T.getSemanticDiagnostics(e)),R.push.apply(R,T.getSyntacticDiagnostics(e)));var i=C.sys.readFile(e),o=C.getSourceFile(e);if(!o)throw new Error("No sourcefile found for "+e+" in twoslash");if(!j.showEmit){for(var s,a=-1==n.indexOf(i)?0:n.indexOf(i),l=n.slice(0,a).split("\n").length-1,c=r(j.noStaticSemanticInfo?[]:function(e,t){var n=[];return function r(i){e.forEachChild(i,(function(i){if(e.isIdentifier(i)){var o=i.getStart(t,!1);n.push({span:e.createTextSpan(o,i.end-o),text:i.getText(t)})}r(i)}))}(t),n}(g,o));!(s=c()).done;){var u=s.value,f=u.span,p=T.getQuickInfoAtPosition(e,f.start);if(p&&p.displayParts){var d=p.displayParts.map((function(e){return e.text})).join(""),h=u.text,v=p.documentation?p.documentation.map((function(e){return e.text})).join("\n"):void 0,m=f.start+a,x=g.createSourceFile("_.ts",n,g.ScriptTarget.ES2015),y=g.getLineAndCharacterOfPosition(x,m);V.push({text:d,docs:v,start:m,length:f.length,line:y.line,character:y.character,targetString:h})}}A.filter((function(t){return t.file===e})).forEach((function(e){var t=g.getPositionOfLineAndCharacter(o,e.line,e.offset)+a;switch(e.kind){case"query":I.push({docs:e.docs,kind:"query",start:t+a,length:e.text.length,text:e.text,offset:e.offset,line:e.line+l+1});break;case"completions":I.push({completions:e.completions,kind:"completions",start:t+a,completionsPrefix:e.completionPrefix,length:1,offset:e.offset,line:e.line+l+1})}}))}}}));var G=R.filter((function(e){return e.file&&D.includes(e.file.fileName)}));!j.noErrorValidation&&G.length&&function(e,t,n,r){var i=e.filter((function(e){return!t.errors.includes(e.code)})),o=i.map((function(e){return e.code})).join(" ");if(i.length){var s="// @errors: "+e.map((function(e){return e.code})).join(" "),a=t.errors.length?" - the annotation specified "+t.errors:"\n\nExpected:\n"+s,l=i.map((function(e){return"["+e.code+"] - "+("string"==typeof e.messageText?e.messageText:e.messageText.messageText)})).join("\n ");throw new Error("Errors were thrown in the sample, but not included in an errors tag: "+o+a+"\n\n "+l+"\n\n## Code\n\n'''"+n+"\n"+r+"\n'''")}}(G,j,i,m);for(var J,Q=[],_=r(G);!(J=_()).done;){var z=J.value,Y=C.sys.readFile(z.file.fileName),H=n.indexOf(Y),K=g.flattenDiagnosticMessageText(z.messageText,"\n"),W="err-"+z.code+"-"+z.start+"-"+z.length,X=g.getLineAndCharacterOfPosition(z.file,z.start);Q.push({category:z.category,code:z.code,length:z.length,start:z.start?z.start+H:void 0,line:X.line,character:X.character,renderedMessage:K,id:W})}if(j.showEmit){var Z=j.showEmittedFile||y,ee=P+Z.replace(".jsx","").replace(".js","").replace(".d.ts","").replace(".map",""),te=D.find((function(e){return e===ee+".ts"||e===ee+".tsx"}));if(!te&&!S.outFile){var ne=D.join(", ");throw new Error("Cannot find the corresponding **source** file for "+Z+" (looking for: "+ee+" in the vfs) - in "+ne)}S.outFile&&(te=D[0]);var re=T.getEmitOutput(te),ie=re.outputFiles.find((function(e){return e.name===P+j.showEmittedFile||e.name===j.showEmittedFile}));if(!ie){var oe=re.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+j.showEmittedFile+" (looking for: "+(P+j.showEmittedFile)+" in the vfs) - in "+oe)}n=ie.text,i=ie.name.split(".").pop(),L=[],A=[],V=[]}var se="https://www.typescriptlang.org/play/#code/"+v.compressToEncodedURIComponent(m),ae="// ---cut---\n";if(n.includes(ae)){var le=n.indexOf(ae)+ae.length,ce=n.substr(0,le).split("\n").length-1;n=n.split(ae).pop(),V.forEach((function(e){e.start-=le,e.line-=ce})),V=V.filter((function(e){return e.start>-1})),Q.forEach((function(e){e.start&&(e.start-=le),e.line&&(e.line-=ce)})),Q=Q.filter((function(e){return e.start&&e.start>-1})),L.forEach((function(e){e.position-=le,e.line-=ce})),L=L.filter((function(e){return e.position>-1})),I.forEach((function(e){return e.line-=ce})),I=I.filter((function(e){return e.line>-1}))}return{code:n,extension:i,highlights:L,queries:I,staticQuickInfos:V,errors:Q,playgroundURL:se}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@typescript/vfs");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function r(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}function i(e,t){switch(t){case"number":return+e;case"string":return e;case"boolean":return"true"===e.toLowerCase()||0===e.length}throw new Error("Unknown primitive type "+t+" with - "+e)}var o=!1;try{o="undefined"!=typeof localStorage}catch(e){}var s="undefined"!=typeof process,a=o&&localStorage.getItem("DEBUG")||s&&process.env.DEBUG?console.log:function(e){return""};function l(e){for(var t=[],n=[],r=0,i=0,o=0,s=function(s){var c=e[s],u=function(){i=r,r+=c.length+1},f=function(t){a("Removing line "+s+" for "+t),o++,e.splice(s,1),s--};if(c.includes("//")){var p=/^\s*\/\/\s*\^+( .+)?$/.exec(c),d=/^\s*\/\/\s*\^\?\s*$/.exec(c),h=/^\s*\/\/ prettier-ignore$/.exec(c),g=/^\s*\/\/\s*\^\|$/.exec(c);if(null!==d){var v=c.indexOf("^");n.push({kind:"query",offset:v,text:void 0,docs:void 0,line:s+o-1}),f("having a query")}else if(null!==p){var m=c.indexOf("^"),x=c.lastIndexOf("^")-m+1,w=i+m,y=p[1]?p[1].trim():"";t.push({kind:"highlight",position:w,length:x,description:y,line:s}),f("having a highlight")}else if(null!==h)f("being a prettier ignore");else if(null!==g){var E=c.indexOf("^");n.push({kind:"completion",offset:E,text:void 0,docs:void 0,line:s+o-1}),f("having a completion query")}else u()}else u();l=s},l=0;l<e.length;l++)s(l);return{highlights:t,queries:n}}function c(e,t,n){var r=n.get(t.toLowerCase());if(a("Get "+e+" mapped option: "+t+" => "+r),void 0===r){var i=Array.from(n.keys());throw new Error("Invalid value "+t+" for "+e+". Allowed values: "+i.join(","))}return r}function u(e,t,n,o){a("Setting "+e+" to "+t);for(var s,l=function(){var r=s.value;if(r.name.toLowerCase()===e.toLowerCase()){switch(r.type){case"number":case"string":case"boolean":n[r.name]=i(t,r.type);break;case"list":var o=r.element.type,a=t.split(",");n[r.name]=a.map("string"==typeof o?function(e){return i(e,o)}:function(e){return c(r.name,e,o)});break;default:n[r.name]=c(r.name,t,r.type)}return{v:void 0}}},u=r(o.optionDeclarations);!(s=u()).done;){var f=l();if("object"==typeof f)return f.v}throw new Error("No compiler setting named '"+e+"' exists!")}var f=/^\/\/\s?@(\w+)$/,p=/^\/\/\s?@(\w+):\s?(.+)$/,d={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:void 0,noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(n,i,o){var s,c,h;void 0===o&&(o={});var g=null!=(s=o.tsModule)?s:require("typescript"),v=null!=(c=o.lzstringModule)?c:require("lz-string"),m=n,x=function(e){switch(e){case"js":case"javascript":return"js";case"ts":case"typescript":return"ts";case"tsx":return"tsx";case"jsx":return"jsx";case"jsn":return"json"}throw new Error("Cannot handle the file extension:"+e)}(i),w="index."+x;a("\n\nLooking at code: \n```"+x+"\n"+n+"\n```\n");var y=t({strict:!0,target:g.ScriptTarget.ES2016,allowJs:!0},null!=(h=o.defaultCompilerOptions)?h:{});!function(e){if(e.includes("// @errors "))throw new Error("You have '@errors ' - you're missing the colon after errors");if(e.includes("// @filename "))throw new Error("You have '@filename ' - you're missing the colon after filename")}(n);var E=(n=function(e){return(e=e.replace(/¨D/g,"$")).replace(/¨T/g,"~")}(n)).split(/\r\n?|\n/g),j=t({},function(e){for(var n=t({},d),r=0;r<e.length;r++){var i=void 0;(i=f.exec(e[r]))?i[1]in n&&(n[i[1]]=!0,a("Setting options."+i[1]+" to true"),e.splice(r,1),r--):(i=p.exec(e[r]))&&i[1]in n&&(n[i[1]]=i[2],a("Setting options."+i[1]+" to "+i[2]),e.splice(r,1),r--)}return"errors"in n&&"string"==typeof n.errors&&(n.errors=n.errors.split(" ").map(Number),a("Setting options.error to ",n.errors)),n}(E),o.defaultOptions),S=function(e,n,r){for(var i=t({},n),o=0;o<e.length;){var s=void 0;if(s=f.exec(e[o]))i[s[1]]=!0,u(s[1],"true",i,r);else{if(!(s=p.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}u(s[1],s[2],i,r)}e.splice(o,1)}return i}(E,y,g);j.showEmittedFile||(j.showEmittedFile=S.jsx&&S.jsx===g.JsxEmit.Preserve?"index.jsx":"index.js");var b=function(){var e=require("path");return(o.vfsRoot||process.cwd()).split(e.sep).join(e.posix.sep)},F=!!o.fsMap,O=F&&o.fsMap?o.fsMap:new Map,k=F?e.createSystem(O):e.createFSBackedSystem(O,b(),g),P=F?"/":b()+"/",C=e.createVirtualTypeScriptEnvironment(k,[],g,S,o.customTransformers),T=C.languageService;n=E.join("\n");for(var q,A=[],I=[],L=[],M=function(e,t,n){for(var i,o=e.split(/\r\n?|\n/g),s=e.includes("@filename: "+t)?"global.ts":t,a=[],l=[],c=r(o);!(i=c()).done;){var u=i.value;u.includes("// @filename: ")?(l.push([n+s,a]),s=u.split("// @filename: ")[1].trim(),a=[]):a.push(u)}return l.push([n+s,a]),l.filter((function(e){return e[1].length>0&&(e[1].length>1||""!==e[1][0])}))}(n,w,P),$=["js","jsx","ts","tsx"],D=M.map((function(e){return e[0]})),N=function(){var e=q.value,t=e[0],n=e[1],r=t.split(".").pop()||"",i=S.resolveJsonModule&&"json"===r;if(!$.includes(r)&&!i)return"continue";var o=n.join("\n");C.createFile(t,o);var s=l(n);L=L.concat(s.highlights);var a=s.queries.map((function(e,n){var r,i,o=C.getSourceFile(t),s=g.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=T.getQuickInfoAtPosition(t,s),l="Could not get LSP result: "+[(r=C.getSourceFile(t).text)[(i=s)-3],r[i-2],r[i-1],">",r[i],"<",r[i+1],r[i+2],r[i+3]].filter(Boolean).join(""),c=void 0;return a&&a.displayParts&&(l=a.displayParts.map((function(e){return e.text})).join(""),c=a.documentation?a.documentation.map((function(e){return e.text})).join("<br/>"):void 0),{kind:"query",text:l,docs:c,line:e.line-n,offset:e.offset,file:t};case"completion":var u=T.getCompletionsAtPosition(t,s-1,{});if(!u&&!j.noErrorValidation)throw new Error("Twoslash: The ^| query at line "+e.line+" in "+t+" did not return any completions");var f=function(e,t){e=String(e),t=Number(t)>>>0;var n=e.slice(0,t+1).search(/\S+$/),r=e.slice(t).search(/\s/);return r<0?{word:e.slice(n),startPos:n}:{word:e.slice(n,r+t),startPos:n}}(o.text,s-1),p=o.text.slice(f.startPos,s).split(".").pop()||"";return{kind:"completions",completions:(null==u?void 0:u.entries)||[],completionPrefix:p,line:e.line-n,offset:e.offset,file:t}}}));A=A.concat(a);var c=n.join("\n");C.updateFile(t,c)},U=r(M);!(q=U()).done;)N();var B=n.split(/\r\n?|\n/g);l(B),n=B.join("\n"),j.emit&&D.forEach((function(e){var t=e.split(".").pop()||"";$.includes(t)&&T.getEmitOutput(e).outputFiles.forEach((function(e){k.writeFile(e.name,e.text)}))}));var R=[],V=[];D.forEach((function(e){var t=e.split(".").pop()||"";if($.includes(t)){j.noErrors||(R=R.concat(T.getSemanticDiagnostics(e),T.getSyntacticDiagnostics(e)));var i=C.sys.readFile(e),o=C.getSourceFile(e);if(!o)throw new Error("No sourcefile found for "+e+" in twoslash");if(!j.showEmit){for(var s,a=-1==n.indexOf(i)?0:n.indexOf(i),l=n.slice(0,a).split("\n").length-1,c=r(j.noStaticSemanticInfo?[]:function(e,t){var n=[];return function r(i){e.forEachChild(i,(function(i){if(e.isIdentifier(i)){var o=i.getStart(t,!1);n.push({span:e.createTextSpan(o,i.end-o),text:i.getText(t)})}r(i)}))}(t),n}(g,o));!(s=c()).done;){var u=s.value,f=u.span,p=T.getQuickInfoAtPosition(e,f.start);if(p&&p.displayParts){var d=p.displayParts.map((function(e){return e.text})).join(""),h=u.text,v=p.documentation?p.documentation.map((function(e){return e.text})).join("\n"):void 0,m=f.start+a,x=g.createSourceFile("_.ts",n,g.ScriptTarget.ES2015),w=g.getLineAndCharacterOfPosition(x,m);V.push({text:d,docs:v,start:m,length:f.length,line:w.line,character:w.character,targetString:h})}}A.filter((function(t){return t.file===e})).forEach((function(e){var t=g.getPositionOfLineAndCharacter(o,e.line,e.offset)+a;switch(e.kind){case"query":I.push({docs:e.docs,kind:"query",start:t+a,length:e.text.length,text:e.text,offset:e.offset,line:e.line+l+1});break;case"completions":I.push({completions:e.completions,kind:"completions",start:t+a,completionsPrefix:e.completionPrefix,length:1,offset:e.offset,line:e.line+l+1})}}))}}}));var G=R.filter((function(e){return e.file&&D.includes(e.file.fileName)}));!j.noErrorValidation&&G.length&&function(e,t,n,r){var i=e.filter((function(e){return!t.errors.includes(e.code)})),o=i.map((function(e){return e.code})).join(" ");if(i.length){var s="// @errors: "+e.map((function(e){return e.code})).join(" "),a=t.errors.length?" - the annotation specified "+t.errors:"\n\nExpected:\n"+s,l=i.map((function(e){return"["+e.code+"] - "+("string"==typeof e.messageText?e.messageText:e.messageText.messageText)})).join("\n ");throw new Error("Errors were thrown in the sample, but not included in an errors tag: "+o+a+"\n\n "+l+"\n\n## Code\n\n'''"+n+"\n"+r+"\n'''")}}(G,j,i,m);for(var J,Q=[],_=r(G);!(J=_()).done;){var z=J.value,Y=C.sys.readFile(z.file.fileName),H=n.indexOf(Y),K=g.flattenDiagnosticMessageText(z.messageText,"\n"),W="err-"+z.code+"-"+z.start+"-"+z.length,X=g.getLineAndCharacterOfPosition(z.file,z.start);Q.push({category:z.category,code:z.code,length:z.length,start:z.start?z.start+H:void 0,line:X.line,character:X.character,renderedMessage:K,id:W})}if(j.showEmit){var Z=j.showEmittedFile||w,ee=P+Z.replace(".jsx","").replace(".js","").replace(".d.ts","").replace(".map",""),te=D.find((function(e){return e===ee+".ts"||e===ee+".tsx"}));if(!te&&!S.outFile){var ne=D.join(", ");throw new Error("Cannot find the corresponding **source** file for "+Z+" (looking for: "+ee+" in the vfs) - in "+ne)}S.outFile&&(te=D[0]);var re=T.getEmitOutput(te),ie=re.outputFiles.find((function(e){return e.name===P+j.showEmittedFile||e.name===j.showEmittedFile}));if(!ie){var oe=re.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+j.showEmittedFile+" (looking for: "+(P+j.showEmittedFile)+" in the vfs) - in "+oe)}n=ie.text,i=ie.name.split(".").pop(),L=[],A=[],V=[]}var se="https://www.typescriptlang.org/play/#code/"+v.compressToEncodedURIComponent(m),ae="// ---cut---\n";if(n.includes(ae)){var le=n.indexOf(ae)+ae.length,ce=n.substr(0,le).split("\n").length-1;n=n.split(ae).pop(),V.forEach((function(e){e.start-=le,e.line-=ce})),V=V.filter((function(e){return e.start>-1})),Q.forEach((function(e){e.start&&(e.start-=le),e.line&&(e.line-=ce)})),Q=Q.filter((function(e){return e.start&&e.start>-1})),L.forEach((function(e){e.position-=le,e.line-=ce})),L=L.filter((function(e){return e.position>-1})),I.forEach((function(e){return e.line-=ce})),I=I.filter((function(e){return e.line>-1}))}return{code:n,extension:i,highlights:L,queries:I,staticQuickInfos:V,errors:Q,playgroundURL:se}};
//# sourceMappingURL=twoslash.cjs.production.min.js.map

@@ -500,4 +500,2 @@ import { createSystem, createFSBackedSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs';

var _loop3 = function _loop3() {
var _highlights, _partialQueries;
var file = _step2.value;

@@ -518,6 +516,4 @@ var filename = file[0],

var updates = filterHighlightLines(codeLines);
highlights = highlights.concat(updates.highlights); // ------ Do the LSP lookup for the queries
(_highlights = highlights).push.apply(_highlights, updates.highlights); // ------ Do the LSP lookup for the queries
var lspedQueries = updates.queries.map(function (q, i) {

@@ -578,6 +574,4 @@ var sourceFile = env.getSourceFile(filename);

});
partialQueries = partialQueries.concat(lspedQueries); // Sets the file in the compiler as being without the comments
(_partialQueries = partialQueries).push.apply(_partialQueries, lspedQueries); // Sets the file in the compiler as being without the comments
var newEditedFileCode = codeLines.join("\n");

@@ -623,4 +617,3 @@ env.updateFile(filename, newEditedFileCode);

if (!handbookOptions.noErrors) {
errs.push.apply(errs, ls.getSemanticDiagnostics(file));
errs.push.apply(errs, ls.getSyntacticDiagnostics(file));
errs = errs.concat(ls.getSemanticDiagnostics(file), ls.getSyntacticDiagnostics(file));
}

@@ -627,0 +620,0 @@

@@ -510,4 +510,2 @@

var _loop3 = function _loop3() {
var _highlights, _partialQueries;
var file = _step2.value;

@@ -528,6 +526,4 @@ var filename = file[0],

var updates = filterHighlightLines(codeLines);
highlights = highlights.concat(updates.highlights); // ------ Do the LSP lookup for the queries
(_highlights = highlights).push.apply(_highlights, updates.highlights); // ------ Do the LSP lookup for the queries
var lspedQueries = updates.queries.map(function (q, i) {

@@ -588,6 +584,4 @@ var sourceFile = env.getSourceFile(filename);

});
partialQueries = partialQueries.concat(lspedQueries); // Sets the file in the compiler as being without the comments
(_partialQueries = partialQueries).push.apply(_partialQueries, lspedQueries); // Sets the file in the compiler as being without the comments
var newEditedFileCode = codeLines.join("\n");

@@ -633,4 +627,3 @@ env.updateFile(filename, newEditedFileCode);

if (!handbookOptions.noErrors) {
errs.push.apply(errs, ls.getSemanticDiagnostics(file));
errs.push.apply(errs, ls.getSyntacticDiagnostics(file));
errs = errs.concat(ls.getSemanticDiagnostics(file), ls.getSyntacticDiagnostics(file));
}

@@ -637,0 +630,0 @@

{
"name": "@typescript/twoslash",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",

@@ -37,3 +37,3 @@ "author": "TypeScript team",

"markdown-magic": "^1.0.0",
"prettier": "*",
"prettier": "^2.3.2",
"tsdx": "^0.14.1",

@@ -40,0 +40,0 @@ "tslib": "^1.10.0",

@@ -236,8 +236,2 @@ # TypeScript TwoSlash

> {
> "name": "memory",
> "kind": "property",
> "kindModifiers": "declare",
> "sortText": "1"
> },
> {
> "name": "assert",

@@ -291,8 +285,2 @@ > "kind": "method",

> {
> "name": "exception",
> "kind": "method",
> "kindModifiers": "declare",
> "sortText": "1"
> },
> {
> "name": "group",

@@ -541,3 +529,3 @@ > "kind": "method",

> "character": 0,
> "renderedMessage": "Type 'Record<string, string>' is not assignable to type 'Record<string, number>'.\n Index signatures are incompatible.\n Type 'string' is not assignable to type 'number'.",
> "renderedMessage": "Type 'Record<string, string>' is not assignable to type 'Record<string, number>'.\n 'string' index signatures are incompatible.\n Type 'string' is not assignable to type 'number'.",
> "id": "err-2322-72-1"

@@ -760,8 +748,14 @@ > }

> (this && this.__spreadArray) ||
> function (to, from) {
> for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]
> return to
> function (to, from, pack) {
> if (pack || arguments.length === 2)
> for (var i = 0, l = from.length, ar; i < l; i++) {
> if (ar || !(i in from)) {
> if (!ar) ar = Array.prototype.slice.call(from, 0, i)
> ar[i] = from[i]
> }
> }
> return to.concat(ar || from)
> }
> export function fn(arr) {
> var arr2 = __spreadArray([1], __read(arr))
> var arr2 = __spreadArray([1], __read(arr), false)
> }

@@ -768,0 +762,0 @@ > ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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