Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
d231df17
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d231df17
编写于
9月 13, 2019
作者:
K
Kitson Kelly
提交者:
Ryan Dahl
9月 12, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deno_typescript cleanup/improvements (#2901)
上级
c03cdcc9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
35 deletion
+55
-35
deno_typescript/compiler_main.js
deno_typescript/compiler_main.js
+40
-31
js/compiler.ts
js/compiler.ts
+1
-2
js/diagnostics.ts
js/diagnostics.ts
+0
-2
js/ts_global.d.ts
js/ts_global.d.ts
+14
-0
未找到文件。
deno_typescript/compiler_main.js
浏览文件 @
d231df17
...
...
@@ -11,6 +11,7 @@ const ASSETS = "$asset$";
* @param {string} configText
* @param {Array<string>} rootNames
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function
main
(
configText
,
rootNames
)
{
println
(
`>>> ts version
${
ts
.
version
}
`
);
println
(
`>>> rootNames
${
rootNames
}
`
);
...
...
@@ -19,22 +20,26 @@ function main(configText, rootNames) {
assert
(
rootNames
.
length
>
0
);
le
t
{
options
,
diagnostics
}
=
configure
(
configText
);
cons
t
{
options
,
diagnostics
}
=
configure
(
configText
);
handleDiagnostics
(
host
,
diagnostics
);
println
(
`>>> TS config:
${
JSON
.
stringify
(
options
)}
`
);
const
program
=
ts
.
createProgram
(
rootNames
,
options
,
host
);
diagnostics
=
ts
.
getPreEmitDiagnostics
(
program
).
filter
(({
code
})
=>
{
// TS2691: An import path cannot end with a '.ts' extension. Consider
// importing 'bad-module' instead.
if
(
code
===
2691
)
return
false
;
// TS5009: Cannot find the common subdirectory path for the input files.
if
(
code
===
5009
)
return
false
;
return
true
;
});
handleDiagnostics
(
host
,
diagnostics
);
handleDiagnostics
(
host
,
ts
.
getPreEmitDiagnostics
(
program
).
filter
(({
code
})
=>
{
// TS1063: An export assignment cannot be used in a namespace.
if
(
code
===
1063
)
return
false
;
// TS2691: An import path cannot end with a '.ts' extension. Consider
// importing 'bad-module' instead.
if
(
code
===
2691
)
return
false
;
// TS5009: Cannot find the common subdirectory path for the input files.
if
(
code
===
5009
)
return
false
;
return
true
;
})
);
const
emitResult
=
program
.
emit
();
handleDiagnostics
(
host
,
emitResult
.
diagnostics
);
...
...
@@ -102,20 +107,25 @@ const ops = {
};
/**
* This is a minimal implementation of a compiler host to be able to allow the
* creation of runtime bundles. Some of the methods are implemented in a way
* to just appease the TypeScript compiler, not to necessarily be a general
* purpose implementation.
*
* @implements {ts.CompilerHost}
*/
class
Host
{
/**
* @param {string} fileName
* @param {string}
_
fileName
*/
fileExists
(
fileName
)
{
fileExists
(
_
fileName
)
{
return
true
;
}
/**
* @param {string} fileName
* @param {string}
_
fileName
*/
readFile
(
fileName
)
{
readFile
(
_
fileName
)
{
unreachable
();
return
undefined
;
}
...
...
@@ -163,18 +173,17 @@ class Host {
.
replace
(
"
/index.d.ts
"
,
""
);
}
le
t
{
sourceCode
,
moduleName
}
=
dispatch
(
"
readFile
"
,
{
cons
t
{
sourceCode
,
moduleName
}
=
dispatch
(
"
readFile
"
,
{
fileName
,
languageVersion
,
shouldCreateNewSourceFile
});
// TODO(ry) A terrible hack. Please remove ASAP.
if
(
fileName
.
endsWith
(
"
typescript.d.ts
"
))
{
sourceCode
=
sourceCode
.
replace
(
"
export = ts;
"
,
""
);
}
let
sourceFile
=
ts
.
createSourceFile
(
fileName
,
sourceCode
,
languageVersion
);
const
sourceFile
=
ts
.
createSourceFile
(
fileName
,
sourceCode
,
languageVersion
);
sourceFile
.
moduleName
=
moduleName
;
return
sourceFile
;
}
...
...
@@ -201,18 +210,18 @@ class Host {
}
/**
* @param {string} fileName
* @param {ts.Path} path
* @param {ts.ScriptTarget} languageVersion
* @param {*} onError
* @param {boolean} shouldCreateNewSourceFile
* @param {string}
_
fileName
* @param {ts.Path}
_
path
* @param {ts.ScriptTarget}
_
languageVersion
* @param {*}
_
onError
* @param {boolean}
_
shouldCreateNewSourceFile
*/
getSourceFileByPath
(
fileName
,
path
,
languageVersion
,
onError
,
shouldCreateNewSourceFile
_
fileName
,
_
path
,
_
languageVersion
,
_
onError
,
_
shouldCreateNewSourceFile
)
{
unreachable
();
return
undefined
;
...
...
js/compiler.ts
浏览文件 @
d231df17
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// TODO(ry) Combine this implementation with //deno_typescript/compiler_main.js
/// <reference types="../third_party/node_modules/typescript/lib/typescript.d.ts"/>
import
"
./globals.ts
"
;
import
"
./ts_global.d.ts
"
;
import
{
bold
,
cyan
,
yellow
}
from
"
./colors.ts
"
;
import
{
Console
}
from
"
./console.ts
"
;
...
...
js/diagnostics.ts
浏览文件 @
d231df17
...
...
@@ -4,8 +4,6 @@
// compiler, which is strongly influenced by the format of TypeScript
// diagnostics.
/// <reference types="../third_party/node_modules/typescript/lib/typescript.d.ts"/>
/** The log category for a diagnostic message */
export
enum
DiagnosticCategory
{
Log
=
0
,
...
...
js/ts_global.d.ts
0 → 100644
浏览文件 @
d231df17
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// This scopes the `ts` namespace globally, which is where it exists at runtime
// when building Deno, but the `typescript/lib/typescript.d.ts` is defined as a
// module.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import
*
as
ts_
from
"
../node_modules/typescript/lib/typescript.d.ts
"
;
declare
global
{
namespace
ts
{
export
=
ts_
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录