Adds a utility that will find if a source file has a top-level identifier with a certain name. This will be useful when trying to avoid conflicts in generated imports later on.
Expands the `insertImport` utility to allow for imports to be inserted wuth an alias. Also adds unit tests and reworks the internals to be a bit more precise in where they look for matching nodes since previously they could've broken in some cases.
Angular v15.1 deprecated the `CanLoad` guard in favor of `CanMatch`.
This commit removes the support for `CanLoad` when generating a guard with the CLI, to encourage developers to use `CanMatch` instead.
BREAKING CHANGE:
The CLI no longer allows to generate `CanLoad` guards. Use `CanMatch` instead.
Due to incorrect castings previously the code would crash when the module doesn't contain an routing module with the following error:
```
Cannot read property 'properties' of undefined
```
Closes#21397
All TypeScript files have been updated to pass the new eslint-based linting checks. eslint compatible disabling comments have also been added in place of the previous tslint comments.
Previously, `addSymbolToNgModuleMetadata()` assumed that the added
symbol would not span multiple lines. In most cases, the added symbol is
a single word, so this assumption was correct. In some cases, however,
we might want to add a mutli-line string, such as a static method of an
`@NgModule`:
```ts
imports: [
SomeModule.staticMethod({
prop1: 'val1',
prop2: 'val2'
})
]
```
This commit allows `addSymbolToNgModuleMetadata()` to correctly handle
multi-line strings by ensuring that added metadata symbols are always
put on a new line (even if the array is empty) and each line in the
string is indented as necessary.
Curtrently, when a node of kind is found, we recursivly continue to look up it's child nodes until the end of the AST. This ends up returing other nodes which we were not looking for as typically we are looking for the first level of children of the specified kind.
By default now, we stop recursivly looking for child nodes of kind when we encounter one.
Closes#15117
`findNodes` will continue looking for arrays recursively unless we specify that we specify that we want only the first array.
Routes array can contain nested arrays such as when specifying guards.
Fixes#15016
At the moment, at least a single whitespace is required as otherwise the following error `Cannot read property '0' of null ` will be thrown
Fixes#12950