pull/14315/head
Rich Harris 2 years ago
parent 4fcc7d1ac2
commit c84aea7be5

@ -26,30 +26,18 @@ export function ExportSpecifier(node, context) {
if (binding) binding.reassigned = binding.updated = true;
}
} else {
const undefined_exports = context.state.analysis.undefined_exports;
validate_export(node, context.state.scope, local_name, undefined_exports);
}
}
/**
*
* @param {Node} node
* @param {Scope} scope
* @param {string} name
* @param {Map<string, any>} undefined_exports
*/
function validate_export(node, scope, name, undefined_exports) {
const binding = scope.get(name);
if (!binding) {
undefined_exports.set(name, node);
return;
}
const binding = context.state.scope.get(local_name);
if (binding.kind === 'derived') {
e.derived_invalid_export(node);
}
if (binding) {
if (binding.kind === 'derived') {
e.derived_invalid_export(node);
}
if ((binding.kind === 'state' || binding.kind === 'raw_state') && binding.reassigned) {
e.state_invalid_export(node);
if ((binding.kind === 'state' || binding.kind === 'raw_state') && binding.reassigned) {
e.state_invalid_export(node);
}
} else {
context.state.analysis.undefined_exports.set(local_name, node);
}
}
}

@ -28,16 +28,16 @@ export function SnippetBlock(node, context) {
context.path[0].type === 'Fragment' &&
can_hoist_snippet(context.state.scope, context.state.scopes);
const undefined_exports = context.state.analysis.undefined_exports;
const name = node.expression.name;
if (can_hoist) {
const binding = /** @type {Binding} */ (context.state.scope.get(name));
context.state.analysis.module.scope.declarations.set(name, binding);
}
if (!can_hoist && undefined_exports.has(name)) {
e.snippet_invalid_export(/** @type {any} */ (undefined_exports.get(name)));
} else {
const undefined_export = context.state.analysis.undefined_exports.get(name);
if (undefined_export) {
e.snippet_invalid_export(undefined_export);
}
}
node.metadata.can_hoist = can_hoist;

@ -1,5 +1,5 @@
import type { AST, Binding, Css, SvelteNode } from '#compiler';
import type { Identifier, LabeledStatement, Program, VariableDeclaration } from 'estree';
import type { Identifier, LabeledStatement, Node, Program } from 'estree';
import type { Scope, ScopeRoot } from './scope.js';
export interface Js {

Loading…
Cancel
Save