mirror of https://github.com/sveltejs/svelte
parent
4f757ef271
commit
02194d68f4
@ -0,0 +1,31 @@
|
|||||||
|
/** @import { Declaration, Statement, StaticBlock, VariableDeclaration } from 'estree' */
|
||||||
|
/** @import { ComponentContext } from '../types' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StaticBlock} node
|
||||||
|
* @param {ComponentContext} context
|
||||||
|
*/
|
||||||
|
export function StaticBlock(node, context) {
|
||||||
|
/** @type {StaticBlock['body']} */
|
||||||
|
const body = [];
|
||||||
|
for (const child of node.body) {
|
||||||
|
const visited = /** @type {Declaration | Statement} */ (context.visit(child));
|
||||||
|
if (
|
||||||
|
visited.type === 'ClassDeclaration' &&
|
||||||
|
'metadata' in visited &&
|
||||||
|
visited.metadata !== null &&
|
||||||
|
typeof visited.metadata === 'object' &&
|
||||||
|
'computed_field_declarations' in visited.metadata
|
||||||
|
) {
|
||||||
|
body.push(
|
||||||
|
.../** @type {VariableDeclaration[]} */ (visited.metadata.computed_field_declarations)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
body.push(visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
body
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/** @import { BlockStatement, Declaration, Statement, VariableDeclaration } from 'estree' */
|
||||||
|
/** @import { Context } from '../types' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {BlockStatement} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function BlockStatement(node, context) {
|
||||||
|
/** @type {BlockStatement['body']} */
|
||||||
|
const body = [];
|
||||||
|
for (const child of node.body) {
|
||||||
|
const visited = /** @type {Declaration | Statement} */ (context.visit(child));
|
||||||
|
if (
|
||||||
|
visited.type === 'ClassDeclaration' &&
|
||||||
|
'metadata' in visited &&
|
||||||
|
visited.metadata !== null &&
|
||||||
|
typeof visited.metadata === 'object' &&
|
||||||
|
'computed_field_declarations' in visited.metadata
|
||||||
|
) {
|
||||||
|
body.push(
|
||||||
|
.../** @type {VariableDeclaration[]} */ (visited.metadata.computed_field_declarations)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
body.push(visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
body
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/** @import { Declaration, Program, Statement, VariableDeclaration } from 'estree' */
|
||||||
|
/** @import { Context } from '../types.js' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Program} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function Program(node, context) {
|
||||||
|
/** @type {Program['body']} */
|
||||||
|
const body = [];
|
||||||
|
for (const child of node.body) {
|
||||||
|
const visited = /** @type {Declaration | Statement} */ (context.visit(child));
|
||||||
|
if (
|
||||||
|
visited.type === 'ClassDeclaration' &&
|
||||||
|
'metadata' in visited &&
|
||||||
|
visited.metadata !== null &&
|
||||||
|
typeof visited.metadata === 'object' &&
|
||||||
|
'computed_field_declarations' in visited.metadata
|
||||||
|
) {
|
||||||
|
body.push(
|
||||||
|
.../** @type {VariableDeclaration[]} */ (visited.metadata.computed_field_declarations)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
body.push(visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
body
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/** @import { Declaration, Statement, StaticBlock, VariableDeclaration } from 'estree' */
|
||||||
|
/** @import { Context } from '../types' */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StaticBlock} node
|
||||||
|
* @param {Context} context
|
||||||
|
*/
|
||||||
|
export function StaticBlock(node, context) {
|
||||||
|
/** @type {StaticBlock['body']} */
|
||||||
|
const body = [];
|
||||||
|
for (const child of node.body) {
|
||||||
|
const visited = /** @type {Declaration | Statement} */ (context.visit(child));
|
||||||
|
if (
|
||||||
|
visited.type === 'ClassDeclaration' &&
|
||||||
|
'metadata' in visited &&
|
||||||
|
visited.metadata !== null &&
|
||||||
|
typeof visited.metadata === 'object' &&
|
||||||
|
'computed_field_declarations' in visited.metadata
|
||||||
|
) {
|
||||||
|
body.push(
|
||||||
|
.../** @type {VariableDeclaration[]} */ (visited.metadata.computed_field_declarations)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
body.push(visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
body
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in new issue