summaryrefslogtreecommitdiff
path: root/cpp/src/slice2js
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2018-11-22 21:36:37 +0100
committerJose <jose@zeroc.com>2018-11-22 21:42:20 +0100
commit6e53fc191bbcdd999021d8c0e9542171f63a593c (patch)
tree5a18415751b3ba395bebd0e16bd62358d787151e /cpp/src/slice2js
parenttypescript: missing ice_cause in Ice.Exception (diff)
downloadice-6e53fc191bbcdd999021d8c0e9542171f63a593c.tar.bz2
ice-6e53fc191bbcdd999021d8c0e9542171f63a593c.tar.xz
ice-6e53fc191bbcdd999021d8c0e9542171f63a593c.zip
typescript: don't generate Prx definiton for Class without operations
Close #302
Diffstat (limited to 'cpp/src/slice2js')
-rw-r--r--cpp/src/slice2js/Gen.cpp181
-rw-r--r--cpp/src/slice2js/JsUtil.cpp34
2 files changed, 115 insertions, 100 deletions
diff --git a/cpp/src/slice2js/Gen.cpp b/cpp/src/slice2js/Gen.cpp
index c3cc7810599..28f1bc41e9b 100644
--- a/cpp/src/slice2js/Gen.cpp
+++ b/cpp/src/slice2js/Gen.cpp
@@ -2796,114 +2796,115 @@ Slice::Gen::TypeScriptVisitor::visitClassDefStart(const ClassDefPtr& p)
}
else
{
- //
- // Define servant an proxy types for non local classes
- //
- _out << sp;
- _out << nl << "abstract class " << fixId(p->name() + "Prx")
- << " extends " << icePrefix << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix);
- _out << sb;
const OperationList ops = p->allOperations();
- for(OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q)
+ if(p->isInterface() || !ops.empty())
{
- const OperationPtr op = *q;
- const ParamDeclList paramList = op->parameters();
- const TypePtr ret = op->returnType();
- ParamDeclList inParams, outParams;
- for(ParamDeclList::const_iterator r = paramList.begin(); r != paramList.end(); ++r)
+ //
+ // Define servant an proxy types for non local classes
+ //
+ _out << sp;
+ _out << nl << "abstract class " << fixId(p->name() + "Prx")
+ << " extends " << icePrefix << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix);
+ _out << sb;
+
+ for(OperationList::const_iterator q = ops.begin(); q != ops.end(); ++q)
{
- if((*r)->isOutParam())
+ const OperationPtr op = *q;
+ const ParamDeclList paramList = op->parameters();
+ const TypePtr ret = op->returnType();
+ ParamDeclList inParams, outParams;
+ for(ParamDeclList::const_iterator r = paramList.begin(); r != paramList.end(); ++r)
{
- outParams.push_back(*r);
+ if((*r)->isOutParam())
+ {
+ outParams.push_back(*r);
+ }
+ else
+ {
+ inParams.push_back(*r);
+ }
}
- else
+
+ const string contextParam = escapeParam(paramList, "context");
+ CommentPtr comment = op->parseComment(false);
+ const string contextDoc = "@param " + contextParam + " The Context map to send with the invocation.";
+ const string asyncDoc = "The asynchronous result object for the invocation.";
+ if(comment)
{
- inParams.push_back(*r);
+ StringList postParams, returns;
+ postParams.push_back(contextDoc);
+ returns.push_back(asyncDoc);
+ writeOpDocSummary(_out, op, comment, OpDocInParams, false, StringList(), postParams, returns);
}
- }
-
- const string contextParam = escapeParam(paramList, "context");
- CommentPtr comment = op->parseComment(false);
- const string contextDoc = "@param " + contextParam + " The Context map to send with the invocation.";
- const string asyncDoc = "The asynchronous result object for the invocation.";
- if(comment)
- {
- StringList postParams, returns;
- postParams.push_back(contextDoc);
- returns.push_back(asyncDoc);
- writeOpDocSummary(_out, op, comment, OpDocInParams, false, StringList(), postParams, returns);
- }
- _out << nl << fixId((*q)->name()) << spar;
- for(ParamDeclList::const_iterator r = inParams.begin(); r != inParams.end(); ++r)
- {
- _out << (fixId((*r)->name()) +
- ((*r)->optional() ? "?" : "") +
- ":" +
- typeToString((*r)->type(), p, imports(), true, false, true));
- }
- _out << "context?:Map<string, string>";
- _out << epar;
-
- _out << ":" << icePrefix << getUnqualified("Ice.AsyncResult", p->scope(), icePrefix);
- if(!ret && outParams.empty())
- {
- _out << "<void>";
- }
- else if((ret && outParams.empty()) || (!ret && outParams.size() == 1))
- {
- TypePtr t = ret ? ret : outParams.front()->type();
- _out << "<" << typeToString(t, p, imports(), true, false, true) << ">";
- }
- else
- {
- _out << "<[";
- if(ret)
+ _out << nl << fixId((*q)->name()) << spar;
+ for(ParamDeclList::const_iterator r = inParams.begin(); r != inParams.end(); ++r)
{
- _out << typeToString(ret, p, imports(), true, false, true) << ", ";
+ _out << (fixId((*r)->name()) +
+ ((*r)->optional() ? "?" : "") +
+ ":" +
+ typeToString((*r)->type(), p, imports(), true, false, true));
}
+ _out << "context?:Map<string, string>";
+ _out << epar;
- for(ParamDeclList::const_iterator i = outParams.begin(); i != outParams.end();)
+ _out << ":" << icePrefix << getUnqualified("Ice.AsyncResult", p->scope(), icePrefix);
+ if(!ret && outParams.empty())
+ {
+ _out << "<void>";
+ }
+ else if((ret && outParams.empty()) || (!ret && outParams.size() == 1))
+ {
+ TypePtr t = ret ? ret : outParams.front()->type();
+ _out << "<" << typeToString(t, p, imports(), true, false, true) << ">";
+ }
+ else
{
- _out << typeToString((*i)->type(), p, imports(), true, false, true);
- if(++i != outParams.end())
+ _out << "<[";
+ if(ret)
{
- _out << ", ";
+ _out << typeToString(ret, p, imports(), true, false, true) << ", ";
+ }
+
+ for(ParamDeclList::const_iterator i = outParams.begin(); i != outParams.end();)
+ {
+ _out << typeToString((*i)->type(), p, imports(), true, false, true);
+ if(++i != outParams.end())
+ {
+ _out << ", ";
+ }
}
+
+ _out << "]>";
}
- _out << "]>";
+ _out << ";";
}
- _out << ";";
- }
-
- const string icePrefix = importPrefix("Ice.ObjectPrx", p);
- _out << sp;
- _out << nl << "/**";
- _out << nl << " * Downcasts a proxy without confirming the target object's type via a remote invocation.";
- _out << nl << " * @param prx The target proxy.";
- _out << nl << " * @return A proxy with the requested type.";
- _out << nl << " */";
- _out << nl << "static uncheckedCast(prx:" << icePrefix
- << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix) << ", "
- << "facet?:string):"
- << fixId(p->name() + "Prx") << ";";
- _out << nl << "/**";
- _out << nl << " * Downcasts a proxy after confirming the target object's type via a remote invocation.";
- _out << nl << " * @param prx The target proxy.";
- _out << nl << " * @param facet A facet name.";
- _out << nl << " * @param context The context map for the invocation.";
- _out << nl << " * @return A proxy with the requested type and facet, or nil if the target proxy is nil or the target";
- _out << nl << " * object does not support the requested type.";
- _out << nl << " */";
- _out << nl << "static checkedCast(prx:" << icePrefix
- << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix) << ", "
- << "facet?:string, contex?:Map<string, string>):" << icePrefix
- << getUnqualified("Ice.AsyncResult", p->scope(), icePrefix) << "<" << fixId(p->name() + "Prx") << ">;";
- _out << eb;
+ const string icePrefix = importPrefix("Ice.ObjectPrx", p);
+ _out << sp;
+ _out << nl << "/**";
+ _out << nl << " * Downcasts a proxy without confirming the target object's type via a remote invocation.";
+ _out << nl << " * @param prx The target proxy.";
+ _out << nl << " * @return A proxy with the requested type.";
+ _out << nl << " */";
+ _out << nl << "static uncheckedCast(prx:" << icePrefix
+ << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix) << ", "
+ << "facet?:string):"
+ << fixId(p->name() + "Prx") << ";";
+ _out << nl << "/**";
+ _out << nl << " * Downcasts a proxy after confirming the target object's type via a remote invocation.";
+ _out << nl << " * @param prx The target proxy.";
+ _out << nl << " * @param facet A facet name.";
+ _out << nl << " * @param context The context map for the invocation.";
+ _out << nl << " * @return A proxy with the requested type and facet, or nil if the target proxy is nil or the target";
+ _out << nl << " * object does not support the requested type.";
+ _out << nl << " */";
+ _out << nl << "static checkedCast(prx:" << icePrefix
+ << getUnqualified("Ice.ObjectPrx", p->scope(), icePrefix) << ", "
+ << "facet?:string, contex?:Map<string, string>):" << icePrefix
+ << getUnqualified("Ice.AsyncResult", p->scope(), icePrefix) << "<" << fixId(p->name() + "Prx") << ">;";
+ _out << eb;
- if(p->isInterface() || !ops.empty())
- {
_out << sp;
_out << nl << "abstract class " << fixId(p->name() + (p->isInterface() ? "" : "Disp"))
<< " extends " << icePrefix << getUnqualified("Ice.Object", p->scope(), icePrefix);
diff --git a/cpp/src/slice2js/JsUtil.cpp b/cpp/src/slice2js/JsUtil.cpp
index c1f6e6912fe..002919087f0 100644
--- a/cpp/src/slice2js/JsUtil.cpp
+++ b/cpp/src/slice2js/JsUtil.cpp
@@ -520,20 +520,34 @@ Slice::JsGenerator::typeToString(const TypePtr& type,
if(proxy)
{
ostringstream os;
- string prefix;
- if(typescript)
+ ClassDefPtr def = proxy->_class()->definition();
+ if(!def->isInterface() && def->allOperations().empty())
{
- prefix = importPrefix(ContainedPtr::dynamicCast(proxy->_class()->definition()), toplevel, imports);
- os << prefix;
- }
-
- if(prefix.empty() && typescript)
- {
- os << getUnqualified(fixId(proxy->_class()->scoped() + "Prx"), toplevel->scope(), prefix);
+ if(getModuleMetadata(toplevel) != "ice")
+ {
+ os << "iceNS0.";
+ }
+ os << getUnqualified(typeScriptBuiltinTable[Builtin::KindObjectProxy],
+ toplevel->scope(),
+ getModuleMetadata(toplevel));
}
else
{
- os << fixId(proxy->_class()->scoped() + "Prx");
+ string prefix;
+ if(typescript)
+ {
+ prefix = importPrefix(ContainedPtr::dynamicCast(def), toplevel, imports);
+ os << prefix;
+ }
+
+ if(prefix.empty() && typescript)
+ {
+ os << getUnqualified(fixId(proxy->_class()->scoped() + "Prx"), toplevel->scope(), prefix);
+ }
+ else
+ {
+ os << fixId(proxy->_class()->scoped() + "Prx");
+ }
}
return os.str();
}