Skip to content

Conversation

justingrant
Copy link
Collaborator

The zoneRequired option in ES.ParseTemporalTimeZoneString doesn't work, because the zonesplit regex in regex.mjs matches any string. (It does correctly match each component, it just doesn't fail if none match.) Furthermore, callers of this option don't really follow the spec that requires throwing as soon as we know that it's not the right regex for the type.

This PR fixes #1973 by:

  • Removing the zoneRequired option
  • Removing the now-unused datetime regex, and renaming the instant regex to zoneddatetime to better reflect what it's doing.
  • Refactoring a few of the parsing methods to better match the spec, which expects that strings that don't satisfy the production will throw before doing non-parsing work. After this PR, every Parse* AO will throw if the string doesn't match the production for that type.

@justingrant justingrant added non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! no-spec-text PR can be ignored by implementors labels Dec 14, 2021
@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #1979 (9fafb23) into main (93fe7b8) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1979      +/-   ##
==========================================
+ Coverage   94.98%   94.99%   +0.01%     
==========================================
  Files          19       19              
  Lines       10943    10939       -4     
  Branches     1739     1739              
==========================================
- Hits        10394    10392       -2     
+ Misses        533      531       -2     
  Partials       16       16              
Flag Coverage Δ
test262 80.10% <100.00%> (+0.05%) ⬆️
tests 89.86% <91.30%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.24% <100.00%> (+0.04%) ⬆️
polyfill/lib/regex.mjs 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 93fe7b8...9fafb23. Read the comment docs.

Copy link
Collaborator

@ptomato ptomato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

ParseTemporalInstantString: (isoString) => {
return ES.ParseISODateTime(isoString, { zoneRequired: true });
const result = ES.ParseISODateTime(isoString);
if (!result || (!result.z && !result.offset)) throw new RangeError('Temporal.Instant requires a time zone offset');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need !result here? It seems like an object will always be returned. (Same comment goes for ParseTemporalZonedDateTimeString below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, must have been left over from a previous go at solving this problem with the same "return false" pattern that we're actually removing. I'll remove and then merge.

The `zoneRequired` option in ParseTemporalTimeZoneString doesn't work,
because the `zonesplit` regex in regex.mjs matches any string. (It does
correctly match each component, it just doesn't fail if none match.)
Furthermore, callers of this option don't really follow the spec that
requires throwing as soon as we know that it's not the right regex
for the type.

This commit fixes tc39#1973 by:
* Removing the `zoneRequired` option
* Removing the now-unused `datetime` regex, and renaming the `instant`
  regex to `zoneddatetime` to better reflect what it's doing.
* Refactoring a few of the parsing methods to better match the spec,
  which expects that strings that don't satisfy the production will
  throw before doing non-parsing work. After this commit, every `Parse*`
  method will throw if the string doesn't match the production for that
  type.
@justingrant justingrant force-pushed the remove-zone-required-option branch from 050aa56 to 9fafb23 Compare December 14, 2021 21:27
@justingrant justingrant merged commit 90ee179 into tc39:main Dec 15, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Dec 15, 2021
justingrant added a commit to js-temporal/temporal-polyfill that referenced this pull request Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-spec-text PR can be ignored by implementors non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polyfill: ParseISODateTime(isoString, { zoneRequired: true }) doesn't actually require a zone. Expected?

2 participants