Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 11, 2024
1 parent e0588a2 commit b6f0452
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const ESM_RE =
const BUILTIN_EXTENSIONS = new Set([".mjs", ".cjs", ".node", ".wasm"]);

export function hasESMSyntax(code: string): boolean {
return ESM_RE.test(code.replace(/\/\*.+?\*\/|\/\/.*(?=[nr])/g, ''));
return ESM_RE.test(code.replace(/\/\*.+?\*\/|\/\/.*(?=[nr])/g, ""));
}

const CJS_RE =
/([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
export function hasCJSSyntax(code: string): boolean {
return CJS_RE.test(code.replace(/\/\*.+?\*\/|\/\/.*(?=[nr])/g, ''));
return CJS_RE.test(code.replace(/\/\*.+?\*\/|\/\/.*(?=[nr])/g, ""));
}

export function detectSyntax(code: string) {
Expand Down
3 changes: 2 additions & 1 deletion test/syntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const staticTests = {
isMixed: false,
},
"const a={};": { hasESM: false, hasCJS: false, isMixed: false },
"// They're exposed using \"export import\" so that types are passed along as expected\nmodule.exports={};": { hasESM: false, hasCJS: true , isMixed: false }
'// They\'re exposed using "export import" so that types are passed along as expected\nmodule.exports={};':
{ hasESM: false, hasCJS: true, isMixed: false },
};

describe("detectSyntax", () => {
Expand Down

0 comments on commit b6f0452

Please sign in to comment.