Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
a72ea641
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,发现更多精彩内容 >>
提交
a72ea641
编写于
10月 28, 2016
作者:
A
Alexey Andreev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
JS: fix translation of lambdas in public inline functions; fix AMD emulation for Ant test
上级
6791ed7b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
90 addition
and
41 deletion
+90
-41
compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js
...js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js
+8
-2
js/js.frontend/src/org/jetbrains/kotlin/js/naming/NameSuggestion.kt
...tend/src/org/jetbrains/kotlin/js/naming/NameSuggestion.kt
+23
-3
js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/invocationUtils.kt
...rc/org/jetbrains/kotlin/js/inline/util/invocationUtils.kt
+12
-29
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
...etbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
+6
-0
js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/LiteralFunctionTranslator.kt
...tlin/js/translate/expression/LiteralFunctionTranslator.kt
+24
-7
js/js.translator/testData/box/crossModuleRef/lambda.kt
js/js.translator/testData/box/crossModuleRef/lambda.kt
+17
-0
未找到文件。
compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLibModuleKind/amd.js
浏览文件 @
a72ea641
...
...
@@ -4,10 +4,16 @@
function
define
(
name
,
dependencies
,
body
)
{
var
resolvedDependencies
=
[];
var
currentModule
=
{};
modules
[
name
]
=
currentModule
;
for
(
var
i
=
0
;
i
<
dependencies
.
length
;
++
i
)
{
resolvedDependencies
[
i
]
=
modules
[
dependencies
[
i
]];
var
dependencyName
=
dependencies
[
i
];
resolvedDependencies
[
i
]
=
dependencyName
===
'
exports
'
?
currentModule
:
modules
[
dependencyName
];
}
currentModule
=
body
.
apply
(
body
,
resolvedDependencies
);
if
(
currentModule
)
{
modules
[
name
]
=
currentModule
;
}
modules
[
name
]
=
body
.
apply
(
body
,
resolvedDependencies
);
}
define
.
amd
=
{};
...
...
js/js.frontend/src/org/jetbrains/kotlin/js/naming/NameSuggestion.kt
浏览文件 @
a72ea641
...
...
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.js.naming
import
org.jetbrains.kotlin.descriptors.*
import
org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import
org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
import
org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
import
org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.getNameForAnnotatedObject
import
org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils.isNativeObject
import
org.jetbrains.kotlin.resolve.DescriptorUtils
...
...
@@ -105,8 +104,29 @@ class NameSuggestion {
// Local functions and variables are always private with their own names as suggested names
is
CallableDescriptor
->
if
(
DescriptorUtils
.
isDescriptorWithLocalVisibility
(
descriptor
))
{
val
name
=
getNameForAnnotatedObject
(
descriptor
)
?:
getSuggestedName
(
descriptor
)
return
SuggestedName
(
listOf
(
name
),
false
,
descriptor
,
descriptor
.
containingDeclaration
)
val
ownName
=
getNameForAnnotatedObject
(
descriptor
)
?:
getSuggestedName
(
descriptor
)
var
name
=
ownName
var
scope
=
descriptor
.
containingDeclaration
// Local functions always lifted to the closest class or package when they are contained inside public inline function
if
(
descriptor
is
FunctionDescriptor
)
{
var
container
=
descriptor
.
containingDeclaration
var
liftedName
=
ownName
var
hasInline
=
false
while
(
container
is
FunctionDescriptor
)
{
if
(
container
.
isInline
&&
container
.
visibility
.
isPublicAPI
)
{
hasInline
=
true
}
liftedName
=
getSuggestedName
(
container
)
+
"$"
+
liftedName
container
=
container
.
containingDeclaration
}
if
(
hasInline
)
{
scope
=
container
name
=
liftedName
}
}
return
SuggestedName
(
listOf
(
name
),
false
,
descriptor
,
scope
)
}
}
...
...
js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/invocationUtils.kt
浏览文件 @
a72ea641
...
...
@@ -16,15 +16,9 @@
package
org.jetbrains.kotlin.js.inline.util
import
com.google.dart.compiler.backend.js.ast.JsInvocation
import
com.google.dart.compiler.backend.js.ast.JsName
import
com.google.dart.compiler.backend.js.ast.JsExpression
import
com.google.dart.compiler.backend.js.ast.JsNameRef
import
com.google.dart.compiler.backend.js.ast.JsFunction
import
org.jetbrains.kotlin.js.translate.context.Namer
import
com.google.dart.compiler.backend.js.ast.HasName
import
com.google.dart.compiler.backend.js.ast.JsNode
import
com.google.dart.compiler.backend.js.ast.*
import
com.google.dart.compiler.backend.js.ast.metadata.staticRef
import
org.jetbrains.kotlin.js.translate.context.Namer
/**
* Gets invocation qualifier name.
...
...
@@ -62,19 +56,6 @@ fun getSimpleIdent(call: JsInvocation): String? {
return
null
}
/**
* Checks if JsInvocation is function creator call.
*
* Function creator is a function, that creates closure.
*/
fun
isFunctionCreatorInvocation
(
invocation
:
JsInvocation
):
Boolean
{
val
staticRef
=
getStaticRef
(
invocation
)
return
when
(
staticRef
)
{
is
JsFunction
->
isFunctionCreator
(
staticRef
)
else
->
false
}
}
/**
* Tests if invocation is JavaScript call function
*
...
...
@@ -116,12 +97,6 @@ private fun getCallerQualifierImpl(invocation: JsInvocation): JsExpression? {
return
(
invocation
.
qualifier
as
?
JsNameRef
)
?.
qualifier
}
private
fun
getStaticRef
(
invocation
:
JsInvocation
):
JsNode
?
{
val
qualifier
=
invocation
.
qualifier
val
qualifierName
=
(
qualifier
as
?
HasName
)
?.
name
return
qualifierName
?.
staticRef
}
/**
* If an expression A references to another expression B, which in turn references to C, or a corresponding expression
* at the end of a chain of references. They are usually JsNameRef expressions with JsFunction at the very end.
...
...
@@ -131,8 +106,16 @@ private fun getStaticRef(invocation: JsInvocation): JsNode? {
val
JsExpression
.
transitiveStaticRef
:
JsExpression
get
()
{
var
qualifier
=
this
while
(
qualifier
is
JsNameRef
)
{
qualifier
=
qualifier
.
name
?.
staticRef
as
?
JsExpression
?:
break
loop@
while
(
true
)
{
qualifier
=
when
(
qualifier
)
{
is
JsNameRef
->
{
qualifier
.
name
?.
staticRef
as
?
JsExpression
?:
break
@loop
}
is
JsInvocation
->
{
getSimpleName
(
qualifier
)
?.
staticRef
as
?
JsExpression
?:
break
@loop
}
else
->
break
@loop
}
}
return
qualifier
}
\ No newline at end of file
js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java
浏览文件 @
a72ea641
...
...
@@ -803,6 +803,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest
(
fileName
);
}
@TestMetadata
(
"lambda.kt"
)
public
void
testLambda
()
throws
Exception
{
String
fileName
=
KotlinTestUtils
.
navigationMetadata
(
"js/js.translator/testData/box/crossModuleRef/lambda.kt"
);
doTest
(
fileName
);
}
@TestMetadata
(
"object.kt"
)
public
void
testObject
()
throws
Exception
{
String
fileName
=
KotlinTestUtils
.
navigationMetadata
(
"js/js.translator/testData/box/crossModuleRef/object.kt"
);
...
...
js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/LiteralFunctionTranslator.kt
浏览文件 @
a72ea641
...
...
@@ -62,25 +62,25 @@ class LiteralFunctionTranslator(context: TranslationContext) : AbstractTranslato
tracker
.
getNameForCapturedDescriptor
(
descriptor
)
}
else
{
context
()
.
getInnerNameForDescriptor
(
descriptor
)
invokingContext
.
getInnerNameForDescriptor
(
descriptor
)
}
if
(
tracker
.
hasCapturedExceptContaining
())
{
val
lambdaCreator
=
simpleReturnFunction
(
invokingContext
.
scope
(),
lambda
)
lambdaCreator
.
name
=
context
()
.
getInnerNameForDescriptor
(
descriptor
)
lambdaCreator
.
name
=
invokingContext
.
getInnerNameForDescriptor
(
descriptor
)
lambdaCreator
.
isLocal
=
true
if
(!
isRecursive
)
{
lambda
.
name
=
null
}
lambdaCreator
.
name
.
staticRef
=
lambdaCreator
return
lambdaCreator
.
withCapturedParameters
(
functionContext
,
invokingContext
)
return
lambdaCreator
.
withCapturedParameters
(
descriptor
,
functionContext
,
invokingContext
)
}
lambda
.
isLocal
=
true
context
()
.
addDeclarationStatement
(
lambda
.
makeStmt
())
invokingContext
.
addDeclarationStatement
(
lambda
.
makeStmt
())
lambda
.
name
.
staticRef
=
lambda
return
lambda
.
name
.
makeRef
().
apply
{
sideEffects
=
SideEffectKind
.
PURE
}
return
getReferenceToLambda
(
invokingContext
,
descriptor
,
lambda
.
name
)
}
fun
ValueParameterDescriptorImpl
.
WithDestructuringDeclaration
.
translate
(
context
:
TranslationContext
):
JsVars
{
...
...
@@ -93,9 +93,13 @@ class LiteralFunctionTranslator(context: TranslationContext) : AbstractTranslato
}
}
fun
JsFunction
.
withCapturedParameters
(
context
:
TranslationContext
,
invokingContext
:
TranslationContext
):
JsExpression
{
fun
JsFunction
.
withCapturedParameters
(
descriptor
:
CallableMemberDescriptor
,
context
:
TranslationContext
,
invokingContext
:
TranslationContext
):
JsExpression
{
context
.
addDeclarationStatement
(
makeStmt
())
val
ref
=
name
.
makeRef
().
apply
{
sideEffects
=
SideEffectKind
.
PURE
}
val
ref
=
getReferenceToLambda
(
invokingContext
,
descriptor
,
name
)
val
invocation
=
JsInvocation
(
ref
).
apply
{
sideEffects
=
SideEffectKind
.
PURE
}
val
invocationArguments
=
invocation
.
arguments
...
...
@@ -128,6 +132,19 @@ fun JsFunction.withCapturedParameters(context: TranslationContext, invokingConte
return
invocation
}
private
fun
getReferenceToLambda
(
context
:
TranslationContext
,
descriptor
:
CallableMemberDescriptor
,
name
:
JsName
):
JsExpression
{
return
if
(
context
.
isPublicInlineFunction
)
{
val
fqn
=
context
.
getQualifiedReference
(
descriptor
)
if
(
fqn
is
JsNameRef
)
{
fqn
.
name
?.
let
{
it
.
staticRef
=
name
.
staticRef
}
}
fqn
}
else
{
JsAstUtils
.
pureFqn
(
name
,
null
)
}
}
private
data class
CapturedArgsParams
(
val
arguments
:
List
<
JsExpression
>
=
listOf
(),
val
parameters
:
List
<
JsParameter
>
=
listOf
())
/**
...
...
js/js.translator/testData/box/crossModuleRef/lambda.kt
0 → 100644
浏览文件 @
a72ea641
// MODULE: lib
// FILE: lib.kt
package
lib
fun
bar
(
f
:
()
->
String
)
=
f
()
inline
fun
foo
():
String
{
return
bar
{
"OK"
}
}
// MODULE: main(lib)
// FILE: main.kt
package
main
import
lib.*
fun
box
()
=
foo
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录