mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix ordering of code fix import with triple-slash directives (#52484)
This commit is contained in:
parent
0f724c0430
commit
8369d41efe
@ -1072,7 +1072,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;
|
||||
}
|
||||
@ -2365,8 +2367,10 @@ export function getJSDocCommentRanges(node: Node, text: string) {
|
||||
/** @internal */
|
||||
export const fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)(('[^']*')|("[^"]*")).*?\/>/;
|
||||
const fullTripleSlashReferenceTypeReferenceDirectiveRegEx = /^(\/\/\/\s*<reference\s+types\s*=\s*)(('[^']*')|("[^"]*")).*?\/>/;
|
||||
const fullTripleSlashLibReferenceRegEx = /^(\/\/\/\s*<reference\s+lib\s*=\s*)(('[^']*')|("[^"]*")).*?\/>/;
|
||||
/** @internal */
|
||||
export const fullTripleSlashAMDReferencePathRegEx = /^(\/\/\/\s*<amd-dependency\s+path\s*=\s*)(('[^']*')|("[^"]*")).*?\/>/;
|
||||
const fullTripleSlashAMDModuleRegEx = /^\/\/\/\s*<amd-module\s+.*?\/>/;
|
||||
const defaultLibReferenceRegEx = /^(\/\/\/\s*<reference\s+no-default-lib\s*=\s*)(('[^']*')|("[^"]*"))\s*\/>/;
|
||||
|
||||
/** @internal */
|
||||
|
||||
@ -12,6 +12,7 @@ declare const elem: HTMLElement;
|
||||
//// [file1.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/// <reference lib="dom" />
|
||||
//// [file2.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
@ -13,6 +13,7 @@ declare const elem: HTMLElement;
|
||||
define("file1", ["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/// <reference lib="dom" />
|
||||
});
|
||||
define("file2", ["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
|
||||
@ -25,6 +25,7 @@ export const elem: HTMLElement = { field: 'a' };
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.elem = void 0;
|
||||
/// <reference lib="dom" />
|
||||
exports.elem = { field: 'a' };
|
||||
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ define("file1", ["require", "exports"], function (require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.elem = void 0;
|
||||
/// <reference lib="dom" />
|
||||
exports.elem = { field: 'a' };
|
||||
});
|
||||
|
||||
|
||||
122
tests/cases/fourslash/importNameCodeFix_tripleSlashOrdering.ts
Normal file
122
tests/cases/fourslash/importNameCodeFix_tripleSlashOrdering.ts
Normal file
@ -0,0 +1,122 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// repro from #52263
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
////{
|
||||
//// "compilerOptions": {
|
||||
//// "skipDefaultLibCheck": false
|
||||
//// }
|
||||
////}
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const x = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <reference lib="es2017.string" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
// @Filename: /c.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <reference path="jquery-1.8.3.js" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
// @Filename: /d.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <reference types="node" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
// @Filename: /e.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <reference no-default-lib="true" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
// @Filename: /f.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <amd-module name="NamedModule" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
// @Filename: /g.ts
|
||||
////// some comment
|
||||
////
|
||||
/////// <amd-dependency path="legacy/moduleA" name="moduleA" />
|
||||
////
|
||||
////const y = x + 1;
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <reference lib="es2017.string" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <reference path="jquery-1.8.3.js" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
|
||||
goTo.file("/d.ts");
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
|
||||
goTo.file("/e.ts");
|
||||
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <reference no-default-lib="true" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
|
||||
goTo.file("/f.ts");
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <amd-module name="NamedModule" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
|
||||
goTo.file("/g.ts");
|
||||
verify.importFixAtPosition([
|
||||
`// some comment
|
||||
|
||||
/// <amd-dependency path="legacy/moduleA" name="moduleA" />
|
||||
|
||||
import { x } from "./a";
|
||||
|
||||
const y = x + 1;`,
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user