function parseComponentPath(filePath, relativePath) {
  var REG = /(\/|^)[^/]+$/; // `abc/xxx` 中的 `/xxx`
  var SAME_REG = /^\.\//; // 以 `./` 开头
  var DIFF_REG = /^\.\.\//; // 以 `../` 开头
  var generatePath = function generatePath(list) {
    return list.filter(function (item) {
      return item;
    }).join('/');
  };
  if (filePath.startsWith('/')) {
    return filePath.replace(/^\//, '');
  }
  if (relativePath.startsWith('/')) {
    return relativePath.replace(/^\//, '');
  }
  var tempResult = filePath;
  tempResult = tempResult.replace(REG, '');
  if (SAME_REG.test(relativePath)) {
    return generatePath([tempResult, relativePath.replace(SAME_REG, '')]);
  }
  var tempRelative = relativePath;
  while (DIFF_REG.test(tempRelative)) {
    tempResult = tempResult.replace(REG, '');
    tempRelative = tempRelative.replace(DIFF_REG, '');
  }
  return generatePath([tempResult, tempRelative]);
}

export { parseComponentPath };
