TypeScript F12 转到定义,得到两个相同的结果,

utugiqy6  于 4个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(37)

模板信息由@mjbvz添加

TypeScript版本: 3.7.0-dev.20190913
搜索词

  • JavaScript
  • Commonjs / node
  • 跳转到定义
    仓库
  1. 使用以下代码
  2. m1.m1echo() 内部的 m2.js 中运行 go to definition

原始报告如下

// Win10(x64) + node js 10.16.3 + npm -v 6.9.0
// Peek m1echo/m2echo definition will get 2 SAME definitions
// index.js

const m1 = require('./m1.js');
const m2 = require('./m2.js');

m1.m1work();
m2.m2work();

// m1.js

module.exports = {};
const m2 = require('./m2.js');

module.exports.m1work = function () {
    console.log('m1.m2.echo = <' + m2.m2echo() + '>');
}
module.exports.m1echo = function () {
    return 'this m1.';
}

// m2.js

module.exports = {};
const m1 = require('./m1.js');

module.exports.m2work = function () {
    console.log('m2.m1.echo = <' + m1.m1echo() + '>');
}
module.exports.m2echo = function () {
    return 'this m2.';
}
5fjcxozz

5fjcxozz1#

这是一个TS服务器响应的示例:

[Trace  - 5:49:29 PM] <semantic> Response received: definitionAndBoundSpan (23). Request took 2 ms. Success: true 
Result: {
    "definitions": [
        {
            "file": "/Users/matb/projects/san/m1.js",
            "start": {
                "line": 7,
                "offset": 16
            },
            "end": {
                "line": 7,
                "offset": 22
            },
            "contextStart": {
                "line": 7,
                "offset": 1
            },
            "contextEnd": {
                "line": 7,
                "offset": 22
            }
        },
        {
            "file": "/Users/matb/projects/san/m1.js",
            "start": {
                "line": 7,
                "offset": 16
            },
            "end": {
                "line": 7,
                "offset": 22
            },
            "contextStart": {
                "line": 7,
                "offset": 25
            },
            "contextEnd": {
                "line": 9,
                "offset": 2
            }
        }
    ],
    "textSpan": {
        "start": {
            "line": 5,
            "offset": 39
        },
        "end": {
            "line": 5,
            "offset": 45
        }
    }
}

相关问题