goodbye-acorn
Nic 19 hours ago
parent 03ee8b51bf
commit 0bc2e55cae

@ -2,9 +2,8 @@
/** @import { AST } from '#compiler' */
/** @import { Parser } from '../index.js' */
import * as e from '../../../errors.js';
import { ExpressionMetadata } from '../../nodes.js';
import { create_fragment, ExpressionMetadata } from '../../nodes.js';
import { read_expression, read_params, read_pattern, read_statement } from '../js.js';
import { create_fragment } from '../../nodes.js';
import { find_matching_bracket, match_bracket } from '../utils/bracket.js';
const regex_whitespace_with_closing_curly_brace = /\s*}/y;

@ -961,7 +961,8 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
for (const binding of parsed.bindings) {
if ((binding.kind === 'param') !== params) continue;
// no node: `arguments`, or a declaration erased with the TypeScript it belonged to
if (binding.node === null || binding.kind === 'class-name' || binding.kind === 'pattern') continue;
if (binding.node === null || binding.kind === 'class-name' || binding.kind === 'pattern')
continue;
/** @type {DeclarationKind} */
let kind = 'let';
switch (binding.kind) {
@ -1078,10 +1079,13 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
const parsed = scopeOf(/** @type {any} */ (node));
const parent = context.path.at(-1);
if (parsed === undefined) {
const of_function = node.type === 'BlockStatement' && parent && scopeOf(/** @type {any} */ (parent));
const of_function =
node.type === 'BlockStatement' && parent && scopeOf(/** @type {any} */ (parent));
if (
of_function &&
(parent.type === 'FunctionDeclaration' || parent.type === 'FunctionExpression' || parent.type === 'ArrowFunctionExpression')
(parent.type === 'FunctionDeclaration' ||
parent.type === 'FunctionExpression' ||
parent.type === 'ArrowFunctionExpression')
) {
// the body holds the non-porous function scope; the parameters live one above
const scope = context.state.scope.child();
@ -1097,7 +1101,8 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
scopes.set(node, scope);
declare_parsed(scope, parsed, true, /** @type {any} */ (node));
if (node.type === 'FunctionExpression' && node.id) declare_parsed(scope, parsed, false);
else if (node.type === 'ArrowFunctionExpression' && node.body.type !== 'BlockStatement') declare_parsed(scope, parsed, false);
else if (node.type === 'ArrowFunctionExpression' && node.body.type !== 'BlockStatement')
declare_parsed(scope, parsed, false);
return context.next({ scope });
}
case 'block':
@ -1211,7 +1216,9 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
ImportDeclaration(node, { state }) {
for (const specifier of node.specifiers) {
const binding = declared(specifier.local) ?? state.scope.declare(specifier.local, 'normal', 'import', node);
const binding =
declared(specifier.local) ??
state.scope.declare(specifier.local, 'normal', 'import', node);
binding.initial = node;
}
},

Loading…
Cancel
Save