Skip to content

Feature: support stable id macro generators #32

Description

@conartist6

I think there's room to build a really cool feature here which fits with my general goal of exposing the behind-the-scenes magic that makes most modern javascript run. The idea is basically to build support for continuous codemods. These would continuously evaluate on source files and would have the opportunity to react to changes in files. The main purpose of this would be to insert stable identifiers into the code.

In practice I've seen a few kinds of expressions that would benefit from being tagged with stable ids: errors and translations. Each will likely need to be tracked and cross-referenced across multiple versions of a codebase, which may even have structural differences. For translations the most stable possible ID is valuable since churn in the unique key of the translation likely leads to paying translators to redo translations that are already done. For errors the advantage is in aggregating errors with the same fundamental cause in order to give engineers good data which will permit statistical analysis and integration across a range of products.

Here's what I imagine this looking like:

import { uid } from 'unique.stable.macro';

throw new CodedError('test', { code: uid`` });

When a file with those contents was saved, a generator would react and attempt to generate changes. unique.macro would find the empty uid tagged template string and would fill it with some unique identifier, resulting in something like this:

import { uid } from 'unique.stable.macro';

throw new CodedError('test', { code: uid`001F` });

Any further evaluations of the generator and the macro must not write the file at this point, or an infinite loop would be caused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions