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

54 Views Asked by At

I am trying to import a .js file into antoher.js file. JSLint is throwing errors and doesn't seem to recognize the "import" statement

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;
        }

1

There are 1 best solutions below

0
ruffin On

Okay, I'm going to stick to my original comment that you likely want to move to eslint, but I took your snippet, filled it out, and this lints.

I think the bottom line is that jslint only allows one import syntax currently:

import foo from "source" or 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));

So obviously you should edit match something to your use case, but then it should lint.