Skip to content

Commit

Permalink
update multiline capture to be simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Nov 24, 2024
1 parent 00bae95 commit d3e1b75
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function compile(
const imports = new Set<string>();

/**
* Tested on https://regex101.com/r/qfrOft/9
* Tested on https://regex101.com/r/qfrOft/10
*
* groups
* - 1st `prefix`
Expand All @@ -37,9 +37,9 @@ export function compile(
* - 2rd `blank`
* - `\s*` - blank characters (spaces, tabs, lf, etc) before the `graphql` tag
* - 3rd `query`
* - `[\s\S]*?` - multiline text (lazy) inside of the `graphql` tag
* - `[^`]*` - multiline text (lazy) inside of the `graphql` tag
*/
const pattern = /(?<prefix>^|[\=\?\:\|\&\,\;\(\[\{\}\.\>]|\*\/)(?<blank>\s*)graphql`(?<query>[\s\S]*?)`/gm;
const pattern = /(?<prefix>^|[\=\?\:\|\&\,\;\(\[\{\}\.\>]|\*\/)(?<blank>\s*)graphql`(?<query>[^`]*)`/gm;
content.replace(pattern, (match, prefix: string, blank: string, query: string) => {
// Guess if it is in JS comment lines
//
Expand Down

0 comments on commit d3e1b75

Please sign in to comment.