Skip to content

Commit 09440a2

Browse files
committed
chore: 添加测试用例
1 parent e6dba75 commit 09440a2

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

packages/uni-cli-shared/__tests__/usingComponents.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,43 @@ export function createApp() {
301301
`const _easycom_test = ()=>import('${inputDir}/components/test/test.vue')`
302302
)
303303
})
304+
test(`recursion`, async () => {
305+
await testLocal(
306+
`
307+
const _sfc_main = {
308+
};
309+
const __BINDING_COMPONENTS__ = '{"index":{"name":"_component_index","type":"unknown"}}';
310+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
311+
return {};
312+
}
313+
import "${filename}?vue&type=style&index=0&lang.css";
314+
import _export_sfc from "plugin-vue:export-helper";
315+
export default /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
316+
`,
317+
{
318+
index: '/pages/index/index',
319+
},
320+
``
321+
)
322+
await testLocal(
323+
`import { defineComponent as _defineComponent } from "vue";
324+
const __BINDING_COMPONENTS__ = '{"test":{"name":"test","type":"unknown"}}';
325+
326+
export default /* @__PURE__ */ _defineComponent({
327+
__name: "test",
328+
setup(__props) {
329+
return (_ctx, _cache) => {
330+
return {};
331+
};
332+
}
333+
});
334+
import "${inputDir}/pages/index/index.vue?vue&type=style&index=0&lang.css";
335+
`,
336+
{
337+
test: '/pages/index/index',
338+
},
339+
``
340+
)
341+
})
304342
})
305343
})

packages/uni-cli-shared/src/mp/usingComponents.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function parseVueComponentName(filename: string) {
216216
} else if (
217217
declaration.type === 'CallExpression' &&
218218
declaration.callee.type === 'Identifier' &&
219-
declaration.callee.name === '_defineComponent'
219+
/_*defineComponent/.test(declaration.callee.name)
220220
) {
221221
defineComponentDeclaration =
222222
(declaration.arguments[0] as ObjectExpression | undefined) || null
@@ -228,7 +228,7 @@ function parseVueComponentName(filename: string) {
228228
if (
229229
prop.type === 'ObjectProperty' &&
230230
prop.key.type === 'Identifier' &&
231-
prop.key.name === '__name' &&
231+
/(__)?name/.test(prop.key.name) &&
232232
prop.value.type === 'StringLiteral'
233233
) {
234234
return prop.value.value
@@ -261,15 +261,18 @@ function createUsingComponents(
261261
})
262262

263263
if (filename) {
264-
const name = parseVueComponentName(filename)
264+
const componentName = normalizeComponentName(
265+
hyphenate(parseVueComponentName(filename))
266+
)
265267

266268
if (
267269
!Object.keys(bindingComponents).find(
268-
(v) => bindingComponents[v].tag === name
270+
(v) =>
271+
normalizeComponentName(hyphenate(bindingComponents[v].tag)) ===
272+
componentName
269273
)
270274
)
271275
return usingComponents
272-
const componentName = normalizeComponentName(hyphenate(name))
273276
if (!usingComponents[componentName]) {
274277
usingComponents[componentName] = addLeadingSlash(
275278
removeExt(normalizeMiniProgramFilename(filename, inputDir))

0 commit comments

Comments
 (0)