Skip to content

Commit ae26bc9

Browse files
committed
AS3ExternsGenerator, TSExternsGenerator: update
1 parent f7e0c78 commit ae26bc9

2 files changed

Lines changed: 33 additions & 18 deletions

File tree

scripts/AS3ExternsGenerator.hx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ class AS3ExternsGenerator {
204204
}
205205
if (options != null) {
206206
if (options.includedPackages != null) {
207+
final qnameLastDotIndex = qname.lastIndexOf(".");
208+
final qnamePack = qnameLastDotIndex != -1 ? qname.substr(0, qnameLastDotIndex).split(".") : [];
207209
for (includedPackage in options.includedPackages) {
208-
if (isInPackage(includedPackage.split("."), baseType.pack, false)) {
210+
if (isInPackage(includedPackage.split("."), qnamePack, false)) {
209211
if (options.excludeSymbols != null) {
210-
var qname = baseTypeToQname(baseType, []);
211212
if (options.excludeSymbols.indexOf(qname) != -1) {
212213
return true;
213214
}
@@ -219,7 +220,6 @@ class AS3ExternsGenerator {
219220
return true;
220221
}
221222
} else if (options.excludeSymbols != null) {
222-
var qname = baseTypeToQname(baseType, []);
223223
if (options.excludeSymbols.indexOf(qname) != -1) {
224224
return true;
225225
}
@@ -964,6 +964,7 @@ class AS3ExternsGenerator {
964964
}
965965

966966
private function macroTypeToQname(type:Type, includeParams:Bool = true):String {
967+
var defTypeParams:Array<Type> = null;
967968
while (type != null) {
968969
switch (type) {
969970
case TInst(t, params):
@@ -976,16 +977,16 @@ class AS3ExternsGenerator {
976977
}
977978
if (typeParamSourceQname == "Vector")
978979
{
979-
return baseTypeToQname(classType, params, includeParams);
980+
return baseTypeToQname(classType, defTypeParams != null ? defTypeParams : params, includeParams);
980981
}
981982
return "*";
982983
default:
983984
}
984-
return baseTypeToQname(classType, params, includeParams);
985+
return baseTypeToQname(classType, defTypeParams != null ? defTypeParams : params, includeParams);
985986
case TEnum(t, params):
986-
return baseTypeToQname(t.get(), params, includeParams);
987+
return baseTypeToQname(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
987988
case TAbstract(t, params):
988-
return abstractTypeToQname(t.get(), params, includeParams);
989+
return abstractTypeToQname(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
989990
case TType(t, params):
990991
var defType = t.get();
991992
if (options != null && options.renameSymbols != null) {
@@ -1010,6 +1011,9 @@ class AS3ExternsGenerator {
10101011
}
10111012
}
10121013
type = t.get().type;
1014+
if (defTypeParams == null) {
1015+
defTypeParams = params;
1016+
}
10131017
case TDynamic(t):
10141018
return "*";
10151019
case TAnonymous(a):

scripts/TSExternsGenerator.hx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ class TSExternsGenerator {
199199
}
200200
if (options != null) {
201201
if (options.includedPackages != null) {
202+
final qnameLastDotIndex = qname.lastIndexOf(".");
203+
final qnamePack = qnameLastDotIndex != -1 ? qname.substr(0, qnameLastDotIndex).split(".") : [];
202204
for (includedPackage in options.includedPackages) {
203-
if (isInPackage(includedPackage.split("."), baseType.pack, false)) {
205+
if (isInPackage(includedPackage.split("."), qnamePack, false)) {
204206
if (options.excludeSymbols != null) {
205-
var qname = baseTypeToQname(baseType, []);
206207
if (options.excludeSymbols.indexOf(qname) != -1) {
207208
return true;
208209
}
@@ -214,7 +215,6 @@ class TSExternsGenerator {
214215
return true;
215216
}
216217
} else if (options.excludeSymbols != null) {
217-
var qname = baseTypeToQname(baseType, []);
218218
if (options.excludeSymbols.indexOf(qname) != -1) {
219219
return true;
220220
}
@@ -788,6 +788,9 @@ class TSExternsGenerator {
788788
}
789789
break;
790790
case TType(t, params):
791+
for (param in params) {
792+
addMacroTypeQnamesForImport(param, qnames, pack);
793+
}
791794
var typedefType = t.get();
792795
type = typedefType.type;
793796
case TFun(args, ret):
@@ -1137,20 +1140,21 @@ class TSExternsGenerator {
11371140
}
11381141

11391142
private function macroTypeToQname(type:Type, includeParams:Bool = true):String {
1143+
var defTypeParams:Array<Type> = null;
11401144
while (type != null) {
11411145
switch (type) {
11421146
case TInst(t, params):
11431147
var classType = t.get();
11441148
switch (classType.kind) {
11451149
case KTypeParameter(constraints):
1146-
return baseTypeToUnqualifiedName(classType, params, includeParams);
1150+
return baseTypeToUnqualifiedName(classType, defTypeParams != null ? defTypeParams : params, includeParams);
11471151
default:
11481152
}
1149-
return baseTypeToQname(classType, params, includeParams);
1153+
return baseTypeToQname(classType, defTypeParams != null ? defTypeParams : params, includeParams);
11501154
case TEnum(t, params):
1151-
return baseTypeToQname(t.get(), params, includeParams);
1155+
return baseTypeToQname(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
11521156
case TAbstract(t, params):
1153-
return abstractTypeToQname(t.get(), params, includeParams);
1157+
return abstractTypeToQname(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
11541158
case TType(t, params):
11551159
var defType = t.get();
11561160
if (options != null && options.renameSymbols != null) {
@@ -1175,6 +1179,9 @@ class TSExternsGenerator {
11751179
}
11761180
}
11771181
type = t.get().type;
1182+
if (defTypeParams == null) {
1183+
defTypeParams = params;
1184+
}
11781185
case TDynamic(t):
11791186
if (t != null) {
11801187
var valueType = macroTypeToUnqualifiedName(t, includeParams);
@@ -1228,20 +1235,21 @@ class TSExternsGenerator {
12281235
}
12291236

12301237
private function macroTypeToUnqualifiedName(type:Type, includeParams:Bool = true):String {
1238+
var defTypeParams:Array<Type> = null;
12311239
while (type != null) {
12321240
switch (type) {
12331241
case TInst(t, params):
12341242
var classType = t.get();
12351243
switch (classType.kind) {
12361244
case KTypeParameter(constraints):
1237-
return baseTypeToUnqualifiedName(classType, params, includeParams);
1245+
return baseTypeToUnqualifiedName(classType, defTypeParams != null ? defTypeParams : params, includeParams);
12381246
default:
12391247
}
1240-
return baseTypeToUnqualifiedName(classType, params, includeParams);
1248+
return baseTypeToUnqualifiedName(classType, defTypeParams != null ? defTypeParams : params, includeParams);
12411249
case TEnum(t, params):
1242-
return baseTypeToUnqualifiedName(t.get(), params, includeParams);
1250+
return baseTypeToUnqualifiedName(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
12431251
case TAbstract(t, params):
1244-
return abstractTypeToUnqualifiedName(t.get(), params, includeParams);
1252+
return abstractTypeToUnqualifiedName(t.get(), defTypeParams != null ? defTypeParams : params, includeParams);
12451253
case TType(t, params):
12461254
var defType = t.get();
12471255
if (options != null && options.renameSymbols != null) {
@@ -1266,6 +1274,9 @@ class TSExternsGenerator {
12661274
}
12671275
}
12681276
type = t.get().type;
1277+
if (defTypeParams == null) {
1278+
defTypeParams = params;
1279+
}
12691280
case TDynamic(t):
12701281
if (t != null) {
12711282
var valueType = macroTypeToUnqualifiedName(t, includeParams);

0 commit comments

Comments
 (0)