Commit a869ce03 authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1779989 - Explicitly disallow ES modules in ESLint import-globals-from statements. r=arai

parent f724fd0c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -12,3 +12,7 @@ on each other's globals.

If <path> is a relative path, then it must be relative to the file being
checked by the rule.

Note: ``import-globals-from`` does not support loading globals from ES modules.
These should be imported as variable definitions directly, or the file where
they are imported should be referenced.
+18 −1
Original line number Diff line number Diff line
@@ -81,8 +81,9 @@ var lastHTMLGlobals = {};
 * @param  {String} filePath
 *         The absolute path of the file being parsed.
 */
function GlobalsForNode(filePath) {
function GlobalsForNode(filePath, context) {
  this.path = filePath;
  this.context = context;

  if (this.path) {
    this.dirname = path.dirname(this.path);
@@ -128,6 +129,22 @@ GlobalsForNode.prototype = {

      let filePath = match[1].trim();

      if (filePath.endsWith(".mjs")) {
        if (this.context) {
          this.context.report(
            comment,
            "import-globals-from does not support module files - use a direct import instead"
          );
        } else {
          // Fall back to throwing an error, as we do not have a context in all situations,
          // e.g. when loading the environment.
          throw new Error(
            "import-globals-from does not support module files - use a direct import instead"
          );
        }
        continue;
      }

      if (!path.isAbsolute(filePath)) {
        filePath = path.resolve(this.dirname, filePath);
      } else {