JS: fix bootstrap
This commit is contained in:
@@ -876,6 +876,11 @@ public final class StaticContext {
|
||||
|
||||
@NotNull
|
||||
public JsExpression getReferenceToIntrinsic(@NotNull String name) {
|
||||
return pureFqn(getNameForIntrinsic(name), null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsName getNameForIntrinsic(@NotNull String name) {
|
||||
JsName resultName = intrinsicNames.computeIfAbsent(name, k -> {
|
||||
if (isStdlib) {
|
||||
DeclarationDescriptor descriptor = findDescriptorForIntrinsic(name);
|
||||
@@ -886,7 +891,7 @@ public final class StaticContext {
|
||||
return importDeclaration(NameSuggestion.sanitizeName(name), "intrinsic:" + name, TranslationUtils.getIntrinsicFqn(name));
|
||||
});
|
||||
|
||||
return pureFqn(resultName, null);
|
||||
return resultName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+10
-4
@@ -328,25 +328,31 @@ public class TranslationContext {
|
||||
|
||||
@NotNull
|
||||
public JsExpression getReferenceToIntrinsic(@NotNull String intrinsicName) {
|
||||
JsExpression result;
|
||||
return pureFqn(getNameForIntrinsic(intrinsicName), null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsName getNameForIntrinsic(@NotNull String intrinsicName) {
|
||||
JsName result;
|
||||
if (inlineFunctionContext == null || !isPublicInlineFunction()) {
|
||||
result = staticContext.getReferenceToIntrinsic(intrinsicName);
|
||||
result = staticContext.getNameForIntrinsic(intrinsicName);
|
||||
}
|
||||
else {
|
||||
String tag = "intrinsic:" + intrinsicName;
|
||||
result = pureFqn(inlineFunctionContext.getImports().computeIfAbsent(tag, t -> {
|
||||
result = inlineFunctionContext.getImports().computeIfAbsent(tag, t -> {
|
||||
JsExpression imported = TranslationUtils.getIntrinsicFqn(intrinsicName);
|
||||
|
||||
JsName name = JsScope.declareTemporaryName(NameSuggestion.sanitizeName(intrinsicName));
|
||||
MetadataProperties.setImported(name, true);
|
||||
inlineFunctionContext.getImportBlock().getStatements().add(JsAstUtils.newVar(name, imported));
|
||||
return name;
|
||||
}), null);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public JsName getNameForObjectInstance(@NotNull ClassDescriptor descriptor) {
|
||||
return staticContext.getNameForObjectInstance(descriptor);
|
||||
|
||||
+7
-1
@@ -289,7 +289,13 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
public static JsExpression getObjectKClass(@NotNull TranslationContext context, @Nullable ClassifierDescriptor descriptor) {
|
||||
JsExpression primitiveExpression = getPrimitiveClass(context, descriptor);
|
||||
if (primitiveExpression != null) return primitiveExpression;
|
||||
return new JsInvocation(context.getNameForSpecialFunction(SpecialFunction.GET_KCLASS).makeRef(), UtilsKt.getReferenceToJsClass(descriptor, context));
|
||||
|
||||
// getKClass should be imported as intrinsic when used outside of inline context, otherwise bootstrap fails.
|
||||
// Inside an inline function it should however be marked as SpecialFunction to support T::class when T -> Int (KT-32215)
|
||||
JsName kClassName = context.getNameForIntrinsic(SpecialFunction.GET_KCLASS.getSuggestedName());
|
||||
MetadataProperties.setSpecialFunction(kClassName, SpecialFunction.GET_KCLASS);
|
||||
|
||||
return new JsInvocation(kClassName.makeRef(), UtilsKt.getReferenceToJsClass(descriptor, context));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user