@typescript/twoslash
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -0,1 +1,5 @@ | ||
## 1.1.1 | ||
- Better handling of JSON files | ||
## 1.1.0 | ||
@@ -2,0 +6,0 @@ |
@@ -474,3 +474,5 @@ 'use strict'; | ||
if (!sourceFiles.includes(filetype)) { | ||
var allowJSON = compilerOptions.resolveJsonModule && filetype === "json"; | ||
if (!sourceFiles.includes(filetype) && !allowJSON) { | ||
return "continue"; | ||
@@ -572,2 +574,4 @@ } // Create the file in the vfs | ||
filenames.forEach(function (f) { | ||
var filetype = f.split(".").pop() || ""; | ||
if (!sourceFiles.includes(filetype)) return; | ||
var output = ls.getEmitOutput(f); | ||
@@ -574,0 +578,0 @@ output.outputFiles.forEach(function (output) { |
@@ -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 s(e){for(var t=[],r=[],n=0,i=0,s=0,a=function(a){var c=e[a],f=function(){i=n,n+=c.length+1},u=function(t){o("Removing line "+a+" for "+t),s++,e.splice(a,1),a--};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("^");r.push({kind:"query",offset:v,text:void 0,docs:void 0,line:a+s-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:a}),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:a+s-1}),u("having a completion query")}else f()}else f();l=a},l=0;l<e.length;l++)a(l);return{highlights:t,queries:r}}function a(e,t,n,i){o("Setting "+e+" to "+t);var s=function(){if(l){if(c>=a.length)return"break";f=a[c++]}else{if((c=a.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 s=i.type;if(n[i.name]=s.get(t.toLowerCase()),o("Set "+i.name+" to "+n[i.name]),void 0===n[i.name]){var u=Array.from(s.keys());throw new Error("Invalid value "+t+" for "+i.name+". Allowed values: "+u.join(","))}}return{v:void 0}}},a=i.optionDeclarations,l=Array.isArray(a),c=0;e:for(a=l?a:a[Symbol.iterator]();;){var f,u=s();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;void 0===i&&(i={});var h=null!==(u=i.tsModule)&&void 0!==u?u:require("typescript"),g=null!==(p=i.lzstringModule)&&void 0!==p?p:require("lz-string"),v=r,m=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."+m;o("\n\nLooking at code: \n```"+m+"\n"+r+"\n```\n");var x=t({strict:!0,target:h.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 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.defaultOptions),b=function(e,r,n){for(var i=t({},r),o=0;o<e.length;){var s=void 0;if(s=l.exec(e[o]))i[s[1]]=!0,a(s[1],"true",i,n);else{if(!(s=c.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}a(s[1],s[2],i,n)}e.splice(o,1)}return i}(w,x,h),S=function(){var e=require("path");return(i.vfsRoot||process.cwd()).split(e.sep).join(e.posix.sep)},k=!!i.fsMap,j=k&&i.fsMap?i.fsMap:new Map,P=k?e.createSystem(j):e.createFSBackedSystem(j,S(),h),A=k?"/":S()+"/",O=e.createVirtualTypeScriptEnvironment(P,[],h,b,i.customTransformers),F=O.languageService;r=w.join("\n");var C=[],T=[],q=[],L=function(e,t,r){var n=e.split(/\r\n?|\n/g),i=e.includes("@filename: "+t)?"global.ts":t,o=[],s=[],a=n,l=Array.isArray(a),c=0;for(a=l?a:a[Symbol.iterator]();;){var f;if(l){if(c>=a.length)break;f=a[c++]}else{if((c=a.next()).done)break;f=c.value}var u=f;u.includes("// @filename: ")?(s.push([r+i,o]),i=u.split("// @filename: ")[1].trim(),o=[]):o.push(u)}return s.push([r+i,o]),s.filter((function(e){return e[1].length>0&&(e[1].length>1||""!==e[1][0])}))}(r,y,A),I=["js","jsx","ts","tsx"],M=L.map((function(e){return e[0]})),D=function(){var e,t;if(N){if(U>=$.length)return"break";B=$[U++]}else{if((U=$.next()).done)return"break";B=U.value}var r=B[0],n=B[1],i=r.split(".").pop()||"";if(!I.includes(i))return"continue";var o=n.join("\n");O.createFile(r,o);var a=s(n);(e=q).push.apply(e,a.highlights);var l=a.queries.map((function(e,t){var n,i,o=O.getSourceFile(r),s=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=F.getQuickInfoAtPosition(r,s),l=F.getDefinitionAtPosition(r,s),c="Could not get LSP result: "+[(n=O.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(""),f=void 0;return a&&l&&a.displayParts&&(c=a.displayParts.map((function(e){return e.text})).join(""),f=a.documentation?a.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=F.getCompletionsAtPosition(r,s-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,s-1),d=o.text.slice(p.startPos,s).split(".").pop()||"";return{kind:"completions",completions:(null==u?void 0:u.entries)||[],completionPrefix:d,line:e.line-t,offset:e.offset,file:r}}}));(t=C).push.apply(t,l);var c=n.join("\n");O.updateFile(r,c)},$=L,N=Array.isArray($),U=0;e:for($=N?$:$[Symbol.iterator]();;){var B;switch(D()){case"break":break e;case"continue":continue}}var R=r.split(/\r\n?|\n/g);s(R),r=R.join("\n"),E.emit&&M.forEach((function(e){F.getEmitOutput(e).outputFiles.forEach((function(e){P.writeFile(e.name,e.text)}))}));var V=[],Q=[];M.forEach((function(e){var t=e.split(".").pop()||"";if(I.includes(t)){E.noErrors||(V.push.apply(V,F.getSemanticDiagnostics(e)),V.push.apply(V,F.getSyntacticDiagnostics(e)));var n=O.sys.readFile(e),i=O.getSourceFile(e);if(!i)throw new Error("No sourcefile found for "+e+" in twoslash");if(!E.showEmit){var o=-1==r.indexOf(n)?0:r.indexOf(n),s=r.slice(0,o).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,i),l=Array.isArray(a),c=0;for(a=l?a:a[Symbol.iterator]();;){var f;if(l){if(c>=a.length)break;f=a[c++]}else{if((c=a.next()).done)break;f=c.value}var u=f,p=u.span,d=F.getQuickInfoAtPosition(e,p.start);if(d&&d.displayParts){var g=d.displayParts.map((function(e){return e.text})).join(""),v=u.text,m=d.documentation?d.documentation.map((function(e){return e.text})).join("\n"):void 0,y=p.start+o,x=h.createSourceFile("_.ts",r,h.ScriptTarget.ES2015),w=h.getLineAndCharacterOfPosition(x,y);Q.push({text:g,docs:m,start:y,length:p.length,line:w.line,character:w.character,targetString:v})}}C.filter((function(t){return t.file===e})).forEach((function(e){var t=h.getPositionOfLineAndCharacter(i,e.line,e.offset)+o;switch(e.kind){case"query":T.push({docs:e.docs,kind:"query",start:t+o,length:e.text.length,text:e.text,offset:e.offset,line:e.line+s+1});break;case"completions":T.push({completions:e.completions,kind:"completions",start:t+o,completionsPrefix:e.completionPrefix,length:1,offset:e.offset,line:e.line+s+1})}}))}}}));var _=V.filter((function(e){return e.file&&M.includes(e.file.fileName)}));!E.noErrorValidation&&_.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 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'''"+r+"\n"+n+"\n'''")}}(_,E,n,v);var z=[],G=_,Y=Array.isArray(G),J=0;for(G=Y?G:G[Symbol.iterator]();;){var H;if(Y){if(J>=G.length)break;H=G[J++]}else{if((J=G.next()).done)break;H=J.value}var K=H,W=O.sys.readFile(K.file.fileName),X=r.indexOf(W),Z=h.flattenDiagnosticMessageText(K.messageText,"\n").replace(/</g,"<"),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||y,ne=A+re.replace(".js","").replace(".d.ts","").replace(".map",""),ie=M.find((function(e){return e===ne+".ts"||e===ne+".tsx"}));if(!ie){var oe=M.join(", ");throw new Error("Cannot find the corresponding source file for "+re+" (looking for: "+ne+" in the vfs) - in "+oe)}var se=F.getEmitOutput(ie),ae=se.outputFiles.find((function(e){return e.name===A+E.showEmittedFile}));if(!ae){var le=se.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+E.showEmittedFile+" (looking for: "+(A+E.showEmittedFile)+" in the vfs) - in "+le)}r=ae.text,n=ae.name.split(".").pop(),q=[],C=[],Q=[]}var ce="https://www.typescriptlang.org/play/#code/"+g.compressToEncodedURIComponent(v),fe="// ---cut---\n";if(r.includes(fe)){var ue=r.indexOf(fe)+fe.length,pe=r.substr(0,ue).split("\n").length-1;r=r.split(fe).pop(),Q.forEach((function(e){e.start-=ue,e.line-=pe})),Q=Q.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})),q.forEach((function(e){e.position-=ue,e.line-=pe})),q=q.filter((function(e){return e.position>-1})),T.forEach((function(e){return e.line-=pe})),T=T.filter((function(e){return e.line>-1}))}return{code:r,extension:n,highlights:q,queries:T,staticQuickInfos:Q,errors:z,playgroundURL:ce}}; | ||
"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 s(e){for(var t=[],r=[],n=0,i=0,s=0,a=function(a){var c=e[a],f=function(){i=n,n+=c.length+1},u=function(t){o("Removing line "+a+" for "+t),s++,e.splice(a,1),a--};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("^");r.push({kind:"query",offset:v,text:void 0,docs:void 0,line:a+s-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:a}),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:a+s-1}),u("having a completion query")}else f()}else f();l=a},l=0;l<e.length;l++)a(l);return{highlights:t,queries:r}}function a(e,t,n,i){o("Setting "+e+" to "+t);var s=function(){if(l){if(c>=a.length)return"break";f=a[c++]}else{if((c=a.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 s=i.type;if(n[i.name]=s.get(t.toLowerCase()),o("Set "+i.name+" to "+n[i.name]),void 0===n[i.name]){var u=Array.from(s.keys());throw new Error("Invalid value "+t+" for "+i.name+". Allowed values: "+u.join(","))}}return{v:void 0}}},a=i.optionDeclarations,l=Array.isArray(a),c=0;e:for(a=l?a:a[Symbol.iterator]();;){var f,u=s();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;void 0===i&&(i={});var h=null!==(u=i.tsModule)&&void 0!==u?u:require("typescript"),g=null!==(p=i.lzstringModule)&&void 0!==p?p:require("lz-string"),v=r,m=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."+m;o("\n\nLooking at code: \n```"+m+"\n"+r+"\n```\n");var x=t({strict:!0,target:h.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 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.defaultOptions),b=function(e,r,n){for(var i=t({},r),o=0;o<e.length;){var s=void 0;if(s=l.exec(e[o]))i[s[1]]=!0,a(s[1],"true",i,n);else{if(!(s=c.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}a(s[1],s[2],i,n)}e.splice(o,1)}return i}(w,x,h),S=function(){var e=require("path");return(i.vfsRoot||process.cwd()).split(e.sep).join(e.posix.sep)},k=!!i.fsMap,j=k&&i.fsMap?i.fsMap:new Map,P=k?e.createSystem(j):e.createFSBackedSystem(j,S(),h),A=k?"/":S()+"/",O=e.createVirtualTypeScriptEnvironment(P,[],h,b,i.customTransformers),F=O.languageService;r=w.join("\n");var C=[],T=[],q=[],L=function(e,t,r){var n=e.split(/\r\n?|\n/g),i=e.includes("@filename: "+t)?"global.ts":t,o=[],s=[],a=n,l=Array.isArray(a),c=0;for(a=l?a:a[Symbol.iterator]();;){var f;if(l){if(c>=a.length)break;f=a[c++]}else{if((c=a.next()).done)break;f=c.value}var u=f;u.includes("// @filename: ")?(s.push([r+i,o]),i=u.split("// @filename: ")[1].trim(),o=[]):o.push(u)}return s.push([r+i,o]),s.filter((function(e){return e[1].length>0&&(e[1].length>1||""!==e[1][0])}))}(r,y,A),I=["js","jsx","ts","tsx"],M=L.map((function(e){return e[0]})),D=function(){var e,t;if(N){if(U>=$.length)return"break";B=$[U++]}else{if((U=$.next()).done)return"break";B=U.value}var r=B[0],n=B[1],i=r.split(".").pop()||"",o=b.resolveJsonModule&&"json"===i;if(!I.includes(i)&&!o)return"continue";var a=n.join("\n");O.createFile(r,a);var l=s(n);(e=q).push.apply(e,l.highlights);var c=l.queries.map((function(e,t){var n,i,o=O.getSourceFile(r),s=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=F.getQuickInfoAtPosition(r,s),l=F.getDefinitionAtPosition(r,s),c="Could not get LSP result: "+[(n=O.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(""),f=void 0;return a&&l&&a.displayParts&&(c=a.displayParts.map((function(e){return e.text})).join(""),f=a.documentation?a.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=F.getCompletionsAtPosition(r,s-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,s-1),d=o.text.slice(p.startPos,s).split(".").pop()||"";return{kind:"completions",completions:(null==u?void 0:u.entries)||[],completionPrefix:d,line:e.line-t,offset:e.offset,file:r}}}));(t=C).push.apply(t,c);var f=n.join("\n");O.updateFile(r,f)},$=L,N=Array.isArray($),U=0;e:for($=N?$:$[Symbol.iterator]();;){var B;switch(D()){case"break":break e;case"continue":continue}}var R=r.split(/\r\n?|\n/g);s(R),r=R.join("\n"),E.emit&&M.forEach((function(e){var t=e.split(".").pop()||"";I.includes(t)&&F.getEmitOutput(e).outputFiles.forEach((function(e){P.writeFile(e.name,e.text)}))}));var V=[],Q=[];M.forEach((function(e){var t=e.split(".").pop()||"";if(I.includes(t)){E.noErrors||(V.push.apply(V,F.getSemanticDiagnostics(e)),V.push.apply(V,F.getSyntacticDiagnostics(e)));var n=O.sys.readFile(e),i=O.getSourceFile(e);if(!i)throw new Error("No sourcefile found for "+e+" in twoslash");if(!E.showEmit){var o=-1==r.indexOf(n)?0:r.indexOf(n),s=r.slice(0,o).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,i),l=Array.isArray(a),c=0;for(a=l?a:a[Symbol.iterator]();;){var f;if(l){if(c>=a.length)break;f=a[c++]}else{if((c=a.next()).done)break;f=c.value}var u=f,p=u.span,d=F.getQuickInfoAtPosition(e,p.start);if(d&&d.displayParts){var g=d.displayParts.map((function(e){return e.text})).join(""),v=u.text,m=d.documentation?d.documentation.map((function(e){return e.text})).join("\n"):void 0,y=p.start+o,x=h.createSourceFile("_.ts",r,h.ScriptTarget.ES2015),w=h.getLineAndCharacterOfPosition(x,y);Q.push({text:g,docs:m,start:y,length:p.length,line:w.line,character:w.character,targetString:v})}}C.filter((function(t){return t.file===e})).forEach((function(e){var t=h.getPositionOfLineAndCharacter(i,e.line,e.offset)+o;switch(e.kind){case"query":T.push({docs:e.docs,kind:"query",start:t+o,length:e.text.length,text:e.text,offset:e.offset,line:e.line+s+1});break;case"completions":T.push({completions:e.completions,kind:"completions",start:t+o,completionsPrefix:e.completionPrefix,length:1,offset:e.offset,line:e.line+s+1})}}))}}}));var _=V.filter((function(e){return e.file&&M.includes(e.file.fileName)}));!E.noErrorValidation&&_.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 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'''"+r+"\n"+n+"\n'''")}}(_,E,n,v);var z=[],G=_,J=Array.isArray(G),Y=0;for(G=J?G:G[Symbol.iterator]();;){var H;if(J){if(Y>=G.length)break;H=G[Y++]}else{if((Y=G.next()).done)break;H=Y.value}var K=H,W=O.sys.readFile(K.file.fileName),X=r.indexOf(W),Z=h.flattenDiagnosticMessageText(K.messageText,"\n").replace(/</g,"<"),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||y,ne=A+re.replace(".js","").replace(".d.ts","").replace(".map",""),ie=M.find((function(e){return e===ne+".ts"||e===ne+".tsx"}));if(!ie){var oe=M.join(", ");throw new Error("Cannot find the corresponding source file for "+re+" (looking for: "+ne+" in the vfs) - in "+oe)}var se=F.getEmitOutput(ie),ae=se.outputFiles.find((function(e){return e.name===A+E.showEmittedFile}));if(!ae){var le=se.outputFiles.map((function(e){return e.name})).join(", ");throw new Error("Cannot find the file "+E.showEmittedFile+" (looking for: "+(A+E.showEmittedFile)+" in the vfs) - in "+le)}r=ae.text,n=ae.name.split(".").pop(),q=[],C=[],Q=[]}var ce="https://www.typescriptlang.org/play/#code/"+g.compressToEncodedURIComponent(v),fe="// ---cut---\n";if(r.includes(fe)){var ue=r.indexOf(fe)+fe.length,pe=r.substr(0,ue).split("\n").length-1;r=r.split(fe).pop(),Q.forEach((function(e){e.start-=ue,e.line-=pe})),Q=Q.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})),q.forEach((function(e){e.position-=ue,e.line-=pe})),q=q.filter((function(e){return e.position>-1})),T.forEach((function(e){return e.line-=pe})),T=T.filter((function(e){return e.line>-1}))}return{code:r,extension:n,highlights:q,queries:T,staticQuickInfos:Q,errors:z,playgroundURL:ce}}; | ||
//# sourceMappingURL=twoslash.cjs.production.min.js.map |
@@ -470,3 +470,5 @@ import { createSystem, createFSBackedSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'; | ||
if (!sourceFiles.includes(filetype)) { | ||
var allowJSON = compilerOptions.resolveJsonModule && filetype === "json"; | ||
if (!sourceFiles.includes(filetype) && !allowJSON) { | ||
return "continue"; | ||
@@ -568,2 +570,4 @@ } // Create the file in the vfs | ||
filenames.forEach(function (f) { | ||
var filetype = f.split(".").pop() || ""; | ||
if (!sourceFiles.includes(filetype)) return; | ||
var output = ls.getEmitOutput(f); | ||
@@ -570,0 +574,0 @@ output.outputFiles.forEach(function (output) { |
@@ -480,3 +480,5 @@ | ||
if (!sourceFiles.includes(filetype)) { | ||
var allowJSON = compilerOptions.resolveJsonModule && filetype === "json"; | ||
if (!sourceFiles.includes(filetype) && !allowJSON) { | ||
return "continue"; | ||
@@ -578,2 +580,4 @@ } // Create the file in the vfs | ||
filenames.forEach(function (f) { | ||
var filetype = f.split(".").pop() || ""; | ||
if (!sourceFiles.includes(filetype)) return; | ||
var output = ls.getEmitOutput(f); | ||
@@ -580,0 +584,0 @@ output.outputFiles.forEach(function (output) { |
{ | ||
"name": "@typescript/twoslash", | ||
"version": "1.1.0", | ||
"version": "1.1.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
288024
2320