store analysis for use during transformation

pull/15820/head
Rich Harris 4 months ago
parent f81405cb87
commit 41e8ade562

@ -267,7 +267,8 @@ export function analyze_module(ast, options) {
scope,
scopes,
analysis: /** @type {ComponentAnalysis} */ (analysis),
class_state: null,
classes: new Map(),
class: null,
// TODO the following are not needed for modules, but we have to pass them in order to avoid type error,
// and reducing the type would result in a lot of tedious type casts elsewhere - find a good solution one day
ast_type: /** @type {any} */ (null),
@ -626,7 +627,8 @@ export function analyze_component(root, source, options) {
has_props_rune: false,
component_slots: new Set(),
expression: null,
class_state: null,
classes: new Map(),
class: null,
function_depth: scope.function_depth,
reactive_statement: null
};
@ -693,7 +695,8 @@ export function analyze_component(root, source, options) {
reactive_statement: null,
component_slots: new Set(),
expression: null,
class_state: null,
classes: new Map(),
class: null,
function_depth: scope.function_depth
};

@ -2,6 +2,7 @@ import type { Scope } from '../scope.js';
import type { ComponentAnalysis, ReactiveStatement } from '../types.js';
import type { AST, ExpressionMetadata, ValidatedCompileOptions } from '#compiler';
import type { ClassAnalysis } from './visitors/shared/class-analysis.js';
import type { ClassBody } from 'estree';
export interface AnalysisState {
scope: Scope;
@ -21,7 +22,9 @@ export interface AnalysisState {
expression: ExpressionMetadata | null;
/** Used to analyze class state. */
class_state: ClassAnalysis | null;
classes: Map<ClassBody, ClassAnalysis>;
class: ClassAnalysis | null;
function_depth: number;
// legacy stuff

@ -23,6 +23,6 @@ export function AssignmentExpression(node, context) {
}
}
context.state.class_state?.register?.(node, context);
context.state.class?.register?.(node, context);
context.next();
}

@ -118,7 +118,7 @@ export function CallExpression(node, context) {
const valid =
is_variable_declaration(parent, context) ||
is_class_property_definition(parent) ||
context.state.class_state?.is_class_property_assignment_at_constructor_root(
context.state.class?.is_class_property_assignment_at_constructor_root(
parent,
context.path.slice(0, -1)
);

@ -9,6 +9,6 @@ import { ClassAnalysis } from './shared/class-analysis.js';
export function ClassBody(node, context) {
context.next({
...context.state,
class_state: context.state.analysis.runes ? new ClassAnalysis() : null
class: context.state.analysis.runes ? new ClassAnalysis() : null
});
}

@ -7,6 +7,6 @@
* @param {Context} context
*/
export function PropertyDefinition(node, context) {
context.state.class_state?.register(node, context);
context.state.class?.register(node, context);
context.next();
}

@ -140,7 +140,7 @@ export class ClassAnalysis {
return;
}
e.constructor_state_reassignment(node, name, locate_node(existing.node));
e.constructor_state_reassignment(node);
}
/**

Loading…
Cancel
Save