Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(convert-signal-inputs): handle input name overlap in template #263

Merged

Conversation

joshuamorony
Copy link
Contributor

I used the signal inputs generator on a big project recently and ran into trouble with cases like this:

<test [normalInput]="normalInput" />
<test-normalInput />
<normalInput />
<another-component something="blah-normalInput" />

In cases where:

  • A child component input had the same name as a parent component input
  • The name of an input was used as part of a tag name
  • The name of an input was used within a property value

The template was being updated incorrectly, e.g:

<test [normalInput()]="normalInput()" />
<test-normalInput() />
<normalInput() />
<another-component something="blah-normalInput()" />

NOTE: I noticed there where two different regexes being used for the template based on whether it was a templateUrl or inline. One was simpler and I assume was mistaking left un-updated whilst the other one had been updated to something more complex. I have updated both to use the same updated regex now, but wanted to make a note in case something intentional was happening here

This updates the RegExp to handle the cases I mentioned, break down from ChatGPT who gets credit for writing the actual regex:

  • (?<![\w-]): Negative lookbehind to ensure ${convertedInput} is not immediately preceded by any word character or hyphen.
  • \b${convertedInput}\b: Matches ${convertedInput} as a whole word.
  • (?!\]): Negative lookahead to ensure ${convertedInput} is not immediately followed by ].
  • (?!>): Negative lookahead to ensure ${convertedInput} is not immediately followed by >.
  • (?![\w-]): Negative lookahead to ensure ${convertedInput} is not immediately followed by any word character or hyphen.

Copy link

nx-cloud bot commented Jan 31, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 64d51e1. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --target=lint --parallel=3
✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@nartc nartc merged commit d076b48 into ngxtension:main Feb 2, 2024
5 of 6 checks passed
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