|
1 | 1 | /** @import { Context } from 'zimmerframe' */ |
2 | 2 | /** @import { TransformState } from './types.js' */ |
3 | 3 | /** @import { AST, Binding, Namespace, ValidatedCompileOptions } from '#compiler' */ |
4 | | -/** @import { Node, Expression, CallExpression } from 'estree' */ |
| 4 | +/** @import { Node, Expression, CallExpression, MemberExpression } from 'estree' */ |
5 | 5 | import { |
6 | 6 | regex_ends_with_whitespaces, |
7 | 7 | regex_not_whitespace, |
@@ -452,30 +452,19 @@ export function determine_namespace_for_children(node, namespace) { |
452 | 452 | } |
453 | 453 |
|
454 | 454 | /** |
455 | | - * @template {TransformState} T |
| 455 | + * @param {'$inspect' | '$inspect().with'} rune |
456 | 456 | * @param {CallExpression} node |
457 | | - * @param {Context<any, T>} context |
| 457 | + * @param {(node: AST.SvelteNode) => AST.SvelteNode} visit |
458 | 458 | */ |
459 | | -export function transform_inspect_rune(node, context) { |
460 | | - const { state, visit } = context; |
461 | | - const as_fn = state.options.generate === 'client'; |
462 | | - |
463 | | - if (!dev) return b.empty; |
464 | | - |
465 | | - if (node.callee.type === 'MemberExpression') { |
466 | | - const raw_inspect_args = /** @type {CallExpression} */ (node.callee.object).arguments; |
467 | | - const inspect_args = |
468 | | - /** @type {Array<Expression>} */ |
469 | | - (raw_inspect_args.map((arg) => visit(arg))); |
470 | | - const with_arg = /** @type {Expression} */ (visit(node.arguments[0])); |
471 | | - |
472 | | - return b.call( |
473 | | - '$.inspect', |
474 | | - as_fn ? b.thunk(b.array(inspect_args)) : b.array(inspect_args), |
475 | | - with_arg |
476 | | - ); |
477 | | - } else { |
478 | | - const arg = node.arguments.map((arg) => /** @type {Expression} */ (visit(arg))); |
479 | | - return b.call('$.inspect', as_fn ? b.thunk(b.array(arg)) : b.array(arg)); |
480 | | - } |
| 459 | +export function get_inspect_args(rune, node, visit) { |
| 460 | + const call = |
| 461 | + rune === '$inspect' |
| 462 | + ? node |
| 463 | + : /** @type {CallExpression} */ (/** @type {MemberExpression} */ (node.callee).object); |
| 464 | + |
| 465 | + return { |
| 466 | + args: call.arguments.map((arg) => /** @type {Expression} */ (visit(arg))), |
| 467 | + inspector: |
| 468 | + rune === '$inspect' ? 'console.log' : /** @type {Expression} */ (visit(node.arguments[0])) |
| 469 | + }; |
481 | 470 | } |
0 commit comments