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

fix(compiler-cli): do not lower expressions in non-modules #21649

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
5 changes: 3 additions & 2 deletions packages/compiler-cli/src/transformers/lower_expressions.ts
Expand Up @@ -325,13 +325,14 @@ export class LowerMetadataCache implements RequestsMap {
};

// Do not validate or lower metadata in a declaration file. Declaration files are requested
// when we need to update the version of the metadata to add informatoin that might be missing
// when we need to update the version of the metadata to add information that might be missing
// in the out-of-date version that can be recovered from the .d.ts file.
const declarationFile = sourceFile.isDeclarationFile;
const moduleFile = ts.isExternalModule(sourceFile);

const metadata = this.collector.getMetadata(
sourceFile, this.strict && !declarationFile,
declarationFile ? undefined : substituteExpression);
moduleFile && !declarationFile ? substituteExpression : undefined);

return {metadata, requests};
}
Expand Down
Expand Up @@ -99,7 +99,17 @@ describe('Expression lowering', () => {
.toBeTruthy('did not find the data field');
});

it('should throw a validation execption for invalid files', () => {
it('should not lower a non-module', () => {
const collected = collect(`
declare const global: any;
const ngDevMode: boolean = (function(global: any) {
return global.ngDevMode = true;
})(typeof window != 'undefined' && window || typeof self != 'undefined' && self || typeof global != 'undefined' && global);
`);
expect(collected.requests.size).toBe(0, 'unexpected rewriting');
});

it('should throw a validation exception for invalid files', () => {
const cache = new LowerMetadataCache({}, /* strict */ true);
const sourceFile = ts.createSourceFile(
'foo.ts', `
Expand Down