dismantle 0.5.0 → 0.6.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.
- package/dist/cjs/development/index.cjs +60 -55
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +1 -1
- package/dist/esm/development/index.mjs +60 -55
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +1 -1
- package/dist/types/src/split-block-directive.d.ts.map +1 -1
- package/dist/types/src/split-function.d.ts +1 -1
- package/dist/types/src/split-function.d.ts.map +1 -1
- package/dist/types/src/split.d.ts +1 -1
- package/dist/types/src/split.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/split-block-directive.ts +8 -2
- package/src/split-function.ts +14 -5
- package/src/split.ts +1 -7
- package/src/transform-call.ts +2 -2
- package/src/transform-function-directive.ts +2 -2
|
@@ -160,45 +160,6 @@ function generateCode(id, node) {
|
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
// src/utils/get-descriptive-name.ts
|
|
164
|
-
function getDescriptiveName(path2, defaultName) {
|
|
165
|
-
let current = path2;
|
|
166
|
-
while (current) {
|
|
167
|
-
switch (current.node.type) {
|
|
168
|
-
case "FunctionDeclaration":
|
|
169
|
-
case "FunctionExpression": {
|
|
170
|
-
if (current.node.id) {
|
|
171
|
-
return current.node.id.name;
|
|
172
|
-
}
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
case "VariableDeclarator": {
|
|
176
|
-
if (current.node.id.type === "Identifier") {
|
|
177
|
-
return current.node.id.name;
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
case "ClassPrivateMethod":
|
|
182
|
-
case "ClassMethod":
|
|
183
|
-
case "ObjectMethod": {
|
|
184
|
-
switch (current.node.key.type) {
|
|
185
|
-
case "Identifier":
|
|
186
|
-
return current.node.key.name;
|
|
187
|
-
case "PrivateName":
|
|
188
|
-
return current.node.key.id.name;
|
|
189
|
-
default:
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
default:
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
current = current.parentPath;
|
|
198
|
-
}
|
|
199
|
-
return defaultName;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
163
|
// src/utils/get-module-definition.ts
|
|
203
164
|
var t4 = __toESM(require("@babel/types"), 1);
|
|
204
165
|
|
|
@@ -495,11 +456,7 @@ function createRootFile(ctx, statements) {
|
|
|
495
456
|
);
|
|
496
457
|
return rootFile;
|
|
497
458
|
}
|
|
498
|
-
function createEntryFile(ctx,
|
|
499
|
-
let id = `${idPrefix || ""}${ctx.blocks.hash}-${ctx.blocks.count++}`;
|
|
500
|
-
if (ctx.options.env !== "production") {
|
|
501
|
-
id += `-${getDescriptiveName(path2, "anonymous")}`;
|
|
502
|
-
}
|
|
459
|
+
function createEntryFile(ctx, id, type, rootFile, imported) {
|
|
503
460
|
const entryID = t5.identifier("entry");
|
|
504
461
|
const entryImports = [
|
|
505
462
|
{
|
|
@@ -776,6 +733,45 @@ function getFunctionReplacement(ctx, path2, entryFile, dependencies) {
|
|
|
776
733
|
);
|
|
777
734
|
}
|
|
778
735
|
|
|
736
|
+
// src/utils/get-descriptive-name.ts
|
|
737
|
+
function getDescriptiveName(path2, defaultName) {
|
|
738
|
+
let current = path2;
|
|
739
|
+
while (current) {
|
|
740
|
+
switch (current.node.type) {
|
|
741
|
+
case "FunctionDeclaration":
|
|
742
|
+
case "FunctionExpression": {
|
|
743
|
+
if (current.node.id) {
|
|
744
|
+
return current.node.id.name;
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
case "VariableDeclarator": {
|
|
749
|
+
if (current.node.id.type === "Identifier") {
|
|
750
|
+
return current.node.id.name;
|
|
751
|
+
}
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
case "ClassPrivateMethod":
|
|
755
|
+
case "ClassMethod":
|
|
756
|
+
case "ObjectMethod": {
|
|
757
|
+
switch (current.node.key.type) {
|
|
758
|
+
case "Identifier":
|
|
759
|
+
return current.node.key.name;
|
|
760
|
+
case "PrivateName":
|
|
761
|
+
return current.node.key.id.name;
|
|
762
|
+
default:
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
break;
|
|
766
|
+
}
|
|
767
|
+
default:
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
current = current.parentPath;
|
|
771
|
+
}
|
|
772
|
+
return defaultName;
|
|
773
|
+
}
|
|
774
|
+
|
|
779
775
|
// src/utils/get-foreign-bindings.ts
|
|
780
776
|
var t6 = __toESM(require("@babel/types"), 1);
|
|
781
777
|
function isForeignBinding(checker, current, name) {
|
|
@@ -1218,13 +1214,16 @@ function replaceBlockDirective(ctx, path2, directive, dependencies) {
|
|
|
1218
1214
|
)
|
|
1219
1215
|
)
|
|
1220
1216
|
);
|
|
1217
|
+
let id = `${directive.idPrefix || ""}${ctx.blocks.hash}-${ctx.blocks.count++}`;
|
|
1218
|
+
if (ctx.options.env !== "production") {
|
|
1219
|
+
id += `-${getDescriptiveName(path2, "anonymous")}`;
|
|
1220
|
+
}
|
|
1221
1221
|
const entryFile = createEntryFile(
|
|
1222
1222
|
ctx,
|
|
1223
|
+
id,
|
|
1223
1224
|
"block",
|
|
1224
|
-
path2,
|
|
1225
1225
|
ctx.options.mode === "server" ? createRootFile(ctx, statements) : void 0,
|
|
1226
|
-
directive.target
|
|
1227
|
-
directive.idPrefix
|
|
1226
|
+
directive.target
|
|
1228
1227
|
);
|
|
1229
1228
|
const result = getBlockDirectiveReplacement(
|
|
1230
1229
|
ctx,
|
|
@@ -1344,15 +1343,21 @@ var t10 = __toESM(require("@babel/types"), 1);
|
|
|
1344
1343
|
function replaceFunction(ctx, path2, definition, dependencies) {
|
|
1345
1344
|
const statements = getModuleImports(dependencies.modules);
|
|
1346
1345
|
statements.push(transformRootFunction(path2, dependencies));
|
|
1346
|
+
let id = `${definition.idPrefix || ""}${ctx.blocks.hash}-${ctx.blocks.count++}`;
|
|
1347
|
+
if (ctx.options.env !== "production") {
|
|
1348
|
+
id += `-${getDescriptiveName(path2, "anonymous")}`;
|
|
1349
|
+
}
|
|
1347
1350
|
const entryFile = createEntryFile(
|
|
1348
1351
|
ctx,
|
|
1352
|
+
id,
|
|
1349
1353
|
path2.node.generator ? "generator" : "function",
|
|
1350
|
-
path2,
|
|
1351
1354
|
ctx.options.mode === "server" ? createRootFile(ctx, statements) : void 0,
|
|
1352
|
-
definition.target
|
|
1353
|
-
definition.idPrefix
|
|
1355
|
+
definition.target
|
|
1354
1356
|
);
|
|
1355
|
-
return
|
|
1357
|
+
return [
|
|
1358
|
+
id,
|
|
1359
|
+
getFunctionReplacement(ctx, path2, entryFile, dependencies)
|
|
1360
|
+
];
|
|
1356
1361
|
}
|
|
1357
1362
|
function splitFunction(ctx, path2, definition) {
|
|
1358
1363
|
return replaceFunction(
|
|
@@ -1422,12 +1427,12 @@ function transformCall(ctx, path2) {
|
|
|
1422
1427
|
const args = path2.get("arguments");
|
|
1423
1428
|
const expr = args[0];
|
|
1424
1429
|
if (isPathValid(expr, isValidFunction)) {
|
|
1425
|
-
const replacement = splitFunction(ctx, expr, definition);
|
|
1430
|
+
const [id, replacement] = splitFunction(ctx, expr, definition);
|
|
1426
1431
|
path2.scope.crawl();
|
|
1427
1432
|
path2.replaceWith(
|
|
1428
1433
|
t10.callExpression(
|
|
1429
1434
|
getImportIdentifier(ctx.imports, path2, definition.handle),
|
|
1430
|
-
[replacement]
|
|
1435
|
+
[t10.stringLiteral(id), replacement]
|
|
1431
1436
|
)
|
|
1432
1437
|
);
|
|
1433
1438
|
}
|
|
@@ -1461,12 +1466,12 @@ function transformFunctionDirective(ctx, path2) {
|
|
|
1461
1466
|
if (isPathValid(body, t11.isBlockStatement)) {
|
|
1462
1467
|
const definition = getFunctionDirectiveDefinition(ctx, body);
|
|
1463
1468
|
if (definition) {
|
|
1464
|
-
const replacement = splitFunction(ctx, path2, definition);
|
|
1469
|
+
const [id, replacement] = splitFunction(ctx, path2, definition);
|
|
1465
1470
|
path2.scope.crawl();
|
|
1466
1471
|
path2.replaceWith(
|
|
1467
1472
|
t11.callExpression(
|
|
1468
1473
|
getImportIdentifier(ctx.imports, path2, definition.handle),
|
|
1469
|
-
[replacement]
|
|
1474
|
+
[t11.stringLiteral(id), replacement]
|
|
1470
1475
|
)
|
|
1471
1476
|
);
|
|
1472
1477
|
}
|