Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2767b596
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2767b596
编写于
12月 01, 2015
作者:
M
Martin Aeschlimann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[js] TypeError: e.split is not a function #829
上级
6c326105
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
16 deletion
+60
-16
src/vs/languages/typescript/common/features/quickFix.ts
src/vs/languages/typescript/common/features/quickFix.ts
+6
-5
src/vs/languages/typescript/test/common/features/quickfix.test.ts
...anguages/typescript/test/common/features/quickfix.test.ts
+54
-11
未找到文件。
src/vs/languages/typescript/common/features/quickFix.ts
浏览文件 @
2767b596
...
...
@@ -168,7 +168,8 @@ var sinonDD = 'sinon/sinon.d.ts';
var
jasmineDD
=
'
jasmine/jasmine.d.ts
'
;
var
handlebarsDD
=
'
handlebars/handlebars.d.ts
'
;
var
typingsMap
:
{
[
key
:
string
]:
string
|
string
[]
}
=
{
// exported for tests
export
var
typingsMap
:
{
[
key
:
string
]:
string
|
string
[]
}
=
{
'
angular
'
:
angularDD
,
'
$
'
:
jqueryDD
,
'
jquery
'
:
jqueryDD
,
'
jQuery
'
:
jqueryDD
,
'
process
'
:
nodejsDD
,
'
__dirname
'
:
nodejsDD
,
...
...
@@ -195,13 +196,13 @@ function computeAddTypeDefinitionProposals(languageService: ts.LanguageService,
offset
=
converter
.
getOffset
(
sourceFile
,
{
lineNumber
:
range
.
endLineNumber
,
column
:
range
.
endColumn
}),
token
=
ts
.
findTokenOnLeftOfPosition
(
sourceFile
,
offset
);
if
(
!
token
||
token
.
getWidth
()
===
0
)
{
if
(
!
token
||
token
.
getWidth
()
===
0
||
(
network
.
schemas
.
inMemory
===
resource
.
scheme
)
)
{
return
;
}
var
currentWord
=
ts
.
getTextOfNode
(
token
);
var
mapping
=
typingsMap
[
currentWord
];
if
(
mapping
&&
(
network
.
schemas
.
inMemory
!==
resource
.
scheme
))
{
if
(
typingsMap
.
hasOwnProperty
(
currentWord
))
{
var
mapping
=
typingsMap
[
currentWord
];
var
dtsRefs
:
string
[]
=
Array
.
isArray
(
mapping
)
?
<
string
[]
>
mapping
:
[
<
string
>
mapping
];
dtsRefs
.
forEach
((
dtsRef
)
=>
{
result
.
push
({
...
...
@@ -212,7 +213,7 @@ function computeAddTypeDefinitionProposals(languageService: ts.LanguageService,
});
}
if
(
strings
.
endsWith
(
resource
.
fsP
ath
,
'
.js
'
))
{
if
(
strings
.
endsWith
(
resource
.
p
ath
,
'
.js
'
))
{
result
.
push
({
label
:
nls
.
localize
(
'
typescript.quickfix.addAsGlobal
'
,
"
Mark '{0}' as global
"
,
currentWord
),
id
:
JSON
.
stringify
({
type
:
'
addglobal
'
,
name
:
currentWord
}),
...
...
src/vs/languages/typescript/test/common/features/quickfix.test.ts
浏览文件 @
2767b596
...
...
@@ -16,30 +16,73 @@ import Options = require('vs/languages/typescript/common/options');
suite
(
'
TS - quick fix
'
,
()
=>
{
function
assertQuickFix
(
code
:
string
,
callback
:
(
outline
:
Modes
.
IQuickFix
[])
=>
any
):
void
{
var
fileName
=
'
a.ts
'
;
var
host
=
new
utils
.
LanguageServiceHost
().
add
(
fileName
,
code
);
function
assertQuickFix
(
code
:
string
,
fileName
:
string
,
callback
:
(
outline
:
Modes
.
IQuickFix
[])
=>
any
):
void
{
var
filePath
=
'
file://test/
'
+
fileName
;
var
fileURL
=
network
.
URL
.
parse
(
filePath
);
var
host
=
new
utils
.
LanguageServiceHost
().
add
(
filePath
,
code
);
var
service
=
ts
.
createLanguageService
(
host
,
ts
.
createDocumentRegistry
());
var
markers
=
diagnostics
.
getSemanticDiagnostics
(
service
,
network
.
URL
.
fromValue
(
fileName
)
,
Options
.
typeScriptOptions
).
markers
;
var
markers
=
diagnostics
.
getSemanticDiagnostics
(
service
,
fileURL
,
Options
.
typeScriptOptions
).
markers
;
assert
.
equal
(
markers
.
length
,
1
);
var
marker
=
markers
[
0
];
var
elements
=
quickfix
.
compute
(
service
,
network
.
URL
.
fromValue
(
fileName
)
,
marker
);
var
elements
=
quickfix
.
compute
(
service
,
fileURL
,
marker
);
try
{
callback
(
elements
);
}
catch
(
e
)
{
assert
.
ok
(
false
,
e
);
}
callback
(
elements
);
}
test
(
'
quickfix
'
,
function
()
{
assertQuickFix
(
'
class C { private hello = 0; private world = this.hell0; }
'
,
(
elements
)
=>
{
assertQuickFix
(
'
class C { private hello = 0; private world = this.hell0; }
'
,
'
a.ts
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Rename to 'hello'
"
);
});
assertQuickFix
(
'
_.foo();
'
,
'
a.ts
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
2
);
assert
.
equal
(
elements
[
0
].
label
,
"
Download type definition underscore.d.ts
"
);
assert
.
equal
(
elements
[
1
].
label
,
"
Download type definition lodash.d.ts
"
);
});
assertQuickFix
(
'
describe("x");
'
,
'
a.js
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
3
);
assert
.
equal
(
elements
[
0
].
label
,
"
Download type definition mocha.d.ts
"
);
assert
.
equal
(
elements
[
1
].
label
,
"
Download type definition jasmine.d.ts
"
);
assert
.
equal
(
elements
[
2
].
label
,
"
Mark 'describe' as global
"
);
});
assertQuickFix
(
'
angular.foo = 1;
'
,
'
a.ts
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Download type definition angular.d.ts
"
);
});
assertQuickFix
(
'
var x = __dirname;
'
,
'
a.ts
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Download type definition node.d.ts
"
);
});
assertQuickFix
(
'
ko.observable(null);
'
,
'
a.ts
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Download type definition knockout.d.ts
"
);
});
for
(
var
id
in
quickfix
.
typingsMap
)
{
assertQuickFix
(
id
+
'
.foo();
'
,
'
a.ts
'
,
(
elements
)
=>
{
var
value
=
quickfix
.
typingsMap
[
id
];
var
length
=
Array
.
isArray
(
value
)
?
value
.
length
:
1
;
assert
.
equal
(
elements
.
length
,
length
);
});
}
assertQuickFix
(
'
foo.observable(null);
'
,
'
a.js
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Mark 'foo' as global
"
);
});
assertQuickFix
(
'
toString();
'
,
'
a.js
'
,
(
elements
)
=>
{
assert
.
equal
(
elements
.
length
,
1
);
assert
.
equal
(
elements
[
0
].
label
,
"
Mark 'toString' as global
"
);
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录