diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/GOLDEN_PARTIAL.js b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/GOLDEN_PARTIAL.js deleted file mode 100644 index 8b13789179..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/GOLDEN_PARTIAL.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json deleted file mode 100644 index ef9628442d..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/TEST_CASES.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "$schema": "../../test_case_schema.json", - "cases": [ - { - "description": "should throw on nested i18n sections", - "inputFiles": [ - "nested_i18n_msg.ts" - ], - "compilationModeFilter": [ - "full compile" - ], - "expectations": [ - { - "expectedErrors": [ - { - "message": "Cannot mark an element as translatable inside of a translatable section\\. Please remove the nested i18n marker\\.", - "location": "nested_i18n_msg\\.ts \\(7,5\\)" - } - ] - } - ] - }, - { - "description": "should throw on nested i18n sections with tags in between", - "inputFiles": [ - "nested_i18n_msg_with_tags.ts" - ], - "compilationModeFilter": [ - "full compile" - ], - "expectations": [ - { - "expectedErrors": [ - { - "message": "Cannot mark an element as translatable inside of a translatable section\\. Please remove the nested i18n marker\\.", - "location": "nested_i18n_msg_with_tags\\.ts \\(8,7\\)" - } - ] - } - ] - }, - { - "description": "should throw on nested i18n sections represented with s", - "inputFiles": [ - "nested_i18n_msg_with_ng-containers.ts" - ], - "compilationModeFilter": [ - "full compile" - ], - "expectations": [ - { - "expectedErrors": [ - { - "message": "Cannot mark an element as translatable inside of a translatable section\\. Please remove the nested i18n marker\\.", - "location": "nested_i18n_msg_with_ng-containers\\.ts \\(8,7\\)" - } - ] - } - ] - } - ] -} diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg.ts deleted file mode 100644 index 533f1f9060..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg.ts +++ /dev/null @@ -1,16 +0,0 @@ -import {Component, NgModule} from '@angular/core'; - -@Component({ - selector: 'my-component', - template: ` -
-
Some content
-
-`, -}) -export class MyComponent { -} - -@NgModule({declarations: [MyComponent]}) -export class MyModule { -} \ No newline at end of file diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_ng-containers.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_ng-containers.ts deleted file mode 100644 index e5690686f2..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_ng-containers.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {Component, NgModule} from '@angular/core'; - -@Component({ - selector: 'my-component', - template: ` - -
- Some content -
-
-`, -}) -export class MyComponent { -} - -@NgModule({declarations: [MyComponent]}) -export class MyModule { -} \ No newline at end of file diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_tags.ts b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_tags.ts deleted file mode 100644 index e8942340c2..0000000000 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/errors/nested_i18n_msg_with_tags.ts +++ /dev/null @@ -1,18 +0,0 @@ -import {Component, NgModule} from '@angular/core'; - -@Component({ - selector: 'my-component', - template: ` -
-
-
Some content
-
-
-`, -}) -export class MyComponent { -} - -@NgModule({declarations: [MyComponent]}) -export class MyModule { -} \ No newline at end of file diff --git a/packages/compiler-cli/test/compliance_old/r3_view_compiler_i18n_spec.ts b/packages/compiler-cli/test/compliance_old/r3_view_compiler_i18n_spec.ts index e87b65c0a5..f0cf9ac3a5 100644 --- a/packages/compiler-cli/test/compliance_old/r3_view_compiler_i18n_spec.ts +++ b/packages/compiler-cli/test/compliance_old/r3_view_compiler_i18n_spec.ts @@ -3325,61 +3325,6 @@ $` + String.raw`{$I18N_4$}:ICU:\`; }); }); - describe('errors', () => { - const verifyNestedSectionsError = (errorThrown: any, expectedErrorText: string) => { - expect(errorThrown.ngParseErrors.length).toBe(1); - const msg = errorThrown.ngParseErrors[0].toString(); - expect(msg).toContain( - 'Cannot mark an element as translatable inside of a translatable section. Please remove the nested i18n marker.'); - expect(msg).toContain(expectedErrorText); - expect(msg).toMatch(/app\/spec\.ts\@\d+\:\d+/); - }; - - it('should throw on nested i18n sections', () => { - const files = getAppFilesWithTemplate(` -
-
Some content
-
- `); - try { - compile(files, angularFiles); - } catch (error) { - verifyNestedSectionsError(error, '[ERROR ->]
Some content
'); - } - }); - - it('should throw on nested i18n sections with tags in between', () => { - const files = getAppFilesWithTemplate(` -
-
-
Some content
-
-
- `); - try { - compile(files, angularFiles); - } catch (error) { - verifyNestedSectionsError(error, '[ERROR ->]
Some content
'); - } - }); - - it('should throw on nested i18n sections represented with s', () => { - const files = getAppFilesWithTemplate(` - -
- Some content -
-
- `); - try { - compile(files, angularFiles); - } catch (error) { - verifyNestedSectionsError( - error, '[ERROR ->]Some content'); - } - }); - }); - describe('namespaces', () => { it('should handle namespaces inside i18n blocks', () => { const input = ` diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index b613f5ee9b..b44016d070 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -7601,6 +7601,74 @@ export const Foo = Foo__PRE_R3__; expect(getDiagnosticSourceCode(diags[0])).toBe('\''); }); }); + + describe('i18n errors', () => { + it('should report helpful error message on nested i18n sections', () => { + env.write('test.ts', ` + import {Component} from '@angular/core'; + @Component({ + selector: 'test-component', + template: '
Content
' + }) + class TestComponent {} + `); + + const diags = env.driveDiagnostics(); + + expect(diags.length).toEqual(1); + expect(diags[0].messageText) + .toEqual( + 'Cannot mark an element as translatable inside of a translatable section.' + + ' Please remove the nested i18n marker.'); + expect(diags[0].file?.fileName).toEqual(absoluteFrom('/test.ts')); + expect(diags[0].file?.text.substr(diags[0].start!, diags[0].length)) + .toEqual('
Content
'); + }); + + it('report a diagnostic on nested i18n sections with tags in between', () => { + env.write('test.ts', ` + import {Component} from '@angular/core'; + @Component({ + selector: 'test-component', + template: '
Content
' + }) + class TestComponent {} + `); + + const diags = env.driveDiagnostics(); + + expect(diags.length).toEqual(1); + expect(diags[0].messageText) + .toEqual( + 'Cannot mark an element as translatable inside of a translatable section.' + + ' Please remove the nested i18n marker.'); + expect(diags[0].file?.fileName).toEqual(absoluteFrom('/test.ts')); + expect(diags[0].file?.text.substr(diags[0].start!, diags[0].length)) + .toEqual('
Content
'); + }); + + it('report a diagnostic on nested i18n sections represented with s', () => { + env.write('test.ts', ` + import {Component} from '@angular/core'; + @Component({ + selector: 'test-component', + template: '
Content
' + }) + class TestComponent {} + `); + + const diags = env.driveDiagnostics(); + + expect(diags.length).toEqual(1); + expect(diags[0].messageText) + .toEqual( + 'Cannot mark an element as translatable inside of a translatable section.' + + ' Please remove the nested i18n marker.'); + expect(diags[0].file?.fileName).toEqual(absoluteFrom('/test.ts')); + expect(diags[0].file?.text.substr(diags[0].start!, diags[0].length)) + .toEqual('Content'); + }); + }); }); });