Skip to content

“Map.prototype.getOrInsert” made its way to TC39 Stage 4, use it in “setIfMissing”. #350

@theengineear

Description

@theengineear

The https://github.com/tc39/proposal-upsert was just announced at Stage 4 and already has support in FF. Waiting on Chrome and Safari. Currently, we manage this ourselves, but the native behavior should be more performant and carry better semantics.

TODO:

  • Shipping in Chrome (ticket)
  • Shipping in FF (ticket)
  • Shipping in Safari (ticket ??)
  • Shipping in TypeScript 6.0 (no need to switch to this ahead of type definitions, there’s no rush)
// before
const analysis = TemplateEngine.#setIfMissing(TemplateEngine.#stringsToAnalysis, strings, () => ({}));

// after
const analysis = TemplateEngine.#stringsToAnalysis.getOrInsertComputed(strings, () => ({}));
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions