@next-core/brick-utils 2.44.7 → 2.45.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/index.bundle.js +655 -388
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +648 -389
- package/dist/index.esm.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/scanAliasInStoryboard.d.ts +1 -1
- package/dist/types/scanBricksInStoryboard.d.ts +1 -1
- package/dist/types/scanStoryboard.d.ts +13 -2
- package/package.json +5 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
2
|
-
import { uniq, get, cloneDeep, set, isEmpty, escapeRegExp,
|
|
2
|
+
import { uniq, get, cloneDeep, set, isEmpty, escapeRegExp, remove } 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';
|
|
@@ -600,271 +600,616 @@ function paramCase(input, options) {
|
|
|
600
600
|
}
|
|
601
601
|
|
|
602
602
|
// Ref https://github.com/lodash/lodash/blob/4.17.11/lodash.js#L11744
|
|
603
|
-
function isObject(value) {
|
|
603
|
+
function isObject$1(value) {
|
|
604
604
|
var type = typeof value;
|
|
605
605
|
return value != null && (type == "object" || type == "function");
|
|
606
606
|
}
|
|
607
607
|
|
|
608
|
-
/**
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
ignoreBricksInUnusedCustomTemplates
|
|
619
|
-
} = isObject(options) ? options : {
|
|
620
|
-
keepDuplicates: !options
|
|
608
|
+
/** Parse storyboard as AST. */
|
|
609
|
+
|
|
610
|
+
function parseStoryboard(storyboard) {
|
|
611
|
+
var _storyboard$meta;
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
type: "Root",
|
|
615
|
+
raw: storyboard,
|
|
616
|
+
routes: parseRoutes(storyboard.routes),
|
|
617
|
+
templates: parseTemplates((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.customTemplates)
|
|
621
618
|
};
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
var selfDefined = new Set(["form-renderer.form-renderer"]);
|
|
619
|
+
}
|
|
620
|
+
/** Parse storyboard routes as AST. */
|
|
625
621
|
|
|
626
|
-
|
|
627
|
-
|
|
622
|
+
function parseRoutes(routes, options) {
|
|
623
|
+
if (Array.isArray(routes)) {
|
|
624
|
+
return routes.map(route => _objectSpread(_objectSpread({
|
|
625
|
+
type: "Route",
|
|
626
|
+
raw: route
|
|
627
|
+
}, options !== null && options !== void 0 && options.routesOnly ? null : {
|
|
628
|
+
context: parseContext(route.context),
|
|
629
|
+
redirect: parseResolvable(route.redirect),
|
|
630
|
+
menu: parseMenu(route.menu),
|
|
631
|
+
providers: parseRouteProviders(route.providers),
|
|
632
|
+
defineResolves: Array.isArray(route.defineResolves) ? route.defineResolves.map(item => parseResolvable(item)).filter(Boolean) : undefined
|
|
633
|
+
}), {}, {
|
|
634
|
+
children: route.type === "routes" ? parseRoutes(route.routes, options) : parseBricks(route.bricks, options)
|
|
635
|
+
}));
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
return [];
|
|
639
|
+
}
|
|
640
|
+
/** Parse storyboard templates as AST. */
|
|
628
641
|
|
|
629
|
-
|
|
630
|
-
|
|
642
|
+
function parseTemplates(templates) {
|
|
643
|
+
if (Array.isArray(templates)) {
|
|
644
|
+
return templates.map(parseTemplate);
|
|
645
|
+
}
|
|
631
646
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
collection.push(...collectionByTpl.get(item));
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
} else {
|
|
639
|
-
var _storyboard$meta2;
|
|
647
|
+
return [];
|
|
648
|
+
}
|
|
649
|
+
/** Parse a storyboard template as AST. */
|
|
640
650
|
|
|
641
|
-
|
|
651
|
+
function parseTemplate(tpl) {
|
|
652
|
+
return {
|
|
653
|
+
type: "Template",
|
|
654
|
+
raw: tpl,
|
|
655
|
+
bricks: parseBricks(tpl.bricks),
|
|
656
|
+
context: parseContext(tpl.state)
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function parseBricks(bricks, options) {
|
|
661
|
+
if (Array.isArray(bricks)) {
|
|
662
|
+
return bricks.map(brick => parseBrick(brick, options));
|
|
642
663
|
}
|
|
643
664
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
665
|
+
return [];
|
|
666
|
+
}
|
|
667
|
+
/** Parse a storyboard brick as AST. */
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
function parseBrick(brick, options) {
|
|
671
|
+
return _objectSpread(_objectSpread({
|
|
672
|
+
type: "Brick",
|
|
673
|
+
raw: brick,
|
|
674
|
+
isUseBrick: options === null || options === void 0 ? void 0 : options.isUseBrick
|
|
675
|
+
}, options !== null && options !== void 0 && options.routesOnly ? null : _objectSpread(_objectSpread({
|
|
676
|
+
if: parseCondition(brick.if),
|
|
677
|
+
events: parseEvents(brick.events),
|
|
678
|
+
lifeCycle: parseLifeCycles(brick.lifeCycle)
|
|
679
|
+
}, parseBrickProperties(brick.properties)), {}, {
|
|
680
|
+
context: parseContext(brick.context)
|
|
681
|
+
})), {}, {
|
|
682
|
+
children: parseSlots(brick.slots, options)
|
|
654
683
|
});
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function parseCondition(condition) {
|
|
687
|
+
if (isObject(condition)) {
|
|
688
|
+
return {
|
|
689
|
+
type: "ResolvableCondition",
|
|
690
|
+
resolve: parseResolvable(condition)
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
655
694
|
return {
|
|
656
|
-
|
|
657
|
-
customApis: keepDuplicates ? customApis : uniq(customApis)
|
|
695
|
+
type: "LiteralCondition"
|
|
658
696
|
};
|
|
659
697
|
}
|
|
660
|
-
function collectBricksInBrickConf(brickConf, collection) {
|
|
661
|
-
if (brickConf.brick) {
|
|
662
|
-
collection.push(brickConf.brick);
|
|
663
|
-
}
|
|
664
698
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
699
|
+
function parseBrickProperties(props) {
|
|
700
|
+
var useBrick = [];
|
|
701
|
+
var useBackend = [];
|
|
702
|
+
|
|
703
|
+
function walkBrickProperties(value) {
|
|
704
|
+
if (Array.isArray(value)) {
|
|
705
|
+
for (var item of value) {
|
|
706
|
+
walkBrickProperties(item);
|
|
707
|
+
}
|
|
708
|
+
} else if (isObject(value)) {
|
|
709
|
+
if (value.useBrick || value.useBackend) {
|
|
710
|
+
var _value$useBackend;
|
|
711
|
+
|
|
712
|
+
if (value.useBrick) {
|
|
713
|
+
useBrick.push({
|
|
714
|
+
type: "UseBrickEntry",
|
|
715
|
+
rawContainer: value,
|
|
716
|
+
rawKey: "useBrick",
|
|
717
|
+
children: parseBricks([].concat(value.useBrick), {
|
|
718
|
+
isUseBrick: true
|
|
719
|
+
})
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
var provider = (_value$useBackend = value.useBackend) === null || _value$useBackend === void 0 ? void 0 : _value$useBackend.provider;
|
|
724
|
+
|
|
725
|
+
if (typeof provider === "string") {
|
|
726
|
+
useBackend.push({
|
|
727
|
+
type: "UseBackendEntry",
|
|
728
|
+
rawContainer: value,
|
|
729
|
+
rawKey: "useBackend",
|
|
730
|
+
children: [parseBrick({
|
|
731
|
+
brick: provider
|
|
732
|
+
})]
|
|
733
|
+
});
|
|
734
|
+
}
|
|
669
735
|
} else {
|
|
670
|
-
|
|
736
|
+
for (var _item of Object.values(value)) {
|
|
737
|
+
walkBrickProperties(_item);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
walkBrickProperties(props);
|
|
744
|
+
return {
|
|
745
|
+
useBrick,
|
|
746
|
+
useBackend
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function parseLifeCycles(lifeCycle) {
|
|
751
|
+
if (isObject(lifeCycle)) {
|
|
752
|
+
return Object.entries(lifeCycle).map(_ref => {
|
|
753
|
+
var [name, conf] = _ref;
|
|
754
|
+
|
|
755
|
+
switch (name) {
|
|
756
|
+
case "useResolves":
|
|
757
|
+
return {
|
|
758
|
+
type: "ResolveLifeCycle",
|
|
759
|
+
rawContainer: lifeCycle,
|
|
760
|
+
rawKey: name,
|
|
761
|
+
resolves: Array.isArray(conf) ? conf.map(item => parseResolvable(item, true)).filter(Boolean) : undefined
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
case "onPageLoad":
|
|
765
|
+
case "onPageLeave":
|
|
766
|
+
case "onAnchorLoad":
|
|
767
|
+
case "onAnchorUnload":
|
|
768
|
+
case "onMessageClose":
|
|
769
|
+
case "onBeforePageLoad":
|
|
770
|
+
case "onBeforePageLeave":
|
|
771
|
+
case "onMediaChange":
|
|
772
|
+
return {
|
|
773
|
+
type: "SimpleLifeCycle",
|
|
774
|
+
name,
|
|
775
|
+
rawContainer: lifeCycle,
|
|
776
|
+
rawKey: name,
|
|
777
|
+
handlers: parseEventHandlers(conf)
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
case "onMessage":
|
|
781
|
+
case "onScrollIntoView":
|
|
782
|
+
return {
|
|
783
|
+
type: "ConditionalLifeCycle",
|
|
784
|
+
name,
|
|
785
|
+
events: [].concat(conf).filter(Boolean).map(item => ({
|
|
786
|
+
type: "ConditionalEvent",
|
|
787
|
+
rawContainer: item,
|
|
788
|
+
rawKey: "handlers",
|
|
789
|
+
handlers: parseEventHandlers(item.handlers)
|
|
790
|
+
}))
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
default:
|
|
794
|
+
return {
|
|
795
|
+
type: "UnknownLifeCycle"
|
|
796
|
+
};
|
|
671
797
|
}
|
|
672
798
|
});
|
|
673
799
|
}
|
|
800
|
+
}
|
|
674
801
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
802
|
+
function parseSlots(slots, options) {
|
|
803
|
+
if (isObject(slots)) {
|
|
804
|
+
return Object.entries(slots).map(_ref2 => {
|
|
805
|
+
var [slot, conf] = _ref2;
|
|
806
|
+
return {
|
|
807
|
+
type: "Slot",
|
|
808
|
+
raw: conf,
|
|
809
|
+
slot,
|
|
810
|
+
childrenType: conf.type === "routes" ? "Route" : "Brick",
|
|
811
|
+
children: conf.type === "routes" ? parseRoutes(conf.routes, options) : parseBricks(conf.bricks, options)
|
|
812
|
+
};
|
|
678
813
|
});
|
|
679
814
|
}
|
|
680
815
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
useResolves,
|
|
684
|
-
onPageLoad,
|
|
685
|
-
onPageLeave,
|
|
686
|
-
onAnchorLoad,
|
|
687
|
-
onAnchorUnload,
|
|
688
|
-
onMessage,
|
|
689
|
-
onMessageClose,
|
|
690
|
-
onBeforePageLoad,
|
|
691
|
-
onBeforePageLeave,
|
|
692
|
-
onMediaChange,
|
|
693
|
-
onScrollIntoView
|
|
694
|
-
} = brickConf.lifeCycle;
|
|
695
|
-
|
|
696
|
-
if (Array.isArray(useResolves)) {
|
|
697
|
-
useResolves.forEach(useResolve => {
|
|
698
|
-
var useProvider = useResolve.useProvider;
|
|
699
|
-
|
|
700
|
-
if (useProvider) {
|
|
701
|
-
collection.push(useProvider);
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
}
|
|
816
|
+
return [];
|
|
817
|
+
}
|
|
705
818
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}, collection);
|
|
819
|
+
function parseEvents(events) {
|
|
820
|
+
if (isObject(events)) {
|
|
821
|
+
return Object.entries(events).map(_ref3 => {
|
|
822
|
+
var [eventType, handlers] = _ref3;
|
|
823
|
+
return {
|
|
824
|
+
type: "Event",
|
|
825
|
+
rawContainer: events,
|
|
826
|
+
rawKey: eventType,
|
|
827
|
+
handlers: parseEventHandlers(handlers)
|
|
828
|
+
};
|
|
829
|
+
});
|
|
718
830
|
}
|
|
719
|
-
|
|
720
|
-
collectUsedBricksInEventHandlers(brickConf.events, collection);
|
|
721
|
-
collectBricksInResolvable(brickConf.if, collection);
|
|
722
|
-
collectBricksInContext(brickConf.context, collection);
|
|
723
|
-
collectUsedBricksInProperties(brickConf.properties, collection);
|
|
724
831
|
}
|
|
725
832
|
|
|
726
|
-
function
|
|
727
|
-
if (
|
|
728
|
-
|
|
833
|
+
function parseContext(contexts) {
|
|
834
|
+
if (Array.isArray(contexts)) {
|
|
835
|
+
return contexts.map(context => ({
|
|
836
|
+
type: "Context",
|
|
837
|
+
raw: context,
|
|
838
|
+
resolve: parseResolvable(context.resolve),
|
|
839
|
+
onChange: parseEventHandlers(context.onChange)
|
|
840
|
+
}));
|
|
729
841
|
}
|
|
730
842
|
}
|
|
731
843
|
|
|
732
|
-
function
|
|
733
|
-
if (
|
|
734
|
-
|
|
735
|
-
|
|
844
|
+
function parseMenu(menu) {
|
|
845
|
+
if (menu === false) {
|
|
846
|
+
return {
|
|
847
|
+
type: "FalseMenu"
|
|
848
|
+
};
|
|
849
|
+
}
|
|
736
850
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
851
|
+
if (!menu) {
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
switch (menu.type) {
|
|
856
|
+
case "brick":
|
|
857
|
+
return {
|
|
858
|
+
type: "BrickMenu",
|
|
859
|
+
raw: menu,
|
|
860
|
+
brick: parseBrick(menu)
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
case "resolve":
|
|
864
|
+
return {
|
|
865
|
+
type: "ResolvableMenu",
|
|
866
|
+
resolve: parseResolvable(menu.resolve)
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
default:
|
|
870
|
+
return {
|
|
871
|
+
type: "StaticMenu"
|
|
872
|
+
};
|
|
743
873
|
}
|
|
744
874
|
}
|
|
745
875
|
|
|
746
|
-
function
|
|
747
|
-
if (isObject(
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
876
|
+
function parseResolvable(resolve, isConditional) {
|
|
877
|
+
if (isObject(resolve)) {
|
|
878
|
+
return {
|
|
879
|
+
type: "Resolvable",
|
|
880
|
+
raw: resolve,
|
|
881
|
+
isConditional
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
}
|
|
753
885
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
886
|
+
function parseEventHandlers(handlers) {
|
|
887
|
+
return [].concat(handlers).filter(Boolean).map(handler => ({
|
|
888
|
+
type: "EventHandler",
|
|
889
|
+
callback: parseEventCallback(handler.callback),
|
|
890
|
+
raw: handler
|
|
891
|
+
}));
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function parseEventCallback(callback) {
|
|
895
|
+
if (isObject(callback)) {
|
|
896
|
+
return Object.entries(callback).map(_ref4 => {
|
|
897
|
+
var [callbackType, handlers] = _ref4;
|
|
898
|
+
return {
|
|
899
|
+
type: "EventCallback",
|
|
900
|
+
rawContainer: callback,
|
|
901
|
+
rawKey: callbackType,
|
|
902
|
+
handlers: parseEventHandlers(handlers)
|
|
903
|
+
};
|
|
758
904
|
});
|
|
759
905
|
}
|
|
760
906
|
}
|
|
761
907
|
|
|
762
|
-
function
|
|
763
|
-
if (Array.isArray(
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
if (value.useBrick) {
|
|
770
|
-
[].concat(value.useBrick).forEach(useBrickConf => {
|
|
771
|
-
if (typeof (useBrickConf === null || useBrickConf === void 0 ? void 0 : useBrickConf.brick) === "string") {
|
|
772
|
-
collection.push(useBrickConf.brick);
|
|
773
|
-
collectUsedBricksInProperties(useBrickConf.properties, collection);
|
|
774
|
-
collectUsedBricksInEventHandlers(useBrickConf.events, collection);
|
|
775
|
-
|
|
776
|
-
if (useBrickConf.slots) {
|
|
777
|
-
Object.values(useBrickConf.slots).forEach(slotConf => {
|
|
778
|
-
collectBricksInBrickConfs(slotConf.bricks, collection);
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
}
|
|
908
|
+
function parseRouteProviders(providers) {
|
|
909
|
+
if (Array.isArray(providers)) {
|
|
910
|
+
return providers.map(provider => parseBrick(typeof provider === "string" ? {
|
|
911
|
+
brick: provider
|
|
912
|
+
} : provider));
|
|
913
|
+
}
|
|
914
|
+
} // Ref https://github.com/lodash/lodash/blob/4.17.11/lodash.js#L11744
|
|
784
915
|
|
|
785
|
-
if (value.useBackend) {
|
|
786
|
-
var _value$useBackend;
|
|
787
916
|
|
|
788
|
-
|
|
789
|
-
|
|
917
|
+
function isObject(value) {
|
|
918
|
+
var type = typeof value;
|
|
919
|
+
return value != null && (type == "object" || type == "function");
|
|
920
|
+
}
|
|
790
921
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
922
|
+
/** Traverse a storyboard AST. */
|
|
923
|
+
function traverseStoryboard(ast, callback) {
|
|
924
|
+
traverseNode(ast, callback);
|
|
925
|
+
}
|
|
926
|
+
/** Traverse any node(s) in storyboard AST. */
|
|
927
|
+
|
|
928
|
+
function traverse(nodeOrNodes, callback) {
|
|
929
|
+
if (Array.isArray(nodeOrNodes)) {
|
|
930
|
+
traverseNodes(nodeOrNodes, callback);
|
|
931
|
+
} else {
|
|
932
|
+
traverseNode(nodeOrNodes, callback);
|
|
799
933
|
}
|
|
800
934
|
}
|
|
801
935
|
|
|
802
|
-
function
|
|
803
|
-
if (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
936
|
+
function traverseNodes(nodes, callback) {
|
|
937
|
+
if (!nodes) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
for (var _node of nodes) {
|
|
942
|
+
traverseNode(_node, callback);
|
|
807
943
|
}
|
|
808
944
|
}
|
|
809
945
|
|
|
810
|
-
function
|
|
811
|
-
if (
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
946
|
+
function traverseNode(node, callback) {
|
|
947
|
+
if (!node) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
callback(node);
|
|
952
|
+
|
|
953
|
+
switch (node.type) {
|
|
954
|
+
case "Root":
|
|
955
|
+
traverseNodes(node.routes, callback);
|
|
956
|
+
traverseNodes(node.templates, callback);
|
|
957
|
+
break;
|
|
958
|
+
|
|
959
|
+
case "Route":
|
|
960
|
+
traverseNodes(node.context, callback);
|
|
961
|
+
traverseNode(node.redirect, callback);
|
|
962
|
+
traverseNode(node.menu, callback);
|
|
963
|
+
traverseNodes(node.providers, callback);
|
|
964
|
+
traverseNodes(node.defineResolves, callback);
|
|
965
|
+
traverseNodes(node.children, callback);
|
|
966
|
+
break;
|
|
967
|
+
|
|
968
|
+
case "Template":
|
|
969
|
+
traverseNodes(node.bricks, callback);
|
|
970
|
+
traverseNodes(node.context, callback);
|
|
971
|
+
break;
|
|
972
|
+
|
|
973
|
+
case "Brick":
|
|
974
|
+
traverseNode(node.if, callback);
|
|
975
|
+
traverseNodes(node.events, callback);
|
|
976
|
+
traverseNodes(node.lifeCycle, callback);
|
|
977
|
+
traverseNodes(node.useBrick, callback);
|
|
978
|
+
traverseNodes(node.useBackend, callback);
|
|
979
|
+
traverseNodes(node.context, callback);
|
|
980
|
+
traverseNodes(node.children, callback);
|
|
981
|
+
break;
|
|
982
|
+
|
|
983
|
+
case "Slot":
|
|
984
|
+
case "UseBrickEntry":
|
|
985
|
+
case "UseBackendEntry":
|
|
986
|
+
traverseNodes(node.children, callback);
|
|
987
|
+
break;
|
|
988
|
+
|
|
989
|
+
case "Context":
|
|
990
|
+
traverseNode(node.resolve, callback);
|
|
991
|
+
traverseNodes(node.onChange, callback);
|
|
992
|
+
break;
|
|
993
|
+
|
|
994
|
+
case "ResolvableCondition":
|
|
995
|
+
case "ResolvableMenu":
|
|
996
|
+
traverseNode(node.resolve, callback);
|
|
997
|
+
break;
|
|
998
|
+
|
|
999
|
+
case "ResolveLifeCycle":
|
|
1000
|
+
traverseNodes(node.resolves, callback);
|
|
1001
|
+
break;
|
|
1002
|
+
|
|
1003
|
+
case "Event":
|
|
1004
|
+
case "EventCallback":
|
|
1005
|
+
case "SimpleLifeCycle":
|
|
1006
|
+
case "ConditionalEvent":
|
|
1007
|
+
traverseNodes(node.handlers, callback);
|
|
1008
|
+
break;
|
|
1009
|
+
|
|
1010
|
+
case "EventHandler":
|
|
1011
|
+
traverseNodes(node.callback, callback);
|
|
1012
|
+
break;
|
|
1013
|
+
|
|
1014
|
+
case "ConditionalLifeCycle":
|
|
1015
|
+
traverseNodes(node.events, callback);
|
|
1016
|
+
break;
|
|
1017
|
+
|
|
1018
|
+
case "BrickMenu":
|
|
1019
|
+
traverseNode(node.brick, callback);
|
|
1020
|
+
break;
|
|
1021
|
+
|
|
1022
|
+
case "Resolvable":
|
|
1023
|
+
case "FalseMenu":
|
|
1024
|
+
case "StaticMenu":
|
|
1025
|
+
case "UnknownLifeCycle":
|
|
1026
|
+
case "LiteralCondition":
|
|
1027
|
+
break;
|
|
1028
|
+
|
|
1029
|
+
default:
|
|
1030
|
+
// istanbul ignore if
|
|
1031
|
+
if (process.env.NODE_ENV === "development") {
|
|
1032
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1033
|
+
// @ts-expect-error
|
|
1034
|
+
throw new Error("Unhandled storyboard node type: ".concat(node.type));
|
|
1035
|
+
}
|
|
1036
|
+
|
|
815
1037
|
}
|
|
816
1038
|
}
|
|
817
1039
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
1040
|
+
/**
|
|
1041
|
+
* Scan bricks and custom apis in storyboard.
|
|
1042
|
+
*
|
|
1043
|
+
* @param storyboard - Storyboard.
|
|
1044
|
+
* @param options - If options is a boolean, it means `isUniq` or `de-duplicate`.
|
|
1045
|
+
*/
|
|
1046
|
+
function scanStoryboard(storyboard) {
|
|
1047
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1048
|
+
var ast = parseStoryboard(storyboard);
|
|
1049
|
+
return scanStoryboardAst(ast, options);
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Scan bricks and custom apis in storyboard.
|
|
1053
|
+
*
|
|
1054
|
+
* @param storyboard - Storyboard.
|
|
1055
|
+
* @param options - If options is a boolean, it means `isUniq` or `de-duplicate`.
|
|
1056
|
+
*/
|
|
1057
|
+
|
|
1058
|
+
function scanStoryboardAst(ast) {
|
|
1059
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
1060
|
+
var {
|
|
1061
|
+
keepDuplicates,
|
|
1062
|
+
ignoreBricksInUnusedCustomTemplates
|
|
1063
|
+
} = isObject$1(options) ? options : {
|
|
1064
|
+
keepDuplicates: !options
|
|
1065
|
+
};
|
|
1066
|
+
var selfDefined = new Set(["form-renderer.form-renderer"]);
|
|
1067
|
+
var collection;
|
|
1068
|
+
|
|
1069
|
+
if (ignoreBricksInUnusedCustomTemplates) {
|
|
1070
|
+
collection = collect(ast.routes, keepDuplicates);
|
|
1071
|
+
|
|
1072
|
+
if (Array.isArray(ast.templates)) {
|
|
1073
|
+
var tplMap = new Map();
|
|
1074
|
+
|
|
1075
|
+
for (var tpl of ast.templates) {
|
|
1076
|
+
tplMap.set(tpl.raw.name, tpl);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
for (var _item of collection) {
|
|
1080
|
+
if (tplMap.has(_item) && !selfDefined.has(_item)) {
|
|
1081
|
+
selfDefined.add(_item);
|
|
1082
|
+
var collectionByTpl = collect(tplMap.get(_item));
|
|
1083
|
+
|
|
1084
|
+
if (keepDuplicates) {
|
|
1085
|
+
collection.push(_item);
|
|
1086
|
+
collection.push(...collectionByTpl);
|
|
1087
|
+
} else {
|
|
1088
|
+
collection.add(_item);
|
|
824
1089
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1090
|
+
for (var i of collectionByTpl) {
|
|
1091
|
+
collection.add(i);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
828
1094
|
}
|
|
829
1095
|
}
|
|
1096
|
+
}
|
|
1097
|
+
} else {
|
|
1098
|
+
collection = collect(ast, keepDuplicates, selfDefined);
|
|
1099
|
+
}
|
|
830
1100
|
|
|
831
|
-
|
|
832
|
-
|
|
1101
|
+
if (keepDuplicates) {
|
|
1102
|
+
var bricks = [];
|
|
1103
|
+
var customApis = [];
|
|
1104
|
+
|
|
1105
|
+
for (var _item2 of collection) {
|
|
1106
|
+
if (_item2.includes("@")) {
|
|
1107
|
+
customApis.push(_item2);
|
|
833
1108
|
} else {
|
|
834
|
-
|
|
1109
|
+
if (_item2.includes("-") && !selfDefined.has(_item2)) {
|
|
1110
|
+
bricks.push(_item2);
|
|
1111
|
+
}
|
|
835
1112
|
}
|
|
1113
|
+
}
|
|
836
1114
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1115
|
+
return {
|
|
1116
|
+
bricks,
|
|
1117
|
+
customApis
|
|
1118
|
+
};
|
|
1119
|
+
} else {
|
|
1120
|
+
var _bricks = new Set();
|
|
1121
|
+
|
|
1122
|
+
var _customApis = new Set();
|
|
1123
|
+
|
|
1124
|
+
for (var _item3 of collection) {
|
|
1125
|
+
if (_item3.includes("@")) {
|
|
1126
|
+
_customApis.add(_item3);
|
|
1127
|
+
} else {
|
|
1128
|
+
if (_item3.includes("-") && !selfDefined.has(_item3)) {
|
|
1129
|
+
_bricks.add(_item3);
|
|
842
1130
|
}
|
|
843
1131
|
}
|
|
844
|
-
}
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
return {
|
|
1135
|
+
bricks: [..._bricks],
|
|
1136
|
+
customApis: [..._customApis]
|
|
1137
|
+
};
|
|
845
1138
|
}
|
|
846
1139
|
}
|
|
847
1140
|
|
|
848
|
-
function
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1141
|
+
function collect(nodeOrNodes, keepDuplicates, definedTemplates) {
|
|
1142
|
+
var collection;
|
|
1143
|
+
var add;
|
|
1144
|
+
|
|
1145
|
+
if (keepDuplicates) {
|
|
1146
|
+
collection = [];
|
|
1147
|
+
|
|
1148
|
+
add = item => {
|
|
1149
|
+
collection.push(item);
|
|
1150
|
+
};
|
|
1151
|
+
} else {
|
|
1152
|
+
collection = new Set();
|
|
1153
|
+
|
|
1154
|
+
add = item => {
|
|
1155
|
+
collection.add(item);
|
|
1156
|
+
};
|
|
855
1157
|
}
|
|
1158
|
+
|
|
1159
|
+
traverse(nodeOrNodes, node => {
|
|
1160
|
+
switch (node.type) {
|
|
1161
|
+
case "Brick":
|
|
1162
|
+
if (node.raw.brick) {
|
|
1163
|
+
add(node.raw.brick);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
break;
|
|
1167
|
+
|
|
1168
|
+
case "Resolvable":
|
|
1169
|
+
{
|
|
1170
|
+
var _node$raw;
|
|
1171
|
+
|
|
1172
|
+
var useProvider = (_node$raw = node.raw) === null || _node$raw === void 0 ? void 0 : _node$raw.useProvider;
|
|
1173
|
+
|
|
1174
|
+
if (useProvider) {
|
|
1175
|
+
add(useProvider);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
case "EventHandler":
|
|
1182
|
+
{
|
|
1183
|
+
var _node$raw2;
|
|
1184
|
+
|
|
1185
|
+
var _useProvider = (_node$raw2 = node.raw) === null || _node$raw2 === void 0 ? void 0 : _node$raw2.useProvider;
|
|
1186
|
+
|
|
1187
|
+
if (_useProvider) {
|
|
1188
|
+
add(_useProvider);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
break;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
case "Template":
|
|
1195
|
+
definedTemplates === null || definedTemplates === void 0 ? void 0 : definedTemplates.add(node.raw.name);
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
return collection;
|
|
856
1200
|
}
|
|
857
1201
|
|
|
1202
|
+
function collectBricksInBrickConf(brickConf) {
|
|
1203
|
+
var node = parseBrick(brickConf);
|
|
1204
|
+
return [...collect(node)];
|
|
1205
|
+
}
|
|
858
1206
|
function collectBricksByCustomTemplates(customTemplates) {
|
|
859
1207
|
var collectionByTpl = new Map();
|
|
1208
|
+
var templates = parseTemplates(customTemplates);
|
|
860
1209
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
collectionByTpl.set(tpl.name, collection);
|
|
865
|
-
collectBricksInBrickConfs(tpl.bricks, collection);
|
|
866
|
-
collectBricksInContext(tpl.state, collection);
|
|
867
|
-
});
|
|
1210
|
+
for (var tpl of templates) {
|
|
1211
|
+
var collection = collect(tpl, false);
|
|
1212
|
+
collectionByTpl.set(tpl.raw.name, [...collection]);
|
|
868
1213
|
}
|
|
869
1214
|
|
|
870
1215
|
return collectionByTpl;
|
|
@@ -882,11 +1227,9 @@ function scanBricksInStoryboard(storyboard) {
|
|
|
882
1227
|
return scanStoryboard(storyboard, options).bricks;
|
|
883
1228
|
}
|
|
884
1229
|
function scanBricksInBrickConf(brickConf) {
|
|
885
|
-
var
|
|
886
|
-
var collection = [];
|
|
887
|
-
collectBricksInBrickConf(brickConf, collection);
|
|
1230
|
+
var collection = collectBricksInBrickConf(brickConf);
|
|
888
1231
|
var result = collection.filter(item => !item.includes("@") && item.includes("-"));
|
|
889
|
-
return
|
|
1232
|
+
return result;
|
|
890
1233
|
}
|
|
891
1234
|
|
|
892
1235
|
class ExecutionContext {
|
|
@@ -21180,7 +21523,7 @@ options) {
|
|
|
21180
21523
|
} else {
|
|
21181
21524
|
visitNonExpressionString === null || visitNonExpressionString === void 0 ? void 0 : visitNonExpressionString(value);
|
|
21182
21525
|
}
|
|
21183
|
-
} else if (isObject(value)) {
|
|
21526
|
+
} else if (isObject$1(value)) {
|
|
21184
21527
|
// Avoid call stack overflow.
|
|
21185
21528
|
if (memo.has(value)) {
|
|
21186
21529
|
return;
|
|
@@ -22027,34 +22370,12 @@ function beforeVisitPermissionsFactory(collection) {
|
|
|
22027
22370
|
|
|
22028
22371
|
function scanRouteAliasInStoryboard(storyboard) {
|
|
22029
22372
|
var collection = new Map();
|
|
22030
|
-
|
|
22031
|
-
|
|
22032
|
-
}
|
|
22033
|
-
|
|
22034
|
-
|
|
22035
|
-
|
|
22036
|
-
Object.values(brickConf.slots).forEach(slotConf => {
|
|
22037
|
-
if (slotConf.type === "bricks") {
|
|
22038
|
-
collectRouteAliasInBrickConfs(slotConf.bricks, collection);
|
|
22039
|
-
} else {
|
|
22040
|
-
collectRouteAliasInRouteConfs(slotConf.routes, collection);
|
|
22041
|
-
}
|
|
22042
|
-
});
|
|
22043
|
-
}
|
|
22044
|
-
}
|
|
22045
|
-
|
|
22046
|
-
function collectRouteAliasInBrickConfs(bricks, collection) {
|
|
22047
|
-
if (Array.isArray(bricks)) {
|
|
22048
|
-
bricks.forEach(brickConf => {
|
|
22049
|
-
collectRouteAliasInBrickConf(brickConf, collection);
|
|
22050
|
-
});
|
|
22051
|
-
}
|
|
22052
|
-
}
|
|
22053
|
-
|
|
22054
|
-
function collectRouteAliasInRouteConfs(routes, collection) {
|
|
22055
|
-
if (Array.isArray(routes)) {
|
|
22056
|
-
routes.forEach(routeConf => {
|
|
22057
|
-
var alias = routeConf.alias;
|
|
22373
|
+
var routes = parseRoutes(storyboard.routes, {
|
|
22374
|
+
routesOnly: true
|
|
22375
|
+
});
|
|
22376
|
+
traverse(routes, node => {
|
|
22377
|
+
if (node.type === "Route") {
|
|
22378
|
+
var alias = node.raw.alias;
|
|
22058
22379
|
|
|
22059
22380
|
if (alias) {
|
|
22060
22381
|
if (collection.has(alias)) {
|
|
@@ -22064,17 +22385,12 @@ function collectRouteAliasInRouteConfs(routes, collection) {
|
|
|
22064
22385
|
|
|
22065
22386
|
collection.set(alias, {
|
|
22066
22387
|
alias,
|
|
22067
|
-
path:
|
|
22388
|
+
path: node.raw.path
|
|
22068
22389
|
});
|
|
22069
22390
|
}
|
|
22070
|
-
|
|
22071
|
-
|
|
22072
|
-
|
|
22073
|
-
} else {
|
|
22074
|
-
collectRouteAliasInBrickConfs(routeConf.bricks, collection);
|
|
22075
|
-
}
|
|
22076
|
-
});
|
|
22077
|
-
}
|
|
22391
|
+
}
|
|
22392
|
+
});
|
|
22393
|
+
return collection;
|
|
22078
22394
|
}
|
|
22079
22395
|
|
|
22080
22396
|
var I18N = "I18N";
|
|
@@ -23387,185 +23703,128 @@ function makeThrottledAggregation(namespace, request, select) {
|
|
|
23387
23703
|
* `FLAGS["your-feature-flag"]` is falsy.
|
|
23388
23704
|
*/
|
|
23389
23705
|
function removeDeadConditions(storyboard, options) {
|
|
23390
|
-
var _storyboard$meta;
|
|
23391
|
-
|
|
23392
23706
|
if (storyboard.$$deadConditionsRemoved) {
|
|
23393
23707
|
return;
|
|
23394
23708
|
}
|
|
23395
23709
|
|
|
23396
|
-
|
|
23397
|
-
|
|
23398
|
-
customTemplates
|
|
23399
|
-
} = (_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 ? _storyboard$meta : {};
|
|
23400
|
-
|
|
23401
|
-
if (Array.isArray(customTemplates)) {
|
|
23402
|
-
for (var tpl of customTemplates) {
|
|
23403
|
-
removeDeadConditionsInTpl(tpl, options);
|
|
23404
|
-
}
|
|
23405
|
-
}
|
|
23406
|
-
|
|
23710
|
+
var ast = parseStoryboard(storyboard);
|
|
23711
|
+
removeDeadConditionsByAst(ast, options);
|
|
23407
23712
|
storyboard.$$deadConditionsRemoved = true;
|
|
23408
23713
|
}
|
|
23409
|
-
/**
|
|
23410
|
-
* Like `removeDeadConditions` but applied to a custom template.
|
|
23411
|
-
*/
|
|
23412
|
-
|
|
23413
|
-
function removeDeadConditionsInTpl(tplConstructor, options) {
|
|
23414
|
-
removeDeadConditionsInBricks(tplConstructor.bricks, options);
|
|
23415
|
-
}
|
|
23416
23714
|
|
|
23417
|
-
function
|
|
23418
|
-
|
|
23419
|
-
|
|
23420
|
-
|
|
23421
|
-
|
|
23422
|
-
|
|
23423
|
-
|
|
23424
|
-
|
|
23425
|
-
|
|
23426
|
-
|
|
23427
|
-
}
|
|
23715
|
+
function removeDeadConditionsByAst(ast, options) {
|
|
23716
|
+
// First, we mark constant conditions.
|
|
23717
|
+
traverse(ast, node => {
|
|
23718
|
+
switch (node.type) {
|
|
23719
|
+
case "Route":
|
|
23720
|
+
case "Brick":
|
|
23721
|
+
case "EventHandler":
|
|
23722
|
+
case "Context":
|
|
23723
|
+
computeConstantCondition(node.raw, options);
|
|
23724
|
+
break;
|
|
23428
23725
|
|
|
23429
|
-
|
|
23430
|
-
|
|
23431
|
-
|
|
23432
|
-
for (var slot of Object.values(brick.slots)) {
|
|
23433
|
-
if (slot.type === "routes") {
|
|
23434
|
-
removeDeadConditionsInRoutes(slot.routes, options);
|
|
23435
|
-
} else {
|
|
23436
|
-
removeDeadConditionsInBricks(slot.bricks, options);
|
|
23726
|
+
case "Resolvable":
|
|
23727
|
+
if (node.isConditional) {
|
|
23728
|
+
computeConstantCondition(node.raw, options);
|
|
23437
23729
|
}
|
|
23438
|
-
}
|
|
23439
|
-
}
|
|
23440
|
-
|
|
23441
|
-
removeDeadConditionsInLifeCycle(brick.lifeCycle, options);
|
|
23442
|
-
removeDeadConditionsInEvents(brick.events, options);
|
|
23443
|
-
removeDeadConditionsInContext(brick.context, options);
|
|
23444
|
-
removeDeadConditionsInProperties(brick.properties, options);
|
|
23445
|
-
});
|
|
23446
|
-
}
|
|
23447
23730
|
|
|
23448
|
-
|
|
23449
|
-
if (Array.isArray(value)) {
|
|
23450
|
-
for (var _item of value) {
|
|
23451
|
-
removeDeadConditionsInProperties(_item, options);
|
|
23452
|
-
}
|
|
23453
|
-
} else if (isObject(value)) {
|
|
23454
|
-
if (value.useBrick) {
|
|
23455
|
-
if (Array.isArray(value.useBrick)) {
|
|
23456
|
-
// For useBrick as array, just remove dead items.
|
|
23457
|
-
removeDeadConditionsInArray(value.useBrick, options, useBrick => {
|
|
23458
|
-
removeDeadConditionsInUseBrick(useBrick, options);
|
|
23459
|
-
});
|
|
23460
|
-
} else {
|
|
23461
|
-
// For useBrick as single one, we have to keep it,
|
|
23462
|
-
// and we change it to an empty <div>.
|
|
23463
|
-
computeConstantCondition(value.useBrick, options);
|
|
23464
|
-
|
|
23465
|
-
if (value.useBrick.if === false) {
|
|
23466
|
-
value.useBrick = {
|
|
23467
|
-
brick: "div",
|
|
23468
|
-
if: false
|
|
23469
|
-
};
|
|
23470
|
-
} else {
|
|
23471
|
-
removeDeadConditionsInUseBrick(value.useBrick, options);
|
|
23472
|
-
}
|
|
23473
|
-
}
|
|
23474
|
-
} else {
|
|
23475
|
-
for (var _item2 of Object.values(value)) {
|
|
23476
|
-
removeDeadConditionsInProperties(_item2, options);
|
|
23477
|
-
}
|
|
23731
|
+
break;
|
|
23478
23732
|
}
|
|
23479
|
-
}
|
|
23480
|
-
}
|
|
23733
|
+
}); // Then, we remove dead conditions accordingly.
|
|
23481
23734
|
|
|
23482
|
-
|
|
23483
|
-
|
|
23484
|
-
|
|
23735
|
+
traverse(ast, node => {
|
|
23736
|
+
var rawContainer;
|
|
23737
|
+
var conditionalNodes;
|
|
23738
|
+
var rawKey;
|
|
23739
|
+
var deleteEmptyArray = false;
|
|
23485
23740
|
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
|
|
23492
|
-
|
|
23493
|
-
function removeDeadConditionsInEvents(events, options) {
|
|
23494
|
-
if (isObject(events)) {
|
|
23495
|
-
for (var eventType of Object.keys(events)) {
|
|
23496
|
-
removeDeadConditionsInEvent(events, eventType, options);
|
|
23497
|
-
}
|
|
23498
|
-
}
|
|
23499
|
-
}
|
|
23741
|
+
switch (node.type) {
|
|
23742
|
+
case "Root":
|
|
23743
|
+
conditionalNodes = node.routes;
|
|
23744
|
+
rawContainer = node.raw;
|
|
23745
|
+
rawKey = "routes";
|
|
23746
|
+
break;
|
|
23500
23747
|
|
|
23501
|
-
|
|
23502
|
-
|
|
23748
|
+
case "Template":
|
|
23749
|
+
conditionalNodes = node.bricks;
|
|
23750
|
+
rawContainer = node.raw;
|
|
23751
|
+
rawKey = "bricks";
|
|
23752
|
+
break;
|
|
23503
23753
|
|
|
23504
|
-
|
|
23505
|
-
|
|
23506
|
-
|
|
23754
|
+
case "Route":
|
|
23755
|
+
case "Slot":
|
|
23756
|
+
conditionalNodes = node.children;
|
|
23757
|
+
rawContainer = node.raw;
|
|
23758
|
+
rawKey = node.raw.type === "routes" ? "routes" : "bricks";
|
|
23759
|
+
break;
|
|
23507
23760
|
|
|
23508
|
-
|
|
23509
|
-
|
|
23510
|
-
|
|
23511
|
-
|
|
23512
|
-
|
|
23513
|
-
|
|
23514
|
-
|
|
23515
|
-
|
|
23761
|
+
case "Event":
|
|
23762
|
+
case "EventCallback":
|
|
23763
|
+
case "SimpleLifeCycle":
|
|
23764
|
+
case "ConditionalEvent":
|
|
23765
|
+
conditionalNodes = node.handlers;
|
|
23766
|
+
rawContainer = node.rawContainer;
|
|
23767
|
+
rawKey = node.rawKey;
|
|
23768
|
+
deleteEmptyArray = true;
|
|
23769
|
+
break;
|
|
23516
23770
|
|
|
23517
|
-
|
|
23518
|
-
|
|
23519
|
-
|
|
23520
|
-
|
|
23771
|
+
case "ResolveLifeCycle":
|
|
23772
|
+
conditionalNodes = node.resolves;
|
|
23773
|
+
rawContainer = node.rawContainer;
|
|
23774
|
+
rawKey = node.rawKey;
|
|
23775
|
+
deleteEmptyArray = true;
|
|
23776
|
+
break;
|
|
23521
23777
|
|
|
23522
|
-
|
|
23523
|
-
|
|
23778
|
+
case "UseBrickEntry":
|
|
23779
|
+
conditionalNodes = node.children;
|
|
23780
|
+
rawContainer = node.rawContainer;
|
|
23781
|
+
rawKey = node.rawKey;
|
|
23782
|
+
break;
|
|
23524
23783
|
}
|
|
23525
|
-
}
|
|
23526
|
-
}
|
|
23527
|
-
|
|
23528
|
-
function removeDeadConditionsInContext(context, options) {
|
|
23529
|
-
removeDeadConditionsInArray(context, options);
|
|
23530
|
-
}
|
|
23531
|
-
|
|
23532
|
-
function removeDeadConditionsInArray(list, options, callback) {
|
|
23533
|
-
if (Array.isArray(list)) {
|
|
23534
|
-
var removes = [];
|
|
23535
23784
|
|
|
23536
|
-
|
|
23537
|
-
computeConstantCondition(_item3, options);
|
|
23785
|
+
shakeConditionalNodes(node, rawContainer, conditionalNodes, rawKey, deleteEmptyArray); // Remove unreachable context/state.
|
|
23538
23786
|
|
|
23539
|
-
|
|
23540
|
-
removes.push(_item3);
|
|
23541
|
-
continue;
|
|
23542
|
-
}
|
|
23787
|
+
deleteEmptyArray = false;
|
|
23543
23788
|
|
|
23544
|
-
|
|
23789
|
+
switch (node.type) {
|
|
23790
|
+
case "Route":
|
|
23791
|
+
case "Brick":
|
|
23792
|
+
case "Template":
|
|
23793
|
+
rawContainer = node.raw;
|
|
23794
|
+
rawKey = node.type === "Template" ? "state" : "context";
|
|
23795
|
+
conditionalNodes = node.context;
|
|
23796
|
+
break;
|
|
23545
23797
|
}
|
|
23546
23798
|
|
|
23547
|
-
|
|
23548
|
-
}
|
|
23799
|
+
shakeConditionalNodes(node, rawContainer, conditionalNodes, rawKey, deleteEmptyArray);
|
|
23800
|
+
});
|
|
23549
23801
|
}
|
|
23550
23802
|
|
|
23551
|
-
function
|
|
23552
|
-
if
|
|
23553
|
-
removeDeadConditionsInArray(lifeCycle.useResolves, options);
|
|
23803
|
+
function shakeConditionalNodes(node, rawContainer, conditionalNodes, rawKey, deleteEmptyArray) {
|
|
23804
|
+
var removedNodes = remove(conditionalNodes, node => node.raw.if === false);
|
|
23554
23805
|
|
|
23555
|
-
|
|
23556
|
-
|
|
23557
|
-
|
|
23558
|
-
|
|
23559
|
-
|
|
23560
|
-
|
|
23561
|
-
|
|
23562
|
-
|
|
23563
|
-
|
|
23564
|
-
|
|
23806
|
+
if (removedNodes.length > 0) {
|
|
23807
|
+
if (node.type === "UseBrickEntry" && !Array.isArray(rawContainer[rawKey])) {
|
|
23808
|
+
rawContainer[rawKey] = {
|
|
23809
|
+
brick: "div",
|
|
23810
|
+
if: false
|
|
23811
|
+
};
|
|
23812
|
+
} else if (deleteEmptyArray && conditionalNodes.length === 0) {
|
|
23813
|
+
delete rawContainer[rawKey];
|
|
23814
|
+
} else {
|
|
23815
|
+
rawContainer[rawKey] = conditionalNodes.map(node => node.raw);
|
|
23565
23816
|
}
|
|
23566
23817
|
}
|
|
23567
23818
|
}
|
|
23819
|
+
/**
|
|
23820
|
+
* Like `removeDeadConditions` but applied to a custom template.
|
|
23821
|
+
*/
|
|
23568
23822
|
|
|
23823
|
+
|
|
23824
|
+
function removeDeadConditionsInTpl(tplConstructor, options) {
|
|
23825
|
+
var ast = parseTemplate(tplConstructor);
|
|
23826
|
+
removeDeadConditionsByAst(ast, options);
|
|
23827
|
+
}
|
|
23569
23828
|
function computeConstantCondition(ifContainer) {
|
|
23570
23829
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23571
23830
|
|
|
@@ -23583,8 +23842,8 @@ function computeConstantCondition(ifContainer) {
|
|
|
23583
23842
|
} = options;
|
|
23584
23843
|
var hasDynamicVariables = false;
|
|
23585
23844
|
|
|
23586
|
-
for (var
|
|
23587
|
-
if (
|
|
23845
|
+
for (var item of attemptToVisitGlobals) {
|
|
23846
|
+
if (item !== "undefined" && (!constantFeatureFlags || item !== "FLAGS")) {
|
|
23588
23847
|
hasDynamicVariables = true;
|
|
23589
23848
|
break;
|
|
23590
23849
|
}
|
|
@@ -23658,5 +23917,5 @@ function isConstantLogical(node, expect, options) {
|
|
|
23658
23917
|
return node.type === "LogicalExpression" ? node.operator === (expect ? "||" : "&&") && [node.left, node.right].some(item => isConstantLogical(item, expect, options)) : node.type === "UnaryExpression" ? node.operator === "!" && isConstantLogical(node.argument, !expect, options) : node.type === "Literal" ? !!node.value === expect : node.type === "Identifier" ? node.name === "undefined" ? !expect : false : constantFeatureFlags && node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "FLAGS" && (node.computed ? node.property.type === "Literal" && typeof node.property.value === "string" && !!featureFlags[node.property.value] === expect : node.property.type === "Identifier" && !!featureFlags[node.property.name] === expect);
|
|
23659
23918
|
}
|
|
23660
23919
|
|
|
23661
|
-
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject, isRouteNode, isSnippetNode, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseForAnalysis, precook, precookFunction, preevaluate, prefetchScript, removeDeadConditions, removeDeadConditionsInTpl, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
23920
|
+
export { JsonStorage, PrecookFunctionVisitor, PrecookVisitor, asyncProcessBrick, asyncProcessStoryboard, collectBricksByCustomTemplates, computeConstantCondition, computeRealRoutePath, convertValueByPrecision, cook, createProviderClass, debounceByAnimationFrame, deepFreeze, formatValue, getDependencyMapOfContext, getDepsOfTemplates, getDllAndDepsByResource, getDllAndDepsOfBricks, getDllAndDepsOfStoryboard, getTemplateDepsOfStoryboard, hasOwnProperty$1 as hasOwnProperty, inject, isBrickNode, isCustomTemplateNode, isEvaluable, isObject$1 as isObject, isRouteNode, isSnippetNode, lint, loadScript, makeThrottledAggregation, mapCustomApisToNameAndNamespace, matchPath, normalizeBuilderNode, normalizeMenu, parseBrick, parseForAnalysis, parseRoutes, parseStoryboard, parseTemplate, parseTemplates, precook, precookFunction, preevaluate, prefetchScript, removeDeadConditions, removeDeadConditionsInTpl, resolveContextConcurrently, restoreDynamicTemplates, scanAppGetMenuInAny, scanAppGetMenuInStoryboard, scanBricksInBrickConf, scanBricksInStoryboard, scanCustomApisInStoryboard, scanI18NInAny, scanI18NInStoryboard, scanInstalledAppsInStoryboard, scanPermissionActionsInAny, scanPermissionActionsInStoryboard, scanProcessorsInAny, scanProcessorsInStoryboard, scanRouteAliasInStoryboard, scanStoryboard, scanStoryboardAst, scanTemplatesInBrick, scanTemplatesInStoryboard, shouldAllowRecursiveEvaluations, smartDisplayForEvaluableString, syncResolveContextConcurrently, toPath, tokTypes_1 as tokTypes, trackContext, trackState, trackUsedContext, trackUsedState, transform, transformAndInject, traverse, traverseStoryboard, visitStoryboardExpressions, visitStoryboardFunctions };
|
|
23662
23921
|
//# sourceMappingURL=index.esm.js.map
|