Skip to content

Commit

Permalink
add "mdn" as a compat table data source
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 13, 2023
1 parent b07e747 commit af1d35c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 51 deletions.
11 changes: 11 additions & 0 deletions compat-table/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions compat-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"williamkapke/node-compat-table": "b11fbdb3e6c6d5fffbf4688d830c7453eb64cff7"
},
"dependencies": {
"@mdn/browser-compat-data": "5.3.2",
"@types/caniuse-lite": "1.0.1",
"@types/node": "20.3.2",
"caniuse-lite": "1.0.30001508"
Expand Down
61 changes: 11 additions & 50 deletions compat-table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs = require('fs')
import path = require('path')
import { generateTableForJS } from './js_table'
import * as caniuse from './caniuse'
import * as mdn from './mdn'

export type Engine = keyof typeof engines
export const engines = {
Expand Down Expand Up @@ -242,6 +243,9 @@ import('./kangax').then(({ js }) => {
// Merge data from https://caniuse.com into the JavaScript support map
mergeSupportMaps(js, caniuse.js)

// Merge data from the Mozilla Developer Network into the JavaScript support map
mergeSupportMaps(js, mdn.js)

// ES5 features
js.ObjectAccessors.ES = { 5: { force: true } }
js.ObjectAccessors.Node = { '0.4': { force: true } } // "node-compat-table" doesn't appear to cover ES5 features...
Expand Down Expand Up @@ -284,6 +288,7 @@ import('./kangax').then(({ js }) => {

// ES2020 features
js.Bigint.ES = { 2020: { force: true } }
js.ExportStarAs.ES = { 2020: { force: true } }
js.ImportMeta.ES = { 2020: { force: true } }
js.NullishCoalescing.ES = { 2020: { force: true } }
js.OptionalChain.ES = { 2020: { force: true } }
Expand All @@ -307,37 +312,6 @@ import('./kangax').then(({ js }) => {
js.ArbitraryModuleNamespaceNames.ES = { 2022: { force: true } }
js.RegexpMatchIndices.ES = { 2022: { force: true } }

// Manually copied from https://caniuse.com/?search=export%20*%20as
{
js.ExportStarAs.Chrome = { 72: { force: true } }
js.ExportStarAs.Edge = { 79: { force: true } }
js.ExportStarAs.ES = { 2020: { force: true } }
js.ExportStarAs.Firefox = { 80: { force: true } }
js.ExportStarAs.Node = { 12: { force: true } } // From https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export
js.ExportStarAs.Opera = { 60: { force: true } }

// This feature has been implemented in Safari but I have no idea what version
// this bug corresponds to: https://bugs.webkit.org/show_bug.cgi?id=214379
}

// Manually copied from https://caniuse.com/#search=import.meta
js.ImportMeta.Chrome = { 64: { force: true } }
js.ImportMeta.Edge = { 79: { force: true } }
js.ImportMeta.Firefox = { 62: { force: true } }
js.ImportMeta.IOS = { 12: { force: true } }
js.ImportMeta.Node = { '10.4': { force: true } } // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta
js.ImportMeta.Opera = { 51: { force: true } }
js.ImportMeta.Safari = { '11.1': { force: true } }

// Manually copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await
js.TopLevelAwait.Chrome = { 89: { force: true } }
js.TopLevelAwait.Edge = { 89: { force: true } }
js.TopLevelAwait.Firefox = { 89: { force: true } }
js.TopLevelAwait.IOS = { 15: { force: true } }
js.TopLevelAwait.Node = { '14.8': { force: true } }
js.TopLevelAwait.Opera = { 75: { force: true } }
js.TopLevelAwait.Safari = { 15: { force: true } }

// This is a problem specific to Internet Explorer. See https://github.com/tc39/ecma262/issues/1440
for (const engine in engines) {
if (engine as Engine !== 'ES' && engine as Engine !== 'IE') {
Expand Down Expand Up @@ -420,31 +394,18 @@ import('./kangax').then(({ js }) => {
// this bug corresponds to: https://bugs.webkit.org/show_bug.cgi?id=217576
}

// Import assertions
// Import assertions (note: these were removed from the JavaScript specification and never standardized)
{
// From https://www.chromestatus.com/feature/5765269513306112
js.ImportAssertions.Chrome = { 91: { force: true } }

// From https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V16.md#16.14.0
js.ImportAssertions.Node = { '16.14': { force: true } }

// Not yet in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1736059
// MDN data is wrong here: https://bugs.webkit.org/show_bug.cgi?id=251600
delete js.ImportAssertions.IOS
delete js.ImportAssertions.Safari
}

// Manually copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_static_initialization_blocks
js.ClassStaticBlocks.Chrome = { 91: { force: true } } // From https://www.chromestatus.com/feature/6482797915013120
js.ClassStaticBlocks.Edge = { 94: { force: true } }
js.ClassStaticBlocks.Firefox = { 93: { force: true } }
js.ClassStaticBlocks.Node = { '16.11': { force: true } }
js.ClassStaticBlocks.Opera = { 80: { force: true } }

// Manually copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/hasIndices
js.RegexpMatchIndices.Chrome = { 90: { force: true } }
js.RegexpMatchIndices.Edge = { 90: { force: true } }
js.RegexpMatchIndices.Firefox = { 88: { force: true } }
js.RegexpMatchIndices.IOS = { 15: { force: true } }
js.RegexpMatchIndices.Opera = { 76: { force: true } }
js.RegexpMatchIndices.Safari = { 15: { force: true } }
// MDN data is wrong here: https://www.chromestatus.com/feature/6482797915013120
js.ClassStaticBlocks.Chrome = { 91: { force: true } }

const jsVersionRanges = supportMapToVersionRanges(js)
generateTableForJS(jsVersionRanges)
Expand Down
60 changes: 60 additions & 0 deletions compat-table/src/mdn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This file processes data from https://developer.mozilla.org/en-US/docs/Web

import bcd from '@mdn/browser-compat-data'
import { Engine, JSFeature, Support, SupportMap } from './index'

const supportedEnvironments: Record<string, Engine> = {
chrome: 'Chrome',
deno: 'Deno',
edge: 'Edge',
firefox: 'Firefox',
ie: 'IE',
nodejs: 'Node',
opera: 'Opera',
safari: 'Safari',
safari_ios: 'IOS',
}

const jsFeatures: Record<string, JSFeature> = {
'javascript.builtins.RegExp.hasIndices': 'RegexpMatchIndices',
'javascript.classes.static_initialization_blocks': 'ClassStaticBlocks',
'javascript.operators.await.top_level': 'TopLevelAwait',
'javascript.operators.import_meta': 'ImportMeta',
'javascript.statements.export.namespace': 'ExportStarAs',
'javascript.statements.import.import_assertions': 'ImportAssertions',
}

export const js: SupportMap<JSFeature> = {} as SupportMap<JSFeature>

for (const feature in jsFeatures) {
const jsFeature = jsFeatures[feature]
const engines: Partial<Record<Engine, Record<string, Support>>> = {}
let object: any = bcd

// Traverse the JSON object to find the data
for (const key of feature.split('.')) {
object = object[key]
}

const support = object.__compat.support

for (const env in support) {
const engine = supportedEnvironments[env]

if (engine) {
const entries = support[env]

for (const { flags, version_added, version_removed } of Array.isArray(entries) ? entries : [entries]) {
if (flags && flags.length > 0) {
// The feature isn't considered to be supported if it requires a flag
continue
}
if (version_added && !version_removed && /^\d+(?:\.\d+(?:\.\d+)?)?$/.test(version_added)) {
engines[engine] = { [version_added]: { force: true } }
}
}
}
}

js[jsFeature] = engines
}
14 changes: 13 additions & 1 deletion internal/compat/js_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,14 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
ClassStaticBlocks: {
Chrome: {{start: v{91, 0, 0}}},
Deno: {{start: v{1, 14, 0}}},
Edge: {{start: v{94, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{93, 0, 0}}},
IOS: {{start: v{16, 4, 0}}},
Node: {{start: v{16, 11, 0}}},
Opera: {{start: v{80, 0, 0}}},
Safari: {{start: v{16, 4, 0}}},
},
ClassStaticField: {
Chrome: {{start: v{73, 0, 0}}},
Expand Down Expand Up @@ -427,11 +430,14 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
ExportStarAs: {
Chrome: {{start: v{72, 0, 0}}},
Deno: {{start: v{1, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
ES: {{start: v{2020, 0, 0}}},
Firefox: {{start: v{80, 0, 0}}},
Node: {{start: v{12, 0, 0}}},
IOS: {{start: v{14, 5, 0}}},
Node: {{start: v{13, 2, 0}}},
Opera: {{start: v{60, 0, 0}}},
Safari: {{start: v{14, 1, 0}}},
},
ForAwait: {
Chrome: {{start: v{63, 0, 0}}},
Expand Down Expand Up @@ -494,10 +500,13 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
ImportAssertions: {
Chrome: {{start: v{91, 0, 0}}},
Deno: {{start: v{1, 17, 0}}},
Edge: {{start: v{91, 0, 0}}},
Node: {{start: v{16, 14, 0}}},
},
ImportMeta: {
Chrome: {{start: v{64, 0, 0}}},
Deno: {{start: v{1, 0, 0}}},
Edge: {{start: v{79, 0, 0}}},
ES: {{start: v{2020, 0, 0}}},
Firefox: {{start: v{62, 0, 0}}},
Expand Down Expand Up @@ -649,10 +658,12 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
RegexpMatchIndices: {
Chrome: {{start: v{90, 0, 0}}},
Deno: {{start: v{1, 8, 0}}},
Edge: {{start: v{90, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{88, 0, 0}}},
IOS: {{start: v{15, 0, 0}}},
Node: {{start: v{16, 0, 0}}},
Opera: {{start: v{76, 0, 0}}},
Safari: {{start: v{15, 0, 0}}},
},
Expand Down Expand Up @@ -715,6 +726,7 @@ var jsTable = map[JSFeature]map[Engine][]versionRange{
},
TopLevelAwait: {
Chrome: {{start: v{89, 0, 0}}},
Deno: {{start: v{1, 0, 0}}},
Edge: {{start: v{89, 0, 0}}},
ES: {{start: v{2022, 0, 0}}},
Firefox: {{start: v{89, 0, 0}}},
Expand Down

0 comments on commit af1d35c

Please sign in to comment.