@dcloudio/uni-cli-shared 3.0.0-alpha-3030820220114003 → 3.0.0-alpha-3030820220114006

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/mp/event.js CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatMiniProgramEvent = void 0;
4
+ const uni_shared_1 = require("@dcloudio/uni-shared");
4
5
  function formatMiniProgramEvent(eventName, { isCatch, isCapture, isComponent, }) {
6
+ if (isComponent) {
7
+ // 自定义组件的自定义事件需要格式化,因为 triggerEvent 时也会格式化
8
+ eventName = (0, uni_shared_1.customizeEvent)(eventName);
9
+ }
5
10
  if (!isComponent && eventName === 'click') {
6
11
  eventName = 'tap';
7
12
  }
@@ -1,4 +1,5 @@
1
1
  export * from './ast';
2
+ export * from './wxs';
2
3
  export * from './nvue';
3
4
  export * from './event';
4
5
  export * from './style';
package/dist/mp/index.js CHANGED
@@ -12,6 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.updateMiniProgramComponentExternalClasses = exports.findMiniProgramComponentExternalClasses = exports.parseExternalClasses = exports.hasExternalClasses = exports.updateMiniProgramComponentsByTemplateFilename = exports.updateMiniProgramComponentsByScriptFilename = exports.updateMiniProgramComponentsByMainFilename = exports.updateMiniProgramGlobalComponents = exports.transformDynamicImports = exports.parseTemplateDescriptor = exports.parseScriptDescriptor = exports.parseMainDescriptor = exports.copyMiniProgramPluginJson = exports.HTML_TO_MINI_PROGRAM_TAGS = void 0;
14
14
  __exportStar(require("./ast"), exports);
15
+ __exportStar(require("./wxs"), exports);
15
16
  __exportStar(require("./nvue"), exports);
16
17
  __exportStar(require("./event"), exports);
17
18
  __exportStar(require("./style"), exports);
@@ -130,8 +130,22 @@ function findBindingComponent(tag, bindingComponents) {
130
130
  return tag === componentTag || tag === camelName || tag === PascalName;
131
131
  });
132
132
  }
133
+ function normalizeComponentId(id) {
134
+ // _unref(test) => test
135
+ if (id.includes('_unref(')) {
136
+ return id.replace('_unref(', '').replace(')', '');
137
+ }
138
+ // $setup["test"] => test
139
+ if (id.includes('$setup[')) {
140
+ return id.replace('$setup["', '').replace('"', '');
141
+ }
142
+ return id;
143
+ }
133
144
  function parseBindingComponents(templateBindingComponents, scriptBindingComponents) {
134
- const bindingComponents = { ...templateBindingComponents };
145
+ const bindingComponents = {};
146
+ Object.keys(templateBindingComponents).forEach((id) => {
147
+ bindingComponents[normalizeComponentId(id)] = templateBindingComponents[id];
148
+ });
135
149
  Object.keys(scriptBindingComponents).forEach((id) => {
136
150
  const { tag } = scriptBindingComponents[id];
137
151
  const name = findBindingComponent(tag, templateBindingComponents);
@@ -0,0 +1,2 @@
1
+ export declare function parseWxsCallMethods(code: string): string[];
2
+ export declare function genWxsCallMethodsCode(code: string): string;
package/dist/mp/wxs.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genWxsCallMethodsCode = exports.parseWxsCallMethods = void 0;
4
+ const types_1 = require("@babel/types");
5
+ const estree_walker_1 = require("estree-walker");
6
+ const ast_1 = require("./ast");
7
+ function parseWxsCallMethods(code) {
8
+ if (!code.includes('callMethod')) {
9
+ return [];
10
+ }
11
+ const ast = (0, ast_1.parseProgram)(code, '', {});
12
+ const wxsCallMethods = new Set();
13
+ estree_walker_1.walk(ast, {
14
+ enter(child) {
15
+ if (!(0, types_1.isCallExpression)(child)) {
16
+ return;
17
+ }
18
+ const { callee } = child;
19
+ // .callMethod
20
+ if (!(0, types_1.isMemberExpression)(callee) ||
21
+ !(0, types_1.isIdentifier)(callee.property) ||
22
+ callee.property.name !== 'callMethod') {
23
+ return;
24
+ }
25
+ // .callMethod('test',...)
26
+ const args = child.arguments;
27
+ if (!args.length) {
28
+ return;
29
+ }
30
+ const [name] = args;
31
+ if (!(0, types_1.isStringLiteral)(name)) {
32
+ return;
33
+ }
34
+ wxsCallMethods.add(name.value);
35
+ },
36
+ });
37
+ return [...wxsCallMethods];
38
+ }
39
+ exports.parseWxsCallMethods = parseWxsCallMethods;
40
+ function genWxsCallMethodsCode(code) {
41
+ const wxsCallMethods = parseWxsCallMethods(code);
42
+ if (!wxsCallMethods.length) {
43
+ return `export default {}`;
44
+ }
45
+ return `export default (Component) => {
46
+ if(!Component.wxsCallMethods){
47
+ Component.wxsCallMethods = []
48
+ }
49
+ Component.wxsCallMethods.push(${wxsCallMethods
50
+ .map((m) => `'${m}'`)
51
+ .join(', ')})
52
+ }
53
+ `;
54
+ }
55
+ exports.genWxsCallMethodsCode = genWxsCallMethodsCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3030820220114003",
3
+ "version": "3.0.0-alpha-3030820220114006",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "@babel/core": "^7.16.5",
22
22
  "@babel/parser": "^7.16.4",
23
23
  "@babel/types": "^7.16.0",
24
- "@dcloudio/uni-i18n": "3.0.0-alpha-3030820220114003",
25
- "@dcloudio/uni-shared": "3.0.0-alpha-3030820220114003",
24
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3030820220114006",
25
+ "@dcloudio/uni-shared": "3.0.0-alpha-3030820220114006",
26
26
  "@rollup/pluginutils": "^4.1.2",
27
27
  "@vue/compiler-core": "3.2.27",
28
28
  "@vue/compiler-dom": "3.2.27",