scenery-io / stallion

Scripting bridge for Cavalry
https://marketplace.visualstudio.com/items?itemName=Scenery.cavalry-bridge
MIT License
8 stars 0 forks source link

Strip Triple-Slash Directives #4

Closed Klustre closed 1 month ago

Klustre commented 1 month ago

Strip Typescript's Triple-Slash Directives from the code when using Send to Cavalry As…. They're only useful in VSCode and pollute Cavalry's expression editor.

Klustre commented 1 month ago

/\/\/\/\s<reference.+\/>/g

yevgenymakarov commented 1 month ago

Try this way:

let regex = /^\/\/\/\s<reference.+\/>\n/;
text = text.replace(regex, "")

You need something like this for the line ending, though: (\r\n|\n|\r).

Klustre commented 1 month ago

There's no need to make it more specific than necessary. The one you posted only works in a single case and fails when preceded by comments.

Triple-slash directives are only valid at the top of their containing file. A triple-slash directive can only be preceded by single or multi-line comments, including other triple-slash directives. If they are encountered following a statement or a declaration they are treated as regular single-line comments, and hold no special meaning. Source