@typescript/twoslash
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -103,2 +103,5 @@ 'use strict'; | ||
case "jsx": | ||
return "jsx"; | ||
case "jsn": | ||
@@ -105,0 +108,0 @@ return "json"; |
@@ -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"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,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}}; | ||
//# sourceMappingURL=twoslash.cjs.production.min.js.map |
@@ -99,2 +99,5 @@ import { createSystem, createFSBackedSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'; | ||
case "jsx": | ||
return "jsx"; | ||
case "jsn": | ||
@@ -101,0 +104,0 @@ return "json"; |
@@ -109,2 +109,5 @@ | ||
case "jsx": | ||
return "jsx"; | ||
case "jsn": | ||
@@ -111,0 +114,0 @@ return "json"; |
@@ -7,3 +7,3 @@ export declare function escapeHtml(text: string): string; | ||
export declare function cleanMarkdownEscaped(code: string): string; | ||
export declare function typesToExtension(types: string): "js" | "ts" | "tsx" | "json"; | ||
export declare function typesToExtension(types: string): "js" | "ts" | "tsx" | "jsx" | "json"; | ||
export declare function getIdentifierTextSpans(ts: typeof import("typescript"), sourceFile: import("typescript").SourceFile): { | ||
@@ -10,0 +10,0 @@ span: import("typescript").TextSpan; |
{ | ||
"name": "@typescript/twoslash", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "TypeScript team", |
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
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
302454
2299