2019-07-18 16:05:32 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-07-18 16:05:32 -04:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2020-01-06 17:12:19 -05:00
|
|
|
|
2019-11-23 12:54:07 -05:00
|
|
|
import * as ts from 'typescript';
|
|
|
|
|
2020-01-06 17:12:19 -05:00
|
|
|
import {makeDiagnostic} from '../../../src/ngtsc/diagnostics';
|
|
|
|
import {absoluteFrom} from '../../../src/ngtsc/file_system';
|
2019-10-20 14:40:48 -04:00
|
|
|
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
import {SemanticSymbol} from '../../../src/ngtsc/incremental/semantic_graph';
|
2020-05-14 15:06:12 -04:00
|
|
|
import {MockLogger} from '../../../src/ngtsc/logging/testing';
|
2020-01-06 17:12:19 -05:00
|
|
|
import {ClassDeclaration, Decorator, isNamedClassDeclaration} from '../../../src/ngtsc/reflection';
|
2020-11-04 15:27:19 -05:00
|
|
|
import {getDeclaration, loadTestFiles} from '../../../src/ngtsc/testing';
|
fix(compiler-cli): remove the concept of an errored trait (#39923)
Previously, if a trait's analysis step resulted in diagnostics, the trait
would be considered "errored" and no further operations, including register,
would be performed. Effectively, this meant that the compiler would pretend
the class in question was actually undecorated.
However, this behavior is problematic for several reasons:
1. It leads to inaccurate diagnostics being reported downstream.
For example, if a component is put into the error state, for example due to
a template error, the NgModule which declares the component would produce a
diagnostic claiming that the declaration is neither a directive nor a pipe.
This happened because the compiler wouldn't register() the component trait,
so the component would not be recorded as actually being a directive.
2. It can cause incorrect behavior on incremental builds.
This bug is more complex, but the general issue is that if the compiler
fails to associate a component and its module, then incremental builds will
not correctly re-analyze the module when the component's template changes.
Failing to register the component as such is one link in the larger chain of
issues that result in these kinds of issues.
3. It lumps together diagnostics produced during analysis and resolve steps.
This is not causing issues currently as the dependency graph ensures the
right classes are re-analyzed when needed, instead of showing stale
diagnostics. However, the dependency graph was not intended to serve this
role, and could potentially be optimized in ways that would break this
functionality.
This commit removes the concept of an "errored" trait entirely from the
trait system. Instead, analyzed and resolved traits have corresponding (and
separate) diagnostics, in addition to potentially `null` analysis results.
Analysis (but not resolution) diagnostics are carried forward during
incremental build operations. Compilation (emit) is only performed when
a trait reaches the resolved state with no diagnostics.
This change is functionally different than before as the `register` step is
now performed even in the presence of analysis errors, as long as analysis
results are also produced. This fixes problem 1 above, and is part of the
larger solution to problem 2.
PR Close #39923
2020-11-25 18:01:24 -05:00
|
|
|
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../../src/ngtsc/transform';
|
2019-07-18 16:05:32 -04:00
|
|
|
import {DefaultMigrationHost} from '../../src/analysis/migration_host';
|
2020-01-06 17:12:19 -05:00
|
|
|
import {NgccTraitCompiler} from '../../src/analysis/ngcc_trait_compiler';
|
|
|
|
import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
2019-11-23 12:54:07 -05:00
|
|
|
import {createComponentDecorator} from '../../src/migrations/utils';
|
2020-01-06 17:12:19 -05:00
|
|
|
import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
|
|
|
|
import {makeTestEntryPointBundle} from '../helpers/utils';
|
fix(compiler-cli): remove the concept of an errored trait (#39923)
Previously, if a trait's analysis step resulted in diagnostics, the trait
would be considered "errored" and no further operations, including register,
would be performed. Effectively, this meant that the compiler would pretend
the class in question was actually undecorated.
However, this behavior is problematic for several reasons:
1. It leads to inaccurate diagnostics being reported downstream.
For example, if a component is put into the error state, for example due to
a template error, the NgModule which declares the component would produce a
diagnostic claiming that the declaration is neither a directive nor a pipe.
This happened because the compiler wouldn't register() the component trait,
so the component would not be recorded as actually being a directive.
2. It can cause incorrect behavior on incremental builds.
This bug is more complex, but the general issue is that if the compiler
fails to associate a component and its module, then incremental builds will
not correctly re-analyze the module when the component's template changes.
Failing to register the component as such is one link in the larger chain of
issues that result in these kinds of issues.
3. It lumps together diagnostics produced during analysis and resolve steps.
This is not causing issues currently as the dependency graph ensures the
right classes are re-analyzed when needed, instead of showing stale
diagnostics. However, the dependency graph was not intended to serve this
role, and could potentially be optimized in ways that would break this
functionality.
This commit removes the concept of an "errored" trait entirely from the
trait system. Instead, analyzed and resolved traits have corresponding (and
separate) diagnostics, in addition to potentially `null` analysis results.
Analysis (but not resolution) diagnostics are carried forward during
incremental build operations. Compilation (emit) is only performed when
a trait reaches the resolved state with no diagnostics.
This change is functionally different than before as the `register` step is
now performed even in the presence of analysis errors, as long as analysis
results are also produced. This fixes problem 1 above, and is part of the
larger solution to problem 2.
PR Close #39923
2020-11-25 18:01:24 -05:00
|
|
|
import {getTraitDiagnostics} from '../host/util';
|
2019-07-18 16:05:32 -04:00
|
|
|
|
2019-10-20 14:40:48 -04:00
|
|
|
runInEachFileSystem(() => {
|
|
|
|
describe('DefaultMigrationHost', () => {
|
|
|
|
let _: typeof absoluteFrom;
|
|
|
|
let mockMetadata: any = {};
|
|
|
|
let mockEvaluator: any = {};
|
|
|
|
let mockClazz: any;
|
2020-01-06 17:12:19 -05:00
|
|
|
let injectedDecorator: any = {name: 'InjectedDecorator'};
|
2019-10-20 14:40:48 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
_ = absoluteFrom;
|
|
|
|
const mockSourceFile: any = {
|
|
|
|
fileName: _('/node_modules/some-package/entry-point/test-file.js'),
|
|
|
|
};
|
|
|
|
mockClazz = {
|
|
|
|
name: {text: 'MockClazz'},
|
|
|
|
getSourceFile: () => mockSourceFile,
|
2020-01-06 17:12:19 -05:00
|
|
|
getStart: () => 0,
|
|
|
|
getWidth: () => 0,
|
2019-10-20 14:40:48 -04:00
|
|
|
};
|
2019-07-18 16:05:32 -04:00
|
|
|
});
|
|
|
|
|
2020-01-06 17:12:19 -05:00
|
|
|
function createMigrationHost({entryPoint, handlers}: {
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
entryPoint: EntryPointBundle;
|
|
|
|
handlers: DecoratorHandler<unknown, unknown, SemanticSymbol|null, unknown>[]
|
2020-01-06 17:12:19 -05:00
|
|
|
}) {
|
|
|
|
const reflectionHost = new Esm2015ReflectionHost(new MockLogger(), false, entryPoint.src);
|
|
|
|
const compiler = new NgccTraitCompiler(handlers, reflectionHost);
|
|
|
|
const host = new DefaultMigrationHost(
|
|
|
|
reflectionHost, mockMetadata, mockEvaluator, compiler, entryPoint.entryPoint.path);
|
|
|
|
return {compiler, host};
|
|
|
|
}
|
2019-10-20 14:40:48 -04:00
|
|
|
|
2020-01-06 17:12:19 -05:00
|
|
|
describe('injectSyntheticDecorator()', () => {
|
|
|
|
it('should add the injected decorator into the compilation', () => {
|
|
|
|
const handler = new DetectDecoratorHandler('InjectedDecorator', HandlerPrecedence.WEAK);
|
|
|
|
loadTestFiles([{name: _('/node_modules/test/index.js'), contents: ``}]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host, compiler} = createMigrationHost({entryPoint, handlers: [handler]});
|
|
|
|
host.injectSyntheticDecorator(mockClazz, injectedDecorator);
|
|
|
|
|
2020-04-06 03:30:08 -04:00
|
|
|
const record = compiler.recordFor(mockClazz)!;
|
2020-01-06 17:12:19 -05:00
|
|
|
expect(record).toBeDefined();
|
|
|
|
expect(record.traits.length).toBe(1);
|
|
|
|
expect(record.traits[0].detected.decorator).toBe(injectedDecorator);
|
2019-10-20 14:40:48 -04:00
|
|
|
});
|
2019-11-23 12:54:07 -05:00
|
|
|
|
2020-01-06 17:12:19 -05:00
|
|
|
it('should mention the migration that failed in the diagnostics message', () => {
|
|
|
|
const handler = new DiagnosticProducingHandler();
|
|
|
|
loadTestFiles([{name: _('/node_modules/test/index.js'), contents: ``}]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host, compiler} = createMigrationHost({entryPoint, handlers: [handler]});
|
2019-11-23 12:54:07 -05:00
|
|
|
const decorator = createComponentDecorator(mockClazz, {selector: 'comp', exportAs: null});
|
|
|
|
host.injectSyntheticDecorator(mockClazz, decorator);
|
|
|
|
|
2020-04-06 03:30:08 -04:00
|
|
|
const record = compiler.recordFor(mockClazz)!;
|
2020-01-06 17:12:19 -05:00
|
|
|
const migratedTrait = record.traits[0];
|
fix(compiler-cli): remove the concept of an errored trait (#39923)
Previously, if a trait's analysis step resulted in diagnostics, the trait
would be considered "errored" and no further operations, including register,
would be performed. Effectively, this meant that the compiler would pretend
the class in question was actually undecorated.
However, this behavior is problematic for several reasons:
1. It leads to inaccurate diagnostics being reported downstream.
For example, if a component is put into the error state, for example due to
a template error, the NgModule which declares the component would produce a
diagnostic claiming that the declaration is neither a directive nor a pipe.
This happened because the compiler wouldn't register() the component trait,
so the component would not be recorded as actually being a directive.
2. It can cause incorrect behavior on incremental builds.
This bug is more complex, but the general issue is that if the compiler
fails to associate a component and its module, then incremental builds will
not correctly re-analyze the module when the component's template changes.
Failing to register the component as such is one link in the larger chain of
issues that result in these kinds of issues.
3. It lumps together diagnostics produced during analysis and resolve steps.
This is not causing issues currently as the dependency graph ensures the
right classes are re-analyzed when needed, instead of showing stale
diagnostics. However, the dependency graph was not intended to serve this
role, and could potentially be optimized in ways that would break this
functionality.
This commit removes the concept of an "errored" trait entirely from the
trait system. Instead, analyzed and resolved traits have corresponding (and
separate) diagnostics, in addition to potentially `null` analysis results.
Analysis (but not resolution) diagnostics are carried forward during
incremental build operations. Compilation (emit) is only performed when
a trait reaches the resolved state with no diagnostics.
This change is functionally different than before as the `register` step is
now performed even in the presence of analysis errors, as long as analysis
results are also produced. This fixes problem 1 above, and is part of the
larger solution to problem 2.
PR Close #39923
2020-11-25 18:01:24 -05:00
|
|
|
const diagnostics = getTraitDiagnostics(migratedTrait);
|
|
|
|
if (diagnostics === null) {
|
2020-01-06 17:12:19 -05:00
|
|
|
return fail('Expected migrated class trait to be in an error state');
|
|
|
|
}
|
|
|
|
|
fix(compiler-cli): remove the concept of an errored trait (#39923)
Previously, if a trait's analysis step resulted in diagnostics, the trait
would be considered "errored" and no further operations, including register,
would be performed. Effectively, this meant that the compiler would pretend
the class in question was actually undecorated.
However, this behavior is problematic for several reasons:
1. It leads to inaccurate diagnostics being reported downstream.
For example, if a component is put into the error state, for example due to
a template error, the NgModule which declares the component would produce a
diagnostic claiming that the declaration is neither a directive nor a pipe.
This happened because the compiler wouldn't register() the component trait,
so the component would not be recorded as actually being a directive.
2. It can cause incorrect behavior on incremental builds.
This bug is more complex, but the general issue is that if the compiler
fails to associate a component and its module, then incremental builds will
not correctly re-analyze the module when the component's template changes.
Failing to register the component as such is one link in the larger chain of
issues that result in these kinds of issues.
3. It lumps together diagnostics produced during analysis and resolve steps.
This is not causing issues currently as the dependency graph ensures the
right classes are re-analyzed when needed, instead of showing stale
diagnostics. However, the dependency graph was not intended to serve this
role, and could potentially be optimized in ways that would break this
functionality.
This commit removes the concept of an "errored" trait entirely from the
trait system. Instead, analyzed and resolved traits have corresponding (and
separate) diagnostics, in addition to potentially `null` analysis results.
Analysis (but not resolution) diagnostics are carried forward during
incremental build operations. Compilation (emit) is only performed when
a trait reaches the resolved state with no diagnostics.
This change is functionally different than before as the `register` step is
now performed even in the presence of analysis errors, as long as analysis
results are also produced. This fixes problem 1 above, and is part of the
larger solution to problem 2.
PR Close #39923
2020-11-25 18:01:24 -05:00
|
|
|
expect(diagnostics.length).toBe(1);
|
|
|
|
expect(ts.flattenDiagnosticMessageText(diagnostics[0].messageText, '\n'))
|
2019-11-23 12:54:07 -05:00
|
|
|
.toEqual(
|
|
|
|
`test diagnostic\n` +
|
|
|
|
` Occurs for @Component decorator inserted by an automatic migration\n` +
|
|
|
|
` @Component({ template: "", selector: "comp" })`);
|
|
|
|
});
|
2019-07-18 16:05:32 -04:00
|
|
|
});
|
|
|
|
|
2020-01-06 17:12:19 -05:00
|
|
|
describe('getAllDecorators', () => {
|
2019-10-20 14:40:48 -04:00
|
|
|
it('should include injected decorators', () => {
|
2020-01-06 17:12:19 -05:00
|
|
|
const directiveHandler = new DetectDecoratorHandler('Directive', HandlerPrecedence.WEAK);
|
|
|
|
const injectedHandler =
|
|
|
|
new DetectDecoratorHandler('InjectedDecorator', HandlerPrecedence.WEAK);
|
|
|
|
loadTestFiles([{
|
|
|
|
name: _('/node_modules/test/index.js'),
|
|
|
|
contents: `
|
|
|
|
import {Directive} from '@angular/core';
|
|
|
|
|
|
|
|
export class MyClass {};
|
|
|
|
MyClass.decorators = [{ type: Directive }];
|
|
|
|
`
|
|
|
|
}]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host, compiler} =
|
|
|
|
createMigrationHost({entryPoint, handlers: [directiveHandler, injectedHandler]});
|
|
|
|
const myClass = getDeclaration(
|
|
|
|
entryPoint.src.program, _('/node_modules/test/index.js'), 'MyClass',
|
|
|
|
isNamedClassDeclaration);
|
|
|
|
|
|
|
|
compiler.analyzeFile(entryPoint.src.file);
|
|
|
|
|
|
|
|
host.injectSyntheticDecorator(myClass, injectedDecorator);
|
|
|
|
|
2020-04-06 03:30:08 -04:00
|
|
|
const decorators = host.getAllDecorators(myClass)!;
|
2019-10-20 14:40:48 -04:00
|
|
|
expect(decorators.length).toBe(2);
|
2020-01-06 17:12:19 -05:00
|
|
|
expect(decorators[0].name).toBe('Directive');
|
|
|
|
expect(decorators[1].name).toBe('InjectedDecorator');
|
2019-10-20 14:40:48 -04:00
|
|
|
});
|
2019-07-18 16:05:32 -04:00
|
|
|
});
|
|
|
|
|
2019-10-20 14:40:48 -04:00
|
|
|
describe('isInScope', () => {
|
|
|
|
it('should be true for nodes within the entry-point', () => {
|
2020-01-06 17:12:19 -05:00
|
|
|
loadTestFiles([
|
|
|
|
{name: _('/node_modules/test/index.js'), contents: `export * from './internal';`},
|
|
|
|
{name: _('/node_modules/test/internal.js'), contents: `export class InternalClass {}`},
|
|
|
|
]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host} = createMigrationHost({entryPoint, handlers: []});
|
|
|
|
const internalClass = getDeclaration(
|
|
|
|
entryPoint.src.program, _('/node_modules/test/internal.js'), 'InternalClass',
|
|
|
|
isNamedClassDeclaration);
|
|
|
|
|
|
|
|
expect(host.isInScope(internalClass)).toBe(true);
|
2019-10-20 14:40:48 -04:00
|
|
|
});
|
|
|
|
|
2020-04-10 08:13:20 -04:00
|
|
|
it('should be false for nodes outside the entry-point (in sibling package)', () => {
|
2020-01-06 17:12:19 -05:00
|
|
|
loadTestFiles([
|
|
|
|
{name: _('/node_modules/external/index.js'), contents: `export class ExternalClass {}`},
|
|
|
|
{
|
|
|
|
name: _('/node_modules/test/index.js'),
|
|
|
|
contents: `
|
|
|
|
export {ExternalClass} from 'external';
|
|
|
|
export class InternalClass {}
|
|
|
|
`
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host} = createMigrationHost({entryPoint, handlers: []});
|
|
|
|
const externalClass = getDeclaration(
|
|
|
|
entryPoint.src.program, _('/node_modules/external/index.js'), 'ExternalClass',
|
|
|
|
isNamedClassDeclaration);
|
|
|
|
|
|
|
|
expect(host.isInScope(externalClass)).toBe(false);
|
2019-10-20 14:40:48 -04:00
|
|
|
});
|
2020-04-10 08:13:20 -04:00
|
|
|
|
|
|
|
it('should be false for nodes outside the entry-point (in nested `node_modules/`)', () => {
|
|
|
|
loadTestFiles([
|
|
|
|
{
|
|
|
|
name: _('/node_modules/test/index.js'),
|
|
|
|
contents: `
|
|
|
|
export {NestedDependencyClass} from 'nested';
|
|
|
|
export class InternalClass {}
|
|
|
|
`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: _('/node_modules/test/node_modules/nested/index.js'),
|
|
|
|
contents: `export class NestedDependencyClass {}`,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
const entryPoint =
|
|
|
|
makeTestEntryPointBundle('test', 'esm2015', false, [_('/node_modules/test/index.js')]);
|
|
|
|
const {host} = createMigrationHost({entryPoint, handlers: []});
|
|
|
|
const nestedDepClass = getDeclaration(
|
|
|
|
entryPoint.src.program, _('/node_modules/test/node_modules/nested/index.js'),
|
|
|
|
'NestedDependencyClass', isNamedClassDeclaration);
|
|
|
|
|
|
|
|
expect(host.isInScope(nestedDepClass)).toBe(false);
|
|
|
|
});
|
2019-07-18 16:05:32 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
class DetectDecoratorHandler implements DecoratorHandler<unknown, unknown, null, unknown> {
|
2020-01-06 17:12:19 -05:00
|
|
|
readonly name = DetectDecoratorHandler.name;
|
|
|
|
|
|
|
|
constructor(private decorator: string, readonly precedence: HandlerPrecedence) {}
|
2019-07-18 16:05:32 -04:00
|
|
|
|
2019-12-09 18:22:59 -05:00
|
|
|
detect(node: ClassDeclaration, decorators: Decorator[]|null): DetectResult<unknown>|undefined {
|
2020-01-06 17:12:19 -05:00
|
|
|
if (decorators === null) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const decorator = decorators.find(decorator => decorator.name === this.decorator);
|
|
|
|
if (decorator === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return {trigger: node, decorator, metadata: {}};
|
2019-07-18 16:05:32 -04:00
|
|
|
}
|
2020-01-06 17:12:19 -05:00
|
|
|
|
2020-04-06 03:30:08 -04:00
|
|
|
analyze(node: ClassDeclaration): AnalysisOutput<unknown> {
|
|
|
|
return {};
|
|
|
|
}
|
2020-01-06 17:12:19 -05:00
|
|
|
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
symbol(node: ClassDeclaration, analysis: Readonly<unknown>): null {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-09 15:32:56 -04:00
|
|
|
compileFull(node: ClassDeclaration): CompileResult|CompileResult[] {
|
2020-04-06 03:30:08 -04:00
|
|
|
return [];
|
|
|
|
}
|
2019-07-18 16:05:32 -04:00
|
|
|
}
|
|
|
|
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
class DiagnosticProducingHandler implements DecoratorHandler<unknown, unknown, null, unknown> {
|
2020-01-06 17:12:19 -05:00
|
|
|
readonly name = DiagnosticProducingHandler.name;
|
|
|
|
readonly precedence = HandlerPrecedence.PRIMARY;
|
|
|
|
|
2019-12-09 18:22:59 -05:00
|
|
|
detect(node: ClassDeclaration, decorators: Decorator[]|null): DetectResult<unknown>|undefined {
|
2020-01-06 17:12:19 -05:00
|
|
|
const decorator = decorators !== null ? decorators[0] : null;
|
|
|
|
return {trigger: node, decorator, metadata: {}};
|
2019-07-18 16:05:32 -04:00
|
|
|
}
|
2019-11-23 12:54:07 -05:00
|
|
|
|
|
|
|
analyze(node: ClassDeclaration): AnalysisOutput<any> {
|
|
|
|
return {diagnostics: [makeDiagnostic(9999, node, 'test diagnostic')]};
|
|
|
|
}
|
2020-01-06 17:12:19 -05:00
|
|
|
|
perf(compiler-cli): detect semantic changes and their effect on an incremental rebuild (#40947)
In Angular programs, changing a file may require other files to be
emitted as well due to implicit NgModule dependencies. For example, if
the selector of a directive is changed then all components that have
that directive in their compilation scope need to be recompiled, as the
change of selector may affect the directive matching results.
Until now, the compiler solved this problem using a single dependency
graph. The implicit NgModule dependencies were represented in this
graph, such that a changed file would correctly also cause other files
to be re-emitted. This approach is limited in a few ways:
1. The file dependency graph is used to determine whether it is safe to
reuse the analysis data of an Angular decorated class. This analysis
data is invariant to unrelated changes to the NgModule scope, but
because the single dependency graph also tracked the implicit
NgModule dependencies the compiler had to consider analysis data as
stale far more often than necessary.
2. It is typical for a change to e.g. a directive to not affect its
public API—its selector, inputs, outputs, or exportAs clause—in which
case there is no need to re-emit all declarations in scope, as their
compilation output wouldn't have changed.
This commit implements a mechanism by which the compiler is able to
determine the impact of a change by comparing it to the prior
compilation. To achieve this, a new graph is maintained that tracks all
public API information of all Angular decorated symbols. During an
incremental compilation this information is compared to the information
that was captured in the most recently succeeded compilation. This
determines the exact impact of the changes to the public API, which
is then used to determine which files need to be re-emitted.
Note that the file dependency graph remains, as it is still used to
track the dependencies of analysis data. This graph does no longer track
the implicit NgModule dependencies, which allows for better reuse of
analysis data.
These changes also fix a bug where template type-checking would fail to
incorporate changes made to a transitive base class of a
directive/component. This used to be a problem because transitive base
classes were not recorded as a transitive dependency in the file
dependency graph, such that prior type-check blocks would erroneously
be reused.
This commit also fixes an incorrectness where a change to a declaration
in NgModule `A` would not cause the declarations in NgModules that
import from NgModule `A` to be re-emitted. This was intentionally
incorrect as otherwise the performance of incremental rebuilds would
have been far worse. This is no longer a concern, as the compiler is now
able to only re-emit when actually necessary.
Fixes #34867
Fixes #40635
Closes #40728
PR Close #40947
2020-11-20 15:18:46 -05:00
|
|
|
symbol(node: ClassDeclaration, analysis: Readonly<unknown>): null {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-09-09 15:32:56 -04:00
|
|
|
compileFull(node: ClassDeclaration): CompileResult|CompileResult[] {
|
2020-04-06 03:30:08 -04:00
|
|
|
return [];
|
|
|
|
}
|
2019-11-23 12:54:07 -05:00
|
|
|
}
|