Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
8192262a
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,发现更多精彩内容 >>
未验证
提交
8192262a
编写于
3月 05, 2020
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more support for exported imports in tree shaking
上级
686798f2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
0 deletion
+76
-0
build/lib/treeshaking.js
build/lib/treeshaking.js
+37
-0
build/lib/treeshaking.ts
build/lib/treeshaking.ts
+39
-0
未找到文件。
build/lib/treeshaking.js
浏览文件 @
8192262a
...
@@ -254,6 +254,7 @@ function markNodes(languageService, options) {
...
@@ -254,6 +254,7 @@ function markNodes(languageService, options) {
}
}
const
black_queue
=
[];
const
black_queue
=
[];
const
gray_queue
=
[];
const
gray_queue
=
[];
const
export_import_queue
=
[];
const
sourceFilesLoaded
=
{};
const
sourceFilesLoaded
=
{};
function
enqueueTopLevelModuleStatements
(
sourceFile
)
{
function
enqueueTopLevelModuleStatements
(
sourceFile
)
{
sourceFile
.
forEachChild
((
node
)
=>
{
sourceFile
.
forEachChild
((
node
)
=>
{
...
@@ -270,6 +271,11 @@ function markNodes(languageService, options) {
...
@@ -270,6 +271,11 @@ function markNodes(languageService, options) {
setColor
(
node
,
2
/* Black */
);
setColor
(
node
,
2
/* Black */
);
enqueueImport
(
node
,
node
.
moduleSpecifier
.
text
);
enqueueImport
(
node
,
node
.
moduleSpecifier
.
text
);
}
}
if
(
node
.
exportClause
&&
ts
.
isNamedExports
(
node
.
exportClause
))
{
for
(
const
exportSpecifier
of
node
.
exportClause
.
elements
)
{
export_import_queue
.
push
(
exportSpecifier
);
}
}
return
;
return
;
}
}
if
(
ts
.
isExpressionStatement
(
node
)
if
(
ts
.
isExpressionStatement
(
node
)
...
@@ -448,6 +454,22 @@ function markNodes(languageService, options) {
...
@@ -448,6 +454,22 @@ function markNodes(languageService, options) {
};
};
node
.
forEachChild
(
loop
);
node
.
forEachChild
(
loop
);
}
}
while
(
export_import_queue
.
length
>
0
)
{
const
node
=
export_import_queue
.
shift
();
if
(
nodeOrParentIsBlack
(
node
))
{
continue
;
}
const
symbol
=
node
.
symbol
;
if
(
!
symbol
)
{
continue
;
}
const
aliased
=
checker
.
getAliasedSymbol
(
symbol
);
if
(
aliased
.
declarations
&&
aliased
.
declarations
.
length
>
0
)
{
if
(
nodeOrParentIsBlack
(
aliased
.
declarations
[
0
])
||
nodeOrChildIsBlack
(
aliased
.
declarations
[
0
]))
{
setColor
(
node
,
2
/* Black */
);
}
}
}
}
}
function
nodeIsInItsOwnDeclaration
(
nodeSourceFile
,
node
,
symbol
)
{
function
nodeIsInItsOwnDeclaration
(
nodeSourceFile
,
node
,
symbol
)
{
for
(
let
i
=
0
,
len
=
symbol
.
declarations
.
length
;
i
<
len
;
i
++
)
{
for
(
let
i
=
0
,
len
=
symbol
.
declarations
.
length
;
i
<
len
;
i
++
)
{
...
@@ -539,6 +561,21 @@ function generateResult(languageService, shakeLevel) {
...
@@ -539,6 +561,21 @@ function generateResult(languageService, shakeLevel) {
}
}
}
}
}
}
if
(
ts
.
isExportDeclaration
(
node
))
{
if
(
node
.
exportClause
&&
node
.
moduleSpecifier
&&
ts
.
isNamedExports
(
node
.
exportClause
))
{
let
survivingExports
=
[];
for
(
const
exportSpecifier
of
node
.
exportClause
.
elements
)
{
if
(
getColor
(
exportSpecifier
)
===
2
/* Black */
)
{
survivingExports
.
push
(
exportSpecifier
.
getFullText
(
sourceFile
));
}
}
const
leadingTriviaWidth
=
node
.
getLeadingTriviaWidth
();
const
leadingTrivia
=
sourceFile
.
text
.
substr
(
node
.
pos
,
leadingTriviaWidth
);
if
(
survivingExports
.
length
>
0
)
{
return
write
(
`
${
leadingTrivia
}
export {
${
survivingExports
.
join
(
'
,
'
)}
} from
${
node
.
moduleSpecifier
.
getFullText
(
sourceFile
)}
;`
);
}
}
}
if
(
shakeLevel
===
2
/* ClassMembers */
&&
(
ts
.
isClassDeclaration
(
node
)
||
ts
.
isInterfaceDeclaration
(
node
))
&&
nodeOrChildIsBlack
(
node
))
{
if
(
shakeLevel
===
2
/* ClassMembers */
&&
(
ts
.
isClassDeclaration
(
node
)
||
ts
.
isInterfaceDeclaration
(
node
))
&&
nodeOrChildIsBlack
(
node
))
{
let
toWrite
=
node
.
getFullText
();
let
toWrite
=
node
.
getFullText
();
for
(
let
i
=
node
.
members
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
node
.
members
.
length
-
1
;
i
>=
0
;
i
--
)
{
...
...
build/lib/treeshaking.ts
浏览文件 @
8192262a
...
@@ -336,6 +336,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
...
@@ -336,6 +336,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
const
black_queue
:
ts
.
Node
[]
=
[];
const
black_queue
:
ts
.
Node
[]
=
[];
const
gray_queue
:
ts
.
Node
[]
=
[];
const
gray_queue
:
ts
.
Node
[]
=
[];
const
export_import_queue
:
ts
.
Node
[]
=
[];
const
sourceFilesLoaded
:
{
[
fileName
:
string
]:
boolean
}
=
{};
const
sourceFilesLoaded
:
{
[
fileName
:
string
]:
boolean
}
=
{};
function
enqueueTopLevelModuleStatements
(
sourceFile
:
ts
.
SourceFile
):
void
{
function
enqueueTopLevelModuleStatements
(
sourceFile
:
ts
.
SourceFile
):
void
{
...
@@ -356,6 +357,11 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
...
@@ -356,6 +357,11 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
setColor
(
node
,
NodeColor
.
Black
);
setColor
(
node
,
NodeColor
.
Black
);
enqueueImport
(
node
,
node
.
moduleSpecifier
.
text
);
enqueueImport
(
node
,
node
.
moduleSpecifier
.
text
);
}
}
if
(
node
.
exportClause
&&
ts
.
isNamedExports
(
node
.
exportClause
))
{
for
(
const
exportSpecifier
of
node
.
exportClause
.
elements
)
{
export_import_queue
.
push
(
exportSpecifier
);
}
}
return
;
return
;
}
}
...
@@ -566,6 +572,23 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
...
@@ -566,6 +572,23 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
};
};
node
.
forEachChild
(
loop
);
node
.
forEachChild
(
loop
);
}
}
while
(
export_import_queue
.
length
>
0
)
{
const
node
=
export_import_queue
.
shift
()
!
;
if
(
nodeOrParentIsBlack
(
node
))
{
continue
;
}
const
symbol
:
ts
.
Symbol
|
undefined
=
(
<
any
>
node
).
symbol
;
if
(
!
symbol
)
{
continue
;
}
const
aliased
=
checker
.
getAliasedSymbol
(
symbol
);
if
(
aliased
.
declarations
&&
aliased
.
declarations
.
length
>
0
)
{
if
(
nodeOrParentIsBlack
(
aliased
.
declarations
[
0
])
||
nodeOrChildIsBlack
(
aliased
.
declarations
[
0
]))
{
setColor
(
node
,
NodeColor
.
Black
);
}
}
}
}
}
function
nodeIsInItsOwnDeclaration
(
nodeSourceFile
:
ts
.
SourceFile
,
node
:
ts
.
Node
,
symbol
:
ts
.
Symbol
):
boolean
{
function
nodeIsInItsOwnDeclaration
(
nodeSourceFile
:
ts
.
SourceFile
,
node
:
ts
.
Node
,
symbol
:
ts
.
Symbol
):
boolean
{
...
@@ -667,6 +690,22 @@ function generateResult(languageService: ts.LanguageService, shakeLevel: ShakeLe
...
@@ -667,6 +690,22 @@ function generateResult(languageService: ts.LanguageService, shakeLevel: ShakeLe
}
}
}
}
if
(
ts
.
isExportDeclaration
(
node
))
{
if
(
node
.
exportClause
&&
node
.
moduleSpecifier
&&
ts
.
isNamedExports
(
node
.
exportClause
))
{
let
survivingExports
:
string
[]
=
[];
for
(
const
exportSpecifier
of
node
.
exportClause
.
elements
)
{
if
(
getColor
(
exportSpecifier
)
===
NodeColor
.
Black
)
{
survivingExports
.
push
(
exportSpecifier
.
getFullText
(
sourceFile
));
}
}
const
leadingTriviaWidth
=
node
.
getLeadingTriviaWidth
();
const
leadingTrivia
=
sourceFile
.
text
.
substr
(
node
.
pos
,
leadingTriviaWidth
);
if
(
survivingExports
.
length
>
0
)
{
return
write
(
`
${
leadingTrivia
}
export {
${
survivingExports
.
join
(
'
,
'
)}
} from
${
node
.
moduleSpecifier
.
getFullText
(
sourceFile
)}
;`
);
}
}
}
if
(
shakeLevel
===
ShakeLevel
.
ClassMembers
&&
(
ts
.
isClassDeclaration
(
node
)
||
ts
.
isInterfaceDeclaration
(
node
))
&&
nodeOrChildIsBlack
(
node
))
{
if
(
shakeLevel
===
ShakeLevel
.
ClassMembers
&&
(
ts
.
isClassDeclaration
(
node
)
||
ts
.
isInterfaceDeclaration
(
node
))
&&
nodeOrChildIsBlack
(
node
))
{
let
toWrite
=
node
.
getFullText
();
let
toWrite
=
node
.
getFullText
();
for
(
let
i
=
node
.
members
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
node
.
members
.
length
-
1
;
i
>=
0
;
i
--
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录