JavaScript ES modules import and export with trailing commas All In One

发布时间 2023-03-24 15:07:50作者: xgqfrms

JavaScript ES modules import and export with trailing commas All In One

JavaScript 最佳实践

image

export + trailing commas


export {
  module1,
  module2,
  // ...
  moduleN,
} from './modules/index.ts';

demos

React 中就是这种写法

trailing comma + export

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

// Export all exports so that they're available in tests.
// We can't use export * from in Flow for some reason.
export {default as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/ReactDOMSharedInternals';
export {
  createPortal,
  createRoot,
  hydrateRoot,
  findDOMNode,
  flushSync,
  hydrate,
  render,
  unmountComponentAtNode,
  unstable_batchedUpdates,
  unstable_createEventHandle,
  unstable_renderSubtreeIntoContainer,
  unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
  prefetchDNS,
  preconnect,
  preload,
  preinit,
  version,
} from './src/client/ReactDOM';

https://github.com/facebook/react/blob/main/packages/react-dom/index.js

https://raw.githubusercontent.com/facebook/react/main/packages/react-dom/index.js

bugs

const uppercaseString = (string) => {
  return string.toUpperCase();
}

const lowercaseString = (string) => {
  return string.toLowerCase()
}

// export {uppercaseString, lowercaseString};
export {
  uppercaseString,
  lowercaseString // ✅
  // lowercaseString,// bug ❌
};
export const uppercaseString = (string) => {
   return string.toUpperCase();
}

export const lowercaseString = (string) => {
  return string.toLowerCase()
}

image

image

https://forum.freecodecamp.org/t/es6-export/600314

(? 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 ?️,侵权必究⚠️!