@typescript/twoslash
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,5 @@ | ||
## 1.0.1 | ||
- Adds an option for declaring the project's root to overlay the vfs over: `vfsRoot` | ||
## 1.0.0 | ||
@@ -2,0 +6,0 @@ |
@@ -112,2 +112,4 @@ declare type LZ = typeof import("lz-string"); | ||
fsMap?: Map<string, string>; | ||
/** The cwd for the folder which the virtual fs should be overlaid on top of when using local fs, opts to process.cwd() if not present */ | ||
vfsRoot?: string; | ||
} | ||
@@ -114,0 +116,0 @@ /** |
@@ -434,3 +434,4 @@ 'use strict'; | ||
return process.cwd().split(path.sep).join(path.posix.sep); | ||
var rootPath = options.vfsRoot || process.cwd(); | ||
return rootPath.split(path.sep).join(path.posix.sep); | ||
}; // In a browser we want to DI everything, in node we can use local infra | ||
@@ -437,0 +438,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@typescript/vfs");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){switch(t){case"number":return+e;case"string":return e;case"boolean":return"true"===e.toLowerCase()||0===e.length}throw new Error("Unknown primitive type "+t+" with - "+e)}var n=!1;try{n="undefined"!=typeof localStorage}catch(e){}var i="undefined"!=typeof process,o=n&&localStorage.getItem("DEBUG")||i&&process.env.DEBUG?console.log:function(e){return""};function a(e){for(var t=[],r=[],n=0,i=0,a=0,s=function(s){var c=e[s],f=function(){i=n,n+=c.length+1},u=function(t){o("Removing line "+s+" for "+t),a++,e.splice(s,1),s--};if(c.includes("//")){var p=/^\/\/\s*\^+( .+)?$/.exec(c),d=/^\/\/\s*\^\?\s*$/.exec(c),h=/^\s*\/\/ prettier-ignore$/.exec(c),g=/^\/\/\s*\^\|$/.exec(c);if(null!==d){var v=c.indexOf("^");r.push({kind:"query",offset:v,text:void 0,docs:void 0,line:s+a-1}),u("having a query")}else if(null!==p){var m=c.indexOf("^"),y=c.lastIndexOf("^")-m+1,x=i+m,w=p[1]?p[1].trim():"";t.push({kind:"highlight",position:x,length:y,description:w,line:s}),u("having a highlight")}else if(null!==h)u("being a prettier ignore");else if(null!==g){var E=c.indexOf("^");r.push({kind:"completion",offset:E,text:void 0,docs:void 0,line:s+a-1}),u("having a completion query")}else f()}else f();l=s},l=0;l<e.length;l++)s(l);return{highlights:t,queries:r}}function s(e,t,n,i){o("Setting "+e+" to "+t);var a=function(){if(l){if(c>=s.length)return"break";f=s[c++]}else{if((c=s.next()).done)return"break";f=c.value}var i=f;if(i.name.toLowerCase()===e.toLowerCase()){switch(i.type){case"number":case"string":case"boolean":n[i.name]=r(t,i.type);break;case"list":n[i.name]=t.split(",").map((function(e){return r(e,i.element.type)}));break;default:var a=i.type;if(n[i.name]=a.get(t.toLowerCase()),o("Set "+i.name+" to "+n[i.name]),void 0===n[i.name]){var u=Array.from(a.keys());throw new Error("Invalid value "+t+" for "+i.name+". Allowed values: "+u.join(","))}}return{v:void 0}}},s=i.optionDeclarations,l=Array.isArray(s),c=0;e:for(s=l?s:s[Symbol.iterator]();;){var f,u=a();switch(u){case"break":break e;default:if("object"==typeof u)return u.v}}throw new Error("No compiler setting named '"+e+"' exists!")}var l=/^\/\/\s?@(\w+)$/,c=/^\/\/\s?@(\w+):\s?(.+)$/,f={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:"index.js",noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(r,n,i){var u,p,d;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 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=function(){var e=require("path");return 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=[],a=[],s=n,l=Array.isArray(s),c=0;for(s=l?s:s[Symbol.iterator]();;){var f;if(l){if(c>=s.length)break;f=s[c++]}else{if((c=s.next()).done)break;f=c.value}var u=f;u.includes("// @filename: ")?(a.push([r+i,o]),i=u.split("// @filename: ")[1].trim(),o=[]):o.push(u)}return a.push([r+i,o]),a.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 s=a(n);(e=q).push.apply(e,s.highlights);var l=s.queries.map((function(e,t){var n,i,o=O.getSourceFile(r),a=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var s=F.getQuickInfoAtPosition(r,a),l=F.getDefinitionAtPosition(r,a),c="Could not get LSP result: "+[(n=O.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=F.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=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 V=r.split(/\r\n?|\n/g);a(V),r=V.join("\n"),E.emit&&M.forEach((function(e){F.getEmitOutput(e).outputFiles.forEach((function(e){P.writeFile(e.name,e.text)}))}));var Q=[],R=[];M.forEach((function(e){var t=e.split(".").pop()||"";if(I.includes(t)){E.noErrors||(Q.push.apply(Q,F.getSemanticDiagnostics(e)),Q.push.apply(Q,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),a=r.slice(0,o).split("\n").length-1,s=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(s),c=0;for(s=l?s:s[Symbol.iterator]();;){var f;if(l){if(c>=s.length)break;f=s[c++]}else{if((c=s.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);R.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+a+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+a+1})}}))}}}));var _=Q.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 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'''")}}(_,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 ae=F.getEmitOutput(ie),se=ae.outputFiles.find((function(e){return e.name===A+E.showEmittedFile}));if(!se){var le=ae.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=se.text,n=se.name.split(".").pop(),q=[],C=[],R=[]}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(),R.forEach((function(e){e.start-=ue,e.line-=pe})),R=R.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:R,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 a(e){for(var t=[],r=[],n=0,i=0,a=0,s=function(s){var c=e[s],f=function(){i=n,n+=c.length+1},u=function(t){o("Removing line "+s+" for "+t),a++,e.splice(s,1),s--};if(c.includes("//")){var p=/^\/\/\s*\^+( .+)?$/.exec(c),d=/^\/\/\s*\^\?\s*$/.exec(c),h=/^\s*\/\/ prettier-ignore$/.exec(c),g=/^\/\/\s*\^\|$/.exec(c);if(null!==d){var v=c.indexOf("^");r.push({kind:"query",offset:v,text:void 0,docs:void 0,line:s+a-1}),u("having a query")}else if(null!==p){var m=c.indexOf("^"),y=c.lastIndexOf("^")-m+1,x=i+m,w=p[1]?p[1].trim():"";t.push({kind:"highlight",position:x,length:y,description:w,line:s}),u("having a highlight")}else if(null!==h)u("being a prettier ignore");else if(null!==g){var E=c.indexOf("^");r.push({kind:"completion",offset:E,text:void 0,docs:void 0,line:s+a-1}),u("having a completion query")}else f()}else f();l=s},l=0;l<e.length;l++)s(l);return{highlights:t,queries:r}}function s(e,t,n,i){o("Setting "+e+" to "+t);var a=function(){if(l){if(c>=s.length)return"break";f=s[c++]}else{if((c=s.next()).done)return"break";f=c.value}var i=f;if(i.name.toLowerCase()===e.toLowerCase()){switch(i.type){case"number":case"string":case"boolean":n[i.name]=r(t,i.type);break;case"list":n[i.name]=t.split(",").map((function(e){return r(e,i.element.type)}));break;default:var a=i.type;if(n[i.name]=a.get(t.toLowerCase()),o("Set "+i.name+" to "+n[i.name]),void 0===n[i.name]){var u=Array.from(a.keys());throw new Error("Invalid value "+t+" for "+i.name+". Allowed values: "+u.join(","))}}return{v:void 0}}},s=i.optionDeclarations,l=Array.isArray(s),c=0;e:for(s=l?s:s[Symbol.iterator]();;){var f,u=a();switch(u){case"break":break e;default:if("object"==typeof u)return u.v}}throw new Error("No compiler setting named '"+e+"' exists!")}var l=/^\/\/\s?@(\w+)$/,c=/^\/\/\s?@(\w+):\s?(.+)$/,f={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:"index.js",noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(r,n,i){var u,p,d;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 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=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=[],a=[],s=n,l=Array.isArray(s),c=0;for(s=l?s:s[Symbol.iterator]();;){var f;if(l){if(c>=s.length)break;f=s[c++]}else{if((c=s.next()).done)break;f=c.value}var u=f;u.includes("// @filename: ")?(a.push([r+i,o]),i=u.split("// @filename: ")[1].trim(),o=[]):o.push(u)}return a.push([r+i,o]),a.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 s=a(n);(e=q).push.apply(e,s.highlights);var l=s.queries.map((function(e,t){var n,i,o=O.getSourceFile(r),a=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var s=F.getQuickInfoAtPosition(r,a),l=F.getDefinitionAtPosition(r,a),c="Could not get LSP result: "+[(n=O.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=F.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=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);a(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),a=r.slice(0,o).split("\n").length-1,s=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(s),c=0;for(s=l?s:s[Symbol.iterator]();;){var f;if(l){if(c>=s.length)break;f=s[c++]}else{if((c=s.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+a+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+a+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 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'''")}}(_,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 ae=F.getEmitOutput(ie),se=ae.outputFiles.find((function(e){return e.name===A+E.showEmittedFile}));if(!se){var le=ae.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=se.text,n=se.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 |
@@ -430,3 +430,4 @@ import { createSystem, createFSBackedSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'; | ||
return process.cwd().split(path.sep).join(path.posix.sep); | ||
var rootPath = options.vfsRoot || process.cwd(); | ||
return rootPath.split(path.sep).join(path.posix.sep); | ||
}; // In a browser we want to DI everything, in node we can use local infra | ||
@@ -433,0 +434,0 @@ |
{ | ||
"name": "@typescript/twoslash", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "TypeScript team", |
@@ -773,2 +773,4 @@ # TypeScript TwoSlash | ||
fsMap?: Map<string, string> | ||
/** The cwd for the folder which the virtual fs should be overlaid on top of when using local fs, opts to process.cwd() if not present */ | ||
vfsRoot?: string | ||
} | ||
@@ -775,0 +777,0 @@ ``` |
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
256966
1603
864