pull/17038/head
Rich Harris 4 weeks ago
parent 3ad47c324d
commit c856ea2032

@ -687,17 +687,6 @@ export function analyze_component(root, source, options) {
} }
} }
if (analysis.runes) {
const props_refs = module.scope.references.get('$$props');
if (props_refs) {
e.legacy_props_invalid(props_refs[0].node);
}
const rest_props_refs = module.scope.references.get('$$restProps');
if (rest_props_refs) {
e.legacy_rest_props_invalid(rest_props_refs[0].node);
}
/** /**
* @param {ESTree.Node} expression * @param {ESTree.Node} expression
* @param {Scope} scope * @param {Scope} scope
@ -886,6 +875,17 @@ export function analyze_component(root, source, options) {
} }
} }
if (analysis.runes) {
const props_refs = module.scope.references.get('$$props');
if (props_refs) {
e.legacy_props_invalid(props_refs[0].node);
}
const rest_props_refs = module.scope.references.get('$$restProps');
if (rest_props_refs) {
e.legacy_rest_props_invalid(rest_props_refs[0].node);
}
for (const { ast, scope, scopes } of [module, instance, template]) { for (const { ast, scope, scopes } of [module, instance, template]) {
/** @type {AnalysisState} */ /** @type {AnalysisState} */
const state = { const state = {

@ -33,7 +33,6 @@ import { FunctionExpression } from './visitors/FunctionExpression.js';
import { HtmlTag } from './visitors/HtmlTag.js'; import { HtmlTag } from './visitors/HtmlTag.js';
import { Identifier } from './visitors/Identifier.js'; import { Identifier } from './visitors/Identifier.js';
import { IfBlock } from './visitors/IfBlock.js'; import { IfBlock } from './visitors/IfBlock.js';
import { ImportDeclaration } from './visitors/ImportDeclaration.js';
import { KeyBlock } from './visitors/KeyBlock.js'; import { KeyBlock } from './visitors/KeyBlock.js';
import { LabeledStatement } from './visitors/LabeledStatement.js'; import { LabeledStatement } from './visitors/LabeledStatement.js';
import { LetDirective } from './visitors/LetDirective.js'; import { LetDirective } from './visitors/LetDirective.js';
@ -111,7 +110,6 @@ const visitors = {
HtmlTag, HtmlTag,
Identifier, Identifier,
IfBlock, IfBlock,
ImportDeclaration,
KeyBlock, KeyBlock,
LabeledStatement, LabeledStatement,
LetDirective, LetDirective,

@ -1,17 +0,0 @@
/** @import { ImportDeclaration } from 'estree' */
/** @import { ComponentContext } from '../types' */
import * as b from '#compiler/builders';
/**
* @param {ImportDeclaration} node
* @param {ComponentContext} context
*/
export function ImportDeclaration(node, context) {
if ('hoisted' in context.state) {
// TODO we can get rid of this visitor
context.state.hoisted.push(node);
return b.empty;
}
context.next();
}

@ -3,7 +3,6 @@
import { build_getter, is_prop_source } from '../utils.js'; import { build_getter, is_prop_source } from '../utils.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { add_state_transformers } from './shared/declarations.js'; import { add_state_transformers } from './shared/declarations.js';
import { runes } from '../../../../state.js';
import { transform_body } from '../../shared/transform-async.js'; import { transform_body } from '../../shared/transform-async.js';
/** /**
@ -139,15 +138,13 @@ export function Program(node, context) {
add_state_transformers(context); add_state_transformers(context);
if (context.state.is_instance && runes) { if (context.state.is_instance) {
return { return {
...node, ...node,
body: transform_body( body: transform_body(
node,
context.state.analysis.instance_body, context.state.analysis.instance_body,
b.id('$.run'), b.id('$.run'),
(node) => /** @type {Node} */ (context.visit(node)), (node) => /** @type {Node} */ (context.visit(node))
(statement) => context.state.hoisted.push(statement)
) )
}; };
} }

@ -1,7 +1,6 @@
/** @import { Node, Program } from 'estree' */ /** @import { Node, Program } from 'estree' */
/** @import { Context, ComponentContext } from '../types' */ /** @import { Context, ComponentContext } from '../types' */
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { runes } from '../../../../state.js';
import { transform_body } from '../../shared/transform-async.js'; import { transform_body } from '../../shared/transform-async.js';
/** /**
@ -9,18 +8,16 @@ import { transform_body } from '../../shared/transform-async.js';
* @param {Context} context * @param {Context} context
*/ */
export function Program(node, context) { export function Program(node, context) {
if (context.state.is_instance && runes) { if (context.state.is_instance) {
// @ts-ignore wtf // @ts-ignore wtf
const c = /** @type {ComponentContext} */ (context); const c = /** @type {ComponentContext} */ (context);
return { return {
...node, ...node,
body: transform_body( body: transform_body(
node,
c.state.analysis.instance_body, c.state.analysis.instance_body,
b.id('$$renderer.run'), b.id('$$renderer.run'),
(node) => /** @type {Node} */ (context.visit(node)), (node) => /** @type {Node} */ (context.visit(node))
(statement) => c.state.hoisted.push(statement)
) )
}; };
} }

@ -2,15 +2,16 @@
/** @import { ComponentAnalysis } from '../../types' */ /** @import { ComponentAnalysis } from '../../types' */
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
// TODO find a way to DRY out this and the corresponding server visitor
/** /**
* @param {ESTree.Program} program
* @param {ComponentAnalysis['instance_body']} instance_body * @param {ComponentAnalysis['instance_body']} instance_body
* @param {ESTree.Expression} runner * @param {ESTree.Expression} runner
* @param {(node: ESTree.Node) => ESTree.Node} transform * @param {(node: ESTree.Node) => ESTree.Node} transform
* @returns {Array<ESTree.Statement | ESTree.VariableDeclaration>}
*/ */
export function transform_body(program, instance_body, runner, transform) { export function transform_body(instance_body, runner, transform) {
const statements = instance_body.sync.map(transform); const statements = instance_body.sync.map(
(node) => /** @type {ESTree.Statement | ESTree.VariableDeclaration} */ (transform(node))
);
if (instance_body.declarations.length > 0) { if (instance_body.declarations.length > 0) {
statements.push( statements.push(

Loading…
Cancel
Save