diff --git a/lib/rules/no-export-in-script-setup.js b/lib/rules/no-export-in-script-setup.js index 66286375a..98d41ae38 100644 --- a/lib/rules/no-export-in-script-setup.js +++ b/lib/rules/no-export-in-script-setup.js @@ -28,8 +28,11 @@ module.exports = { }, /** @param {RuleContext} context */ create(context) { - /** @param {ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration} node */ - function verify(node) { + /** + * @param {ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration} node + * @param {SourceLocation} loc + */ + function verify(node, loc) { const tsNode = /** @type {TSESTreeExportAllDeclaration | TSESTreeExportDefaultDeclaration | TSESTreeExportNamedDeclaration} */ ( node @@ -46,14 +49,24 @@ module.exports = { } context.report({ node, + loc, messageId: 'forbidden' }) } return utils.defineScriptSetupVisitor(context, { - ExportAllDeclaration: verify, - ExportDefaultDeclaration: verify, - ExportNamedDeclaration: verify + ExportAllDeclaration: (node) => verify(node, node.loc), + ExportDefaultDeclaration: (node) => verify(node, node.loc), + ExportNamedDeclaration: (node) => { + // export let foo = 'foo', export class Foo {}, export function foo() {} + if (node.declaration) { + verify(node, context.getSourceCode().getFirstToken(node).loc) + } + // export { foo }, export { foo } from 'bar' + else { + verify(node, node.loc) + } + } }) } } diff --git a/tests/lib/rules/no-export-in-script-setup.js b/tests/lib/rules/no-export-in-script-setup.js index 8703dc74a..bf24b8682 100644 --- a/tests/lib/rules/no-export-in-script-setup.js +++ b/tests/lib/rules/no-export-in-script-setup.js @@ -92,20 +92,62 @@ ruleTester.run('no-export-in-script-setup', rule, { export * from 'foo' export default {} export class A {} + export const test = '123' + export function foo() {} + const a = 1 + export { a } + export { fao } from 'bar' `, errors: [ { message: '`