fix(compiler): more robust logic to check if regex can be optimized · angular/angular@a56f1cd · GitHub
Skip to content

Commit a56f1cd

Browse files
crisbetoatscott
authored andcommitted
fix(compiler): more robust logic to check if regex can be optimized
Currently we only skip regex optimization if it has the `g` flag, however regexes can also have a state with the `y` flag. These changes move to an allowlist model where we only optimize for a set of know flags. (cherry picked from commit 636cc94)
1 parent 32b348a commit a56f1cd

6 files changed

Lines changed: 77 additions & 5 deletions

File tree

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/GOLDEN_PARTIAL.js

Lines changed: 27 additions & 0 deletions

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/TEST_CASES.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,16 @@
317317
}
318318
]
319319
},
320+
{
321+
"description": "should not optimize sticky regular expressions",
322+
"inputFiles": ["regular_expression_with_sticky_flag.ts"],
323+
"expectations": [
324+
{
325+
"failureMessage": "Invalid template",
326+
"files": ["regular_expression_with_sticky_flag.js"]
327+
}
328+
]
329+
},
320330
{
321331
"description": "should support rest arguments in a function call",
322332
"inputFiles": ["call_rest.ts"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function TestComp_Template(rf, ctx) {
2+
if (rf & 1) {
3+
$r3$.ɵɵtext(0);
4+
}
5+
if (rf & 2) {
6+
$r3$.ɵɵtextInterpolate(/^hello/y.test(ctx.value));
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
template: `{{/^hello/y.test(value)}}`,
5+
})
6+
export class TestComp {
7+
value = '123';
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as i0 from "@angular/core";
2+
export declare class TestComp {
3+
value: string;
4+
static ɵfac: i0.ɵɵFactoryDeclaration<TestComp, never>;
5+
static ɵcmp: i0.ɵɵComponentDeclaration<TestComp, "ng-component", never, {}, {}, never, never, true, never>;
6+
}

packages/compiler/src/template/pipeline/src/phases/regular_expression_optimization.ts

Lines changed: 18 additions & 5 deletions

0 commit comments

Comments
 (0)