@typescript/twoslash
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -268,3 +268,3 @@ 'use strict'; | ||
var _loop3 = function _loop3() { | ||
var _loop2 = function _loop2() { | ||
if (_isArray) { | ||
@@ -318,14 +318,9 @@ if (_i2 >= _iterator.length) return "break"; | ||
_loop2: for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _ret = _loop3(); | ||
var _ret = _loop2(); | ||
switch (_ret) { | ||
case "break": | ||
break _loop2; | ||
default: | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
if (_ret === "break") break; | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
@@ -428,4 +423,4 @@ | ||
var ts = (_options$tsModule = options.tsModule) !== null && _options$tsModule !== void 0 ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) !== null && _options$lzstringModu !== void 0 ? _options$lzstringModu : require("lz-string"); | ||
var ts = (_options$tsModule = options.tsModule) != null ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) != null ? _options$lzstringModu : require("lz-string"); | ||
var originalCode = code; | ||
@@ -440,3 +435,3 @@ var safeExtension = typesToExtension(extension); | ||
allowJs: true | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) !== null && _options$defaultCompi !== void 0 ? _options$defaultCompi : {}); | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) != null ? _options$defaultCompi : {}); | ||
@@ -448,3 +443,3 @@ validateInput(code); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), {}, options.defaultOptions); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), options.defaultOptions); | ||
@@ -483,3 +478,3 @@ var compilerOptions = filterCompilerOptions(codeLines, defaultCompilerOptions, ts); // Handle special casing the lookup for when using jsx preserve which creates .jsx files | ||
var _loop5 = function _loop5() { | ||
var _loop3 = function _loop3() { | ||
var _highlights, _partialQueries; | ||
@@ -561,3 +556,3 @@ | ||
kind: "completions", | ||
completions: (_quickInfo === null || _quickInfo === void 0 ? void 0 : _quickInfo.entries) || [], | ||
completions: (_quickInfo == null ? void 0 : _quickInfo.entries) || [], | ||
completionPrefix: lastDot, | ||
@@ -580,14 +575,9 @@ line: q.line - i, | ||
_loop4: for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _ret2 = _loop5(); | ||
var _ret2 = _loop3(); | ||
switch (_ret2) { | ||
case "break": | ||
break _loop4; | ||
case "continue": | ||
continue; | ||
} | ||
if (_ret2 === "break") break; | ||
if (_ret2 === "continue") continue; | ||
} // We need to also strip the highlights + queries from the main file which is shown to people | ||
@@ -594,0 +584,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 s(e){for(var t=[],r=[],n=0,i=0,s=0,a=function(a){var c=e[a],u=function(){i=n,n+=c.length+1},f=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}),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:a}),f("having a highlight")}else if(null!==h)f("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}),f("having a completion query")}else u()}else u();l=a},l=0;l<e.length;l++)a(l);return{highlights:t,queries:r}}function a(e,t,r){var n=r.get(t.toLowerCase());if(o("Get "+e+" mapped option: "+t+" => "+n),void 0===n){var i=Array.from(r.keys());throw new Error("Invalid value "+t+" for "+e+". Allowed values: "+i.join(","))}return n}function l(e,t,n,i){o("Setting "+e+" to "+t);var s=function(){if(c){if(u>=l.length)return"break";f=l[u++]}else{if((u=l.next()).done)return"break";f=u.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":var o=i.element.type,s=t.split(",");n[i.name]=s.map("string"==typeof o?function(e){return r(e,o)}:function(e){return a(i.name,e,o)});break;default:n[i.name]=a(i.name,t,i.type)}return{v:void 0}}},l=i.optionDeclarations,c=Array.isArray(l),u=0;e:for(l=c?l:l[Symbol.iterator]();;){var f,p=s();switch(p){case"break":break e;default:if("object"==typeof p)return p.v}}throw new Error("No compiler setting named '"+e+"' exists!")}var c=/^\/\/\s?@(\w+)$/,u=/^\/\/\s?@(\w+):\s?(.+)$/,f={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:void 0,noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(r,n,i){var a,p,d;void 0===i&&(i={});var h=null!==(a=i.tsModule)&&void 0!==a?a: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),x="index."+m;o("\n\nLooking at code: \n```"+m+"\n"+r+"\n```\n");var y=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=c.exec(e[n]))?i[1]in r&&(r[i[1]]=!0,o("Setting options."+i[1]+" to true"),e.splice(n,1),n--):(i=u.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=c.exec(e[o]))i[s[1]]=!0,l(s[1],"true",i,n);else{if(!(s=u.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}l(s[1],s[2],i,n)}e.splice(o,1)}return i}(w,y,h);E.showEmittedFile||(E.showEmittedFile=b.jsx&&b.jsx===h.JsxEmit.Preserve?"index.jsx":"index.js");var 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,F=k?e.createSystem(j):e.createFSBackedSystem(j,S(),h),P=k?"/":S()+"/",A=e.createVirtualTypeScriptEnvironment(F,[],h,b,i.customTransformers),O=A.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 u;if(l){if(c>=a.length)break;u=a[c++]}else{if((c=a.next()).done)break;u=c.value}var f=u;f.includes("// @filename: ")?(s.push([r+i,o]),i=f.split("// @filename: ")[1].trim(),o=[]):o.push(f)}return s.push([r+i,o]),s.filter((function(e){return e[1].length>0&&(e[1].length>1||""!==e[1][0])}))}(r,x,P),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");A.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=A.getSourceFile(r),s=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=O.getQuickInfoAtPosition(r,s),l=O.getDefinitionAtPosition(r,s),c="Could not get LSP result: "+[(n=A.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(""),u=void 0;return a&&l&&a.displayParts&&(c=a.displayParts.map((function(e){return e.text})).join(""),u=a.documentation?a.documentation.map((function(e){return e.text})).join("<br/>"):void 0),{kind:"query",text:c,docs:u,line:e.line-t,offset:e.offset,file:r};case"completion":var f=O.getCompletionsAtPosition(r,s-1,{});if(!f&&!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==f?void 0:f.entries)||[],completionPrefix:d,line:e.line-t,offset:e.offset,file:r}}}));(t=C).push.apply(t,c);var u=n.join("\n");A.updateFile(r,u)},$=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)&&O.getEmitOutput(e).outputFiles.forEach((function(e){F.writeFile(e.name,e.text)}))}));var V=[],G=[];M.forEach((function(e){var t=e.split(".").pop()||"";if(I.includes(t)){E.noErrors||(V.push.apply(V,O.getSemanticDiagnostics(e)),V.push.apply(V,O.getSyntacticDiagnostics(e)));var n=A.sys.readFile(e),i=A.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 u;if(l){if(c>=a.length)break;u=a[c++]}else{if((c=a.next()).done)break;u=c.value}var f=u,p=f.span,d=O.getQuickInfoAtPosition(e,p.start);if(d&&d.displayParts){var g=d.displayParts.map((function(e){return e.text})).join(""),v=f.text,m=d.documentation?d.documentation.map((function(e){return e.text})).join("\n"):void 0,x=p.start+o,y=h.createSourceFile("_.ts",r,h.ScriptTarget.ES2015),w=h.getLineAndCharacterOfPosition(y,x);G.push({text:g,docs:m,start:x,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 J=V.filter((function(e){return e.file&&M.includes(e.file.fileName)}));!E.noErrorValidation&&J.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'''")}}(J,E,n,v);var Q=[],_=J,z=Array.isArray(_),Y=0;for(_=z?_:_[Symbol.iterator]();;){var H;if(z){if(Y>=_.length)break;H=_[Y++]}else{if((Y=_.next()).done)break;H=Y.value}var K=H,W=A.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);Q.push({category:K.category,code:K.code,length:K.length,start:K.start?K.start+X:void 0,line:te.line,character:te.character,renderedMessage:Z,id:ee})}if(E.showEmit){var re=E.showEmittedFile||x,ne=P+re.replace(".jsx","").replace(".js","").replace(".d.ts","").replace(".map",""),ie=M.find((function(e){return e===ne+".ts"||e===ne+".tsx"}));if(!ie&&!b.outFile){var oe=M.join(", ");throw new Error("Cannot find the corresponding **source** file for "+re+" (looking for: "+ne+" in the vfs) - in "+oe)}b.outFile&&(ie=M[0]);var se=O.getEmitOutput(ie),ae=se.outputFiles.find((function(e){return e.name===P+E.showEmittedFile||e.name===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: "+(P+E.showEmittedFile)+" in the vfs) - in "+le)}r=ae.text,n=ae.name.split(".").pop(),q=[],C=[],G=[]}var ce="https://www.typescriptlang.org/play/#code/"+g.compressToEncodedURIComponent(v),ue="// ---cut---\n";if(r.includes(ue)){var fe=r.indexOf(ue)+ue.length,pe=r.substr(0,fe).split("\n").length-1;r=r.split(ue).pop(),G.forEach((function(e){e.start-=fe,e.line-=pe})),G=G.filter((function(e){return e.start>-1})),Q.forEach((function(e){e.start&&(e.start-=fe),e.line&&(e.line-=pe)})),Q=Q.filter((function(e){return e.start&&e.start>-1})),q.forEach((function(e){e.position-=fe,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:G,errors:Q,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("^"),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: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,r){var n=r.get(t.toLowerCase());if(o("Get "+e+" mapped option: "+t+" => "+n),void 0===n){var i=Array.from(r.keys());throw new Error("Invalid value "+t+" for "+e+". Allowed values: "+i.join(","))}return n}function l(e,t,n,i){o("Setting "+e+" to "+t);var s=function(){if(c){if(f>=l.length)return"break";u=l[f++]}else{if((f=l.next()).done)return"break";u=f.value}var i=u;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":var o=i.element.type,s=t.split(",");n[i.name]=s.map("string"==typeof o?function(e){return r(e,o)}:function(e){return a(i.name,e,o)});break;default:n[i.name]=a(i.name,t,i.type)}return{v:void 0}}},l=i.optionDeclarations,c=Array.isArray(l),f=0;for(l=c?l:l[Symbol.iterator]();;){var u,p=s();if("break"===p)break;if("object"==typeof p)return p.v}throw new Error("No compiler setting named '"+e+"' exists!")}var c=/^\/\/\s?@(\w+)$/,f=/^\/\/\s?@(\w+):\s?(.+)$/,u={errors:[],noErrors:!1,showEmit:!1,showEmittedFile:void 0,noStaticSemanticInfo:!1,emit:!1,noErrorValidation:!1};exports.twoslasher=function(r,n,i){var a,p,d;void 0===i&&(i={});var h=null!=(a=i.tsModule)?a:require("typescript"),g=null!=(p=i.lzstringModule)?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),x="index."+m;o("\n\nLooking at code: \n```"+m+"\n"+r+"\n```\n");var y=t({strict:!0,target:h.ScriptTarget.ES2016,allowJs:!0},null!=(d=i.defaultCompilerOptions)?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({},u),n=0;n<e.length;n++){var i=void 0;(i=c.exec(e[n]))?i[1]in r&&(r[i[1]]=!0,o("Setting options."+i[1]+" to true"),e.splice(n,1),n--):(i=f.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=c.exec(e[o]))i[s[1]]=!0,l(s[1],"true",i,n);else{if(!(s=f.exec(e[o]))){o++;continue}if("filename"===s[1]){o++;continue}l(s[1],s[2],i,n)}e.splice(o,1)}return i}(w,y,h);E.showEmittedFile||(E.showEmittedFile=b.jsx&&b.jsx===h.JsxEmit.Preserve?"index.jsx":"index.js");var 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,F=k?e.createSystem(j):e.createFSBackedSystem(j,S(),h),P=k?"/":S()+"/",A=e.createVirtualTypeScriptEnvironment(F,[],h,b,i.customTransformers),O=A.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,x,P),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");A.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=A.getSourceFile(r),s=h.getPositionOfLineAndCharacter(o,e.line,e.offset);switch(e.kind){case"query":var a=O.getQuickInfoAtPosition(r,s),l=O.getDefinitionAtPosition(r,s),c="Could not get LSP result: "+[(n=A.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=O.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");A.updateFile(r,f)},$=L,N=Array.isArray($),U=0;for($=N?$:$[Symbol.iterator]();;){var B;if("break"===D())break}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)&&O.getEmitOutput(e).outputFiles.forEach((function(e){F.writeFile(e.name,e.text)}))}));var V=[],G=[];M.forEach((function(e){var t=e.split(".").pop()||"";if(I.includes(t)){E.noErrors||(V.push.apply(V,O.getSemanticDiagnostics(e)),V.push.apply(V,O.getSyntacticDiagnostics(e)));var n=A.sys.readFile(e),i=A.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=O.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,x=p.start+o,y=h.createSourceFile("_.ts",r,h.ScriptTarget.ES2015),w=h.getLineAndCharacterOfPosition(y,x);G.push({text:g,docs:m,start:x,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 J=V.filter((function(e){return e.file&&M.includes(e.file.fileName)}));!E.noErrorValidation&&J.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'''")}}(J,E,n,v);var Q=[],_=J,z=Array.isArray(_),Y=0;for(_=z?_:_[Symbol.iterator]();;){var H;if(z){if(Y>=_.length)break;H=_[Y++]}else{if((Y=_.next()).done)break;H=Y.value}var K=H,W=A.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);Q.push({category:K.category,code:K.code,length:K.length,start:K.start?K.start+X:void 0,line:te.line,character:te.character,renderedMessage:Z,id:ee})}if(E.showEmit){var re=E.showEmittedFile||x,ne=P+re.replace(".jsx","").replace(".js","").replace(".d.ts","").replace(".map",""),ie=M.find((function(e){return e===ne+".ts"||e===ne+".tsx"}));if(!ie&&!b.outFile){var oe=M.join(", ");throw new Error("Cannot find the corresponding **source** file for "+re+" (looking for: "+ne+" in the vfs) - in "+oe)}b.outFile&&(ie=M[0]);var se=O.getEmitOutput(ie),ae=se.outputFiles.find((function(e){return e.name===P+E.showEmittedFile||e.name===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: "+(P+E.showEmittedFile)+" in the vfs) - in "+le)}r=ae.text,n=ae.name.split(".").pop(),q=[],C=[],G=[]}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(),G.forEach((function(e){e.start-=ue,e.line-=pe})),G=G.filter((function(e){return e.start>-1})),Q.forEach((function(e){e.start&&(e.start-=ue),e.line&&(e.line-=pe)})),Q=Q.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:G,errors:Q,playgroundURL:ce}}; | ||
//# sourceMappingURL=twoslash.cjs.production.min.js.map |
@@ -264,3 +264,3 @@ import { createSystem, createFSBackedSystem, createVirtualTypeScriptEnvironment } from '@typescript/vfs'; | ||
var _loop3 = function _loop3() { | ||
var _loop2 = function _loop2() { | ||
if (_isArray) { | ||
@@ -314,14 +314,9 @@ if (_i2 >= _iterator.length) return "break"; | ||
_loop2: for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _ret = _loop3(); | ||
var _ret = _loop2(); | ||
switch (_ret) { | ||
case "break": | ||
break _loop2; | ||
default: | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
if (_ret === "break") break; | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
@@ -424,4 +419,4 @@ | ||
var ts = (_options$tsModule = options.tsModule) !== null && _options$tsModule !== void 0 ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) !== null && _options$lzstringModu !== void 0 ? _options$lzstringModu : require("lz-string"); | ||
var ts = (_options$tsModule = options.tsModule) != null ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) != null ? _options$lzstringModu : require("lz-string"); | ||
var originalCode = code; | ||
@@ -436,3 +431,3 @@ var safeExtension = typesToExtension(extension); | ||
allowJs: true | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) !== null && _options$defaultCompi !== void 0 ? _options$defaultCompi : {}); | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) != null ? _options$defaultCompi : {}); | ||
@@ -444,3 +439,3 @@ validateInput(code); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), {}, options.defaultOptions); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), options.defaultOptions); | ||
@@ -479,3 +474,3 @@ var compilerOptions = filterCompilerOptions(codeLines, defaultCompilerOptions, ts); // Handle special casing the lookup for when using jsx preserve which creates .jsx files | ||
var _loop5 = function _loop5() { | ||
var _loop3 = function _loop3() { | ||
var _highlights, _partialQueries; | ||
@@ -557,3 +552,3 @@ | ||
kind: "completions", | ||
completions: (_quickInfo === null || _quickInfo === void 0 ? void 0 : _quickInfo.entries) || [], | ||
completions: (_quickInfo == null ? void 0 : _quickInfo.entries) || [], | ||
completionPrefix: lastDot, | ||
@@ -576,14 +571,9 @@ line: q.line - i, | ||
_loop4: for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _ret2 = _loop5(); | ||
var _ret2 = _loop3(); | ||
switch (_ret2) { | ||
case "break": | ||
break _loop4; | ||
case "continue": | ||
continue; | ||
} | ||
if (_ret2 === "break") break; | ||
if (_ret2 === "continue") continue; | ||
} // We need to also strip the highlights + queries from the main file which is shown to people | ||
@@ -590,0 +580,0 @@ |
@@ -274,3 +274,3 @@ | ||
var _loop3 = function _loop3() { | ||
var _loop2 = function _loop2() { | ||
if (_isArray) { | ||
@@ -324,14 +324,9 @@ if (_i2 >= _iterator.length) return "break"; | ||
_loop2: for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = ts.optionDeclarations, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _ret = _loop3(); | ||
var _ret = _loop2(); | ||
switch (_ret) { | ||
case "break": | ||
break _loop2; | ||
default: | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
if (_ret === "break") break; | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
@@ -434,4 +429,4 @@ | ||
var ts = (_options$tsModule = options.tsModule) !== null && _options$tsModule !== void 0 ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) !== null && _options$lzstringModu !== void 0 ? _options$lzstringModu : require("lz-string"); | ||
var ts = (_options$tsModule = options.tsModule) != null ? _options$tsModule : require("typescript"); | ||
var lzstring = (_options$lzstringModu = options.lzstringModule) != null ? _options$lzstringModu : require("lz-string"); | ||
var originalCode = code; | ||
@@ -446,3 +441,3 @@ var safeExtension = typesToExtension(extension); | ||
allowJs: true | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) !== null && _options$defaultCompi !== void 0 ? _options$defaultCompi : {}); | ||
}, (_options$defaultCompi = options.defaultCompilerOptions) != null ? _options$defaultCompi : {}); | ||
@@ -454,3 +449,3 @@ validateInput(code); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), {}, options.defaultOptions); | ||
var handbookOptions = _extends({}, filterHandbookOptions(codeLines), options.defaultOptions); | ||
@@ -489,3 +484,3 @@ var compilerOptions = filterCompilerOptions(codeLines, defaultCompilerOptions, ts); // Handle special casing the lookup for when using jsx preserve which creates .jsx files | ||
var _loop5 = function _loop5() { | ||
var _loop3 = function _loop3() { | ||
var _highlights, _partialQueries; | ||
@@ -567,3 +562,3 @@ | ||
kind: "completions", | ||
completions: (_quickInfo === null || _quickInfo === void 0 ? void 0 : _quickInfo.entries) || [], | ||
completions: (_quickInfo == null ? void 0 : _quickInfo.entries) || [], | ||
completionPrefix: lastDot, | ||
@@ -586,14 +581,9 @@ line: q.line - i, | ||
_loop4: for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
for (var _iterator2 = nameContent, _isArray2 = Array.isArray(_iterator2), _i5 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
var _ret2 = _loop5(); | ||
var _ret2 = _loop3(); | ||
switch (_ret2) { | ||
case "break": | ||
break _loop4; | ||
case "continue": | ||
continue; | ||
} | ||
if (_ret2 === "break") break; | ||
if (_ret2 === "continue") continue; | ||
} // We need to also strip the highlights + queries from the main file which is shown to people | ||
@@ -600,0 +590,0 @@ |
{ | ||
"name": "@typescript/twoslash", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"license": "MIT", | ||
"author": "TypeScript team", | ||
"homepage": "https://github.com/microsoft/TypeScript-Website", | ||
"repository": { | ||
"url": "https://github.com/microsoft/TypeScript-Website.git", | ||
"directory": "packages/create-typescript-playground-plugin", | ||
"type": "git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/microsoft/TypeScript-Website/issues" | ||
}, | ||
"main": "dist/index.js", | ||
@@ -29,3 +38,3 @@ "module": "dist/twoslash.esm.js", | ||
"prettier": "*", | ||
"tsdx": "^0.12.3", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^1.10.0", | ||
@@ -45,3 +54,3 @@ "typescript": "*" | ||
"dependencies": { | ||
"@typescript/vfs": "1.3.0", | ||
"@typescript/vfs": "1.3.2", | ||
"debug": "^4.1.1", | ||
@@ -48,0 +57,0 @@ "lz-string": "^1.4.4" |
@@ -9,3 +9,3 @@ # TypeScript TwoSlash | ||
You can preview twoslash on the TypeScript website here: https://typescriptlang.org/dev/twoslash | ||
You can preview twoslash on the TypeScript website here: https://www.typescriptlang.org/dev/twoslash/ | ||
@@ -714,10 +714,10 @@ ### What is Twoslash? | ||
> } | ||
> var __spread = | ||
> (this && this.__spread) || | ||
> function () { | ||
> for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])) | ||
> return ar | ||
> var __spreadArray = | ||
> (this && this.__spreadArray) || | ||
> function (to, from) { | ||
> for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i] | ||
> return to | ||
> } | ||
> export function fn(arr) { | ||
> var arr2 = __spread([1], arr) | ||
> var arr2 = __spreadArray([1], __read(arr)) | ||
> } | ||
@@ -724,0 +724,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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
302237
0
1
5
15
2346
+ Added@typescript/vfs@1.3.2(transitive)
- Removed@typescript/vfs@1.3.0(transitive)
Updated@typescript/vfs@1.3.2