Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bazel): transform generated shims (in Ivy) with tsickle #35848

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/bazel/src/ngc-wrapped/index.ts
Expand Up @@ -184,7 +184,7 @@ export function compile({allDepsCompiledWithBazel = true, compilerOpts, tsHost,
}

// Detect from compilerOpts whether the entrypoint is being invoked in Ivy mode.
const isInIvyMode = compilerOpts.enableIvy === 'ngtsc';
const isInIvyMode = !!compilerOpts.enableIvy;

// Disable downleveling and Closure annotation if in Ivy mode.
if (isInIvyMode) {
Expand Down Expand Up @@ -245,9 +245,18 @@ export function compile({allDepsCompiledWithBazel = true, compilerOpts, tsHost,
files, compilerOpts, bazelOpts, tsHost, fileLoader, generatedFileModuleResolver);
}

// Also need to disable decorator downleveling in the BazelHost in Ivy mode.
if (isInIvyMode) {
// Also need to disable decorator downleveling in the BazelHost in Ivy mode.
bazelHost.transformDecorators = false;

const delegate = bazelHost.shouldSkipTsickleProcessing.bind(bazelHost);
bazelHost.shouldSkipTsickleProcessing = (fileName: string) => {
// The base implementation of shouldSkipTsickleProcessing checks whether `fileName` is part of
// the original `srcs[]`. For Angular (Ivy) compilations, ngfactory/ngsummary files that are
// shims for original .ts files in the program should be treated identically. Thus, strip the
// '.ngfactory' or '.ngsummary' part of the filename away before calling the delegate.
return delegate(fileName.replace(/\.(ngfactory|ngsummary)\.ts$/, '.ts'));
};
}

// Prevent tsickle adding any types at all if we don't want closure compiler annotations.
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-cli/src/main.ts
Expand Up @@ -103,8 +103,9 @@ function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|un
tsickle.TsickleHost, 'shouldSkipTsickleProcessing'|'pathToModuleName'|
'shouldIgnoreWarningsForPath'|'fileNameToModuleId'|'googmodule'|'untyped'|
'convertIndexImportShorthand'|'transformDecorators'|'transformTypesToClosure'> = {
shouldSkipTsickleProcessing: (fileName) =>
/\.d\.ts$/.test(fileName) || GENERATED_FILES.test(fileName),
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName) ||
alxhub marked this conversation as resolved.
Show resolved Hide resolved
// View Engine's generated files were never intended to be processed with tsickle.
(!options.enableIvy && GENERATED_FILES.test(fileName)),
pathToModuleName: (context, importPath) => '',
shouldIgnoreWarningsForPath: (filePath) => false,
fileNameToModuleId: (fileName) => fileName,
Expand Down
25 changes: 25 additions & 0 deletions packages/compiler-cli/test/ngtsc/ngtsc_spec.ts
Expand Up @@ -4594,6 +4594,31 @@ runInEachFileSystem(os => {
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();
});

it('should be produced for generated factory files', () => {
env.tsconfig({
'annotateForClosureCompiler': true,
'generateNgFactoryShims': true,
});
env.write(`test.ts`, `
import {Component} from '@angular/core';

@Component({
template: '<div class="test"></div>',
})
export class SomeComp {}
`);

env.driveMain();
const jsContents = env.getContents('test.ngfactory.js');
const fileoverview = `
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
`;
expect(trim(jsContents).startsWith(trim(fileoverview))).toBeTruthy();
});

it('should always be at the very beginning of a script (if placed above imports)', () => {
env.tsconfig({
'annotateForClosureCompiler': true,
Expand Down