miaoda-expo-devkit 0.1.1-beta.74 → 0.1.1-beta.76

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.
@@ -1,4 +1,4 @@
1
- import { types, PluginObj } from '@babel/core';
1
+ import { types, PluginObj, PluginPass } from '@babel/core';
2
2
 
3
3
  /**
4
4
  * babel-plugin-jsx-source
@@ -40,11 +40,16 @@ interface JsxSourcePluginOptions {
40
40
  /** 需要跳过注入的包名列表,从这些包导入的组件不会被注入 */
41
41
  excludePackages?: string[];
42
42
  }
43
+ interface PluginState extends PluginPass {
44
+ opts: JsxSourcePluginOptions;
45
+ /** 当前文件中来自被排除包的本地标识符集合,Program 阶段初始化 */
46
+ excludedComponents: Set<string>;
47
+ }
43
48
  /**
44
49
  * Babel 插件:为 JSX 元素注入 dataSet
45
50
  */
46
51
  declare function babelPluginJsxSource({ types: t, }: {
47
52
  types: typeof types;
48
- }): PluginObj;
53
+ }): PluginObj<PluginState>;
49
54
 
50
55
  export { type JsxSourcePluginOptions, babelPluginJsxSource as default };
@@ -104,24 +104,25 @@ function shouldSkipElement(t, name) {
104
104
  function babelPluginJsxSource({
105
105
  types: t
106
106
  }) {
107
- let excludedIdentifiers;
108
107
  return {
109
108
  name: "babel-plugin-jsx-source",
110
109
  visitor: {
111
110
  Program(_path, state) {
112
- excludedIdentifiers = /* @__PURE__ */ new Set();
113
111
  const excludePackages = [
114
112
  ...DEFAULT_EXCLUDE_PACKAGES,
115
- ...state.opts.excludePackages || []
113
+ ...state.opts.excludePackages ?? []
116
114
  ];
117
- const programBody = _path.node.body;
118
- for (const node of programBody) {
119
- if (t.isImportDeclaration(node) && excludePackages.some((pkg) => node.source.value === pkg || node.source.value.startsWith(pkg + "/"))) {
115
+ const excluded = /* @__PURE__ */ new Set();
116
+ for (const node of _path.node.body) {
117
+ if (t.isImportDeclaration(node) && excludePackages.some(
118
+ (pkg) => node.source.value === pkg || node.source.value.startsWith(pkg + "/")
119
+ )) {
120
120
  for (const specifier of node.specifiers) {
121
- excludedIdentifiers.add(specifier.local.name);
121
+ excluded.add(specifier.local.name);
122
122
  }
123
123
  }
124
124
  }
125
+ state.excludedComponents = excluded;
125
126
  },
126
127
  JSXOpeningElement(path, state) {
127
128
  const { opts, filename } = state;
@@ -130,8 +131,8 @@ function babelPluginJsxSource({
130
131
  if (opts.excludePaths?.some((p) => filename.includes(p))) return;
131
132
  if (shouldSkipElement(t, path.node.name)) return;
132
133
  const elementName = path.node.name;
133
- if (t.isJSXIdentifier(elementName) && excludedIdentifiers.has(elementName.name)) return;
134
- if (t.isJSXMemberExpression(elementName) && t.isJSXIdentifier(elementName.object) && excludedIdentifiers.has(elementName.object.name)) return;
134
+ if (t.isJSXIdentifier(elementName) && state.excludedComponents.has(elementName.name)) return;
135
+ if (t.isJSXMemberExpression(elementName) && t.isJSXIdentifier(elementName.object) && state.excludedComponents.has(elementName.object.name)) return;
135
136
  const loc = path.node.loc;
136
137
  if (!loc) return;
137
138
  let filePath = filename;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-expo-devkit",
3
- "version": "0.1.1-beta.74",
3
+ "version": "0.1.1-beta.76",
4
4
  "description": "Expo 应用开发工具集:Sentry DSN 替换 stub、错误/网络捕获、Metro 符号化",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",