web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

  1. # import/unambiguous
  2. Warn if a `module` could be mistakenly parsed as a `script` by a consumer leveraging
  3. [Unambiguous JavaScript Grammar] to determine correct parsing goal.
  4. Will respect the [`parserOptions.sourceType`] from ESLint config, i.e. files parsed
  5. as `script` per that setting will not be reported.
  6. This plugin uses [Unambiguous JavaScript Grammar] internally to decide whether
  7. dependencies should be parsed as modules and searched for exports matching the
  8. `import`ed names, so it may be beneficial to keep this rule on even if your application
  9. will run in an explicit `module`-only environment.
  10. ## Rule Details
  11. For files parsed as `module` by ESLint, the following are valid:
  12. ```js
  13. import 'foo'
  14. function x() { return 42 }
  15. ```
  16. ```js
  17. export function x() { return 42 }
  18. ```
  19. ```js
  20. (function x() { return 42 })()
  21. export {} // simple way to mark side-effects-only file as 'module' without any imports/exports
  22. ```
  23. ...whereas the following file would be reported:
  24. ```js
  25. (function x() { return 42 })()
  26. ```
  27. ## When Not To Use It
  28. If your application environment will always know via [some other means](https://github.com/nodejs/node-eps/issues/13)
  29. how to parse, regardless of syntax, you may not need this rule.
  30. Remember, though, that this plugin uses this strategy internally, so if you were
  31. to `import` from a module with no `import`s or `export`s, this plugin would not
  32. report it as it would not be clear whether it should be considered a `script` or
  33. a `module`.
  34. ## Further Reading
  35. - [Unambiguous JavaScript Grammar]
  36. - [`parserOptions.sourceType`]
  37. - [node-eps#13](https://github.com/nodejs/node-eps/issues/13)
  38. [`parserOptions.sourceType`]: http://eslint.org/docs/user-guide/configuring#specifying-parser-options
  39. [Unambiguous JavaScript Grammar]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md#32-determining-if-source-is-an-es-module