fix(date): Date.UTC defaults, setter optional args, Date.parse grammar - #3407
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2826
Closes #2851
Closes #2827
Implementation
Reworks
Dateargument semantics incrates/perry-runtime/src/date.rsto match Node exactly, with the supporting HIR/codegen plumbing to carry full argument lists.#2826 —
Date.UTCdefaults, year rebasing, invalid-argument semanticsjs_date_utcnow takes(args_ptr, argc)(a NaN-boxed args buffer + count) instead of seven pre-paddedf64s, so the runtime can distinguish omitted from explicit-zero components.argc == 0→NaN; omittedmonth→ 0, omittedday→ 1, omitted time fields → 0.yearin0..=99is rebased to1900 + year(rebase_two_digit_year).NaN→ Invalid (NaN).days_from_civil+make_utc_ms(ECMA MakeDay/MakeTime), shared bynew Date(...)local construction.#2851 — Date setters honor optional trailing arguments
{ date, value }to{ date, args: Vec<Expr> }(crates/perry-hir/src/ir/expr.rs), with matching updates to the stable-hash field hashing, both HIR walkers, lowering (url_date_instance.rs, no longer gated on!args.is_empty()), and all native/JS/wasm codegen backends.js_date_apply_setter(date, is_utc, field, args_ptr, argc)replaces the per-setter helpers. It applies every supplied component (setUTCHours(h, min?, sec?, ms?),setUTCFullYear(y, mo?, d?), etc.), keeps omitted trailing fields, and treats an omitted/undefinedleading argument asNaN→ Invalid Date (setHours()→ Invalid).rebuild_with/rebuild_local_withwere rewritten to takeOption<f64>overrides with NaN-propagation.#2827 —
Date.parsestring grammar + timezone handlingparse_date_stringrewritten intoparse_iso8601+parse_rfc_or_named:YYYY,YYYY-MM,YYYY-MM-DD, optionalTHH:MM[:SS[.sss]], optionalZ/+HH:MM/-HH:MM/+HHMMoffset; date-only/no-offset treated as UTC.YYYY-MM-DD HH:MM:SS(MySQL).Thu, 01 Jan 1970 00:00:00 GMT,01 Jan 1970 00:00:00 GMT(optional weekday, GMT/UTC/offset).March 7, 2020), interpreted as local time when no zone token is present.s.parse::<f64>()-first behavior that madeDate.parse("2020")return2020is gone.New
#[no_mangle]symbolsjs_date_utc(signature change) andjs_date_apply_setterget#[used]keepalive anchors so the auto-optimize whole-program LLVM rebuild doesn't dead-strip them.Validation
test-files/test_gap_date_2826_2851_2827.ts(fixed inputs only — noDate.now()/arglessnew Date()) is byte-identical tonode --experimental-strip-typesunder the default auto-optimize compile.cargo test --release -p perry-runtime date(19 passed) andcargo test --release -p perry-hir(green, includingexpr_variant_stable_hash_tags_are_unique)../scripts/check_file_size.shexit 0,cargo fmt --all -- --checkclean, fullcargo build --releaseclean (cold).test_gap_date_methods.ts,test_issue_1187_date_setters.ts,test_issue_2089_date_reference.ts,test_issue_748_invalid_date.ts,test_gap_2371_console_invalid_date.tsremain byte-identical to Node. Extra edge cases (negative ISO offset, month underflowDate.UTC(2020,-1,1),Mar 31 → setUTCMonth(1)rollover) also verified identical.