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 0.6.1 to 0.6.2

dist/test/custom_transformers.test.d.ts

3

dist/index.d.ts
declare type LZ = typeof import("lz-string");
declare type TS = typeof import("typescript");
declare type CompilerOptions = import("typescript").CompilerOptions;
declare type CustomTransformers = import("typescript").CustomTransformers;
declare module "typescript" {

@@ -100,2 +101,4 @@ type Option = {

defaultCompilerOptions?: CompilerOptions;
/** Allows applying custom transformers to the emit result, only useful with the showEmit output */
customTransformers?: CustomTransformers;
/** An optional copy of the TypeScript import, if missing it will be require'd. */

@@ -102,0 +105,0 @@ tsModule?: TS;

2

dist/twoslash.cjs.development.js

@@ -432,3 +432,3 @@ 'use strict';

var system = vfs.createSystem(vfs$1);
var env = vfs.createVirtualTypeScriptEnvironment(system, [], ts, compilerOptions);
var env = vfs.createVirtualTypeScriptEnvironment(system, [], ts, compilerOptions, options.customTransformers);
var ls = env.languageService;

@@ -435,0 +435,0 @@ code = codeLines.join("\n");

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

@@ -428,3 +428,3 @@ import { createDefaultMapFromNodeModules, createSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs';

var system = createSystem(vfs);
var env = createVirtualTypeScriptEnvironment(system, [], ts, compilerOptions);
var env = createVirtualTypeScriptEnvironment(system, [], ts, compilerOptions, options.customTransformers);
var ls = env.languageService;

@@ -431,0 +431,0 @@ code = codeLines.join("\n");

{
"name": "@typescript/twoslash",
"version": "0.6.1",
"version": "0.6.2",
"license": "MIT",

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

"dependencies": {
"@typescript/vfs": "1.1.1",
"@typescript/vfs": "1.1.2",
"debug": "^4.1.1",

@@ -46,0 +46,0 @@ "lz-string": "^1.4.4"

@@ -710,2 +710,4 @@ # TypeScript TwoSlash

defaultCompilerOptions?: CompilerOptions
/** Allows applying custom transformers to the emit result, only useful with the showEmit output */
customTransformers?: CustomTransformers
/** An optional copy of the TypeScript import, if missing it will be require'd. */

@@ -712,0 +714,0 @@ tsModule?: TS

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