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

Perform update in content rather than returning AST #33

Closed
benmccann opened this issue Sep 26, 2024 · 0 comments · Fixed by #75
Closed

Perform update in content rather than returning AST #33

benmccann opened this issue Sep 26, 2024 · 0 comments · Fixed by #75

Comments

@benmccann
Copy link
Member

Something along the lines of:

{
  name: () => 'foo.svelte',
  content: ({ source })) => {
    const { script, css, template, generateCode } = parseSvelte(source);
        
    // do manipulations
    const ms = new MagicString(script.code);
    ms.overwrite(...);
    
    // or ast manipulation
    doStuff(script.ast);
    
    // performs a text replacement of `script`
    return generateCode({ script: ms.toString() });
    // or
    return generateCode({ script: script.generateCode() }); 
  }
},

This would allow us to touch only updated lines of code. There are currently 37 files written so is still pretty manageable.

This one would be important to figure out before release because we should make any breaking API changes before we start having community editors

We'd have to figure out the exact API. E.g. maybe it shouldn't be called generateCode but rather something like writeFile so that it can operate on files that might not be considered code. And the arg could be content rather than script for that reason

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 a pull request may close this issue.

1 participant