first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

11
node_modules/flow-enums-runtime/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,11 @@
# 0.0.6
- Update README documentation
# 0.0.5
- `.members()` on a mirrored enum now returns an iterator (not just an iterable), matching non-mirrored enums
# 0.0.4
- Added `getName` method
# 0.0.3
- Initial open-source version

21
node_modules/flow-enums-runtime/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) Facebook, Inc. and its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

15
node_modules/flow-enums-runtime/README.md generated vendored Normal file
View File

@@ -0,0 +1,15 @@
flow-enums-runtime
==================
This is the runtime used with the [Flow Enums](https://flow.org/en/docs/enums/) [Babel transform](https://www.npmjs.com/package/babel-plugin-transform-flow-enums).
Install this package in your regular dependencies, as it is required and used by the output of the Flow Enums transform at runtime.
Read more about how to [enable Flow Enums in your project](https://flow.org/en/docs/enums/enabling-enums/).
### Requirements
This package requires support (either natively or through a polyfill) for [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
and [Array.prototype.values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values).
Support for [WeakMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) is suggested,
but not required (will fall back to `Map` instead if not present).

View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
// Must be before we require `../index`
const originalWeakMap = global.WeakMap;
global.WeakMap = undefined;
const Enum = require('../index');
global.WeakMap = originalWeakMap;
test('works when `WeakMap` is not defined', () => {
const F = Enum({A: 1});
expect(F.isValid(1)).toBe(true);
});

248
node_modules/flow-enums-runtime/__tests__/tests.js generated vendored Normal file
View File

@@ -0,0 +1,248 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const Enum = require('../index');
describe('Enum', () => {
const E = Enum({A: 1, B: 2});
test('access members', () => {
expect(E.A).toBe(1);
expect(E.B).toBe(2);
});
test('only two own properties', () => {
expect(Object.getOwnPropertyNames(E).length).toBe(2);
});
test('no enumerable properties', () => {
let count = 0;
for (const _ in E) {
count++;
}
expect(count).toBe(0);
});
test('not extensible', () => {
expect(Object.isExtensible(E)).toBe(false);
expect(() => {
E.C = 3;
}).toThrow();
expect(E.C).toBe(undefined);
expect(Object.getOwnPropertyNames(E).length).toBe(2);
});
test('not writable', () => {
expect(() => {
E.A = 66;
}).toThrow();
expect(() => {
E.B = 66;
}).toThrow();
expect(E.A).toBe(1);
expect(E.B).toBe(2);
});
test('not deletable', () => {
expect(() => {
delete E.A;
}).toThrow();
expect(() => {
delete E.B;
}).toThrow();
expect(E.A).toBe(1);
expect(E.B).toBe(2);
});
test('not configurable', () => {
expect(() => {
Object.defineProperty(E, 'A', {
value: 66,
writable: true,
enumerable: true,
configurable: true,
});
}).toThrow('Cannot redefine property: A');
});
test('not castable to primitive', () => {
expect(() => {
'' + E;
}).toThrow('Cannot convert object to primitive value');
});
test('prototype frozen', () => {
const F = Enum({A: 1});
expect(() => {
Object.getPrototypeOf(F).isValid = () => true;
}).toThrow();
expect(F.isValid(1)).toBe(true);
});
describe('prototype methods', () => {
test('isValid', () => {
expect(E.isValid(1)).toBe(true);
expect(E.isValid(2)).toBe(true);
expect(E.isValid(3)).toBe(false);
expect(E.isValid(null)).toBe(false);
expect(E.isValid(undefined)).toBe(false);
});
test('cast', () => {
expect(E.cast(1)).toBe(E.A);
expect(E.cast(2)).toBe(E.B);
expect(E.cast(3)).toBe(undefined);
});
test('members iterable', () => {
expect(Array.from(E.members())).toEqual([1, 2]);
let i = 1;
for (const x of E.members()) {
expect(x).toEqual(i);
i++;
}
});
test('members iterator', () => {
const iter = E.members();
expect(iter.next()).toEqual({value: 1, done: false});
expect(iter.next()).toEqual({value: 2, done: false});
expect(iter.next()).toEqual({value: undefined, done: true});
});
test('getName', () => {
expect(E.getName(E.A)).toBe('A');
expect(E.getName(E.B)).toBe('B');
});
});
});
describe('Enum.Mirrored', () => {
const E = Enum.Mirrored(['A', 'B']);
test('access members', () => {
expect(E.A).toBe('A');
expect(E.B).toBe('B');
});
test('only two own properties', () => {
expect(Object.getOwnPropertyNames(E).length).toBe(2);
});
test('no enumerable properties', () => {
let count = 0;
for (const _ in E) {
count++;
}
expect(count).toBe(0);
});
test('not extensible', () => {
expect(Object.isExtensible(E)).toBe(false);
expect(() => {
E.C = 'C';
}).toThrow();
expect(E.C).toBe(undefined);
expect(Object.getOwnPropertyNames(E).length).toBe(2);
});
test('not writable', () => {
expect(() => {
E.A = 'foo';
}).toThrow();
expect(() => {
E.B = 'bar';
}).toThrow();
expect(E.A).toBe('A');
expect(E.B).toBe('B');
});
test('not deletable', () => {
expect(() => {
delete E.A;
}).toThrow();
expect(() => {
delete E.B;
}).toThrow();
expect(E.A).toBe('A');
expect(E.B).toBe('B');
});
test('not configurable', () => {
expect(() => {
Object.defineProperty(E, 'A', {
value: 'x',
writable: true,
enumerable: true,
configurable: true,
});
}).toThrow('Cannot redefine property: A');
});
test('not castable to primitive', () => {
expect(() => {
'' + E;
}).toThrow('Cannot convert object to primitive value');
});
test('prototype frozen', () => {
const F = Enum.Mirrored(['A']);
expect(() => {
Object.getPrototypeOf(F).isValid = () => true;
}).toThrow();
expect(F.isValid('A')).toBe(true);
});
describe('prototype methods', () => {
test('isValid', () => {
expect(E.isValid('A')).toBe(true);
expect(E.isValid('B')).toBe(true);
expect(E.isValid('C')).toBe(false);
expect(E.isValid(null)).toBe(false);
expect(E.isValid(undefined)).toBe(false);
const s = {
toString() {
return 'A';
},
};
expect(E.isValid(s)).toBe(false);
});
test('cast', () => {
expect(E.cast('A')).toBe(E.A);
expect(E.cast('B')).toBe(E.B);
expect(E.cast('C')).toBe(undefined);
});
test('members iterable', () => {
const expected = ['A', 'B'];
expect(Array.from(E.members())).toEqual(expected);
let i = 0;
for (const x of E.members()) {
expect(x).toEqual(expected[i]);
i++;
}
});
test('members iterator', () => {
const iter = E.members();
expect(iter.next()).toEqual({value: 'A', done: false});
expect(iter.next()).toEqual({value: 'B', done: false});
expect(iter.next()).toEqual({value: undefined, done: true});
});
test('getName', () => {
expect(E.getName(E.A)).toBe('A');
expect(E.getName(E.B)).toBe('B');
});
});
});

115
node_modules/flow-enums-runtime/index.js generated vendored Normal file
View File

@@ -0,0 +1,115 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
// Below we want to use `hasOwnProperty` on an object that doesn't have
// `Object.prototype` in its proto chain, so we must extract it here.
var hasOwnProperty = Object.prototype.hasOwnProperty;
// Map from an enum object to a reverse map of its values to names
var reverseMapCache = typeof WeakMap === 'function' ? new WeakMap() : new Map();
// Computes the reverse mapping of the enum object: from value to name.
// Flow Enum values are unique (enforced by the parser), so this is a
// one to one mapping.
function getReverseMap(enumObject) {
var reverseMap = reverseMapCache.get(enumObject);
if (reverseMap !== undefined) {
return reverseMap;
}
// We aren't using `Object.values` because that gets enumerable
// properties, and our properties aren't enumerable.
var newReverseMap = new Map();
Object.getOwnPropertyNames(enumObject).forEach(function (name) {
newReverseMap.set(enumObject[name], name);
});
reverseMapCache.set(enumObject, newReverseMap);
return newReverseMap;
}
var EnumPrototype = Object.freeze(
Object.defineProperties(Object.create(null), {
isValid: {
value: function (x) {
return getReverseMap(this).has(x);
},
},
cast: {
value: function (x) {
return this.isValid(x) ? x : undefined;
},
},
members: {
value: function () {
return getReverseMap(this).keys();
},
},
getName: {
value: function (value) {
return getReverseMap(this).get(value);
}
}
})
);
// `members` is an object mapping name to value.
function Enum(members) {
var o = Object.create(EnumPrototype);
for (var k in members) {
if (hasOwnProperty.call(members, k)) {
// Create non-enumerable properties.
Object.defineProperty(o, k, {value: members[k]});
}
}
return Object.freeze(o);
}
// Mirrored enum (string enum with no member initializers).
// Optimized implementation, taking advantage of the fact that
// keys and values are identical.
var EnumMirroredPrototype = Object.freeze(
Object.defineProperties(Object.create(null), {
isValid: {
value: function (x) {
if (typeof x === 'string') {
return hasOwnProperty.call(this, x);
}
return false;
},
},
cast: {
value: EnumPrototype.cast,
},
members: {
value: function () {
// We aren't using `Object.values` because that gets enumerable
// properties, and our properties aren't enumerable.
return Object.getOwnPropertyNames(this).values();
},
},
getName: {
value: function (value) {
return value;
}
}
})
);
// `members` is an array of names (which, are also the values).
Enum.Mirrored = function EnumMirrored(members) {
var o = Object.create(EnumMirroredPrototype);
for (var i = 0, len = members.length; i < len; ++i) {
// Value is same as key. Also, non-enumerable.
Object.defineProperty(o, members[i], {value: members[i]});
}
return Object.freeze(o);
};
Object.freeze(Enum.Mirrored);
module.exports = Object.freeze(Enum);

17
node_modules/flow-enums-runtime/package.json generated vendored Normal file
View File

@@ -0,0 +1,17 @@
{
"name": "flow-enums-runtime",
"version": "0.0.6",
"description": "Runtime to be use with the Flow Enums transform.",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/flow.git"
},
"devDependencies": {
"jest": "^26.6.3"
}
}