Repository navigation
Commit 672b464
committed
refactor(compiler): tighten the i18n placeholder name annotation regex
The regex that reads the name out of a `//i18n(ph="NAME")` annotation on an
interpolation expression chained five greedy `[\s\S]*` segments between the
literals `i18n`, `(`, `ph`, `=` and the opening quote. The separators in that
annotation are only ever whitespace, so bind them to `\s*`, and stop the name at
its own delimiter quote instead of letting it scan to the end of the input.
The loose pattern also had to try every way a run of `i18n(ph=` text could be
split across those wildcards, so rejecting an unterminated annotation took
exponential time: `'//' + 'i18n(ph='.repeat(200)` (~1.6 KB) took ~96s to
extract, and now resolves immediately.
Well-formed annotations resolve to the same name as before. The stricter pattern
does differ on malformed or repeated annotations, where the greedy wildcards
used to reach across them:
- `// i18n(ph="A") // i18n(ph="B")` resolves to `A` rather than `B`.
- `// i18n(ph="A"] )` is no longer recognized, since `]` is not whitespace.
- `// i18n(ph='say "hi"')` resolves to `say "hi"` rather than `hi`.1 parent 3bf2430 commit 672b464
2 files changed
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
457 | | - | |
| 456 | + | |
458 | 457 | | |
459 | 458 | | |
460 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
150 | 161 | | |
151 | 162 | | |
152 | 163 | | |
| |||
0 commit comments