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, accessors: false,
runes: true, runes: true,
immutable: true, immutable: true,
tracing: false tracing: false,
classes: new Map()
}; };
walk( walk(
@ -265,7 +266,6 @@ export function analyze_module(ast, options) {
scope, scope,
scopes, scopes,
analysis: /** @type {ComponentAnalysis} */ (analysis), analysis: /** @type {ComponentAnalysis} */ (analysis),
classes: new Map(),
state_fields: null, state_fields: null,
// TODO the following are not needed for modules, but we have to pass them in order to avoid type error, // 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 // 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: [], elements: [],
runes, runes,
tracing: false, tracing: false,
classes: new Map(),
immutable: runes || options.immutable, immutable: runes || options.immutable,
exports: [], exports: [],
uses_props: false, uses_props: false,
@ -625,7 +626,6 @@ export function analyze_component(root, source, options) {
has_props_rune: false, has_props_rune: false,
component_slots: new Set(), component_slots: new Set(),
expression: null, expression: null,
classes: new Map(),
state_fields: null, state_fields: null,
function_depth: scope.function_depth, function_depth: scope.function_depth,
reactive_statement: null reactive_statement: null
@ -693,7 +693,6 @@ export function analyze_component(root, source, options) {
reactive_statement: null, reactive_statement: null,
component_slots: new Set(), component_slots: new Set(),
expression: null, expression: null,
classes: new Map(),
state_fields: null, state_fields: null,
function_depth: scope.function_depth function_depth: scope.function_depth
}; };

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

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

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

Loading…
Cancel
Save