Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module exports should not be recognized as accessors #70

Merged
merged 13 commits into from
Feb 13, 2022

Conversation

metonym
Copy link
Collaborator

@metonym metonym commented Feb 13, 2022

Fixes #56

Currently, module exports are being falsely recognized as component accessors.

<script context="module">
  /**
   * Log something (export)
   * @type {(message: string) => void}
   */
  export function log(message) {
    console.log(message);
  }
</script>

<script>
  /**
   * Log something (accessor)
   * @type {(message: string) => void}
   */
  export function log(message) {
    console.log(message);
  }
</script>

Unexpected output

/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";

export interface InputProps {}

export default class Input extends SvelteComponentTyped<InputProps, {}, {}> {
  /**
   * Log something (export)
   */
  log: (message: string) => void;
}

Expected output

The expected behavior is that module exports should be treated as named exports.

/// <reference types="svelte" />
import { SvelteComponentTyped } from "svelte";

/**
 * Log something (export)
 */
export type log = (message: string) => void;

export interface InputProps {}

export default class Input extends SvelteComponentTyped<InputProps, {}, {}> {
  /**
   * Log something (accessor)
   */
  log: (message: string) => void;
}

The corresponding index.d.ts will also export any named exports:

export { default as Component, log } from "./Component.svelte";

Approach

  • still compile Svelte source to obtain reactive_vars
  • parse Svelte source to obtain instance, module, and html
  • walk instance and module separately

@metonym metonym merged commit ae85e72 into main Feb 13, 2022
@metonym metonym deleted the parse-instance branch February 13, 2022 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type annotations for module="context" scripts exports
1 participant