将一个 .js 文件导入另一个文件(JSLINT 无法识别“导入”关键字)

Import a .js file into another (JSLINT doesn't recognize the "Import" key word)

提问人:Mark 提问时间:2/25/2023 更新时间:2/25/2023 访问量:37

问:

我正在尝试将.js文件导入到antoher.js文件中。JSLint 抛出错误,似乎无法识别“import”语句

The errros

import "./Scripts/dompurify/purify.min.js";

(function ($, constants, appUtilities, window, confirm) {
    var DATE_PATTERN = /^(?=\d)(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))$/, GTSelectedTestId,
        ADDRESS_PATTERN = /^[0-9a-zA-Z.'@#%&\/-\s]*$/;

    function mutexCheckboxSelection(mutexCheckboxes, event) {
        if (!mutexCheckboxes || mutexCheckboxes.length < 2) {
            return;
        }

JavaScript 导入 jslint

评论

0赞 ruffin 2/25/2023
JSLint 不再由 Douglas Crockford 维护,每次我再看一遍,代码似乎更加臃肿,网站不太用户友好,最后一个是在说些什么。在es6+的使用上一直很保守,我在 jslint.com 上找不到允许的选项。似乎它在那里,但代码有大量注释掉的东西,并且并不紧凑。我曾经讨厌人们这么说,但现在可能是时候转向 eslint 了。import

答:

0赞 ruffin 2/25/2023 #1

好的,我将坚持我最初的评论,即您可能想转移到 eslint,但我拿走了您的片段,填写了它,然后这个 lints。

我认为底线是 jslint 目前只允许一种导入语法

import foo from "source"import {foo, bar} from "source"

/*global jQuery */
import something from "./Scripts/dompurify/purify.min.js";

(function ($, constants, appUtilities, window, confirm) {
    var GTSelectedTestId;
    var ADDRESS_PATTERN = /^[0-9a-zA-Z.'@#%&\/-\s]*$/;

    function mutexCheckboxSelection(mutexCheckboxes, event) {
        if (!mutexCheckboxes || mutexCheckboxes.length < 2) {
            return;
        }

        return event;
    }

    GTSelectedTestId = 5;
    console.log(
        "listing vars here to shush errors about unused vars",
        $,
        constants,
        appUtilities,
        window,
        confirm,
        GTSelectedTestId,
        ADDRESS_PATTERN,
        something
    );

    return mutexCheckboxSelection;
}(jQuery, [], [], window, true));

所以很明显,你应该编辑与你的用例的匹配,但随后它应该lint。something