зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1779989 - Explicitly disallow ES modules in ESLint import-globals-from statements. r=arai
Differential Revision: https://phabricator.services.mozilla.com/D152002
This commit is contained in:
Родитель
f724fd0ca0
Коммит
a869ce033b
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
Загрузка…
Ссылка в новой задаче