Skip to content

Commit

Permalink
fix: non greedy regex for ts links
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Nov 11, 2023
1 parent 2ac278d commit b012eee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/regexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const edgeComponentsAsTagsRegex =
/**
* Find all the views that are being used inside a TS/Js file
*/
export const tsRegex = /((?:[Vv]iew|[Ee]dge)\.render(?:Sync)?\(['"](.*)['"])/g
export const tsRegex = /((?:[Vv]iew|[Ee]dge)\.render(?:Sync)?\(['"](.*?)['"])/g

/**
* Check if we are currently inside a view link and capture the user input to suggest completions
Expand Down
27 changes: 27 additions & 0 deletions tests/linker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,31 @@ test.group('Views Linker | .ts', () => {
const positions = result.map((r) => r.position)
assert.deepEqual(positions, [{ colEnd: 37, colStart: 20, line: 2 }])
})

test('should find link even when the template props include "(" character', async ({
assert,
fs,
}) => {
await fs.create('resources/views/components/button.edge', '')

const template = dedent`
return view.render('components/button', { prop: route('bar') })
`

const indexer = new TemplateIndexer({
rootPath: fs.basePath,
disks: { default: 'resources/views' },
})

await indexer.scan()

const result = await Linker.getLinks({
fileContent: template,
indexer,
sourceType: 'ts',
})

const positions = result.map((r) => r.position)
assert.deepEqual(positions, [{ colEnd: 37, colStart: 20, line: 0 }])
})
})

0 comments on commit b012eee

Please sign in to comment.