swc/node-swc/__tests__/is_module_unknown_test.js
Sven 65d376a91b
feat(swc): Add IsModule (#2601)
swc:
 - Allow parsing input as a `Program`. (Closes #2541)
2021-11-16 10:31:02 +00:00

17 lines
488 B
JavaScript

const swc = require("../../");
it("should detect script", () => {
const script = swc.parseSync(`const fs = require('fs');`, { isModule: "unknown" });
expect(script.type).toBe("Script");
});
it("should default to isModule: true", () => {
const script = swc.parseSync(`foo;`, {});
expect(script.type).toBe("Module");
});
it("should detect module", () => {
const script = swc.parseSync(`import fs from "fs";`, { isModule: "unknown" });
expect(script.type).toBe("Module");
});