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(router): revert commit that replaced last helper with native Array.at(-1) #54051

Open
wants to merge 2 commits into
base: 17.0.x
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ jobs:
//packages/zone.js/test/closure:closure_js \

- run: |
rm -Rf packages/zone.js/build
rm -Rf packages/zone.js/test/extra/*.umd.js

mkdir -p packages/zone.js/build/
mkdir -p packages/zone.js/build/test/
mkdir -p packages/zone.js/test/

cp dist/bin/packages/zone.js/bundles/zone.umd.js packages/zone.js/build/zone.umd.js
cp dist/bin/packages/zone.js/npm_package/bundles/zone-mix.umd.js ./packages/zone.js/test/extra/
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,9 @@
{
"name": "last"
},
{
"name": "last3"
},
{
"name": "lastNodeWasCreated"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/create_url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {RuntimeErrorCode} from './errors';
import {ActivatedRouteSnapshot} from './router_state';
import {Params, PRIMARY_OUTLET} from './shared';
import {createRoot, squashSegmentGroup, UrlSegment, UrlSegmentGroup, UrlTree} from './url_tree';
import {shallowEqual} from './utils/collection';
import {last, shallowEqual} from './utils/collection';


/**
Expand Down Expand Up @@ -187,7 +187,7 @@ class Navigation {
}

const cmdWithOutlet = commands.find(isCommandWithOutlets);
if (cmdWithOutlet && cmdWithOutlet !== commands.at(-1)) {
if (cmdWithOutlet && cmdWithOutlet !== last(commands)) {
throw new RuntimeError(
RuntimeErrorCode.MISPLACED_OUTLETS_COMMAND,
(typeof ngDevMode === 'undefined' || ngDevMode) &&
Expand Down
7 changes: 7 additions & 0 deletions packages/router/src/utils/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export function equalArraysOrString(a: string|string[], b: string|string[]) {
}
}

/**
* Return the last element of an array.
*/
export function last<T>(a: T[]): T|null {
return a.length > 0 ? a[a.length - 1] : null;
}

export function wrapIntoObservable<T>(value: T|Promise<T>|Observable<T>): Observable<T> {
if (isObservable(value)) {
return value;
Expand Down
3 changes: 2 additions & 1 deletion packages/router/src/utils/config_matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {runCanMatchGuards} from '../operators/check_guards';
import {defaultUrlMatcher, PRIMARY_OUTLET} from '../shared';
import {UrlSegment, UrlSegmentGroup, UrlSerializer} from '../url_tree';

import {last} from './collection';
import {getOrCreateRouteInjectorIfNeeded, getOutlet} from './config';

export interface MatchResult {
Expand Down Expand Up @@ -95,7 +96,7 @@ export function match(
function createWildcardMatchResult(segments: UrlSegment[]): MatchResult {
return {
matched: true,
parameters: segments.at(-1)?.parameters ?? {},
parameters: segments.length > 0 ? last(segments)!.parameters : {},
consumedSegments: segments,
remainingSegments: [],
positionalParamSegments: {},
Expand Down
27 changes: 27 additions & 0 deletions packages/zone.js/test/typings/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@types/node@^16.11.7":
version "16.18.74"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.74.tgz#af518a0abafe8ab453f04c12ee62cfad75a8ca8d"
integrity sha512-eEn8RkzZFcT0gb8qyi0CcfSOQnLE+NbGLIIaxGGmjn/N35v/C3M8ohxcpSlNlCv+H8vPpMGmrGDdCkzr8xu2tQ==

"domino@https://github.com/angular/domino.git#9e7881d2ac1e5977cefbc557f935931ec23f6658":
version "2.1.6"
resolved "https://github.com/angular/domino.git#9e7881d2ac1e5977cefbc557f935931ec23f6658"

tslib@^2.3.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==

typescript@5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.2.2.tgz#5ebb5e5a5b75f085f22bc3f8460fba308310fa78"
integrity sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==

"zone.js@file:../../../../dist/bin/packages/zone.js/npm_package":
version "0.14.3"
dependencies:
tslib "^2.3.0"