@next-core/brick-utils 2.51.4 → 2.51.5
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/index.bundle.js +60 -34
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +61 -35
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
2
|
-
import lodash, { uniq, get, cloneDeep, set, isEmpty, escapeRegExp,
|
|
2
|
+
import lodash, { uniq, get, cloneDeep, set, isEmpty, escapeRegExp, pull } from 'lodash';
|
|
3
3
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
4
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
5
5
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
@@ -20277,68 +20277,92 @@ function removeDeadConditionsByAst(ast, options) {
|
|
|
20277
20277
|
|
|
20278
20278
|
// Then, we remove dead conditions accordingly.
|
|
20279
20279
|
traverse(ast, node => {
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
|
|
20280
|
+
// let conditionalNodes: ConditionalStoryboardNode[];
|
|
20281
|
+
// let rawContainer: any;
|
|
20282
|
+
// let rawKey: string;
|
|
20283
|
+
// let deleteEmptyArray = false;
|
|
20284
|
+
// let isUseBrickEntry = false;
|
|
20285
|
+
// let keepConditionalHandlers = false;
|
|
20286
|
+
|
|
20284
20287
|
switch (node.type) {
|
|
20285
20288
|
case "Root":
|
|
20286
|
-
|
|
20287
|
-
rawContainer = node.raw;
|
|
20288
|
-
rawKey = "routes";
|
|
20289
|
+
shakeConditionalNodes(node.routes, node.raw, "routes");
|
|
20289
20290
|
break;
|
|
20290
20291
|
case "Template":
|
|
20291
|
-
|
|
20292
|
-
rawContainer = node.raw;
|
|
20293
|
-
rawKey = "bricks";
|
|
20292
|
+
shakeConditionalNodes(node.bricks, node.raw, "bricks");
|
|
20294
20293
|
break;
|
|
20295
20294
|
case "Route":
|
|
20296
20295
|
case "Slot":
|
|
20297
|
-
|
|
20298
|
-
rawContainer = node.raw;
|
|
20299
|
-
rawKey = node.raw.type === "routes" ? "routes" : "bricks";
|
|
20296
|
+
shakeConditionalNodes(node.children, node.raw, node.raw.type === "routes" ? "routes" : "bricks");
|
|
20300
20297
|
break;
|
|
20301
20298
|
case "Event":
|
|
20302
20299
|
case "EventCallback":
|
|
20303
20300
|
case "SimpleLifeCycle":
|
|
20304
20301
|
case "ConditionalEvent":
|
|
20305
|
-
|
|
20306
|
-
|
|
20307
|
-
|
|
20308
|
-
|
|
20302
|
+
shakeConditionalNodes(node.handlers, node.rawContainer, node.rawKey, {
|
|
20303
|
+
deleteEmptyArray: true,
|
|
20304
|
+
keepConditionalHandlers: true
|
|
20305
|
+
});
|
|
20309
20306
|
break;
|
|
20310
20307
|
case "ResolveLifeCycle":
|
|
20311
|
-
|
|
20312
|
-
|
|
20313
|
-
|
|
20314
|
-
deleteEmptyArray = true;
|
|
20308
|
+
shakeConditionalNodes(node.resolves, node.rawContainer, node.rawKey, {
|
|
20309
|
+
deleteEmptyArray: true
|
|
20310
|
+
});
|
|
20315
20311
|
break;
|
|
20316
20312
|
case "UseBrickEntry":
|
|
20317
|
-
|
|
20318
|
-
|
|
20319
|
-
|
|
20313
|
+
shakeConditionalNodes(node.children, node.rawContainer, node.rawKey, {
|
|
20314
|
+
isUseBrickEntry: true
|
|
20315
|
+
});
|
|
20316
|
+
break;
|
|
20317
|
+
case "EventHandler":
|
|
20318
|
+
shakeConditionalNodes(node.then, node.raw, "then");
|
|
20319
|
+
shakeConditionalNodes(node.else, node.raw, "else");
|
|
20320
20320
|
break;
|
|
20321
20321
|
}
|
|
20322
|
-
shakeConditionalNodes(node, rawContainer, conditionalNodes, rawKey, deleteEmptyArray);
|
|
20323
20322
|
|
|
20324
20323
|
// Remove unreachable context/state.
|
|
20325
|
-
deleteEmptyArray = false;
|
|
20326
20324
|
switch (node.type) {
|
|
20327
20325
|
case "Route":
|
|
20328
20326
|
case "Brick":
|
|
20329
20327
|
case "Template":
|
|
20330
|
-
|
|
20331
|
-
rawKey = node.type === "Template" ? "state" : "context";
|
|
20332
|
-
conditionalNodes = node.context;
|
|
20333
|
-
break;
|
|
20328
|
+
shakeConditionalNodes(node.context, node.raw, node.type === "Template" ? "state" : "context");
|
|
20334
20329
|
}
|
|
20335
|
-
shakeConditionalNodes(node, rawContainer, conditionalNodes, rawKey, deleteEmptyArray);
|
|
20336
20330
|
});
|
|
20337
20331
|
}
|
|
20338
|
-
function shakeConditionalNodes(
|
|
20339
|
-
var
|
|
20332
|
+
function shakeConditionalNodes(conditionalNodes, rawContainer, rawKey) {
|
|
20333
|
+
var {
|
|
20334
|
+
deleteEmptyArray,
|
|
20335
|
+
isUseBrickEntry,
|
|
20336
|
+
keepConditionalHandlers
|
|
20337
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
20338
|
+
var removedNodes = [];
|
|
20339
|
+
if (Array.isArray(conditionalNodes)) {
|
|
20340
|
+
for (var node of conditionalNodes) {
|
|
20341
|
+
var _else;
|
|
20342
|
+
if (keepConditionalHandlers && (_else = node.else) !== null && _else !== void 0 && _else.length) {
|
|
20343
|
+
switch (node.raw.if) {
|
|
20344
|
+
case false:
|
|
20345
|
+
node.then = node.else;
|
|
20346
|
+
node.else = [];
|
|
20347
|
+
node.raw.then = node.raw.else;
|
|
20348
|
+
delete node.raw.else;
|
|
20349
|
+
delete node.raw.if;
|
|
20350
|
+
continue;
|
|
20351
|
+
case true:
|
|
20352
|
+
case undefined:
|
|
20353
|
+
node.else = [];
|
|
20354
|
+
delete node.raw.else;
|
|
20355
|
+
continue;
|
|
20356
|
+
}
|
|
20357
|
+
}
|
|
20358
|
+
if (node.raw.if === false) {
|
|
20359
|
+
removedNodes.push(node);
|
|
20360
|
+
}
|
|
20361
|
+
}
|
|
20362
|
+
}
|
|
20363
|
+
pull(conditionalNodes, ...removedNodes);
|
|
20340
20364
|
if (removedNodes.length > 0) {
|
|
20341
|
-
if (
|
|
20365
|
+
if (isUseBrickEntry && !Array.isArray(rawContainer[rawKey])) {
|
|
20342
20366
|
rawContainer[rawKey] = {
|
|
20343
20367
|
brick: "div",
|
|
20344
20368
|
if: false
|
|
@@ -20386,6 +20410,8 @@ function computeConstantCondition(ifContainer) {
|
|
|
20386
20410
|
console.warn("[removed dead if]:", ifContainer.if, ifContainer);
|
|
20387
20411
|
}
|
|
20388
20412
|
ifContainer.if = false;
|
|
20413
|
+
} else if (isConstantLogical(expression, true, options)) {
|
|
20414
|
+
ifContainer.if = true;
|
|
20389
20415
|
}
|
|
20390
20416
|
return;
|
|
20391
20417
|
}
|