Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修改引用多个相同小程序组件时构建错误的问题 (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pochodaydayup authored and yesmeck committed Nov 20, 2019
1 parent 209302f commit da01293
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import '../npm/remax/esm/adapters/alipay/api.js';

var D = function(props) {
return createElement(
'd-1',
'd-0',
props,
props.children
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ const importers: Importers<
export const getKebabCaseName = (sourcePath: string) =>
kebabCase(path.basename(path.dirname(sourcePath)));

const nativeIds: Map<string, number> = new Map();
const nativeIds: Map<string, string[]> = new Map();

const getHashId = (id: string) => {
const nativeId = nativeIds.get(id);
const getHashId = (sourcePath: string, id: string) => {
const sourcePaths = nativeIds.get(id);

if (nativeId === undefined) {
nativeIds.set(id, 0);
return `${id}-0`;
}
if (sourcePaths) {
const index = sourcePaths.findIndex(source => source === sourcePath);

if (index >= 0) {
return `${id}-${index}`;
}

nativeIds.set(id, nativeId + 1);
sourcePaths.push(sourcePath);
return `${id}-${sourcePaths.length - 1}`;
}

return `${id}-${nativeId + 1}`;
nativeIds.set(id, [sourcePath]);
return `${id}-0`;
};

export default (options: RemaxOptions, adapter: Adapter) => {
Expand All @@ -43,9 +48,9 @@ export default (options: RemaxOptions, adapter: Adapter) => {
importers.delete(state.opts.filename);
},
visitor: {
JSXElement(nodePath: NodePath, state: any) {
JSXElement(nodePath: NodePath<t.JSXElement>, state: any) {
const importer: string = state.file.opts.filename;
const node = nodePath.node as t.JSXElement;
const node = nodePath.node;

if (t.isJSXIdentifier(node.openingElement.name)) {
const tagName = node.openingElement.name.name;
Expand Down Expand Up @@ -88,7 +93,7 @@ export default (options: RemaxOptions, adapter: Adapter) => {
id: sourcePath,
props: new Set(props),
importer,
hashId: getHashId(id),
hashId: getHashId(sourcePath, id),
pages: new Set([]),
};

Expand Down

0 comments on commit da01293

Please sign in to comment.