From 2b9439c6ca130d32540fe8a665d06e53bb82ceb7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Jul 2025 10:23:16 -0700 Subject: [PATCH 1/8] Update for TS7 I am testing Typescript 7's JS support, which I've largely rewritten during the switch to Go. The new code doesn't support old, Closure-derived syntax, such as uninitialised class property declarations, which VFileMessage uses. I made the smallest syntactic change to fix this, which is to initialise all the optional properties declared this way with `undefined`. The other two ways I thought of are: 1. Declare these properties as class properties in the body of the class. This splits the properties up in a non-obvious way though. 2. Declare an interface type in a separate .d.ts file and merge that with VFileMessage so Typescript thinks they are there without changing the runtime shape of VFileMessage. I can't think of the JS syntax to make this merge happen, though. Other options are: 3. Do nothing, don't update to TS7. 4. Switch to .ts, add a build step to strip types. I don't know how VFileMessage is used; having a consistent runtime shape by virtue of using class property declarations or initialising all properties to undefined generally means: faster performance, but more memory usage. I suspect it doesn't matter because people aren't creating millions of these objects per second, but I don't really know. Because TS7 is quite a way off, I don't know whether you'll want to take this PR. I created it to see how hard it would be to update popular JS code that uses TS for checking. --- lib/index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index c7676df..bcffea5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -158,7 +158,6 @@ export class VFileMessage extends Error { ? options.place.start : options.place - /* eslint-disable no-unused-expressions */ /** * Stack of ancestor nodes surrounding the message. * @@ -196,7 +195,7 @@ export class VFileMessage extends Error { * * @type {string | undefined} */ - this.file + this.file = undefined // Field from `Error`. /** @@ -274,21 +273,21 @@ export class VFileMessage extends Error { * * @type {string | undefined} */ - this.actual + this.actual = undefined /** * Suggest acceptable values that can be used instead of `actual`. * * @type {Array | undefined} */ - this.expected + this.expected = undefined /** * Long form description of the message (you should use markdown). * * @type {string | undefined} */ - this.note + this.note = undefined /** * Link to docs for the message. @@ -298,8 +297,7 @@ export class VFileMessage extends Error { * * @type {string | undefined} */ - this.url - /* eslint-enable no-unused-expressions */ + this.url = undefined } } From 6fcabaf799f83cd44a1546293d6df0b51cf6e276 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:32:37 -0700 Subject: [PATCH 2/8] Use interface merging to provide properties --- lib/index.js | 29 ----------------------------- tsconfig.json | 3 ++- tsconfig.tsbuildinfo | 1 + types.d.ts | 22 ++++++++++++++++++++++ 4 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 tsconfig.tsbuildinfo create mode 100644 types.d.ts diff --git a/lib/index.js b/lib/index.js index bcffea5..0bef7bf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -190,13 +190,6 @@ export class VFileMessage extends Error { */ this.fatal = undefined - /** - * Path of a file (used throughout the `VFile` ecosystem). - * - * @type {string | undefined} - */ - this.file = undefined - // Field from `Error`. /** * Reason for message. @@ -267,28 +260,6 @@ export class VFileMessage extends Error { // Not standard. // Feel free to add other non-standard fields to your messages. - /** - * Specify the source value that’s being reported, which is deemed - * incorrect. - * - * @type {string | undefined} - */ - this.actual = undefined - - /** - * Suggest acceptable values that can be used instead of `actual`. - * - * @type {Array | undefined} - */ - this.expected = undefined - - /** - * Long form description of the message (you should use markdown). - * - * @type {string | undefined} - */ - this.note = undefined - /** * Link to docs for the message. * diff --git a/tsconfig.json b/tsconfig.json index 82cc749..fba7f22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "checkJs": true, + "noEmit": true, "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, @@ -11,5 +12,5 @@ "target": "es2022" }, "exclude": ["coverage/", "node_modules/"], - "include": ["**/*.js"] + "include": ["**/*.js", "types.d.ts"] } diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo new file mode 100644 index 0000000..fa1a8ea --- /dev/null +++ b/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./index.js","./test.js","./lib/index.js","./types.d.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 0000000..f41f116 --- /dev/null +++ b/types.d.ts @@ -0,0 +1,22 @@ +interface Error { + /** + * Path of a file (used throughout the `VFile` ecosystem). + */ + file?: string + + /** + * Specify the source value that's being reported, which is deemed + * incorrect. + */ + actual?: unknown + + /** + * Suggest acceptable values that can be used instead of `actual`. + */ + expected?: unknown + + /** + * Long form description of the message (you should use markdown). + */ + note?: string +} From 47c5c01c898fd8c3555d4ffab06f4a6ed2b22a83 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:48:20 -0700 Subject: [PATCH 3/8] also move url --- lib/index.js | 14 -------------- types.d.ts | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0bef7bf..2eb3b19 100644 --- a/lib/index.js +++ b/lib/index.js @@ -255,20 +255,6 @@ export class VFileMessage extends Error { legacyCause && options.cause && typeof options.cause.stack === 'string' ? options.cause.stack : '' - - // The following fields are “well known”. - // Not standard. - // Feel free to add other non-standard fields to your messages. - - /** - * Link to docs for the message. - * - * > 👉 **Note**: this must be an absolute URL that can be passed as `x` - * > to `new URL(x)`. - * - * @type {string | undefined} - */ - this.url = undefined } } diff --git a/types.d.ts b/types.d.ts index f41f116..3250484 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,4 +1,7 @@ interface Error { + // The following fields are “well known”. + // Not standard. + // Feel free to add other non-standard fields to your messages. /** * Path of a file (used throughout the `VFile` ecosystem). */ @@ -19,4 +22,12 @@ interface Error { * Long form description of the message (you should use markdown). */ note?: string + + /** + * Link to docs for the message. + * + * > 👉 **Note**: this must be an absolute URL that can be passed as `x` + * > to `new URL(x)`. + */ + url?: string } From cfb75277168a0acf0a6dd1b15e3de0232b64e82e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:48:53 -0700 Subject: [PATCH 4/8] remove tsbuildinfo --- tsconfig.tsbuildinfo | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tsconfig.tsbuildinfo diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo deleted file mode 100644 index fa1a8ea..0000000 --- a/tsconfig.tsbuildinfo +++ /dev/null @@ -1 +0,0 @@ -{"root":["./index.js","./test.js","./lib/index.js","./types.d.ts"],"version":"5.8.3"} \ No newline at end of file From c31de17dc038fb19e4c94850d39269a74773df9a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Jul 2025 06:48:13 -0700 Subject: [PATCH 5/8] Revert "remove tsbuildinfo" This reverts commit cfb75277168a0acf0a6dd1b15e3de0232b64e82e. --- tsconfig.tsbuildinfo | 1 + 1 file changed, 1 insertion(+) create mode 100644 tsconfig.tsbuildinfo diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo new file mode 100644 index 0000000..fa1a8ea --- /dev/null +++ b/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./index.js","./test.js","./lib/index.js","./types.d.ts"],"version":"5.8.3"} \ No newline at end of file From b36a4b9aafdfd7d3486fe2c3f675b665a3d5c7f8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Jul 2025 06:48:31 -0700 Subject: [PATCH 6/8] Revert "also move url" This reverts commit 47c5c01c898fd8c3555d4ffab06f4a6ed2b22a83. --- lib/index.js | 14 ++++++++++++++ types.d.ts | 11 ----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/index.js b/lib/index.js index 2eb3b19..0bef7bf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -255,6 +255,20 @@ export class VFileMessage extends Error { legacyCause && options.cause && typeof options.cause.stack === 'string' ? options.cause.stack : '' + + // The following fields are “well known”. + // Not standard. + // Feel free to add other non-standard fields to your messages. + + /** + * Link to docs for the message. + * + * > 👉 **Note**: this must be an absolute URL that can be passed as `x` + * > to `new URL(x)`. + * + * @type {string | undefined} + */ + this.url = undefined } } diff --git a/types.d.ts b/types.d.ts index 3250484..f41f116 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,7 +1,4 @@ interface Error { - // The following fields are “well known”. - // Not standard. - // Feel free to add other non-standard fields to your messages. /** * Path of a file (used throughout the `VFile` ecosystem). */ @@ -22,12 +19,4 @@ interface Error { * Long form description of the message (you should use markdown). */ note?: string - - /** - * Link to docs for the message. - * - * > 👉 **Note**: this must be an absolute URL that can be passed as `x` - * > to `new URL(x)`. - */ - url?: string } From 0f7a65e839f3fea2873c0fb112c27ea332c36c56 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Jul 2025 06:48:43 -0700 Subject: [PATCH 7/8] Revert "Use interface merging to provide properties" This reverts commit 6fcabaf799f83cd44a1546293d6df0b51cf6e276. --- lib/index.js | 29 +++++++++++++++++++++++++++++ tsconfig.json | 3 +-- tsconfig.tsbuildinfo | 1 - types.d.ts | 22 ---------------------- 4 files changed, 30 insertions(+), 25 deletions(-) delete mode 100644 tsconfig.tsbuildinfo delete mode 100644 types.d.ts diff --git a/lib/index.js b/lib/index.js index 0bef7bf..bcffea5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -190,6 +190,13 @@ export class VFileMessage extends Error { */ this.fatal = undefined + /** + * Path of a file (used throughout the `VFile` ecosystem). + * + * @type {string | undefined} + */ + this.file = undefined + // Field from `Error`. /** * Reason for message. @@ -260,6 +267,28 @@ export class VFileMessage extends Error { // Not standard. // Feel free to add other non-standard fields to your messages. + /** + * Specify the source value that’s being reported, which is deemed + * incorrect. + * + * @type {string | undefined} + */ + this.actual = undefined + + /** + * Suggest acceptable values that can be used instead of `actual`. + * + * @type {Array | undefined} + */ + this.expected = undefined + + /** + * Long form description of the message (you should use markdown). + * + * @type {string | undefined} + */ + this.note = undefined + /** * Link to docs for the message. * diff --git a/tsconfig.json b/tsconfig.json index fba7f22..82cc749 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "compilerOptions": { "checkJs": true, - "noEmit": true, "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, @@ -12,5 +11,5 @@ "target": "es2022" }, "exclude": ["coverage/", "node_modules/"], - "include": ["**/*.js", "types.d.ts"] + "include": ["**/*.js"] } diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo deleted file mode 100644 index fa1a8ea..0000000 --- a/tsconfig.tsbuildinfo +++ /dev/null @@ -1 +0,0 @@ -{"root":["./index.js","./test.js","./lib/index.js","./types.d.ts"],"version":"5.8.3"} \ No newline at end of file diff --git a/types.d.ts b/types.d.ts deleted file mode 100644 index f41f116..0000000 --- a/types.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -interface Error { - /** - * Path of a file (used throughout the `VFile` ecosystem). - */ - file?: string - - /** - * Specify the source value that's being reported, which is deemed - * incorrect. - */ - actual?: unknown - - /** - * Suggest acceptable values that can be used instead of `actual`. - */ - expected?: unknown - - /** - * Long form description of the message (you should use markdown). - */ - note?: string -} From 62e8a8b32924416c191ac049ca29d98f63c56950 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 24 Jul 2025 06:51:44 -0700 Subject: [PATCH 8/8] correct default value for VFileMessage.file --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index bcffea5..e6b54a3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -195,7 +195,7 @@ export class VFileMessage extends Error { * * @type {string | undefined} */ - this.file = undefined + this.file = '' // Field from `Error`. /**