From bbf4d10ee20a041192e06cccac8212c517785995 Mon Sep 17 00:00:00 2001 From: tgreyuk Date: Mon, 6 May 2024 23:36:04 +0100 Subject: [PATCH] fix(core): escape symbols signatures correctly --- package-lock.json | 26 ++--- .../src/libs/utils/escape-chars.ts | 2 + .../test/fixtures/src/reflections/classes.ts | 7 ++ .../__snapshots__/navigation.spec.ts.snap | 5 + .../objects-and-params.spec.ts.snap | 6 +- .../reflection.class.spec.ts.snap | 107 ++++++++++++------ .../reflection.variable.spec.ts.snap | 4 +- .../specs/__snapshots__/urls.spec.ts.snap | 2 + .../test/specs/reflection.class.spec.ts | 9 ++ 9 files changed, 118 insertions(+), 50 deletions(-) diff --git a/package-lock.json b/package-lock.json index 31154fc32..560e4bd92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23432,49 +23432,49 @@ } }, "packages/docusaurus-plugin-typedoc": { - "version": "1.0.0-next.30", + "version": "1.0.0", "license": "MIT", "devDependencies": { "@docusaurus/core": "^3.2.1", "@docusaurus/types": "^3.2.1" }, "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.45" + "typedoc-plugin-markdown": ">=4.0.0" } }, "packages/typedoc-github-wiki-theme": { - "version": "2.0.0-next.9", + "version": "2.0.0", "license": "MIT", "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.51" + "typedoc-plugin-markdown": ">=4.0.0" } }, "packages/typedoc-gitlab-wiki-theme": { - "version": "2.0.0-next.8", + "version": "2.0.0", "license": "MIT", "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.51" + "typedoc-plugin-markdown": ">=4.0.0" } }, "packages/typedoc-plugin-frontmatter": { - "version": "1.0.0-next.1", + "version": "1.0.0", "license": "MIT", "dependencies": { "yaml": "^2.3.4" }, "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.54" + "typedoc-plugin-markdown": ">=4.0.0" } }, "packages/typedoc-plugin-markdown": { - "version": "4.0.0-next.59", + "version": "4.0.0", "license": "MIT", "peerDependencies": { "typedoc": "0.25.x" } }, "packages/typedoc-plugin-remark": { - "version": "1.0.0-next.4", + "version": "1.0.0", "license": "MIT", "dependencies": { "remark": "^15.0.1", @@ -23483,14 +23483,14 @@ "to-vfile": "^8.0.0" }, "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.40" + "typedoc-plugin-markdown": ">=4.0.0" } }, "packages/typedoc-vitepress-theme": { - "version": "1.0.0-next.11", + "version": "1.0.0", "license": "MIT", "peerDependencies": { - "typedoc-plugin-markdown": ">=4.0.0-next.51" + "typedoc-plugin-markdown": ">=4.0.0" } } } diff --git a/packages/typedoc-plugin-markdown/src/libs/utils/escape-chars.ts b/packages/typedoc-plugin-markdown/src/libs/utils/escape-chars.ts index 1e7c0b89e..757cada6d 100644 --- a/packages/typedoc-plugin-markdown/src/libs/utils/escape-chars.ts +++ b/packages/typedoc-plugin-markdown/src/libs/utils/escape-chars.ts @@ -7,5 +7,7 @@ export function escapeChars(str: string) { .replace(/_/g, '\\_') .replace(/`/g, '\\`') .replace(/\|/g, '\\|') + .replace(/\[/g, '\\[') + .replace(/\]/g, '\\]') .replace(/\*/g, '\\*'); } diff --git a/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts b/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts index 778bf2d9d..3053d1fb3 100644 --- a/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts +++ b/packages/typedoc-plugin-markdown/test/fixtures/src/reflections/classes.ts @@ -101,6 +101,13 @@ export class DerivedClassB extends AbstractClass { } } +const symbolConst: unique symbol = Symbol('SomeSymbol'); + +export class ClassWithSymbols { + [Symbol.dispose]() {} + public static [symbolConst]?: () => void; +} + export class DisposableClass implements Disposable { [Symbol.dispose]() {} } diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap index e2a3f983e..343bb1586 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap @@ -2730,6 +2730,11 @@ exports[`Navigation should gets Navigation Json for single entry point: (Output "kind": 128, "path": "classes/ClassWithSimpleProps.md" }, + { + "title": "ClassWithSymbols", + "kind": 128, + "path": "classes/ClassWithSymbols.md" + }, { "title": "ClassWithTypeParameters", "kind": 128, diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap index 858ba0882..cf501c5a6 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/objects-and-params.spec.ts.snap @@ -763,9 +763,9 @@ Comments variable with symbol ## Type declaration -### [sym] +### \\[sym\\] -> **[sym]**: \`string\` = \`'value'\` +> **\\[sym\\]**: \`string\` = \`'value'\` Comments for symbol " @@ -784,7 +784,7 @@ Comments variable with symbol ## Type declaration -### [sym] +### \\[sym\\] \`\`\`ts [sym]: string = 'value'; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap index 8cf938d4e..09ae63e5a 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.class.spec.ts.snap @@ -205,7 +205,7 @@ Comments for ClassWithAccessors #### Source -[classes.ts:139](http://source-url) +[classes.ts:146](http://source-url) ## Accessors @@ -231,7 +231,7 @@ Param comments #### Source -[classes.ts:143](http://source-url) +[classes.ts:150](http://source-url) *** @@ -245,7 +245,7 @@ Param comments #### Source -[classes.ts:159](http://source-url) +[classes.ts:166](http://source-url) *** @@ -259,7 +259,7 @@ Param comments #### Source -[classes.ts:155](http://source-url) +[classes.ts:162](http://source-url) " `; @@ -314,7 +314,7 @@ Comments for setter #### Source -[classes.ts:143](http://source-url) +[classes.ts:150](http://source-url) *** @@ -332,7 +332,7 @@ set noGetter(x: string): void #### Source -[classes.ts:159](http://source-url) +[classes.ts:166](http://source-url) *** @@ -348,7 +348,7 @@ get noSetter(): string #### Source -[classes.ts:155](http://source-url) +[classes.ts:162](http://source-url) " `; @@ -451,7 +451,7 @@ Comments for x number #### Source -[classes.ts:117](http://source-url) +[classes.ts:124](http://source-url) ### new ClassWithConstructorOverloads() @@ -469,7 +469,7 @@ Comments for x string #### Source -[classes.ts:122](http://source-url) +[classes.ts:129](http://source-url) ### new ClassWithConstructorOverloads() @@ -485,7 +485,7 @@ Comments for x string #### Source -[classes.ts:123](http://source-url) +[classes.ts:130](http://source-url) " `; @@ -515,7 +515,7 @@ new ClassWithConstructorOverloads(x: number, y: string): ClassWithConstructorOve #### Source -[classes.ts:117](http://source-url) +[classes.ts:124](http://source-url) ### new ClassWithConstructorOverloads() @@ -535,7 +535,7 @@ new ClassWithConstructorOverloads(x: string): ClassWithConstructorOverloads #### Source -[classes.ts:122](http://source-url) +[classes.ts:129](http://source-url) ### new ClassWithConstructorOverloads() @@ -555,7 +555,7 @@ new ClassWithConstructorOverloads(s: string): ClassWithConstructorOverloads #### Source -[classes.ts:123](http://source-url) +[classes.ts:130](http://source-url) " `; @@ -584,7 +584,7 @@ Comment for ClassWithFlags #### Source -[classes.ts:218](http://source-url) +[classes.ts:225](http://source-url) *** @@ -596,7 +596,7 @@ Comment for ClassWithFlags #### Source -[classes.ts:220](http://source-url) +[classes.ts:227](http://source-url) ## Methods @@ -612,7 +612,7 @@ Comment for ClassWithFlags #### Source -[classes.ts:222](http://source-url) +[classes.ts:229](http://source-url) *** @@ -628,7 +628,7 @@ Comment for ClassWithFlags #### Source -[classes.ts:226](http://source-url) +[classes.ts:233](http://source-url) " `; @@ -672,7 +672,7 @@ expermintalMethod(): void #### Source -[classes.ts:222](http://source-url) +[classes.ts:229](http://source-url) *** @@ -690,7 +690,7 @@ protected internalMethod(): void #### Source -[classes.ts:226](http://source-url) +[classes.ts:233](http://source-url) " `; @@ -721,7 +721,7 @@ Comments for privateProp #### Source -[classes.ts:176](http://source-url) +[classes.ts:183](http://source-url) *** @@ -733,7 +733,7 @@ Comments for protectedProp #### Source -[classes.ts:186](http://source-url) +[classes.ts:193](http://source-url) *** @@ -745,7 +745,7 @@ Comments for propWithDefault #### Source -[classes.ts:191](http://source-url) +[classes.ts:198](http://source-url) *** @@ -757,7 +757,7 @@ Comments for abstractProperty #### Source -[classes.ts:181](http://source-url) +[classes.ts:188](http://source-url) *** @@ -769,7 +769,7 @@ Comments for staticProp #### Source -[classes.ts:171](http://source-url) +[classes.ts:178](http://source-url) ## Methods @@ -785,7 +785,7 @@ Comment for privateMethod #### Source -[classes.ts:203](http://source-url) +[classes.ts:210](http://source-url) *** @@ -801,7 +801,7 @@ Comment for publicMethod #### Source -[classes.ts:196](http://source-url) +[classes.ts:203](http://source-url) *** @@ -817,7 +817,7 @@ Comment for staticMethod #### Source -[classes.ts:208](http://source-url) +[classes.ts:215](http://source-url) " `; @@ -866,7 +866,7 @@ Comment for privateMethod #### Source -[classes.ts:203](http://source-url) +[classes.ts:210](http://source-url) *** @@ -884,7 +884,7 @@ Comment for publicMethod #### Source -[classes.ts:196](http://source-url) +[classes.ts:203](http://source-url) *** @@ -902,7 +902,7 @@ Comment for staticMethod #### Source -[classes.ts:208](http://source-url) +[classes.ts:215](http://source-url) " `; @@ -1016,6 +1016,49 @@ new ClassWithSimpleProps(): ClassWithSimpleProps " `; +exports[`Class Reflection should compile class with symbols: (Output File Strategy "members") (Option Group "1") 1`] = ` +"# Class: ClassWithSymbols + +## Constructors + +### new ClassWithSymbols() + +> **new ClassWithSymbols**(): [\`ClassWithSymbols\`](ClassWithSymbols.md) + +#### Returns + +[\`ClassWithSymbols\`](ClassWithSymbols.md) + +## Properties + +### \\[symbolConst\\]()? + +> \`static\` \`optional\` **\\[symbolConst\\]**: () => \`void\` + +#### Returns + +\`void\` + +#### Source + +[classes.ts:108](http://source-url) + +## Methods + +### \`[dispose]\`() + +> **\\[dispose\\]**(): \`void\` + +#### Returns + +\`void\` + +#### Source + +[classes.ts:107](http://source-url) +" +`; + exports[`Class Reflection should compile class with type parameters: (Output File Strategy "members") (Option Group "1") 1`] = ` "# Class: ClassWithTypeParameters\\ @@ -1250,7 +1293,7 @@ exports[`Class Reflection should compile disposable class: (Output File Strategy ### \`[dispose]\`() -> **[dispose]**(): \`void\` +> **\\[dispose\\]**(): \`void\` #### Returns @@ -1262,6 +1305,6 @@ exports[`Class Reflection should compile disposable class: (Output File Strategy #### Source -[classes.ts:105](http://source-url) +[classes.ts:112](http://source-url) " `; diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.variable.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.variable.spec.ts.snap index 4045d44fa..00596d1f5 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.variable.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/reflection.variable.spec.ts.snap @@ -9,9 +9,9 @@ Comments variable with symbol ## Type declaration -### [sym] +### \\[sym\\] -> **[sym]**: \`string\` = \`'value'\` +> **\\[sym\\]**: \`string\` = \`'value'\` Comments for symbol diff --git a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap index 87f3773c1..eac0afe40 100644 --- a/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap +++ b/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap @@ -504,6 +504,7 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb "classes/ClassWithFlags.md", "classes/ClassWithModifiers.md", "classes/ClassWithSimpleProps.md", + "classes/ClassWithSymbols.md", "classes/ClassWithTypeParameters.md", "classes/DerivedClassA.md", "classes/DerivedClassB.md", @@ -573,6 +574,7 @@ exports[`Urls should gets Urls for single entry points: outputFileStrategy: memb "classes/ClassWithFlags.md", "classes/ClassWithModifiers.md", "classes/ClassWithSimpleProps.md", + "classes/ClassWithSymbols.md", "classes/ClassWithTypeParameters.md", "classes/DerivedClassA.md", "classes/DerivedClassB.md", diff --git a/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts b/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts index db741e9e3..a2455ef08 100644 --- a/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts +++ b/packages/typedoc-plugin-markdown/test/specs/reflection.class.spec.ts @@ -73,4 +73,13 @@ describe(`Class Reflection`, () => { 1, ); }); + + test(`should compile class with symbols`, () => { + expectFileToEqual( + 'reflections', + 'members', + 'classes/ClassWithSymbols.md', + 1, + ); + }); });