Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update es-builtins #174

Merged

Conversation

scagood
Copy link

@scagood scagood commented Jan 26, 2024

I took the data from mdn/browser-compat-data and used that to update the es-builtins file (it was a lot-a-bit manual).

I do wander if we should make a script to automate this fully.

Copy link
Author

@scagood scagood left a comment

Choose a reason for hiding this comment

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

Comment on lines +295 to +303
dotAll: { [READ]: { supported: "8.10.0" } },
hasIndices: { [READ]: { supported: "16.0.0" } },
input: { [READ]: { supported: "0.10.0" } },
lastIndex: { [READ]: { supported: "0.10.0" } },
lastMatch: { [READ]: { supported: "0.10.0" } },
lastParen: { [READ]: { supported: "0.10.0" } },
leftContext: { [READ]: { supported: "0.10.0" } },
n: { [READ]: { supported: "0.10.0" } },
rightContext: { [READ]: { supported: "0.10.0" } },
Copy link
Author

Choose a reason for hiding this comment

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

There appear to be some wrong here, I will look more later 🤔

@scagood
Copy link
Author

scagood commented Jan 27, 2024

I have a little extension to this in scagood#1

That removes all the 'backport' properties in favour of just having a supported array.
I will make that PR after this one is either merged or closed 👀

@scagood scagood marked this pull request as ready for review January 27, 2024 16:45
@scagood
Copy link
Author

scagood commented Jan 27, 2024

There is data that we want in both data.javascript.builtins and data.api.

The script I used to help automate this is:
const data = require("./data.json")

const knownIssues = new Set([
    "TypedArray",
    "AsyncFunction",
    "Generator",
    "AsyncGenerator",
    "GeneratorFunction",
    "AsyncGeneratorFunction",
    "Iterator",
    "AsyncIterator",
    "undefined",
    "AggregateError.errors",
])

function getVersion(data) {
    return (
        data.__compat?.support?.nodejs?.version_added ??
        data.__compat?.support?.nodejs?.[0]?.version_added ??
        false
    )
}

const dataset = data.javascript.builtins

for (const builtin in dataset) {
    if (knownIssues.has(builtin)) {
        continue
    }
    const builtinData =
        builtin.endsWith("Array") && !builtin.startsWith("Array")
            ? {
                  ...dataset.TypedArray,
                  ...dataset[builtin],
              }
            : dataset[builtin]
    const builtinVersion = getVersion(builtinData)

    if (builtinVersion === false) {
        continue
    }

    let lines = [
        `${builtin}: {`,
        `    [READ]: { supported: "${builtinVersion}" },`,
    ]

    for (const fullKey of Object.keys(builtinData)) {
        // if (fullKey.endsWith('_static') === false) {
        //     continue;
        // }

        const key = fullKey //.slice(0, -7);
        const keyData = builtinData[fullKey]
        if (
            key === builtin ||
            key === "__compat" ||
            key.startsWith("@@") ||
            knownIssues.has(`${builtin}.${key}`) ||
            knownIssues.has(`${builtin}.*`) ||
            knownIssues.has(`*.${key}`)
        ) {
            continue
        }

        if (
            // Its a new feature of ${builtin}
            keyData.__compat?.spec_url == null ||
            // Its not a static property
            keyData.__compat?.spec_url.includes(
                `.prototype.${key.toLowerCase()}`
            )
        ) {
            continue
        }

        const keyVersion = getVersion(keyData)
        if (keyVersion === false) {
            continue
        }

        lines.push(`    ${key}: { [READ]: { supported: "${keyVersion}" } },`)
    }

    lines.push("},")

    console.info(lines.join("\n"))
}

Even though its super hacky... when the data.api dataset is used we need to uncomment the following:

if (fullKey.endsWith('_static') === false) {
    continue;
}

const key = fullKey.slice(0, -7);

@aladdin-add aladdin-add changed the title fix: Update es-builtins feat: Update es-builtins Jan 29, 2024
Copy link

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants