Skip to content

Commit 9a89db7

Browse files
JoostKalxhub
authored andcommitted
fix(compiler-cli): avoid broken references in .d.ts files due to @internal markers (angular#43965)
The `ErrorCode` enum in the `error_code.ts` file is governed by public api guards but the other top-level exports from that file are exempt from public api documentation and are therefore marked as `@internal`. However, TypeScript is configured with the `stripInternal` compiler option such that declarations with `@internal` markers are not emitted into the `.d.ts` files, but this means that the reexports in the barrel file end up referring to missing declarations. The `stripInternal` option is considered internal and its documentation states to use at your own risk (as per microsoft/TypeScript#45307). Having the option enabled is desirable for us as it works well for hiding class fields that are marked `@internal`, which is an effective way to hide members from the .d.ts file. As a workaround for the issue with top-level symbols, the declarations with `@internal` markers are moved to dedicated files for which no public api guard is setup, therefore allowing their `@internal` markers to be dropped. Fixes angular#43097 PR Close angular#43965
1 parent 8d060dd commit 9a89db7

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

packages/compiler-cli/src/ngtsc/diagnostics/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
export {COMPILER_ERRORS_WITH_GUIDES, ERROR_DETAILS_PAGE_BASE_URL} from './src/docs';
910
export {FatalDiagnosticError, isFatalDiagnosticError, makeDiagnostic, makeRelatedInformation} from './src/error';
10-
export {COMPILER_ERRORS_WITH_GUIDES, ERROR_DETAILS_PAGE_BASE_URL, ErrorCode, ngErrorCode} from './src/error_code';
11-
export {replaceTsWithNgInErrors} from './src/util';
11+
export {ErrorCode} from './src/error_code';
12+
export {ngErrorCode, replaceTsWithNgInErrors} from './src/util';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {ErrorCode} from './error_code';
10+
11+
/**
12+
* Base URL for the error details page.
13+
* Keep this value in sync with a similar const in
14+
* `packages/core/src/render3/error_code.ts`.
15+
*/
16+
export const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
17+
18+
/**
19+
* Contains a set of error messages that have detailed guides at angular.io.
20+
* Full list of available error guides can be found at https://angular.io/errors
21+
*/
22+
export const COMPILER_ERRORS_WITH_GUIDES = new Set([
23+
ErrorCode.DECORATOR_ARG_NOT_LITERAL,
24+
ErrorCode.IMPORT_CYCLE_DETECTED,
25+
ErrorCode.PARAM_MISSING_TOKEN,
26+
ErrorCode.SCHEMA_INVALID_ELEMENT,
27+
ErrorCode.SCHEMA_INVALID_ATTRIBUTE,
28+
ErrorCode.MISSING_REFERENCE_TARGET,
29+
ErrorCode.COMPONENT_INVALID_SHADOW_DOM_SELECTOR,
30+
]);

packages/compiler-cli/src/ngtsc/diagnostics/src/error.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import * as ts from 'typescript';
1010

11-
import {ErrorCode, ngErrorCode} from './error_code';
11+
import {ErrorCode} from './error_code';
12+
import {ngErrorCode} from './util';
1213

1314
export class FatalDiagnosticError {
1415
constructor(

packages/compiler-cli/src/ngtsc/diagnostics/src/error_code.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -226,33 +226,3 @@ export enum ErrorCode {
226226
*/
227227
SUGGEST_SUBOPTIMAL_TYPE_INFERENCE = 10002,
228228
}
229-
230-
/**
231-
* @internal
232-
* Base URL for the error details page.
233-
* Keep this value in sync with a similar const in
234-
* `packages/core/src/render3/error_code.ts`.
235-
*/
236-
export const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
237-
238-
/**
239-
* @internal
240-
* Contains a set of error messages that have detailed guides at angular.io.
241-
* Full list of available error guides can be found at https://angular.io/errors
242-
*/
243-
export const COMPILER_ERRORS_WITH_GUIDES = new Set([
244-
ErrorCode.DECORATOR_ARG_NOT_LITERAL,
245-
ErrorCode.IMPORT_CYCLE_DETECTED,
246-
ErrorCode.PARAM_MISSING_TOKEN,
247-
ErrorCode.SCHEMA_INVALID_ELEMENT,
248-
ErrorCode.SCHEMA_INVALID_ATTRIBUTE,
249-
ErrorCode.MISSING_REFERENCE_TARGET,
250-
ErrorCode.COMPONENT_INVALID_SHADOW_DOM_SELECTOR,
251-
]);
252-
253-
/**
254-
* @internal
255-
*/
256-
export function ngErrorCode(code: ErrorCode): number {
257-
return parseInt('-99' + code);
258-
}

packages/compiler-cli/src/ngtsc/diagnostics/src/util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {ErrorCode} from './error_code';
10+
911
const ERROR_CODE_MATCHER = /(\u001b\[\d+m ?)TS-99(\d+: ?\u001b\[\d+m)/g;
1012

1113
/**
@@ -20,3 +22,7 @@ const ERROR_CODE_MATCHER = /(\u001b\[\d+m ?)TS-99(\d+: ?\u001b\[\d+m)/g;
2022
export function replaceTsWithNgInErrors(errors: string): string {
2123
return errors.replace(ERROR_CODE_MATCHER, '$1NG$2');
2224
}
25+
26+
export function ngErrorCode(code: ErrorCode): number {
27+
return parseInt('-99' + code);
28+
}

packages/core/src/render3/error_code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Base URL for the error details page.
1010
// Keep this value in sync with a similar const in
11-
// `packages/compiler-cli/src/ngtsc/diagnostics/src/error_code.ts`.
11+
// `packages/compiler-cli/src/ngtsc/diagnostics/src/docs.ts`.
1212
const ERROR_DETAILS_PAGE_BASE_URL = 'https://angular.io/errors';
1313

1414
export const enum RuntimeErrorCode {

0 commit comments

Comments
 (0)