pull/15820/head
S. Elliott Johnson 1 year ago
parent fb8d6d7975
commit 033a466e84

@ -22,5 +22,8 @@ export function ClassDeclaration(node, context) {
w.perf_avoid_nested_class(node);
}
context.next({ ...context.state, class_state: new ClassAnalysis() });
context.next({
...context.state,
class_state: context.state.analysis.runes ? new ClassAnalysis() : null
});
}

@ -6,6 +6,7 @@ import { get_parent } from '../../../../utils/ast.js';
import { get_rune } from '../../../scope.js';
import * as e from '../../../../errors.js';
import { locate_node } from '../../../../state.js';
import { is_state_creation_rune } from '../../../../../utils.js';
/** @typedef {'$state' | '$state.raw' | '$derived' | '$derived.by' | 'regular'} PropertyAssignmentType */
/** @typedef {{ type: PropertyAssignmentType; node: AssignmentExpression | PropertyDefinition; }} PropertyAssignmentDetails */
@ -67,7 +68,7 @@ export class ClassAnalysis {
* @template {AST.SvelteNode} T
* @param {AST.SvelteNode} node
* @param {T[]} path
* @returns {node is AssignmentExpression & { left: { type: 'MemberExpression' } & { object: { type: 'ThisExpression' }; property: { type: 'Identifier' } } }}
* @returns {node is AssignmentExpression & { left: { type: 'MemberExpression' } & { object: { type: 'ThisExpression' }; property: { type: 'Identifier' | 'PrivateIdentifier' } } }}
*/
is_class_property_assignment_at_constructor_root(node, path) {
if (
@ -76,7 +77,8 @@ export class ClassAnalysis {
node.operator === '=' &&
node.left.type === 'MemberExpression' &&
node.left.object.type === 'ThisExpression' &&
node.left.property.type === 'Identifier'
(node.left.property.type === 'Identifier' ||
node.left.property.type === 'PrivateIdentifier')
)
) {
return false;
@ -137,8 +139,8 @@ export class ClassAnalysis {
if (rune === null) {
return 'regular';
}
if (property_assignment_types.has(rune)) {
return /** @type {PropertyAssignmentType} */ (rune);
if (is_state_creation_rune(rune)) {
return rune;
}
// this does mean we return `regular` for some other runes (like `$trace` or `$state.raw`)
// -- this is ok because the rune placement rules will throw if they're invalid.

@ -447,14 +447,28 @@ const RUNES = /** @type {const} */ ([
'$host'
]);
/** @typedef {RUNES[number]} RuneName */
/**
* @param {string} name
* @returns {name is RUNES[number]}
* @returns {name is RuneName}
*/
export function is_rune(name) {
return RUNES.includes(/** @type {RUNES[number]} */ (name));
}
/** @typedef {'$state' | '$state.raw' | '$derived' | '$derived.by'} StateCreationRuneName */
/**
* @param {string} name
* @returns {name is StateCreationRuneName}
*/
export function is_state_creation_rune(name) {
return (
name === '$state' || name === '$state.raw' || name === '$derived' || name === '$derived.by'
);
}
/** List of elements that require raw contents and should not have SSR comments put in them */
const RAW_TEXT_ELEMENTS = /** @type {const} */ (['textarea', 'script', 'style', 'title']);

Loading…
Cancel
Save