diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 57c7bf9aa8329..5cbb7d6553dc2 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1039,7 +1039,9 @@ export function isRecognizedTripleSlashComment(text: string, commentPos: number, const textSubStr = text.substring(commentPos, commentEnd); return fullTripleSlashReferencePathRegEx.test(textSubStr) || fullTripleSlashAMDReferencePathRegEx.test(textSubStr) || + fullTripleSlashAMDModuleRegEx.test(textSubStr) || fullTripleSlashReferenceTypeReferenceDirectiveRegEx.test(textSubStr) || + fullTripleSlashLibReferenceRegEx.test(textSubStr) || defaultLibReferenceRegEx.test(textSubStr) ? true : false; } @@ -2021,8 +2023,10 @@ export function getJSDocCommentRanges(node: Node, text: string) { /** @internal */ export const fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; const fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*/; +const fullTripleSlashLibReferenceRegEx = /^(\/\/\/\s*/; /** @internal */ export const fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*/; +const fullTripleSlashAMDModuleRegEx = /^\/\/\/\s*/; const defaultLibReferenceRegEx = /^(\/\/\/\s*/; /** @internal */ diff --git a/tests/baselines/reference/libReferenceDeclarationEmit.js b/tests/baselines/reference/libReferenceDeclarationEmit.js index 83082c3ee9898..2163c64449d3e 100644 --- a/tests/baselines/reference/libReferenceDeclarationEmit.js +++ b/tests/baselines/reference/libReferenceDeclarationEmit.js @@ -12,6 +12,7 @@ declare const elem: HTMLElement; //// [file1.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +/// //// [file2.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/libReferenceDeclarationEmitBundle.js b/tests/baselines/reference/libReferenceDeclarationEmitBundle.js index 03474372f874b..2332f58efe663 100644 --- a/tests/baselines/reference/libReferenceDeclarationEmitBundle.js +++ b/tests/baselines/reference/libReferenceDeclarationEmitBundle.js @@ -13,6 +13,7 @@ declare const elem: HTMLElement; define("file1", ["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); + /// }); define("file2", ["require", "exports"], function (require, exports) { "use strict"; diff --git a/tests/baselines/reference/libReferenceNoLib.js b/tests/baselines/reference/libReferenceNoLib.js index 7f48c71d46446..35e682f1ad4e7 100644 --- a/tests/baselines/reference/libReferenceNoLib.js +++ b/tests/baselines/reference/libReferenceNoLib.js @@ -25,6 +25,7 @@ export const elem: HTMLElement = { field: 'a' }; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.elem = void 0; +/// exports.elem = { field: 'a' }; diff --git a/tests/baselines/reference/libReferenceNoLibBundle.js b/tests/baselines/reference/libReferenceNoLibBundle.js index f62a90503f7b7..00aa696d8c6c7 100644 --- a/tests/baselines/reference/libReferenceNoLibBundle.js +++ b/tests/baselines/reference/libReferenceNoLibBundle.js @@ -25,6 +25,7 @@ define("file1", ["require", "exports"], function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.elem = void 0; + /// exports.elem = { field: 'a' }; }); diff --git a/tests/cases/fourslash/importNameCodeFix_tripleSlashOrdering.ts b/tests/cases/fourslash/importNameCodeFix_tripleSlashOrdering.ts new file mode 100644 index 0000000000000..e491d9dd89e9a --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFix_tripleSlashOrdering.ts @@ -0,0 +1,122 @@ +/// + +// repro from #52263 + +// @Filename: /tsconfig.json +////{ +//// "compilerOptions": { +//// "skipDefaultLibCheck": false +//// } +////} + +// @Filename: /a.ts +////export const x = 0; + +// @Filename: /b.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +// @Filename: /c.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +// @Filename: /d.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +// @Filename: /e.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +// @Filename: /f.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +// @Filename: /g.ts +////// some comment +//// +/////// +//// +////const y = x + 1; + +goTo.file("/b.ts"); +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]); + +goTo.file("/c.ts"); +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]); + +goTo.file("/d.ts"); +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]); + +goTo.file("/e.ts"); + +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]); + +goTo.file("/f.ts"); +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]); + +goTo.file("/g.ts"); +verify.importFixAtPosition([ +`// some comment + +/// + +import { x } from "./a"; + +const y = x + 1;`, +]);