From 7543021ba6bea9fb7258c323e8714ce2929ad4c2 Mon Sep 17 00:00:00 2001 From: Yue JIN <40021217+kingyue737@users.noreply.github.com> Date: Fri, 7 Jul 2023 14:05:25 +0800 Subject: [PATCH] fix estree plugin type declaration (#15018) Co-authored-by: fisker Cheung --- changelog_unreleased/api/15018.md | 3 +++ scripts/build/build-types.js | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelog_unreleased/api/15018.md diff --git a/changelog_unreleased/api/15018.md b/changelog_unreleased/api/15018.md new file mode 100644 index 000000000000..d3aefb56a202 --- /dev/null +++ b/changelog_unreleased/api/15018.md @@ -0,0 +1,3 @@ +#### Fix plugins/estree.d.ts to make it a module (#15018 by @kingyue737) + +Add `export {}` in `plugins/estree.d.ts` to fix the "File is not a module" error diff --git a/scripts/build/build-types.js b/scripts/build/build-types.js index 546c9233e27a..71e09f4aa13d 100644 --- a/scripts/build/build-types.js +++ b/scripts/build/build-types.js @@ -38,10 +38,10 @@ async function buildPluginTypes({ file: { input, output } }) { const parserNames = Object.keys(plugin.parsers ?? {}); // We only add `parsers` to types file, printers should not be used alone - // For `estree` plugin, we just write an empty file + // For `estree` plugin, we just export an empty object to ensure it treated as a module const code = parserNames.length === 0 - ? "" + ? "export {};" : outdent` import { Parser } from "../index.js"; @@ -52,10 +52,10 @@ async function buildPluginTypes({ file: { input, output } }) { `${" ".repeat(2)}${toPropertyKey(parserName)}: Parser;`, ) .join("\n")} - };\n + }; `; - await writeFile(path.join(DIST_DIR, output.file), code); + await writeFile(path.join(DIST_DIR, output.file), `${code}\n`); } function buildTypes(options) {