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.4.0 to 0.5.0

8

CHANGELOG.md

@@ -0,1 +1,7 @@

## 0.5.0
- Support TS 4.0
- Improvements to @showEmit and @showEmittedFile
- when `noStaticSemanticInfo` is enabled then you an still run queries
## 0.4.0

@@ -13,3 +19,3 @@

myString.s
// ^?
// ^?
```

@@ -16,0 +22,0 @@

2

dist/index.d.ts

@@ -6,3 +6,3 @@ declare type LZ = typeof import("lz-string");

name: string;
type: "list" | "boolean" | "number" | "string" | import("typescript").Map<number>;
type: "list" | "boolean" | "number" | "string";
element?: Option;

@@ -9,0 +9,0 @@ };

@@ -276,7 +276,9 @@ 'use strict';

default:
opts[opt.name] = opt.type.get(value.toLowerCase());
// It's a map!
var optMap = opt.type;
opts[opt.name] = optMap.get(value.toLowerCase());
log("Set " + opt.name + " to " + opts[opt.name]);
if (opts[opt.name] === undefined) {
var keys = Array.from(opt.type.keys());
var keys = Array.from(optMap.keys());
throw new Error("Invalid value " + value + " for " + opt.name + ". Allowed values: " + keys.join(","));

@@ -578,7 +580,7 @@ }

if (!handbookOptions.noStaticSemanticInfo && !handbookOptions.showEmit) {
if (!handbookOptions.showEmit) {
var fileContentStartIndexInModifiedFile = code.indexOf(source) == -1 ? 0 : code.indexOf(source);
var linesAbove = code.slice(0, fileContentStartIndexInModifiedFile).split("\n").length - 1; // Get all interesting identifiers in the file, so we can show hover info for it
var identifiers = getIdentifierTextSpans(ts, sourceFile);
var identifiers = handbookOptions.noStaticSemanticInfo ? [] : getIdentifierTextSpans(ts, sourceFile);

@@ -715,3 +717,15 @@ for (var _iterator3 = identifiers, _isArray3 = Array.isArray(_iterator3), _i6 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {

if (handbookOptions.showEmit) {
var output = ls.getEmitOutput(defaultFileName);
// Get the file which created the file we want to show:
var emitFilename = handbookOptions.showEmittedFile || defaultFileName;
var emitSourceFilename = emitFilename.replace(".js", "").replace(".d.ts", "").replace(".map", "");
var emitSource = filenames.find(function (f) {
return f === emitSourceFilename + ".ts" || f === emitSourceFilename + ".tsx";
});
if (!emitSource) {
var allFiles = filenames.join(", ");
throw new Error("Cannot find the corresponding source file for " + emitFilename + " " + handbookOptions.showEmittedFile + " - in " + allFiles);
}
var output = ls.getEmitOutput(emitSource);
var file = output.outputFiles.find(function (o) {

@@ -722,6 +736,7 @@ return o.name === handbookOptions.showEmittedFile;

if (!file) {
var allFiles = output.outputFiles.map(function (o) {
var _allFiles = output.outputFiles.map(function (o) {
return o.name;
}).join(", ");
throw new Error("Cannot find the file " + handbookOptions.showEmittedFile + " - in " + allFiles);
throw new Error("Cannot find the file " + handbookOptions.showEmittedFile + " - in " + _allFiles);
}

@@ -728,0 +743,0 @@

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

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

@@ -270,7 +270,9 @@ import debug from 'debug';

default:
opts[opt.name] = opt.type.get(value.toLowerCase());
// It's a map!
var optMap = opt.type;
opts[opt.name] = optMap.get(value.toLowerCase());
log("Set " + opt.name + " to " + opts[opt.name]);
if (opts[opt.name] === undefined) {
var keys = Array.from(opt.type.keys());
var keys = Array.from(optMap.keys());
throw new Error("Invalid value " + value + " for " + opt.name + ". Allowed values: " + keys.join(","));

@@ -572,7 +574,7 @@ }

if (!handbookOptions.noStaticSemanticInfo && !handbookOptions.showEmit) {
if (!handbookOptions.showEmit) {
var fileContentStartIndexInModifiedFile = code.indexOf(source) == -1 ? 0 : code.indexOf(source);
var linesAbove = code.slice(0, fileContentStartIndexInModifiedFile).split("\n").length - 1; // Get all interesting identifiers in the file, so we can show hover info for it
var identifiers = getIdentifierTextSpans(ts, sourceFile);
var identifiers = handbookOptions.noStaticSemanticInfo ? [] : getIdentifierTextSpans(ts, sourceFile);

@@ -709,3 +711,15 @@ for (var _iterator3 = identifiers, _isArray3 = Array.isArray(_iterator3), _i6 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {

if (handbookOptions.showEmit) {
var output = ls.getEmitOutput(defaultFileName);
// Get the file which created the file we want to show:
var emitFilename = handbookOptions.showEmittedFile || defaultFileName;
var emitSourceFilename = emitFilename.replace(".js", "").replace(".d.ts", "").replace(".map", "");
var emitSource = filenames.find(function (f) {
return f === emitSourceFilename + ".ts" || f === emitSourceFilename + ".tsx";
});
if (!emitSource) {
var allFiles = filenames.join(", ");
throw new Error("Cannot find the corresponding source file for " + emitFilename + " " + handbookOptions.showEmittedFile + " - in " + allFiles);
}
var output = ls.getEmitOutput(emitSource);
var file = output.outputFiles.find(function (o) {

@@ -716,6 +730,7 @@ return o.name === handbookOptions.showEmittedFile;

if (!file) {
var allFiles = output.outputFiles.map(function (o) {
var _allFiles = output.outputFiles.map(function (o) {
return o.name;
}).join(", ");
throw new Error("Cannot find the file " + handbookOptions.showEmittedFile + " - in " + allFiles);
throw new Error("Cannot find the file " + handbookOptions.showEmittedFile + " - in " + _allFiles);
}

@@ -722,0 +737,0 @@

{
"name": "@typescript/twoslash",
"version": "0.4.0",
"version": "0.5.0",
"license": "MIT",

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

"dependencies": {
"@typescript/vfs": "1.0.0",
"@typescript/vfs": "1.0.1",
"debug": "^4.1.1",

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

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