Commit graph

31 commits

Author SHA1 Message Date
Andrew Scott
4e098fa8a7 refactor(core): move Zone providers to a single provider function (#49373)
This commit moves the providers for `NgZone`-based change detection to a
single provider function. This function is currently called by default
in all places where `NgZone` was provided
(`bootstrapApplication`, `bootstrapModule`, and `TestBed`).

When we want to make Angular applications zoneless by default, we
can make a public provider method that has to be used in order to enable
the zone change detection features. When this method is not called,
Angular would use `NoopNgZone` by default and not initialize any
subscriptions to the `NgZone` stability events.

Side note: There are actually two places that `NgZone` is provided for `TestBed`
(providers in `compileTestModule` and `BrowserTestingModule`). This
likely doesn't need to be in both locations.

PR Close #49373
2023-03-14 09:20:53 -07:00
robertIsaac
c5a84851ea docs: add NG0403.md for Bootstrapped NgModule doesn't specify which component to initialize error (#48483)
- update `errors.ts` to annotate the error NG0403, so that the runtime can add a link to that guide when an error is thrown
- update `application_ref_spec.ts` to include the new link of the error
- update `errors.md` as a result of running `yarn bazel test packages/core/test`

Fixes #47985

PR Close #48483
2023-01-04 09:59:24 -08:00
Andrew Scott
ff84c73603 docs(core): Document invalid multi token (#48267)
Add error page for invalid multi token runtime error

PR Close #48267
2022-12-13 14:05:59 -08:00
Andrew Kushnir
ec8b52af69 docs(core): add an error details page for unsafe <iframe> bindings (#48027)
PR Close #48027
2022-11-11 11:28:35 -08:00
Andrew Kushnir
2d8d562604 fix(core): hardening attribute and property binding rules for <iframe> elements (#47964)
This commit updates the logic related to the attribute and property binding rules for <iframe> elements. There is a set of <iframe> attributes that may affect the behavior of an iframe and this change enforces that these attributes are only applied as static attributes, making sure that they are taken into account while creating an <iframe>.

If Angular detects that some of the security-sensitive attributes are applied as an attribute or property binding, it throws an error message, which contains the name of an attribute that is causing the problem and the name of a Component where an iframe is located.

BREAKING CHANGE:

Existing iframe usages may have security-sensitive attributes applied as an attribute or property binding in a template or via host bindings in a directive. Such usages would require an update to ensure compliance with the new stricter rules around iframe bindings.

PR Close #47964
2022-11-09 00:47:56 -08:00
Dylan Hunn
8e6ec72beb fix(forms): Runtime error pages must begin with leading zero (#47991)
I recently checked in a new error guide. The corresponding page must have a leading zero because it is a runtime error. Otherwise links to this error guide will be invalid.

PR Close #47991
2022-11-08 10:35:09 -08:00
Andrew Kushnir
13b863a1bf Revert "fix(core): hardening rules related to the attribute order on iframe elements (#47935)" (#47959)
This reverts commit 2d08965b1a.

The reason for revert is that we've identified some issues with implementation. The issues will get addressed soon and the fix would be re-submitted.

PR Close #47959
2022-11-03 11:20:32 -07:00
Andrew Kushnir
2d08965b1a fix(core): hardening rules related to the attribute order on iframe elements (#47935)
This commit updates the logic related to the attribute order on iframes and makes the rules more strict. There is a set of iframe attributes that may affect the behavior of an iframe, this change enforces that these attributes are applied before an `src` or `srcdoc` attributes are applied to an iframe, so that they are taken into account.

If Angular detects that some of the attributes are set after the `src` or `srcdoc`, it throws an error message, which contains the name of ann attribute that is causing the problem and the name of a Component where an iframe is located. In most cases, it should be enough to change the order of attributes in a template to move the `src` or `srcdoc` ones to the very end.

BREAKING CHANGE:

Existing iframe usages may have `src` or `srcdoc` preceding other attributes. Such usages may need to be updated to ensure compliance with the new stricter rules around iframe bindings.

PR Close #47935
2022-11-02 09:07:31 -07:00
Kristiyan Kostadinov
50f8928d56 refactor(core): add host directive definitions validation (#47589)
Adds some logic to ensure that host directives are configured correctly.

PR Close #47589
2022-09-30 10:52:12 -07:00
Andrew Kushnir
66e41223f3 refactor(core): improve an error message when ENVIRONMENT_INITIALIZER is not a multi provider (#46829)
Currently if the `ENVIRONMENT_INITIALIZER` token is not configured with `multi: true` flag, the code fails while trying to iterate over the value. This commit checks whether the `ENVIRONMENT_INITIALIZER` token value type is an array and throws a helpful error message.

PR Close #46829
2022-07-13 22:01:14 +00:00
Alex Rickabaugh
af600cd2b7 refactor(core): disable automatic usage of Renderer3 (#46605)
Previously, when instantiating a component, Angular would look in the DI
hierarchy for `RendererFactory2`. Any DI tree which rolls up through an
application injector (that is, one created with `BrowserModule`) should be
able to provide this interface. If not found, Angular would switch to the
experimental `Renderer3` mechanism. This switch was designed this way,
because it allowed for the creation of experimental applications where
`RendererFactory2` was not included in the bundle at all.

In this commit, instead of automatically falling back on `Renderer3`-style
rendering, an error is raised instead if `RendererFactory2` is missing from
the DI hierarchy.

PR Close #46605
2022-06-30 09:04:56 -07:00
Ramesh Thiruchelvam
07828528be refactor(core): make di error messages tree shakable (#46422)
Tree shake error messages from the production build and introduce error codes.

PR Close #46422
2022-06-24 13:12:21 -07:00
Ramesh Thiruchelvam
7da389a461 refactor(core): make zone error messages tree shakable (#46480)
Make the error messages tree shakable from the production build to reduce the bundle size.

PR Close #46480
2022-06-24 13:11:14 -07:00
Ramesh Thiruchelvam
1da3a051b5 refactor(core): make i18n error messages tree shakable (#46468)
Make the error messages tree shakable from the production build to reduce the bundle size.

PR Close #46468
2022-06-23 16:36:35 -07:00
dario-piotrowicz
0b7ab075b7 refactor(core): improve the runtime errors formatting (#46239)
the formatted error messages always include a period separator between the
provided error message and the find-more suffix, this is not always
desirable as it may add periods when they shoud not be, so improve the
formatting by checking and applying the period only if the provided message
doesn't end with a character which already represents a separator

additionally also improve the formatting by trimming the provided error
message

note that such trimming needs to be performed before the separator check
so that for example an error message like `"some error! "` doesn't produce
`"some error! ."` but it successfully produces "some error!"

PR Close #46239
2022-06-06 10:12:05 -07:00
Pawel Kozlowski
12b4ec3d85 docs: create a dedicated page for the NG0203 error (#46166)
Adds a dedicated error page for NG0203 (injection context).

PR Close #46166
2022-05-27 10:15:55 -07:00
Pawel Kozlowski
410d81f0e2 refactor(core): disallow standalone components in importProvidersFrom calls (#45837)
This commit narrows down acceptable argument types of the
`importProvidersFrom` function. More specifically, it rejects
standalone components as a source of imports.

PR Close #45837
2022-05-03 13:12:36 -07:00
Alex Rickabaugh
d322052db3 refactor(core): guard against importProvidersFrom in components (#45838)
`importProvidersFrom` provides a bridge from the world of NgModule-based DI
configuration to the new, "standalone" world of direct providers and
environment injectors. Early user feedback suggested some confusion around
where this function was supposed to be used, particularly around importing
NgModule-based providers into standalone component `providers` arrays, which
is not the intended use. This confusion is exacerbated by the fact that due
to the unified `Provider` type, this kind of misconfiguration was happily
accepted by the type system.

This commit changes the return type of `importProvidersFrom` to wrap the
returned providers in an opaque type that prevents them from being used in
component provider contexts. This, together with stronger documentation
around the purpose and functionality of `importProvidersFrom`, should
address some of the above confusion.

PR Close #45838
2022-05-02 15:50:44 -07:00
Andrew Kushnir
5771b18a98 feat(core): add the bootstrapApplication function (#45674)
This commit implements the `bootstrapApplication` function that allows bootstrapping an application and pass a standalone component as a root component.

PR Close #45674
2022-04-21 17:47:54 -07:00
Andrew Kushnir
174ce7dd13 feat(core): add ApplicationRef.destroy method (#45624)
This commit implements the `destroy` method on the `ApplicationRef` class. This feature is a preparation for the new logic to bootstrap (and teardown) standalone components (without going through the `NgModuleRef` destroy), which would return an instance of the `ApplicationRef` (the current bootstrap APIs return an instance of the `NgModuleRef`).

PR Close #45624
2022-04-18 14:09:47 -07:00
Andrew Kushnir
ed1732c268 refactor(core): the RuntimeError class should support more compact syntax (#44783)
This commit refactors the `RuntimeError` class to support a short version of providing error messages:
```
throw new RuntimeError(
  RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
  ngDevMode && 'Injector has already been destroyed.');
```
In prod mode, the second argument becomes `false` andn this commit extends the typings to support that.

This commit also contains a couple places were the `RuntimeError` class is used to demostrate the compact form.

PR Close #44783
2022-02-01 00:15:56 +00:00
Ramesh Thiruchelvam
bc03a2e3e3 refactor(core): make the error messages tree shakable (#44359)
Long error messages can be tree-shaken in the production build and replaced with error codes.

See: https://github.com/angular/angular/pull/44219#issuecomment-983216374

PR Close #44359
2022-01-18 17:38:10 -08:00
Andrew Kushnir
a84f99fd1c refactor(core): move runtime error code logic (#44398)
This commit moves some logic to make the location of runtime error codes consistent across packages. Now all error codes are located in `packages/core/src/errors.ts` file.

PR Close #44398
2022-01-06 23:43:18 +00:00
Alex Rickabaugh
8c71b9fc42 refactor: delete the View Engine runtime (#43884)
This commit removes the View Engine runtime. Itself, this change is
relatively straightforward, but it represents the final step in a multi-year
journey. It's only possible due to the hard work of many current and former
team members and collaborators, who are too numerous to list here.

Co-authored-by: Alan Agius <alan.agius4@gmail.com>
Co-authored-by: Andrew Kushnir <akushnir@google.com>
Co-authored-by: Andrew Scott <atscott01@gmail.com>
Co-authored-by: Andrew Seguin <andrewjs@google.com>
Co-authored-by: Cédric Exbrayat <cedric@ninja-squad.com>
Co-authored-by: Charles Lyding <19598772+clydin@users.noreply.github.com>
Co-authored-by: Dave Shevitz <dshevitz@google.com>
Co-authored-by: Doug Parker <dgp1130@users.noreply.github.com>
Co-authored-by: Dylan Hunn <dylhunn@gmail.com>
Co-authored-by: Emma Twersky <emmatwersky@google.com>
Co-authored-by: George Kalpakas <kalpakas.g@gmail.com>
Co-authored-by: Igor Minar <iminar@google.com>
Co-authored-by: Jeremy Elbourn <jelbourn@google.com>
Co-authored-by: Jessica Janiuk <jessicajaniuk@google.com>
Co-authored-by: JiaLiPassion <JiaLi.Passion@gmail.com>
Co-authored-by: Joey Perrott <josephperrott@gmail.com>
Co-authored-by: Joost Koehoorn <joost.koehoorn@gmail.com>
Co-authored-by: Kristiyan Kostadinov <crisbeto@abv.bg>
Co-authored-by: Madleina Scheidegger <mscheid@google.com>
Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com>
Co-authored-by: Minko Gechev <mgechev@gmail.com>
Co-authored-by: Paul Gschwendtner <paulgschwendtner@gmail.com>
Co-authored-by: Pawel Kozlowski <pkozlowski.opensource@gmail.com>
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
Co-authored-by: Wagner Maciel <wagnermaciel@google.com>
Co-authored-by: Zach Arend <zachzach@google.com>

PR Close #43884
2021-11-23 21:10:06 +00:00
George Kalpakas
eefe1682e8 fix(core): correctly handle null or undefined in ErrorHandler#handleError() (#42881)
Since `ErrorHandler#handleError()` expects an argument of type `any` it
should be able to handle values such as `null` and `undefined`.
Previously, it failed to handle these values, because it was trying to
access properties on them.

This commit fixes it by ensuring no properties are accessed on `null` or
`undefined` values.

NOTE: This is part of fully addressing #28106.

Fixes #21252

PR Close #42881
2021-07-21 22:35:34 +00:00
Andrew Kushnir
95b8a8706a refactor(core): reduce the number of circular deps (#38805)
This commit updates several import statements in the core package to decrease the number of
cycles detected by the dependency checker tool.

PR Close #38805
2020-09-18 11:20:08 -07:00
Joey Perrott
d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00
Misko Hevery
885f1af509 build: extract interface and util sub compilation from core (#28028)
PR Close #28028
2019-01-10 16:31:44 -08:00
Tobias Bosch
0cc77b4a69 refactor(compiler): split compiler and core (#18683)
After this, neither @angular/compiler nor @angular/comnpiler-cli depend
on @angular/core.

This add a duplication of some interfaces and enums which is stored
in @angular/compiler/src/core.ts

BREAKING CHANGE:
- `@angular/platform-server` now additionally depends on
  `@angular/platform-browser-dynamic` as a peer dependency.


PR Close #18683
2017-08-16 17:58:53 -05:00
Tobias Bosch
cdc882bd36 feat: introduce source maps for templates (#15011)
The main use case for the generated source maps is to give
errors a meaningful context in terms of the original source
that the user wrote.

Related changes that are included in this commit:

* renamed virtual folders used for jit:
  * ng://<module type>/module.ngfactory.js
  * ng://<module type>/<comp type>.ngfactory.js
  * ng://<module type>/<comp type>.html (for inline templates)
* error logging:
  * all errors that happen in templates are logged
    from the place of the nearest element.
  * instead of logging error messages and stacks separately,
    we log the actual error. This is needed so that browsers apply
    source maps to the stack correctly.
  * error type and error is logged as one log entry.

Note that long-stack-trace zone has a bug that 
disables source maps for stack traces,
see https://github.com/angular/zone.js/issues/661.

BREAKING CHANGE:

- DebugNode.source no more returns the source location of a node.  

Closes 14013
2017-03-14 09:16:15 -07:00
Jason Aden
3e51a19983 refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00
Renamed from modules/@angular/core/src/errors.ts (Browse further)