Skip to content

Commit 00dcb51

Browse files
committed
ExternsGenerators: Add includedSymbols
1 parent ebf4888 commit 00dcb51

4 files changed

Lines changed: 73 additions & 3 deletions

File tree

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ lib-esm/_gen/
3333
lib/**/*.as
3434
lib/**/*.d.ts
3535
!lib/**/index.d.ts
36+
!lib/flash/display/ShaderData.as
37+
!lib/flash/net/navigateToURL.as
38+
!lib/flash/net/sendToURL.as
39+
!lib/flash/net/URLVariables.as
40+
!lib/flash/utils/clearTimeout.as
41+
!lib/flash/utils/Dictionary.as
42+
!lib/flash/utils/getDefinitionByName.as
43+
!lib/flash/utils/getQualifiedClassName.as
44+
!lib/flash/utils/getQualifiedSuperclassName.as
45+
!lib/flash/utils/getTimer.as
46+
!lib/flash/utils/setTimeout.as
3647
test/**/bundle.js
3748
npm-debug.log
3849
*.map

scripts/AS3ExternsGenerator.hx

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ class AS3ExternsGenerator {
214214
return true;
215215
}
216216
if (options != null) {
217+
if (options.includedSymbols != null) {
218+
for (includedSymbol in options.includedSymbols) {
219+
if (qname == includedSymbol) {
220+
return false;
221+
}
222+
}
223+
}
217224
if (options.includedPackages != null) {
218225
final qnameLastDotIndex = qname.lastIndexOf(".");
219226
final qnamePack = qnameLastDotIndex != -1 ? qname.substr(0, qnameLastDotIndex).split(".") : [];
@@ -965,10 +972,39 @@ class AS3ExternsGenerator {
965972
return true;
966973
}
967974
var qname = baseTypeToQname(baseType, []);
968-
if (qname.indexOf(".") == -1) {
975+
if (qname.indexOf(".") == -1 && ALWAYS_ALLOWED_REFERENCE_TYPES.indexOf(baseType.name) != -1) {
969976
return true;
970977
}
971-
if (isInPackage(currentPackage, baseType.pack, true)) {
978+
var baseTypePack = baseType.pack;
979+
var i = 0;
980+
if (options != null && options.renameSymbols != null) {
981+
var renameSymbols = options.renameSymbols;
982+
while (i < renameSymbols.length) {
983+
var originalName = renameSymbols[i];
984+
i++;
985+
var newName = renameSymbols[i];
986+
i++;
987+
if (baseTypePack.indexOf(originalName) != -1) {
988+
baseTypePack[baseTypePack.indexOf(originalName)] = newName;
989+
break;
990+
}
991+
}
992+
}
993+
if (options != null && options.renamePackages != null) {
994+
i = 0;
995+
var renamePackages = options.renamePackages;
996+
while (i < renamePackages.length) {
997+
var originalName = renamePackages[i];
998+
i++;
999+
var newName = renamePackages[i];
1000+
i++;
1001+
if (baseTypePack.indexOf(originalName) != -1) {
1002+
baseTypePack[baseTypePack.indexOf(originalName)] = newName;
1003+
break;
1004+
}
1005+
}
1006+
}
1007+
if (isInPackage(currentPackage, baseTypePack, true)) {
9721008
return true;
9731009
}
9741010
return false;
@@ -1273,6 +1309,14 @@ typedef AS3GeneratorOptions = {
12731309
**/
12741310
?includedPackages:Array<String>,
12751311

1312+
/**
1313+
Externs will be generated for symbols specified.
1314+
1315+
Types from other packages may still be referenced by fields or method
1316+
signatures. Use `allowedPackageReferences` to restrict those too.
1317+
**/
1318+
?includedSymbols:Array<String>,
1319+
12761320
/**
12771321
When `includedPackages` is not empty, `allowedPackageReferences` may
12781322
be used to allow types from other packages to be used for field types,

scripts/TSExternsGenerator.hx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ class TSExternsGenerator {
198198
return true;
199199
}
200200
if (options != null) {
201+
if (options.includedSymbols != null) {
202+
for (includedSymbol in options.includedSymbols) {
203+
if (qname == includedSymbol) {
204+
return false;
205+
}
206+
}
207+
}
201208
if (options.includedPackages != null) {
202209
final qnameLastDotIndex = qname.lastIndexOf(".");
203210
final qnamePack = qnameLastDotIndex != -1 ? qname.substr(0, qnameLastDotIndex).split(".") : [];
@@ -1576,6 +1583,14 @@ typedef TSGeneratorOptions = {
15761583
**/
15771584
?includedPackages:Array<String>,
15781585

1586+
/**
1587+
Externs will be generated for symbols specified.
1588+
1589+
Types from other packages may still be referenced by fields or method
1590+
signatures. Use `allowedPackageReferences` to restrict those too.
1591+
**/
1592+
?includedSymbols:Array<String>,
1593+
15791594
/**
15801595
When `includedPackages` is not empty, `allowedPackageReferences` may
15811596
be used to allow types from other packages to be used for field types,

scripts/build.hxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
-D webgl1
3636
--macro AS3ExternsGenerator.generate({outputPath: "../lib", includedPackages: ["openfl"], allowedPackageReferences: [], renameSymbols: ["openfl.VectorData", "openfl.Vector", "openfl.utils.ByteArrayData", "openfl.utils.ByteArray", "lime.app.Future", "openfl.utils.Future"]})
3737
--macro TSExternsGenerator.generate({outputPath: "../lib", includedPackages: ["openfl"], allowedPackageReferences: [], renameSymbols: ["openfl.VectorData", "openfl.Vector", "openfl.utils.ByteArrayData", "openfl.utils.ByteArray", "lime.app.Future", "openfl.utils.Future"]})
38-
--macro AS3ExternsGenerator.generate({outputPath: "../lib", includedPackages: ["flash"], allowedPackageReferences: [], renameSymbols: ["flash.VectorData", "flash.Vector", "flash.utils.ByteArrayData", "flash.utils.ByteArray", "lime.app.Future", "flash.utils.Future", "flash.errors.IllegalOperationError", "IllegalOperationError", "flash.errors.IOError", "IOError", "flash.errors.ArgumentError", "ArgumentError", "flash.errors.SecurityError", "SecurityError"], renamePackages: ["openfl", "flash"]})
38+
--macro AS3ExternsGenerator.generate({outputPath: "../lib", includedPackages: ["flash"], includedSymbols: ["ArgumentError", "SecurityError"], allowedPackageReferences: [], renameSymbols: ["flash.VectorData", "flash.Vector", "flash.utils.ByteArrayData", "flash.utils.ByteArray", "lime.app.Future", "flash.utils.Future", "flash.errors.ArgumentError", "ArgumentError", "flash.errors.SecurityError", "SecurityError"], renamePackages: ["openfl", "flash"]})
3939
--no-inline

0 commit comments

Comments
 (0)