Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
9b4b7960
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b4b7960
编写于
12月 22, 2016
作者:
A
Alexey Andreev
提交者:
Alexey Andreev
12月 22, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JS: prevent compiler from importing module more than once if not necessary. See KT-15260
上级
1ecd9579
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
93 addition
and
7 deletion
+93
-7
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
...etbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
+12
-0
js/js.tests/test/org/jetbrains/kotlin/js/test/utils/DirectiveTestUtils.java
...rg/jetbrains/kotlin/js/test/utils/DirectiveTestUtils.java
+12
-0
js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java
.../jetbrains/kotlin/js/translate/context/StaticContext.java
+8
-7
js/js.translator/testData/box/jsModule/importCountCommonJS.js
...s.translator/testData/box/jsModule/importCountCommonJS.js
+12
-0
js/js.translator/testData/box/jsModule/importCountCommonJS.kt
...s.translator/testData/box/jsModule/importCountCommonJS.kt
+17
-0
js/js.translator/testData/box/jsModule/importCountUmd.js
js/js.translator/testData/box/jsModule/importCountUmd.js
+11
-0
js/js.translator/testData/box/jsModule/importCountUmd.kt
js/js.translator/testData/box/jsModule/importCountUmd.kt
+21
-0
未找到文件。
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
浏览文件 @
9b4b7960
...
...
@@ -5083,6 +5083,18 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
String
fileName
=
KotlinTestUtils
.
navigationMetadata
(
"js/js.translator/testData/box/jsModule/externalProperty.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"importCountCommonJS.kt"
)
public
void
testImportCountCommonJS
()
throws
Exception
{
String
fileName
=
KotlinTestUtils
.
navigationMetadata
(
"js/js.translator/testData/box/jsModule/importCountCommonJS.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"importCountUmd.kt"
)
public
void
testImportCountUmd
()
throws
Exception
{
String
fileName
=
KotlinTestUtils
.
navigationMetadata
(
"js/js.translator/testData/box/jsModule/importCountUmd.kt"
);
doTest
(
fileName
);
}
}
@TestMetadata
(
"js/js.translator/testData/box/jsName"
)
...
...
js/js.tests/test/org/jetbrains/kotlin/js/test/utils/DirectiveTestUtils.java
浏览文件 @
9b4b7960
...
...
@@ -92,6 +92,17 @@ public class DirectiveTestUtils {
}
};
private
static
final
DirectiveHandler
FUNCTION_CALLED_TIMES
=
new
DirectiveHandler
(
"FUNCTION_CALLED_TIMES"
)
{
@Override
void
processEntry
(
@NotNull
JsNode
ast
,
@NotNull
ArgumentsHelper
arguments
)
throws
Exception
{
int
expectedCount
=
Integer
.
parseInt
(
arguments
.
getNamedArgument
(
"count"
));
String
functionName
=
arguments
.
getFirst
();
CallCounter
counter
=
CallCounter
.
countCalls
(
ast
);
int
actualCount
=
counter
.
getUnqualifiedCallsCount
(
functionName
);
assertEquals
(
"Function "
+
functionName
,
expectedCount
,
actualCount
);
}
};
private
static
boolean
parseBooleanArgument
(
@NotNull
ArgumentsHelper
arguments
,
@NotNull
String
name
,
boolean
defaultValue
)
{
String
value
=
arguments
.
findNamedArgument
(
name
);
return
value
!=
null
?
Boolean
.
parseBoolean
(
value
)
:
defaultValue
;
...
...
@@ -253,6 +264,7 @@ public class DirectiveTestUtils {
private
static
final
List
<
DirectiveHandler
>
DIRECTIVE_HANDLERS
=
Arrays
.
asList
(
FUNCTION_CONTAINS_NO_CALLS
,
FUNCTION_NOT_CALLED
,
FUNCTION_CALLED_TIMES
,
PROPERTY_NOT_USED
,
PROPERTY_NOT_READ_FROM
,
PROPERTY_NOT_WRITTEN_TO
,
...
...
js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java
浏览文件 @
9b4b7960
...
...
@@ -661,12 +661,13 @@ public final class StaticContext {
@NotNull
private
ImportedModule
getImportedModule
(
@NotNull
String
baseName
,
@Nullable
DeclarationDescriptor
descriptor
)
{
ImportedModuleKey
key
=
new
ImportedModuleKey
(
baseName
,
descriptor
);
JsName
plainName
=
descriptor
!=
null
&&
config
.
getModuleKind
()
==
ModuleKind
.
UMD
?
rootScope
.
declareName
(
getPlainId
(
descriptor
))
:
null
;
ImportedModuleKey
key
=
new
ImportedModuleKey
(
baseName
,
plainName
);
ImportedModule
module
=
importedModules
.
get
(
key
);
if
(
module
==
null
)
{
JsName
internalName
=
rootScope
.
declareTemporaryName
(
Namer
.
LOCAL_MODULE_PREFIX
+
Namer
.
suggestedModuleName
(
baseName
));
JsName
plainName
=
descriptor
!=
null
?
rootScope
.
declareName
(
getPlainId
(
descriptor
))
:
null
;
module
=
new
ImportedModule
(
baseName
,
internalName
,
plainName
!=
null
?
pureFqn
(
plainName
,
null
)
:
null
);
importedModules
.
put
(
key
,
module
);
}
...
...
@@ -835,11 +836,11 @@ public final class StaticContext {
private
final
String
baseName
;
@Nullable
private
final
DeclarationDescriptor
declaration
;
private
final
JsName
plainName
;
public
ImportedModuleKey
(
@NotNull
String
baseName
,
@Nullable
DeclarationDescriptor
declaration
)
{
public
ImportedModuleKey
(
@NotNull
String
baseName
,
@Nullable
JsName
plainName
)
{
this
.
baseName
=
baseName
;
this
.
declaration
=
declaration
;
this
.
plainName
=
plainName
;
}
@Override
...
...
@@ -850,7 +851,7 @@ public final class StaticContext {
ImportedModuleKey
key
=
(
ImportedModuleKey
)
o
;
if
(!
baseName
.
equals
(
key
.
baseName
))
return
false
;
if
(
declaration
!=
null
?
!
declaration
.
equals
(
key
.
declaration
)
:
key
.
declaration
!=
null
)
return
false
;
if
(
plainName
!=
null
?
!
plainName
.
equals
(
key
.
plainName
)
:
key
.
plainName
!=
null
)
return
false
;
return
true
;
}
...
...
@@ -858,7 +859,7 @@ public final class StaticContext {
@Override
public
int
hashCode
()
{
int
result
=
baseName
.
hashCode
();
result
=
31
*
result
+
(
declaration
!=
null
?
declaration
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
plainName
!=
null
?
plainName
.
hashCode
()
:
0
);
return
result
;
}
}
...
...
js/js.translator/testData/box/jsModule/importCountCommonJS.js
0 → 100644
浏览文件 @
9b4b7960
__beginModule__
();
module
.
exports
=
function
(
param
)
{
switch
(
typeof
param
)
{
case
"
number
"
:
return
"
a
"
;
case
"
string
"
:
return
"
b
"
;
default
:
return
"
c
"
;
}
};
__endModule__
(
"
lib
"
);
\ No newline at end of file
js/js.translator/testData/box/jsModule/importCountCommonJS.kt
0 → 100644
浏览文件 @
9b4b7960
// MODULE_KIND: COMMON_JS
// FUNCTION_CALLED_TIMES: require count=2
@JsModule
(
"lib"
)
external
fun
f
(
x
:
Int
):
String
@JsModule
(
"lib"
)
external
fun
f
(
x
:
String
):
String
@JsModule
(
"lib"
)
external
fun
g
(
x
:
Boolean
):
String
fun
box
():
String
{
val
result
=
f
(
23
)
+
f
(
"foo"
)
+
g
(
true
)
if
(
result
!=
"abc"
)
return
"fail: $result"
return
"OK"
}
\ No newline at end of file
js/js.translator/testData/box/jsModule/importCountUmd.js
0 → 100644
浏览文件 @
9b4b7960
var
f
=
function
(
param
)
{
switch
(
typeof
param
)
{
case
"
number
"
:
return
"
a
"
;
case
"
string
"
:
return
"
b
"
;
default
:
return
"
c
"
;
}
};
var
g
=
f
;
\ No newline at end of file
js/js.translator/testData/box/jsModule/importCountUmd.kt
0 → 100644
浏览文件 @
9b4b7960
// MODULE_KIND: UMD
// NO_JS_MODULE_SYSTEM
// FUNCTION_CALLED_TIMES: require count=3
@JsModule
(
"lib"
)
@JsNonModule
external
fun
f
(
x
:
Int
):
String
@JsModule
(
"lib"
)
@JsNonModule
external
fun
f
(
x
:
String
):
String
@JsModule
(
"lib"
)
@JsNonModule
external
fun
g
(
x
:
Boolean
):
String
fun
box
():
String
{
val
result
=
f
(
23
)
+
f
(
"foo"
)
+
g
(
true
)
if
(
result
!=
"abc"
)
return
"fail: $result"
return
"OK"
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录