Hi, I'm trying to figure out how to insert an import statement after a comment block at the top of a file. The sample input is:
/**
* This is a code block I want to add an import statement after
*/
// something else
const thar = 'that';
and I'd like to insert:
import {SomeClass} from 'my-module';
after the first block to produce:
/**
* This is a code block I want to add an import statement after
*/
import {SomeClass} from 'my-module';
// something else
const thar = 'that';
I wrote a visitor look for comments and append my import declaration, but it seems like when I run that code it doesn't change the output at all. Here's the transformer I came up with:
what's more curious is that if I reduce the input script to just the top comment block, then running this transformer actually removes all the code in the input.
Hi, I'm trying to figure out how to insert an
import
statement after a comment block at the top of a file. The sample input is:and I'd like to insert:
after the first block to produce:
I wrote a visitor look for comments and append my import declaration, but it seems like when I run that code it doesn't change the output at all. Here's the transformer I came up with:
(view in astexplorer)
what's more curious is that if I reduce the input script to just the top comment block, then running this transformer actually removes all the code in the input.