fix(compiler): handle strings inside bindings that contain binding ch… · angular/angular@f5aab2b
@@ -762,6 +762,37 @@ describe('parser', () => {
762762expect(ast.expressions[0].name).toEqual('a');
763763});
764764765+it('should parse interpolation inside quotes', () => {
766+const ast = parseInterpolation('"{{a}}"')!.ast as Interpolation;
767+expect(ast.strings).toEqual(['"', '"']);
768+expect(ast.expressions.length).toEqual(1);
769+expect(ast.expressions[0].name).toEqual('a');
770+});
771+772+it('should parse interpolation with interpolation characters inside quotes', () => {
773+checkInterpolation('{{"{{a}}"}}', '{{ "{{a}}" }}');
774+checkInterpolation('{{"{{"}}', '{{ "{{" }}');
775+checkInterpolation('{{"}}"}}', '{{ "}}" }}');
776+checkInterpolation('{{"{"}}', '{{ "{" }}');
777+checkInterpolation('{{"}"}}', '{{ "}" }}');
778+});
779+780+it('should parse interpolation with escaped quotes', () => {
781+checkInterpolation(`{{'It\\'s just Angular'}}`, `{{ "It's just Angular" }}`);
782+checkInterpolation(`{{'It\\'s {{ just Angular'}}`, `{{ "It's {{ just Angular" }}`);
783+checkInterpolation(`{{'It\\'s }} just Angular'}}`, `{{ "It's }} just Angular" }}`);
784+});
785+786+it('should parse interpolation with escaped backslashes', () => {
787+checkInterpolation(`{{foo.split('\\\\')}}`, `{{ foo.split("\\") }}`);
788+checkInterpolation(`{{foo.split('\\\\\\\\')}}`, `{{ foo.split("\\\\") }}`);
789+checkInterpolation(`{{foo.split('\\\\\\\\\\\\')}}`, `{{ foo.split("\\\\\\") }}`);
790+});
791+792+it('should not parse interpolation with mismatching quotes', () => {
793+expect(parseInterpolation(`{{ "{{a}}' }}`)).toBeNull();
794+});
795+765796it('should parse prefix/suffix with multiple interpolation', () => {
766797const originalExp = 'before {{ a }} middle {{ b }} after';
767798const ast = parseInterpolation(originalExp)!.ast;
@@ -819,6 +850,10 @@ describe('parser', () => {
819850it('should retain // in nested, unterminated strings', () => {
820851checkInterpolation(`{{ "a\'b\`" //comment}}`, `{{ "a\'b\`" }}`);
821852});
853+854+it('should ignore quotes inside a comment', () => {
855+checkInterpolation(`"{{name // " }}"`, `"{{ name }}"`);
856+});
822857});
823858});
824859@@ -999,8 +1034,11 @@ function parseSimpleBindingIvy(
9991034}
1000103510011036function checkInterpolation(exp: string, expected?: string) {
1002-const ast = parseInterpolation(exp)!;
1037+const ast = parseInterpolation(exp);
10031038if (expected == null) expected = exp;
1039+if (ast === null) {
1040+throw Error(`Failed to parse expression "${exp}"`);
1041+}
10041042expect(unparse(ast)).toEqual(expected);
10051043validate(ast);
10061044}