aurelia icon indicating copy to clipboard operation
aurelia copied to clipboard

feat(syntax): Nullish coalescing op ??

Open bigopon opened this issue 3 years ago • 7 comments

Pull Request

📖 Description

Add support for ?? in the expression parser, and template. Now it's possible to do this

<el value.bind="prop1 ?? prop2">

An issue with Aurelia expression behavior is that Aurelia automatically coerces null/undefined to empty string in non strict mode, which won't work with ??. We will probably need to start thinking of adding safe navigation operator ?. and revisit strict vs non-strict mode soon.

Thanks @fkleuver for the parser work.

bigopon avatar Jun 27 '21 09:06 bigopon

Can we have ?. too? (for array and ...) related to this issue

image

HamedFathi avatar Jun 27 '21 09:06 HamedFathi

@HamedFathi thanks for reminding about that issue. That probably should be added too. I'm not sure whether it should be added together with this, or a separate one. cc @fkleuver

bigopon avatar Jun 27 '21 10:06 bigopon

The benchmarking comparison can be found here: https://au2-bench-viewer.azurewebsites.net/compare?branch=master&commit=13a730fabf730bd59498ad4d84fc14361fd922b3&branch=nullish-coalescing-op&commit=ea3371707d9156d9d798b2f602449ba0921b7b4f

AureliaEffect avatar Jun 27 '21 10:06 AureliaEffect

Codecov Report

Merging #1202 (8731a6c) into master (3d468c9) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1202      +/-   ##
==========================================
+ Coverage   87.94%   87.95%   +0.01%     
==========================================
  Files         159      159              
  Lines       17224    17241      +17     
  Branches     3588     3598      +10     
==========================================
+ Hits        15147    15164      +17     
  Misses       2077     2077              
Impacted Files Coverage Δ
packages/runtime/src/binding/ast.ts 76.61% <100.00%> (+0.05%) :arrow_up:
packages/runtime/src/binding/expression-parser.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3d468c9...8731a6c. Read the comment docs.

codecov[bot] avatar Jun 27 '21 10:06 codecov[bot]

I'm not sure whether it should be added together with this, or a separate one.

Doesn't matter, there's no breaking changes or conflicts etc either way. I can't predict very well when I'll have time though at the moment.

fkleuver avatar Jun 27 '21 11:06 fkleuver

are these things not going to make it into v2?

milkshakeuk avatar Feb 25 '22 13:02 milkshakeuk

are these things not going to make it into v2?

@milkshakeuk null/undefined are often treated as an empty string, hence the mention of strict vs non strict mode (default). Applications normally prefer non strict mode I'd assume, so while it could be useful, it's not a lot more meaningful yet. Though eventually this and ?. should be in.

bigopon avatar Mar 15 '22 12:03 bigopon