make analysis available at transform time

pull/15820/head
Rich Harris 4 months ago
parent b1e095af52
commit c407dc09de

@ -256,7 +256,8 @@ export function analyze_module(ast, options) {
accessors: false,
runes: true,
immutable: true,
tracing: false
tracing: false,
classes: new Map()
};
walk(
@ -265,7 +266,6 @@ export function analyze_module(ast, options) {
scope,
scopes,
analysis: /** @type {ComponentAnalysis} */ (analysis),
classes: new Map(),
state_fields: 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
@ -430,6 +430,7 @@ export function analyze_component(root, source, options) {
elements: [],
runes,
tracing: false,
classes: new Map(),
immutable: runes || options.immutable,
exports: [],
uses_props: false,
@ -625,7 +626,6 @@ export function analyze_component(root, source, options) {
has_props_rune: false,
component_slots: new Set(),
expression: null,
classes: new Map(),
state_fields: null,
function_depth: scope.function_depth,
reactive_statement: null
@ -693,7 +693,6 @@ export function analyze_component(root, source, options) {
reactive_statement: null,
component_slots: new Set(),
expression: null,
classes: new Map(),
state_fields: null,
function_depth: scope.function_depth
};

@ -21,7 +21,6 @@ export interface AnalysisState {
expression: ExpressionMetadata | null;
/** Used to analyze class state. */
classes: Map<ClassBody, Record<string, StateField>>;
state_fields: Record<string, StateField> | null;
function_depth: number;

@ -18,6 +18,8 @@ export function ClassBody(node, context) {
/** @type {Record<string, StateField>} */
const state_fields = {};
context.state.analysis.classes.set(node, state_fields);
/** @type {string[]} */
const seen = [];

@ -1,7 +1,15 @@
import type { AST, Binding } from '#compiler';
import type { AssignmentExpression, Identifier, LabeledStatement, Node, Program } from 'estree';
import type { AST, Binding, StateField } from '#compiler';
import type {
AssignmentExpression,
ClassBody,
Identifier,
LabeledStatement,
Node,
Program
} from 'estree';
import type { Scope, ScopeRoot } from './scope.js';
import type { StateCreationRuneName } from '../../utils.js';
import type { AnalysisState } from './2-analyze/types.js';
export interface Js {
ast: Program;
@ -30,6 +38,8 @@ export interface Analysis {
immutable: boolean;
tracing: boolean;
classes: Map<ClassBody, Record<string, StateField>>;
// TODO figure out if we can move this to ComponentAnalysis
accessors: boolean;
}

Loading…
Cancel
Save