@next-core/brick-utils 2.38.1 → 2.39.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/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.39.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.38.3...@next-core/brick-utils@2.39.0) (2022-08-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * context can track its deps now ([4993308](https://github.com/easyops-cn/next-core/commit/49933089e1ff6ec1ec5f01eeac5609dde07c1e2e))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.38.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.38.2...@next-core/brick-utils@2.38.3) (2022-08-23)
18
+
19
+ **Note:** Version bump only for package @next-core/brick-utils
20
+
21
+
22
+
23
+
24
+
25
+ ## [2.38.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.38.1...@next-core/brick-utils@2.38.2) (2022-08-19)
26
+
27
+ **Note:** Version bump only for package @next-core/brick-utils
28
+
29
+
30
+
31
+
32
+
6
33
  ## [2.38.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-utils@2.38.0...@next-core/brick-utils@2.38.1) (2022-08-08)
7
34
 
8
35
  **Note:** Version bump only for package @next-core/brick-utils
@@ -22633,7 +22633,7 @@
22633
22633
  };
22634
22634
 
22635
22635
  if (!_contextConf2.property) {
22636
- visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory(stats, keyword), keyword);
22636
+ visitStoryboardExpressions([_contextConf2.if, _contextConf2.value, _contextConf2.resolve], beforeVisitContextFactory$1(stats, keyword), keyword);
22637
22637
  }
22638
22638
 
22639
22639
  depsMap.set(_contextConf2, stats);
@@ -22642,7 +22642,7 @@
22642
22642
  return depsMap;
22643
22643
  }
22644
22644
 
22645
- function beforeVisitContextFactory(stats, keyword) {
22645
+ function beforeVisitContextFactory$1(stats, keyword) {
22646
22646
  return function beforeVisitContext(node, parent) {
22647
22647
  if (node.name === keyword) {
22648
22648
  var memberParent = parent[parent.length - 1];
@@ -22970,6 +22970,12 @@
22970
22970
  function trackState(raw) {
22971
22971
  return track(raw, "track state", "STATE");
22972
22972
  }
22973
+ function trackUsedContext(data) {
22974
+ return trackUsed(data, "CTX");
22975
+ }
22976
+ function trackUsedState(data) {
22977
+ return trackUsed(data, "STATE");
22978
+ }
22973
22979
 
22974
22980
  function track(raw, trackText, variableName) {
22975
22981
  if (raw.includes(trackText)) {
@@ -22979,22 +22985,7 @@
22979
22985
  } = preevaluate(raw, {
22980
22986
  withParent: true,
22981
22987
  hooks: {
22982
- beforeVisitGlobal(node, parent) {
22983
- if (node.name === variableName) {
22984
- var memberParent = parent[parent.length - 1];
22985
-
22986
- if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
22987
- var memberNode = memberParent.node;
22988
-
22989
- if (!memberNode.computed && memberNode.property.type === "Identifier") {
22990
- contexts.add(memberNode.property.name);
22991
- } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
22992
- contexts.add(memberNode.property.value);
22993
- }
22994
- }
22995
- }
22996
- }
22997
-
22988
+ beforeVisitGlobal: beforeVisitContextFactory(contexts, variableName)
22998
22989
  }
22999
22990
  });
23000
22991
  var trackCtxExp;
@@ -23012,6 +23003,30 @@
23012
23003
  return false;
23013
23004
  }
23014
23005
 
23006
+ function trackUsed(data, variableName) {
23007
+ var contexts = new Set();
23008
+ visitStoryboardExpressions(data, beforeVisitContextFactory(contexts, variableName), variableName);
23009
+ return Array.from(contexts);
23010
+ }
23011
+
23012
+ function beforeVisitContextFactory(contexts, variableName) {
23013
+ return function beforeVisitContext(node, parent) {
23014
+ if (node.name === variableName) {
23015
+ var memberParent = parent[parent.length - 1];
23016
+
23017
+ if ((memberParent === null || memberParent === void 0 ? void 0 : memberParent.node.type) === "MemberExpression" && memberParent.key === "object") {
23018
+ var memberNode = memberParent.node;
23019
+
23020
+ if (!memberNode.computed && memberNode.property.type === "Identifier") {
23021
+ contexts.add(memberNode.property.name);
23022
+ } else if (memberNode.computed && memberNode.property.type === "Literal" && typeof memberNode.property.value === "string") {
23023
+ contexts.add(memberNode.property.value);
23024
+ }
23025
+ }
23026
+ }
23027
+ };
23028
+ }
23029
+
23015
23030
  // The debounce function receives our function as a parameter
23016
23031
  function debounceByAnimationFrame(fn) {
23017
23032
  // This holds the requestAnimationFrame reference, so we can cancel it if we wish
@@ -23134,6 +23149,8 @@
23134
23149
  exports.tokTypes = tokTypes_1;
23135
23150
  exports.trackContext = trackContext;
23136
23151
  exports.trackState = trackState;
23152
+ exports.trackUsedContext = trackUsedContext;
23153
+ exports.trackUsedState = trackUsedState;
23137
23154
  exports.transform = transform;
23138
23155
  exports.transformAndInject = transformAndInject;
23139
23156
  exports.visitStoryboardExpressions = visitStoryboardExpressions;