dismantle 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/cjs/development/index.cjs +148 -104
  2. package/dist/cjs/development/index.cjs.map +2 -2
  3. package/dist/cjs/development/runtime.cjs +32 -1928
  4. package/dist/cjs/development/runtime.cjs.map +4 -4
  5. package/dist/cjs/production/index.cjs +1 -1
  6. package/dist/cjs/production/runtime.cjs +1 -1
  7. package/dist/esm/development/index.mjs +148 -104
  8. package/dist/esm/development/index.mjs.map +2 -2
  9. package/dist/esm/development/runtime.mjs +29 -1915
  10. package/dist/esm/development/runtime.mjs.map +4 -4
  11. package/dist/esm/production/index.mjs +1 -1
  12. package/dist/esm/production/runtime.mjs +1 -1
  13. package/dist/types/runtime/index.d.ts +10 -0
  14. package/dist/types/runtime/index.d.ts.map +1 -0
  15. package/dist/types/src/hidden-imports.d.ts.map +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -0
  17. package/dist/types/src/plugin.d.ts.map +1 -0
  18. package/dist/types/src/split-block-directive.d.ts.map +1 -0
  19. package/dist/types/src/split-call.d.ts.map +1 -0
  20. package/dist/types/src/split-function-directive.d.ts.map +1 -0
  21. package/dist/types/{split.d.ts → src/split.d.ts} +1 -1
  22. package/dist/types/src/split.d.ts.map +1 -0
  23. package/dist/types/src/transform-block-directive.d.ts.map +1 -0
  24. package/dist/types/src/transform-call.d.ts.map +1 -0
  25. package/dist/types/src/transform-function-directive.d.ts.map +1 -0
  26. package/dist/types/{types.d.ts → src/types.d.ts} +4 -0
  27. package/dist/types/src/types.d.ts.map +1 -0
  28. package/dist/types/src/utils/assert.d.ts.map +1 -0
  29. package/dist/types/src/utils/bubble-function-declaration.d.ts.map +1 -0
  30. package/dist/types/src/utils/directive-check.d.ts.map +1 -0
  31. package/dist/types/src/utils/generate-unique-name.d.ts.map +1 -0
  32. package/dist/types/src/utils/generator-shim.d.ts.map +1 -0
  33. package/dist/types/src/utils/get-descriptive-name.d.ts.map +1 -0
  34. package/dist/types/src/utils/get-foreign-bindings.d.ts.map +1 -0
  35. package/dist/types/src/utils/get-identifiers-from-lval.d.ts.map +1 -0
  36. package/dist/types/src/utils/get-import-identifier.d.ts.map +1 -0
  37. package/dist/types/src/utils/get-import-specifier-name.d.ts.map +1 -0
  38. package/dist/types/src/utils/get-module-definition.d.ts.map +1 -0
  39. package/dist/types/src/utils/get-root-statement-path.d.ts.map +1 -0
  40. package/dist/types/src/utils/is-statement-top-level.d.ts.map +1 -0
  41. package/dist/types/src/utils/register-import-specifiers.d.ts.map +1 -0
  42. package/dist/types/src/utils/unwrap.d.ts.map +1 -0
  43. package/dist/types/src/utils/xxhash32.d.ts.map +1 -0
  44. package/package.json +10 -12
  45. package/src/split-block-directive.ts +52 -37
  46. package/src/split-call.ts +45 -30
  47. package/src/split-function-directive.ts +44 -30
  48. package/src/split.ts +2 -1
  49. package/src/types.ts +4 -0
  50. package/dist/types/hidden-imports.d.ts.map +0 -1
  51. package/dist/types/index.d.ts.map +0 -1
  52. package/dist/types/plugin.d.ts.map +0 -1
  53. package/dist/types/split-block-directive.d.ts.map +0 -1
  54. package/dist/types/split-call.d.ts.map +0 -1
  55. package/dist/types/split-function-directive.d.ts.map +0 -1
  56. package/dist/types/split.d.ts.map +0 -1
  57. package/dist/types/transform-block-directive.d.ts.map +0 -1
  58. package/dist/types/transform-call.d.ts.map +0 -1
  59. package/dist/types/transform-function-directive.d.ts.map +0 -1
  60. package/dist/types/types.d.ts.map +0 -1
  61. package/dist/types/utils/assert.d.ts.map +0 -1
  62. package/dist/types/utils/bubble-function-declaration.d.ts.map +0 -1
  63. package/dist/types/utils/directive-check.d.ts.map +0 -1
  64. package/dist/types/utils/generate-unique-name.d.ts.map +0 -1
  65. package/dist/types/utils/generator-shim.d.ts.map +0 -1
  66. package/dist/types/utils/get-descriptive-name.d.ts.map +0 -1
  67. package/dist/types/utils/get-foreign-bindings.d.ts.map +0 -1
  68. package/dist/types/utils/get-identifiers-from-lval.d.ts.map +0 -1
  69. package/dist/types/utils/get-import-identifier.d.ts.map +0 -1
  70. package/dist/types/utils/get-import-specifier-name.d.ts.map +0 -1
  71. package/dist/types/utils/get-module-definition.d.ts.map +0 -1
  72. package/dist/types/utils/get-root-statement-path.d.ts.map +0 -1
  73. package/dist/types/utils/is-statement-top-level.d.ts.map +0 -1
  74. package/dist/types/utils/register-import-specifiers.d.ts.map +0 -1
  75. package/dist/types/utils/unwrap.d.ts.map +0 -1
  76. package/dist/types/utils/xxhash32.d.ts.map +0 -1
  77. /package/dist/types/{hidden-imports.d.ts → src/hidden-imports.d.ts} +0 -0
  78. /package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
  79. /package/dist/types/{plugin.d.ts → src/plugin.d.ts} +0 -0
  80. /package/dist/types/{split-block-directive.d.ts → src/split-block-directive.d.ts} +0 -0
  81. /package/dist/types/{split-call.d.ts → src/split-call.d.ts} +0 -0
  82. /package/dist/types/{split-function-directive.d.ts → src/split-function-directive.d.ts} +0 -0
  83. /package/dist/types/{transform-block-directive.d.ts → src/transform-block-directive.d.ts} +0 -0
  84. /package/dist/types/{transform-call.d.ts → src/transform-call.d.ts} +0 -0
  85. /package/dist/types/{transform-function-directive.d.ts → src/transform-function-directive.d.ts} +0 -0
  86. /package/dist/types/{utils → src/utils}/assert.d.ts +0 -0
  87. /package/dist/types/{utils → src/utils}/bubble-function-declaration.d.ts +0 -0
  88. /package/dist/types/{utils → src/utils}/directive-check.d.ts +0 -0
  89. /package/dist/types/{utils → src/utils}/generate-unique-name.d.ts +0 -0
  90. /package/dist/types/{utils → src/utils}/generator-shim.d.ts +0 -0
  91. /package/dist/types/{utils → src/utils}/get-descriptive-name.d.ts +0 -0
  92. /package/dist/types/{utils → src/utils}/get-foreign-bindings.d.ts +0 -0
  93. /package/dist/types/{utils → src/utils}/get-identifiers-from-lval.d.ts +0 -0
  94. /package/dist/types/{utils → src/utils}/get-import-identifier.d.ts +0 -0
  95. /package/dist/types/{utils → src/utils}/get-import-specifier-name.d.ts +0 -0
  96. /package/dist/types/{utils → src/utils}/get-module-definition.d.ts +0 -0
  97. /package/dist/types/{utils → src/utils}/get-root-statement-path.d.ts +0 -0
  98. /package/dist/types/{utils → src/utils}/is-statement-top-level.d.ts +0 -0
  99. /package/dist/types/{utils → src/utils}/register-import-specifiers.d.ts +0 -0
  100. /package/dist/types/{utils → src/utils}/unwrap.d.ts +0 -0
  101. /package/dist/types/{utils → src/utils}/xxhash32.d.ts +0 -0
@@ -427,8 +427,8 @@ function createRootFile(ctx, bindings, replacement) {
427
427
  );
428
428
  return rootFile;
429
429
  }
430
- function createEntryFile(ctx, path2, rootFile, imported) {
431
- let id = `${ctx.blocks.hash}-${ctx.blocks.count++}`;
430
+ function createEntryFile(ctx, path2, rootFile, imported, idPrefix) {
431
+ let id = `${idPrefix || ""}${ctx.blocks.hash}-${ctx.blocks.count++}`;
432
432
  if (ctx.options.env !== "production") {
433
433
  id += `-${getDescriptiveName(path2, "anonymous")}`;
434
434
  }
@@ -809,24 +809,32 @@ function getBlockDirectiveReplacement(ctx, path2, entryFile, bindings, halting)
809
809
  t9.variableDeclaration("const", [
810
810
  t9.variableDeclarator(
811
811
  blockID,
812
- t9.callExpression(getImportIdentifier(ctx, path2, HIDDEN_GENERATOR), [
813
- t9.memberExpression(
814
- t9.awaitExpression(t9.importExpression(t9.stringLiteral(entryFile))),
815
- t9.identifier("default")
816
- ),
817
- bindings.mutations.length ? t9.arrowFunctionExpression(
818
- [returnMutations],
819
- t9.assignmentExpression(
820
- "=",
821
- t9.objectPattern(
822
- bindings.mutations.map(
823
- (item) => t9.objectProperty(item, item, false, true)
824
- )
812
+ t9.callExpression(
813
+ getImportIdentifier(ctx, path2, {
814
+ ...HIDDEN_GENERATOR,
815
+ source: ctx.options.runtime
816
+ }),
817
+ [
818
+ t9.memberExpression(
819
+ t9.awaitExpression(
820
+ t9.importExpression(t9.stringLiteral(entryFile))
825
821
  ),
826
- returnMutations
827
- )
828
- ) : t9.nullLiteral()
829
- ])
822
+ t9.identifier("default")
823
+ ),
824
+ bindings.mutations.length ? t9.arrowFunctionExpression(
825
+ [returnMutations],
826
+ t9.assignmentExpression(
827
+ "=",
828
+ t9.objectPattern(
829
+ bindings.mutations.map(
830
+ (item) => t9.objectProperty(item, item, false, true)
831
+ )
832
+ ),
833
+ returnMutations
834
+ )
835
+ ) : t9.nullLiteral()
836
+ ]
837
+ )
830
838
  )
831
839
  ])
832
840
  );
@@ -853,26 +861,32 @@ function getBlockDirectiveReplacement(ctx, path2, entryFile, bindings, halting)
853
861
  t9.arrayPattern([returnType, returnResult]),
854
862
  t9.awaitExpression(
855
863
  t9.callExpression(
856
- t9.callExpression(getImportIdentifier(ctx, path2, HIDDEN_FUNC), [
857
- t9.memberExpression(
858
- t9.awaitExpression(
859
- t9.importExpression(t9.stringLiteral(entryFile))
860
- ),
861
- t9.identifier("default")
862
- ),
863
- bindings.mutations.length ? t9.arrowFunctionExpression(
864
- [returnMutations],
865
- t9.assignmentExpression(
866
- "=",
867
- t9.objectPattern(
868
- bindings.mutations.map(
869
- (item) => t9.objectProperty(item, item, false, true)
870
- )
864
+ t9.callExpression(
865
+ getImportIdentifier(ctx, path2, {
866
+ ...HIDDEN_FUNC,
867
+ source: ctx.options.runtime
868
+ }),
869
+ [
870
+ t9.memberExpression(
871
+ t9.awaitExpression(
872
+ t9.importExpression(t9.stringLiteral(entryFile))
871
873
  ),
872
- returnMutations
873
- )
874
- ) : t9.nullLiteral()
875
- ]),
874
+ t9.identifier("default")
875
+ ),
876
+ bindings.mutations.length ? t9.arrowFunctionExpression(
877
+ [returnMutations],
878
+ t9.assignmentExpression(
879
+ "=",
880
+ t9.objectPattern(
881
+ bindings.mutations.map(
882
+ (item) => t9.objectProperty(item, item, false, true)
883
+ )
884
+ ),
885
+ returnMutations
886
+ )
887
+ ) : t9.nullLiteral()
888
+ ]
889
+ ),
876
890
  bindings.locals
877
891
  )
878
892
  )
@@ -901,7 +915,8 @@ function replaceBlockDirective(ctx, path2, directive, bindings) {
901
915
  true
902
916
  )
903
917
  ) : void 0,
904
- directive.target
918
+ directive.target,
919
+ directive.idPrefix
905
920
  );
906
921
  path2.replaceWith(
907
922
  getBlockDirectiveReplacement(ctx, path2, entryFile, bindings, halting)
@@ -1089,21 +1104,27 @@ function getFunctionReplacement(ctx, path2, entryFile, bindings) {
1089
1104
  t11.variableDeclaration("const", [
1090
1105
  t11.variableDeclarator(
1091
1106
  funcID,
1092
- t11.callExpression(getImportIdentifier(ctx, path2, HIDDEN_GENERATOR), [
1093
- source,
1094
- bindings.mutations.length ? t11.arrowFunctionExpression(
1095
- [returnMutations],
1096
- t11.assignmentExpression(
1097
- "=",
1098
- t11.objectPattern(
1099
- bindings.mutations.map(
1100
- (item) => t11.objectProperty(item, item, false, true)
1101
- )
1102
- ),
1103
- returnMutations
1104
- )
1105
- ) : t11.nullLiteral()
1106
- ])
1107
+ t11.callExpression(
1108
+ getImportIdentifier(ctx, path2, {
1109
+ ...HIDDEN_GENERATOR,
1110
+ source: ctx.options.runtime
1111
+ }),
1112
+ [
1113
+ source,
1114
+ bindings.mutations.length ? t11.arrowFunctionExpression(
1115
+ [returnMutations],
1116
+ t11.assignmentExpression(
1117
+ "=",
1118
+ t11.objectPattern(
1119
+ bindings.mutations.map(
1120
+ (item) => t11.objectProperty(item, item, false, true)
1121
+ )
1122
+ ),
1123
+ returnMutations
1124
+ )
1125
+ ) : t11.nullLiteral()
1126
+ ]
1127
+ )
1107
1128
  )
1108
1129
  ])
1109
1130
  );
@@ -1129,21 +1150,27 @@ function getFunctionReplacement(ctx, path2, entryFile, bindings) {
1129
1150
  t11.arrayPattern([returnType, returnResult]),
1130
1151
  t11.awaitExpression(
1131
1152
  t11.callExpression(
1132
- t11.callExpression(getImportIdentifier(ctx, path2, HIDDEN_FUNC), [
1133
- source,
1134
- bindings.mutations.length ? t11.arrowFunctionExpression(
1135
- [returnMutations],
1136
- t11.assignmentExpression(
1137
- "=",
1138
- t11.objectPattern(
1139
- bindings.mutations.map(
1140
- (item) => t11.objectProperty(item, item, false, true)
1141
- )
1142
- ),
1143
- returnMutations
1144
- )
1145
- ) : t11.nullLiteral()
1146
- ]),
1153
+ t11.callExpression(
1154
+ getImportIdentifier(ctx, path2, {
1155
+ ...HIDDEN_FUNC,
1156
+ source: ctx.options.runtime
1157
+ }),
1158
+ [
1159
+ source,
1160
+ bindings.mutations.length ? t11.arrowFunctionExpression(
1161
+ [returnMutations],
1162
+ t11.assignmentExpression(
1163
+ "=",
1164
+ t11.objectPattern(
1165
+ bindings.mutations.map(
1166
+ (item) => t11.objectProperty(item, item, false, true)
1167
+ )
1168
+ ),
1169
+ returnMutations
1170
+ )
1171
+ ) : t11.nullLiteral()
1172
+ ]
1173
+ ),
1147
1174
  [t11.arrayExpression(bindings.locals), t11.spreadElement(rest)]
1148
1175
  )
1149
1176
  )
@@ -1205,7 +1232,8 @@ function replaceIsomorphicFunction(ctx, path2, func, bindings) {
1205
1232
  path2.node.async
1206
1233
  )
1207
1234
  ),
1208
- func.target
1235
+ func.target,
1236
+ func.idPrefix
1209
1237
  );
1210
1238
  const source = generateUniqueName(path2, "source");
1211
1239
  const rest = generateUniqueName(path2, "rest");
@@ -1260,7 +1288,8 @@ function replaceFunctionFromCall(ctx, path2, func, bindings) {
1260
1288
  path2.node.async
1261
1289
  )
1262
1290
  ) : void 0,
1263
- func.target
1291
+ func.target,
1292
+ func.idPrefix
1264
1293
  );
1265
1294
  return getFunctionReplacement(ctx, path2, entryFile, bindings);
1266
1295
  }
@@ -1281,7 +1310,8 @@ function replaceExpressionFromCall(ctx, path2, func, bindings) {
1281
1310
  ctx,
1282
1311
  path2,
1283
1312
  ctx.options.mode === "server" || func.isomorphic ? createRootFile(ctx, bindings, path2.node) : void 0,
1284
- func.target
1313
+ func.target,
1314
+ func.idPrefix
1285
1315
  );
1286
1316
  const rest = generateUniqueName(path2, "rest");
1287
1317
  const source = generateUniqueName(path2, "source");
@@ -1467,21 +1497,27 @@ function getFunctionReplacement2(ctx, path2, entryFile, bindings) {
1467
1497
  t13.variableDeclaration("const", [
1468
1498
  t13.variableDeclarator(
1469
1499
  funcID,
1470
- t13.callExpression(getImportIdentifier(ctx, path2, HIDDEN_GENERATOR), [
1471
- source,
1472
- bindings.mutations.length ? t13.arrowFunctionExpression(
1473
- [returnMutations],
1474
- t13.assignmentExpression(
1475
- "=",
1476
- t13.objectPattern(
1477
- bindings.mutations.map(
1478
- (item) => t13.objectProperty(item, item, false, true)
1479
- )
1480
- ),
1481
- returnMutations
1482
- )
1483
- ) : t13.nullLiteral()
1484
- ])
1500
+ t13.callExpression(
1501
+ getImportIdentifier(ctx, path2, {
1502
+ ...HIDDEN_GENERATOR,
1503
+ source: ctx.options.runtime
1504
+ }),
1505
+ [
1506
+ source,
1507
+ bindings.mutations.length ? t13.arrowFunctionExpression(
1508
+ [returnMutations],
1509
+ t13.assignmentExpression(
1510
+ "=",
1511
+ t13.objectPattern(
1512
+ bindings.mutations.map(
1513
+ (item) => t13.objectProperty(item, item, false, true)
1514
+ )
1515
+ ),
1516
+ returnMutations
1517
+ )
1518
+ ) : t13.nullLiteral()
1519
+ ]
1520
+ )
1485
1521
  )
1486
1522
  ])
1487
1523
  );
@@ -1507,21 +1543,27 @@ function getFunctionReplacement2(ctx, path2, entryFile, bindings) {
1507
1543
  t13.arrayPattern([returnType, returnResult]),
1508
1544
  t13.awaitExpression(
1509
1545
  t13.callExpression(
1510
- t13.callExpression(getImportIdentifier(ctx, path2, HIDDEN_FUNC), [
1511
- source,
1512
- bindings.mutations.length ? t13.arrowFunctionExpression(
1513
- [returnMutations],
1514
- t13.assignmentExpression(
1515
- "=",
1516
- t13.objectPattern(
1517
- bindings.mutations.map(
1518
- (item) => t13.objectProperty(item, item, false, true)
1519
- )
1520
- ),
1521
- returnMutations
1522
- )
1523
- ) : t13.nullLiteral()
1524
- ]),
1546
+ t13.callExpression(
1547
+ getImportIdentifier(ctx, path2, {
1548
+ ...HIDDEN_FUNC,
1549
+ source: ctx.options.runtime
1550
+ }),
1551
+ [
1552
+ source,
1553
+ bindings.mutations.length ? t13.arrowFunctionExpression(
1554
+ [returnMutations],
1555
+ t13.assignmentExpression(
1556
+ "=",
1557
+ t13.objectPattern(
1558
+ bindings.mutations.map(
1559
+ (item) => t13.objectProperty(item, item, false, true)
1560
+ )
1561
+ ),
1562
+ returnMutations
1563
+ )
1564
+ ) : t13.nullLiteral()
1565
+ ]
1566
+ ),
1525
1567
  [t13.arrayExpression(bindings.locals), t13.spreadElement(rest)]
1526
1568
  )
1527
1569
  )
@@ -1583,7 +1625,8 @@ function replaceIsomorphicFunction2(ctx, path2, directive, bindings) {
1583
1625
  path2.node.async
1584
1626
  )
1585
1627
  ),
1586
- directive.target
1628
+ directive.target,
1629
+ directive.idPrefix
1587
1630
  );
1588
1631
  const source = generateUniqueName(path2, "source");
1589
1632
  const rest = generateUniqueName(path2, "rest");
@@ -1638,7 +1681,8 @@ function replaceFunctionDirective(ctx, path2, directive, bindings) {
1638
1681
  path2.node.async
1639
1682
  )
1640
1683
  ) : void 0,
1641
- directive.target
1684
+ directive.target,
1685
+ directive.idPrefix
1642
1686
  );
1643
1687
  return getFunctionReplacement2(ctx, path2, entryFile, bindings);
1644
1688
  }