Skip to content

Feature: @transpile block#38

Open
nicholaides wants to merge 2 commits intoDanielXMoore:mainfrom
nicholaides:transpile-block
Open

Feature: @transpile block#38
nicholaides wants to merge 2 commits intoDanielXMoore:mainfrom
nicholaides:transpile-block

Conversation

@nicholaides
Copy link

@nicholaides nicholaides commented Mar 29, 2025

Works like this:

@transpile
  const { compile } = require('@danielx/civet')

  // return a function that will be used to transpile handler functions
  return (code, filename) => compile(
    // puts the handler code inside a `return do ...` block then compiles it
    `return do\\n${code.replace(/^/gm, '  ')}`,
    { sync: true, filename }
  )

Rule
  /.+/ ->
    // use your pre-transpiled language
    $0 |> .toUpperCase()

Currently does not support async. In Node.js that will be ok because require is sync. Civet and esbuild both have sync versions of compile/transform.

TODO:

  • support transpilation "target" so that it can compile to JS or TS depending on the context
  • apply the transpile to code blocks (code in triple backticks)

Questions

  • What are the security concerns around having the LSP execute arbitrary code when a .hera file is opened?
  • The @transpile block can only be synchronous right now. Does that work for the scenarios this needs to support?

@nicholaides
Copy link
Author

This fails the should parse decompiled rules round-tripping test. Not sure how to address this.

@edemaine
Copy link
Collaborator

Wow! I'm excited to use Civet in Civet's Hera rules!

I know I suggested this API, but maybe we should turn the second argument into an object with filename property so that we can add other properties too? E.g. we talked about js vs ts.

@nicholaides
Copy link
Author

maybe we should turn the second argument into an object with filename property so that we can add other properties too? E.g. we talked about js vs ts.

I was thinking the same thing.

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.

2 participants