Skip to content

Commit

Permalink
make to go formatter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 18, 2022
1 parent 0d4fae1 commit d981064
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 104 deletions.
200 changes: 100 additions & 100 deletions internal/compat/js_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,110 +98,110 @@ const (

var StringToJSFeature = map[string]JSFeature{
"arbitrary-module-namespace-names": ArbitraryModuleNamespaceNames,
"array-spread": ArraySpread,
"arrow": Arrow,
"async-await": AsyncAwait,
"async-generator": AsyncGenerator,
"bigint": Bigint,
"class": Class,
"class-field": ClassField,
"class-private-accessor": ClassPrivateAccessor,
"class-private-brand-check": ClassPrivateBrandCheck,
"class-private-field": ClassPrivateField,
"class-private-method": ClassPrivateMethod,
"class-private-static-accessor": ClassPrivateStaticAccessor,
"class-private-static-field": ClassPrivateStaticField,
"class-private-static-method": ClassPrivateStaticMethod,
"class-static-blocks": ClassStaticBlocks,
"class-static-field": ClassStaticField,
"const-and-let": ConstAndLet,
"default-argument": DefaultArgument,
"destructuring": Destructuring,
"dynamic-import": DynamicImport,
"exponent-operator": ExponentOperator,
"export-star-as": ExportStarAs,
"for-await": ForAwait,
"for-of": ForOf,
"generator": Generator,
"hashbang": Hashbang,
"import-assertions": ImportAssertions,
"import-meta": ImportMeta,
"logical-assignment": LogicalAssignment,
"nested-rest-binding": NestedRestBinding,
"new-target": NewTarget,
"node-colon-prefix-import": NodeColonPrefixImport,
"node-colon-prefix-require": NodeColonPrefixRequire,
"nullish-coalescing": NullishCoalescing,
"object-accessors": ObjectAccessors,
"object-extensions": ObjectExtensions,
"object-rest-spread": ObjectRestSpread,
"optional-catch-binding": OptionalCatchBinding,
"optional-chain": OptionalChain,
"regexp-dot-all-flag": RegexpDotAllFlag,
"regexp-lookbehind-assertions": RegexpLookbehindAssertions,
"regexp-match-indices": RegexpMatchIndices,
"regexp-named-capture-groups": RegexpNamedCaptureGroups,
"regexp-sticky-and-unicode-flags": RegexpStickyAndUnicodeFlags,
"regexp-unicode-property-escapes": RegexpUnicodePropertyEscapes,
"rest-argument": RestArgument,
"template-literal": TemplateLiteral,
"top-level-await": TopLevelAwait,
"typeof-exotic-object-is-object": TypeofExoticObjectIsObject,
"unicode-escapes": UnicodeEscapes,
"array-spread": ArraySpread,
"arrow": Arrow,
"async-await": AsyncAwait,
"async-generator": AsyncGenerator,
"bigint": Bigint,
"class": Class,
"class-field": ClassField,
"class-private-accessor": ClassPrivateAccessor,
"class-private-brand-check": ClassPrivateBrandCheck,
"class-private-field": ClassPrivateField,
"class-private-method": ClassPrivateMethod,
"class-private-static-accessor": ClassPrivateStaticAccessor,
"class-private-static-field": ClassPrivateStaticField,
"class-private-static-method": ClassPrivateStaticMethod,
"class-static-blocks": ClassStaticBlocks,
"class-static-field": ClassStaticField,
"const-and-let": ConstAndLet,
"default-argument": DefaultArgument,
"destructuring": Destructuring,
"dynamic-import": DynamicImport,
"exponent-operator": ExponentOperator,
"export-star-as": ExportStarAs,
"for-await": ForAwait,
"for-of": ForOf,
"generator": Generator,
"hashbang": Hashbang,
"import-assertions": ImportAssertions,
"import-meta": ImportMeta,
"logical-assignment": LogicalAssignment,
"nested-rest-binding": NestedRestBinding,
"new-target": NewTarget,
"node-colon-prefix-import": NodeColonPrefixImport,
"node-colon-prefix-require": NodeColonPrefixRequire,
"nullish-coalescing": NullishCoalescing,
"object-accessors": ObjectAccessors,
"object-extensions": ObjectExtensions,
"object-rest-spread": ObjectRestSpread,
"optional-catch-binding": OptionalCatchBinding,
"optional-chain": OptionalChain,
"regexp-dot-all-flag": RegexpDotAllFlag,
"regexp-lookbehind-assertions": RegexpLookbehindAssertions,
"regexp-match-indices": RegexpMatchIndices,
"regexp-named-capture-groups": RegexpNamedCaptureGroups,
"regexp-sticky-and-unicode-flags": RegexpStickyAndUnicodeFlags,
"regexp-unicode-property-escapes": RegexpUnicodePropertyEscapes,
"rest-argument": RestArgument,
"template-literal": TemplateLiteral,
"top-level-await": TopLevelAwait,
"typeof-exotic-object-is-object": TypeofExoticObjectIsObject,
"unicode-escapes": UnicodeEscapes,
}

var JSFeatureToString = map[JSFeature]string{
ArbitraryModuleNamespaceNames: "arbitrary-module-namespace-names",
ArraySpread: "array-spread",
Arrow: "arrow",
AsyncAwait: "async-await",
AsyncGenerator: "async-generator",
Bigint: "bigint",
Class: "class",
ClassField: "class-field",
ClassPrivateAccessor: "class-private-accessor",
ClassPrivateBrandCheck: "class-private-brand-check",
ClassPrivateField: "class-private-field",
ClassPrivateMethod: "class-private-method",
ClassPrivateStaticAccessor: "class-private-static-accessor",
ClassPrivateStaticField: "class-private-static-field",
ClassPrivateStaticMethod: "class-private-static-method",
ClassStaticBlocks: "class-static-blocks",
ClassStaticField: "class-static-field",
ConstAndLet: "const-and-let",
DefaultArgument: "default-argument",
Destructuring: "destructuring",
DynamicImport: "dynamic-import",
ExponentOperator: "exponent-operator",
ExportStarAs: "export-star-as",
ForAwait: "for-await",
ForOf: "for-of",
Generator: "generator",
Hashbang: "hashbang",
ImportAssertions: "import-assertions",
ImportMeta: "import-meta",
LogicalAssignment: "logical-assignment",
NestedRestBinding: "nested-rest-binding",
NewTarget: "new-target",
NodeColonPrefixImport: "node-colon-prefix-import",
NodeColonPrefixRequire: "node-colon-prefix-require",
NullishCoalescing: "nullish-coalescing",
ObjectAccessors: "object-accessors",
ObjectExtensions: "object-extensions",
ObjectRestSpread: "object-rest-spread",
OptionalCatchBinding: "optional-catch-binding",
OptionalChain: "optional-chain",
RegexpDotAllFlag: "regexp-dot-all-flag",
RegexpLookbehindAssertions: "regexp-lookbehind-assertions",
RegexpMatchIndices: "regexp-match-indices",
RegexpNamedCaptureGroups: "regexp-named-capture-groups",
RegexpStickyAndUnicodeFlags: "regexp-sticky-and-unicode-flags",
RegexpUnicodePropertyEscapes: "regexp-unicode-property-escapes",
RestArgument: "rest-argument",
TemplateLiteral: "template-literal",
TopLevelAwait: "top-level-await",
TypeofExoticObjectIsObject: "typeof-exotic-object-is-object",
UnicodeEscapes: "unicode-escapes",
ArraySpread: "array-spread",
Arrow: "arrow",
AsyncAwait: "async-await",
AsyncGenerator: "async-generator",
Bigint: "bigint",
Class: "class",
ClassField: "class-field",
ClassPrivateAccessor: "class-private-accessor",
ClassPrivateBrandCheck: "class-private-brand-check",
ClassPrivateField: "class-private-field",
ClassPrivateMethod: "class-private-method",
ClassPrivateStaticAccessor: "class-private-static-accessor",
ClassPrivateStaticField: "class-private-static-field",
ClassPrivateStaticMethod: "class-private-static-method",
ClassStaticBlocks: "class-static-blocks",
ClassStaticField: "class-static-field",
ConstAndLet: "const-and-let",
DefaultArgument: "default-argument",
Destructuring: "destructuring",
DynamicImport: "dynamic-import",
ExponentOperator: "exponent-operator",
ExportStarAs: "export-star-as",
ForAwait: "for-await",
ForOf: "for-of",
Generator: "generator",
Hashbang: "hashbang",
ImportAssertions: "import-assertions",
ImportMeta: "import-meta",
LogicalAssignment: "logical-assignment",
NestedRestBinding: "nested-rest-binding",
NewTarget: "new-target",
NodeColonPrefixImport: "node-colon-prefix-import",
NodeColonPrefixRequire: "node-colon-prefix-require",
NullishCoalescing: "nullish-coalescing",
ObjectAccessors: "object-accessors",
ObjectExtensions: "object-extensions",
ObjectRestSpread: "object-rest-spread",
OptionalCatchBinding: "optional-catch-binding",
OptionalChain: "optional-chain",
RegexpDotAllFlag: "regexp-dot-all-flag",
RegexpLookbehindAssertions: "regexp-lookbehind-assertions",
RegexpMatchIndices: "regexp-match-indices",
RegexpNamedCaptureGroups: "regexp-named-capture-groups",
RegexpStickyAndUnicodeFlags: "regexp-sticky-and-unicode-flags",
RegexpUnicodePropertyEscapes: "regexp-unicode-property-escapes",
RestArgument: "rest-argument",
TemplateLiteral: "template-literal",
TopLevelAwait: "top-level-await",
TypeofExoticObjectIsObject: "typeof-exotic-object-is-object",
UnicodeEscapes: "unicode-escapes",
}

func (features JSFeature) Has(feature JSFeature) bool {
Expand Down
16 changes: 12 additions & 4 deletions scripts/compat-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,15 @@ function jsFeatureString(feature) {
return feature.replace(/([A-Z])/g, '-$1').slice(1).toLowerCase()
}

function writeInnerMap(obj) {
function simpleMap(entries) {
let maxLength = 0
for (const [key] of entries) {
maxLength = Math.max(maxLength, key.length + 1)
}
return entries.map(([key, value]) => `\t${(key + ':').padEnd(maxLength)} ${value},`).join('\n')
}

function jsTableMap(obj) {
const keys = Object.keys(obj).sort()
const maxLength = keys.reduce((a, b) => Math.max(a, b.length + 1), 0)
if (keys.length === 0) return '{}'
Expand Down Expand Up @@ -379,11 +387,11 @@ ${Object.keys(versions).sort().map((x, i) => `\t${x}${i ? '' : ' JSFeature = 1 <
)
var StringToJSFeature = map[string]JSFeature{
${Object.keys(versions).sort().map(x => `\t"${jsFeatureString(x)}": ${x},`).join('\n')}
${simpleMap(Object.keys(versions).sort().map(x => [`"${jsFeatureString(x)}"`, x]))}
}
var JSFeatureToString = map[JSFeature]string{
${Object.keys(versions).sort().map(x => `\t${x}: "${jsFeatureString(x)}",`).join('\n')}
${simpleMap(Object.keys(versions).sort().map(x => [x, `"${jsFeatureString(x)}"`]))}
}
func (features JSFeature) Has(feature JSFeature) bool {
Expand All @@ -395,7 +403,7 @@ func (features JSFeature) ApplyOverrides(overrides JSFeature, mask JSFeature) JS
}
var jsTable = map[JSFeature]map[Engine][]versionRange{
${Object.keys(versions).sort().map(x => `\t${x}: ${writeInnerMap(versions[x])},`).join('\n')}
${Object.keys(versions).sort().map(x => `\t${x}: ${jsTableMap(versions[x])},`).join('\n')}
}
// Return all features that are not available in at least one environment
Expand Down

1 comment on commit d981064

@asciidiego
Copy link

Choose a reason for hiding this comment

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

so cool!

Please sign in to comment.