diff --git a/README.md b/README.md index 8a7fc6ac6e9e..c88f4532d909 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,11 @@ code . Working on this repo is done by running `yarn start` - this starts up the website on port `8000` and creates a builder worker for every package in the repo, so if you make a change outside of the site it will compile and lint etc. +Some useful knowledge: + +- All packages have: `yarn bootstrap`, `yarn build` and `yarn test` +- All packages use [debug](https://www.npmjs.com/package/debug) - which means you can do `env DEBUG="*" yarn test` to get verbose logs + # Website Packages ## TypeScriptLang-Org @@ -71,33 +76,23 @@ The code samples used in the Playground # Infra Packages -## TS Twoslasher +All of these packages use [`tsdx`](https://github.com/jaredpalmer/tsdx). -A code sample markup extension for TypeScript. - -```sh -# Tests -yarn workspace ts-twoslasher test +## TS Twoslash -# Build -yarn workspace ts-twoslasher build -``` +A code sample markup extension for TypeScript. ## Gatsby Remark Twoslasher Code Blocks -A Gasby Remark plugin which runs twoslash for any code blocks with twoslash in their metadata +A Gatsby Remark plugin which runs twoslash for any code blocks with twoslash in their metadata ## Gatsby Remark Shiki -A Gasby Remark plugin which highlights code (using vscode's parsers) then annotates the code with twoslash information +A Gatsby Remark plugin which highlights code (using vscode's parsers) then annotates the code with twoslash information -```sh -# Tests -yarn workspace gatsby-remark-shiki test +## TypeScript VFS -# Build -yarn workspace gatsby-remark-shiki build -``` +A comprehensive way to run TypeScript projects in-memory in a browser or node environment # Contributing diff --git a/packages/gatsby-remark-shiki/src/renderer.ts b/packages/gatsby-remark-shiki/src/renderer.ts index 6296d6f7baf5..63367a478b6e 100644 --- a/packages/gatsby-remark-shiki/src/renderer.ts +++ b/packages/gatsby-remark-shiki/src/renderer.ts @@ -28,9 +28,12 @@ export function renderToHTML(lines: Lines, options: Options, twoslash?: TwoSlash const lspValues = staticQuickInfosGroupedByLine.get(i) || [] const queries = queriesGroupedByLine.get(i) || [] - if (l.length === 0) { - html += `\n` + if (l.length === 0 && i === 0) { + // Skip the first newline if it's blank + filePos += 1 + } else if (l.length === 0) { filePos += 1 + html += `\n` } else { // Keep track of the position of the current token in a line so we can match it up to the // errors and lang serv identifiers @@ -41,10 +44,10 @@ export function renderToHTML(lines: Lines, options: Options, twoslash?: TwoSlash // console.log(tokenPos, token.content.length, filePos) // Underlining particular words const findTokenFunc = (start: number) => (e: any) => - start <= e.character && start + token.content.length <= e.character + e.length + start <= e.character && start + token.content.length >= e.character + e.length const findTokenDebug = (start: number) => (e: any) => { - const result = start <= e.character && start + token.content.length <= e.character + e.length + const result = start <= e.character && start + token.content.length >= e.character + e.length // prettier-ignore console.log(result, start, '<=', e.character, '&&', start + token.content.length, '<=', e.character + e.length) return result @@ -55,6 +58,7 @@ export function renderToHTML(lines: Lines, options: Options, twoslash?: TwoSlash const queriesInToken = queries.filter(findTokenFunc(tokenPos)) const allTokensByStart = [...errorsInToken, ...lspResponsesInToken, ...queriesInToken] + if (allTokensByStart.length) { const ranges = allTokensByStart.map(token => { const range: any = { diff --git a/packages/gatsby-remark-shiki/test/results/exporting.html b/packages/gatsby-remark-shiki/test/results/exporting.html index 3874dba9ea08..13720ad6e0c4 100644 --- a/packages/gatsby-remark-shiki/test/results/exporting.html +++ b/packages/gatsby-remark-shiki/test/results/exporting.html @@ -2,8 +2,8 @@
ts// @filename: utilFunctions.js -Module '"utilFunctions"' can only be default-imported using the 'allowSyntheticDefaultImports' flag1259Module '"utilFunctions"' can only be default-imported using the 'allowSyntheticDefaultImports' flagconst getStringLength = str => str.length -modulemodule export= (property) export=: { getStringLength: (str: any) => any; }.module export= (property) export=: { getStringLength: (str: any) => any; }exports = { +const getStringLength = str => str.length +module.exports = { getStringLength, } diff --git a/packages/gatsby-remark-shiki/test/results/exporting.json b/packages/gatsby-remark-shiki/test/results/exporting.json index a8497dd79c4d..25ff2657f4e4 100644 --- a/packages/gatsby-remark-shiki/test/results/exporting.json +++ b/packages/gatsby-remark-shiki/test/results/exporting.json @@ -5,41 +5,6 @@ "highlights": [], "queries": [], "staticQuickInfos": [ - { - "text": "import utils", - "docs": "", - "start": 144, - "length": 5, - "line": 1, - "character": 108, - "targetString": "utils" - }, - { - "text": "const count: any", - "docs": "", - "start": 179, - "length": 5, - "line": 1, - "character": 143, - "targetString": "count" - }, - { - "text": "import utils", - "docs": "", - "start": 187, - "length": 5, - "line": 1, - "character": 151, - "targetString": "utils" - }, - { - "text": "any", - "start": 193, - "length": 15, - "line": 1, - "character": 157, - "targetString": "getStringLength" - }, { "text": "const getStringLength: (str: any) => any", "docs": "", @@ -101,20 +66,45 @@ "line": 5, "character": 11, "targetString": "getStringLength" - } - ], - "errors": [ + }, { - "category": 1, - "code": 1259, - "length": 5, + "text": "import utils", + "docs": "", "start": 144, - "line": 0, - "character": 7, - "renderedMessage": "Module '\"utilFunctions\"' can only be default-imported using the 'allowSyntheticDefaultImports' flag", - "id": "err-1259-7-5" + "length": 5, + "line": 1, + "character": 108, + "targetString": "utils" + }, + { + "text": "const count: any", + "docs": "", + "start": 179, + "length": 5, + "line": 1, + "character": 143, + "targetString": "count" + }, + { + "text": "import utils", + "docs": "", + "start": 187, + "length": 5, + "line": 1, + "character": 151, + "targetString": "utils" + }, + { + "text": "(property) getStringLength: (str: any) => any", + "docs": "", + "start": 193, + "length": 15, + "line": 1, + "character": 157, + "targetString": "getStringLength" } ], - "playgroundURL": "https://www.typescriptlang.org/play/#code/PTAEAEDMEsBsFMB2BDAtvAXKArgFzgGLaIDG+A9ogM4B0AVlQFAmVW6gDm8uAyrgE7REHADJIOuABagAvKDb9ZAPnkCaCYVMapyAE2wIa8AB4AHcv1xVZoAN6NQnbn0HCxmyQBpGAX0aMQCBgNNExQIV0TGitGaFRzSxx8WGtIfnJUUAByGmA8QmIyaFYs5lZ2FmJ2OXyUmi5eASFRcSkACiyAYUl4EgBrUAApHiyASiA" + "errors": [], + "playgroundURL": "https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygIwCYCsBOAUCBAGYCWANpAHYCGAtpKgK4Au5AYo5QMatyWIA6AFaI8XPomagA5pGYBlZtBKVpAGSrTmAC1ABeUJOj6AfIaUCKqnXlpwAJowoDIADwAOCZon2gA3nigMnKKyqoa1toANHgAvngEYOCkVnQMoCr2bgLeeCS0ntBSLOQ+RPC0oADkAsAlZBzcvPxVYhJS4pxSBvWCsgpKKuqaOgAUVQDC2pBcANagAFLyVQCUQA" } ] diff --git a/packages/gatsby-remark-shiki/test/results/one.html b/packages/gatsby-remark-shiki/test/results/one.html index f3606a778fd0..d670bf26c06b 100644 --- a/packages/gatsby-remark-shiki/test/results/one.html +++ b/packages/gatsby-remark-shiki/test/results/one.html @@ -1,7 +1,7 @@
One liner with multiple IDs
+>tsconst getStringLengthconst getStringLength: (str: string) => number = (str(parameter) str: string: string) => str(parameter) str: string.length(property) String.length: number
tsconst getStringLengthconst getStringLength: (str: string) => number = (str(parameter) str: string: string) => str(parameter) str: string.length(property) String.length: number