| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,9 @@ SELECT * FROM authors | |||
| 7 | 7 | ORDER BY name; | |
| 8 | 8 | ||
| 9 | 9 | -- name: CreateAuthor :one | |
| 10 | + -- Create a new author. | ||
| 11 | + -- This is the second line.*/ | ||
| 12 | + --/This is the third line. | ||
| 10 | 13 | INSERT INTO authors ( | |
| 11 | 14 | name, bio | |
| 12 | 15 | ) VALUES ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,11 @@ export interface CreateAuthorRow { | |||
| 81 | 81 | bio: string | null; | |
| 82 | 82 | } | |
| 83 | 83 | ||
| 84 | + /** | ||
| 85 | + * Create a new author. | ||
| 86 | + * This is the second line.*\/ | ||
| 87 | + *\/This is the third line. | ||
| 88 | + */ | ||
| 84 | 89 | export async function createAuthor(client: Client, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> { | |
| 85 | 90 | const result = await client.query({ | |
| 86 | 91 | text: createAuthorQuery, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,11 @@ export interface CreateAuthorRow { | |||
| 69 | 69 | bio: string | null; | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + /** | ||
| 73 | + * Create a new author. | ||
| 74 | + * This is the second line.*\/ | ||
| 75 | + *\/This is the third line. | ||
| 76 | + */ | ||
| 72 | 77 | export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> { | |
| 73 | 78 | const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values(); | |
| 74 | 79 | if (rows.length !== 1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,11 @@ export interface CreateAuthorRow { | |||
| 81 | 81 | bio: string | null; | |
| 82 | 82 | } | |
| 83 | 83 | ||
| 84 | + /** | ||
| 85 | + * Create a new author. | ||
| 86 | + * This is the second line.*\/ | ||
| 87 | + *\/This is the third line. | ||
| 88 | + */ | ||
| 84 | 89 | export async function createAuthor(client: Client, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> { | |
| 85 | 90 | const result = await client.query({ | |
| 86 | 91 | text: createAuthorQuery, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,6 +69,11 @@ export interface CreateAuthorRow { | |||
| 69 | 69 | bio: string | null; | |
| 70 | 70 | } | |
| 71 | 71 | ||
| 72 | + /** | ||
| 73 | + * Create a new author. | ||
| 74 | + * This is the second line.*\/ | ||
| 75 | + *\/This is the third line. | ||
| 76 | + */ | ||
| 72 | 77 | export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<CreateAuthorRow | null> { | |
| 73 | 78 | const rows = await sql.unsafe(createAuthorQuery, [args.name, args.bio]).values(); | |
| 74 | 79 | if (rows.length !== 1) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,8 +4,8 @@ | |||
| 4 | 4 | // @ts-expect-error | |
| 5 | 5 | import { readFileSync, writeFileSync, STDIO } from "javy/fs"; | |
| 6 | 6 | import { | |
| 7 | + addSyntheticLeadingComment, | ||
| 7 | 8 | EmitHint, | |
| 8 | - FunctionDeclaration, | ||
| 9 | 9 | NewLineKind, | |
| 10 | 10 | TypeNode, | |
| 11 | 11 | ScriptKind, | |
@@ -161,38 +161,50 @@ ${query.text}` | |||
| 161 | 161 | switch (query.cmd) { | |
| 162 | 162 | case ":exec": { | |
| 163 | 163 | nodes.push( | |
| 164 | - driver.execDecl(lowerName, textName, argIface, query.params) | ||
| 164 | + withComment( | ||
| 165 | + driver.execDecl(lowerName, textName, argIface, query.params), | ||
| 166 | + query.comments | ||
| 167 | + ) | ||
| 165 | 168 | ); | |
| 166 | 169 | break; | |
| 167 | 170 | } | |
| 168 | 171 | case ":execlastid": { | |
| 169 | 172 | nodes.push( | |
| 170 | - driver.execlastidDecl(lowerName, textName, argIface, query.params) | ||
| 173 | + withComment( | ||
| 174 | + driver.execlastidDecl(lowerName, textName, argIface, query.params), | ||
| 175 | + query.comments | ||
| 176 | + ) | ||
| 171 | 177 | ); | |
| 172 | 178 | break; | |
| 173 | 179 | } | |
| 174 | 180 | case ":one": { | |
| 175 | 181 | nodes.push( | |
| 176 | - driver.oneDecl( | ||
| 177 | - lowerName, | ||
| 178 | - textName, | ||
| 179 | - argIface, | ||
| 180 | - returnIface ?? "void", | ||
| 181 | - query.params, | ||
| 182 | - query.columns | ||
| 182 | + withComment( | ||
| 183 | + driver.oneDecl( | ||
| 184 | + lowerName, | ||
| 185 | + textName, | ||
| 186 | + argIface, | ||
| 187 | + returnIface ?? "void", | ||
| 188 | + query.params, | ||
| 189 | + query.columns | ||
| 190 | + ), | ||
| 191 | + query.comments | ||
| 183 | 192 | ) | |
| 184 | 193 | ); | |
| 185 | 194 | break; | |
| 186 | 195 | } | |
| 187 | 196 | case ":many": { | |
| 188 | 197 | nodes.push( | |
| 189 | - driver.manyDecl( | ||
| 190 | - lowerName, | ||
| 191 | - textName, | ||
| 192 | - argIface, | ||
| 193 | - returnIface ?? "void", | ||
| 194 | - query.params, | ||
| 195 | - query.columns | ||
| 198 | + withComment( | ||
| 199 | + driver.manyDecl( | ||
| 200 | + lowerName, | ||
| 201 | + textName, | ||
| 202 | + argIface, | ||
| 203 | + returnIface ?? "void", | ||
| 204 | + query.params, | ||
| 205 | + query.columns | ||
| 206 | + ), | ||
| 207 | + query.comments, | ||
| 196 | 208 | ) | |
| 197 | 209 | ); | |
| 198 | 210 | break; | |
@@ -279,6 +291,31 @@ function rowDecl( | |||
| 279 | 291 | ); | |
| 280 | 292 | } | |
| 281 | 293 | ||
| 294 | + function withComment(node: Node, comments: string[]): Node { | ||
| 295 | + if (comments.length === 0) return node; | ||
| 296 | + const multilineCommentTerminator = /\*\//g; | ||
| 297 | + addSyntheticLeadingComment( | ||
| 298 | + node, | ||
| 299 | + SyntaxKind.MultiLineCommentTrivia, | ||
| 300 | + ( | ||
| 301 | + "*\n" + | ||
| 302 | + comments.map((line) => { | ||
| 303 | + if (line.startsWith("/")) { | ||
| 304 | + // Escape leading `*/` | ||
| 305 | + line = `\\${line}`; | ||
| 306 | + } | ||
| 307 | + // Escape `*/` in the middle | ||
| 308 | + line = line.replace(multilineCommentTerminator, "*\\/"); | ||
| 309 | + | ||
| 310 | + return ` *${line}`; | ||
| 311 | + }).join("\n") + | ||
| 312 | + "\n " | ||
| 313 | + ), | ||
| 314 | + true, | ||
| 315 | + ); | ||
| 316 | + return node; | ||
| 317 | + } | ||
| 318 | + | ||
| 282 | 319 | function printNode(nodes: Node[]): string { | |
| 283 | 320 | // https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#creating-and-printing-a-typescript-ast | |
| 284 | 321 | const resultFile = createSourceFile( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments