@typescript/twoslash
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -13,8 +13,8 @@ declare type LZ = typeof import("lz-string"); | ||
export interface ExampleOptions { | ||
/** Let's the sample suppress all error diagnostics */ | ||
noErrors: false; | ||
/** Lets the sample suppress all error diagnostics */ | ||
noErrors: boolean; | ||
/** An array of TS error codes, which you write as space separated - this is so the tool can know about unexpected errors */ | ||
errors: number[]; | ||
/** Shows the JS equivalent of the TypeScript code instead */ | ||
showEmit: false; | ||
showEmit: boolean; | ||
/** | ||
@@ -21,0 +21,0 @@ * Must be used with showEmit, lets you choose the file to present instead of the source - defaults to index.js which |
@@ -5,5 +5,2 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var debug = _interopDefault(require('debug')); | ||
var vfs = require('@typescript/vfs'); | ||
@@ -155,5 +152,10 @@ | ||
var log = | ||
var hasLocalStorage = typeof localStorage !== "undefined"; | ||
var hasProcess = typeof process !== "undefined"; | ||
var shouldDebug = hasLocalStorage && | ||
/*#__PURE__*/ | ||
debug("twoslasher"); | ||
localStorage.getItem("DEBUG") || hasProcess && process.env.DEBUG; | ||
var log = shouldDebug ? console.log : function (_message) { | ||
return ""; | ||
}; | ||
@@ -160,0 +162,0 @@ function filterHighlightLines(codeLines) { |
@@ -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],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),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}),u("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}),u("having a highlight")}else if(null!==d)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,h){var d=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),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),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,x,d),S=null!=h?h:function(e){return r.createDefaultMapFromNodeModules(e)}(b),k=r.createSystem(S),j=r.createVirtualTypeScriptEnvironment(k,[],d,b),P=j.languageService;e=w.join("\n");var A=[],F=[],O=[],C=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])}))}(e,y),q=C.map((function(e){return e[0]})),T=function(){var e,t;if(I){if($>=L.length)return"break";D=L[$++]}else{if(($=L.next()).done)return"break";D=$.value}var r=D[0],n=D[1],i=n.join("\n");j.createFile(r,i);var o=a(n);(e=O).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(""),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&&!E.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),h=o.text.slice(p.startPos,a).split(".").pop()||"";return{kind:"completions",completions:(null==u?void 0:u.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)},L=C,I=Array.isArray(L),$=0;for(L=I?L:L[Symbol.iterator]();;){var D;if("break"===T())break}var N=e.split(/\r\n?|\n/g);a(N),e=N.join("\n"),E.emit&&q.forEach((function(e){P.getEmitOutput(e).outputFiles.forEach((function(e){k.writeFile(e.name,e.text)}))}));var M=[],V=[];q.forEach((function(t){E.noErrors||(M.push.apply(M,P.getSemanticDiagnostics(t)),M.push.apply(M,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}(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 f=c,u=f.span,p=P.getQuickInfoAtPosition(t,u.start);if(p&&p.displayParts){var h=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,y=d.createSourceFile("_.ts",e,d.ScriptTarget.ES2015),x=d.getLineAndCharacterOfPosition(y,v);V.push({text:h,docs:m,start:v,length:u.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":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 Q=M.filter((function(e){return e.file&&q.includes(e.file.fileName)}));!E.noErrorValidation&&Q.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'''")}}(Q,E,t,m);var R=[],U=Q,_=Array.isArray(U),Y=0;for(U=_?U:U[Symbol.iterator]();;){var z;if(_){if(Y>=U.length)break;z=U[Y++]}else{if((Y=U.next()).done)break;z=Y.value}var B=z,J=j.sys.readFile(B.file.fileName),G=e.indexOf(J),H=d.flattenDiagnosticMessageText(B.messageText,"\n").replace(/</g,"<"),K="err-"+B.code+"-"+B.start+"-"+B.length,W=d.getLineAndCharacterOfPosition(B.file,B.start);R.push({category:B.category,code:B.code,length:B.length,start:B.start?B.start+G:void 0,line:W.line,character:W.character,renderedMessage:H,id:K})}if(E.showEmit){var X=E.showEmittedFile||y,Z=X.replace(".js","").replace(".d.ts","").replace(".map",""),ee=q.find((function(e){return e===Z+".ts"||e===Z+".tsx"}));if(!ee){var te=q.join(", ");throw new Error("Cannot find the corresponding source file for "+X+" "+E.showEmittedFile+" - in "+te)}var re=P.getEmitOutput(ee),ne=re.outputFiles.find((function(e){return e.name===E.showEmittedFile}));if(!ne){var ie=re.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+E.showEmittedFile+" - in "+ie)}e=ne.text,t=ne.name.split(".").pop(),O=[],A=[],V=[]}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(),V.forEach((function(e){e.start-=se,e.line-=le})),V=V.filter((function(e){return e.start>-1})),R.forEach((function(e){e.start&&(e.start-=se),e.line&&(e.line-=le)})),R=R.filter((function(e){return e.start&&e.start>-1})),O.forEach((function(e){e.position-=se,e.line-=le})),O=O.filter((function(e){return e.position>-1})),F.forEach((function(e){return e.line-=le})),F=F.filter((function(e){return e.line>-1}))}return{code:e,extension:t,highlights:O,queries:F,staticQuickInfos:V,errors:R,playgroundURL:oe}}; | ||
"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="undefined"!=typeof localStorage,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 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("^"),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}),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,u,p,d){var h=null!=u?u:require("typescript"),g=null!=p?p:require("lz-string"),m=r,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)}(n),y="index."+v;o("\n\nLooking at code: \n```"+v+"\n"+r+"\n```\n");var x={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")}(r);var w=(r=function(e){return(e=e.replace(/¨D/g,"$")).replace(/¨T/g,"~")}(r)).split(/\r\n?|\n/g),E=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}(w),{},i),b=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}(w,x,h),S=null!=d?d:function(t){return e.createDefaultMapFromNodeModules(t)}(b),k=e.createSystem(S),j=e.createVirtualTypeScriptEnvironment(k,[],h,b),P=j.languageService;r=w.join("\n");var A=[],F=[],O=[],C=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,y),T=C.map((function(e){return e[0]})),q=function(){var e,t;if(I){if(D>=L.length)return"break";$=L[D++]}else{if((D=L.next()).done)return"break";$=D.value}var r=$[0],n=$[1],i=n.join("\n");j.createFile(r,i);var o=a(n);(e=O).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&&!E.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=A).push.apply(t,s);var l=n.join("\n");j.updateFile(r,l)},L=C,I=Array.isArray(L),D=0;for(L=I?L:L[Symbol.iterator]();;){var $;if("break"===q())break}var N=r.split(/\r\n?|\n/g);a(N),r=N.join("\n"),E.emit&&T.forEach((function(e){P.getEmitOutput(e).outputFiles.forEach((function(e){k.writeFile(e.name,e.text)}))}));var M=[],U=[];T.forEach((function(e){E.noErrors||(M.push.apply(M,P.getSemanticDiagnostics(e)),M.push.apply(M,P.getSyntacticDiagnostics(e)));var t=j.sys.readFile(e),n=j.getSourceFile(e);if(!n)throw new Error("No sourcefile found for "+e+" in twoslash");if(!E.showEmit){var i=-1==r.indexOf(t)?0:r.indexOf(t),o=r.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(e,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,y=h.createSourceFile("_.ts",r,h.ScriptTarget.ES2015),x=h.getLineAndCharacterOfPosition(y,v);U.push({text:d,docs:m,start:v,length:u.length,line:x.line,character:x.character,targetString:g})}}A.filter((function(t){return t.file===e})).forEach((function(e){var t=h.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 V=M.filter((function(e){return e.file&&T.includes(e.file.fileName)}));!E.noErrorValidation&&V.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'''")}}(V,E,n,m);var B=[],Q=V,R=Array.isArray(Q),_=0;for(Q=R?Q:Q[Symbol.iterator]();;){var G;if(R){if(_>=Q.length)break;G=Q[_++]}else{if((_=Q.next()).done)break;G=_.value}var Y=G,z=j.sys.readFile(Y.file.fileName),J=r.indexOf(z),H=h.flattenDiagnosticMessageText(Y.messageText,"\n").replace(/</g,"<"),K="err-"+Y.code+"-"+Y.start+"-"+Y.length,W=h.getLineAndCharacterOfPosition(Y.file,Y.start);B.push({category:Y.category,code:Y.code,length:Y.length,start:Y.start?Y.start+J:void 0,line:W.line,character:W.character,renderedMessage:H,id:K})}if(E.showEmit){var X=E.showEmittedFile||y,Z=X.replace(".js","").replace(".d.ts","").replace(".map",""),ee=T.find((function(e){return e===Z+".ts"||e===Z+".tsx"}));if(!ee){var te=T.join(", ");throw new Error("Cannot find the corresponding source file for "+X+" "+E.showEmittedFile+" - in "+te)}var re=P.getEmitOutput(ee),ne=re.outputFiles.find((function(e){return e.name===E.showEmittedFile}));if(!ne){var ie=re.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+E.showEmittedFile+" - in "+ie)}r=ne.text,n=ne.name.split(".").pop(),O=[],A=[],U=[]}var oe="https://www.typescriptlang.org/play/#code/"+g.compressToEncodedURIComponent(m),ae="// ---cut---\n";if(r.includes(ae)){var se=r.indexOf(ae)+ae.length,le=r.substr(0,se).split("\n").length-1;r=r.split(ae).pop(),U.forEach((function(e){e.start-=se,e.line-=le})),U=U.filter((function(e){return e.start>-1})),B.forEach((function(e){e.start&&(e.start-=se),e.line&&(e.line-=le)})),B=B.filter((function(e){return e.start&&e.start>-1})),O.forEach((function(e){e.position-=se,e.line-=le})),O=O.filter((function(e){return e.position>-1})),F.forEach((function(e){return e.line-=le})),F=F.filter((function(e){return e.line>-1}))}return{code:r,extension:n,highlights:O,queries:F,staticQuickInfos:U,errors:B,playgroundURL:oe}}; | ||
//# sourceMappingURL=twoslash.cjs.production.min.js.map |
@@ -1,2 +0,1 @@ | ||
import debug from 'debug'; | ||
import { createDefaultMapFromNodeModules, createSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'; | ||
@@ -148,5 +147,10 @@ | ||
var log = | ||
var hasLocalStorage = typeof localStorage !== "undefined"; | ||
var hasProcess = typeof process !== "undefined"; | ||
var shouldDebug = hasLocalStorage && | ||
/*#__PURE__*/ | ||
debug("twoslasher"); | ||
localStorage.getItem("DEBUG") || hasProcess && process.env.DEBUG; | ||
var log = shouldDebug ? console.log : function (_message) { | ||
return ""; | ||
}; | ||
@@ -153,0 +157,0 @@ function filterHighlightLines(codeLines) { |
{ | ||
"name": "@typescript/twoslash", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"license": "MIT", | ||
@@ -27,2 +27,3 @@ "author": "TypeScript team", | ||
"markdown-magic": "^1.0.0", | ||
"prettier": "*", | ||
"tsdx": "^0.12.3", | ||
@@ -29,0 +30,0 @@ "tslib": "^1.10.0", |
@@ -99,8 +99,8 @@ # TypeScript TwoSlash | ||
export interface ExampleOptions { | ||
/** Let's the sample suppress all error diagnostics */ | ||
noErrors: false | ||
/** Lets the sample suppress all error diagnostics */ | ||
noErrors: boolean | ||
/** An array of TS error codes, which you write as space separated - this is so the tool can know about unexpected errors */ | ||
errors: number[] | ||
/** Shows the JS equivalent of the TypeScript code instead */ | ||
showEmit: false | ||
showEmit: boolean | ||
/** | ||
@@ -107,0 +107,0 @@ * Must be used with showEmit, lets you choose the file to present instead of the source - defaults to index.js which |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
244915
1540
10
5