wildly confusing to have so many things called 'class analysis' - rename the transform-phrase ones to transformers

pull/15820/head
Rich Harris 4 months ago
parent 0ac22c19b2
commit 4edebbcfb1

@ -12,10 +12,10 @@ import type { AST, Namespace, ValidatedCompileOptions } from '#compiler';
import type { TransformState } from '../types.js';
import type { ComponentAnalysis } from '../../types.js';
import type { SourceLocation } from '#shared';
import type { ClassAnalysis } from '../shared/types.js';
import type { ClassTransformer } from '../shared/types.js';
export interface ClientTransformState extends TransformState {
readonly class_analysis: ClassAnalysis<Context> | null;
readonly class_analysis: ClassTransformer<Context> | null;
/**
* `true` if the current lexical scope belongs to a class constructor. this allows

@ -1,6 +1,6 @@
/** @import { ClassBody } from 'estree' */
/** @import { Context } from '../types' */
import { create_client_class_analysis } from './shared/client-class-analysis.js';
import { create_client_class_transformer } from './shared/client-class-transformer.js';
/**
* @param {ClassBody} node
@ -12,8 +12,8 @@ export function ClassBody(node, context) {
return;
}
const class_analysis = create_client_class_analysis(node.body);
const body = class_analysis.generate_body(context);
const class_transformer = create_client_class_transformer(node.body);
const body = class_transformer.generate_body(context);
return { ...node, body };
}

@ -1,16 +1,16 @@
/** @import { Context } from '../../types.js' */
/** @import { MethodDefinition, PropertyDefinition, Expression, StaticBlock, SpreadElement } from 'estree' */
/** @import { StateCreationRuneName } from '../../../../../../utils.js' */
/** @import { AssignmentBuilder, ClassAnalysis, StateFieldBuilder } from '../../../shared/types.js' */
/** @import { AssignmentBuilder, ClassTransformer, StateFieldBuilder } from '../../../shared/types.js' */
import * as b from '#compiler/builders';
import { create_class_analysis } from '../../../shared/class_analysis.js';
import { create_class_transformer } from '../../../shared/class_transformer.js';
import { should_proxy } from '../../utils.js';
/**
* @param {Array<MethodDefinition | PropertyDefinition | StaticBlock>} body
* @returns {ClassAnalysis<Context>}
* @returns {ClassTransformer<Context>}
*/
export function create_client_class_analysis(body) {
export function create_client_class_transformer(body) {
/** @type {StateFieldBuilder<Context>} */
function build_state_field({ is_private, field, node, context }) {
let original_id = node.type === 'AssignmentExpression' ? node.left.property : node.key;
@ -66,7 +66,7 @@ export function create_client_class_analysis(body) {
};
}
return create_class_analysis(body, build_state_field, build_assignment);
return create_class_transformer(body, build_state_field, build_assignment);
}
/**

@ -2,12 +2,12 @@ import type { Expression, Statement, ModuleDeclaration, LabeledStatement } from
import type { AST, Namespace, ValidatedCompileOptions } from '#compiler';
import type { TransformState } from '../types.js';
import type { ComponentAnalysis } from '../../types.js';
import type { ClassAnalysis } from '../shared/types.js';
import type { ClassTransformer } from '../shared/types.js';
export interface ServerTransformState extends TransformState {
/** The $: calls, which will be ordered in the end */
readonly legacy_reactive_statements: Map<LabeledStatement, Statement>;
readonly class_analysis: ClassAnalysis<Context> | null;
readonly class_analysis: ClassTransformer<Context> | null;
}
export interface ComponentServerTransformState extends ServerTransformState {

@ -1,6 +1,6 @@
/** @import { ClassBody } from 'estree' */
/** @import { Context } from '../types.js' */
import { create_server_class_analysis } from './shared/server-class-analysis.js';
import { create_server_class_transformer } from './shared/server-class-transformer.js';
/**
* @param {ClassBody} node
@ -12,8 +12,8 @@ export function ClassBody(node, context) {
return;
}
const class_analysis = create_server_class_analysis(node.body);
const body = class_analysis.generate_body(context);
const class_transformer = create_server_class_transformer(node.body);
const body = class_transformer.generate_body(context);
return { ...node, body };
}

@ -1,18 +1,18 @@
/** @import { Expression, MethodDefinition, StaticBlock, PropertyDefinition, SpreadElement } from 'estree' */
/** @import { Context } from '../../types.js' */
/** @import { AssignmentBuilder, StateFieldBuilder } from '../../../shared/types.js' */
/** @import { ClassAnalysis } from '../../../shared/types.js' */
/** @import { ClassTransformer } from '../../../shared/types.js' */
/** @import { StateCreationRuneName } from '../../../../../../utils.js' */
import * as b from '#compiler/builders';
import { dev } from '../../../../../state.js';
import { create_class_analysis } from '../../../shared/class_analysis.js';
import { create_class_transformer } from '../../../shared/class_transformer.js';
/**
* @param {Array<MethodDefinition | PropertyDefinition | StaticBlock>} body
* @returns {ClassAnalysis<Context>}
* @returns {ClassTransformer<Context>}
*/
export function create_server_class_analysis(body) {
export function create_server_class_transformer(body) {
/** @type {StateFieldBuilder<Context>} */
function build_state_field({ is_private, field, node, context }) {
let original_id = node.type === 'AssignmentExpression' ? node.left.property : node.key;
@ -79,7 +79,7 @@ export function create_server_class_analysis(body) {
};
}
return create_class_analysis(body, build_state_field, build_assignment);
return create_class_transformer(body, build_state_field, build_assignment);
}
/**

@ -3,7 +3,7 @@
/** @import { Context as ClientContext } from '../client/types.js' */
/** @import { Context as ServerContext } from '../server/types.js' */
/** @import { StateCreationRuneName } from '../../../../utils.js' */
/** @import { AssignmentBuilder, ClassAnalysis, StateFieldBuilder, StatefulAssignment, StatefulPropertyDefinition } from './types.js' */
/** @import { AssignmentBuilder, ClassTransformer, StateFieldBuilder, StatefulAssignment, StatefulPropertyDefinition } from './types.js' */
/** @import { Scope } from '../../scope.js' */
import * as b from '#compiler/builders';
import { once } from '../../../../internal/server/index.js';
@ -16,9 +16,9 @@ import { get_rune } from '../../scope.js';
* @param {Array<PropertyDefinition | MethodDefinition | StaticBlock>} body
* @param {StateFieldBuilder<TContext>} build_state_field
* @param {AssignmentBuilder<TContext>} build_assignment
* @returns {ClassAnalysis<TContext>}
* @returns {ClassTransformer<TContext>}
*/
export function create_class_analysis(body, build_state_field, build_assignment) {
export function create_class_transformer(body, build_state_field, build_assignment) {
/**
* Public, stateful fields.
* @type {Map<string, StateField>}

@ -48,7 +48,7 @@ export type AssignmentBuilder<TContext extends ServerContext | ClientContext> =
params: AssignmentBuilderParams<TContext>
) => AssignmentExpression;
export type ClassAnalysis<TContext extends ServerContext | ClientContext> = {
export type ClassTransformer<TContext extends ServerContext | ClientContext> = {
/**
* @param name - The name of the field.
* @param is_private - Whether the field is private (whether its name starts with '#').

Loading…
Cancel
Save