mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Handle module specifiers
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// @Filename: foo.ts
|
||||
//// export function foo() { return "foo"; }
|
||||
|
||||
//// import("[|./foo|]")
|
||||
//// var x = import("[|./foo|]")
|
||||
//// [|import("[|{| "declarationRangeIndex": 0 |}./foo|]")|]
|
||||
//// [|var x = import("[|{| "declarationRangeIndex": 2 |}./foo|]")|]
|
||||
|
||||
verify.singleReferenceGroup('module "/tests/cases/fourslash/foo"');
|
||||
verify.singleReferenceGroup('module "/tests/cases/fourslash/foo"', "./foo");
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
////[|export as namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}THREE|];|]
|
||||
|
||||
// @Filename: /typings/global.d.ts
|
||||
////import * as _THREE from '[|three|]';
|
||||
////[|import * as _THREE from '[|{| "declarationRangeIndex": 2 |}three|]';|]
|
||||
////declare global {
|
||||
//// [|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}THREE|]: typeof _THREE;|]
|
||||
//// [|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}THREE|]: typeof _THREE;|]
|
||||
////}
|
||||
|
||||
// @Filename: /src/index.ts
|
||||
@@ -38,7 +38,7 @@
|
||||
//// "files": ["/src/index.ts", "typings/global.d.ts"]
|
||||
////}
|
||||
|
||||
const [r0Def, r0, r1, r2Def, ...rest] = test.ranges();
|
||||
const [r0Def, r0, r1Def, r1, r2Def, ...rest] = test.ranges();
|
||||
// GH#29533
|
||||
// TODO:: this should be var THREE: typeof import instead of module name as var but thats existing issue and repros with quickInfo too.
|
||||
verify.singleReferenceGroup(`module "/node_modules/@types/three/index"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
////[|[|{| "declarationRangeIndex": 2 |}export|] = [|{| "declarationRangeIndex": 2 |}T|];|]
|
||||
|
||||
// @Filename: /b.ts
|
||||
////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}T|] = require("[|./a|]");|]
|
||||
////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}T|] = require("[|{| "declarationRangeIndex": 5 |}./a|]");|]
|
||||
|
||||
const [r0Def, r0, r12Def, r1, r2, r3Def, r3, r4] = test.ranges();
|
||||
const mod = { definition: 'module "/a"', ranges: [r4, r1] };
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
////export const x = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import { x } from "[|./a|]";
|
||||
////[|import { x } from "[|{| "declarationRangeIndex": 0 |}./a|]";|]
|
||||
|
||||
// @Filename: /c/sub.js
|
||||
////const a = require("[|../a|]");
|
||||
////[|const a = require("[|{| "declarationRangeIndex": 2 |}../a|]");|]
|
||||
|
||||
// @Filename: /d.ts
|
||||
//// /// <reference path="[|./a.ts|]" />
|
||||
|
||||
const ranges = test.ranges();
|
||||
const [r0, r1, r2] = ranges;
|
||||
const [r0Def, r0, r1Def, r1, r2] = test.ranges();
|
||||
const ranges = [r0, r1, r2];
|
||||
verify.referenceGroups(ranges, [{ definition: 'module "/a"', ranges: [r0, r1, r2] }]);
|
||||
// Testing that it works with documentHighlights too
|
||||
verify.rangesAreDocumentHighlights();
|
||||
verify.rangesAreDocumentHighlights(ranges);
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
// @Filename: /b.ts
|
||||
/////// <reference types="[|foo|]" />
|
||||
////import { x } from "[|foo|]";
|
||||
////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|]" {}|]
|
||||
////[|import { x } from "[|{| "declarationRangeIndex": 1 |}foo|]";|]
|
||||
////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}foo|]" {}|]
|
||||
|
||||
verify.noErrors();
|
||||
verify.singleReferenceGroup('module "/node_modules/foo/index"', "foo");
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
// @resolveJsonModule: true
|
||||
|
||||
// @Filename: /a.ts
|
||||
////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}j|] = require("[|./j.json|]");|]
|
||||
////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}j|] = require("[|{| "declarationRangeIndex": 0 |}./j.json|]");|]
|
||||
////[|j|];
|
||||
|
||||
// @Filename: /b.js
|
||||
////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}j|] = require("[|./j.json|]");|]
|
||||
////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}j|] = require("[|{| "declarationRangeIndex": 4 |}./j.json|]");|]
|
||||
////[|j|];
|
||||
|
||||
// @Filename: /j.json
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
////const b = require("[|./b|]");
|
||||
////[|const b = require("[|{| "declarationRangeIndex": 0 |}./b|]");|]
|
||||
|
||||
// @Filename: /b.js
|
||||
////[|[|{| "declarationRangeIndex": 1 |}module|].exports = 0;|]
|
||||
////[|[|{| "declarationRangeIndex": 2 |}module|].exports = 0;|]
|
||||
|
||||
const [r0, rDef, r1] = test.ranges();
|
||||
const [r0Def, r0, rDef, r1] = test.ranges();
|
||||
verify.singleReferenceGroup('module "/b"', [r0, r1]);
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
////[|[|{| "declarationRangeIndex": 4 |}export|] = [|{| "declarationRangeIndex": 4 |}T|];|]
|
||||
|
||||
// @Filename: /b.ts
|
||||
////const x: import("[|./[|a|]|]") = 0;
|
||||
////const y: import("[|./[|a|]|]").U = "";
|
||||
////[|const x: import("[|{| "declarationRangeIndex": 7 |}./[|a|]|]") = 0;|]
|
||||
////[|const y: import("[|{| "declarationRangeIndex": 10 |}./[|a|]|]").U = "";|]
|
||||
|
||||
verify.noErrors();
|
||||
|
||||
const [r0Def, r0, r1Def, r1, r2Def, rExport, r2, r3, r3b, r4, r4b] = test.ranges();
|
||||
const [r0Def, r0, r1Def, r1, r2Def, rExport, r2, r3Def, r3, r3b, r4Def, r4, r4b] = test.ranges();
|
||||
verify.referenceGroups(r0, [{ definition: "type T = number\nnamespace T", ranges: [r0, r2, r3] }]);
|
||||
verify.referenceGroups(r1, [{ definition: "namespace T", ranges: [r1, r2] }]);
|
||||
const t: FourSlashInterface.ReferenceGroup = { definition: "type T = number\nnamespace T", ranges: [r0, r1, r2, r3] };
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
////[|module.exports.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}D|] = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}D|] {}|];|]
|
||||
|
||||
// @Filename: /b.js
|
||||
/////** @type {import("[|./a|]")} */
|
||||
/////** [|@type {import("[|{| "declarationRangeIndex": 8 |}./a|]")}|] */
|
||||
////const x = 0;
|
||||
/////** @type {import("[|./a|]").[|D|]} */
|
||||
/////** [|@type {import("[|{| "declarationRangeIndex": 10 |}./a|]").[|D|]}|] */
|
||||
////const y = 0;
|
||||
|
||||
verify.noErrors();
|
||||
|
||||
// TODO: GH#24025
|
||||
|
||||
const [rModuleDef, rModule, r0Def, r0, r1Def, r1, r2Def, r2, r3, r4, r5] = test.ranges();
|
||||
const [rModuleDef, rModule, r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4, r5] = test.ranges();
|
||||
verify.referenceGroups(rModule, [{ definition: 'module "/a"', ranges: [r3, r4, rModule] }]);
|
||||
verify.referenceGroups(r0, [
|
||||
{ definition: "(local class) C", ranges: [r0] },
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
////export const x = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////const x: typeof import("[|./a|]") = { x: 0 };
|
||||
////const y: typeof import("[|./a|]") = { x: 0 };
|
||||
////[|const x: typeof import("[|{| "declarationRangeIndex": 0 |}./a|]") = { x: 0 };|]
|
||||
////[|const y: typeof import("[|{| "declarationRangeIndex": 2 |}./a|]") = { x: 0 };|]
|
||||
|
||||
verify.singleReferenceGroup('module "/a"');
|
||||
verify.singleReferenceGroup('module "/a"', "./a");
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
////}|]
|
||||
////
|
||||
////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}bar|]" {
|
||||
//// [|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|] = require("[|foo|]");|]
|
||||
//// [|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|] = require("[|{| "declarationRangeIndex": 6 |}foo|]");|]
|
||||
//// var f2: typeof [|foo|].[|f|];
|
||||
////}|]
|
||||
////
|
||||
////declare module "baz" {
|
||||
//// import bar = require("[|bar|]");
|
||||
//// [|import bar = require("[|{| "declarationRangeIndex": 11 |}bar|]");|]
|
||||
//// var f2: typeof bar.[|foo|];
|
||||
////}
|
||||
|
||||
const [moduleFoo0Def, moduleFoo0, f0Def, f0, moduleBar0Def, moduleBar0, foo0Def, foo0, moduleFoo1, foo1, f1, moduleBar1, foo2] = test.ranges();
|
||||
const [moduleFoo0Def, moduleFoo0, f0Def, f0, moduleBar0Def, moduleBar0, foo0Def, foo0, moduleFoo1, foo1, f1, moduleBar1Def, moduleBar1, foo2] = test.ranges();
|
||||
verify.singleReferenceGroup('module "foo"', [moduleFoo0, moduleFoo1]);
|
||||
verify.singleReferenceGroup('module "bar"', [moduleBar0, moduleBar1]);
|
||||
verify.singleReferenceGroup('(alias) module "foo"\nimport foo = require("foo")', [foo0, foo1, foo2]);
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
////}|]
|
||||
|
||||
// @Filename: referencesForGlobals_2.ts
|
||||
////import f = require("[|foo|]");
|
||||
////[|import f = require("[|{| "declarationRangeIndex": 2 |}foo|]");|]
|
||||
|
||||
verify.singleReferenceGroup('module "foo"', "foo");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
////{}
|
||||
|
||||
// @Filename: a.ts
|
||||
////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|]
|
||||
////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true, "declarationRangeIndex": 0 |}foo|]";|]
|
||||
////[|foo|]();
|
||||
|
||||
goTo.file("a.ts");
|
||||
|
||||
Reference in New Issue
Block a user